public void Can_Get_Process(WorkflowType type, Type expected) { var instance = new WorkflowInstancePoco { Type = (int)type }; WorkflowProcess process = instance.GetProcess(); Assert.IsType(expected, process); }
public IHttpActionResult ResubmitWorkflowTask(TaskData model) { WorkflowInstancePoco instance = _instancesService.GetPopulatedInstance(model.InstanceGuid); WorkflowProcess process = instance.GetProcess(); try { IUser currentUser = _utility.GetCurrentUser(); instance = process.ResubmitWorkflow( instance, currentUser.Id, model.Comment ); string typeDescription = instance.WorkflowType.Description(instance.ScheduledDate); string typeDescriptionPast = instance.WorkflowType.DescriptionPastTense(instance.ScheduledDate); Log.Info($"{typeDescription} request for {instance.Node.Name} [{instance.NodeId}] was resubmitted by {currentUser.Name}"); _hubContext.Clients.All.TaskResubmitted( _tasksService.ConvertToWorkflowTaskList(instance.TaskInstances.ToList(), instance: instance)); return(Json(new { message = $"Changes resubmitted successfully. Page will be {typeDescriptionPast.ToLower()} following workflow completion.", status = 200, notifications = NotificationHelpers.MapEventMessagesToNotifications(process.EventMessages) }, ViewHelpers.CamelCase)); } catch (UmbracoOperationFailedException e) { string msg = $"A Publishing failure occurred processing the approval on {instance.Node.Name} [{instance.Node.Id}]"; Log.Error(msg, e); return(Json(new { message = msg, status = 200, isUmbracoOperationError = true, notifications = NotificationHelpers.MapEventMessagesToNotifications(process.EventMessages) } , ViewHelpers.CamelCase)); } catch (Exception ex) { string msg = $"An error occurred processing the approval on {instance.Node.Name} [{instance.NodeId}]"; Log.Error(msg, ex); return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg))); } }
public IHttpActionResult RejectWorkflowTask(TaskData model) { WorkflowInstancePoco instance = _instancesService.GetPopulatedInstance(model.InstanceGuid); try { WorkflowProcess process = instance.GetProcess(); IUser currentUser = _utility.GetCurrentUser(); instance = process.ActionWorkflow( instance, WorkflowAction.Reject, currentUser.Id, model.Comment ); string typeDescription = instance.WorkflowType.Description(instance.ScheduledDate); Log.Info($"{typeDescription} request for {instance.Node.Name} [{instance.NodeId}] was rejected by {currentUser.Name}"); _hubContext.Clients.All.TaskRejected( _tasksService.ConvertToWorkflowTaskList(instance.TaskInstances.ToList(), instance: instance)); if (model.Offline) { UmbracoContext.Security.ClearCurrentLogin(); } return(Json(new { message = typeDescription + " request has been rejected.", status = 200 }, ViewHelpers.CamelCase)); } catch (Exception ex) { string msg = $"An error occurred rejecting the workflow on {instance.Node.Name} [{instance.NodeId}]"; Log.Error(msg, ex); return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg))); } }
public IHttpActionResult CancelWorkflowTask(TaskData model) { WorkflowInstancePoco instance = _instancesService.GetPopulatedInstance(model.InstanceGuid); try { WorkflowProcess process = instance.GetProcess(); IUser currentUser = _utility.GetCurrentUser(); instance = process.CancelWorkflow( instance, currentUser.Id, model.Comment ); string typeDescription = instance.WorkflowType.Description(instance.ScheduledDate); Log.Info($"{typeDescription} request for {instance.Node.Name} [{instance.NodeId}] was cancelled by {currentUser.Name}"); _hubContext.Clients.All.TaskCancelled( _tasksService.ConvertToWorkflowTaskList(instance.TaskInstances.ToList(), instance: instance) .LastOrDefault()); return(Json(new { status = 200, message = typeDescription + " workflow cancelled" }, ViewHelpers.CamelCase)); } catch (Exception ex) { string msg = $"An error occurred cancelling the workflow on {instance.Node.Name} [{instance.NodeId}]"; Log.Error(msg, ex); return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg))); } }
public IHttpActionResult ApproveWorkflowTask(TaskData model) { WorkflowInstancePoco instance = _instancesService.GetPopulatedInstance(model.InstanceGuid); WorkflowProcess process = instance.GetProcess(); try { IUser currentUser = _utility.GetCurrentUser(); instance = process.ActionWorkflow( instance, WorkflowAction.Approve, currentUser.Id, model.Comment ); string msg = string.Empty; string logMsg = string.Empty; string typeDescription = instance.WorkflowType.Description(instance.ScheduledDate); string typeDescriptionPast = instance.WorkflowType.DescriptionPastTense(instance.ScheduledDate); switch (instance.WorkflowStatus) { case WorkflowStatus.PendingApproval: msg = $"Approval completed successfully. Page will be {typeDescriptionPast.ToLower()} following workflow completion."; logMsg = $"Workflow {typeDescription} task on {instance.Node.Name} [{instance.NodeId}] approved by {currentUser.Name}"; break; case WorkflowStatus.Approved: msg = "Workflow approved successfully."; logMsg = $"Workflow approved by {currentUser.Name} on {instance.Node.Name} [{instance.NodeId}]"; if (instance.ScheduledDate.HasValue) { string scheduled = $" Page scheduled for {typeDescription} at {instance.ScheduledDate.Value.ToString("dd MMM yyyy", CultureInfo.CurrentCulture)}"; msg += scheduled; logMsg += scheduled; } else { msg += $" Page has been {typeDescriptionPast.ToLower()}"; } break; } Log.Info(logMsg); _hubContext.Clients.All.TaskApproved( _tasksService.ConvertToWorkflowTaskList(instance.TaskInstances.ToList(), instance: instance)); if (model.Offline) { UmbracoContext.Security.ClearCurrentLogin(); } return(Json(new { message = msg, status = 200, notifications = NotificationHelpers.MapEventMessagesToNotifications(process.EventMessages) }, ViewHelpers.CamelCase)); } catch (UmbracoOperationFailedException e) { string msg = $"A Publishing failure occurred processing the approval on {instance.Node.Name} [{instance.Node.Id}]"; Log.Error(msg, e); return(Json(new { message = msg, status = 200, isUmbracoOperationError = true, notifications = NotificationHelpers.MapEventMessagesToNotifications(process.EventMessages) } , ViewHelpers.CamelCase)); } catch (Exception ex) { string msg = $"An error occurred processing the approval on {instance.Node.Name} [{instance.Node.Id}]"; Log.Error(msg, ex); return(Content(HttpStatusCode.InternalServerError, ViewHelpers.ApiException(ex, msg))); } }