Skip to content

Commit 16e1de6

Browse files
mkienerMicha Kiener
andauthored
Support manual event subscription based case event-registry start (#3817)
* add support for dynamic, manually created event subscriptions to start a new case based on a specific combination of correlation values * small typos and comment improvements --------- Co-authored-by: Micha Kiener <micha.kiener@flowable.com>
1 parent 96be96b commit 16e1de6

27 files changed

Lines changed: 2118 additions & 8 deletions

File tree

modules/flowable-cmmn-api/src/main/java/org/flowable/cmmn/api/CmmnRuntimeService.java

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import org.flowable.cmmn.api.runtime.CaseInstanceBuilder;
2020
import org.flowable.cmmn.api.runtime.CaseInstanceQuery;
21+
import org.flowable.cmmn.api.runtime.CaseInstanceStartEventSubscriptionBuilder;
22+
import org.flowable.cmmn.api.runtime.CaseInstanceStartEventSubscriptionDeletionBuilder;
23+
import org.flowable.cmmn.api.runtime.CaseInstanceStartEventSubscriptionModificationBuilder;
2124
import org.flowable.cmmn.api.runtime.ChangePlanItemStateBuilder;
2225
import org.flowable.cmmn.api.runtime.GenericEventListenerInstanceQuery;
2326
import org.flowable.cmmn.api.runtime.MilestoneInstanceQuery;
@@ -313,12 +316,12 @@ public interface CmmnRuntimeService {
313316
* @param identityLinkType
314317
* type of identity, cannot be null.
315318
* @throws FlowableObjectNotFoundException
316-
* when the process instance or group doesn't exist.
319+
* when the case instance or group doesn't exist.
317320
*/
318321
void addGroupIdentityLink(String caseInstanceId, String groupId, String identityLinkType);
319322

320323
/**
321-
* Removes the association between a user and a process instance for the given identityLinkType.
324+
* Removes the association between a user and a case instance for the given identityLinkType.
322325
*
323326
* @param caseInstanceId
324327
* id of the case instance, cannot be null.
@@ -332,7 +335,7 @@ public interface CmmnRuntimeService {
332335
void deleteUserIdentityLink(String caseInstanceId, String userId, String identityLinkType);
333336

334337
/**
335-
* Removes the association between a group and a process instance for the given identityLinkType.
338+
* Removes the association between a group and a case instance for the given identityLinkType.
336339
*
337340
* @param caseInstanceId
338341
* id of the case instance, cannot be null.
@@ -381,7 +384,7 @@ public interface CmmnRuntimeService {
381384
FormInfo getStartFormModel(String caseDefinitionId, String caseInstanceId);
382385

383386
/**
384-
* Create a {@link ChangePlanItemStateBuilder}, that allows to set various options for changing the state of a process instance.
387+
* Create a {@link ChangePlanItemStateBuilder}, that allows to set various options for changing the state of a case instance.
385388
*/
386389
ChangePlanItemStateBuilder createChangePlanItemStateBuilder();
387390

@@ -442,4 +445,32 @@ public interface CmmnRuntimeService {
442445
* when the given event is not suitable for dispatching.
443446
*/
444447
void dispatchEvent(FlowableEvent event);
448+
449+
/**
450+
* Creates a new event subscription builder to register a subscription to start a new case instance based on an event with a particular set of
451+
* correlation parameter values. In order for this to work, the case definition needs to have an event-registry based start event with a
452+
* dynamic, manual subscription based behavior and the registered correlation parameter values within the builder need to be based on
453+
* actual correlation parameter definitions within the event model the start event is based on.
454+
* Register one or more correlation parameter value with in the builder before invoking the
455+
* {@link CaseInstanceStartEventSubscriptionBuilder#subscribe()} method to create and register the subscription.
456+
*
457+
* @return the subscription builder
458+
*/
459+
CaseInstanceStartEventSubscriptionBuilder createCaseInstanceStartEventSubscriptionBuilder();
460+
461+
/**
462+
* Creates a new event subscription modification builder to modify one or more previously registered case start event subscriptions based
463+
* on a particular case definition and with an optional combination of correlation parameter values.
464+
*
465+
* @return the subscription modification builder
466+
*/
467+
CaseInstanceStartEventSubscriptionModificationBuilder createCaseInstanceStartEventSubscriptionModificationBuilder();
468+
469+
/**
470+
* Creates a new event subscription deletion builder to delete one or more previously registered case start event subscriptions based
471+
* on a particular case definition and with an optional combination of correlation parameter values.
472+
*
473+
* @return the subscription deletion builder
474+
*/
475+
CaseInstanceStartEventSubscriptionDeletionBuilder createCaseInstanceStartEventSubscriptionDeletionBuilder();
445476
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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.cmmn.api.runtime;
14+
15+
import java.util.Map;
16+
17+
import org.flowable.eventsubscription.api.EventSubscription;
18+
19+
/**
20+
* A builder API to create an event subscription to start an event-based case instance whenever an event with a very specific
21+
* combination of correlation values occurs.
22+
* You can model an event-based start for a case model to create a new case instance whenever that event happens, but not, if
23+
* it should only start a case on a particular combination of correlation values.
24+
*
25+
* In order for this to work, you need a case definition with an event registry start, configured with the manual, correlation based
26+
* subscription behavior.
27+
*
28+
* @author Micha Kiener
29+
*/
30+
public interface CaseInstanceStartEventSubscriptionBuilder {
31+
32+
/**
33+
* Set the case definition to be started using a manually added subscription by its key. By default, always the latest version is
34+
* used to start a new case instance, unless you use {@link #doNotUpdateToLatestVersionAutomatically()} to mark the builder to stick to
35+
* exactly the current version of the case definition and don't update it, if a new version would be deployed later on.
36+
* This method is mandatory and will throw an exception when trying to register a subscription where the case definition key was not set or
37+
* is null.
38+
*
39+
* @param caseDefinitionKey the key of the case definition to be started a new instance of when the subscription has a match at runtime
40+
* @return the builder to be used for method chaining
41+
*/
42+
CaseInstanceStartEventSubscriptionBuilder caseDefinitionKey(String caseDefinitionKey);
43+
44+
/**
45+
* Mark the subscription to not use the latest case definition automatically, should there be a new version deployed after the subscription
46+
* was created. This means, adding the subscription will always stick to the current version of the case definition, and it will NOT be updated
47+
* automatically should there be a new version deployed later on. By default, when this method is not invoked on the builder, the subscription will
48+
* be updated automatically to the latest version when a new version of the case definition is deployed.
49+
* The subscription can still be updated to the latest version by manually migrating it to whatever version you want.
50+
*
51+
* @return the builder to be used for method chaining
52+
*/
53+
CaseInstanceStartEventSubscriptionBuilder doNotUpdateToLatestVersionAutomatically();
54+
55+
/**
56+
* Adds a specific correlation parameter value for the subscription, which means this value needs to exactly match the event
57+
* payload in order to trigger the case start (along with all registered correlation parameter values of course).
58+
*
59+
* @param parameterName the name of the correlation parameter
60+
* @param parameterValue the value of the correlation parameter
61+
* @return the builder to be used for method chaining
62+
*/
63+
CaseInstanceStartEventSubscriptionBuilder addCorrelationParameterValue(String parameterName, Object parameterValue);
64+
65+
/**
66+
* Registers a list of correlation parameter values for the subscription. The result is the same as registering
67+
* them one after the other.
68+
*
69+
* @param parameters the map of correlation parameter values to be registered for the subscription
70+
* @return the builder to be used for method chaining
71+
*/
72+
CaseInstanceStartEventSubscriptionBuilder addCorrelationParameterValues(Map<String, Object> parameters);
73+
74+
/**
75+
* Set the tenant id for the subscription.
76+
*
77+
* @param tenantId the id of the tenant
78+
* @return the builder to be used for method chaining
79+
*/
80+
CaseInstanceStartEventSubscriptionBuilder tenantId(String tenantId);
81+
82+
/**
83+
* Creates the event subscription with the registered combination of correlation parameter values and saves it.
84+
*/
85+
EventSubscription subscribe();
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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.cmmn.api.runtime;
14+
15+
import java.util.Map;
16+
17+
import org.flowable.cmmn.api.CmmnRuntimeService;
18+
19+
/**
20+
* A builder API to delete a manually created case start event subscription which was created and registered using the
21+
* {@link CmmnRuntimeService#createCaseInstanceStartEventSubscriptionBuilder()} builder API.
22+
* With this API you can delete one or more such subscriptions based on the correlation parameter values and event type.
23+
*
24+
* @author Micha Kiener
25+
*/
26+
public interface CaseInstanceStartEventSubscriptionDeletionBuilder {
27+
28+
/**
29+
* Set the case definition using its specific id the manually created subscription is based on. This is mandatory and must be provided.
30+
*
31+
* @param caseDefinitionId the id of the case definition the subscription is based on (an exact version of it)
32+
* @return the builder to be used for method chaining
33+
*/
34+
CaseInstanceStartEventSubscriptionDeletionBuilder caseDefinitionId(String caseDefinitionId);
35+
36+
/**
37+
* Set the tenant id in case you are running in a multi tenant environment and the event model needs to be retrieved from a specific tenant.
38+
*
39+
* @param tenantId the id of the tenant the subscription is created for
40+
* @return the builder to be used for method chaining
41+
*/
42+
CaseInstanceStartEventSubscriptionDeletionBuilder tenantId(String tenantId);
43+
44+
/**
45+
* Adds a specific correlation parameter value for the subscription to be deleted. If you register the same correlation parameter values
46+
* as when creating and registering the event subscription, only that particular one will be deleted with this builder.
47+
* If you want to delete all manually created subscriptions, don't register any correlation parameter values, which would result in all matching
48+
* the provided case definition and event-registry start event will be deleted.
49+
*
50+
* @param parameterName the name of the correlation parameter
51+
* @param parameterValue the value of the correlation parameter
52+
* @return the builder to be used for method chaining
53+
*/
54+
CaseInstanceStartEventSubscriptionDeletionBuilder addCorrelationParameterValue(String parameterName, Object parameterValue);
55+
56+
/**
57+
* Registers a list of correlation parameter values for the subscription(s) to be deleted.
58+
*
59+
* @param parameters the map of correlation parameter values to be registered for the subscription
60+
* @return the builder to be used for method chaining
61+
*/
62+
CaseInstanceStartEventSubscriptionDeletionBuilder addCorrelationParameterValues(Map<String, Object> parameters);
63+
64+
/**
65+
* Deletes all the matching event subscriptions.
66+
*/
67+
void deleteSubscriptions();
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.cmmn.api.runtime;
14+
15+
import java.util.Map;
16+
17+
import org.flowable.cmmn.api.CmmnRuntimeService;
18+
19+
/**
20+
* A builder API to modify a manually created case start event subscription which was created and registered using the
21+
* {@link CmmnRuntimeService#createCaseInstanceStartEventSubscriptionBuilder()} builder API.
22+
* With this API you can modify one or more such subscriptions like migrating to a specific version of a case definition (if you choose to not automatically
23+
* migrate then to the latest version upon deployment of a new version).
24+
*
25+
* @author Micha Kiener
26+
*/
27+
public interface CaseInstanceStartEventSubscriptionModificationBuilder {
28+
29+
/**
30+
* Set the case definition using its specific id the manually created subscription is based on. This is mandatory and must be provided.
31+
*
32+
* @param caseDefinitionId the id of the case definition the subscription is based on (an exact version of it)
33+
* @return the builder to be used for method chaining
34+
*/
35+
CaseInstanceStartEventSubscriptionModificationBuilder caseDefinitionId(String caseDefinitionId);
36+
37+
/**
38+
* Set the tenant id in case you are running in a multi tenant environment and the event model needs to be retrieved from a specific tenant.
39+
*
40+
* @param tenantId the id of the tenant the subscription is created for
41+
* @return the builder to be used for method chaining
42+
*/
43+
CaseInstanceStartEventSubscriptionModificationBuilder tenantId(String tenantId);
44+
45+
/**
46+
* Adds a specific correlation parameter value for the subscription to be modified. If you register the same correlation parameter values as when creating
47+
* and registering the event subscription, only that particular one will be modified with this builder.
48+
* If you want to modify all manually created subscriptions, don't register any correlation parameter values, which would result in all matching
49+
* the provided case definition and event-registry start event will be modified.
50+
*
51+
* @param parameterName the name of the correlation parameter
52+
* @param parameterValue the value of the correlation parameter
53+
* @return the builder to be used for method chaining
54+
*/
55+
CaseInstanceStartEventSubscriptionModificationBuilder addCorrelationParameterValue(String parameterName, Object parameterValue);
56+
57+
/**
58+
* Registers a list of correlation parameter values for the subscription(s) to be modified.
59+
*
60+
* @param parameters the map of correlation parameter values to be registered for the subscription
61+
* @return the builder to be used for method chaining
62+
*/
63+
CaseInstanceStartEventSubscriptionModificationBuilder addCorrelationParameterValues(Map<String, Object> parameters);
64+
65+
/**
66+
* Migrate all the matching event subscriptions to the latest case definition, which should be done if you want to manually upgrade the subscriptions
67+
* to the latest version of the case definition.
68+
*/
69+
void migrateToLatestCaseDefinition();
70+
71+
/**
72+
* Migrate all matching event subscriptions to the specific case definition.
73+
* @param caseDefinitionId the id of the case definition to migrate to
74+
*/
75+
void migrateToCaseDefinition(String caseDefinitionId);
76+
}

modules/flowable-cmmn-converter/src/main/java/org/flowable/cmmn/converter/CmmnXmlConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ public interface CmmnXmlConstants {
221221
String ELEMENT_EVENT_OUT_PARAMETER = "eventOutParameter";
222222
String START_EVENT_CORRELATION_CONFIGURATION = "startEventCorrelationConfiguration";
223223
String START_EVENT_CORRELATION_STORE_AS_UNIQUE_REFERENCE_ID = "storeAsUniqueReferenceId";
224+
String START_EVENT_CORRELATION_MANUAL = "manualSubscription";
224225

225226
String ELEMENT_VARIABLE_AGGREGATION = "variableAggregation";
226227
String ATTRIBUTE_VARIABLE_AGGREGATION_VARIABLE = "variable";

0 commit comments

Comments
 (0)