Skip to content

Commit

Permalink
feat: remove brackets on delegate expression listener
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlukas committed Nov 27, 2024
1 parent 2c1e98d commit 49cc2e7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 49cc2e7

Please sign in to comment.