use of org.activiti.bpmn.model.ExclusiveGateway in project Activiti by Activiti.
the class FlowNodeConverterTest method validateModel.
private void validateModel(BpmnModel model) {
FlowElement flowElement = model.getMainProcess().getFlowElement("sid-B074A0DD-934A-4053-A537-20ADF0781023", true);
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(ExclusiveGateway.class);
ExclusiveGateway gateway = (ExclusiveGateway) flowElement;
List<SequenceFlow> sequenceFlows = gateway.getOutgoingFlows();
assertThat(sequenceFlows.size() == 2).isTrue();
assertThat(sequenceFlows.get(0).getId().equals("sid-07A7E174-8857-4DE9-A7CD-A041706D79C3") || sequenceFlows.get(0).getId().equals("sid-C2068B1E-9A82-41C9-B876-C58E2736C186")).isTrue();
assertThat(sequenceFlows.get(1).getId().equals("sid-07A7E174-8857-4DE9-A7CD-A041706D79C3") || sequenceFlows.get(1).getId().equals("sid-C2068B1E-9A82-41C9-B876-C58E2736C186")).isTrue();
assertThat(sequenceFlows.get(0).getSourceRef().equals("sid-B074A0DD-934A-4053-A537-20ADF0781023")).isTrue();
assertThat(sequenceFlows.get(1).getSourceRef().equals("sid-B074A0DD-934A-4053-A537-20ADF0781023")).isTrue();
assertThat(gateway.getDefaultFlow()).isEqualTo("sid-07A7E174-8857-4DE9-A7CD-A041706D79C3");
}
use of org.activiti.bpmn.model.ExclusiveGateway in project Activiti by Activiti.
the class FeedbackStepDefinitionConverter method createMergingExclusiveGateway.
protected ExclusiveGateway createMergingExclusiveGateway(WorkflowDefinitionConversion conversion) {
ExclusiveGateway mergingExclusiveGateway = new ExclusiveGateway();
mergingExclusiveGateway.setId(conversion.getUniqueNumberedId(ConversionConstants.GATEWAY_ID_PREFIX));
addFlowElement(conversion, mergingExclusiveGateway);
return mergingExclusiveGateway;
}
use of org.activiti.bpmn.model.ExclusiveGateway in project Activiti by Activiti.
the class SequenceFlowJsonConverter method convertToJson.
@Override
public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {
SequenceFlow sequenceFlow = (SequenceFlow) baseElement;
ObjectNode flowNode = BpmnJsonConverterUtil.createChildShape(sequenceFlow.getId(), STENCIL_SEQUENCE_FLOW, 172, 212, 128, 212);
ArrayNode dockersArrayNode = objectMapper.createArrayNode();
ObjectNode dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(sequenceFlow.getSourceRef()).getWidth() / 2.0);
dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(sequenceFlow.getSourceRef()).getHeight() / 2.0);
dockersArrayNode.add(dockNode);
if (model.getFlowLocationGraphicInfo(sequenceFlow.getId()).size() > 2) {
for (int i = 1; i < model.getFlowLocationGraphicInfo(sequenceFlow.getId()).size() - 1; i++) {
GraphicInfo graphicInfo = model.getFlowLocationGraphicInfo(sequenceFlow.getId()).get(i);
dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX());
dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY());
dockersArrayNode.add(dockNode);
}
}
dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(sequenceFlow.getTargetRef()).getWidth() / 2.0);
dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(sequenceFlow.getTargetRef()).getHeight() / 2.0);
dockersArrayNode.add(dockNode);
flowNode.set("dockers", dockersArrayNode);
ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getTargetRef()));
flowNode.set("outgoing", outgoingArrayNode);
flowNode.set("target", BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getTargetRef()));
ObjectNode propertiesNode = objectMapper.createObjectNode();
propertiesNode.put(PROPERTY_OVERRIDE_ID, sequenceFlow.getId());
if (StringUtils.isNotEmpty(sequenceFlow.getName())) {
propertiesNode.put(PROPERTY_NAME, sequenceFlow.getName());
}
if (StringUtils.isNotEmpty(sequenceFlow.getDocumentation())) {
propertiesNode.put(PROPERTY_DOCUMENTATION, sequenceFlow.getDocumentation());
}
if (StringUtils.isNotEmpty(sequenceFlow.getConditionExpression())) {
propertiesNode.put(PROPERTY_SEQUENCEFLOW_CONDITION, sequenceFlow.getConditionExpression());
}
if (StringUtils.isNotEmpty(sequenceFlow.getSourceRef())) {
FlowElement sourceFlowElement = container.getFlowElement(sequenceFlow.getSourceRef());
if (sourceFlowElement != null) {
String defaultFlowId = null;
if (sourceFlowElement instanceof ExclusiveGateway) {
ExclusiveGateway parentExclusiveGateway = (ExclusiveGateway) sourceFlowElement;
defaultFlowId = parentExclusiveGateway.getDefaultFlow();
} else if (sourceFlowElement instanceof Activity) {
Activity parentActivity = (Activity) sourceFlowElement;
defaultFlowId = parentActivity.getDefaultFlow();
}
if (defaultFlowId != null && defaultFlowId.equals(sequenceFlow.getId())) {
propertiesNode.put(PROPERTY_SEQUENCEFLOW_DEFAULT, true);
}
}
}
if (sequenceFlow.getExecutionListeners().size() > 0) {
BpmnJsonConverterUtil.convertListenersToJson(sequenceFlow.getExecutionListeners(), true, propertiesNode);
}
flowNode.set(EDITOR_SHAPE_PROPERTIES, propertiesNode);
shapesArrayNode.add(flowNode);
}
use of org.activiti.bpmn.model.ExclusiveGateway in project Activiti by Activiti.
the class ExclusiveGatewayActivityBehavior method leave.
/**
* The default behaviour of BPMN, taking every outgoing sequence flow (where the condition evaluates to true), is not valid for an exclusive gateway.
*
* Hence, this behaviour is overridden and replaced by the correct behavior: selecting the first sequence flow which condition evaluates to true (or which hasn't got a condition) and leaving the
* activity through that sequence flow.
*
* If no sequence flow is selected (ie all conditions evaluate to false), then the default sequence flow is taken (if defined).
*/
@Override
public void leave(DelegateExecution execution) {
if (log.isDebugEnabled()) {
log.debug("Leaving exclusive gateway '{}'", execution.getCurrentActivityId());
}
ExclusiveGateway exclusiveGateway = (ExclusiveGateway) execution.getCurrentFlowElement();
if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_COMPLETED, exclusiveGateway.getId(), exclusiveGateway.getName(), execution.getId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), exclusiveGateway));
}
SequenceFlow outgoingSequenceFlow = null;
SequenceFlow defaultSequenceFlow = null;
String defaultSequenceFlowId = exclusiveGateway.getDefaultFlow();
// Determine sequence flow to take
Iterator<SequenceFlow> sequenceFlowIterator = exclusiveGateway.getOutgoingFlows().iterator();
while (outgoingSequenceFlow == null && sequenceFlowIterator.hasNext()) {
SequenceFlow sequenceFlow = sequenceFlowIterator.next();
String skipExpressionString = sequenceFlow.getSkipExpression();
if (!SkipExpressionUtil.isSkipExpressionEnabled(execution, skipExpressionString)) {
boolean conditionEvaluatesToTrue = ConditionUtil.hasTrueCondition(sequenceFlow, execution);
if (conditionEvaluatesToTrue && (defaultSequenceFlowId == null || !defaultSequenceFlowId.equals(sequenceFlow.getId()))) {
if (log.isDebugEnabled()) {
log.debug("Sequence flow '{}'selected as outgoing sequence flow.", sequenceFlow.getId());
}
outgoingSequenceFlow = sequenceFlow;
}
} else if (SkipExpressionUtil.shouldSkipFlowElement(Context.getCommandContext(), execution, skipExpressionString)) {
outgoingSequenceFlow = sequenceFlow;
}
// Already store it, if we would need it later. Saves one for loop.
if (defaultSequenceFlowId != null && defaultSequenceFlowId.equals(sequenceFlow.getId())) {
defaultSequenceFlow = sequenceFlow;
}
}
// We have to record the end here, or else we're already past it
Context.getCommandContext().getHistoryManager().recordActivityEnd((ExecutionEntity) execution, null);
// Leave the gateway
if (outgoingSequenceFlow != null) {
execution.setCurrentFlowElement(outgoingSequenceFlow);
} else {
if (defaultSequenceFlow != null) {
execution.setCurrentFlowElement(defaultSequenceFlow);
} else {
// No sequence flow could be found, not even a default one
throw new ActivitiException("No outgoing sequence flow of the exclusive gateway '" + exclusiveGateway.getId() + "' could be selected for continuing the process");
}
}
super.leave(execution);
}
Aggregations