Skip to content

Commit cf09503

Browse files
Add hookpoints to event registry for event payload types
1 parent db1e98c commit cf09503

26 files changed

Lines changed: 399 additions & 84 deletions

File tree

modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/behavior/impl/EventRegistryEventListenerActivityBehaviour.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.flowable.common.engine.impl.el.ExpressionManager;
4242
import org.flowable.common.engine.impl.interceptor.CommandContext;
4343
import org.flowable.eventregistry.api.runtime.EventInstance;
44+
import org.flowable.eventregistry.impl.EventRegistryEngineConfiguration;
4445
import org.flowable.eventregistry.impl.constant.EventConstants;
4546
import org.flowable.eventsubscription.service.EventSubscriptionService;
4647
import org.flowable.eventsubscription.service.impl.persistence.entity.EventSubscriptionEntity;
@@ -161,20 +162,23 @@ protected String getCorrelationKey(CommandContext commandContext, PlanItemInstan
161162
if (!eventCorrelations.isEmpty()) {
162163
CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);
163164
ExpressionManager expressionManager = cmmnEngineConfiguration.getExpressionManager();
164-
165+
166+
EventRegistryEngineConfiguration eventRegistryEngineConfiguration = CommandContextUtil.getEventRegistryEngineConfiguration(commandContext);
167+
165168
Map<String, Object> correlationParameters = new HashMap<>();
166169
for (ExtensionElement eventCorrelation : eventCorrelations) {
167170
String name = eventCorrelation.getAttributeValue(null, "name");
168171
String valueExpression = eventCorrelation.getAttributeValue(null, "value");
169172
if (StringUtils.isNotEmpty(valueExpression)) {
170173
Object value = expressionManager.createExpression(valueExpression).getValue(planItemInstanceEntity);
171-
correlationParameters.put(name, value);
174+
correlationParameters.put(name, eventRegistryEngineConfiguration.getCorrelationValueTransformer().transformRawValue(value));
172175
} else {
173176
correlationParameters.put(name, null);
174177
}
175178
}
176179

177-
correlationKey = CommandContextUtil.getEventRegistry().generateKey(correlationParameters);
180+
correlationKey = CommandContextUtil.getEventRegistry(commandContext).generateKey(correlationParameters);
181+
178182
} else {
179183
correlationKey = null;
180184
}

modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/util/CommandContextUtil.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,12 @@ public static EventRegistryEngineConfiguration getEventRegistryEngineConfigurati
319319
}
320320

321321
public static EventRegistry getEventRegistry() {
322+
return getEventRegistry(getCommandContext());
323+
}
324+
325+
public static EventRegistry getEventRegistry(CommandContext commandContext) {
322326
EventRegistry eventRegistry = null;
323-
EventRegistryEngineConfiguration eventRegistryEngineConfiguration = getEventRegistryEngineConfiguration();
327+
EventRegistryEngineConfiguration eventRegistryEngineConfiguration = getEventRegistryEngineConfiguration(commandContext);
324328
if (eventRegistryEngineConfiguration != null) {
325329
eventRegistry = eventRegistryEngineConfiguration.getEventRegistry();
326330
}

modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/el/JuelExpression.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public void setValue(Object value, VariableContainer variableContainer) {
7878

7979
try {
8080
resolveSetValueExpression(value, elContext);
81+
} catch (FlowableException ex) {
82+
throw ex;
8183
} catch (Exception e) {
8284
throw new FlowableException("Error while evaluating expression: " + expressionText + " with " + variableContainer, e);
8385
} finally {

modules/flowable-engine/src/main/java/org/flowable/engine/impl/util/CorrelationUtil.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.flowable.common.engine.impl.interceptor.CommandContext;
2424
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
2525
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
26+
import org.flowable.eventregistry.impl.EventRegistryEngineConfiguration;
2627

2728
public class CorrelationUtil {
2829

@@ -37,6 +38,8 @@ public static String getCorrelationKey(String elementName, CommandContext comman
3738
if (eventCorrelations != null && !eventCorrelations.isEmpty()) {
3839
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
3940
ExpressionManager expressionManager = processEngineConfiguration.getExpressionManager();
41+
42+
EventRegistryEngineConfiguration eventRegistryEngineConfiguration = CommandContextUtil.getEventRegistryEngineConfiguration(commandContext);
4043

4144
Map<String, Object> correlationParameters = new HashMap<>();
4245
for (ExtensionElement eventCorrelation : eventCorrelations) {
@@ -45,7 +48,8 @@ public static String getCorrelationKey(String elementName, CommandContext comman
4548
if (StringUtils.isNotEmpty(valueExpression)) {
4649
if (executionEntity != null) {
4750
Object value = expressionManager.createExpression(valueExpression).getValue(executionEntity);
48-
correlationParameters.put(name, value);
51+
correlationParameters.put(name, eventRegistryEngineConfiguration.getCorrelationValueTransformer().transformRawValue(value));
52+
4953
} else {
5054
correlationParameters.put(name, valueExpression);
5155
}
@@ -55,7 +59,7 @@ public static String getCorrelationKey(String elementName, CommandContext comman
5559
}
5660
}
5761

58-
correlationKey = CommandContextUtil.getEventRegistry().generateKey(correlationParameters);
62+
correlationKey = CommandContextUtil.getEventRegistry(commandContext).generateKey(correlationParameters);
5963
}
6064
}
6165

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* Licensed under the Apache License, Version 2.0 (the "License");
2+
* you may not use this file except in compliance with the License.
3+
* You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
package org.flowable.eventregistry.api;
14+
15+
import org.flowable.eventregistry.api.runtime.EventPayloadInstance;
16+
17+
public interface CorrelationValueTransformer {
18+
19+
Object transformValue(EventPayloadInstance correlationParameterInstance);
20+
21+
Object transformRawValue(Object value);
22+
}

modules/flowable-event-registry-api/src/main/java/org/flowable/eventregistry/api/InboundEventInfoAwarePayloadExtractor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
@FunctionalInterface
2424
public interface InboundEventInfoAwarePayloadExtractor<T> extends InboundEventPayloadExtractor<T> {
2525

26-
default Collection<EventPayloadInstance> extractPayload(EventModel eventModel, T payload) {
26+
@Override
27+
default Collection<EventPayloadInstance> extractPayload(EventModel eventModel, T payload, String parentDeploymentId, String tenantId) {
2728
throw new UnsupportedOperationException("Payload extraction should never call this ");
2829
}
2930

30-
Collection<EventPayloadInstance> extractPayload(EventModel eventModel, FlowableEventInfo<T> event);
31+
@Override
32+
Collection<EventPayloadInstance> extractPayload(EventModel eventModel, FlowableEventInfo<T> event, String parentDeploymentId, String tenantId);
3133

3234
}

modules/flowable-event-registry-api/src/main/java/org/flowable/eventregistry/api/InboundEventPayloadExtractor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
@FunctionalInterface
2525
public interface InboundEventPayloadExtractor<T> {
2626

27-
Collection<EventPayloadInstance> extractPayload(EventModel eventModel, T payload);
27+
Collection<EventPayloadInstance> extractPayload(EventModel eventModel, T payload, String parentDeploymentId, String tenantId);
2828

29-
default Collection<EventPayloadInstance> extractPayload(EventModel eventModel, FlowableEventInfo<T> event) {
30-
return extractPayload(eventModel, event.getPayload());
29+
default Collection<EventPayloadInstance> extractPayload(EventModel eventModel, FlowableEventInfo<T> event, String parentDeploymentId, String tenantId) {
30+
return extractPayload(eventModel, event.getPayload(), parentDeploymentId, tenantId);
3131
}
3232

3333
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* Licensed under the Apache License, Version 2.0 (the "License");
2+
* you may not use this file except in compliance with the License.
3+
* You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
package org.flowable.eventregistry.api;
14+
15+
import org.flowable.eventregistry.model.EventPayload;
16+
17+
import com.fasterxml.jackson.databind.JsonNode;
18+
19+
public interface JsonPayloadValueTransformer {
20+
21+
Object transformValue(JsonNode parameterNode, String definitionType, EventPayload eventPayload, String parentDeploymentId, String tenantId);
22+
}

modules/flowable-event-registry-json-converter/src/main/java/org/flowable/eventregistry/json/converter/EventJsonConverter.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
package org.flowable.eventregistry.json.converter;
1414

1515
import java.util.Collection;
16+
import java.util.HashMap;
17+
import java.util.Iterator;
18+
import java.util.Map;
1619

1720
import org.flowable.eventregistry.model.EventModel;
1821
import org.flowable.eventregistry.model.EventPayload;
@@ -53,6 +56,8 @@ public EventModel convertToEventModel(String modelJson) {
5356
payload.setHeader(node.path("header").asBoolean(false));
5457
payload.setMetaParameter(node.path("metaParameter").asBoolean(false));
5558
}
59+
60+
processExtensionProperties(node, payload);
5661

5762
eventModel.addPayload(payload);
5863
}
@@ -63,7 +68,9 @@ public EventModel convertToEventModel(String modelJson) {
6368
for (JsonNode correlationPayloadNode : correlationParameters) {
6469
String name = correlationPayloadNode.path("name").asText(null);
6570
String type = correlationPayloadNode.path("type").asText(null);
66-
eventModel.addCorrelation(name, type);
71+
EventPayload payload = eventModel.addCorrelation(name, type);
72+
73+
processExtensionProperties(correlationPayloadNode, payload);
6774
}
6875
}
6976

@@ -113,6 +120,13 @@ public String convertToJson(EventModel definition) {
113120
if (eventPayload.isMetaParameter()) {
114121
eventPayloadNode.put("metaParameter", true);
115122
}
123+
124+
if (eventPayload.getExtensionProperties() != null && !eventPayload.getExtensionProperties().isEmpty()) {
125+
ObjectNode extensionPropNode = eventPayloadNode.putObject("extensionProperties");
126+
for (String propName : eventPayload.getExtensionProperties().keySet()) {
127+
extensionPropNode.put(propName, eventPayload.getExtensionProperties().get(propName));
128+
}
129+
}
116130
}
117131
}
118132

@@ -122,4 +136,18 @@ public String convertToJson(EventModel definition) {
122136
throw new FlowableEventJsonException("Error writing event json", e);
123137
}
124138
}
139+
140+
protected void processExtensionProperties(JsonNode node, EventPayload payload) {
141+
JsonNode extensionNodes = node.path("extensionProperties");
142+
if (extensionNodes != null && !extensionNodes.isMissingNode()) {
143+
Map<String, String> extensionPropertyMap = new HashMap<>();
144+
Iterator<String> propertyNames = extensionNodes.fieldNames();
145+
while (propertyNames.hasNext()) {
146+
String extensionName = propertyNames.next();
147+
extensionPropertyMap.put(extensionName, extensionNodes.get(extensionName).asText());
148+
}
149+
150+
payload.setExtensionProperties(extensionPropertyMap);
151+
}
152+
}
125153
}

modules/flowable-event-registry-json-converter/src/test/java/org/flowable/eventregistry/converter/EventJsonConverterTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import java.io.InputStream;
2121
import java.nio.charset.StandardCharsets;
22+
import java.util.Iterator;
2223

2324
import org.apache.commons.io.IOUtils;
2425
import org.flowable.eventregistry.json.converter.EventJsonConverter;
@@ -35,6 +36,7 @@ public class EventJsonConverterTest {
3536

3637
private static final String JSON_RESOURCE_1 = "org/flowable/eventregistry/converter/simpleEvent.json";
3738
private static final String JSON_RESOURCE_2 = "org/flowable/eventregistry/converter/simpleEventCorrelationPayload.json";
39+
private static final String JSON_RESOURCE_3 = "org/flowable/eventregistry/converter/simpleEventWithExtensionProperties.json";
3840

3941
private static final ObjectMapper objectMapper = new ObjectMapper();
4042

@@ -63,6 +65,50 @@ public void testCorrelationPayloadModelToJson() {
6365
EventModel parsedEventModel = exportAndReadModel(eventModel);
6466
validateSimpleEventModel(parsedEventModel);
6567
}
68+
69+
@Test
70+
public void testExtensionProperties() {
71+
EventModel eventModel = readJson(JSON_RESOURCE_3);
72+
EventModel parsedEventModel = exportAndReadModel(eventModel);
73+
74+
assertThat(parsedEventModel.getCorrelationParameters()).hasSize(1);
75+
EventPayload correlationPayloadProperty = parsedEventModel.getCorrelationParameters().iterator().next();
76+
assertThat(correlationPayloadProperty.getName()).isEqualTo("customerId");
77+
assertThat(correlationPayloadProperty.getType()).isEqualTo("string");
78+
assertThat(correlationPayloadProperty.getExtensionProperties()).hasSize(2);
79+
80+
assertThat(correlationPayloadProperty.getExtensionProperties().get("prop1")).isEqualTo("test1");
81+
assertThat(correlationPayloadProperty.getExtensionProperties().get("prop2")).isEqualTo("num2");
82+
83+
assertThat(parsedEventModel.getPayload())
84+
.extracting(EventPayload::getName, EventPayload::getType)
85+
.containsExactly(
86+
tuple("payload1", "string"),
87+
tuple("payload2", "integer"),
88+
tuple("customerId", "string")
89+
);
90+
91+
Iterator<EventPayload> itPayload = parsedEventModel.getPayload().iterator();
92+
EventPayload payloadItem = itPayload.next();
93+
assertThat(payloadItem.getName()).isEqualTo("payload1");
94+
assertThat(payloadItem.getExtensionProperties()).hasSize(2);
95+
96+
assertThat(payloadItem.getExtensionProperties().get("payload1Prop1")).isEqualTo("test3");
97+
assertThat(payloadItem.getExtensionProperties().get("payload1Prop2")).isEqualTo("num4");
98+
99+
payloadItem = itPayload.next();
100+
assertThat(payloadItem.getName()).isEqualTo("payload2");
101+
assertThat(payloadItem.getExtensionProperties()).hasSize(1);
102+
103+
assertThat(payloadItem.getExtensionProperties().get("payload2Prop1")).isEqualTo("test5");
104+
105+
payloadItem = itPayload.next();
106+
assertThat(payloadItem.getName()).isEqualTo("customerId");
107+
assertThat(payloadItem.getExtensionProperties()).hasSize(2);
108+
109+
assertThat(payloadItem.getExtensionProperties().get("prop1")).isEqualTo("test1");
110+
assertThat(payloadItem.getExtensionProperties().get("prop2")).isEqualTo("num2");
111+
}
66112

67113
protected void validateSimpleEventModel(EventModel eventModel) {
68114
assertThat(eventModel).isNotNull();

0 commit comments

Comments
 (0)