Skip to content

Commit

Permalink
merge: #11160
Browse files Browse the repository at this point in the history
11160: [Backport stable/8.1] fix(engine): fix message transformer of extension elements r=korthout a=koevskinikola

## Description

Backport of #11074 to `stable/8.1`.

relates to #10962 #8521

Co-authored-by: skayliu <skay463@163.com>
  • Loading branch information
zeebe-bors-camunda[bot] and skayliu authored Dec 5, 2022
2 parents 886d044 + 91de863 commit 4ffe94d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
6 changes: 6 additions & 0 deletions bpmn-model/revapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
"matcher": "java-package",
"match": "io.camunda.zeebe.model.bpmn.validation.zeebe"
}
},
{
"ignore": true,
"code": "java.method.addedToInterface",
"new": "method java.util.Optional<T> io.camunda.zeebe.model.bpmn.Query<T extends org.camunda.bpm.model.xml.instance.ModelElementInstance>::findSingleResult()",
"justification": "add optional method findSingleResult() for the usage of get single result"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.camunda.zeebe.model.bpmn;

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import org.camunda.bpm.model.xml.instance.ModelElementInstance;
import org.camunda.bpm.model.xml.type.ModelElementType;
Expand All @@ -37,4 +38,6 @@ public interface Query<T extends ModelElementInstance> {
<V extends ModelElementInstance> Query<V> filterByType(Class<V> elementClass);

T singleResult();

Optional<T> findSingleResult();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import org.camunda.bpm.model.xml.instance.ModelElementInstance;
import org.camunda.bpm.model.xml.type.ModelElementType;
Expand All @@ -36,6 +37,7 @@ public QueryImpl(final Collection<T> collection) {
this.collection = collection;
}

@Override
public Stream<T> stream() {
return collection.stream();
}
Expand Down Expand Up @@ -72,11 +74,21 @@ public <V extends ModelElementInstance> Query<V> filterByType(final Class<V> ele

@Override
public T singleResult() {
if (collection.size() == 1) {
return collection.iterator().next();
final Optional<T> optionalSingleResult = findSingleResult();
if (optionalSingleResult.isPresent()) {
return optionalSingleResult.get();
} else {
throw new BpmnModelException(
"Collection expected to have <1> entry but has <" + collection.size() + ">");
}
}

@Override
public Optional<T> findSingleResult() {
if (collection.size() == 1) {
return Optional.of(collection.iterator().next());
} else {
return Optional.empty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.camunda.zeebe.model.bpmn.instance.ExtensionElements;
import io.camunda.zeebe.model.bpmn.instance.Message;
import io.camunda.zeebe.model.bpmn.instance.zeebe.ZeebeSubscription;
import java.util.Optional;

public final class MessageTransformer implements ModelElementTransformer<Message> {

Expand All @@ -35,12 +36,17 @@ public void transform(final Message element, final TransformContext context) {
final ExtensionElements extensionElements = element.getExtensionElements();

if (extensionElements != null) {
final ZeebeSubscription subscription =
extensionElements.getElementsQuery().filterByType(ZeebeSubscription.class).singleResult();
final Expression correlationKeyExpression =
expressionLanguage.parseExpression(subscription.getCorrelationKey());
final Optional<ZeebeSubscription> subscription =
extensionElements
.getElementsQuery()
.filterByType(ZeebeSubscription.class)
.findSingleResult();
if (subscription.isPresent()) {
final Expression correlationKeyExpression =
expressionLanguage.parseExpression(subscription.get().getCorrelationKey());

executableElement.setCorrelationKeyExpression(correlationKeyExpression);
executableElement.setCorrelationKeyExpression(correlationKeyExpression);
}
}

if (element.getName() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.camunda.zeebe.model.bpmn.BpmnModelInstance;
import io.camunda.zeebe.model.bpmn.builder.ProcessBuilder;
import io.camunda.zeebe.model.bpmn.instance.Message;
import io.camunda.zeebe.model.bpmn.instance.zeebe.ZeebeLoopCharacteristics;
import io.camunda.zeebe.protocol.record.Assertions;
import io.camunda.zeebe.protocol.record.Record;
import io.camunda.zeebe.protocol.record.RecordType;
Expand Down Expand Up @@ -467,6 +468,28 @@ public void shouldNotFilterWithRollbackToPreviousVersion() {
findProcess(originalProcesses, processId), findProcess(repeatedProcesses, processId));
}

@Test
public void shouldCreateDeploymentWithMessageStartEventIgnoreExtensionElements() {
// given
final BpmnModelInstance modelInstance =
Bpmn.createExecutableProcess("processId")
.startEvent("startEvent")
.messageEventDefinition()
.message("messageEvent")
.addExtensionElement(
ZeebeLoopCharacteristics.class, z -> z.setInputCollection("= inputs"))
.messageEventDefinitionDone()
.endEvent()
.done();

// when
final Record<DeploymentRecordValue> deployment =
ENGINE.deployment().withXmlResource(modelInstance).deploy();

// then
assertThat(deployment.getIntent()).isEqualTo(DeploymentIntent.CREATED);
}

private ProcessMetadataValue findProcess(
final List<ProcessMetadataValue> processes, final String processId) {
return processes.stream()
Expand Down

0 comments on commit 4ffe94d

Please sign in to comment.