use of org.activiti.bpmn.model.SequenceFlow in project Activiti by Activiti.
the class FlowNodeInSubProcessConverterTest method validateModel.
private void validateModel(BpmnModel model) {
FlowElement flowElement = model.getMainProcess().getFlowElement("subprocess1", true);
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(SubProcess.class);
SubProcess subProcess = (SubProcess) flowElement;
ParallelGateway gateway = (ParallelGateway) subProcess.getFlowElement("sid-A0E0B174-36DF-4C4F-A952-311CC3C031FC");
assertThat(gateway).isNotNull();
List<SequenceFlow> sequenceFlows = gateway.getOutgoingFlows();
assertThat(sequenceFlows.size() == 2).isTrue();
assertThat(sequenceFlows.get(0).getId().equals("sid-9C669980-C274-4A48-BF7F-B9C5CA577DD2") || sequenceFlows.get(0).getId().equals("sid-A299B987-396F-46CA-8D63-85991FBFCE6E")).isTrue();
assertThat(sequenceFlows.get(1).getId().equals("sid-9C669980-C274-4A48-BF7F-B9C5CA577DD2") || sequenceFlows.get(1).getId().equals("sid-A299B987-396F-46CA-8D63-85991FBFCE6E")).isTrue();
assertThat(sequenceFlows.get(0).getSourceRef().equals("sid-A0E0B174-36DF-4C4F-A952-311CC3C031FC")).isTrue();
assertThat(sequenceFlows.get(1).getSourceRef().equals("sid-A0E0B174-36DF-4C4F-A952-311CC3C031FC")).isTrue();
}
use of org.activiti.bpmn.model.SequenceFlow in project Activiti by Activiti.
the class SequenceflowValidator method executeValidation.
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
List<SequenceFlow> sequenceFlows = process.findFlowElementsOfType(SequenceFlow.class);
for (SequenceFlow sequenceFlow : sequenceFlows) {
String sourceRef = sequenceFlow.getSourceRef();
String targetRef = sequenceFlow.getTargetRef();
if (StringUtils.isEmpty(sourceRef)) {
addError(errors, Problems.SEQ_FLOW_INVALID_SRC, process, sequenceFlow, "Invalid source for sequenceflow");
}
if (StringUtils.isEmpty(targetRef)) {
addError(errors, Problems.SEQ_FLOW_INVALID_TARGET, process, sequenceFlow, "Invalid target for sequenceflow");
}
// Implicit check: sequence flow cannot cross (sub) process
// boundaries, hence we check the parent and not the process
// (could be subprocess for example)
FlowElement source = process.getFlowElement(sourceRef, true);
FlowElement target = process.getFlowElement(targetRef, true);
// Src and target validation
if (source == null) {
addError(errors, Problems.SEQ_FLOW_INVALID_SRC, process, sequenceFlow, "Invalid source for sequenceflow");
}
if (target == null) {
addError(errors, Problems.SEQ_FLOW_INVALID_TARGET, process, sequenceFlow, "Invalid target for sequenceflow");
}
if (source != null && target != null) {
FlowElementsContainer sourceContainer = process.getFlowElementsContainer(source.getId());
FlowElementsContainer targetContainer = process.getFlowElementsContainer(target.getId());
if (sourceContainer == null) {
addError(errors, Problems.SEQ_FLOW_INVALID_SRC, process, sequenceFlow, "Invalid source for sequenceflow");
}
if (targetContainer == null) {
addError(errors, Problems.SEQ_FLOW_INVALID_TARGET, process, sequenceFlow, "Invalid target for sequenceflow");
}
if (sourceContainer != null && targetContainer != null && !sourceContainer.equals(targetContainer)) {
addError(errors, Problems.SEQ_FLOW_INVALID_TARGET, process, sequenceFlow, "Invalid target for sequenceflow, the target isn't defined in the same scope as the source");
}
}
String conditionExpression = sequenceFlow.getConditionExpression();
if (conditionExpression != null) {
try {
new ExpressionFactoryImpl().createValueExpression(new SimpleContext(), conditionExpression.trim(), Object.class);
} catch (Exception e) {
addError(errors, Problems.SEQ_FLOW_INVALID_CONDITIONAL_EXPRESSION, process, sequenceFlow, "Conditional expression is not valid");
}
}
}
}
use of org.activiti.bpmn.model.SequenceFlow 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.SequenceFlow in project Activiti by Activiti.
the class FlowNodeMultipleOutgoingFlowsConverterTest method validateModel.
private void validateModel(BpmnModel model) {
FlowElement flowElement = model.getMainProcess().getFlowElement("parallel1", true);
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(ParallelGateway.class);
ParallelGateway gateway = (ParallelGateway) flowElement;
List<SequenceFlow> sequenceFlows = gateway.getOutgoingFlows();
assertThat(sequenceFlows.size() == 3).isTrue();
assertThat(sequenceFlows.get(0).getId().equals("sid-B9EE4ECE-BF72-4C25-B768-8295906E5CF8") || sequenceFlows.get(0).getId().equals("sid-D2491B73-0382-4EC2-AAAC-C8FD129E4CBE") || sequenceFlows.get(0).getId().equals("sid-7036D56C-E8EF-493B-ADEC-57EED4C6CE1F")).isTrue();
assertThat(sequenceFlows.get(1).getId().equals("sid-B9EE4ECE-BF72-4C25-B768-8295906E5CF8") || sequenceFlows.get(1).getId().equals("sid-D2491B73-0382-4EC2-AAAC-C8FD129E4CBE") || sequenceFlows.get(1).getId().equals("sid-7036D56C-E8EF-493B-ADEC-57EED4C6CE1F")).isTrue();
assertThat(sequenceFlows.get(2).getId().equals("sid-B9EE4ECE-BF72-4C25-B768-8295906E5CF8") || sequenceFlows.get(2).getId().equals("sid-D2491B73-0382-4EC2-AAAC-C8FD129E4CBE") || sequenceFlows.get(2).getId().equals("sid-7036D56C-E8EF-493B-ADEC-57EED4C6CE1F")).isTrue();
assertThat(sequenceFlows.get(0).getSourceRef().equals("parallel1")).isTrue();
assertThat(sequenceFlows.get(1).getSourceRef().equals("parallel1")).isTrue();
assertThat(sequenceFlows.get(2).getSourceRef().equals("parallel1")).isTrue();
flowElement = model.getMainProcess().getFlowElement("parallel2", true);
assertThat(flowElement).isNotNull();
assertThat(flowElement).isInstanceOf(ParallelGateway.class);
gateway = (ParallelGateway) flowElement;
sequenceFlows = gateway.getIncomingFlows();
assertThat(sequenceFlows.size() == 3).isTrue();
assertThat(sequenceFlows.get(0).getId().equals("sid-4C19E041-42FA-485D-9D09-D47CCD9DB270") || sequenceFlows.get(0).getId().equals("sid-05A991A6-0296-4867-ACBA-EF9EEC68FB8A") || sequenceFlows.get(0).getId().equals("sid-C546AC84-379D-4094-9DC3-548593F2EA0D")).isTrue();
assertThat(sequenceFlows.get(1).getId().equals("sid-4C19E041-42FA-485D-9D09-D47CCD9DB270") || sequenceFlows.get(1).getId().equals("sid-05A991A6-0296-4867-ACBA-EF9EEC68FB8A") || sequenceFlows.get(1).getId().equals("sid-C546AC84-379D-4094-9DC3-548593F2EA0D")).isTrue();
assertThat(sequenceFlows.get(2).getId().equals("sid-4C19E041-42FA-485D-9D09-D47CCD9DB270") || sequenceFlows.get(2).getId().equals("sid-05A991A6-0296-4867-ACBA-EF9EEC68FB8A") || sequenceFlows.get(2).getId().equals("sid-C546AC84-379D-4094-9DC3-548593F2EA0D")).isTrue();
assertThat(sequenceFlows.get(0).getTargetRef().equals("parallel2")).isTrue();
assertThat(sequenceFlows.get(1).getTargetRef().equals("parallel2")).isTrue();
assertThat(sequenceFlows.get(2).getTargetRef().equals("parallel2")).isTrue();
}
use of org.activiti.bpmn.model.SequenceFlow in project Activiti by Activiti.
the class SequenceFlowJsonConverter method convertJsonToElement.
@Override
protected FlowElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode, Map<String, JsonNode> shapeMap) {
SequenceFlow flow = new SequenceFlow();
String sourceRef = BpmnJsonConverterUtil.lookForSourceRef(elementNode.get(EDITOR_SHAPE_ID).asText(), modelNode.get(EDITOR_CHILD_SHAPES));
if (sourceRef != null) {
flow.setSourceRef(sourceRef);
JsonNode targetNode = elementNode.get("target");
if (targetNode != null && !targetNode.isNull()) {
String targetId = targetNode.get(EDITOR_SHAPE_ID).asText();
if (shapeMap.get(targetId) != null) {
flow.setTargetRef(BpmnJsonConverterUtil.getElementId(shapeMap.get(targetId)));
}
}
}
JsonNode conditionNode = getProperty(PROPERTY_SEQUENCEFLOW_CONDITION, elementNode);
if (conditionNode != null) {
if (conditionNode.isTextual() && !conditionNode.isNull()) {
flow.setConditionExpression(conditionNode.asText());
} else if (conditionNode.get("expression") != null) {
JsonNode expressionNode = conditionNode.get("expression");
if (expressionNode.get("type") != null) {
String expressionType = expressionNode.get("type").asText();
if ("variables".equalsIgnoreCase(expressionType) && expressionNode.get("fieldType") != null) {
String fieldType = expressionNode.get("fieldType").asText();
if ("field".equalsIgnoreCase(fieldType)) {
setFieldConditionExpression(flow, expressionNode);
} else if ("outcome".equalsIgnoreCase(fieldType)) {
setOutcomeConditionExpression(flow, expressionNode);
}
} else if (expressionNode.get("staticValue") != null && !(expressionNode.get("staticValue").isNull())) {
flow.setConditionExpression(expressionNode.get("staticValue").asText());
}
}
}
}
return flow;
}
Aggregations