Exemplo n.º 1
0
        async Task <ActionResult> IWorkflowManager.RequestReassignAsync(Workflow wf)
        {
            Requires.NonNull(wf, nameof(wf));

            //TODO: Get programatically based on user's region
            var reassignGroupId = await GetNextOwnerUserIdAsync(wf, Properties.Settings.Default.ReassignGroupUserName);

            wf.OwnerUserId = reassignGroupId ?? PortalHelpers.GetUserId(Properties.Settings.Default.ReassignGroupUserName);
            var c           = new RedirectingController();
            var routeValues = new RouteValueDictionary(new Dictionary <string, object>());

            return(await Task.FromResult(c.RedirectToAction(UloController.ActionNames.Index, UloController.Name, routeValues)));
        }
Exemplo n.º 2
0
        async Task <ActionResult> IWorkflowManager.ReassignAsync(Workflow wf, string userId, string actionName)
        {
            Requires.NonNull(wf, nameof(wf));
            Requires.Text(userId, nameof(userId));

            wf.OwnerUserId = userId;
            var routeValues = new RouteValueDictionary(new Dictionary <string, object>());

            await NotifyNewAssigneeAsync(wf, userId, Properties.Settings.Default.ManualReassignmentEmailTemplateId);

            var c = new RedirectingController();

            return(await Task.FromResult(c.RedirectToAction(actionName, UloController.Name, routeValues)));
        }
Exemplo n.º 3
0
        async Task <IActionResult> IWorkflowManager.RequestReassignAsync(Workflow wf)
        {
            Requires.NonNull(wf, nameof(wf));

            var config = ConfigOptions.Value;

            //TODO: Get programatically based on user's region
            var reassignGroupId = await GetNextOwnerUserIdAsync(wf, config.ReassignGroupUserName);

            wf.OwnerUserId = reassignGroupId ?? UserHelpers.GetUserId(config.ReassignGroupUserName);
            var c           = new RedirectingController();
            var routeValues = new RouteValueDictionary(new Dictionary <string, object>());

            return(c.RedirectToAction(UloController.ActionNames.Index, UloController.Name, routeValues));
        }
Exemplo n.º 4
0
        async Task <IActionResult> IWorkflowManager.AdvanceAsync(Workflow wf, UnliqudatedObjectsWorkflowQuestion question, IList <string> submitterGroupNames, bool forceAdvance, bool ignoreActionResult, bool sendNotifications)
        {
            Requires.NonNull(wf, nameof(wf));

            string nextOwnerId     = "";
            var    desc            = await(this as IWorkflowManager).GetWorkflowDescriptionAsync(wf);
            var    currentActivity = desc.WebActionWorkflowActivities.FirstOrDefault(z => z.WorkflowActivityKey == wf.CurrentWorkflowActivityKey);

            //if question is null stays in current activity
            string nextActivityKey = "";

            try
            {
                BusinessLayer.Workflow.WorkflowActivity nextActivity;
                if (question != null)
                {
                    var t = ActivityChooserTypes.FirstOrDefault(z => z.Name == currentActivity.NextActivityChooserTypeName);
                    if (t == null)
                    {
                        LogError("Cannot find type for NextActivityChooser of name {NextActivityChooserTypeName}", currentActivity.NextActivityChooserTypeName);
                    }
                    var chooser = (IActivityChooser)ServiceProvider.GetService(t);
                    nextActivityKey = chooser.GetNextActivityKey(wf, question, currentActivity.NextActivityChooserConfig, submitterGroupNames) ?? wf.CurrentWorkflowActivityKey;
                    nextActivity    = desc.Activities.First(z => z.WorkflowActivityKey == nextActivityKey) ?? currentActivity;
                }
                else
                {
                    nextActivity = currentActivity;
                }

                //TODO: Handle null case which says stay where you are.
                wf.CurrentWorkflowActivityKey = nextActivity.WorkflowActivityKey;

                //TODO: Updata other info like the owner, date
                //TODO: Add logic for handling groups of users.
                if (nextActivity is WebActionWorkflowActivity)
                {
                    if ((wf.CurrentWorkflowActivityKey != currentActivity.WorkflowActivityKey && wf.OwnerUser.UserName != nextActivity.OwnerUserName) || forceAdvance == true)
                    {
                        nextOwnerId = await GetNextOwnerUserIdAsync(wf, null, nextActivity.WorkflowActivityKey);

                        wf.OwnerUserId = nextOwnerId;

                        if (sendNotifications)
                        {
                            await NotifyNewAssigneeAsync(wf, nextOwnerId, nextActivity.EmailTemplateId);
                        }
                    }
                    wf.TargetUlo.Status = nextActivity.ActivityName;

                    if (nextActivity.DueIn != null)
                    {
                        wf.ExpectedDurationInSeconds = (long?)nextActivity.DueIn.Value.TotalSeconds;
                    }

                    if (question != null && question.IsValid)
                    {
                        wf.TargetUlo.Valid = true;
                    }
                    else if (question != null && question.IsInvalid)
                    {
                        wf.TargetUlo.Valid = false;
                    }

                    if (ignoreActionResult)
                    {
                        return(null);
                    }

                    //TODO: if owner changes, look at other ways of redirecting.

                    var next = (WebActionWorkflowActivity)nextActivity;
                    var c    = new RedirectingController();

                    var routeValues = new RouteValueDictionary(next.RouteValueByName);
                    //routeValues[WorkflowIdRouteValueName] = wf.WorkflowId;
                    return(c.RedirectToAction(next.ActionName, next.ControllerName, routeValues));
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            finally
            {
                LogInformation("Workflow {WorkflowId} with {WorkflowKey} changing from activity {OldWorkflowActivityKey} to activity {NewWorkflowActivityKey} owned By {NewOwnerId}", wf.WorkflowId, wf.WorkflowKey, currentActivity, wf.CurrentWorkflowActivityKey, nextOwnerId);
            }
        }