cancel
Showing results for 
Search instead for 
Did you mean: 

JTA inside a java delegate

chimu
Champ in-the-making
Champ in-the-making
We have a Activiti workflow with UI developed using JSF , JPA and CDI. We have a submit screen which is associated with start-form-key and one User task which corresponds
to the approver screen.

I have some questions :-

Q1) We have a requirement such that if Approver rejects the data then we need to send request back to Sumitter which in our case is not
a user task but a form associated with start event, so how do we accomplish that. Either we move submit screen to a user task by itself or  we loop back after approver user task and keep an intermediate user task of re-submission. which one will be good option. ?

Q2) The Approver is selected dynamically from the Submit screen in a drop-down. So where do we store this value such that it becomes a assignee in the Approver user task. Do we inject it as a process variable or we keep it in a session scoped CDI bean and access it via EL expression in the assignee property. ?

Q3) If the approver Rejects the data, how do we assign it back to the original submitter, do we need to keep track of submitter in a process variable or a CDI bean or there is any API available ?

Q4) After Approval I need to "insert" data in our business database which is different than Acitivi, so we have configure JTA for 2 phase commit. Now my question is  that this "insert" should happen inside JSF UI controller code of Approval screen or it should happen inside a service task which gets called after completion   of Approval user Task. In case the "insert" happens inside a service task then how do I pass my Entity and Entity Manager to Java delegate of service task.    Can I inject JTA UserTransaction inside Java delegate so that both my business data Insert and Activiti process completion happens together.

2 REPLIES 2

chimu
Champ in-the-making
Champ in-the-making
I have one more question to include in addition to above one
Q5) If I commit my business data in in user task of final approver, then atleast I can show error message on his screen(on exception) and that task will still remain alive in his Inbox, but on other hand if I commit inside a service task then users will never come to know that final approved data never got committed to database, and their Task explorer will also not show any pending task. So what is best practice, to commit data in service task or in the last approver user task.

frederikherema1
Star Contributor
Star Contributor
Q1: Best to move the screen to a user-task an loop-back. This allows you to have the process persisted with the right state and variables and there is no need to have duplicate logic (both for rendering start-form and rendering task-form with the same form).

Q2: You can just store the assignee the user selected as a process-variable. In the next task where the assignee should be set, use 'activiti:assignee="${assigneeSelectedWhenStarted}"' or use the BPMN2.0 counterpart (see user guide).

Q3: Again, use a process-variable so it's persistent and independent of environment (CDI). Use a gateway with conditions on the flow (e.g.. {$approved == "Yes"}, so it goes to a userTask with activiti:assignee="${initiator}" (having activiti:initiator="initiator" on you start-event).

Q4: Best to do this from the process itself, so all logic related to the process (getaways, tasks, DB-writes) is bundled and contained in one place to have a good overview.

Q5: If you're using JTA and the final task.complete() generates an exception, bot activiti entities and your custom entities will be rolled back. You can just show the error-message and the task WILL NOT be completed and will still be available. It's like the complete never happened…