Class WorkflowInstanceService


  • @Component
    public class WorkflowInstanceService
    extends Object
    Service for managing workflow instances.
    • Method Detail

      • getWorkflowInstance

        public WorkflowInstance getWorkflowInstance​(long id,
                                                    Set<WorkflowInstanceInclude> includes,
                                                    Long maxActions)
        Return the workflow instance matching the given id.
        Parameters:
        id - Workflow instance id.
        includes - Set of properties to be loaded.
        maxActions - Maximum number of actions to be loaded.
        Returns:
        The workflow instance.
        Throws:
        NflowNotFoundException - If workflow instance is not found.
      • getWorkflowInstance

        public WorkflowInstance getWorkflowInstance​(long id,
                                                    Set<WorkflowInstanceInclude> includes,
                                                    Long maxActions,
                                                    boolean queryArchive)
        Return the workflow instance matching the given id.
        Parameters:
        id - Workflow instance id.
        includes - Set of properties to be loaded.
        maxActions - Maximum number of actions to be loaded.
        queryArchive - Query archive tables if not found from main tables.
        Returns:
        The workflow instance
        Throws:
        EmptyResultDataAccessException - if not found
      • insertWorkflowInstance

        public long insertWorkflowInstance​(WorkflowInstance instance)
        Insert the workflow instance to the database and return the id of the instance. If the instance already exists, return the id of the existing instance.
        Parameters:
        instance - The workflow instance to be inserted.
        Returns:
        The id of the inserted or existing workflow instance.
      • updateWorkflowInstance

        @Transactional
        public boolean updateWorkflowInstance​(WorkflowInstance instance,
                                              WorkflowInstanceAction action)
        Update the workflow instance in the database if it is currently not running, and insert the workflow instance action. If the state of the instance is not null, the status of the instance is updated based on the new state. If the state of the instance is null, neither state nor status are updated.
        Parameters:
        instance - The instance to be updated.
        action - The action to be inserted.
        Returns:
        True if the update was successful, false otherwise.
      • wakeupWorkflowInstance

        @Transactional
        public boolean wakeupWorkflowInstance​(long id,
                                              List<String> expectedStates)
        Wake up the workflow instance matching the given id if it is in one of the expected states.
        Parameters:
        id - Workflow instance id.
        expectedStates - The expected states, empty for any.
        Returns:
        True if the instance was woken up, false otherwise.
      • listWorkflowInstances

        public Collection<WorkflowInstance> listWorkflowInstances​(QueryWorkflowInstances query)
        Return workflow instances matching the given query.
        Parameters:
        query - The query parameters.
        Returns:
        Matching workflow instances, or empty collection if none found.
      • listWorkflowInstancesAsStream

        public Stream<WorkflowInstance> listWorkflowInstancesAsStream​(QueryWorkflowInstances query)
        Return workflow instances matching the given query.
        Parameters:
        query - The query parameters.
        Returns:
        Matching workflow instances as Stream. The stream does not need to be closed.
      • getSignal

        public Optional<Integer> getSignal​(long workflowInstanceId)
        Return current signal value for given workflow instance.
        Parameters:
        workflowInstanceId - Workflow instance id.
        Returns:
        Current signal value.
      • setSignal

        public boolean setSignal​(long workflowInstanceId,
                                 Optional<Integer> signal,
                                 String reason,
                                 WorkflowInstanceAction.WorkflowActionType actionType)
        Set signal value for given workflow instance.
        Parameters:
        workflowInstanceId - Workflow instance id.
        signal - New value for the signal.
        reason - The reason for setting the signal.
        actionType - The type of workflow action that is stored to instance actions.
        Returns:
        True when signal was set, false otherwise.
      • hasUnfinishedChildWorkflows

        public boolean hasUnfinishedChildWorkflows​(long workflowInstanceId)
        Return true if this workflow instance has unfinished child workflow instances.
        Parameters:
        workflowInstanceId - The parent workflow instance id.
        Returns:
        True if the workflow instance has unfinished child workflow instances, false otherwise.