Search in sources :

Example 1 with InclusiveGateway

use of org.eclipse.bpmn2.InclusiveGateway 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 InclusiveGateway

use of org.eclipse.bpmn2.InclusiveGateway 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 InclusiveGateway

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

the class GatewayPropertyWriterTest method testSetTargetForInclusiveGateway.

@Test
public void testSetTargetForInclusiveGateway() {
    InclusiveGateway inclusiveGateway = mockGateway(InclusiveGateway.class, ID);
    prepareTestSetSourceOrTarget(inclusiveGateway);
    propertyWriter.setTarget(anotherPropertyWriter);
    verify(inclusiveGateway).setDefault(sequenceFlow);
}
Also used : InclusiveGateway(org.eclipse.bpmn2.InclusiveGateway) Test(org.junit.Test)

Example 4 with InclusiveGateway

use of org.eclipse.bpmn2.InclusiveGateway 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 InclusiveGateway

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

the class Bpmn2JsonMarshaller method marshallInclusiveGateway.

protected void marshallInclusiveGateway(InclusiveGateway gateway, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, Map<String, Object> flowElementProperties) throws JsonGenerationException, IOException {
    if (gateway.getDefault() != null) {
        SequenceFlow defsf = gateway.getDefault();
        String defGatewayStr = defsf.getId();
        flowElementProperties.put("defaultgate", defGatewayStr);
    }
    marshallNode(gateway, flowElementProperties, "InclusiveGateway", plane, generator, xOffset, yOffset);
}
Also used : SequenceFlow(org.eclipse.bpmn2.SequenceFlow)

Aggregations

InclusiveGateway (org.eclipse.bpmn2.InclusiveGateway)5 ExclusiveGateway (org.eclipse.bpmn2.ExclusiveGateway)3 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)3 SimpleFeatureMapEntry (org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 FlowElement (org.eclipse.bpmn2.FlowElement)1 FlowElementsContainer (org.eclipse.bpmn2.FlowElementsContainer)1 FormalExpression (org.eclipse.bpmn2.FormalExpression)1 Gateway (org.eclipse.bpmn2.Gateway)1 Point (org.eclipse.dd.dc.Point)1 EAttributeImpl (org.eclipse.emf.ecore.impl.EAttributeImpl)1 ExtendedMetaData (org.eclipse.emf.ecore.util.ExtendedMetaData)1 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)1