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 1658a501..0f7daaf7 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 @@ -3,29 +3,38 @@ import org.camunda.community.migration.converter.DomElementVisitorContext; import org.camunda.community.migration.converter.NamespaceUri; import org.camunda.community.migration.converter.message.Message; +import org.camunda.community.migration.converter.visitor.AbstractListenerVisitor.ListenerImplementation.ClassImplementation; +import org.camunda.community.migration.converter.visitor.AbstractListenerVisitor.ListenerImplementation.DelegateExpressionImplementation; +import org.camunda.community.migration.converter.visitor.AbstractListenerVisitor.ListenerImplementation.ExpressionImplementation; +import org.camunda.community.migration.converter.visitor.AbstractListenerVisitor.ListenerImplementation.ScriptImplementation; public abstract class AbstractListenerVisitor extends AbstractCamundaElementVisitor { @Override protected final Message visitCamundaElement(DomElementVisitorContext context) { - String implementation = findListenerImplementation(context); + ListenerImplementation implementation = findListenerImplementation(context); String event = context.getElement().getAttribute(NamespaceUri.CAMUNDA, "event"); return visitListener(context, event, implementation); } protected abstract Message visitListener( - DomElementVisitorContext context, String event, String implementation); + DomElementVisitorContext context, String event, ListenerImplementation implementation); - private String findListenerImplementation(DomElementVisitorContext context) { + private ListenerImplementation findListenerImplementation(DomElementVisitorContext context) { String listenerImplementation = context.getElement().getAttribute("delegateExpression"); - if (listenerImplementation == null) { - listenerImplementation = context.getElement().getAttribute("class"); + if (listenerImplementation != null) { + return new DelegateExpressionImplementation(listenerImplementation); } - if (listenerImplementation == null) { - listenerImplementation = context.getElement().getAttribute("expression"); + + listenerImplementation = context.getElement().getAttribute("class"); + if (listenerImplementation != null) { + return new ClassImplementation(listenerImplementation); + } + listenerImplementation = context.getElement().getAttribute("expression"); + if (listenerImplementation != null) { + return new ExpressionImplementation(listenerImplementation); } - if (listenerImplementation == null - && context.getElement().getChildElementsByNameNs(NamespaceUri.CAMUNDA, "script") != null + if (context.getElement().getChildElementsByNameNs(NamespaceUri.CAMUNDA, "script") != null && !context .getElement() .getChildElementsByNameNs(NamespaceUri.CAMUNDA, "script") @@ -36,7 +45,21 @@ private String findListenerImplementation(DomElementVisitorContext context) { .getChildElementsByNameNs(NamespaceUri.CAMUNDA, "script") .get(0) .getAttribute("scriptFormat"); + return new ScriptImplementation(listenerImplementation); } - return listenerImplementation; + throw new IllegalStateException("Unknown listener implementation"); + } + + protected sealed interface ListenerImplementation { + String implementation(); + + record DelegateExpressionImplementation(String implementation) + implements ListenerImplementation {} + + record ClassImplementation(String implementation) implements ListenerImplementation {} + + record ExpressionImplementation(String implementation) implements ListenerImplementation {} + + record ScriptImplementation(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 1160eee0..7a6ce219 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 @@ -8,6 +8,7 @@ import org.camunda.community.migration.converter.message.MessageFactory; import org.camunda.community.migration.converter.version.SemanticVersion; import org.camunda.community.migration.converter.visitor.AbstractListenerVisitor; +import org.camunda.community.migration.converter.visitor.AbstractListenerVisitor.ListenerImplementation.DelegateExpressionImplementation; public class ExecutionListenerVisitor extends AbstractListenerVisitor { @Override @@ -17,18 +18,23 @@ public String localName() { @Override protected Message visitListener( - DomElementVisitorContext context, String event, String implementation) { + DomElementVisitorContext context, String event, ListenerImplementation implementation) { if (isExecutionListenerSupported( SemanticVersion.parse(context.getProperties().getPlatformVersion()))) { ZeebeExecutionListener executionListener = new ZeebeExecutionListener(); executionListener.setEventType(EventType.valueOf(event)); - executionListener.setListenerType(implementation); + if(implementation instanceof DelegateExpressionImplementation){ + // TODO get the pattern as soon as its on the main + executionListener.setListenerType(); + }else{ + executionListener.setListenerType(implementation.implementation()); + } context.addConversion( AbstractExecutionListenerConvertible.class, c -> c.addZeebeExecutionListener(executionListener)); - return MessageFactory.executionListenerSupported(event, implementation); + return MessageFactory.executionListenerSupported(event, implementation.implementation()); } - return MessageFactory.executionListener(event, implementation); + return MessageFactory.executionListener(event, implementation.implementation()); } private boolean isExecutionListenerSupported(SemanticVersion version) {