From e2901940655fdea42e756a4448a0c08aa567cb98 Mon Sep 17 00:00:00 2001 From: Jonathan Lukas Date: Mon, 16 Dec 2024 10:00:33 +0100 Subject: [PATCH] fix: take listener are not respected (#1081) --- .../converter/message/MessageFactory.java | 3 +- .../visitor/AbstractListenerVisitor.java | 23 +++++++++++++- .../element/ExecutionListenerVisitor.java | 21 +++++++++---- .../resources/message-templates.properties | 2 +- .../converter/BpmnConverterTest.java | 13 ++++++++ .../converter/message/MessageFactoryTest.java | 5 ++-- .../src/test/resources/take-listener.bpmn | 30 +++++++++++++++++++ 7 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 backend-diagram-converter/core/src/test/resources/take-listener.bpmn diff --git a/backend-diagram-converter/core/src/main/java/org/camunda/community/migration/converter/message/MessageFactory.java b/backend-diagram-converter/core/src/main/java/org/camunda/community/migration/converter/message/MessageFactory.java index cb769f75..52fd7100 100644 --- a/backend-diagram-converter/core/src/main/java/org/camunda/community/migration/converter/message/MessageFactory.java +++ b/backend-diagram-converter/core/src/main/java/org/camunda/community/migration/converter/message/MessageFactory.java @@ -357,11 +357,12 @@ public static Message property(String elementLocalName, String propertyName) { .build()); } - public static Message executionListener(String event, String implementation) { + public static Message executionListener(String event, String type, String implementation) { return INSTANCE.composeMessage( "execution-listener", ContextBuilder.builder() .entry("event", event) + .entry("type", type) .entry("implementation", implementation) .build()); } diff --git a/backend-diagram-converter/core/src/main/java/org/camunda/community/migration/converter/visitor/AbstractListenerVisitor.java b/backend-diagram-converter/core/src/main/java/org/camunda/community/migration/converter/visitor/AbstractListenerVisitor.java index 5b8b3fa7..6d6b4f34 100644 --- a/backend-diagram-converter/core/src/main/java/org/camunda/community/migration/converter/visitor/AbstractListenerVisitor.java +++ b/backend-diagram-converter/core/src/main/java/org/camunda/community/migration/converter/visitor/AbstractListenerVisitor.java @@ -14,10 +14,14 @@ public abstract class AbstractListenerVisitor extends AbstractCamundaElementVisi @Override protected final Message visitCamundaElement(DomElementVisitorContext context) { ListenerImplementation implementation = findListenerImplementation(context); - String event = context.getElement().getAttribute(NamespaceUri.CAMUNDA, "event"); + String event = findEventName(context); return visitListener(context, event, implementation); } + protected String findEventName(DomElementVisitorContext context) { + return context.getElement().getAttribute(NamespaceUri.CAMUNDA, "event"); + } + protected abstract Message visitListener( DomElementVisitorContext context, String event, ListenerImplementation implementation); @@ -54,6 +58,23 @@ private ListenerImplementation findListenerImplementation(DomElementVisitorConte public sealed interface ListenerImplementation { String implementation(); + static String type(ListenerImplementation implementation) { + if (implementation == null) { + return null; + } else if (implementation instanceof NullImplementation) { + return "null"; + } else if (implementation instanceof DelegateExpressionImplementation) { + return "delegateExpression"; + } else if (implementation instanceof ClassImplementation) { + return "class"; + } else if (implementation instanceof ExpressionImplementation) { + return "expression"; + } else if (implementation instanceof ScriptImplementation) { + return "script"; + } + throw new IllegalArgumentException("Unsupported implementation: " + implementation); + } + record DelegateExpressionImplementation(String implementation) implements ListenerImplementation {} diff --git a/backend-diagram-converter/core/src/main/java/org/camunda/community/migration/converter/visitor/impl/element/ExecutionListenerVisitor.java b/backend-diagram-converter/core/src/main/java/org/camunda/community/migration/converter/visitor/impl/element/ExecutionListenerVisitor.java index f0e5f02b..f87c1ef6 100644 --- a/backend-diagram-converter/core/src/main/java/org/camunda/community/migration/converter/visitor/impl/element/ExecutionListenerVisitor.java +++ b/backend-diagram-converter/core/src/main/java/org/camunda/community/migration/converter/visitor/impl/element/ExecutionListenerVisitor.java @@ -23,7 +23,7 @@ public String localName() { protected Message visitListener( DomElementVisitorContext context, String event, ListenerImplementation implementation) { if (isExecutionListenerSupported( - SemanticVersion.parse(context.getProperties().getPlatformVersion()))) { + SemanticVersion.parse(context.getProperties().getPlatformVersion()), event)) { ZeebeExecutionListener executionListener = new ZeebeExecutionListener(); executionListener.setEventType(EventType.valueOf(event)); if (implementation instanceof DelegateExpressionImplementation) { @@ -38,16 +38,27 @@ protected Message visitListener( c -> c.addZeebeExecutionListener(executionListener)); return MessageFactory.executionListenerSupported(event, implementation.implementation()); } - return MessageFactory.executionListener(event, implementation.implementation()); + return MessageFactory.executionListener( + event, ListenerImplementation.type(implementation), implementation.implementation()); } - private boolean isExecutionListenerSupported(SemanticVersion version) { - return version.ordinal() >= SemanticVersion._8_6.ordinal(); + private boolean isExecutionListenerSupported(SemanticVersion version, String event) { + return version.ordinal() >= SemanticVersion._8_6.ordinal() && isKnownEventType(event); + } + + private boolean isKnownEventType(String event) { + for (EventType eventType : EventType.values()) { + if (eventType.name().equals(event)) { + return true; + } + } + return false; } @Override public boolean canBeTransformed(DomElementVisitorContext context) { return isExecutionListenerSupported( - SemanticVersion.parse(context.getProperties().getPlatformVersion())); + SemanticVersion.parse(context.getProperties().getPlatformVersion()), + findEventName(context)); } } 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 fc46a0f5..2e093978 100644 --- a/backend-diagram-converter/core/src/main/resources/message-templates.properties +++ b/backend-diagram-converter/core/src/main/resources/message-templates.properties @@ -190,7 +190,7 @@ connector-id.severity=REVIEW property.message={{ templates.element-transformed-prefix }} Property '{{ propertyName}}' lives in the Zeebe namespace now. property.severity=INFO # -execution-listener.message=Listener at '{{ event }}' with implementation '{{ implementation }}' cannot be transformed. Execution Listeners do not exist before Zeebe 8.6. +execution-listener.message=Listener at '{{ event }}' with implementation '{{ type }}' '{{ implementation }}' cannot be transformed. execution-listener.severity=WARNING # execution-listener-supported.message=Listener at '{{ event }}' with implementation '{{ implementation }}' can be transformed to a job worker. Please adjust the job type. diff --git a/backend-diagram-converter/core/src/test/java/org/camunda/community/migration/converter/BpmnConverterTest.java b/backend-diagram-converter/core/src/test/java/org/camunda/community/migration/converter/BpmnConverterTest.java index 0ed24fe1..a08c5ed5 100644 --- a/backend-diagram-converter/core/src/test/java/org/camunda/community/migration/converter/BpmnConverterTest.java +++ b/backend-diagram-converter/core/src/test/java/org/camunda/community/migration/converter/BpmnConverterTest.java @@ -922,4 +922,17 @@ void shouldTransformDelegateExpressionAsJobType() { assertThat(taskDefinition.hasAttribute("type")).isTrue(); assertThat(taskDefinition.getAttribute("type")).isEqualTo("myDelegate"); } + + @Test + void shouldNotTransformTakeListener() { + BpmnDiagramCheckResult bpmnDiagramCheckResult = loadAndCheck("take-listener.bpmn"); + BpmnElementCheckResult takeListenerFlow = bpmnDiagramCheckResult.getResult("takeListenerFlow"); + assertThat(takeListenerFlow).isNotNull(); + assertThat(takeListenerFlow.getMessages()).hasSize(1); + BpmnElementCheckMessage message = takeListenerFlow.getMessages().get(0); + assertThat(message).isNotNull(); + assertThat(message.getMessage()) + .isEqualTo( + "Listener at 'take' with implementation 'class' 'abc.def' cannot be transformed."); + } } diff --git a/backend-diagram-converter/core/src/test/java/org/camunda/community/migration/converter/message/MessageFactoryTest.java b/backend-diagram-converter/core/src/test/java/org/camunda/community/migration/converter/message/MessageFactoryTest.java index bbe2c793..f8050282 100644 --- a/backend-diagram-converter/core/src/test/java/org/camunda/community/migration/converter/message/MessageFactoryTest.java +++ b/backend-diagram-converter/core/src/test/java/org/camunda/community/migration/converter/message/MessageFactoryTest.java @@ -344,12 +344,13 @@ void shouldBuildDecisionRef() { @Test void shouldBuildExecutionListener() { - Message message = MessageFactory.executionListener("start", "${myExecutionListener}"); + Message message = + MessageFactory.executionListener("start", "delegateExpression", "${myExecutionListener}"); assertNotNull(message); assertNotNull(message.getMessage()); assertThat(message.getMessage()) .isEqualTo( - "Listener at 'start' with implementation '${myExecutionListener}' cannot be transformed. Execution Listeners do not exist before Zeebe 8.6."); + "Listener at 'start' with implementation 'delegateExpression' '${myExecutionListener}' cannot be transformed."); } @Test diff --git a/backend-diagram-converter/core/src/test/resources/take-listener.bpmn b/backend-diagram-converter/core/src/test/resources/take-listener.bpmn new file mode 100644 index 00000000..f04dcd7a --- /dev/null +++ b/backend-diagram-converter/core/src/test/resources/take-listener.bpmn @@ -0,0 +1,30 @@ + + + + + takeListenerFlow + + + takeListenerFlow + + + + + + + + + + + + + + + + + + + + + +