From f3c1308241584d771d8abc2656dd1a809c07eaa8 Mon Sep 17 00:00:00 2001 From: Jonathan Lukas <81753891+jonathanlukas@users.noreply.github.com> Date: Mon, 28 Nov 2022 15:02:19 +0100 Subject: [PATCH] Feature: Converter is now version-aware (#116) * Added comparison tooling for semver * Adjusted message to respect platform version * Terminate End Event is supported in 8.1.0 * Created new message for inclusive gateway * Inclusive gateway forking is supported in 8.1.0 * Changed default version to 8.1.0 * Added platformVersion parameter to REST and CLI * Adjusted docs * Adjusted message and behaviour * formatter --- .../converter/cli/AbstractConvertCommand.java | 6 ++ .../converter/message/MessageFactory.java | 24 +++-- .../converter/version/SemanticVersion.java | 18 ++++ .../converter/version/VersionComparator.java | 19 ++++ .../converter/version/VersionComparison.java | 12 +++ .../converter/version/VersionExtractor.java | 11 +++ .../AbstractEventDefinitionVisitor.java | 3 +- .../AbstractProcessElementVisitor.java | 11 ++- .../TerminateEventDefinitionVisitor.java | 6 +- .../impl/gateway/InclusiveGatewayVisitor.java | 31 +++++- .../resources/converter-properties.properties | 2 +- .../resources/message-templates.properties | 3 +- .../converter/BpmnConverterTest.java | 46 +++++++++ .../converter/message/MessageFactoryTest.java | 11 ++- .../version/VersionComparatorTest.java | 35 +++++++ .../version/VersionExtractorTest.java | 16 ++++ .../core/src/test/resources/or-gateways.bpmn | 95 +++++++++++++++++++ backend-diagram-converter/webapp/README.md | 34 +++++-- .../webapp/BpmnConverterService.java | 8 +- .../converter/webapp/ConverterController.java | 10 +- 20 files changed, 370 insertions(+), 31 deletions(-) create mode 100644 backend-diagram-converter/core/src/main/java/org/camunda/community/converter/version/SemanticVersion.java create mode 100644 backend-diagram-converter/core/src/main/java/org/camunda/community/converter/version/VersionComparator.java create mode 100644 backend-diagram-converter/core/src/main/java/org/camunda/community/converter/version/VersionComparison.java create mode 100644 backend-diagram-converter/core/src/main/java/org/camunda/community/converter/version/VersionExtractor.java create mode 100644 backend-diagram-converter/core/src/test/java/org/camunda/community/converter/version/VersionComparatorTest.java create mode 100644 backend-diagram-converter/core/src/test/java/org/camunda/community/converter/version/VersionExtractorTest.java create mode 100644 backend-diagram-converter/core/src/test/resources/or-gateways.bpmn diff --git a/backend-diagram-converter/cli/src/main/java/org/camunda/community/converter/cli/AbstractConvertCommand.java b/backend-diagram-converter/cli/src/main/java/org/camunda/community/converter/cli/AbstractConvertCommand.java index d5b487a1..d8e075ec 100644 --- a/backend-diagram-converter/cli/src/main/java/org/camunda/community/converter/cli/AbstractConvertCommand.java +++ b/backend-diagram-converter/cli/src/main/java/org/camunda/community/converter/cli/AbstractConvertCommand.java @@ -41,6 +41,11 @@ public abstract class AbstractConvertCommand implements Callable { description = "If enabled, existing files are overridden") boolean override; + @Option( + names = {"--platform-version"}, + description = "Semantic version of the target platform, defaults to latest version") + String platformVersion; + public AbstractConvertCommand() { BpmnConverterFactory factory = BpmnConverterFactory.getInstance(); factory.getNotificationServiceFactory().setInstance(new PrintNotificationServiceImpl()); @@ -84,6 +89,7 @@ private int handleModel(File file, BpmnModelInstance modelInstance) { protected DefaultConverterProperties converterProperties() { DefaultConverterProperties properties = new DefaultConverterProperties(); properties.setAdapterJobType(adapterJobType); + properties.setPlatformVersion(platformVersion); return properties; } diff --git a/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/message/MessageFactory.java b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/message/MessageFactory.java index f9b08239..225becd4 100644 --- a/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/message/MessageFactory.java +++ b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/message/MessageFactory.java @@ -13,6 +13,10 @@ public class MessageFactory { private MessageFactory() {} + public static Message inclusiveGatewayJoin() { + return INSTANCE.staticMessage("inclusive-gateway-join"); + } + public static Message collectionHint() { return INSTANCE.staticMessage("collection-hint"); } @@ -21,10 +25,12 @@ public static Message callActivityNoCalledElementHint() { return INSTANCE.staticMessage("call-activity-no-called-element-hint"); } - public static Message elementNotSupportedHint(String elementLocalName) { + public static Message elementNotSupportedHint(String elementLocalName, String semanticVersion) { return INSTANCE.composeMessage( "element-not-supported-hint", - ContextBuilder.builder().context(elementNotSupportedPrefix(elementLocalName)).build()); + ContextBuilder.builder() + .context(elementNotSupportedPrefix(elementLocalName, semanticVersion)) + .build()); } public static Message completionCondition(ExpressionTransformationResult transformationResult) { @@ -171,10 +177,12 @@ public static Message elementCanBeUsed(String elementLocalName) { ContextBuilder.builder().context(elementCanBeUsedPrefix(elementLocalName)).build()); } - public static Message elementNotSupported(String elementLocalName) { + public static Message elementNotSupported(String elementLocalName, String semanticVersion) { return INSTANCE.composeMessage( "element-not-supported", - ContextBuilder.builder().context(elementNotSupportedPrefix(elementLocalName)).build()); + ContextBuilder.builder() + .context(elementNotSupportedPrefix(elementLocalName, semanticVersion)) + .build()); } public static Message script() { @@ -435,8 +443,12 @@ private static Map supportedAttributePrefix( .build(); } - private static Map elementNotSupportedPrefix(String elementLocalName) { - return ContextBuilder.builder().entry("elementLocalName", elementLocalName).build(); + private static Map elementNotSupportedPrefix( + String elementLocalName, String semanticVersion) { + return ContextBuilder.builder() + .entry("elementLocalName", elementLocalName) + .entry("semanticVersion", semanticVersion) + .build(); } private static Map elementTransformedPrefix(String elementLocalName) { diff --git a/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/version/SemanticVersion.java b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/version/SemanticVersion.java new file mode 100644 index 00000000..5bea2e7c --- /dev/null +++ b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/version/SemanticVersion.java @@ -0,0 +1,18 @@ +package org.camunda.community.converter.version; + +public enum SemanticVersion { + _8_0_0("8.0.0"), + _8_1_0("8.1.0"), + _8_2_0("8.2.0"); + + private final String name; + + SemanticVersion(String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } +} diff --git a/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/version/VersionComparator.java b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/version/VersionComparator.java new file mode 100644 index 00000000..ce24fcff --- /dev/null +++ b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/version/VersionComparator.java @@ -0,0 +1,19 @@ +package org.camunda.community.converter.version; + +import java.util.Comparator; + +public class VersionComparator implements Comparator { + + @Override + public int compare(int[] version1, int[] version2) { + int positionsToCompare = Math.min(version1.length, version2.length); + int comparison = 0; + for (int i = 0; i < positionsToCompare; i++) { + comparison = version1[i] - version2[i]; + if (comparison != 0) { + return comparison; + } + } + return comparison; + } +} diff --git a/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/version/VersionComparison.java b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/version/VersionComparison.java new file mode 100644 index 00000000..4c1314d7 --- /dev/null +++ b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/version/VersionComparison.java @@ -0,0 +1,12 @@ +package org.camunda.community.converter.version; + +public class VersionComparison { + private static final VersionComparator VERSION_COMPARATOR = new VersionComparator(); + private static final VersionExtractor VERSION_EXTRACTOR = new VersionExtractor(); + + public static boolean isSupported(String actualVersion, String requiredVersion) { + return VERSION_COMPARATOR.compare( + VERSION_EXTRACTOR.apply(actualVersion), VERSION_EXTRACTOR.apply(requiredVersion)) + >= 0; + } +} diff --git a/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/version/VersionExtractor.java b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/version/VersionExtractor.java new file mode 100644 index 00000000..093313a4 --- /dev/null +++ b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/version/VersionExtractor.java @@ -0,0 +1,11 @@ +package org.camunda.community.converter.version; + +import java.util.Arrays; +import java.util.function.Function; + +public class VersionExtractor implements Function { + @Override + public int[] apply(String version) { + return Arrays.stream(version.split("\\.")).mapToInt(Integer::valueOf).toArray(); + } +} diff --git a/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/visitor/AbstractEventDefinitionVisitor.java b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/visitor/AbstractEventDefinitionVisitor.java index 41a7e74d..0de1fa77 100644 --- a/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/visitor/AbstractEventDefinitionVisitor.java +++ b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/visitor/AbstractEventDefinitionVisitor.java @@ -20,7 +20,8 @@ protected final void visitFilteredElement(DomElementVisitorContext context) { } else { context.addMessage( Severity.WARNING, - MessageFactory.elementNotSupported(context.getElement().getLocalName())); + MessageFactory.elementNotSupported( + context.getElement().getLocalName(), context.getProperties().getPlatformVersion())); } } diff --git a/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/visitor/AbstractProcessElementVisitor.java b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/visitor/AbstractProcessElementVisitor.java index 7fb3c427..9207d167 100644 --- a/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/visitor/AbstractProcessElementVisitor.java +++ b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/visitor/AbstractProcessElementVisitor.java @@ -17,9 +17,7 @@ protected final void visitFilteredElement(DomElementVisitorContext context) { context.setAsBpmnProcessElement(createConvertible(context)); postCreationVisitor(context); if (!canBeConverted(context)) { - context.addMessage( - Severity.WARNING, - MessageFactory.elementNotSupportedHint(context.getElement().getLocalName())); + addCannotBeConvertedMessage(context); } } @@ -30,4 +28,11 @@ protected final void visitFilteredElement(DomElementVisitorContext context) { protected void postCreationVisitor(DomElementVisitorContext context) { // do nothing } + + protected void addCannotBeConvertedMessage(DomElementVisitorContext context) { + context.addMessage( + Severity.WARNING, + MessageFactory.elementNotSupportedHint( + context.getElement().getLocalName(), context.getProperties().getPlatformVersion())); + } } diff --git a/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/visitor/impl/eventDefinition/TerminateEventDefinitionVisitor.java b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/visitor/impl/eventDefinition/TerminateEventDefinitionVisitor.java index 82dcf6e0..771e7b92 100644 --- a/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/visitor/impl/eventDefinition/TerminateEventDefinitionVisitor.java +++ b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/visitor/impl/eventDefinition/TerminateEventDefinitionVisitor.java @@ -1,6 +1,8 @@ package org.camunda.community.converter.visitor.impl.eventDefinition; import org.camunda.community.converter.DomElementVisitorContext; +import org.camunda.community.converter.version.SemanticVersion; +import org.camunda.community.converter.version.VersionComparison; import org.camunda.community.converter.visitor.AbstractEventDefinitionVisitor; public class TerminateEventDefinitionVisitor extends AbstractEventDefinitionVisitor { @@ -9,9 +11,9 @@ public String localName() { return "terminateEventDefinition"; } - // TODO this is supported in 8.1 @Override public boolean canBeConverted(DomElementVisitorContext context) { - return false; + return VersionComparison.isSupported( + context.getProperties().getPlatformVersion(), SemanticVersion._8_1_0.toString()); } } diff --git a/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/visitor/impl/gateway/InclusiveGatewayVisitor.java b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/visitor/impl/gateway/InclusiveGatewayVisitor.java index f614fcbb..2183bb93 100644 --- a/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/visitor/impl/gateway/InclusiveGatewayVisitor.java +++ b/backend-diagram-converter/core/src/main/java/org/camunda/community/converter/visitor/impl/gateway/InclusiveGatewayVisitor.java @@ -1,8 +1,14 @@ package org.camunda.community.converter.visitor.impl.gateway; +import org.camunda.bpm.model.xml.instance.DomElement; +import org.camunda.community.converter.BpmnDiagramCheckResult.Severity; import org.camunda.community.converter.DomElementVisitorContext; +import org.camunda.community.converter.NamespaceUri; import org.camunda.community.converter.convertible.Convertible; import org.camunda.community.converter.convertible.InclusiveGatewayConvertible; +import org.camunda.community.converter.message.MessageFactory; +import org.camunda.community.converter.version.SemanticVersion; +import org.camunda.community.converter.version.VersionComparison; import org.camunda.community.converter.visitor.AbstractGatewayVisitor; public class InclusiveGatewayVisitor extends AbstractGatewayVisitor { @@ -11,14 +17,35 @@ public String localName() { return "inclusiveGateway"; } - // TODO this is supported in 8.1 (forking only) @Override public boolean canBeConverted(DomElementVisitorContext context) { - return false; + return isNotJoining(context.getElement()) && isRequiredVersion(context); + } + + private boolean isRequiredVersion(DomElementVisitorContext context) { + return VersionComparison.isSupported( + context.getProperties().getPlatformVersion(), SemanticVersion._8_1_0.toString()); + } + + private boolean isNotJoining(DomElement element) { + return element.getChildElements().stream() + .filter(e -> e.getNamespaceURI().equals(NamespaceUri.BPMN)) + .filter(e -> e.getLocalName().equals("incoming")) + .count() + <= 1; } @Override protected Convertible createConvertible(DomElementVisitorContext context) { return new InclusiveGatewayConvertible(); } + + @Override + protected void addCannotBeConvertedMessage(DomElementVisitorContext context) { + if (!isRequiredVersion(context)) { + super.addCannotBeConvertedMessage(context); + } else { + context.addMessage(Severity.WARNING, MessageFactory.inclusiveGatewayJoin()); + } + } } diff --git a/backend-diagram-converter/core/src/main/resources/converter-properties.properties b/backend-diagram-converter/core/src/main/resources/converter-properties.properties index c2cce865..9d7d1f88 100644 --- a/backend-diagram-converter/core/src/main/resources/converter-properties.properties +++ b/backend-diagram-converter/core/src/main/resources/converter-properties.properties @@ -13,4 +13,4 @@ zeebe-header.resource=resource ## Script format zeebe-header.script-format=scriptFormat # Zeebe Meta Information -zeebe-platform.version=8.0.0 \ No newline at end of file +zeebe-platform.version=8.1.0 \ No newline at end of file diff --git a/backend-diagram-converter/core/src/main/resources/message-templates.properties b/backend-diagram-converter/core/src/main/resources/message-templates.properties index 036093d7..38bcf278 100644 --- a/backend-diagram-converter/core/src/main/resources/message-templates.properties +++ b/backend-diagram-converter/core/src/main/resources/message-templates.properties @@ -3,7 +3,7 @@ expression-transformation-result=Please review transformed expression: '{{ oldEx supported-attribute-prefix=Attribute '{{ attributeLocalName }}' on '{{ elementLocalName }}' was mapped. supported-attribute-expression={{ templates.supported-attribute-prefix }} {{ templates.expression-transformation-result }} attribute-not-supported-prefix=Attribute '{{ attributeLocalName }}' on '{{ elementLocalName }}' is currently not supported. -element-not-supported-prefix=Element '{{ elementLocalName }}' is currently not supported in Zeebe. +element-not-supported-prefix=Element '{{ elementLocalName }}' is not supported in Zeebe version '{{ semanticVersion }}'. element-not-transformable-prefix=Element '{{ elementLocalName }}' cannot be transformed. element-transformed-prefix=Element '{{ elementLocalName }}' was transformed. element-can-be-used-prefix=Element '{{ elementLocalName }}' can be used. @@ -58,6 +58,7 @@ element-can-be-used={{ templates.element-can-be-used-prefix }} element-not-supported={{ templates.element-not-supported-prefix }} script=Script was set to header 'script'. Please review. loop-cardinality=Loop cardinality is currently not supported +inclusive-gateway-join=A joining inclusive gateway is not supported. # BPMN attribute script-format=Script format '{{ scriptFormat }}' was set to header '{{ headerName }}'. Please review. script-format-missing=Script format could not be found. Please review. diff --git a/backend-diagram-converter/core/src/test/java/org/camunda/community/converter/BpmnConverterTest.java b/backend-diagram-converter/core/src/test/java/org/camunda/community/converter/BpmnConverterTest.java index e8542d3d..421238b8 100644 --- a/backend-diagram-converter/core/src/test/java/org/camunda/community/converter/BpmnConverterTest.java +++ b/backend-diagram-converter/core/src/test/java/org/camunda/community/converter/BpmnConverterTest.java @@ -114,4 +114,50 @@ public void testTaskListenerHints() { .isEqualTo( "Element 'script' cannot be transformed. Script 'delegateTask.setName(\"my script name\");' with format 'javascript' on 'taskListener'."); } + + @Test + void testOrGateways() { + BpmnConverter converter = BpmnConverterFactory.getInstance().get(); + BpmnModelInstance modelInstance = + Bpmn.readModelFromStream( + getClass().getClassLoader().getResourceAsStream("or-gateways.bpmn")); + DefaultConverterProperties properties = new DefaultConverterProperties(); + properties.setPlatformVersion("8.0.0"); + BpmnDiagramCheckResult result = + converter.check( + "or-gateways.bpmn", + modelInstance, + false, + ConverterPropertiesFactory.getInstance().merge(properties)); + BpmnElementCheckResult forkGateway = result.getResult("ForkGateway"); + assertThat(forkGateway.getMessages()).hasSize(1); + assertThat(forkGateway.getMessages().get(0).getMessage()) + .isEqualTo( + "Element 'inclusiveGateway' is not supported in Zeebe version '8.0.0'. Please review."); + BpmnElementCheckResult joinGateway = result.getResult("JoinGateway"); + assertThat(joinGateway.getMessages()).hasSize(1); + assertThat(joinGateway.getMessages().get(0).getMessage()) + .isEqualTo( + "Element 'inclusiveGateway' is not supported in Zeebe version '8.0.0'. Please review."); + } + + @Test + void testOrGateways_8_1() { + BpmnConverter converter = BpmnConverterFactory.getInstance().get(); + BpmnModelInstance modelInstance = + Bpmn.readModelFromStream( + getClass().getClassLoader().getResourceAsStream("or-gateways.bpmn")); + DefaultConverterProperties properties = new DefaultConverterProperties(); + properties.setPlatformVersion("8.1.0"); + BpmnDiagramCheckResult result = + converter.check( + "or-gateways.bpmn", + modelInstance, + false, + ConverterPropertiesFactory.getInstance().merge(properties)); + BpmnElementCheckResult joinGateway = result.getResult("JoinGateway"); + assertThat(joinGateway.getMessages()).hasSize(1); + assertThat(joinGateway.getMessages().get(0).getMessage()) + .isEqualTo("A joining inclusive gateway is not supported."); + } } diff --git a/backend-diagram-converter/core/src/test/java/org/camunda/community/converter/message/MessageFactoryTest.java b/backend-diagram-converter/core/src/test/java/org/camunda/community/converter/message/MessageFactoryTest.java index 3ce81f12..87e0b0f3 100644 --- a/backend-diagram-converter/core/src/test/java/org/camunda/community/converter/message/MessageFactoryTest.java +++ b/backend-diagram-converter/core/src/test/java/org/camunda/community/converter/message/MessageFactoryTest.java @@ -27,6 +27,13 @@ void shouldBuildScriptJobType() { assertNotNull(message.getMessage()); } + @Test + void shouldBuildInclusiveGatewayJoin() { + Message message = MessageFactory.inclusiveGatewayJoin(); + assertNotNull(message); + assertNotNull(message.getMessage()); + } + @Test void shouldBuildMap() { Message message = MessageFactory.map(); @@ -169,7 +176,7 @@ void shouldBuildElementCanBeUsed() { @Test void shouldBuildElementNotSupported() { - Message message = MessageFactory.elementNotSupported(random()); + Message message = MessageFactory.elementNotSupported(random(), random()); assertNotNull(message); assertNotNull(message.getMessage()); } @@ -357,7 +364,7 @@ void shouldBuildExecutionListener() { @Test void shouldBuildElementNotSupportedHint() { - Message message = MessageFactory.elementNotSupportedHint(random()); + Message message = MessageFactory.elementNotSupportedHint(random(), random()); assertNotNull(message); assertNotNull(message.getMessage()); } diff --git a/backend-diagram-converter/core/src/test/java/org/camunda/community/converter/version/VersionComparatorTest.java b/backend-diagram-converter/core/src/test/java/org/camunda/community/converter/version/VersionComparatorTest.java new file mode 100644 index 00000000..bb2d846d --- /dev/null +++ b/backend-diagram-converter/core/src/test/java/org/camunda/community/converter/version/VersionComparatorTest.java @@ -0,0 +1,35 @@ +package org.camunda.community.converter.version; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +public class VersionComparatorTest { + + @Test + void shouldFindEqualVersion() { + int[] version1 = new int[] {8, 0, 0}; + int[] version2 = new int[] {8, 0}; + VersionComparator comparator = new VersionComparator(); + int compare = comparator.compare(version1, version2); + assertThat(compare).isEqualTo(0); + } + + @Test + void shouldFindBiggerVersion() { + int[] version1 = new int[] {8, 1, 0}; + int[] version2 = new int[] {8, 0}; + VersionComparator comparator = new VersionComparator(); + int compare = comparator.compare(version1, version2); + assertThat(compare).isEqualTo(1); + } + + @Test + void shouldFindSmallerVersion() { + int[] version1 = new int[] {0, 26, 0}; + int[] version2 = new int[] {8, 1}; + VersionComparator comparator = new VersionComparator(); + int compare = comparator.compare(version1, version2); + assertThat(compare).isEqualTo(-8); + } +} diff --git a/backend-diagram-converter/core/src/test/java/org/camunda/community/converter/version/VersionExtractorTest.java b/backend-diagram-converter/core/src/test/java/org/camunda/community/converter/version/VersionExtractorTest.java new file mode 100644 index 00000000..b8614ac1 --- /dev/null +++ b/backend-diagram-converter/core/src/test/java/org/camunda/community/converter/version/VersionExtractorTest.java @@ -0,0 +1,16 @@ +package org.camunda.community.converter.version; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +public class VersionExtractorTest { + + @Test + void shouldExtractPlatformVersion() { + String version = "8.0.0"; + VersionExtractor extractor = new VersionExtractor(); + int[] extractedVersion = extractor.apply(version); + assertThat(extractedVersion).containsExactly(8, 0, 0); + } +} diff --git a/backend-diagram-converter/core/src/test/resources/or-gateways.bpmn b/backend-diagram-converter/core/src/test/resources/or-gateways.bpmn new file mode 100644 index 00000000..adf7ee1c --- /dev/null +++ b/backend-diagram-converter/core/src/test/resources/or-gateways.bpmn @@ -0,0 +1,95 @@ + + + + + Flow_02geyl2 + + + + ${useMe} + + + ${useMeToo} + + + + + Flow_0aeng9g + + + + Flow_02geyl2 + Flow_1cpl9tb + Flow_01o13a6 + + + Flow_0rigizb + Flow_0k6yurx + Flow_0aeng9g + + + Flow_1cpl9tb + Flow_0rigizb + + + Flow_01o13a6 + Flow_0k6yurx + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/backend-diagram-converter/webapp/README.md b/backend-diagram-converter/webapp/README.md index 53e17b84..c3831038 100644 --- a/backend-diagram-converter/webapp/README.md +++ b/backend-diagram-converter/webapp/README.md @@ -16,17 +16,35 @@ The frontend is self-explanatory. You upload .bpmn Files and then click either * The API offers 2 methods: -`POST /check`: Requires the usage of `FormData`. The formdata needs to consist of fields `files` which are the .bpmn Files. In the `Accept` header, you can either set `application/json` or `text/csv`. It will return: - -`200`: Everything fine. The body contains a list of [check results](./../core/src/main/java/org/camunda/community/converter/BpmnDiagramCheckResult.java), either in `application/json` format or flattened as `text/csv`. - -`POST /convert`: Requires the usage of `FormData`. The formdata needs to consist of fields `files` which are the .bpmn Files plus a field `appendDocumentation` which is a boolean and controls whether the messages are also appended to the documentation section of each BPMN element. It will return: - -`200`: Everything fine. The body contains a zipped `Blob` which can be saved as a file and is a zip archive containing your converted BPMN diagrams. +`POST /check`: + +* Request: + * Format: `FormData` + * Fields + * `files` (`MultipartFile[]`): BPMN files _(mandatory)_ + * `adapterJobType` (`String`): type of the job all service tasks formerly implemented as delegates or expressions should have. _(optional)_ + * `platformVersion` (`String`): version of the target platform _(optional)_ + * Headers + * `Accept`: Either `application/json` or `text/csv` +* Response: + * `200`: Everything fine. The body contains a list of [check results](./../core/src/main/java/org/camunda/community/converter/BpmnDiagramCheckResult.java), either in `application/json` format or flattened as `text/csv`. + +`POST /convert`: + +* Request: + * Format: `FormData` + * Fields + * `files` (`MultipartFile[]`): BPMN files _(mandatory)_ + * `appendDocumentation` (`Boolean`): whether the check results should also be added to the documentation of each BPMN element _(default: `false`)_ + * `adapterJobType` (`String`): type of the job all service tasks formerly implemented as delegates or expressions should have. _(optional)_ + * `platformVersion` (`String`): version of the target platform _(optional)_ +* Response: + * `200`: Everything fine. The body contains a zipped `Blob` which can be saved as a file and is a zip archive containing your converted BPMN diagrams. These error can occur on both endpoints: -`4xx`: The file you provided could not be parsed +`4xx`: The request you provided could not be handled + `5xx`: There was an exception during parsing or transforming your process. ### Notifications diff --git a/backend-diagram-converter/webapp/src/main/java/org/camunda/community/converter/webapp/BpmnConverterService.java b/backend-diagram-converter/webapp/src/main/java/org/camunda/community/converter/webapp/BpmnConverterService.java index f4f3f3e8..40323a50 100644 --- a/backend-diagram-converter/webapp/src/main/java/org/camunda/community/converter/webapp/BpmnConverterService.java +++ b/backend-diagram-converter/webapp/src/main/java/org/camunda/community/converter/webapp/BpmnConverterService.java @@ -21,7 +21,10 @@ public BpmnConverterService(BpmnConverter bpmnConverter) { } public void convert( - BpmnModelInstance modelInstance, boolean appendDocumentation, String adapterJobType) { + BpmnModelInstance modelInstance, + boolean appendDocumentation, + String adapterJobType, + String platformVersion) { DefaultConverterProperties adaptedProperties = new DefaultConverterProperties(); adaptedProperties.setAdapterJobType(adapterJobType); bpmnConverter.convert( @@ -34,7 +37,8 @@ public BpmnDiagramCheckResult check( String filename, BpmnModelInstance modelInstance, boolean appendDocumentation, - String adapterJobType) { + String adapterJobType, + String platformVersion) { DefaultConverterProperties adaptedProperties = new DefaultConverterProperties(); adaptedProperties.setAdapterJobType(adapterJobType); return bpmnConverter.check( diff --git a/backend-diagram-converter/webapp/src/main/java/org/camunda/community/converter/webapp/ConverterController.java b/backend-diagram-converter/webapp/src/main/java/org/camunda/community/converter/webapp/ConverterController.java index f5e22074..16b56508 100644 --- a/backend-diagram-converter/webapp/src/main/java/org/camunda/community/converter/webapp/ConverterController.java +++ b/backend-diagram-converter/webapp/src/main/java/org/camunda/community/converter/webapp/ConverterController.java @@ -46,6 +46,7 @@ public ConverterController( public ResponseEntity check( @RequestParam("files") MultipartFile[] bpmnFiles, @RequestParam(value = "adapterJobType", required = false) String adapterJobType, + @RequestParam(value = "platformVersion", required = false) String platformVersion, @RequestHeader(HttpHeaders.ACCEPT) String[] contentType) { List results = Arrays.stream(bpmnFiles) @@ -56,7 +57,8 @@ public ResponseEntity check( bpmnFile.getOriginalFilename(), Bpmn.readModelFromStream(in), false, - adapterJobType); + adapterJobType, + platformVersion); } catch (IOException e) { BpmnDiagramCheckResult result = new BpmnDiagramCheckResult(); result.setFilename(bpmnFile.getOriginalFilename()); @@ -89,14 +91,16 @@ public ResponseEntity check( public ResponseEntity getFile( @RequestParam("files") MultipartFile[] bpmnFiles, @RequestParam("appendDocumentation") boolean appendDocumentation, - @RequestParam(value = "adapterJobType", required = false) String adapterJobType) { + @RequestParam(value = "adapterJobType", required = false) String adapterJobType, + @RequestParam(value = "platformVersion", required = false) String platformVersion) { Map exceptions = new HashMap<>(); ByteArrayOutputStream bo = new ByteArrayOutputStream(); try (ZipOutputStream out = new ZipOutputStream(bo)) { for (MultipartFile bpmnFile : bpmnFiles) { try (InputStream in = bpmnFile.getInputStream()) { BpmnModelInstance modelInstance = Bpmn.readModelFromStream(in); - bpmnConverter.convert(modelInstance, appendDocumentation, adapterJobType); + bpmnConverter.convert( + modelInstance, appendDocumentation, adapterJobType, platformVersion); ZipEntry entry = new ZipEntry("converted-c8-" + bpmnFile.getOriginalFilename()); out.putNextEntry(entry); out.write(bpmnConverter.printXml(modelInstance.getDocument(), true).getBytes());