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);
}
}
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);
}
}
}
}
}
}
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());
}
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);
}
}
}
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());
}
Aggregations