Esempio n. 1
0
        public async Task AdvanceAsync_should_call_Email_with_proper_params()
        {
            //TODO: Need to figure out how to mock out FieldActivityChooser
            var wf = new Mock <Workflow>().Object;

            wf.WorkflowKey = "4a41abad-bac3-47fb-a8cf-5d667439d7c3";
            wf.OwnerUserId = "f2860baf-a555-4834-baf3-62b929d1b6b1";
            var questions    = new Mock <UnliqudatedObjectsWorkflowQuestion>().Object;
            var actionResult = await WorkflowManager.AdvanceAsync(wf, questions);
        }
Esempio n. 2
0
        //TODO: Email on exception or let user know what happened.
        async Task IBackgroundTasks.AssignWorkFlows(int reviewId, bool sendBatchNotifications)
        {
            var config = ConfigOptions.Value;

            try
            {
                var review = await DB.Reviews.FindAsync(reviewId);

                if (review == null)
                {
                    LogInformation("AssignWorkFlows could not find {reviewId}", reviewId);
                    return;
                }
                review.Status = Review.StatusNames.Assigning;
                await DB.SaveChangesAsync();

                var workflows =
                    DB.Workflows.Include(wf => wf.TargetUlo).Include(wf => wf.OwnerUser).
                    Where(wf => wf.OwnerUserId == UserHelpers.PreAssignmentUserUserId && wf.TargetUlo.ReviewId == reviewId).
                    Take(config.AssignWorkFlowsBatchSize).
                    //OrderBy(wf => wf.TargetUlo.ReviewId == reviewId ? 0 : 1).
                    ToList();

                LogInformation("AssignWorkFlows {reviewId} assigning up to {totalRecords} with {batchSize}", reviewId, workflows.Count, config.AssignWorkFlowsBatchSize);

                int z = 0;
                foreach (var workflow in workflows)
                {
                    await WorkflowManager.AdvanceAsync(workflow, null, null, true, true, !sendBatchNotifications);

                    if (++z % 10 == 0)
                    {
                        await DB.SaveChangesAsync();

                        LogDebug("AssignWorkFlows {reviewId} save after {recordsProcessed}/{totalRecords}", reviewId, z, workflows.Count);
                        var r = await DB.Reviews.FindAsync(reviewId);

                        if (r == null)
                        {
                            LogInformation("AssignWorkFlows cancelled as {reviewId} has been deleted", reviewId);
                            break;
                        }
                    }
                }
                review.SetStatusDependingOnClosedBit();
                await DB.SaveChangesAsync();

                LogInformation("AssignWorkFlows {reviewId} completed after {recordsProcessed}/{totalRecords}", reviewId, z, workflows.Count);

                if (z > 0)
                {
                    BackgroundJob.Enqueue <IBackgroundTasks>(bt => bt.AssignWorkFlows(reviewId, sendBatchNotifications));
                    if (config.SendBatchEmailsDuringAssignWorkflows)
                    {
                        BackgroundJob.Enqueue <IBackgroundTasks>(bt => bt.SendAssignWorkFlowsBatchNotifications(reviewId));
                    }
                }
            }
            catch (Exception ex)
            {
                LogError(ex,
                         "Problem in {methodName}",
                         nameof(IBackgroundTasks.AssignWorkFlows));
                throw;
            }
        }
Esempio n. 3
0
        //TODO: Email on exception or let user know what happened.
        async Task IBackgroundTasks.AssignWorkFlows(int reviewId, bool sendBatchNotifications)
        {
            try
            {
                var review = await DB.Reviews.FindAsync(reviewId);

                if (review == null)
                {
                    Log.Information("AssignWorkFlows could not find {reviewId}", reviewId);
                    return;
                }
                review.Status = Review.StatusNames.Assigning;
                await DB.SaveChangesAsync();

                var workflows =
                    DB.Workflows.Include(wf => wf.UnliquidatedObligation).Include(wf => wf.AspNetUser).
                    Where(wf => wf.OwnerUserId == PortalHelpers.PreAssignmentUserUserId).
                    OrderBy(wf => wf.UnliquidatedObligation.ReviewId == reviewId ? 0 : 1).
                    ToList();

                Log.Information("AssignWorkFlows {reviewId} assigning up to {totalRecords}", reviewId, workflows.Count);

                int z = 0;
                foreach (var workflow in workflows)
                {
                    await WorkflowManager.AdvanceAsync(workflow, null, null, true, true, !sendBatchNotifications);

                    if (++z % 10 == 0)
                    {
                        await DB.SaveChangesAsync();

                        Log.Debug("AssignWorkFlows {reviewId} save after {recordsProcessed}/{totalRecords}", reviewId, z, workflows.Count);
                        using (var zdb = PortalHelpers.UloDbCreator())
                        {
                            var r = await zdb.Reviews.FindAsync(reviewId);

                            if (r == null)
                            {
                                Log.Information("AssignWorkFlows cancelled as {reviewId} has been deleted", reviewId);
                                break;
                            }
                        }
                    }
                }
                review.SetStatusDependingOnClosedBit();
                await DB.SaveChangesAsync();

                Log.Information("AssignWorkFlows {reviewId} completed after {recordsProcessed}/{totalRecords}", reviewId, z, workflows.Count);

                if (Properties.Settings.Default.SendBatchEmailsDuringAssignWorkflows)
                {
                    BackgroundJob.Enqueue <IBackgroundTasks>(bt => bt.SendAssignWorkFlowsBatchNotifications(reviewId));
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex,
                          "Problem in {methodName}",
                          nameof(IBackgroundTasks.AssignWorkFlows));
                throw;
            }
        }
        public async Task <ActionResult> Save(
            int uloId,
            int workflowId,
            [Bind(Include =
                      nameof(AdvanceViewModel.JustificationKey) + "," +
                      nameof(AdvanceViewModel.Answer) + "," +
                      nameof(AdvanceViewModel.ExpectedDateForCompletion) + "," +
                      nameof(AdvanceViewModel.Comments) + "," +
                      nameof(AdvanceViewModel.WorkflowRowVersionString) + "," +
                      nameof(AdvanceViewModel.EditingBeganAtUtc) + "," +
                      nameof(AdvanceViewModel.UnliqudatedWorkflowQuestionsId))]
            AdvanceViewModel advanceModel = null)
        {
            var wf = await DB.FindWorkflowAsync(workflowId);

            if (wf == null)
            {
                return(HttpNotFound());
            }
            if (ModelState.IsValid)
            {
                Log.Information("Altering ULO {UloId} with Workflow {WorkflowId} via command {AlterCommand}", uloId, workflowId, Request["WhatNext"]);

                if (wf.WorkflowRowVersionString != advanceModel.WorkflowRowVersionString)
                {
                    LogStaleWorkflowError(wf, advanceModel.WorkflowRowVersionString, advanceModel.EditingBeganAtUtc);
                    var staleMessage = GetStaleWorkflowErrorMessage(wf, advanceModel.WorkflowRowVersionString, advanceModel.EditingBeganAtUtc);
                    AddPageAlert(staleMessage, false, PageAlert.AlertTypes.Danger, true);
                    return(RedirectToAction(ActionNames.Details, new { uloId = wf.TargetUloId, workflowId = wf.WorkflowId }));
                }

                var submit   = Request["WhatNext"] == "Submit";
                var question = await DB.UnliqudatedObjectsWorkflowQuestions.Where(z => z.WorkflowId == workflowId).OrderByDescending(z => z.UnliqudatedWorkflowQuestionsId).FirstOrDefaultAsync();

                if (question == null || !question.Pending)
                {
                    if (question != null)
                    {
                        question.Pending = false;
                    }
                    question = new UnliqudatedObjectsWorkflowQuestion
                    {
                        WorkflowId = workflowId
                    };
                    DB.UnliqudatedObjectsWorkflowQuestions.Add(question);
                }
                question.JustificationKey = advanceModel.JustificationKey;
                question.UserId           = CurrentUserId;
                question.Answer           = advanceModel.Answer;
                question.Comments         = advanceModel.Comments;
                question.Pending          = !submit;
                question.UnliqudatedWorkflowQuestionsId = advanceModel.UnliqudatedWorkflowQuestionsId;
                question.WorkflowRowVersion             = wf.WorkflowRowVersion;
                question.CreatedAtUtc = DateTime.UtcNow;
                wf.UnliquidatedObligation.ExpectedDateForCompletion = advanceModel.ExpectedDateForCompletion;
                await DB.SaveChangesAsync();

                if (submit)
                {
                    var ulo = await DB.UnliquidatedObligations.FindAsync(uloId);

                    var groupNames = ulo != null && ulo.RegionId != null?User.GetUserGroupNames(ulo.RegionId.Value) : Empty.StringArray.ToList();

                    var ret = await Manager.AdvanceAsync(wf, question, groupNames, Properties.Settings.Default.ForceAdvanceFromUloSubmit);

                    await DB.SaveChangesAsync();

                    AddPageAlert($"WorkflowId={workflowId} for UloId={uloId} on PDN={wf.UnliquidatedObligation.PegasysDocumentNumber} was submitted.", false, PageAlert.AlertTypes.Success, true);
                    return(ret);
                }
                else
                {
                    AddPageAlert($"WorkflowId={workflowId} for UloId={uloId} on PDN={wf.UnliquidatedObligation.PegasysDocumentNumber} was saved.", false, PageAlert.AlertTypes.Success, true);
                    return(RedirectToIndex());
                }
            }
            return(await Details(uloId, workflowId));
        }