BDM Unique Constraint for Active Processes only

1
0
-1

Hello,

I have a process in which each process instance has a BDM object associated with it. If a process has started with a BDM object, I want to prevent users from being able to start another process using the same object as the existing process. If I use a unique constraint on the ID field of my BDM object, users are prevented from ever being able to start a process using an object that was used in the past, which is not what I want. I only want to ensure that a process cannot be started using an object that is being used in an active process.

I know I can accomplish this by getting all active process instances, then looping through each instance, get the execution context for each instance, then get the BDM data reference object, call the object dao to get the object, and finally check if the current process a user is attempting to start requires the same object, but this seems very indirect and inefficient.

Perhaps there is a way to easily associate an ID with a process instance?

I like the concept of "Process Variables" or "Search Keys" but see no way of exposing these through the Java API.

I'd greatly appreciate any ideas.

Thanks

Comments

Submitted by antoine.mottier on Wed, 04/03/2019 - 12:34

I'm not sure I understand correctly your use case. When your process start:

  1. Did the process create a new business variable (e.g. by setting the default value of the business variable using process instantiation contract inputs)? Meaning that a new row will be inserted in the BDM database.
  2. Or did the process start with a unique id (e.g. the persistence id managed by Bonita or a primary key of your business data) referencing to an existing business data and then your business variable is initialized with this existing data? This actually would trigger a select query in the BDM database to retrieve existing data.

Thanks for the clarification.

Submitted by rtumminelli_1394599 on Wed, 04/03/2019 - 17:33

Hello,

I'm starting my process with my unique id being the primary key of my business data. Currently I am using the Search Keys to accomplish what I want, but I am aware this is not the intended use of Search Keys. I have defined the search key of my process as my business data id. In my code, I have a this method:

private boolean checkIfAlreadyInWorkflow(Integer businessObjectId) {
return processAPI
.getProcessInstances(0, -1, ProcessInstanceCriterion.DEFAULT)
.stream()
.anyMatch(processInstance -> {
return businessObjectId.toString()
.equals(processInstance.getStringIndex1());
});
}

I call this before I start new processes just to make sure 2 processes cant start with the same id at the same time.

1 answer

1
+1
-1
This one is the BEST answer!

Based on your use case maybe you can add an attribute on your business object to flag him as being "updated" by a process instance? This attribute might be for example the id of the process instance currently updating the business process data. You should set this attributes value at the beginning of the process after making sure that it is empty and clear it at the end of the process.

Once you defined such attribute, on the instantiation form of your process you can then use the business data information to prevent user from starting a process if the select business variable as the process instance id attribute set. You can also enforce search restriction in the process definition itself to end the process if the process instance id attribute of your business variable is not empty.

I create an example to illustrate my solution.

Notifications