Skip to content

Commit e922b4a

Browse files
add support for xmlXPathExpression for tenant id detection
1 parent fc63177 commit e922b4a

4 files changed

Lines changed: 51 additions & 3 deletions

File tree

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
@@ -24,6 +24,7 @@ public class ChannelEventTenantIdDetection {
2424
protected String fixedValue;
2525
protected String jsonPointerExpression;
2626
protected String xPathExpression;
27+
protected String xmlXPathExpression;
2728
protected String delegateExpression;
2829

2930
public String getFixedValue() {
@@ -44,11 +45,15 @@ public String getxPathExpression() {
4445
public void setxPathExpression(String xPathExpression) {
4546
this.xPathExpression = xPathExpression;
4647
}
47-
48+
public String getXmlXPathExpression() {
49+
return xmlXPathExpression;
50+
}
51+
public void setXmlXPathExpression(String xmlXPathExpression) {
52+
this.xmlXPathExpression = xmlXPathExpression;
53+
}
4854
public String getDelegateExpression() {
4955
return delegateExpression;
5056
}
51-
5257
public void setDelegateExpression(String delegateExpression) {
5358
this.delegateExpression = delegateExpression;
5459
}

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)