use of org.activiti.bpmn.model.CompensateEventDefinition in project Activiti by Activiti.
the class IntermediateThrowEventParseHandler method executeParse.
protected void executeParse(BpmnParse bpmnParse, ThrowEvent intermediateEvent) {
EventDefinition eventDefinition = null;
if (!intermediateEvent.getEventDefinitions().isEmpty()) {
eventDefinition = intermediateEvent.getEventDefinitions().get(0);
}
if (eventDefinition instanceof SignalEventDefinition) {
SignalEventDefinition signalEventDefinition = (SignalEventDefinition) eventDefinition;
intermediateEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateThrowSignalEventActivityBehavior(intermediateEvent, signalEventDefinition, bpmnParse.getBpmnModel().getSignal(signalEventDefinition.getSignalRef())));
} else if (eventDefinition instanceof CompensateEventDefinition) {
CompensateEventDefinition compensateEventDefinition = (CompensateEventDefinition) eventDefinition;
intermediateEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateThrowCompensationEventActivityBehavior(intermediateEvent, compensateEventDefinition));
} else if (eventDefinition instanceof MessageEventDefinition) {
MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;
Message message = bpmnParse.getBpmnModel().getMessage(messageEventDefinition.getMessageRef());
BpmnModel bpmnModel = bpmnParse.getBpmnModel();
if (bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) {
messageEventDefinition.setMessageRef(message.getName());
messageEventDefinition.setExtensionElements(message.getExtensionElements());
}
intermediateEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createThrowMessageEventActivityBehavior(intermediateEvent, messageEventDefinition, message));
} else if (eventDefinition == null) {
intermediateEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateThrowNoneEventActivityBehavior(intermediateEvent));
} else {
logger.warn("Unsupported intermediate throw event type for throw event " + intermediateEvent.getId());
}
}
use of org.activiti.bpmn.model.CompensateEventDefinition in project Activiti by Activiti.
the class CompensateEventDefinitionParser method parseChildElement.
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
if (!(parentElement instanceof Event))
return;
CompensateEventDefinition eventDefinition = new CompensateEventDefinition();
BpmnXMLUtil.addXMLLocation(eventDefinition, xtr);
eventDefinition.setActivityRef(xtr.getAttributeValue(null, ATTRIBUTE_COMPENSATE_ACTIVITYREF));
if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_COMPENSATE_WAITFORCOMPLETION))) {
eventDefinition.setWaitForCompletion(Boolean.parseBoolean(xtr.getAttributeValue(null, ATTRIBUTE_COMPENSATE_WAITFORCOMPLETION)));
}
BpmnXMLUtil.parseChildElements(ELEMENT_EVENT_COMPENSATEDEFINITION, eventDefinition, xtr, model);
((Event) parentElement).getEventDefinitions().add(eventDefinition);
}
use of org.activiti.bpmn.model.CompensateEventDefinition in project Activiti by Activiti.
the class EndExecutionOperation method handleSubProcessEnd.
protected ExecutionEntity handleSubProcessEnd(ExecutionEntityManager executionEntityManager, ExecutionEntity parentExecution, SubProcess subProcess) {
ExecutionEntity executionToContinue = null;
// create a new execution to take the outgoing sequence flows
executionToContinue = executionEntityManager.createChildExecution(parentExecution.getParent());
executionToContinue.setCurrentFlowElement(subProcess);
boolean hasCompensation = false;
if (subProcess instanceof Transaction) {
hasCompensation = true;
} else {
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;
}
}
}
}
}
}
// The following method does exactly that, and moves the executions beneath the process instance.
if (hasCompensation) {
ScopeUtil.createCopyOfSubProcessExecutionForCompensation(parentExecution);
}
executionEntityManager.deleteChildExecutions(parentExecution, null);
executionEntityManager.deleteExecutionAndRelatedData(parentExecution, null);
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_COMPLETED, subProcess.getId(), subProcess.getName(), parentExecution.getId(), parentExecution.getProcessInstanceId(), parentExecution.getProcessDefinitionId(), subProcess));
return executionToContinue;
}
use of org.activiti.bpmn.model.CompensateEventDefinition 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.CompensateEventDefinition in project Activiti by Activiti.
the class BoundaryEventJsonConverter method getStencilId.
protected String getStencilId(BaseElement baseElement) {
BoundaryEvent boundaryEvent = (BoundaryEvent) baseElement;
List<EventDefinition> eventDefinitions = boundaryEvent.getEventDefinitions();
if (eventDefinitions.size() != 1) {
// return timer event as default;
return STENCIL_EVENT_BOUNDARY_TIMER;
}
EventDefinition eventDefinition = eventDefinitions.get(0);
if (eventDefinition instanceof ErrorEventDefinition) {
return STENCIL_EVENT_BOUNDARY_ERROR;
} else if (eventDefinition instanceof SignalEventDefinition) {
return STENCIL_EVENT_BOUNDARY_SIGNAL;
} else if (eventDefinition instanceof MessageEventDefinition) {
return STENCIL_EVENT_BOUNDARY_MESSAGE;
} else if (eventDefinition instanceof CancelEventDefinition) {
return STENCIL_EVENT_BOUNDARY_CANCEL;
} else if (eventDefinition instanceof CompensateEventDefinition) {
return STENCIL_EVENT_BOUNDARY_COMPENSATION;
} else {
return STENCIL_EVENT_BOUNDARY_TIMER;
}
}
Aggregations