Class WorkflowStateHelper

java.lang.Object
de.xima.fc.workflow.designer.helper.WorkflowStateHelper

public final class WorkflowStateHelper extends Object
Helper methods for creating and modifying a WorkflowStateListModel, used by the WorkflowStateBean.
Since:
7.0.0
Author:
XIMA MEDIA GmbH
  • Method Details

    • createNewState

      public static WorkflowStateModel createNewState(WorkflowStateListModel stateListModel, Locale locale)
      Creates a new state with the defaults and no authenticators. Makes sure to assign a name that does not exist yet.
      Parameters:
      stateListModel - State list model with all available states for generating a new unique name.
      locale - Locale to use for localizing the state name and description.
      Returns:
      The newly created state.
    • createNewState

      public static WorkflowStateModel createNewState(WorkflowStateListModel stateListModel, Locale locale, String targetName, Consumer<WorkflowState> configurator)
      Creates a new state with the defaults and no authenticators. Makes sure to assign a name that does not exist yet.
      Parameters:
      stateListModel - State list model with all available states for generating a new unique name.
      locale - Locale to use for localizing the state name and description.
      targetName - The desired target name for the new state. When null or empty, a default name is generated.
      configurator - Additional options to set on the new state.
      Returns:
      The newly created state.
    • createStateListModel

      public static WorkflowStateListModel createStateListModel(IBaseWorkflowEnvironmentData env)
      Reads the available states from the database and creates the initial state model.
      Parameters:
      env - Environment data with the project and workflow version.
      Returns:
      The newly create state list model with the states from the database.
    • deleteState

      Parameters:
      env - Workflow designer context data.
      modelBean - Model bean with the current set of workflow states.
      provider - Provider to use for accessing workflow designer context data.
      item - Item corresponding to a EWorkflowNodeType.FC_CHANGE_STATE with the state to delete.
      Returns:
      The state that was deleted, or null when no state to delete could be found.
      Throws:
      StateReferencedByFormRecordException - When the state is still used by a form record.
      StateReferencedByElementsException - When the state is still used in the configuration of a workflow node or trigger.
    • dispatchAddStateEvent

      public static void dispatchAddStateEvent(DesignerPageBean designerPageBean, WorkflowStateListModel stateListModel, WorkflowStateModel addedState, boolean immediate)
    • dispatchChangedStateEvent

      public static void dispatchChangedStateEvent(DesignerPageBean designerPageBean, WorkflowStateListModel stateListModel, WorkflowStateModel state, String property)
    • dispatchDeleteStateEvent

      public static void dispatchDeleteStateEvent(DesignerPageBean designerPageBean, WorkflowStateModel deletedState)
    • dispatchStateListUpdatedEvent

      public static void dispatchStateListUpdatedEvent(DesignerPageBean designerPageBean, WorkflowStateListModel stateListModel)
    • getStatesByName

      public static List<WorkflowStateModel> getStatesByName(WorkflowStateListModel stateListModel, String stateName, boolean includeDeleted)
      Parameters:
      stateListModel - State list model to search in.
      stateName - Name to search for.
      includeDeleted - true to include states that are scheduled for deletion, false to only return states that still exist.
      Returns:
      All elements in WorkflowStateListModel.getStates() with the given name; or empty list when no such elements exist.
    • insertState

      public static void insertState(IBaseWorkflowEnvironmentData env, WorkflowModelBean modelBean, IWorkflowProvider provider, WorkflowStateModel newState)
      Parameters:
      env - Workflow designer context data.
      modelBean - Model bean with the current set of workflow states.
      provider - Provider to use for accessing workflow designer context data. trigger.
      newState - New state to insert at the end of the available states.
    • isDeletable

      public static boolean isDeletable(WorkflowStateListModel stateListModel, IElementPrototypeWrapper<?> item)
      Parameters:
      stateListModel - State list model to use.
      item - Item to check that corresponds to a EWorkflowNodeType.FC_CHANGE_STATE.
      Returns:
      true when the given item refers to a workflow state, and that state can be deleted.
    • isMarkedForDeletetion

      public static boolean isMarkedForDeletetion(WorkflowStateListModel stateListModel, IElementPrototypeWrapper<?> item)
      Parameters:
      stateListModel - State list model to use.
      item - Item to check that corresponds to a EWorkflowNodeType.FC_CHANGE_STATE.
      Returns:
      true if the given state is marked for deletion, false otherwise.
    • isNewState

      public static boolean isNewState(IElementPrototypeWrapper<?> item)
      Parameters:
      item - Item to check that corresponds to a EWorkflowNodeType.FC_CHANGE_STATE.
      Returns:
      true if the given item is a state change prototype for a new state.
    • isRestorable

      public static boolean isRestorable(WorkflowStateListModel stateListModel, IElementPrototypeWrapper<?> item)
      Parameters:
      stateListModel - State list model to use.
      item - Item to check that corresponds to a EWorkflowNodeType.FC_CHANGE_STATE.
      Returns:
      true if the given state was marked for deletion and can be restored (undeleted), false otherwise.
    • isStateListSavable

      public static boolean isStateListSavable(WorkflowStateListModel stateListModel, IWorkflowProvider provider)
      Check whether the given states are not necessarily valid, but not in such a way that they cannot be saved in the database. That is, checks that the states do not violate any unique constraints etc.
      Parameters:
      stateListModel - State list model to check.
      provider - Current provider for accessing workflow designer context data.
      Returns:
      true if the states can be saved in the database, false otherwise.
    • removeStatesQueuedForDeletion

      public static void removeStatesQueuedForDeletion(WorkflowStateListModel stateListModel)
      Removes all states that were marked for deletion.
      Parameters:
      stateListModel - State list model with the states to clear.
    • restoreState

      public static WorkflowStateModel restoreState(IBaseWorkflowEnvironmentData env, WorkflowModelBean modelBean, IWorkflowProvider provider, IElementPrototypeWrapper<?> item)
      Parameters:
      env - Workflow designer context data.
      modelBean - Model bean with the states.
      provider - Provider for accessing workflow designer context data.
      item - Item corresponding to a EWorkflowNodeType.FC_CHANGE_STATE to restore.
      Returns:
      The state that was restored, or null when no state was found for the given item.
    • mergeWorkflowStates

      public static List<WorkflowStateModel> mergeWorkflowStates(IBaseWorkflowEnvironmentData env, ProcessModel process, Map<ElementKey,com.alibaba.fastjson.JSONObject> paramsMap, List<WorkflowState> oldStates, List<WorkflowStateModel> newStates)
      Used when a backup is loaded. Compares the existing states against the new states from the backup. Attempts to match the existing states to the new states, so references to form records etc. are preserved. Makes sure to preserve existing states that are still referenced by a form record. When a new state is mapped to an existing state, the ID and UUID of the new state is set to the ID and UUID of the old state. In that case, this method also updates the references to that state in workflow nodes and triggers of the given process model.
      Parameters:
      env - Current environment data.
      process - New process model that is to be loaded.
      paramsMap - New custom params map for the model to be loaded.
      oldStates - Existing (persisted) workflow states.
      newStates - New state to be loaded.
      Returns:
      The new list of states that should be used.