Class WorkflowEngine
- java.lang.Object
-
- com.orchestranetworks.workflow.WorkflowEngine
-
public final class WorkflowEngine extends Object
Represents the workflow engine and offers some administration functionalities.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
allocateWorkItem(WorkItemKey aKey, UserReference aUser)
Allocates the specified work item to the specified user.void
allocateWorkItemToMyself(WorkItemKey aWorkItemKey)
Allocates a work item to the current user.void
cleanHistory(ProcessInstanceKey processInstanceKey)
Deletes the data in history for workflows terminated for a givenProcessInstanceKey
.void
cleanHistory(Date aDate)
Deletes the data in history for workflows terminated from a given date.SessionInteraction
createOrOpenInteraction(WorkItemKey aWorkItemKey)
Creates or opens the interaction associated with the specified work item.void
deallocateWorkItem(WorkItemKey aKey)
Deallocates the specified work item.void
forceTerminationWithoutCleaning(ProcessInstanceKey aKey)
Terminates the specified process instance without deleting it.List<UserTask.WorkItem>
getAllWorkItems()
Returns all the work items.static WorkflowEngine
getFromProcedureContext(ProcedureContext aContext)
static WorkflowEngine
getFromRepository(Repository aRepository, Session aSession)
Creates a workflow engine from a repository and, optionally, a session.static WorkflowEngine
getFromServiceContext(ServiceContext aContext)
Deprecated.static WorkflowEngine
getFromUserServiceContext(UserServiceRequest aContext)
Creates a workflow engine from a user service context.SessionInteraction.Specification
getInteractionSpecification(WorkItemKey aWorkItemKey)
Returns the specification of a session interaction.ProcessInstance
getProcessInstance(ProcessInstanceKey aProcessInstanceKey)
Returns information about the specified workflow.List<ProcessInstanceComment>
getProcessInstanceComments(ProcessInstanceKey aProcessInstanceKey)
Returns the comments of the specified workflow.ProcessInstanceHistory
getProcessInstanceHistory(ProcessInstanceKey aProcessInstanceKey)
Returns the history of the specified workflow.List<ProcessInstanceKey>
getProcessInstanceKeys(PublishedProcessKey aKey)
Returns a list containing all existing process instance keys for the specified publication key.List<ProcessInstanceKey>
getProcessInstanceKeys(String aLaunchingPublicationName)
Returns a list containing all existing workflow keys for the specified launching publication name.List<ProcessInstanceKey>
getProcessInstanceKeysForDataContextVariable(PublishedProcessKey publishedProcessKey, String varName, String varValue)
This method selects process instances which: are associated with the specified published process key, have in their current data context the specified variable and equal to the specified value. The result is a list containing all the process instance keys.List<ProcessInstanceKey>
getProcessInstanceKeysFromHistory(PublishedProcessKey aKey)
Returns a list containing all the process instance keys for the specified publication key, including deleted processes.List<ProcessInstanceKey>
getProcessInstanceKeysFromHistory(String aLaucnhingPublicationName)
Returns a list containing all existing workflow keys for the specified launching publication name, including deleted workflows.ProcessLauncher
getProcessLauncher(PublishedProcessKey aKey)
Returns a launcher to create workflows from the specified publication.List<PublishedProcessKey>
getPublishedKeys()
Returns the enabled publication keys.List<PublishedProcessKey>
getPublishedKeys(boolean onlyEnabled)
Returns the publication keys.PublishedProcess
getPublishedProcess(PublishedProcessKey aPublishProcessKey)
Returns information about the specified workflow publication.UserTask.WorkItem
getWorkItem(WorkItemKey aWorkItemKey)
Returns information about the specified work item.List<UserTask.WorkItem>
getWorkItemsAllocatedToUser(UserReference aUser)
Returns all the work items allocated to a user.List<UserTask.WorkItem>
getWorkItemsOfferedToRole(Role aRole)
Returns all the work items offered to a role.List<UserTask.WorkItem>
getWorkItemsOfferedToSession(Session aSession)
Returns all the work items offered to a Session.List<UserTask.WorkItem>
getWorkItemsOfferedToUser(UserReference aUser)
Returns all the work items offered to a user.boolean
isProcessInstanceRunning(ProcessInstanceKey aKey)
Returnstrue
if the specified process instance is running, elsefalse
.boolean
isUserAuthorizedToLaunch(PublishedProcessKey aKey)
Returnstrue
if the user of the current session is authorized to launch a workflow for the specified publication key.boolean
isUserInRoleAdmin(PublishedProcessKey aKey)
Returnstrue
if the user of the current session is the administrator of the process definition associated with the specified publication key.void
reallocateWorkItem(WorkItemKey aKey, UserReference aUser)
Reallocates the specified work item.void
replayCurrentStep(ProcessInstanceKey aKey)
Replays the current step of the specified workflow.WaitTaskResumeResult
resumeWaitTask(WaitTaskResumeMessage aMessage)
Resumes a wait task.void
terminateProcessInstance(ProcessInstanceKey aKey)
Terminates and cleans the specified process instance.
-
-
-
Method Detail
-
getFromRepository
public static WorkflowEngine getFromRepository(Repository aRepository, Session aSession)
Creates a workflow engine from a repository and, optionally, a session.- Parameters:
aRepository
- repository in which the workflow is running.aSession
- optional user session, must only be defined in order to invoke methods that require information about the current user:isUserInRoleAdmin
,allocateWorkItem(WorkItemKey, UserReference)
,deallocateWorkItem(WorkItemKey)
,reallocateWorkItem(WorkItemKey, UserReference)
andterminateProcessInstance
.
-
getFromProcedureContext
public static WorkflowEngine getFromProcedureContext(ProcedureContext aContext)
-
getFromServiceContext
@Deprecated public static WorkflowEngine getFromServiceContext(ServiceContext aContext)
Deprecated.
-
getFromUserServiceContext
public static WorkflowEngine getFromUserServiceContext(UserServiceRequest aContext)
Creates a workflow engine from a user service context.- Since:
- 6.0.0
-
isUserInRoleAdmin
public boolean isUserInRoleAdmin(PublishedProcessKey aKey)
Returnstrue
if the user of the current session is the administrator of the process definition associated with the specified publication key.- Throws:
IllegalStateException
- if the session of the workflow engine isnull
.
-
isUserAuthorizedToLaunch
public boolean isUserAuthorizedToLaunch(PublishedProcessKey aKey)
Returnstrue
if the user of the current session is authorized to launch a workflow for the specified publication key.- Returns:
- a Boolean
- Throws:
IllegalStateException
- if the session of the workflow engine isnull
.- Since:
- 6.0.10
-
getProcessLauncher
public ProcessLauncher getProcessLauncher(PublishedProcessKey aKey)
Returns a launcher to create workflows from the specified publication.- Throws:
IllegalStateException
- if the session of the workflow engine isnull
.
-
forceTerminationWithoutCleaning
public void forceTerminationWithoutCleaning(ProcessInstanceKey aKey)
Terminates the specified process instance without deleting it. Contrary to the methodterminateProcessInstance(ProcessInstanceKey)
, this method does not delete the process instance. It only deletes the objects associated with the current process instance (work items, interactions, sub-workflows).The current user must have the permission to perform the administration action 'Force termination' (unless this method is called from a procedure with all privileges).
This method can only be used in order to force termination of sub-workflows in order to wake up the parent, or to force the termination of a process instance if an error has occurred during normal completion.
- Since:
- 5.5.0
- See Also:
terminateProcessInstance(ProcessInstanceKey)
-
terminateProcessInstance
public void terminateProcessInstance(ProcessInstanceKey aKey)
Terminates and cleans the specified process instance.The current user must have the permissions for the administration action 'Terminate and clean' (unless this method is called from a procedure with all privileges).
- Throws:
IllegalStateException
- if the session of the workflow engine isnull
IllegalArgumentException
- if the process instance to clean is a sub-workflow.- See Also:
forceTerminationWithoutCleaning(ProcessInstanceKey)
-
replayCurrentStep
public void replayCurrentStep(ProcessInstanceKey aKey) throws OperationException
Replays the current step of the specified workflow.This action removes all objects linked to the current step (current work items, interaction, sub-workflows) and restarts it. If an action has already been performed by a user, no rollback is done (for example in the record creation case).
- Parameters:
aKey
- the workflow identifier- Throws:
IllegalStateException
- if the session of the workflow engine isnull
IllegalArgumentException
- if the specified workflow key isnull
.OperationException
- if one of the following occurs:- the user has no permission to replay the step (unless this method is called from a procedure with all privileges),
- the workflow has not been found,
- an unexpected error occurs during the current step restart.
- Since:
- 5.7.1-fix N
-
resumeWaitTask
public WaitTaskResumeResult resumeWaitTask(WaitTaskResumeMessage aMessage) throws OperationException
Resumes a wait task.The resume identifier is required to resume a wait task by a
WaitTaskResumeMessage
.The resumption can fail if:
- the associated workflow has been deleted,
- the resume identifier has not been found,
- the workflow and the associated task are not in a waiting state (if the event has already been received).
In these cases, no exception is thrown, but the
WaitTaskResumeResult
contains the reason of the resumption failure.- Returns:
- a
WaitTaskResumeResult
to indicate if the resumption has failed, and in this case the error reason. - Throws:
OperationException
- If an unexpected error occurs during the wait task resumption.IllegalStateException
- If the session of the workflow engine isnull
.IllegalArgumentException
- If the user is not allowed to resume the wait task (if the user does not belong to the expected profile).- Since:
- 5.6.1
-
allocateWorkItem
public void allocateWorkItem(WorkItemKey aKey, UserReference aUser)
Allocates the specified work item to the specified user.The work item must be in the 'Offered' state, and the current user must have the permission to perform the administration action 'Allocate' (unless this method is called from a procedure with all privileges).
After this method is called, the work item is in the 'Allocated' state.
- Parameters:
aUser
- the new owner of the work item. Even if an offered role is defined for the work item, the workflow engine does not check that the new owner of the work item belongs to the offered role.- Throws:
IllegalStateException
- if the session of the workflow engine isnull
.IllegalArgumentException
- if the work item is not in the 'Offered' state.- See Also:
allocateWorkItemToMyself(WorkItemKey)
-
deallocateWorkItem
public void deallocateWorkItem(WorkItemKey aKey)
Deallocates the specified work item.The work item must be in the 'Allocated' or 'Started' state, and users must be available for allocation. The current user must have the permission to perform the administration action 'Deallocate' (unless this method is called from a procedure with all privileges).
After this method is called, the work item is in the 'Offered' state.
- Throws:
IllegalStateException
- if the session of the workflow engine isnull
.IllegalArgumentException
- if one of the following occurs:- the work item is not in the 'Allocated' or 'Started' state,
- the current user is not allowed for this action.
-
reallocateWorkItem
public void reallocateWorkItem(WorkItemKey aKey, UserReference aUser)
Reallocates the specified work item.The work item must be in the 'Allocated' or 'Started' state, and the current user must have the permission to perform the administration action 'Reallocate' (unless this method is called from a procedure with all privileges).
After this method is called, the work item is in the 'Allocated' state.
- Parameters:
aUser
- the new owner of the work item. No verification is performed on the user. If an offered role is specified, it is not enforced.- Throws:
IllegalStateException
- if one of the following occurs: if the session of the workflow engine isnull
.IllegalArgumentException
- if one of the following occurs:- the work item is not in the 'Allocated' or 'Started' state,
- the current user is not allowed for this action.
-
allocateWorkItemToMyself
public void allocateWorkItemToMyself(WorkItemKey aWorkItemKey) throws OperationException
Allocates a work item to the current user.The work item must be in the offered state, and offered to the current user. After calling this method, the work item will be in the allocated state.
- Throws:
IllegalStateException
- if the session of the workflow engine isnull
.OperationException
- if one of the following occurs:- the work item has not been found,
- the work item is not in the offered state,
- the work item is not offered to the current user.
- Since:
- 5.7.1 fix D
- See Also:
allocateWorkItem(WorkItemKey, UserReference)
-
createOrOpenInteraction
public SessionInteraction createOrOpenInteraction(WorkItemKey aWorkItemKey) throws OperationException
Creates or opens the interaction associated with the specified work item.The work item must be allocated to the current user, and either in the allocated or in the started state. If the work item is in the offered state, first call the
allocateWorkItemToMyself(WorkItemKey)
method (see the work item state diagram).This method does the following:
- If the work item is in the allocated state, it is started.
- If the interaction does not exist, it is created and initialized according to the mapping of the input parameters.
-
Then, if the interaction is associated to an auto-complete service, the
interaction is set in the 'complete' state;
see the
SessionInteraction
life cycle. A custom user service is considered as auto-complete if it has been declared as auto-complete (seeWebComponentDeclarationContext.setAvailableAsWorkflowUserTask(boolean, boolean)
. The following built-in services (or extensions of these services) can be considered as auto-complete too:-
ServiceKey.DEFAULT_SERVICE
if its input parameterdisableAutoComplete
is not equal tofalse
, -
ServiceKey.SELECT_DATASPACE
, -
ServiceKey.MERGE_VIEW
, -
ServiceKey.VALIDATION
, -
ServiceKey.COMPARE
.
-
- Throws:
IllegalStateException
- if: the session of the workflow engine isnull
.OperationException
- if one of the following occurs:- Since:
- 5.7.1 fix D
-
getInteractionSpecification
public SessionInteraction.Specification getInteractionSpecification(WorkItemKey aWorkItemKey)
Returns the specification of a session interaction.Returns
null
if the work item has not been found.- Throws:
IllegalArgumentException
- if the work item key isnull
.- Since:
- 5.8.0
- See Also:
SessionInteraction.getSpecification()
-
getPublishedKeys
public List<PublishedProcessKey> getPublishedKeys()
Returns the enabled publication keys.- Returns:
- a
List
ofPublishedProcessKey
. - See Also:
getPublishedKeys(boolean)
-
getPublishedKeys
public List<PublishedProcessKey> getPublishedKeys(boolean onlyEnabled)
Returns the publication keys.- Parameters:
onlyEnabled
- iftrue
returns only the keys of enabled publications, else returns all keys regardless of the publication state.- Returns:
- a
List
ofPublishedProcessKey
.
-
getPublishedProcess
public PublishedProcess getPublishedProcess(PublishedProcessKey aPublishProcessKey)
Returns information about the specified workflow publication.
-
getProcessInstanceKeys
public List<ProcessInstanceKey> getProcessInstanceKeys(PublishedProcessKey aKey)
Returns a list containing all existing process instance keys for the specified publication key.This method returns only execution data. As a consequence, it does not return deleted processes.
-
getProcessInstanceKeys
public List<ProcessInstanceKey> getProcessInstanceKeys(String aLaunchingPublicationName)
Returns a list containing all existing workflow keys for the specified launching publication name.This method returns all workflows which have been launched with the specified publication name (initial or current publication name), including workflows associated with a disabled publication.
This method returns only execution data. As a consequence, it does not return deleted processes.
- Parameters:
aLaunchingPublicationName
- publication name with which workflows have been launched.- Throws:
IllegalArgumentException
- if the publication is not defined.- Since:
- 5.9.0
- See Also:
getProcessInstanceKeysFromHistory(String)
-
getProcessInstanceKeysFromHistory
public List<ProcessInstanceKey> getProcessInstanceKeysFromHistory(PublishedProcessKey aKey)
Returns a list containing all the process instance keys for the specified publication key, including deleted processes.Unlike
getProcessInstance(ProcessInstanceKey)
, this method will query directly the workflow history.- Parameters:
aKey
- a specified PublishedProcessKey- Throws:
IllegalArgumentException
- if the specifiedPublishedProcessKey
isnull
.- Since:
- 5.8.1
- See Also:
getProcessInstanceKeys(PublishedProcessKey)
-
getProcessInstanceKeysFromHistory
public List<ProcessInstanceKey> getProcessInstanceKeysFromHistory(String aLaucnhingPublicationName) throws IllegalArgumentException, OperationException
Returns a list containing all existing workflow keys for the specified launching publication name, including deleted workflows.This method returns all workflows from history which have been launched with the specified publication name (initial or current publication name), including workflows associated with a disabled publication.
This method will query directly the workflow history.
- Parameters:
aLaucnhingPublicationName
- publication name with which workflows have been launched.- Throws:
IllegalArgumentException
- if the publication is not defined.OperationException
- Since:
- 5.9.0
- See Also:
getProcessInstanceKeys(String)
-
getProcessInstance
public ProcessInstance getProcessInstance(ProcessInstanceKey aProcessInstanceKey)
Returns information about the specified workflow.
-
getProcessInstanceHistory
public ProcessInstanceHistory getProcessInstanceHistory(ProcessInstanceKey aProcessInstanceKey) throws OperationException
Returns the history of the specified workflow.- Parameters:
aProcessInstanceKey
- the key of a workflow, which can represent a completed workflow.- Throws:
OperationException
- Since:
- 5.4.1
-
getProcessInstanceComments
public List<ProcessInstanceComment> getProcessInstanceComments(ProcessInstanceKey aProcessInstanceKey)
Returns the comments of the specified workflow.The result includes comments of the sub-workflows of the specified workflow in a recursive way. The list of comments is sorted by descending date.
If the associated workflow has not been found, returns an empty list.
- Throws:
IllegalArgumentException
- if the process instance key isnull
.- Since:
- 5.8.0
-
getWorkItem
public UserTask.WorkItem getWorkItem(WorkItemKey aWorkItemKey)
Returns information about the specified work item.- Since:
- 5.5.1
-
getWorkItemsOfferedToRole
public List<UserTask.WorkItem> getWorkItemsOfferedToRole(Role aRole)
Returns all the work items offered to a role.Only returns work items in the 'Offered' state.
- Returns:
- a
List
ofUserTask.WorkItem
. - Since:
- 5.4.1
-
getWorkItemsAllocatedToUser
public List<UserTask.WorkItem> getWorkItemsAllocatedToUser(UserReference aUser)
Returns all the work items allocated to a user.The returned work items can be in the following states:
- 'Allocated',
- 'Started': if the user has already opened the work item.
- Returns:
- a
List
ofUserTask.WorkItem
. - Since:
- 5.4.1
-
getWorkItemsOfferedToUser
public List<UserTask.WorkItem> getWorkItemsOfferedToUser(UserReference aUser)
Returns all the work items offered to a user. Only the work items in the 'Offered' state are returned.It only returns the work items in the 'Offered' state.
This method returns an empty list for the system user.
- Returns:
- a
List
ofUserTask.WorkItem
. - Throws:
IllegalArgumentException
- if the user is null.- Since:
- 5.4.1
- See Also:
Session.isSystemUser()
-
getWorkItemsOfferedToSession
public List<UserTask.WorkItem> getWorkItemsOfferedToSession(Session aSession)
Returns all the work items offered to a Session.It only returns the work items in the 'Offered' state.
- Returns:
- a
List
ofUserTask.WorkItem
. - Since:
- 5.5.1
-
getAllWorkItems
public List<UserTask.WorkItem> getAllWorkItems()
Returns all the work items.All the current work items are returned whatever their state: they can be offered, allocated, started, completed or in error.
- Returns:
- a
List
ofUserTask.WorkItem
. - Since:
- 5.4.1
-
getProcessInstanceKeysForDataContextVariable
public List<ProcessInstanceKey> getProcessInstanceKeysForDataContextVariable(PublishedProcessKey publishedProcessKey, String varName, String varValue)
This method selects process instances which:- are associated with the specified published process key,
- have in their current data context the specified variable and equal to the specified value.
-
isProcessInstanceRunning
public boolean isProcessInstanceRunning(ProcessInstanceKey aKey)
Returnstrue
if the specified process instance is running, elsefalse
.
-
cleanHistory
public void cleanHistory(ProcessInstanceKey processInstanceKey) throws OperationException
Deletes the data in history for workflows terminated for a givenProcessInstanceKey
.The method will also remove recursively all history data related to the associated sub-workflows.
- Parameters:
processInstanceKey
- a specified ProcessInstanceKey- Throws:
IllegalArgumentException
- if the specifiedProcessInstanceKey
is null.OperationException
- if one of the following occurs:- no workflow with the specified
ProcessInstanceKey
has been found, - the workflow with the specified
ProcessInstanceKey
is not a main workflow, - the workflow with the specified
ProcessInstanceKey
has not been removed from execution.
- no workflow with the specified
- Since:
- 5.8.1
- See Also:
terminateProcessInstance(ProcessInstanceKey)
,cleanHistory(Date)
-
cleanHistory
public void cleanHistory(Date aDate) throws OperationException
Deletes the data in history for workflows terminated from a given date.This method deletes only workflows which meet the following criteria:
- the workflow is in the terminated state,
- the workflow has been terminated at the specified date or before the specified date,
- the associated execution data has been cleaned.
The workflows which does not meet these criteria are ignored.
The method will also remove recursively all history data related to the associated sub-workflows.
Warning: it may take a long time to complete and as a result, all workflow executions might also be affected. For a more targeted clean, please consider using
cleanHistory(ProcessInstanceKey)
.- Parameters:
aDate
- the date to compare at the termination date of workflows. Only workflows with a terminated date lower than or equal to the specified date will be deleted.- Throws:
IllegalArgumentException
- if the specified date is null.OperationException
- Since:
- 5.8.1
- See Also:
cleanHistory(ProcessInstanceKey)
,terminateProcessInstance(ProcessInstanceKey)
-
-