Skip to content

Commit

Permalink
fix: take listener are not respected (#1081)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlukas authored Dec 16, 2024
1 parent df04d5c commit e290194
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0cqrrmo" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.30.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.22.0">
<bpmn:process id="Process_0wmzg2z" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>takeListenerFlow</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:endEvent id="Event_1ak6z4s">
<bpmn:incoming>takeListenerFlow</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="takeListenerFlow" sourceRef="StartEvent_1" targetRef="Event_1ak6z4s">
<bpmn:extensionElements>
<camunda:executionListener class="abc.def" event="take" />
</bpmn:extensionElements>
</bpmn:sequenceFlow>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0wmzg2z">
<bpmndi:BPMNShape id="StartEvent_1_di" bpmnElement="StartEvent_1">
<dc:Bounds x="182" y="82" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1ak6z4s_di" bpmnElement="Event_1ak6z4s">
<dc:Bounds x="272" y="82" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1gqasw7_di" bpmnElement="takeListenerFlow">
<di:waypoint x="218" y="100" />
<di:waypoint x="272" y="100" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

0 comments on commit e290194

Please sign in to comment.