AnsweredAssumed Answered

JPA Entity-based Process Definitions

Question asked by legistrate on Apr 6, 2015
Latest reply on Apr 7, 2015 by jbarrez
I have started using the Activiti Engine in a greenfield Spring MVC Project. Previously, I was developing customizations for PTC Windchill where workflow processes are based around a primary business object and can be kicked off when an instance of a particular Entity type is created. I found this to be a useful paradigm for managing metadata that is built through user interaction in BPMs. I have tried to replicate this with Activiti and I am concerned that I might be taking the wrong approach so I am looking for advice.

I have a JPA Entity (configured with the same EntityManagerFactory/PlatformTransactionManager) that I set as the "processObject" process level variable when I start an instance of my process and I also use the id of that object as my businessKey.  Perhaps this should be {}:{id}, but since I can specify the process definition key which is one-to-one with the Entity class to find process instances, this decision made for easy conversion to my entity's surrogate key type Long into a businessKey and back.

1. Should I also be storing the processInstanceId on the business Entity to avoid the extra lookup? It is already available through the DelegateExecution in JavaServiceTask handlers.

My first process definition using this design primarily consists of routing between java service tasks and user tasks through a lifecycle. I am capturing this lifecycle as an enum stored on my business Entity. These roughly correspond to wait states at a user task or one of the various possible error/end states.

2. Is there a recommended way to track the lifecycle for the business Entity being routed through a process?

The Java Service Tasks are all fulfilled by Spring service bean that backs my process via UEL method expressions. In each of these methods I need to access my processObject which is available as a process variable on the execution context which I also pass in every UEL call. When completing my user tasks I also store the user's response string as a process variable as I am not sure what local variables are scoped to outside of a task. As it was, I was hoping that completing the user task would give me access to it's task local variable in delegates that followed it. It also seems that the local task variables are not available on HistoicTaskInstances when queried in JavaServiceTasks in that following logic. I believe I read documentation that explained SQL transactions don't end until a chain of non-asynchronous tasks finish in a wait state.

3. When the user's response drives such workflows, is there a better way for driving gateways than sequenceFlow conditionExpressions tested against process variables stored as the task is being marked complete?

Once this history is built for the business Entity, I need to be able to return the associated process history by retrieving the HistoricTaskInstances. I am using the process business key as a parameter for HistoricTaskInstanceQuery. However, I often need to return multiple instances of my business Entity and there isn't a processInstanceBusinessKeyIn parameter so I end up doing separate queries for each Entity. Instead, I'd like to retrieve them all in a single query and matching them up in Java which would likely be faster. Alternatively, if I did store the processId on the business Entity, I could easily build a processInstanceIdIn query parameter, but sadly this is also not supported. I had also considered that there is a process variable that can be queried for tasks, but the documentation says that only the equals comparator works. I wasn't able to find a variable comparator for sets.

4. Is there a mechanism I have missed or technique overlooked which can retrieve a set of all the HistoricTaskInstances for a set of business Entities by Id/Key or ProcessInstanceId?

I hoping the community can offer any suggestions in these areas where you have also implemented Entity-centric BPM (other suggestions welcome too!)