BDM Unique Constraint for Active Processes only
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.
I'm not sure I understand correctly your use case. When your process start:
- 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.
- 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.
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.