Exemple #1
0
        public MoveErrorsToNewIssueResponse Invoke(MoveErrorsToNewIssueRequest request)
        {
            Trace("Starting...");
            TraceObject(request);

            new SynchroniseIndexCommitAction <Indexing.Errors>().Execute(Session);

            //now move errors from the other issues
            Session.RavenDatabaseCommands.UpdateByIndex(CoreConstants.IndexNames.Errors,
                                                        new IndexQuery
            {
                Query = request.Errors.Select(e => e.Id).ToRavenQuery("Id")
            },
                                                        new[]
            {
                new PatchRequest
                {
                    Name  = "IssueId",
                    Type  = PatchCommandType.Set,
                    Value = Issue.GetId(request.IssueId)
                }
            }, true);

            Session.AddCommitAction(new SendMessageCommitAction(new SyncIssueErrorCountsMessage
            {
                IssueId         = request.IssueId,
                OrganisationId  = request.CurrentUser.OrganisationId,
                TriggerEventUtc = DateTime.UtcNow,
            }, _configuration.GetEventsQueueAddress(request.CurrentUser.ActiveOrganisation.RavenInstance.FriendlyId)));

            return(new MoveErrorsToNewIssueResponse());
        }
        public AdjustRulesResponse Invoke(AdjustRulesRequest request)
        {
            Trace("Starting...");

            var currentIssue = Session.Raven.Load <Issue>(Issue.GetId(request.IssueId));

            AdjustRulesResponse response;

            if (!ValidateCommand(currentIssue, request.Rules, out response))
            {
                return(response);
            }

            _authorisationManager.Authorise(currentIssue, request.CurrentUser);

            //craete the new temp issue
            var tempIssue = CreateTempIssue(currentIssue, request);

            var currentDbIssue = currentIssue;

            if (!request.WhatIf)
            {
                //storing at this point makes sure we get an Id for the isssue
                Store(tempIssue);
            }
            else
            {
                //if we're just doing a whatif we don't want to actually change the issue in the db
                //note the properties on the new "currentissue" will still presumably be proxies
                //so need to be careful not to change anything on them...
                currentIssue = new Issue();
                PropertyMapper.Map(currentDbIssue, currentIssue);
            }

            //and update the existing issue
            UpdateCurrentIssue(currentIssue, request);

            Trace("Starting to determine non matching errors , Current Error Count:={0}, Temp Issue Error Count:={1}...", currentIssue.ErrorCount, tempIssue.ErrorCount);
            var nonMatchingErrorsResponse = _getErrorsThatDoNotMatchNewRulesQuery.Invoke(new GetErrorsThatDoNotMatchNewRulesRequest
            {
                IssueWithModifiedRules = currentIssue,
                IssueWithOldRules      = tempIssue
            });

            Trace("Completed determining non matching errors, temp issue error count:={0}, remaining errors:={1}...", tempIssue.ErrorCount, nonMatchingErrorsResponse.Matches);

            if (!request.WhatIf)
            {
                if (nonMatchingErrorsResponse.NonMatches.Count > 0)
                {
                    var dateTimeOffset = DateTime.UtcNow.ToDateTimeOffset(request.CurrentUser.ActiveOrganisation.TimezoneId);

                    //if errors on the original issue did not match the new rules, store the temp issue and move the non matching errors to it
                    Session.AddCommitAction(new RaiseIssueCreatedEvent(tempIssue));

                    //move all these errors to the new issue in a batch
                    _moveErrorsToNewIssueCommand.Invoke(new MoveErrorsToNewIssueRequest
                    {
                        Errors      = nonMatchingErrorsResponse.NonMatches,
                        IssueId     = tempIssue.Id,
                        CurrentUser = request.CurrentUser
                    });

                    //re-sync the error counts only if we have moved errors (do it for both issues)
                    Session.AddCommitAction(new SendMessageCommitAction(new SyncIssueErrorCountsMessage
                    {
                        IssueId         = currentIssue.Id,
                        OrganisationId  = request.CurrentUser.OrganisationId,
                        TriggerEventUtc = DateTime.UtcNow,
                    }, _configuration.GetEventsQueueAddress(request.CurrentUser.ActiveOrganisation.RavenInstance.FriendlyId)));

                    Session.AddCommitAction(new SendMessageCommitAction(new SyncIssueErrorCountsMessage
                    {
                        IssueId         = tempIssue.Id,
                        OrganisationId  = request.CurrentUser.OrganisationId,
                        TriggerEventUtc = DateTime.UtcNow,
                    }, _configuration.GetEventsQueueAddress(request.CurrentUser.ActiveOrganisation.RavenInstance.FriendlyId)));

                    Store(new IssueHistory
                    {
                        DateAddedUtc   = dateTimeOffset,
                        Type           = HistoryItemType.RulesAdjustedCreatedNewIssue,
                        SpawnedIssueId = tempIssue.Id,
                        UserId         = request.CurrentUser.Id,
                        IssueId        = currentIssue.Id,
                        ApplicationId  = currentIssue.ApplicationId,
                        SystemMessage  = true
                    });

                    Store(new IssueHistory
                    {
                        DateAddedUtc    = dateTimeOffset,
                        Type            = HistoryItemType.CreatedByRuleAdjustment,
                        SpawningIssueId = currentIssue.Id,
                        UserId          = request.CurrentUser.Id,
                        IssueId         = tempIssue.Id,
                        ApplicationId   = tempIssue.ApplicationId,
                        SystemMessage   = true
                    });
                }
                else
                {
                    Store(new IssueHistory
                    {
                        DateAddedUtc  = DateTime.UtcNow.ToDateTimeOffset(request.CurrentUser.ActiveOrganisation.TimezoneId),
                        Type          = HistoryItemType.RulesAdjustedNoNewIssue,
                        UserId        = request.CurrentUser.Id,
                        IssueId       = currentIssue.Id,
                        ApplicationId = currentIssue.ApplicationId,
                        SystemMessage = true
                    });

                    Delete(tempIssue);
                }

                Session.AddCommitAction(new RaiseIssueModifiedEvent(currentIssue));
            }

            return(new AdjustRulesResponse
            {
                Status = AdjustRulesStatus.Ok,
                IssueId = currentIssue.FriendlyId,
                ErrorsMatched = nonMatchingErrorsResponse.Matches.Count,
                ErrorsNotMatched = nonMatchingErrorsResponse.NonMatches.Count,
                UnmatchedIssueId = tempIssue.FriendlyId,
            });
        }
Exemple #3
0
        public MergeIssuesResponse Invoke(MergeIssuesRequest request)
        {
            Trace("Starting...");
            TraceObject(request);

            var mergeFromIssue = Load <Issue>(Issue.GetId(request.MergeFromIssueId));
            var mergeToIssue   = Load <Issue>(Issue.GetId(request.MergeToIssueId));

            MergeIssuesResponse response;

            if (!ValidateCommand(mergeFromIssue, mergeToIssue, out response))
            {
                return(response);
            }

            _authorisationManager.Authorise(mergeFromIssue, request.CurrentUser);
            _authorisationManager.Authorise(mergeToIssue, request.CurrentUser);

            new SynchroniseIndexCommitAction <Indexing.Errors>().Execute(Session);

            //move all errors fron the MergeFromIssue to the MergeToIssue
            Session.AddCommitAction(new UpdateByIndexCommitAction(CoreConstants.IndexNames.Errors,
                                                                  new IndexQuery
            {
                Query = "IssueId:{0}".FormatWith(mergeFromIssue.Id)
            },
                                                                  new[]
            {
                new PatchRequest
                {
                    Name  = "IssueId",
                    Type  = PatchCommandType.Set,
                    Value = mergeToIssue.Id
                }
            }, true));

            Store(new IssueHistory
            {
                DateAddedUtc    = DateTime.UtcNow.ToDateTimeOffset(request.CurrentUser.ActiveOrganisation.TimezoneId),
                SpawningIssueId = mergeFromIssue.Id,
                SystemMessage   = true,
                Type            = HistoryItemType.MergedTo,
                IssueId         = mergeToIssue.Id,
                ApplicationId   = mergeToIssue.ApplicationId
            });

            Delete(mergeFromIssue);

            //re-sync the error counts
            Session.AddCommitAction(new SendMessageCommitAction(new SyncIssueErrorCountsMessage
            {
                IssueId         = request.MergeToIssueId,
                OrganisationId  = request.CurrentUser.OrganisationId,
                TriggerEventUtc = DateTime.UtcNow,
            }, _configuration.GetEventsQueueAddress(request.CurrentUser.ActiveOrganisation.RavenInstance.FriendlyId)));

            return(new MergeIssuesResponse
            {
                Status = MergeIssuesStatus.Ok
            });
        }