Skip to content

Commit d50ab76

Browse files
add support for xmlXPathExpression for tenant id detection
1 parent bd8b5d5 commit d50ab76

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

modules/flowable-event-registry-model/src/main/java/org/flowable/eventregistry/model/ChannelEventTenantIdDetection.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class ChannelEventTenantIdDetection {
2626
protected String jsonPointerExpression;
2727
@JsonProperty("xPathExpression")
2828
protected String xPathExpression;
29+
protected String xmlXPathExpression;
2930
protected String delegateExpression;
3031

3132
public String getFixedValue() {
@@ -46,11 +47,15 @@ public String getxPathExpression() {
4647
public void setxPathExpression(String xPathExpression) {
4748
this.xPathExpression = xPathExpression;
4849
}
49-
50+
public String getXmlXPathExpression() {
51+
return xmlXPathExpression;
52+
}
53+
public void setXmlXPathExpression(String xmlXPathExpression) {
54+
this.xmlXPathExpression = xmlXPathExpression;
55+
}
5056
public String getDelegateExpression() {
5157
return delegateExpression;
5258
}
53-
5459
public void setDelegateExpression(String delegateExpression) {
5560
this.delegateExpression = delegateExpression;
5661
}

modules/flowable-event-registry/src/main/java/org/flowable/eventregistry/impl/pipeline/InboundChannelModelProcessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ protected InboundEventProcessingPipeline createXmlEventProcessingPipeline(Inboun
238238
if (channelEventTenantIdDetection != null) {
239239
if (StringUtils.isNotEmpty(channelEventTenantIdDetection.getFixedValue())) {
240240
eventTenantDetector = new InboundEventStaticTenantDetector<>(channelEventTenantIdDetection.getFixedValue());
241+
} else if (StringUtils.isNotEmpty(channelEventTenantIdDetection.getXmlXPathExpression())) {
242+
eventTenantDetector = new XpathBasedInboundEventTenantDetector(channelEventTenantIdDetection.getXmlXPathExpression());
241243
} else if (StringUtils.isNotEmpty(channelEventTenantIdDetection.getxPathExpression())) {
242244
eventTenantDetector = new XpathBasedInboundEventTenantDetector(channelEventTenantIdDetection.getxPathExpression());
243245
} else if (StringUtils.isNotEmpty(channelEventTenantIdDetection.getDelegateExpression())) {
@@ -246,7 +248,7 @@ protected InboundEventProcessingPipeline createXmlEventProcessingPipeline(Inboun
246248
} else {
247249
throw new FlowableException(
248250
"The channel xml tenant detection value was not found for the channel model with key " + channelModel.getKey()
249-
+ ". One of fixedValue, xPathExpression, delegateExpression should be set.");
251+
+ ". One of fixedValue, xmlPathExpression (or xPathExpression), delegateExpression should be set.");
250252
}
251253
}
252254

modules/flowable-event-registry/src/test/java/org/flowable/eventregistry/test/deployment/DeploymentTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,31 @@ public void deployChannelsWithTenantDetection() {
9696
assertThat(((XpathBasedInboundEventTenantDetector) inboundEventProcessingPipeline.getInboundEventTenantDetector()).getXpathExpression())
9797
.isEqualTo("/data/tenantId");
9898
}
99+
100+
@Test
101+
@ChannelDeploymentAnnotation(resources = {
102+
"org/flowable/eventregistry/test/deployment/simpleChannelWithFixedTenant.channel",
103+
"org/flowable/eventregistry/test/deployment/simpleChannelWithJsonPointerTenant.channel",
104+
"org/flowable/eventregistry/test/deployment/simpleChannelWithXmlXPathTenant.channel"
105+
})
106+
public void deployChannelsWithXmlXpathTenantDetection() {
107+
InboundChannelModel channel1 = (InboundChannelModel) eventRegistryEngine.getEventRepositoryService().getChannelModelByKey("channel1");
108+
assertThat(((DefaultInboundEventProcessingPipeline) channel1.getInboundEventProcessingPipeline()).getInboundEventTenantDetector())
109+
.isInstanceOf(InboundEventStaticTenantDetector.class);
110+
111+
InboundChannelModel channel2 = (InboundChannelModel) eventRegistryEngine.getEventRepositoryService().getChannelModelByKey("channel2");
112+
DefaultInboundEventProcessingPipeline inboundEventProcessingPipeline = (DefaultInboundEventProcessingPipeline) channel2
113+
.getInboundEventProcessingPipeline();
114+
assertThat(inboundEventProcessingPipeline.getInboundEventTenantDetector()).isInstanceOf(JsonPointerBasedInboundEventTenantDetector.class);
115+
assertThat(((JsonPointerBasedInboundEventTenantDetector) inboundEventProcessingPipeline.getInboundEventTenantDetector()).getJsonPointerExpression())
116+
.isEqualTo("/tenantId");
117+
118+
InboundChannelModel channel3 = (InboundChannelModel) eventRegistryEngine.getEventRepositoryService().getChannelModelByKey("channel3");
119+
inboundEventProcessingPipeline = (DefaultInboundEventProcessingPipeline) channel3.getInboundEventProcessingPipeline();
120+
assertThat(inboundEventProcessingPipeline.getInboundEventTenantDetector()).isInstanceOf(XpathBasedInboundEventTenantDetector.class);
121+
assertThat(((XpathBasedInboundEventTenantDetector) inboundEventProcessingPipeline.getInboundEventTenantDetector()).getXpathExpression())
122+
.isEqualTo("/data/tenantId");
123+
}
99124

100125
@Test
101126
@EventDeploymentAnnotation(resources = "org/flowable/eventregistry/test/deployment/simpleEvent.event")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"key": "channel3",
3+
"category": "channel",
4+
"name": "My channel",
5+
"description": "My channel description",
6+
"channelType": "inbound",
7+
"type": "jms",
8+
"destination": "testQueue",
9+
"deserializerType": "xml",
10+
"channelEventKeyDetection": {
11+
"fixedValue": "myEvent"
12+
},
13+
"channelEventTenantIdDetection": {
14+
"xmlXPathExpression": "/data/tenantId"
15+
}
16+
}

0 commit comments

Comments
 (0)