use of org.activiti.bpmn.model.ThrowEvent in project Activiti by Activiti.
the class FeedbackStepDefinitionConverter method createProcessArtifact.
@Override
protected Map<String, BaseElement> createProcessArtifact(FeedbackStepDefinition feedbackStepDefinition, WorkflowDefinitionConversion conversion) {
// See feedback-step.png in the resource folder to get a graphical understanding of the conversion below
Map<String, BaseElement> processElements = new HashMap<String, BaseElement>();
// The first user task, responsible for configuring the feedback
UserTask selectPeopleUserTask = createSelectPeopleUserTask(feedbackStepDefinition, conversion, processElements);
// Parallel gateways (forking/joining)
ParallelGateway fork = createForkParallelGateway(conversion, processElements);
addSequenceFlow(conversion, selectPeopleUserTask, fork);
// Gather feedback user task for the initiator of the feedback step
UserTask gatherFeedbackUserTask = createGatherFeedbackUserTask(feedbackStepDefinition, conversion, processElements);
addSequenceFlow(conversion, fork, gatherFeedbackUserTask);
// Global signal event
Signal signal = createSignalDeclaration(conversion);
// Signal throw event after the gather feedback task
ThrowEvent signalThrowEvent = createSignalThrow(conversion, signal);
addSequenceFlow(conversion, gatherFeedbackUserTask, signalThrowEvent);
// Povide feedback step
UserTask feedbackTask = createFeedbackUserTask(feedbackStepDefinition, conversion, processElements);
addSequenceFlow(conversion, fork, feedbackTask);
// Boundary signal catch to shut down all tasks if the 'gather feedback' task is completed
BoundaryEvent boundarySignalCatch = createBoundarySignalCatch(conversion, signal, feedbackTask);
// Exclusive gateway after the feedback task, needed to correctly merge the sequence flow
// such that the joining parallel gateway has exactly two incoming sequence flow
ExclusiveGateway mergingExclusiveGateway = createMergingExclusiveGateway(conversion);
addSequenceFlow(conversion, feedbackTask, mergingExclusiveGateway);
addSequenceFlow(conversion, boundarySignalCatch, mergingExclusiveGateway);
// Parallel gateway that will join it all together
ParallelGateway join = createJoinParallelGateway(conversion, processElements);
addSequenceFlow(conversion, signalThrowEvent, join);
addSequenceFlow(conversion, mergingExclusiveGateway, join);
// Set the last activity id, such that next steps can connect correctly
conversion.setLastActivityId(join.getId());
return processElements;
}
use of org.activiti.bpmn.model.ThrowEvent in project Activiti by Activiti.
the class IntermediateThrowCompensationEventActivityBehavior method execute.
@Override
public void execute(DelegateExecution execution) {
ThrowEvent throwEvent = (ThrowEvent) execution.getCurrentFlowElement();
/*
* From the BPMN 2.0 spec:
*
* The Activity to be compensated MAY be supplied.
*
* If an Activity is not supplied, then the compensation is broadcast to all completed Activities in
* the current Sub- Process (if present), or the entire Process instance (if at the global level). This “throws” the compensation.
*/
final String activityRef = compensateEventDefinition.getActivityRef();
CommandContext commandContext = Context.getCommandContext();
EventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.getEventSubscriptionEntityManager();
List<CompensateEventSubscriptionEntity> eventSubscriptions = new ArrayList<CompensateEventSubscriptionEntity>();
if (StringUtils.isNotEmpty(activityRef)) {
// If an activity ref is provided, only that activity is compensated
eventSubscriptions.addAll(eventSubscriptionEntityManager.findCompensateEventSubscriptionsByProcessInstanceIdAndActivityId(execution.getProcessInstanceId(), activityRef));
} else {
// If no activity ref is provided, it is broadcast to the current sub process / process instance
Process process = ProcessDefinitionUtil.getProcess(execution.getProcessDefinitionId());
FlowElementsContainer flowElementsContainer = null;
if (throwEvent.getSubProcess() == null) {
flowElementsContainer = process;
} else {
flowElementsContainer = throwEvent.getSubProcess();
}
for (FlowElement flowElement : flowElementsContainer.getFlowElements()) {
if (flowElement instanceof Activity) {
eventSubscriptions.addAll(eventSubscriptionEntityManager.findCompensateEventSubscriptionsByProcessInstanceIdAndActivityId(execution.getProcessInstanceId(), flowElement.getId()));
}
}
}
if (eventSubscriptions.isEmpty()) {
leave(execution);
} else {
// TODO: implement async (waitForCompletion=false in bpmn)
ScopeUtil.throwCompensationEvent(eventSubscriptions, execution, false);
leave(execution);
}
}
use of org.activiti.bpmn.model.ThrowEvent in project Activiti by Activiti.
the class CompensateEventDefinitionParseHandler method executeParse.
protected void executeParse(BpmnParse bpmnParse, CompensateEventDefinition eventDefinition) {
if (bpmnParse.getCurrentFlowElement() instanceof ThrowEvent) {
ThrowEvent throwEvent = (ThrowEvent) bpmnParse.getCurrentFlowElement();
throwEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateThrowCompensationEventActivityBehavior(throwEvent, eventDefinition));
} else if (bpmnParse.getCurrentFlowElement() instanceof BoundaryEvent) {
BoundaryEvent boundaryEvent = (BoundaryEvent) bpmnParse.getCurrentFlowElement();
boundaryEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createBoundaryCompensateEventActivityBehavior(boundaryEvent, eventDefinition, boundaryEvent.isCancelActivity()));
} else {
// What to do?
}
}
use of org.activiti.bpmn.model.ThrowEvent in project Activiti by Activiti.
the class IntermediateThrowCatchSignalEventConverterTest method checkThrowEvent.
private void checkThrowEvent(BpmnModel model, String id, String signalRef) {
FlowElement flowElement = model.getMainProcess().getFlowElement(id);
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(ThrowEvent.class);
ThrowEvent throwEvent = (ThrowEvent) flowElement;
assertThat(throwEvent.getIncomingFlows()).hasSize(1);
assertThat(throwEvent.getOutgoingFlows()).hasSize(1);
assertThat(throwEvent.getEventDefinitions()).hasSize(1);
assertThat(throwEvent.getIncomingFlows().get(0).getXmlRowNumber()).isLessThan(throwEvent.getEventDefinitions().get(0).getXmlRowNumber());
checkSignalEventDefinition(throwEvent, signalRef);
}
use of org.activiti.bpmn.model.ThrowEvent in project Activiti by Activiti.
the class ThrowEventXMLConverter method writeAdditionalChildElements.
@Override
protected void writeAdditionalChildElements(BaseElement element, BpmnModel model, XMLStreamWriter xtw) throws Exception {
ThrowEvent throwEvent = (ThrowEvent) element;
writeEventDefinitions(throwEvent, throwEvent.getEventDefinitions(), model, xtw);
}
Aggregations