use of org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow in project kie-wb-common by kiegroup.
the class SequenceFlowConverter method toFlowElement.
public SequenceFlowPropertyWriter toFlowElement(Edge<?, ?> edge, ElementContainer process) {
ViewConnector<SequenceFlow> content = (ViewConnector<SequenceFlow>) edge.getContent();
SequenceFlow definition = content.getDefinition();
org.eclipse.bpmn2.SequenceFlow seq = bpmn2.createSequenceFlow();
SequenceFlowPropertyWriter p = propertyWriterFactory.of(seq);
seq.setId(edge.getUUID());
BasePropertyWriter pSrc = process.getChildElement(edge.getSourceNode().getUUID());
BasePropertyWriter pTgt = process.getChildElement(edge.getTargetNode().getUUID());
p.setSource(pSrc);
p.setTarget(pTgt);
seq.setId(edge.getUUID());
seq.setName(definition.getGeneral().getName().getValue());
p.setConnection(content);
SequenceFlowExecutionSet executionSet = definition.getExecutionSet();
ScriptTypeValue scriptTypeValue = executionSet.getConditionExpression().getValue();
String language = scriptTypeValue.getLanguage();
String script = scriptTypeValue.getScript();
if (script != null) {
FormalExpression formalExpression = bpmn2.createFormalExpression();
String uri = Scripts.scriptLanguageToUri(language);
formalExpression.setLanguage(uri);
formalExpression.setBody(asCData(script));
seq.setConditionExpression(formalExpression);
}
process.addChildElement(p);
process.addChildEdge(p.getEdge());
return p;
}
use of org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow in project kie-wb-common by kiegroup.
the class SequenceFlowConverter method convertEdge.
public BpmnEdge convertEdge(org.eclipse.bpmn2.SequenceFlow seq, Map<String, BpmnNode> nodes) {
Edge<View<SequenceFlow>, Node> edge = factoryManager.newEdge(seq.getId(), SequenceFlow.class);
SequenceFlow definition = edge.getContent().getDefinition();
SequenceFlowPropertyReader p = propertyReaderFactory.of(seq);
definition.setGeneral(new BPMNGeneralSet(new Name(seq.getName()), new Documentation(p.getDocumentation())));
definition.setExecutionSet(new SequenceFlowExecutionSet(new Priority(p.getPriority()), new ConditionExpression(p.getConditionExpression())));
return BpmnEdge.of(edge, nodes.get(p.getSourceId()), p.getSourceConnection(), nodes.get(p.getTargetId()), p.getTargetConnection());
}
use of org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow in project kie-wb-common by kiegroup.
the class BPMNDirectDiagramMarshallerTest method testUnmarshallXorGateway.
@Test
@SuppressWarnings("unchecked")
public void testUnmarshallXorGateway() throws Exception {
Diagram<Graph, Metadata> diagram = unmarshall(BPMN_XORGATEWAY);
assertDiagram(diagram, 7);
assertEquals(diagram.getMetadata().getTitle(), "XORGateway");
Graph graph = diagram.getGraph();
Node<? extends Definition, ?> gatewayNode = graph.getNode("_877EA035-1A14-42E9-8CAA-43E9BF908C70");
ExclusiveGateway xorGateway = (ExclusiveGateway) gatewayNode.getContent().getDefinition();
assertEquals("AgeSplit", xorGateway.getGeneral().getName().getValue());
assertEquals("_5110D608-BDAD-47BF-A3F9-E1DBE43ED7CD", xorGateway.getExecutionSet().getDefaultRoute().getValue());
SequenceFlow sequenceFlow1 = null;
SequenceFlow sequenceFlow2 = null;
List<Edge> outEdges = (List<Edge>) gatewayNode.getOutEdges();
if (outEdges != null) {
for (Edge edge : outEdges) {
if ("_C72E00C3-70DC-4BC9-A08E-761B4263A239".equals(edge.getUUID())) {
sequenceFlow1 = (SequenceFlow) ((ViewConnector) edge.getContent()).getDefinition();
} else if ("_5110D608-BDAD-47BF-A3F9-E1DBE43ED7CD".equals(edge.getUUID())) {
sequenceFlow2 = (SequenceFlow) ((ViewConnector) edge.getContent()).getDefinition();
}
}
}
assertNotNull(sequenceFlow1);
assertEquals("10 and over", sequenceFlow1.getGeneral().getName().getValue());
assertNotNull(sequenceFlow2);
assertEquals("under 10", sequenceFlow2.getGeneral().getName().getValue());
}
use of org.kie.workbench.common.stunner.bpmn.definition.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.kie.workbench.common.stunner.bpmn.definition.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