AnsweredAssumed Answered

Events occuring before DB updates

Question asked by bathe on Sep 30, 2013
Latest reply on Oct 3, 2013 by bathe
Hi,

I am using a simple workflow with 2 tasks as shown in following image.

  [IMG]http://img182.imagevenue.com/loc438/th_565699128_A001CustomerRegistration_122_438lo.jpg[/IMG]
  
User Task has Start and end End task listener as shown:

   @Override
   public void notify(DelegateTask task) {
      System.out.println("Event Received : " + task.getEventName());
      List<String> approvers = new ArrayList<String>();
      
      Set<IdentityLink> identities =  task.getCandidates(); 
      for (IdentityLink identity :identities){
         approvers.add(identity.getUserId());
      }   
      
      List<Object> loggedinUsers = sessionRegistry.getAllPrincipals();
       for (Object loggedinUser : loggedinUsers) {
           if (loggedinUser instanceof MyUserDetails) {
              MyUserDetails myUser = (MyUserDetails) loggedinUser;
              if (approvers.contains(myUser.getUsername())) {
                 System.out.println("Send refresh to :" + myUser.getUsername());
                                     // Notification Logic…..
                 }
           }
       }
   }



User task is assigned to multiple users say M1, M2.  When workflow starts "start" event which is associated with first task is triggered. this will send "Refresh" notification to all associated actors of this task. after getting notification each actor will update task list by calling 


allTasks = taskService.createTaskQuery().taskCandidateUser(userId).list();


Problem statement:
    Step 1: When new workflow starts, START event is fired, captured by listener and refresh notification is send to all actors of task. Till this point everything is working as expected.  But when actors are updating task list, as Activiti engine has not added DB entries of new user task, taskCandidateUser.list() is not returning any results.

    Step 2: When user completes his task, END event is fired, captured by listener and refresh notification is send to all actors of task. Till this point everything is working as expected.  But when actors are updating task list, as Activiti engine has not removed DB entries for completed task, taskCandidateUser.list() is returning task added in step 1.

Please note if I manually refresh screen after step 1 or 2, task list displays updated contents.

Is there anyway to fire events only after complete DB update.

Regards,
Shirish

Outcomes