This chapter describes the usage of Stardust API to abort and start subprocesses:
The
WorkflowService
provides a method spawnPeerProcessInstance, which allows to abort the
originating process and start a peer process.
The user should have the right to abort the originating process if the abortProcessInstance
parameter is set to true, otherwise an IllegalArgumentException occurs.
Also, the peer process should be a startable process.
public ProcessInstance spawnPeerProcessInstance(long processInstanceOid,
String spawnProcessID, SpawnOptions options) throws IllegalOperationException,
ObjectNotFoundException, InvalidArgumentException, ConcurrencyException;
Parameters are the following:
processInstanceOid - The OID of the process to spawn from.spawnProcessID - The ID of the process definition to spawn as a new root process.
Note that you should use the fully qualified process ID to make sure the process is spawned in the correct model
version.options - Specify the action to be taken with the originating process instance. Spawn mode options
are KEEP, ABORT and HALT.copyData - Defines if data of the parent process definition should be copied to the spawned process.data - Contains data IDs as key set and corresponding data values to be set as values.abortProcessInstance - whether the originating process instance should be aborted. Currently has to be true.comment - Allows to specify a comment for the link that is created.The required permission to execute this method is spawnPeerProcessInstance.
You can use a generalized implementation of this method in case you like to switch between versions of a process definition and perform relocation in the same step. Refer to the next chapter Relocating Activities for details.
The following code demonstrates how to spawn to a process with ID targetProcId in model ProcessModel from a process instance with OID orgProcInstOID. The options parameter comprises the following options:
ABORT, to determine that the originating process instance
(with OID orgProcInstOID) should be aborted
DataCopyOptions dataCopyOptions = new DataCopyOptions(true, null, null, true);
ProcessInstance pi;
SpawnOptions options;
options = new SpawnOptions(null, SpawnMode.ABORT, linkComment, dataCopyOptions);
pi = serviceFactoryUtils.getWorkflowService().spawnPeerProcessInstance(orgProcInstOID, {ProcessModel}targetProcId, options);
Note that we use the fully qualified process id for targetProcId to make sure the process is spawned in the correct model version.
Using the ProcessInstanceQuery class, you can find process instances to which a process instance is linked
to via the given link type(s) and direction.
public class ProcessInstanceQuery extends Query
{
...
/**
* Creates a query for finding process instances the given process instance is linked to via the given link type(s) and direction.
*
* @param piOid the OID of the process instance the query should be executed for
* @param direction the direction of the links that should be taken into account when determining the linked process instances
* @param linkType the link types that should be taken into account when determining the linked process instances
* @return ...
*/
public static ProcessInstanceQuery findLinked(long processInstanceOid, LinkDirection direction, String ... linkType);
}
To specify the direction, use ProcessInstanceDetailsOptions
public enum LinkDirection
{
TO,
FROM,
TO_FROM;
}
To view the linked processes and their details, you need to specify the ProcessInstanceDetailsPolicy and the subsequent enum class ProcessInstanceDetailsOptions.
public enum ProcessInstanceDetailsOptions
{
...
/**
* The process instance details will contain information about the linked process instances.
*/
WITH_LINK_INFO
}
Note that when using the API to abort and start a process, you may get a ConcurrencyException.
In that case, wait for sometime and retry the API call.