Skip to content

Commit

Permalink
fix(engine): use static escalation code without evaluating expression
Browse files Browse the repository at this point in the history
Fix for #12326

When we transform the escalation and it's a static value, we would still evaluate the expression. This could result in
either a STRING or a NUMBER. As NUMBER wasn't a case that was implemented it would cause processes to be unable to find
 catch events.

If it's a static value we can just take the escalation code from the escalation event.

(cherry picked from commit efc4a56)
  • Loading branch information
remcowesterhoud authored and github-actions[bot] committed Apr 11, 2023
1 parent d7eba09 commit f560816
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
*/
package io.camunda.zeebe.engine.processing.deployment.model.transformer;

import io.camunda.zeebe.el.EvaluationResult;
import io.camunda.zeebe.el.Expression;
import io.camunda.zeebe.el.ExpressionLanguage;
import io.camunda.zeebe.el.ResultType;
import io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableEscalation;
import io.camunda.zeebe.engine.processing.deployment.model.transformation.ModelElementTransformer;
import io.camunda.zeebe.engine.processing.deployment.model.transformation.TransformContext;
Expand All @@ -35,13 +33,7 @@ public void transform(final Escalation element, final TransformContext context)

escalation.setEscalationCodeExpression(escalationCodeExpression);
if (escalationCodeExpression.isStatic()) {
final EvaluationResult escalationCodeResult =
expressionLanguage.evaluateExpression(escalationCodeExpression, variable -> null);

if (escalationCodeResult.getType() == ResultType.STRING) {
final String escalationCode = escalationCodeResult.getString();
escalation.setEscalationCode(BufferUtil.wrapString(escalationCode));
}
escalation.setEscalationCode(BufferUtil.wrapString(element.getEscalationCode()));
}
}
context.addEscalation(escalation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class EscalationEventTest {
private static final String TASK_ELEMENT_ID = "task";
private static final String PROCESS_ID = "wf";
private static final String ESCALATION_CODE = "ESCALATION";
private static final String ESCALATION_CODE_NUMBER = "404";
private static final String THROW_ELEMENT_ID = "throw";
private static final String CATCH_ELEMENT_ID = "catch";

Expand Down Expand Up @@ -155,6 +156,54 @@ public void shouldCatchEscalationOnBoundaryEventWithoutEscalationCode() {
assertIsEscalated(processInstanceKey, CATCH_ELEMENT_ID, THROW_ELEMENT_ID, ESCALATION_CODE);
}

@Test
public void shouldCatchEscalationOnBoundaryEventWithNumericEscalationCode() {
// Regression for https://github.com/camunda/zeebe/issues/12326
// given
final var process =
Bpmn.createExecutableProcess(PROCESS_ID)
.startEvent()
.subProcess(
"subprocess",
s ->
s.embeddedSubProcess()
.startEvent()
.intermediateThrowEvent(
THROW_ELEMENT_ID, i -> i.escalation(ESCALATION_CODE_NUMBER)))
.boundaryEvent(CATCH_ELEMENT_ID, AbstractBoundaryEventBuilder::escalation)
.manualTask(TASK_ELEMENT_ID)
.endEvent()
.done();
ENGINE.deployment().withXmlResource(process).deploy();

// when
final var processInstanceKey = ENGINE.processInstance().ofBpmnProcessId(PROCESS_ID).create();

// then
assertThat(
RecordingExporter.processInstanceRecords()
.withProcessInstanceKey(processInstanceKey)
.limitToProcessInstanceCompleted())
.extracting(r -> r.getValue().getBpmnElementType(), Record::getIntent)
.containsSubsequence(
tuple(BpmnElementType.SUB_PROCESS, ProcessInstanceIntent.ELEMENT_TERMINATING),
tuple(
BpmnElementType.INTERMEDIATE_THROW_EVENT,
ProcessInstanceIntent.ELEMENT_TERMINATING),
tuple(
BpmnElementType.INTERMEDIATE_THROW_EVENT, ProcessInstanceIntent.ELEMENT_TERMINATED),
tuple(BpmnElementType.SUB_PROCESS, ProcessInstanceIntent.ELEMENT_TERMINATED),
tuple(BpmnElementType.BOUNDARY_EVENT, ProcessInstanceIntent.ELEMENT_COMPLETING),
tuple(BpmnElementType.BOUNDARY_EVENT, ProcessInstanceIntent.ELEMENT_COMPLETED),
tuple(BpmnElementType.MANUAL_TASK, ProcessInstanceIntent.ELEMENT_COMPLETING),
tuple(BpmnElementType.MANUAL_TASK, ProcessInstanceIntent.ELEMENT_COMPLETED),
tuple(BpmnElementType.PROCESS, ProcessInstanceIntent.ELEMENT_COMPLETING),
tuple(BpmnElementType.PROCESS, ProcessInstanceIntent.ELEMENT_COMPLETED));

assertIsEscalated(
processInstanceKey, CATCH_ELEMENT_ID, THROW_ELEMENT_ID, ESCALATION_CODE_NUMBER);
}

@Test
public void shouldCatchEscalationInsideMultiInstanceSubprocess() {
// given
Expand Down

0 comments on commit f560816

Please sign in to comment.