Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use default result variable in dmn #1063

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package org.camunda.community.migration.converter.visitor.impl.activity;

import static org.camunda.community.migration.converter.NamespaceUri.*;

import org.camunda.bpm.model.xml.instance.DomElement;
import org.camunda.community.migration.converter.DomElementVisitorContext;
import org.camunda.community.migration.converter.NamespaceUri;
import org.camunda.community.migration.converter.convertible.BusinessRuleTaskConvertible;
import org.camunda.community.migration.converter.convertible.Convertible;
import org.camunda.community.migration.converter.convertible.ServiceTaskConvertible;
import org.camunda.community.migration.converter.version.SemanticVersion;
import org.camunda.community.migration.converter.visitor.AbstractActivityVisitor;

public class BusinessRuleTaskVisitor extends AbstractActivityVisitor {
public static boolean isDmnImplementation(DomElementVisitorContext context) {
return context.getElement().getAttribute(CAMUNDA, "decisionRef") != null;
}

@Override
public String localName() {
return "businessRuleTask";
Expand All @@ -28,7 +34,16 @@ protected SemanticVersion availableFrom(DomElementVisitorContext context) {
return SemanticVersion._8_0;
}

public static boolean isDmnImplementation(DomElementVisitorContext context) {
return context.getElement().getAttribute(NamespaceUri.CAMUNDA, "decisionRef") != null;
@Override
protected void postCreationVisitor(DomElementVisitorContext context) {
if (isDmnImplementation(context) && !hasDecisionResult(context.getElement())) {
context.addConversion(
BusinessRuleTaskConvertible.class,
br -> br.getZeebeCalledDecision().setResultVariable("decisionResult"));
}
}

private boolean hasDecisionResult(DomElement element) {
return element.hasAttribute(CAMUNDA, "resultVariable");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,22 @@ void testCalledElementRefDeploymentBindingConversion() {
.isEqualTo("deployment");
}

@Test
void testDefaultResultVariable() {
BpmnModelInstance modelInstance = loadAndConvert("default-result-variable.bpmn");
DomElement businessRuleTask = modelInstance.getDocument().getElementById("businessRuleTask");
assertThat(businessRuleTask).isNotNull();
assertThat(businessRuleTask.getChildElementsByNameNs(BPMN, "extensionElements")).hasSize(1);
DomElement extensionElements =
businessRuleTask.getChildElementsByNameNs(BPMN, "extensionElements").get(0);
assertThat(extensionElements).isNotNull();
DomElement calledDecision =
extensionElements.getChildElementsByNameNs(ZEEBE, "calledDecision").get(0);
assertThat(calledDecision).isNotNull();
String resultVariable = calledDecision.getAttribute(ZEEBE, "resultVariable");
assertThat(resultVariable).isNotNull().isEqualTo("decisionResult");
}

@Test
void testGatewayExecutionListenerShouldBeTransformed() {
BpmnModelInstance modelInstance = loadAndConvert("gateway-with-el.bpmn");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_19lhbqh" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.29.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.22.0">
<bpmn:process id="Process_1tv5u8h" isExecutable="true">
<bpmn:businessRuleTask id="businessRuleTask" camunda:decisionRef="awdawd" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1tv5u8h">
<bpmndi:BPMNShape id="Activity_1rmt9rj_di" bpmnElement="businessRuleTask">
<dc:Bounds x="170" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Loading