private bool WasDraftSubmitted(Entities.Workflow workflow, int currentStateId) { var isDirectPublishWorkflow = workflow.IsSystem && workflow.States.Count() == 1; var draftSubmitted = workflow.FirstState.StateID != currentStateId; return(!(isDirectPublishWorkflow || !draftSubmitted)); }
private void CreateContentApprovalWorkflow(int portalId) { var workflow = new Entities.Workflow { WorkflowName = Localization.GetString("DefaultWorkflowName"), Description = Localization.GetString("DefaultWorkflowDescription"), WorkflowKey = ContentAprovalWorkflowKey, IsSystem = true, PortalID = portalId, }; this._workflowRepository.AddWorkflow(workflow); var state = this.GetDraftStateDefinition(1); state.WorkflowID = workflow.WorkflowID; this._workflowStateRepository.AddWorkflowState(state); state = this.GetReadyForReviewStateDefinition(2); state.WorkflowID = workflow.WorkflowID; this._workflowStateRepository.AddWorkflowState(state); state = this.GetPublishedStateDefinition(3); state.WorkflowID = workflow.WorkflowID; this._workflowStateRepository.AddWorkflowState(state); }
private UserInfo GetUserThatHaveStartedOrSubmittedDraftState(Entities.Workflow workflow, ContentItem contentItem, StateTransaction stateTransaction) { bool wasDraftSubmitted = WasDraftSubmitted(workflow, stateTransaction.CurrentStateId); if (wasDraftSubmitted) { return(GetSubmittedDraftStateUser(contentItem)); } return(GetStartedDraftStateUser(contentItem)); }
private string ReplaceNotificationTokens(string text, Entities.Workflow workflow, ContentItem item, WorkflowState state, int userId, string comment = "") { var user = _userController.GetUserById(workflow.PortalID, userId); var datetime = DateTime.UtcNow; var result = text.Replace("[USER]", user != null ? user.DisplayName : ""); result = result.Replace("[DATE]", datetime.ToString("F", CultureInfo.CurrentCulture)); result = result.Replace("[STATE]", state != null ? state.StateName : ""); result = result.Replace("[WORKFLOW]", workflow.WorkflowName); result = result.Replace("[CONTENT]", item != null ? item.ContentTitle : ""); result = result.Replace("[COMMENT]", !String.IsNullOrEmpty(comment) ? comment : ""); return(result); }
private void CreateDirectPublishWorkflow(int portalId) { var workflow = new Entities.Workflow { WorkflowName = Localization.GetString("DefaultDirectPublishWorkflowName"), Description = Localization.GetString("DefaultDirectPublishWorkflowDescription"), WorkflowKey = DirectPublishWorkflowKey, IsSystem = true, PortalID = portalId, }; this._workflowRepository.AddWorkflow(workflow); var publishedState = this.GetPublishedStateDefinition(1); publishedState.WorkflowID = workflow.WorkflowID; this._workflowStateRepository.AddWorkflowState(publishedState); }
public void AddWorkflow(Entities.Workflow workflow) { _workflowRepository.AddWorkflow(workflow); var firstDefaultState = _systemWorkflowManager.GetDraftStateDefinition(1); var lastDefaultState = _systemWorkflowManager.GetPublishedStateDefinition(2); firstDefaultState.WorkflowID = workflow.WorkflowID; lastDefaultState.WorkflowID = workflow.WorkflowID; _workflowStateRepository.AddWorkflowState(firstDefaultState); _workflowStateRepository.AddWorkflowState(lastDefaultState); workflow.States = new List <WorkflowState> { firstDefaultState, lastDefaultState }; }
private WorkflowState GetNextWorkflowState(Entities.Workflow workflow, int stateId) { WorkflowState nextState = null; var states = workflow.States.OrderBy(s => s.Order); int index; // locate the current state for (index = 0; index < states.Count(); index++) { if (states.ElementAt(index).StateID == stateId) { break; } } index = index + 1; if (index < states.Count()) { nextState = states.ElementAt(index); } return(nextState ?? workflow.FirstState); }
private void CreateSaveDraftWorkflow(int portalId) { var workflow = new Entities.Workflow { WorkflowName = Localization.GetString("DefaultSaveDraftWorkflowName"), Description = Localization.GetString("DefaultSaveDraftWorkflowDescription"), WorkflowKey = SaveDraftWorkflowKey, IsSystem = true, PortalID = portalId }; _workflowRepository.AddWorkflow(workflow); var state = GetDraftStateDefinition(1); state.WorkflowID = workflow.WorkflowID; _workflowStateRepository.AddWorkflowState(state); state = GetPublishedStateDefinition(2); state.WorkflowID = workflow.WorkflowID; _workflowStateRepository.AddWorkflowState(state); }
public void DeleteWorkflow(Entities.Workflow workflow) { var workflowToDelete = _workflowRepository.GetWorkflow(workflow.WorkflowID); if (workflowToDelete == null) { return; } if (workflowToDelete.IsSystem) { throw new WorkflowInvalidOperationException(Localization.GetString("SystemWorkflowDeletionException", Localization.ExceptionsResourceFile)); } var usageCount = GetWorkflowUsageCount(workflowToDelete.WorkflowID); if (usageCount > 0) { throw new WorkflowInvalidOperationException(Localization.GetString("WorkflowInUsageException", Localization.ExceptionsResourceFile)); } _workflowRepository.DeleteWorkflow(workflowToDelete); }
private WorkflowState GetPreviousWorkflowState(Entities.Workflow workflow, int stateId) { WorkflowState previousState = null; var states = workflow.States.OrderBy(s => s.Order); int index; if (workflow.FirstState.StateID == stateId) { return(workflow.LastState); } // locate the current state for (index = 0; index < states.Count(); index++) { if (states.ElementAt(index).StateID == stateId) { previousState = states.ElementAt(index - 1); break; } } return(previousState ?? workflow.LastState); }
public void UpdateWorkflow(Entities.Workflow workflow) { _workflowRepository.UpdateWorkflow(workflow); }
private void SendNotificationToWorkflowStarter(StateTransaction stateTransaction, Entities.Workflow workflow, ContentItem contentItem, int starterUserId, WorkflowActionTypes workflowActionType) { try { if (!workflow.FirstState.SendNotification) { return; } var workflowAction = GetWorkflowActionInstance(contentItem, workflowActionType); if (workflowAction == null) { return; } var user = _userController.GetUser(workflow.PortalID, starterUserId); var message = workflowAction.GetActionMessage(stateTransaction, workflow.FirstState); var notification = GetNotification(GetWorkflowNotificationContext(contentItem, workflow.FirstState), stateTransaction, message, ContentWorkflowNotificatioStartWorkflowType); _notificationsController.SendNotification(notification, workflow.PortalID, null, new[] { user }); } catch (Exception ex) { Services.Exceptions.Exceptions.LogException(ex); } }
private void SendNotificationToAuthor(StateTransaction stateTransaction, WorkflowState state, Entities.Workflow workflow, ContentItem contentItem, WorkflowActionTypes workflowActionType) { try { if (!state.SendNotification) { return; } var user = GetUserThatHaveStartedOrSubmittedDraftState(workflow, contentItem, stateTransaction); if (user == null) { //Services.Exceptions.Exceptions.LogException(new WorkflowException(Localization.GetExceptionMessage("WorkflowAuthorNotFound", "Author cannot be found. Notification won't be sent"))); return; } if (user.UserID == stateTransaction.UserId) { return; } var workflowAction = GetWorkflowActionInstance(contentItem, workflowActionType); if (workflowAction == null) { return; } var message = workflowAction.GetActionMessage(stateTransaction, state); var notification = GetNotification(GetWorkflowNotificationContext(contentItem, state), stateTransaction, message, ContentWorkflowNotificationNoActionType); _notificationsController.SendNotification(notification, workflow.PortalID, null, new[] { user }); } catch (Exception ex) { Services.Exceptions.Exceptions.LogException(ex); } }
private void SendNotificationToWorkflowStarter(StateTransaction stateTransaction, Entities.Workflow workflow, ContentItem contentItem, int starterUserId, WorkflowActionTypes workflowActionType) { try { var workflowAction = GetWorkflowActionInstance(contentItem, workflowActionType); if (workflowAction == null) { return; } var user = _userController.GetUser(workflow.PortalID, starterUserId); var message = workflowAction.GetActionMessage(stateTransaction, workflow.FirstState); var notification = new Notification { NotificationTypeID = _notificationsController.GetNotificationType(ContentWorkflowNotificatioStartWorkflowType).NotificationTypeId, Subject = message.Subject, Body = message.Body, IncludeDismissAction = true, SenderUserID = stateTransaction.UserId, Context = GetWorkflowNotificationContext(contentItem, workflow.FirstState) }; _notificationsController.SendNotification(notification, workflow.PortalID, null, new[] { user }); } catch (Exception ex) { Services.Exceptions.Exceptions.LogException(ex); } }