Search in sources :

Example 1 with ExclusiveGateway

use of org.eclipse.bpmn2.ExclusiveGateway in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method applyGatewayProperties.

protected void applyGatewayProperties(Gateway gateway, Map<String, String> properties) {
    if (properties.get("name") != null && properties.get("name").length() > 0) {
        gateway.setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " "));
        // add unescaped and untouched name value as extension element as well
        Utils.setMetaDataExtensionValue(gateway, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n")));
    } else {
        gateway.setName("");
    }
    if (properties.get("defaultgate") != null && (gateway instanceof InclusiveGateway || gateway instanceof ExclusiveGateway)) {
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "dg", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("defaultgate"));
        gateway.getAnyAttribute().add(extensionEntry);
    }
}
Also used : ExclusiveGateway(org.eclipse.bpmn2.ExclusiveGateway) InclusiveGateway(org.eclipse.bpmn2.InclusiveGateway) EAttributeImpl(org.eclipse.emf.ecore.impl.EAttributeImpl) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) ExtendedMetaData(org.eclipse.emf.ecore.util.ExtendedMetaData)

Example 2 with ExclusiveGateway

use of org.eclipse.bpmn2.ExclusiveGateway 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);
                    }
                }
            }
        }
    }
}
Also used : FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) ExclusiveGateway(org.eclipse.bpmn2.ExclusiveGateway) Entry(java.util.Map.Entry) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) InclusiveGateway(org.eclipse.bpmn2.InclusiveGateway) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) FormalExpression(org.eclipse.bpmn2.FormalExpression)

Example 3 with ExclusiveGateway

use of org.eclipse.bpmn2.ExclusiveGateway 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());
}
Also used : NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) SequenceFlow(org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) FlowElement(org.eclipse.bpmn2.FlowElement) RootElement(org.eclipse.bpmn2.RootElement) Element(org.kie.workbench.common.stunner.core.graph.Element) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ExclusiveGateway(org.kie.workbench.common.stunner.bpmn.definition.ExclusiveGateway) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 4 with ExclusiveGateway

use of org.eclipse.bpmn2.ExclusiveGateway in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method setGatewayInfo.

private void setGatewayInfo(FlowElementsContainer container) {
    List<FlowElement> flowElements = container.getFlowElements();
    for (FlowElement fe : flowElements) {
        if (fe instanceof Gateway) {
            Gateway gateway = (Gateway) fe;
            int incoming = gateway.getIncoming() == null ? 0 : gateway.getIncoming().size();
            int outgoing = gateway.getOutgoing() == null ? 0 : gateway.getOutgoing().size();
            if (incoming <= 1 && outgoing > 1) {
                gateway.setGatewayDirection(GatewayDirection.DIVERGING);
            } else if (incoming > 1 && outgoing <= 1) {
                gateway.setGatewayDirection(GatewayDirection.CONVERGING);
            } else // temp. removing support for mixed gateway direction (not supported by runtime yet)
            // else if (incoming > 1 && outgoing > 1) {
            // gateway.setGatewayDirection(GatewayDirection.MIXED);
            // }
            // else if (incoming == 1 && outgoing == 1) {
            // // this handles the 1:1 case of the diverging gateways
            // }
            {
                gateway.setGatewayDirection(GatewayDirection.UNSPECIFIED);
            }
        }
        if (fe instanceof InclusiveGateway) {
            InclusiveGateway ig = (InclusiveGateway) fe;
            List<SequenceFlow> sqList = new ArrayList<SequenceFlow>();
            if (ig.getIncoming() != null) {
                sqList.addAll(ig.getIncoming());
            }
            if (ig.getOutgoing() != null) {
                sqList.addAll(ig.getOutgoing());
            }
            setDefaultGateway(fe, sqList);
        }
        if (fe instanceof ExclusiveGateway) {
            ExclusiveGateway eg = (ExclusiveGateway) fe;
            List<SequenceFlow> sqList = new ArrayList<SequenceFlow>();
            if (eg.getIncoming() != null) {
                sqList.addAll(eg.getIncoming());
            }
            if (eg.getOutgoing() != null) {
                sqList.addAll(eg.getOutgoing());
            }
            setDefaultGateway(fe, sqList);
        }
        if (fe instanceof FlowElementsContainer) {
            setGatewayInfo((FlowElementsContainer) fe);
        }
    }
}
Also used : ExclusiveGateway(org.eclipse.bpmn2.ExclusiveGateway) InclusiveGateway(org.eclipse.bpmn2.InclusiveGateway) FlowElement(org.eclipse.bpmn2.FlowElement) ExclusiveGateway(org.eclipse.bpmn2.ExclusiveGateway) Gateway(org.eclipse.bpmn2.Gateway) InclusiveGateway(org.eclipse.bpmn2.InclusiveGateway) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) ArrayList(java.util.ArrayList) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer) Point(org.eclipse.dd.dc.Point)

Example 5 with ExclusiveGateway

use of org.eclipse.bpmn2.ExclusiveGateway in project kie-wb-common by kiegroup.

the class BPMNDirectDiagramMarshallerTest 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) 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());
}
Also used : ExclusiveGateway(org.kie.workbench.common.stunner.bpmn.definition.ExclusiveGateway) Graph(org.kie.workbench.common.stunner.core.graph.Graph) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) SequenceFlow(org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) FlowElement(org.eclipse.bpmn2.FlowElement) RootElement(org.eclipse.bpmn2.RootElement) Element(org.kie.workbench.common.stunner.core.graph.Element) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Aggregations

ExclusiveGateway (org.eclipse.bpmn2.ExclusiveGateway)3 FlowElement (org.eclipse.bpmn2.FlowElement)3 InclusiveGateway (org.eclipse.bpmn2.InclusiveGateway)3 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)3 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)2 RootElement (org.eclipse.bpmn2.RootElement)2 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)2 Test (org.junit.Test)2 ExclusiveGateway (org.kie.workbench.common.stunner.bpmn.definition.ExclusiveGateway)2 SequenceFlow (org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow)2 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)2 Edge (org.kie.workbench.common.stunner.core.graph.Edge)2 Element (org.kie.workbench.common.stunner.core.graph.Element)2 Graph (org.kie.workbench.common.stunner.core.graph.Graph)2 View (org.kie.workbench.common.stunner.core.graph.content.view.View)2 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)2 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 FlowElementsContainer (org.eclipse.bpmn2.FlowElementsContainer)1 FormalExpression (org.eclipse.bpmn2.FormalExpression)1