Skip to content

Commit d190b4d

Browse files
committed
Add event filter after key detection, as the key is often used in filtering
1 parent d8f57c0 commit d190b4d

File tree

5 files changed

+88
-94
lines changed

5 files changed

+88
-94
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ public interface InboundEventFilter<T> {
2828
* Returns true, if the event should be further processed
2929
* or false if the event should be ignored and will not be processed any further.
3030
*
31+
* @param eventDefinitionKey the key for the inbound event
3132
* @param event the inbound event information
3233
* @return true, if the event should continue to be processed, false, if the pipeline will ignore the event and stop any
3334
* further processing
3435
*/
35-
boolean retain(FlowableEventInfo<T> event);
36+
boolean retain(String eventDefinitionKey, FlowableEventInfo<T> event);
3637

3738
}

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

+51-51
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,17 @@ interface InboundEventProcessingPipelineBuilder {
207207
/**
208208
* Deserializes the event to JSON.
209209
*/
210-
InboundEventFilterJsonBuilder jsonDeserializer();
210+
InboundEventKeyJsonDetectorBuilder jsonDeserializer();
211211

212212
/**
213213
* Deserializes the event to XML.
214214
*/
215-
InboundEventFilterXmlBuilder xmlDeserializer();
215+
InboundEventKeyXmlDetectorBuilder xmlDeserializer();
216216

217217
/**
218218
* Uses a delegate expression to deserialize the event.
219219
*/
220-
InboundEventFilterBuilder delegateExpressionDeserializer(String delegateExpression);
220+
InboundEventKeyDetectorBuilder delegateExpressionDeserializer(String delegateExpression);
221221

222222
/**
223223
* Uses a delegate expression to determine the custom {@link InboundEventProcessingPipeline} instance.
@@ -226,48 +226,6 @@ interface InboundEventProcessingPipelineBuilder {
226226

227227
}
228228

229-
/**
230-
* Builder for the filtering out inbound JSON events.
231-
* If events are filtered out, the pipeline processing will stop there and no subsequent steps will be executed.
232-
*/
233-
interface InboundEventFilterJsonBuilder extends InboundEventKeyJsonDetectorBuilder { // Extends because using filtering is optional
234-
235-
/**
236-
* Uses a delegate expression to filter the events before further processing.
237-
* The expression needs to resolve to a bean implementing the {@link org.flowable.eventregistry.api.InboundEventFilter} interface.
238-
*/
239-
InboundEventKeyJsonDetectorBuilder delegateExpressionEventFilter(String delegateExpression);
240-
241-
}
242-
243-
/**
244-
* Builder for the filtering out inbound XML events.
245-
* If events are filtered out, the pipeline processing will stop there and no subsequent steps will be executed.
246-
*/
247-
interface InboundEventFilterXmlBuilder extends InboundEventKeyXmlDetectorBuilder { // Extends because using filtering is optional
248-
249-
/**
250-
* Uses a delegate expression to filter the events before further processing.
251-
* The expression needs to resolve to a bean implementing the {@link org.flowable.eventregistry.api.InboundEventFilter} interface.
252-
*/
253-
InboundEventKeyXmlDetectorBuilder delegateExpressionEventFilter(String delegateExpression);
254-
255-
}
256-
257-
/**
258-
* Builder for the filtering out inbound events.
259-
* If events are filtered out, the pipeline processing will stop there and no subsequent steps will be executed.
260-
*/
261-
interface InboundEventFilterBuilder extends InboundEventKeyDetectorBuilder { // Extends because using filtering is optional
262-
263-
/**
264-
* Uses a delegate expression to filter the events before further processing.
265-
* The expression needs to resolve to a bean implementing the {@link org.flowable.eventregistry.api.InboundEventFilter} interface.
266-
*/
267-
InboundEventKeyDetectorBuilder delegateExpressionEventFilter(String delegateExpression);
268-
269-
}
270-
271229
/**
272230
* Builder for the 'key detection' part of the {@link InboundChannelModel}, specifically for JSON events.
273231
*/
@@ -276,17 +234,17 @@ interface InboundEventKeyJsonDetectorBuilder {
276234
/**
277235
* Sets the event key to a hardcoded value. This is useful when the channel only receives one type of event.
278236
*/
279-
InboundEventTenantJsonDetectorBuilder fixedEventKey(String key);
237+
InboundEventFilterJsonBuilder fixedEventKey(String key);
280238

281239
/**
282240
* Determines the key of the event based on a top-level field in the JSON representation in the event.
283241
*/
284-
InboundEventTenantJsonDetectorBuilder detectEventKeyUsingJsonField(String field);
242+
InboundEventFilterJsonBuilder detectEventKeyUsingJsonField(String field);
285243

286244
/**
287245
* Determines the key of the event using on a JSON Pointer expression to find the value.
288246
*/
289-
InboundEventTenantJsonDetectorBuilder detectEventKeyUsingJsonPointerExpression(String jsonPointerExpression);
247+
InboundEventFilterJsonBuilder detectEventKeyUsingJsonPointerExpression(String jsonPointerExpression);
290248

291249
}
292250

@@ -315,12 +273,12 @@ interface InboundEventKeyXmlDetectorBuilder {
315273
/**
316274
* Sets the event key to a hardcoded value. This is useful when the channel only receives one type of event.
317275
*/
318-
InboundEventTenantXmlDetectorBuilder fixedEventKey(String key);
276+
InboundEventFilterXmlBuilder fixedEventKey(String key);
319277

320278
/**
321279
* Determines the key of the event using on a XPATH expression to find the value.
322280
*/
323-
InboundEventTenantXmlDetectorBuilder detectEventKeyUsingXPathExpression(String xPathExpression);
281+
InboundEventFilterXmlBuilder detectEventKeyUsingXPathExpression(String xPathExpression);
324282

325283
}
326284

@@ -349,7 +307,49 @@ interface InboundEventKeyDetectorBuilder {
349307
/**
350308
* Uses delegate expression to determine the custom {@link InboundEventKeyDetector}.
351309
*/
352-
InboundEventTenantDetectorBuilder delegateExpressionKeyDetector(String delegateExpression);
310+
InboundEventFilterBuilder delegateExpressionKeyDetector(String delegateExpression);
311+
312+
}
313+
314+
/**
315+
* Builder for the filtering out inbound JSON events.
316+
* If events are filtered out, the pipeline processing will stop there and no subsequent steps will be executed.
317+
*/
318+
interface InboundEventFilterJsonBuilder extends InboundEventTenantJsonDetectorBuilder { // Extends because using filtering is optional
319+
320+
/**
321+
* Uses a delegate expression to filter the events before further processing.
322+
* The expression needs to resolve to a bean implementing the {@link org.flowable.eventregistry.api.InboundEventFilter} interface.
323+
*/
324+
InboundEventTenantJsonDetectorBuilder delegateExpressionEventFilter(String delegateExpression);
325+
326+
}
327+
328+
/**
329+
* Builder for the filtering out inbound XML events.
330+
* If events are filtered out, the pipeline processing will stop there and no subsequent steps will be executed.
331+
*/
332+
interface InboundEventFilterXmlBuilder extends InboundEventTenantXmlDetectorBuilder { // Extends because using filtering is optional
333+
334+
/**
335+
* Uses a delegate expression to filter the events before further processing.
336+
* The expression needs to resolve to a bean implementing the {@link org.flowable.eventregistry.api.InboundEventFilter} interface.
337+
*/
338+
InboundEventTenantXmlDetectorBuilder delegateExpressionEventFilter(String delegateExpression);
339+
340+
}
341+
342+
/**
343+
* Builder for the filtering out inbound events.
344+
* If events are filtered out, the pipeline processing will stop there and no subsequent steps will be executed.
345+
*/
346+
interface InboundEventFilterBuilder extends InboundEventTenantDetectorBuilder { // Extends because using filtering is optional
347+
348+
/**
349+
* Uses a delegate expression to filter the events before further processing.
350+
* The expression needs to resolve to a bean implementing the {@link org.flowable.eventregistry.api.InboundEventFilter} interface.
351+
*/
352+
InboundEventTenantDetectorBuilder delegateExpressionEventFilter(String delegateExpression);
353353

354354
}
355355

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

+28-35
Original file line numberDiff line numberDiff line change
@@ -320,34 +320,34 @@ public InboundEventProcessingPipelineBuilderImpl(InboundChannelModel channelMode
320320
}
321321

322322
@Override
323-
public InboundEventFilterJsonBuilder jsonDeserializer() {
323+
public InboundEventKeyJsonDetectorBuilder jsonDeserializer() {
324324
channelModel.setDeserializerType("json");
325325

326326
InboundEventProcessingPipelineBuilderImpl<JsonNode> jsonPipelineBuilder
327327
= new InboundEventProcessingPipelineBuilderImpl<>(channelModel, eventRepository, channelDefinitionBuilder);
328328
this.channelDefinitionBuilder.inboundEventProcessingPipelineBuilder = jsonPipelineBuilder;
329329

330-
return new InboundEventFilterJsonBuilderImpl(jsonPipelineBuilder);
330+
return new InboundEventKeyJsonDetectorBuilderImpl(jsonPipelineBuilder);
331331
}
332332

333333
@Override
334-
public InboundEventFilterXmlBuilder xmlDeserializer() {
334+
public InboundEventKeyXmlDetectorBuilder xmlDeserializer() {
335335
channelModel.setDeserializerType("xml");
336336
InboundEventProcessingPipelineBuilderImpl<Document> xmlPipelineBuilder
337337
= new InboundEventProcessingPipelineBuilderImpl<>(channelModel, eventRepository, channelDefinitionBuilder);
338338
this.channelDefinitionBuilder.inboundEventProcessingPipelineBuilder = xmlPipelineBuilder;
339339

340-
return new InboundEventFilterXmlBuilderImpl(xmlPipelineBuilder);
340+
return new InboundEventKeyXmlDetectorBuilderImpl(xmlPipelineBuilder);
341341
}
342342

343343
@Override
344-
public InboundEventFilterBuilder delegateExpressionDeserializer(String delegateExpression) {
344+
public InboundEventKeyDetectorBuilder delegateExpressionDeserializer(String delegateExpression) {
345345
channelModel.setDeserializerType("expression");
346346
channelModel.setDeserializerDelegateExpression(delegateExpression);
347347
InboundEventProcessingPipelineBuilderImpl customPipelineBuilder = new InboundEventProcessingPipelineBuilderImpl<>(channelModel,
348348
eventRepository, channelDefinitionBuilder);
349349
this.channelDefinitionBuilder.inboundEventProcessingPipelineBuilder = customPipelineBuilder;
350-
return new InboundEventFilterBuilderImpl(customPipelineBuilder);
350+
return new InboundEventDefinitionKeyDetectorBuilderImpl(customPipelineBuilder);
351351
}
352352

353353
@Override
@@ -357,51 +357,44 @@ public InboundChannelModelBuilder eventProcessingPipeline(String delegateExpress
357357
}
358358
}
359359

360-
public static class InboundEventFilterJsonBuilderImpl extends InboundEventKeyJsonDetectorBuilderImpl implements InboundEventFilterJsonBuilder {
360+
public static class InboundEventFilterJsonBuilderImpl extends InboundEventTenantJsonDetectorBuilderImpl implements InboundEventFilterJsonBuilder {
361361

362362
public InboundEventFilterJsonBuilderImpl(InboundEventProcessingPipelineBuilderImpl<JsonNode> inboundEventProcessingPipelineBuilder) {
363363
super(inboundEventProcessingPipelineBuilder);
364364
}
365365

366366
@Override
367-
public InboundEventKeyJsonDetectorBuilder delegateExpressionEventFilter(String delegateExpression) {
367+
public InboundEventTenantJsonDetectorBuilder delegateExpressionEventFilter(String delegateExpression) {
368368
inboundEventProcessingPipelineBuilder.channelModel.setEventFilterDelegateExpression(delegateExpression);
369-
return new InboundEventKeyJsonDetectorBuilderImpl(inboundEventProcessingPipelineBuilder);
369+
return new InboundEventTenantJsonDetectorBuilderImpl(inboundEventProcessingPipelineBuilder);
370370
}
371371

372372
}
373373

374-
public static class InboundEventFilterXmlBuilderImpl extends InboundEventKeyXmlDetectorBuilderImpl implements InboundEventFilterXmlBuilder {
374+
public static class InboundEventFilterXmlBuilderImpl extends InboundEventTenantXmlDetectorBuilderImpl implements InboundEventFilterXmlBuilder {
375375

376376
public InboundEventFilterXmlBuilderImpl(InboundEventProcessingPipelineBuilderImpl<Document> inboundEventProcessingPipelineBuilder) {
377377
super(inboundEventProcessingPipelineBuilder);
378378
}
379379

380380
@Override
381-
public InboundEventKeyXmlDetectorBuilder delegateExpressionEventFilter(String delegateExpression) {
381+
public InboundEventTenantXmlDetectorBuilder delegateExpressionEventFilter(String delegateExpression) {
382382
inboundEventProcessingPipelineBuilder.channelModel.setEventFilterDelegateExpression(delegateExpression);
383-
return new InboundEventKeyXmlDetectorBuilderImpl(inboundEventProcessingPipelineBuilder);
383+
return new InboundEventTenantXmlDetectorBuilderImpl(inboundEventProcessingPipelineBuilder);
384384
}
385385

386386
}
387387

388-
public static class InboundEventFilterBuilderImpl implements InboundEventFilterBuilder {
389-
390-
protected InboundEventProcessingPipelineBuilderImpl inboundEventProcessingPipelineBuilder;
388+
public static class InboundEventFilterBuilderImpl extends InboundEventTenantDetectorBuilderImpl implements InboundEventFilterBuilder {
391389

392390
public InboundEventFilterBuilderImpl(InboundEventProcessingPipelineBuilderImpl inboundEventProcessingPipelineBuilder) {
393-
this.inboundEventProcessingPipelineBuilder = inboundEventProcessingPipelineBuilder;
391+
super(inboundEventProcessingPipelineBuilder);
394392
}
395393

396394
@Override
397-
public InboundEventKeyDetectorBuilder delegateExpressionEventFilter(String delegateExpression) {
395+
public InboundEventTenantDetectorBuilder delegateExpressionEventFilter(String delegateExpression) {
398396
inboundEventProcessingPipelineBuilder.channelModel.setEventFilterDelegateExpression(delegateExpression);
399-
return new InboundEventDefinitionKeyDetectorBuilderImpl(inboundEventProcessingPipelineBuilder);
400-
}
401-
402-
@Override
403-
public InboundEventTenantDetectorBuilder delegateExpressionKeyDetector(String delegateExpression) {
404-
return null;
397+
return new InboundEventTenantDetectorBuilderImpl(inboundEventProcessingPipelineBuilder);
405398
}
406399

407400
}
@@ -415,27 +408,27 @@ public InboundEventKeyJsonDetectorBuilderImpl(InboundEventProcessingPipelineBuil
415408
}
416409

417410
@Override
418-
public InboundEventTenantJsonDetectorBuilder fixedEventKey(String key) {
411+
public InboundEventFilterJsonBuilder fixedEventKey(String key) {
419412
ChannelEventKeyDetection keyDetection = new ChannelEventKeyDetection();
420413
keyDetection.setFixedValue(key);
421414
this.inboundEventProcessingPipelineBuilder.channelModel.setChannelEventKeyDetection(keyDetection);
422-
return new InboundEventTenantJsonDetectorBuilderImpl(inboundEventProcessingPipelineBuilder);
415+
return new InboundEventFilterJsonBuilderImpl(inboundEventProcessingPipelineBuilder);
423416
}
424417

425418
@Override
426-
public InboundEventTenantJsonDetectorBuilder detectEventKeyUsingJsonField(String field) {
419+
public InboundEventFilterJsonBuilder detectEventKeyUsingJsonField(String field) {
427420
ChannelEventKeyDetection keyDetection = new ChannelEventKeyDetection();
428421
keyDetection.setJsonField(field);
429422
this.inboundEventProcessingPipelineBuilder.channelModel.setChannelEventKeyDetection(keyDetection);
430-
return new InboundEventTenantJsonDetectorBuilderImpl(inboundEventProcessingPipelineBuilder);
423+
return new InboundEventFilterJsonBuilderImpl(inboundEventProcessingPipelineBuilder);
431424
}
432425

433426
@Override
434-
public InboundEventTenantJsonDetectorBuilder detectEventKeyUsingJsonPointerExpression(String jsonPointerExpression) {
427+
public InboundEventFilterJsonBuilder detectEventKeyUsingJsonPointerExpression(String jsonPointerExpression) {
435428
ChannelEventKeyDetection keyDetection = new ChannelEventKeyDetection();
436429
keyDetection.setJsonPointerExpression(jsonPointerExpression);
437430
this.inboundEventProcessingPipelineBuilder.channelModel.setChannelEventKeyDetection(keyDetection);
438-
return new InboundEventTenantJsonDetectorBuilderImpl(inboundEventProcessingPipelineBuilder);
431+
return new InboundEventFilterJsonBuilderImpl(inboundEventProcessingPipelineBuilder);
439432
}
440433
}
441434

@@ -448,19 +441,19 @@ public InboundEventKeyXmlDetectorBuilderImpl(InboundEventProcessingPipelineBuild
448441
}
449442

450443
@Override
451-
public InboundEventTenantXmlDetectorBuilder fixedEventKey(String key) {
444+
public InboundEventFilterXmlBuilder fixedEventKey(String key) {
452445
ChannelEventKeyDetection keyDetection = new ChannelEventKeyDetection();
453446
keyDetection.setFixedValue(key);
454447
this.inboundEventProcessingPipelineBuilder.channelModel.setChannelEventKeyDetection(keyDetection);
455-
return new InboundEventTenantXmlDetectorBuilderImpl(inboundEventProcessingPipelineBuilder);
448+
return new InboundEventFilterXmlBuilderImpl(inboundEventProcessingPipelineBuilder);
456449
}
457450

458451
@Override
459-
public InboundEventTenantXmlDetectorBuilder detectEventKeyUsingXPathExpression(String xPathExpression) {
452+
public InboundEventFilterXmlBuilder detectEventKeyUsingXPathExpression(String xPathExpression) {
460453
ChannelEventKeyDetection keyDetection = new ChannelEventKeyDetection();
461454
keyDetection.setXmlXPathExpression(xPathExpression);
462455
this.inboundEventProcessingPipelineBuilder.channelModel.setChannelEventKeyDetection(keyDetection);
463-
return new InboundEventTenantXmlDetectorBuilderImpl(inboundEventProcessingPipelineBuilder);
456+
return new InboundEventFilterXmlBuilderImpl(inboundEventProcessingPipelineBuilder);
464457
}
465458

466459
}
@@ -474,11 +467,11 @@ public InboundEventDefinitionKeyDetectorBuilderImpl(InboundEventProcessingPipeli
474467
}
475468

476469
@Override
477-
public InboundEventTenantDetectorBuilder delegateExpressionKeyDetector(String delegateExpression) {
470+
public InboundEventFilterBuilder delegateExpressionKeyDetector(String delegateExpression) {
478471
ChannelEventKeyDetection keyDetection = new ChannelEventKeyDetection();
479472
keyDetection.setDelegateExpression(delegateExpression);
480473
inboundEventProcessingPipelineBuilder.channelModel.setChannelEventKeyDetection(keyDetection);
481-
return new InboundEventTenantDetectorBuilderImpl(inboundEventProcessingPipelineBuilder);
474+
return new InboundEventFilterBuilderImpl(inboundEventProcessingPipelineBuilder);
482475
}
483476

484477
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,18 @@ public Collection<EventRegistryEvent> run(InboundChannelModel inboundChannel, In
8181

8282
FlowableEventInfo<T> event = new FlowableEventInfoImpl<>(inboundEvent, deserializedBody, inboundChannel);
8383

84+
String eventKey = detectEventDefinitionKey(event);
85+
8486
// if there is a custom filter in place, invoke it to retain only the events that are wanted or to abort the pipeline
8587
if (inboundEventFilter != null) {
86-
if (!inboundEventFilter.retain(event)) {
88+
if (!inboundEventFilter.retain(eventKey, event)) {
8789
if (debugLoggingEnabled) {
8890
logger.debug("Inbound event {} on inbound {} channel {} was filtered out.", inboundEvent, inboundChannel.getChannelType(), inboundChannel.getKey());
8991
}
9092
return Collections.emptyList();
9193
}
9294
}
9395

94-
String eventKey = detectEventDefinitionKey(event);
95-
9696
boolean multiTenant = false;
9797
String tenantId = AbstractEngineConfiguration.NO_TENANT_ID;
9898
if (inboundEventTenantDetector != null) {

0 commit comments

Comments
 (0)