Skip to content

Commit

Permalink
Bugfix: message ref on send events (#847)
Browse files Browse the repository at this point in the history
* removing an attribute is context-sensitive now

* helpful methods on abstract class for re-use

* remove message ref if on message throw or end event

* test to assert that message refs are removed from throw and end event

* formatter
  • Loading branch information
jonathanlukas authored Apr 8, 2024
1 parent 6696c8a commit a85ef0e
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public abstract class AbstractAttributeVisitor extends AbstractFilteringVisitor
protected void visitFilteredElement(DomElementVisitorContext context) {
String attribute = context.getElement().getAttribute(namespaceUri(), attributeLocalName());
visitAttribute(context, attribute);
if (removeAttribute()) {
if (removeAttribute(context)) {
context.addAttributeToRemove(attributeLocalName(), namespaceUri());
}
}
Expand All @@ -29,7 +29,7 @@ protected boolean canVisit(DomElementVisitorContext context) {

protected abstract void visitAttribute(DomElementVisitorContext context, String attribute);

protected abstract boolean removeAttribute();
protected abstract boolean removeAttribute(DomElementVisitorContext context);

@Override
protected void logVisit(DomElementVisitorContext context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.camunda.community.migration.converter.visitor;

import org.camunda.community.migration.converter.DomElementVisitorContext;
import org.camunda.community.migration.converter.NamespaceUri;

public abstract class AbstractBpmnAttributeVisitor extends AbstractAttributeVisitor {
Expand All @@ -9,7 +10,7 @@ protected String namespaceUri() {
}

@Override
protected boolean removeAttribute() {
protected boolean removeAttribute(DomElementVisitorContext context) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ protected String namespaceUri() {
return NamespaceUri.CAMUNDA;
}

protected boolean removeAttribute() {
protected boolean removeAttribute(DomElementVisitorContext context) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.camunda.community.migration.converter.visitor;

import org.camunda.bpm.model.xml.instance.DomElement;
import org.camunda.community.migration.converter.DomElementVisitorContext;

public abstract class AbstractEventRefVisitor extends AbstractBpmnAttributeVisitor {
Expand All @@ -8,4 +9,12 @@ public abstract class AbstractEventRefVisitor extends AbstractBpmnAttributeVisit
protected void visitAttribute(DomElementVisitorContext context, String attribute) {
context.references(attribute);
}

protected boolean isEndEvent(DomElement element) {
return element.getParentElement().getLocalName().equals("endEvent");
}

protected boolean isIntermediateThrowEvent(DomElement element) {
return element.getParentElement().getLocalName().equals("intermediateThrowEvent");
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
package org.camunda.community.migration.converter.visitor.impl;

import org.camunda.community.migration.converter.DomElementVisitorContext;
import org.camunda.community.migration.converter.visitor.AbstractEventRefVisitor;

public class MessageRefVisitor extends AbstractEventRefVisitor {
@Override
public String attributeLocalName() {
return "messageRef";
}

@Override
protected boolean removeAttribute(DomElementVisitorContext context) {
if (isEndEvent(context.getElement()) || isIntermediateThrowEvent(context.getElement())) {
return true;
}
return false;
}

@Override
protected void visitAttribute(DomElementVisitorContext context, String attribute) {
if (isEndEvent(context.getElement()) || isIntermediateThrowEvent(context.getElement())) {
return;
}
super.visitAttribute(context, attribute);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public class BpmnConverterTest {
"collaboration.bpmn",
"empty-input-parameter.bpmn",
"flexible-timer-event.bpmn",
"business-rule-task-as-expression.bpmn"
"business-rule-task-as-expression.bpmn",
"message-event-definition-handling.bpmn"
})
public void shouldConvert(String bpmnFile) {
BpmnConverter converter = BpmnConverterFactory.getInstance().get();
Expand Down Expand Up @@ -559,4 +560,38 @@ void testEscalationCode() {
assertThat(escalation.getAttribute(BPMN, "name")).isEqualTo("EscalationName");
assertThat(escalation.getAttribute(BPMN, "escalationCode")).isEqualTo("EscalationCode");
}

@Test
void testMessageEventDefinitionOnThrowEvents() {
BpmnModelInstance modelInstance = loadAndConvert("message-event-definition-handling.bpmn");
DomElement catchEvent = modelInstance.getDocument().getElementById("CatchEvent");
DomElement throwEvent = modelInstance.getDocument().getElementById("ThrowEvent");
DomElement endEvent = modelInstance.getDocument().getElementById("EndEndEvent");
DomElement message = modelInstance.getDocument().getElementById("Message_1o49fvh");
assertThat(catchEvent).isNotNull();
assertThat(throwEvent).isNotNull();
assertThat(endEvent).isNotNull();
assertThat(message).isNotNull();
assertThat(throwEvent.getChildElementsByNameNs(BPMN, "extensionElements")).isEmpty();
assertThat(endEvent.getChildElementsByNameNs(BPMN, "extensionElements")).isEmpty();
assertThat(catchEvent.getChildElementsByNameNs(BPMN, "extensionElements")).hasSize(1);
assertThat(message.getChildElementsByNameNs(BPMN, "extensionElements")).hasSize(1);
assertThat(throwEvent.getChildElementsByNameNs(BPMN, "messageEventDefinition")).hasSize(1);
assertThat(endEvent.getChildElementsByNameNs(BPMN, "messageEventDefinition")).hasSize(1);
assertThat(catchEvent.getChildElementsByNameNs(BPMN, "messageEventDefinition")).hasSize(1);
assertThat(
message
.getChildElementsByNameNs(BPMN, "extensionElements")
.get(0)
.getChildElementsByNameNs(CONVERSION, "referencedBy"))
.hasSize(1);
assertThat(
message
.getChildElementsByNameNs(BPMN, "extensionElements")
.get(0)
.getChildElementsByNameNs(CONVERSION, "referencedBy")
.get(0)
.getTextContent())
.isEqualTo("CatchEvent");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_04vagz4" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.21.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.20.0">
<bpmn:process id="Process_114gj9f" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_19kxilc</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_19kxilc" sourceRef="StartEvent_1" targetRef="ThrowEvent" />
<bpmn:sequenceFlow id="Flow_1sazhdd" sourceRef="ThrowEvent" targetRef="CatchEvent" />
<bpmn:sequenceFlow id="Flow_1xxrrri" sourceRef="CatchEvent" targetRef="EndEndEvent" />
<bpmn:intermediateThrowEvent id="ThrowEvent" name="throw">
<bpmn:incoming>Flow_19kxilc</bpmn:incoming>
<bpmn:outgoing>Flow_1sazhdd</bpmn:outgoing>
<bpmn:messageEventDefinition id="MessageEventDefinition_0xo656s" messageRef="Message_1o49fvh" />
</bpmn:intermediateThrowEvent>
<bpmn:intermediateCatchEvent id="CatchEvent" name="catch">
<bpmn:incoming>Flow_1sazhdd</bpmn:incoming>
<bpmn:outgoing>Flow_1xxrrri</bpmn:outgoing>
<bpmn:messageEventDefinition id="MessageEventDefinition_0g26sho" messageRef="Message_1o49fvh" />
</bpmn:intermediateCatchEvent>
<bpmn:endEvent id="EndEndEvent" name="end">
<bpmn:incoming>Flow_1xxrrri</bpmn:incoming>
<bpmn:messageEventDefinition id="MessageEventDefinition_0vjwv1l" messageRef="Message_1o49fvh" />
</bpmn:endEvent>
</bpmn:process>
<bpmn:message id="Message_1o49fvh" name="msg" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_114gj9f">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="79" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1j8fv5i_di" bpmnElement="ThrowEvent">
<dc:Bounds x="272" y="79" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="277" y="122" width="27" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0mll5rm_di" bpmnElement="CatchEvent">
<dc:Bounds x="372" y="79" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="377" y="122" width="27" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_05qb7s8_di" bpmnElement="EndEndEvent">
<dc:Bounds x="472" y="79" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="481" y="122" width="19" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_19kxilc_di" bpmnElement="Flow_19kxilc">
<di:waypoint x="215" y="97" />
<di:waypoint x="272" y="97" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1sazhdd_di" bpmnElement="Flow_1sazhdd">
<di:waypoint x="308" y="97" />
<di:waypoint x="372" y="97" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1xxrrri_di" bpmnElement="Flow_1xxrrri">
<di:waypoint x="408" y="97" />
<di:waypoint x="472" y="97" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

0 comments on commit a85ef0e

Please sign in to comment.