use of org.activiti.bpmn.model.CallActivity in project Activiti by Activiti.
the class CallActivityXMLConverter method writeAdditionalAttributes.
@Override
protected void writeAdditionalAttributes(BaseElement element, BpmnModel model, XMLStreamWriter xtw) throws Exception {
CallActivity callActivity = (CallActivity) element;
if (StringUtils.isNotEmpty(callActivity.getCalledElement())) {
xtw.writeAttribute(ATTRIBUTE_CALL_ACTIVITY_CALLEDELEMENT, callActivity.getCalledElement());
xtw.writeAttribute(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_CALL_ACTIVITY_INHERITVARIABLES, String.valueOf(callActivity.isInheritVariables()));
}
}
use of org.activiti.bpmn.model.CallActivity in project Activiti by Activiti.
the class CallActivityXMLConverter method convertXMLToElement.
@Override
protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception {
CallActivity callActivity = new CallActivity();
BpmnXMLUtil.addXMLLocation(callActivity, xtr);
callActivity.setCalledElement(xtr.getAttributeValue(null, ATTRIBUTE_CALL_ACTIVITY_CALLEDELEMENT));
callActivity.setBusinessKey(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_CALL_ACTIVITY_BUSINESS_KEY));
callActivity.setInheritBusinessKey(Boolean.parseBoolean(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_CALL_ACTIVITY_INHERIT_BUSINESS_KEY)));
callActivity.setInheritVariables(Boolean.valueOf(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_CALL_ACTIVITY_INHERITVARIABLES)));
parseChildElements(getXMLElementName(), callActivity, childParserMap, model, xtr);
return callActivity;
}
use of org.activiti.bpmn.model.CallActivity in project Activiti by Activiti.
the class BpmnAutoLayout method layout.
protected void layout(FlowElementsContainer flowElementsContainer) {
graph = new mxGraph();
cellParent = graph.getDefaultParent();
graph.getModel().beginUpdate();
// Subprocesses are handled in a new instance of BpmnAutoLayout, hence they instantiations of new maps here.
handledFlowElements = new HashMap<String, FlowElement>();
handledArtifacts = new HashMap<String, Artifact>();
generatedVertices = new HashMap<String, Object>();
generatedSequenceFlowEdges = new HashMap<String, Object>();
generatedAssociationEdges = new HashMap<String, Object>();
// Associations are gathered and processed afterwards, because we must be sure we already found source and target
associations = new HashMap<String, Association>();
// Text Annotations are gathered and processed afterwards, because we must be sure we already found the parent.
textAnnotations = new HashMap<String, TextAnnotation>();
// Sequence flow are gathered and processed afterwards,because we mustbe sure we already found source and target
sequenceFlows = new HashMap<String, SequenceFlow>();
// Boundary events are gathered and processed afterwards, because we must be sure we have its parent
boundaryEvents = new ArrayList<BoundaryEvent>();
// Process all elements
for (FlowElement flowElement : flowElementsContainer.getFlowElements()) {
if (flowElement instanceof SequenceFlow) {
handleSequenceFlow((SequenceFlow) flowElement);
} else if (flowElement instanceof Event) {
handleEvent(flowElement);
} else if (flowElement instanceof Gateway) {
createGatewayVertex(flowElement);
} else if (flowElement instanceof Task || flowElement instanceof CallActivity) {
handleActivity(flowElement);
} else if (flowElement instanceof SubProcess) {
handleSubProcess(flowElement);
}
handledFlowElements.put(flowElement.getId(), flowElement);
}
// process artifacts
for (Artifact artifact : flowElementsContainer.getArtifacts()) {
if (artifact instanceof Association) {
handleAssociation((Association) artifact);
} else if (artifact instanceof TextAnnotation) {
handleTextAnnotation((TextAnnotation) artifact);
}
handledArtifacts.put(artifact.getId(), artifact);
}
// Process gathered elements
handleBoundaryEvents();
handleSequenceFlow();
handleAssociations();
// All elements are now put in the graph. Let's layout them!
CustomLayout layout = new CustomLayout(graph, SwingConstants.WEST);
layout.setIntraCellSpacing(100.0);
layout.setResizeParent(true);
layout.setFineTuning(true);
layout.setParentBorder(20);
layout.setMoveParent(true);
layout.setDisableEdgeStyle(false);
layout.setUseBoundingBox(true);
layout.execute(graph.getDefaultParent());
graph.getModel().endUpdate();
generateDiagramInterchangeElements();
}
use of org.activiti.bpmn.model.CallActivity in project Activiti by Activiti.
the class ParallelMultiInstanceBehavior method leave.
/**
* Called when the wrapped {@link ActivityBehavior} calls the {@link AbstractBpmnActivityBehavior#leave(ActivityExecution)} method. Handles the completion of one of the parallel instances
*/
public void leave(DelegateExecution execution) {
boolean zeroNrOfInstances = false;
if (resolveNrOfInstances(execution) == 0) {
// Empty collection, just leave.
zeroNrOfInstances = true;
removeLocalLoopVariable(execution, getCollectionElementIndexVariable());
// Plan the default leave
super.leave(execution);
execution.setMultiInstanceRoot(false);
}
int loopCounter = getLoopVariable(execution, getCollectionElementIndexVariable());
int nrOfInstances = getLoopVariable(execution, NUMBER_OF_INSTANCES);
int nrOfCompletedInstances = getLoopVariable(execution, NUMBER_OF_COMPLETED_INSTANCES) + 1;
int nrOfActiveInstances = getLoopVariable(execution, NUMBER_OF_ACTIVE_INSTANCES) - 1;
Context.getCommandContext().getHistoryManager().recordActivityEnd((ExecutionEntity) execution, null);
callActivityEndListeners(execution);
if (zeroNrOfInstances) {
return;
}
DelegateExecution miRootExecution = getMultiInstanceRootExecution(execution);
if (miRootExecution != null) {
// will be null in case of empty collection
setLoopVariable(miRootExecution, NUMBER_OF_COMPLETED_INSTANCES, nrOfCompletedInstances);
setLoopVariable(miRootExecution, NUMBER_OF_ACTIVE_INSTANCES, nrOfActiveInstances);
}
updateResultCollection(execution, miRootExecution);
// executeCompensationBoundaryEvents(execution.getCurrentFlowElement(), execution);
logLoopDetails(execution, "instance completed", loopCounter, nrOfCompletedInstances, nrOfActiveInstances, nrOfInstances);
ExecutionEntity executionEntity = (ExecutionEntity) execution;
if (executionEntity.getParent() != null) {
executionEntity.inactivate();
lockFirstParentScope(executionEntity);
if (nrOfCompletedInstances >= nrOfInstances || completionConditionSatisfied(execution.getParent())) {
ExecutionEntity executionToUse = null;
if (nrOfInstances > 0) {
executionToUse = executionEntity.getParent();
} else {
executionToUse = executionEntity;
}
propagateLoopDataOutputRefToProcessInstance(executionToUse);
boolean hasCompensation = false;
Activity activity = (Activity) execution.getCurrentFlowElement();
if (activity instanceof Transaction) {
hasCompensation = true;
} else if (activity instanceof SubProcess) {
SubProcess subProcess = (SubProcess) activity;
for (FlowElement subElement : subProcess.getFlowElements()) {
if (subElement instanceof Activity) {
Activity subActivity = (Activity) subElement;
if (CollectionUtil.isNotEmpty(subActivity.getBoundaryEvents())) {
for (BoundaryEvent boundaryEvent : subActivity.getBoundaryEvents()) {
if (CollectionUtil.isNotEmpty(boundaryEvent.getEventDefinitions()) && boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition) {
hasCompensation = true;
break;
}
}
}
}
}
}
if (hasCompensation) {
ScopeUtil.createCopyOfSubProcessExecutionForCompensation(executionToUse);
}
if (activity instanceof CallActivity) {
ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();
if (executionToUse != null) {
List<String> callActivityExecutionIds = new ArrayList<String>();
// Find all execution entities that are at the call activity
List<ExecutionEntity> childExecutions = executionEntityManager.collectChildren(executionToUse);
if (childExecutions != null) {
for (ExecutionEntity childExecution : childExecutions) {
if (activity.getId().equals(childExecution.getCurrentActivityId())) {
callActivityExecutionIds.add(childExecution.getId());
}
}
// Now all call activity executions have been collected, loop again and check which should be removed
for (int i = childExecutions.size() - 1; i >= 0; i--) {
ExecutionEntity childExecution = childExecutions.get(i);
if (StringUtils.isNotEmpty(childExecution.getSuperExecutionId()) && callActivityExecutionIds.contains(childExecution.getSuperExecutionId())) {
executionEntityManager.deleteProcessInstanceExecutionEntity(childExecution.getId(), activity.getId(), "call activity completion condition met", true, true);
}
}
}
}
}
deleteChildExecutions(executionToUse, false, Context.getCommandContext());
removeLocalLoopVariable(executionToUse, getCollectionElementIndexVariable());
executionToUse.setScope(false);
executionToUse.setMultiInstanceRoot(false);
Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(executionToUse, true);
}
dispatchActivityCompletedEvent(executionEntity);
} else {
dispatchActivityCompletedEvent(executionEntity);
removeLocalLoopVariable(execution, getCollectionElementIndexVariable());
execution.setMultiInstanceRoot(false);
super.leave(execution);
}
}
use of org.activiti.bpmn.model.CallActivity in project Activiti by Activiti.
the class CallActivityBehavior method execute.
public void execute(DelegateExecution execution) {
String finalProcessDefinitonKey = null;
if (processDefinitionExpression != null) {
finalProcessDefinitonKey = (String) processDefinitionExpression.getValue(execution);
} else {
finalProcessDefinitonKey = processDefinitonKey;
}
ProcessDefinition processDefinition = findProcessDefinition(finalProcessDefinitonKey, execution.getTenantId());
// Get model from cache
Process subProcess = ProcessDefinitionUtil.getProcess(processDefinition.getId());
if (subProcess == null) {
throw new ActivitiException("Cannot start a sub process instance. Process model " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") could not be found");
}
FlowElement initialFlowElement = subProcess.getInitialFlowElement();
if (initialFlowElement == null) {
throw new ActivitiException("No start element found for process definition " + processDefinition.getId());
}
// Do not start a process instance if the process definition is suspended
if (ProcessDefinitionUtil.isProcessDefinitionSuspended(processDefinition.getId())) {
throw new ActivitiException("Cannot start process instance. Process definition " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") is suspended");
}
ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();
ExpressionManager expressionManager = processEngineConfiguration.getExpressionManager();
ExecutionEntity executionEntity = (ExecutionEntity) execution;
CallActivity callActivity = (CallActivity) executionEntity.getCurrentFlowElement();
String businessKey = null;
if (!StringUtils.isEmpty(callActivity.getBusinessKey())) {
Expression expression = expressionManager.createExpression(callActivity.getBusinessKey());
businessKey = expression.getValue(execution).toString();
} else if (callActivity.isInheritBusinessKey()) {
ExecutionEntity processInstance = executionEntityManager.findById(execution.getProcessInstanceId());
businessKey = processInstance.getBusinessKey();
}
ExecutionEntity subProcessInstance = Context.getCommandContext().getExecutionEntityManager().createSubprocessInstance(processDefinition, executionEntity, businessKey);
Context.getCommandContext().getHistoryManager().recordSubProcessInstanceStart(executionEntity, subProcessInstance, initialFlowElement);
// process template-defined data objects
Map<String, Object> variables = processDataObjects(subProcess.getDataObjects());
if (callActivity.isInheritVariables()) {
Map<String, Object> executionVariables = execution.getVariables();
for (Map.Entry<String, Object> entry : executionVariables.entrySet()) {
variables.put(entry.getKey(), entry.getValue());
}
}
Map<String, Object> variablesFromExtensionFile = calculateInboundVariables(execution, processDefinition);
variables.putAll(variablesFromExtensionFile);
if (!variables.isEmpty()) {
initializeVariables(subProcessInstance, variables);
}
// Create the first execution that will visit all the process definition elements
ExecutionEntity subProcessInitialExecution = executionEntityManager.createChildExecution(subProcessInstance);
subProcessInitialExecution.setCurrentFlowElement(initialFlowElement);
Context.getAgenda().planContinueProcessOperation(subProcessInitialExecution);
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createProcessStartedEvent(subProcessInitialExecution, variables, false));
}
Aggregations