@Named public class BusinessProcess extends Object implements Serializable
BusinessProcess
bean
with a particular Execution / Task, then perform some changes (retrieve / set process
variables) and then end the unit of work. This bean makes sure that our changes are
only "flushed" to the process engine when we successfully complete the unit of work.
A typical usage scenario might look like this:conversation.begin(); ... businessProcess.setVariable("billingId", "1"); // setting variables before starting the process businessProcess.startProcessByKey("billingProcess"); conversation.end();2nd unit of work ("perform a user task"):
conversation.begin(); businessProcess.startTask(id); // now we have associated a task with the current conversation ... // this allows us to retrieve and change process variables // and @BusinessProcessScoped beans businessProcess.setVariable("billingDetails", "someValue"); // these changes are cached in the conversation ... businessProcess.completeTask(); // now all changed process variables are flushed conversation.end();NOTE: in the absence of a conversation, (non faces request, i.e. when processing a JAX-RS, JAX-WS, JMS, remote EJB or plain Servlet requests), the
BusinessProcess
bean associates with the
current Request (see @RequestScoped
).
NOTE: in the absence of a request, ie. when the JobExecutor accesses
@BusinessProcessScoped
beans, the execution is associated with the
current thread.Constructor and Description |
---|
BusinessProcess() |
Modifier and Type | Method and Description |
---|---|
protected void |
assertCommandContextNotActive() |
protected void |
assertExecutionAssociated() |
protected void |
assertTaskAssociated() |
void |
associateExecutionById(String executionId)
Associate with the provided execution.
|
void |
completeTask()
Completes the current UserTask, see
TaskService.complete(String)
Ends the current unit of work (flushes changes to process variables set
using setVariable(String, Object) or made on
@BusinessProcessScoped beans). |
void |
completeTask(boolean endConversation) |
void |
flushVariableCache()
This method allows to flush the cached variables to the Task or Execution.
|
Map<String,Object> |
getAndClearVariableCache()
Get the map of cached variables and clear the internal variable cache.
|
Map<String,Object> |
getAndClearVariableLocalCache()
Get the map of local cached variables and clear the internal variable cache.
|
Execution |
getExecution()
Returns the currently associated execution or 'null'
|
String |
getExecutionId() |
ProcessInstance |
getProcessInstance()
Returns the
ProcessInstance currently associated or 'null' |
String |
getProcessInstanceId()
Returns the id of the currently associated process instance or 'null'
|
Task |
getTask()
Returns the currently associated
Task or 'null' |
String |
getTaskId()
Returns the id of the task associated with the current conversation or 'null'.
|
<T> T |
getVariable(String variableName) |
Map<String,Object> |
getVariableCache()
Get a copy of the map of cached variables.
|
<T> T |
getVariableLocal(String variableName) |
Map<String,Object> |
getVariableLocalCache()
Get a copy of the map of local cached variables.
|
boolean |
isAssociated()
returns true if an
Execution is associated. |
boolean |
isTaskAssociated() |
void |
saveTask()
Save the currently associated task.
|
void |
setExecution(Execution execution) |
protected void |
setExecutionId(String executionId) |
void |
setTask(Task task) |
void |
setTaskId(String taskId) |
void |
setVariable(String variableName,
Object value)
Set a value for a process variable.
|
void |
setVariableLocal(String variableName,
Object value)
Set a value for a local process variable.
|
void |
signalExecution()
Signals the current execution, see
RuntimeService.signal(String)
Ends the current unit of work (flushes changes to process variables set
using setVariable(String, Object) or made on
@BusinessProcessScoped beans). |
void |
signalExecution(boolean endConversation) |
ProcessInstance |
startProcessById(String processDefinitionId) |
ProcessInstance |
startProcessById(String processDefinitionId,
Map<String,Object> variables) |
ProcessInstance |
startProcessById(String processDefinitionId,
String businessKey) |
ProcessInstance |
startProcessById(String processDefinitionId,
String businessKey,
Map<String,Object> variables) |
ProcessInstance |
startProcessByKey(String key) |
ProcessInstance |
startProcessByKey(String key,
Map<String,Object> variables) |
ProcessInstance |
startProcessByKey(String key,
String businessKey) |
ProcessInstance |
startProcessByKey(String key,
String businessKey,
Map<String,Object> variables) |
ProcessInstance |
startProcessByMessage(String messageName) |
ProcessInstance |
startProcessByMessage(String messageName,
Map<String,Object> processVariables) |
ProcessInstance |
startProcessByMessage(String messageName,
String businessKey,
Map<String,Object> processVariables) |
Task |
startTask(String taskId)
Associates the task with the provided taskId with the current conversation.
|
Task |
startTask(String taskId,
boolean beginConversation) |
void |
stopTask()
Stop working on a task.
|
void |
stopTask(boolean endConversation)
Stop working on a task.
|
public ProcessInstance startProcessById(String processDefinitionId)
public ProcessInstance startProcessById(String processDefinitionId, String businessKey)
public ProcessInstance startProcessById(String processDefinitionId, Map<String,Object> variables)
public ProcessInstance startProcessById(String processDefinitionId, String businessKey, Map<String,Object> variables)
public ProcessInstance startProcessByKey(String key)
public ProcessInstance startProcessByKey(String key, String businessKey)
public ProcessInstance startProcessByKey(String key, Map<String,Object> variables)
public ProcessInstance startProcessByKey(String key, String businessKey, Map<String,Object> variables)
public ProcessInstance startProcessByMessage(String messageName)
public ProcessInstance startProcessByMessage(String messageName, Map<String,Object> processVariables)
public ProcessInstance startProcessByMessage(String messageName, String businessKey, Map<String,Object> processVariables)
public void associateExecutionById(String executionId)
executionId
- the id of the execution to associate with.public boolean isAssociated()
Execution
is associated.associateExecutionById(String)
public void signalExecution()
RuntimeService.signal(String)
Ends the current unit of work (flushes changes to process variables set
using setVariable(String, Object)
or made on
@BusinessProcessScoped
beans).ProcessEngineCdiException
- if no execution is currently associatedProcessEngineException
- if the activiti command failspublic void signalExecution(boolean endConversation)
public Task startTask(String taskId)
taskId
- the id of the taskProcessEngineCdiException
- if no such task is foundpublic void completeTask()
TaskService.complete(String)
Ends the current unit of work (flushes changes to process variables set
using setVariable(String, Object)
or made on
@BusinessProcessScoped
beans).ProcessEngineCdiException
- if no task is currently associatedProcessEngineException
- if the activiti command failspublic void completeTask(boolean endConversation)
public boolean isTaskAssociated()
public void saveTask()
ProcessEngineCdiException
- if called from a process engine command or if no Task is currently associated.public void stopTask()
Stop working on a task. Clears the current association.
NOTE: this method does not flush any changes.
flushVariableCache()
prior to calling this method,saveTask()
prior to calling this method.ProcessEngineCdiException
- if called from a process engine command or if no Task is currently associated.public void stopTask(boolean endConversation)
Stop working on a task. Clears the current association.
NOTE: this method does not flush any changes.
flushVariableCache()
prior to calling this method,saveTask()
prior to calling this method.This method allows you to optionally end the current conversation
endConversation
- if true, end current conversation.ProcessEngineCdiException
- if called from a process engine command or if no Task is currently associated.public <T> T getVariable(String variableName)
variableName
- the name of the process variable for which the value is to be
retrievedpublic void setVariable(String variableName, Object value)
variableName
- the name of the process variable for which a value is to be setvalue
- the value to be setpublic Map<String,Object> getAndClearVariableCache()
public Map<String,Object> getVariableCache()
public <T> T getVariableLocal(String variableName)
variableName
- the name of the local process variable for which the value is to be
retrievedpublic void setVariableLocal(String variableName, Object value)
variableName
- the name of the local process variable for which a value is to be setvalue
- the value to be setpublic Map<String,Object> getAndClearVariableLocalCache()
public Map<String,Object> getVariableLocalCache()
public void flushVariableCache()
This method allows to flush the cached variables to the Task or Execution.
TaskService.setVariables(String, Map)
RuntimeService.setVariables(String, Map)
A successful invocation of this method will empty the variable cache.
If this method is called from an active command (ie. from inside a Java Delegate).
ProcessEngineCdiException
is thrown.
ProcessEngineCdiException
- if called from a process engine command or if neither a Task nor an Execution is associated.public void setTask(Task task)
startTask(String)
public void setTaskId(String taskId)
startTask(String)
public void setExecution(Execution execution)
associateExecutionById(String)
protected void setExecutionId(String executionId)
associateExecutionById(String)
public String getProcessInstanceId()
public String getTaskId()
public Task getTask()
Task
or 'null'ProcessEngineCdiException
- if no Task
is associated. Use isTaskAssociated()
to check whether an association exists.public Execution getExecution()
public String getExecutionId()
getExecution()
public ProcessInstance getProcessInstance()
ProcessInstance
currently associated or 'null'ProcessEngineCdiException
- if no Execution
is associated. Use
isAssociated()
to check whether an association exists.protected void assertExecutionAssociated()
protected void assertTaskAssociated()
protected void assertCommandContextNotActive()
Copyright © 2015. All rights reserved.