From a864b9024c25227a7c576d5c21ae435166e20638 Mon Sep 17 00:00:00 2001 From: Niklas Kiefer Date: Fri, 17 Jun 2016 13:27:29 +0200 Subject: [PATCH] add gateway types to gateway parser --- .../bpmnncl/BPMNModelBuilder.java | 6 +- .../niklaskiefer/bpmnncl/MainApplication.java | 2 +- .../bpmnncl/parser/BnclGatewayParser.java | 64 +++++++++++++++---- .../bpmnncl/BnclToXmlWriterTest.java | 2 +- 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/src/main/java/de/niklaskiefer/bpmnncl/BPMNModelBuilder.java b/src/main/java/de/niklaskiefer/bpmnncl/BPMNModelBuilder.java index 855d537..7be1ea0 100644 --- a/src/main/java/de/niklaskiefer/bpmnncl/BPMNModelBuilder.java +++ b/src/main/java/de/niklaskiefer/bpmnncl/BPMNModelBuilder.java @@ -5,7 +5,9 @@ import org.camunda.bpm.model.bpmn.instance.BpmnModelElementInstance; import org.camunda.bpm.model.bpmn.instance.Definitions; import org.camunda.bpm.model.bpmn.instance.EventDefinition; +import org.camunda.bpm.model.bpmn.instance.ExclusiveGateway; import org.camunda.bpm.model.bpmn.instance.FlowNode; +import org.camunda.bpm.model.bpmn.instance.Gateway; import org.camunda.bpm.model.bpmn.instance.ParallelGateway; import org.camunda.bpm.model.bpmn.instance.Process; import org.camunda.bpm.model.bpmn.instance.SequenceFlow; @@ -73,8 +75,8 @@ public SequenceFlow createSequenceFlow(Process process, String idFrom, String id return null; } - public ParallelGateway createParallelGateway(Process process, Map attributes) { - return createElement(process, ParallelGateway.class, attributes); + public Gateway createGateway(Process process, Map attributes, Class type) { + return (Gateway) createElement(process, type, attributes); } public SequenceFlow createSequenceFlow(Process process, FlowNode from, FlowNode to) { diff --git a/src/main/java/de/niklaskiefer/bpmnncl/MainApplication.java b/src/main/java/de/niklaskiefer/bpmnncl/MainApplication.java index 185ed77..4112c93 100644 --- a/src/main/java/de/niklaskiefer/bpmnncl/MainApplication.java +++ b/src/main/java/de/niklaskiefer/bpmnncl/MainApplication.java @@ -13,7 +13,7 @@ public class MainApplication { "errorevent signed event1 called 3 Stunden vergangen with " + "scripttask signed usertask1 called dosomething with " + "usertask signed usertask2 with " + - "parallelgateway signed gateway1 with " + + "inclusivegateway signed gateway1 with " + "parallelgateway signed gateway2 with " + "sequenceflow comesfrom startevent1 goesto event1 with " + "sequenceflow comesfrom event1 goesto gateway1 with " + diff --git a/src/main/java/de/niklaskiefer/bpmnncl/parser/BnclGatewayParser.java b/src/main/java/de/niklaskiefer/bpmnncl/parser/BnclGatewayParser.java index 67b5a16..2a85600 100644 --- a/src/main/java/de/niklaskiefer/bpmnncl/parser/BnclGatewayParser.java +++ b/src/main/java/de/niklaskiefer/bpmnncl/parser/BnclGatewayParser.java @@ -2,8 +2,13 @@ import de.niklaskiefer.bpmnncl.BPMNModelBuilder; +import org.camunda.bpm.model.bpmn.instance.EventBasedGateway; +import org.camunda.bpm.model.bpmn.instance.ExclusiveGateway; import org.camunda.bpm.model.bpmn.instance.Gateway; +import org.camunda.bpm.model.bpmn.instance.InclusiveGateway; +import org.camunda.bpm.model.bpmn.instance.ParallelGateway; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -12,33 +17,66 @@ */ public class BnclGatewayParser extends BnclElementParser { - // types - private static final String PARALLEL_GATEWAY = "parallelgateway"; + private List gatewayTypes = new ArrayList<>(); public BnclGatewayParser(BPMNModelBuilder builder) { super(builder); + initGatewayTypes(); } public Gateway parseGateway(String elementString) throws Exception { List withoutSpaces = BnclParser.getWordsWithoutSpaces(elementString); - /**for (String word : withoutSpaces) { - logger().info(word); - }**/ - - String id; - Class type; if (!BnclParser.checkWords(withoutSpaces)) { return null; } - switch (withoutSpaces.get(0).toLowerCase()) { - case PARALLEL_GATEWAY: + String first = withoutSpaces.get(0).toLowerCase(); + for (GatewayType gatewayType : gatewayTypes) { + if (first.equals(gatewayType.getKeyword())) { Map attributes = parseAttributes(withoutSpaces); - return builder.createParallelGateway(builder.getProcess(), attributes); - default: - return null; + return builder.createGateway(builder.getProcess(), attributes, gatewayType.getType()); + } + } + + return null; + } + + private void initGatewayTypes() { + gatewayTypes.add(new GatewayType("parallelgateway", ParallelGateway.class)); + gatewayTypes.add(new GatewayType("exclusivegateway", ExclusiveGateway.class)); + gatewayTypes.add(new GatewayType("inclusivegateway", InclusiveGateway.class)); + gatewayTypes.add(new GatewayType("eventbasedgateway", EventBasedGateway.class)); + } + + public List getGatewayTypes() { + return gatewayTypes; + } + + private static class GatewayType { + private String keyword; + private Class type; + + private GatewayType(String keyword, Class type) { + this.keyword = keyword; + this.type = type; + } + + public String getKeyword() { + return keyword; + } + + public void setKeyword(String keyword) { + this.keyword = keyword; + } + + public Class getType() { + return type; + } + + public void setType(Class type) { + this.type = type; } } } diff --git a/src/test/java/de/niklaskiefer/bpmnncl/BnclToXmlWriterTest.java b/src/test/java/de/niklaskiefer/bpmnncl/BnclToXmlWriterTest.java index 009a867..fde3527 100644 --- a/src/test/java/de/niklaskiefer/bpmnncl/BnclToXmlWriterTest.java +++ b/src/test/java/de/niklaskiefer/bpmnncl/BnclToXmlWriterTest.java @@ -26,7 +26,7 @@ public class BnclToXmlWriterTest { private BnclEventParser eventParser; private BnclTaskParser taskParser; - private final String testBncl = "lets create a process with startevent signed startEvent1 called startevent1 with usertask signed usertask1 called dosomething with usertask signed usertask2 with parallelgateway signed gateway1 with parallelgateway signed gateway2 with sequenceflow comesfrom startevent1 goesto gateway1 with sequenceflow comesfrom gateway1 goesto usertask1 with sequenceflow comesfrom gateway1 goesto usertask2 with sequenceflow comesfrom usertask1 goesto gateway2 with sequenceflow comesfrom usertask2 goesto gateway2 with endevent signed endevent1 called terminated with sequenceflow comesfrom gateway2 goesto endevent1"; + private final String testBncl = "lets create a process with startevent signed startEvent1 called startevent1 with usertask signed usertask1 called dosomething with usertask signed usertask2 with parallelgateway signed gateway1 with exclusivegateway signed gateway2 with sequenceflow comesfrom startevent1 goesto gateway1 with sequenceflow comesfrom gateway1 goesto usertask1 with sequenceflow comesfrom gateway1 goesto usertask2 with sequenceflow comesfrom usertask1 goesto gateway2 with sequenceflow comesfrom usertask2 goesto gateway2 with endevent signed endevent1 called terminated with sequenceflow comesfrom gateway2 goesto endevent1"; @Before public void setUp() {