use of org.eclipse.bpmn2.SequenceFlow in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method createBpmnEdgeForSequenceFlow.
private void createBpmnEdgeForSequenceFlow(BpmnDiFactory factory, BPMNPlane plane, SequenceFlow sequenceFlow) {
BPMNEdge edge = factory.createBPMNEdge();
edge.setBpmnElement(sequenceFlow);
DcFactory dcFactory = DcFactory.eINSTANCE;
Point point = dcFactory.createPoint();
List<Point> dockers = _dockers.get(sequenceFlow.getId());
if (sequenceFlow.getSourceRef() != null) {
Bounds sourceBounds = _bounds.get(sequenceFlow.getSourceRef().getId());
// Test for valid docker with X and Y > -1, created by EdgeParser
if (dockers != null && dockers.size() > 0 && dockers.get(0).getX() > -1 && dockers.get(0).getY() > -1) {
// First docker is connection to Source
point.setX(sourceBounds.getX() + dockers.get(0).getX());
point.setY(sourceBounds.getY() + dockers.get(0).getY());
} else {
// Default is right middle of Source
point.setX(sourceBounds.getX() + sourceBounds.getWidth());
point.setY(sourceBounds.getY() + (sourceBounds.getHeight() / 2));
}
}
edge.getWaypoint().add(point);
for (int i = 1; i < dockers.size() - 1; i++) {
edge.getWaypoint().add(dockers.get(i));
}
point = dcFactory.createPoint();
if (sequenceFlow.getTargetRef() != null) {
Bounds targetBounds = _bounds.get(sequenceFlow.getTargetRef().getId());
// Test for valid docker with X and Y > -1, created by EdgeParser
if (dockers != null && dockers.size() > 1 && dockers.get(dockers.size() - 1).getX() > -1 && dockers.get(dockers.size() - 1).getY() > -1) {
// Last docker is connection to Target
point.setX(targetBounds.getX() + dockers.get(dockers.size() - 1).getX());
point.setY(targetBounds.getY() + dockers.get(dockers.size() - 1).getY());
} else {
// Default is left middle of Target
point.setX(targetBounds.getX());
point.setY(targetBounds.getY() + (targetBounds.getHeight() / 2));
}
}
edge.getWaypoint().add(point);
plane.getPlaneElement().add(edge);
}
use of org.eclipse.bpmn2.SequenceFlow in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method applySequenceFlowCondition.
protected void applySequenceFlowCondition(SequenceFlow sequenceFlow, Map<String, String> properties) {
String conditionExpression = properties.get("conditionexpression");
if (conditionExpression != null && !conditionExpression.isEmpty()) {
ScriptTypeValue value = new ScriptTypeTypeSerializer().parse(conditionExpression);
if (value.getScript() != null && !value.getScript().isEmpty()) {
FormalExpression expr = Bpmn2Factory.eINSTANCE.createFormalExpression();
expr.setBody(wrapInCDATABlock(value.getScript()));
if (value.getLanguage() != null && !value.getLanguage().isEmpty()) {
String languageFormat = Utils.getScriptLanguageFormat(value.getLanguage());
if (languageFormat == null) {
// default to mvel
languageFormat = "http://www.mvel.org/2.0";
}
expr.setLanguage(languageFormat);
}
sequenceFlow.setConditionExpression(expr);
}
}
}
use of org.eclipse.bpmn2.SequenceFlow in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method setDefaultGateway.
private void setDefaultGateway(FlowElement fe, List<SequenceFlow> sqList) {
Iterator<FeatureMap.Entry> iter = fe.getAnyAttribute().iterator();
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("dg")) {
for (SequenceFlow newFlow : sqList) {
String entryValue = (String) entry.getValue();
String entryValueId = "";
String[] entryValueParts = entryValue.split(" : ");
if (entryValueParts.length == 1) {
entryValueId = entryValueParts[0];
} else if (entryValueParts.length > 1) {
entryValueId = entryValueParts[1];
}
if (newFlow.getId().equals(entryValueId)) {
if (fe instanceof ExclusiveGateway) {
((ExclusiveGateway) fe).setDefault(newFlow);
} else if (fe instanceof InclusiveGateway) {
((InclusiveGateway) fe).setDefault(newFlow);
}
if (newFlow.getConditionExpression() == null) {
FormalExpression expr = Bpmn2Factory.eINSTANCE.createFormalExpression();
expr.setBody("");
newFlow.setConditionExpression(expr);
}
}
}
}
}
}
use of org.eclipse.bpmn2.SequenceFlow in project kie-wb-common by kiegroup.
the class BPMNDiagramMarshallerTest method assertConditionLanguage.
private void assertConditionLanguage(Diagram<Graph, Metadata> diagram, String id, String value) {
List<Node> nodes = getNodes(diagram);
Optional<SequenceFlow> sequenceFlow = Stream.concat(nodes.stream().flatMap(node -> {
List<Edge> d = node.getInEdges();
return d.stream();
}), nodes.stream().flatMap(node -> {
List<Edge> d = node.getOutEdges();
return d.stream();
})).filter(edge -> edge.getUUID().equals(id)).map(node -> (View) node.getContent()).filter(view -> view.getDefinition() instanceof SequenceFlow).map(view -> ((SequenceFlow) view.getDefinition())).findFirst();
String conditionLanguage = (sequenceFlow.isPresent() ? sequenceFlow.get().getExecutionSet().getConditionExpression().getValue().getLanguage() : null);
assertEquals(value, conditionLanguage);
}
use of org.eclipse.bpmn2.SequenceFlow in project kie-wb-common by kiegroup.
the class BPMNDiagramMarshallerTest method testUnmarshallSequenceFlow.
@Test
public void testUnmarshallSequenceFlow() throws Exception {
Diagram<Graph, Metadata> diagram = unmarshall(BPMN_SEQUENCEFLOW);
SequenceFlow sequenceFlow1 = null;
SequenceFlow sequenceFlow2 = null;
Iterator<Element> it = nodesIterator(diagram);
while (it.hasNext()) {
Element element = it.next();
if (element.getContent() instanceof View) {
Object oDefinition = ((View) element.getContent()).getDefinition();
if (oDefinition instanceof ExclusiveGateway) {
List<Edge> outEdges = ((NodeImpl) element).getOutEdges();
for (Edge edge : outEdges) {
SequenceFlow flow = (SequenceFlow) ((ViewConnectorImpl) ((EdgeImpl) edge).getContent()).getDefinition();
if ("route1".equals(flow.getGeneral().getName().getValue())) {
sequenceFlow1 = flow;
}
if ("route2".equals(flow.getGeneral().getName().getValue())) {
sequenceFlow2 = flow;
}
}
}
}
}
assertNotNull(sequenceFlow1);
assertNotNull(sequenceFlow1.getExecutionSet());
assertNotNull(sequenceFlow1.getExecutionSet().getConditionExpression());
assertNotNull(sequenceFlow1.getExecutionSet().getPriority());
assertNotNull(sequenceFlow1.getGeneral());
assertNotNull(sequenceFlow1.getGeneral().getName());
assertEquals("route1", sequenceFlow1.getGeneral().getName().getValue());
assertEquals("age >= 10;", sequenceFlow1.getExecutionSet().getConditionExpression().getValue().getScript());
assertEquals("javascript", sequenceFlow1.getExecutionSet().getConditionExpression().getValue().getLanguage());
assertEquals("2", sequenceFlow1.getExecutionSet().getPriority().getValue());
assertNotNull(sequenceFlow2);
assertNotNull(sequenceFlow2.getExecutionSet());
assertNotNull(sequenceFlow2.getExecutionSet().getConditionExpression());
assertNotNull(sequenceFlow2.getExecutionSet().getPriority());
assertNotNull(sequenceFlow2.getGeneral());
assertNotNull(sequenceFlow2.getGeneral().getName());
assertEquals("route2", sequenceFlow2.getGeneral().getName().getValue());
assertEquals("age\n" + "<\n" + "10;", sequenceFlow2.getExecutionSet().getConditionExpression().getValue().getScript());
assertEquals("java", sequenceFlow2.getExecutionSet().getConditionExpression().getValue().getLanguage());
assertEquals("1", sequenceFlow2.getExecutionSet().getPriority().getValue());
}
Aggregations