cancel
Showing results for 
Search instead for 
Did you mean: 

Assignee cannot be updated with updateTask in Java

joko71
Confirmed Champ
Confirmed Champ
snippet from workflow model:

      <type name="sdzwf:someTask">
         <parent>bpm:workflowTask</parent>
         <overrides>
            <property name="bpm:packageActionGroup">
               <default>add_package_item_actions</default>
            </property>
            <property name="bpm:packageItemActionGroup">
               <default>edit_package_item_actions</default>
            </property>
         </overrides>
         <mandatory-aspects>
            <aspect>bpm:assignee</aspect>
         </mandatory-aspects>
      </type>

snippet from workflow definition:

   <swimlane name="somelane">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <actor>#{bpm_assignee}</actor>
      </assignment>
   </swimlane>                  
 


   <task-node name="someTask">
      <task name="sdzwf:someTask" swimlane="somelane"></task>
      <transition to="someTask1" name="Odobri"></transition>
      <transition to="someTask2" name="Vrati"></transition>
   </task-node>

snippet from java code:

      TransactionService transactionService = AlfrescoServices.getTransactionService();
      RetryingTransactionCallback<Object> work = new RetryingTransactionCallback<Object>() {

         public Object execute() throws Throwable {
            
            NodeRef nrUser = Authentication.getInstance().getUserNodeRef(ticket);
            
            WorkflowTask task = AlfrescoServices.getWorkflowService().getTaskById(taskId);
            String pathId = task.path.id;
            
            // update map
            Map<QName, Serializable> updateProperties = new HashMap<QName, Serializable>();
            
             // assignee node reference
             NodeRef nrAssignee = AlfrescoServices.getPersonService().getPerson(assigneeUsername);

             if(nrAssignee != null) {

                updateProperties.put(WorkflowModel.ASSOC_ASSIGNEE, nrAssignee);
               
                // update task
                AlfrescoServices.getWorkflowService().updateTask(taskId, updateProperties, null, null);
               
                // execute task
               WorkflowPath path = AlfrescoServices.getWorkflowService().signal(pathId, transitionId);
             }

            return null;
         }
      };
      
      transactionService.getRetryingTransactionHelper().doInTransaction(work);

Problem is that updateTask method does not update bpm:assignee property in HashMap which task object holds, the old value from previous task persists. What must I change within my code for this to work?

Oh yes, I'm working with Alfresco 2.1 … Smiley Happy
7 REPLIES 7

joko71
Confirmed Champ
Confirmed Champ
I discovered interesting thing: "bpm:assignee" property is changed in the task, but this change is not visible if new WorkflowTask reference is not created.

WorkflowTask task = AlfrescoServices.getWorkflowService().getTaskById(taskId);

// change assignee property
updateProperties.put(WorkflowModel.ASSOC_ASSIGNEE, nrAssignee);
               
// update task
AlfrescoServices.getWorkflowService().updateTask(taskId, updateProperties, null, null);

WorkflowTask task2 = AlfrescoServices.getWorkflowService().getTaskById(taskId);

In task2 property map "bpm:assignee" property is set on new value.

But, nevertheless, if I execute a transition with signal, it behaves as if old assignee value is still valid. Very interesting, but frustrating. Please help! Smiley Happy

joko71
Confirmed Champ
Confirmed Champ
I tried also the other approach to define different swimlanes with different actor variables for each of the tasks in series. Similar as with bpm:assignee, I can put update value in updateProperties hash map, but updateTask method does not update the task with key/value par. Of course, I get exception because task variable is not set:

org.alfresco.service.cmr.workflow.WorkflowException: Failed to signal transition 'Odobri' from workflow path 'jbpm$40-@'
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.signal(JBPMEngine.java:863)
   at org.alfresco.repo.workflow.WorkflowServiceImpl.signal(WorkflowServiceImpl.java:317)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:256)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:191)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
   at $Proxy43.signal(Unknown Source)
   at com.inkubator.test.app.workflow.Workflow$3.execute(Workflow.java:384)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:225)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:155)
   at com.inkubator.test.app.workflow.Workflow.executeTransition(Workflow.java:391)
   at com.inkubator.test.app.ui.Menu.displayTaskManageTransitionsScreen(Menu.java:757)
   at com.inkubator.test.app.ui.Menu.display(Menu.java:130)
   at com.inkubator.test.app.AlfrescoWorkflowApiTestConsoleApp$1.execute(AlfrescoWorkflowApiTestConsoleApp.java:64)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:225)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:155)
   at com.inkubator.test.app.AlfrescoWorkflowApiTestConsoleApp.main(AlfrescoWorkflowApiTestConsoleApp.java:74)
Caused by: org.jbpm.graph.def.DelegationException: Failed to execute supplied script: Failed to execute supplied script: ReferenceError: "sdzwf_xyz" is not defined. (AlfrescoScript#1)

<?xml version="1.0" encoding="UTF-8"?>

<process-definition
  xmlns="urn:jbpm.org:jpdl-3.1"  name="sdzwf:myWorkflow">
 
   <swimlane name="initiator" />
        
   <swimlane name="aaa">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <actor>#{sdzwf_aaa}</actor>
      </assignment>
   </swimlane>
   
   <swimlane name="xyz">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <actor>#{sdzwf_xyz}</actor>
      </assignment>
   </swimlane>
   
   <swimlane name="bbb">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <actor>#{sdzwf_bbb}</actor>
      </assignment>
   </swimlane>                  
 
   <start-state name="start">
      <task name="sdzwf:startTask" swimlane="initiator" />      
      <transition name="" to="aaaTask"></transition>
   </start-state>
        
   <task-node name="aaaTask">
      <task name="sdzwf:aaaTask" swimlane="aaa"></task>
      <transition to="xyzTask" name="Odobri"></transition>
   </task-node>

   <task-node name="xyzTask">
      <task name="sdzwf:xyzTask" swimlane="xyz"></task>
      <transition to="bbbTask" name="Odobri"></transition>
      <transition to="aaaTask" name="Vrati"></transition>
   </task-node>

   <task-node name="bbbTask">
      <task name="sdzwf:bbbTask" swimlane="bbb"></task>            
      <transition to="xyzTask" name="Vrati"></transition>
      <transition to="end" name="Odobri"></transition>
   </task-node>
  
   <end-state name="end"></end-state>
  
</process-definition>

      <type name="sdzwf:startTask">
         <parent>bpm:startTask</parent>
         <overrides>
            <property name="bpm:packageActionGroup">
               <default>add_package_item_actions</default>
            </property>
            <property name="bpm:packageItemActionGroup">
               <default>edit_package_item_actions</default>
            </property>
         </overrides>
         <mandatory-aspects>
            <aspect>sdzwf:aaa</aspect>
         </mandatory-aspects>
      </type>
            
      <type name="sdzwf:aaaTask">
         <parent>bpm:workflowTask</parent>
         <overrides>
            <property name="bpm:packageActionGroup">
               <default>add_package_item_actions</default>
            </property>
            <property name="bpm:packageItemActionGroup">
               <default>edit_package_item_actions</default>
            </property>
         </overrides>
         <mandatory-aspects>
            <aspect>sdzwf:xyz</aspect>
         </mandatory-aspects>
      </type>
      
      <type name="sdzwf:xyzTask">
         <parent>bpm:workflowTask</parent>
         <overrides>
            <property name="bpm:packageActionGroup">
               <default>add_package_item_actions</default>
            </property>
            <property name="bpm:packageItemActionGroup">
               <default>edit_package_item_actions</default>
            </property>
         </overrides>
         <mandatory-aspects>
            <aspect>sdzwf:bbb</aspect>
         </mandatory-aspects>
      </type>
      
      <type name="sdzwf:bbbTask">
         <parent>bpm:workflowTask</parent>
         <overrides>
            <property name="bpm:packageActionGroup">
               <default>add_package_item_actions</default>
            </property>
            <property name="bpm:packageItemActionGroup">
               <default>edit_package_item_actions</default>
            </property>
         </overrides>
      </type>
      
   </types>

   <aspects>
      
   <aspect name="sdzwf:aaa">
      <associations>
         <association name="sdzwf:aaa">
            <source>
               <mandatory>false</mandatory>
               <many>false</many>
            </source>
            <target>
               <class>cm:person</class>
               <mandatory>false</mandatory>
               <many>false</many>
            </target>
         </association>
      </associations>
   </aspect>
   
   <aspect name="sdzwf:xyz">
      <associations>
         <association name="sdzwf:xyz">
            <source>
               <mandatory>false</mandatory>
               <many>false</many>
            </source>
            <target>
               <class>cm:person</class>
               <mandatory>false</mandatory>
               <many>false</many>
            </target>
         </association>
      </associations>
   </aspect>
   
   <aspect name="sdzwf:bbb">
      <associations>
         <association name="sdzwf:bbb">
            <source>
               <mandatory>false</mandatory>
               <many>false</many>
            </source>
            <target>
               <class>cm:person</class>
               <mandatory>false</mandatory>
               <many>false</many>
            </target>
         </association>
      </associations>
   </aspect>

   </aspects>

joko71
Confirmed Champ
Confirmed Champ
Haven't found a solution for my problems yet…

My serial workflow is working perfectly in Alfresco web client, I can assign new actor when I perform a task, but I can't do the same in Java code. Java method updateTask does not update task properties with the actor necessary for the next task.

Anyone?

joko71
Confirmed Champ
Confirmed Champ
I thought I solved this issue with a some kind of workaround, but it came back with a vengeance.

Still I cannot overwrite old bpm:assignee value with the new thru updateTask method. Signal on transition causes that task is delegated on the same user that created it.

Has anyone seen this behavior? Please help, I'm getting desperate… Smiley Sad

Here's transition execution code:
   public static void executeTransition(final String taskId, String taskOwnerUsername, final String nrPackage, final String transitionId, final String assigneeUsername, final String comment, final String ticket) {
      
      /*TransactionService transactionService = AlfrescoServices.getTransactionService();
      RetryingTransactionCallback<Object> work = new RetryingTransactionCallback<Object>() {

         public Object execute() throws Throwable {*/
            
            NodeRef nrUser = Authentication.getInstance().getUserNodeRef(ticket);
            String userName = DefaultTypeConverter.INSTANCE.convert(String.class, AlfrescoServices.getNodeService().getProperty(nrUser, ContentModel.PROP_USERNAME));
            
            WorkflowTask task = AlfrescoServices.getWorkflowService().getTaskById(taskId);
            
            // update map
            Map<QName, Serializable> updateProperties = new HashMap<QName, Serializable>();
            
            // comment
            if(comment != null) {
               updateProperties.put(QName.createQName(BPM_DESCRIPTION_QNAME), comment);
            }
            
            // package
            if(nrPackage != null) {
               updateProperties.put(WorkflowModel.ASSOC_PACKAGE, new NodeRef(nrPackage));
            }
            
            // TODO: due date
            // parameters.put(WorkflowModel.PROP_DUE_DATE, dueDate);

             // assignee node reference
             NodeRef nrAssignee = AlfrescoServices.getPersonService().getPerson(assigneeUsername);

             if(nrAssignee != null) {
                //updateProperties.put(WorkflowModel.ASSOC_ASSIGNEE, assigneeUsername);
                updateProperties.put(WorkflowModel.ASSOC_ASSIGNEE, nrAssignee);
                
                updateProperties.put(ContentModel.PROP_OWNER, assigneeUsername);
                
               // auth 1 begin
               net.sf.acegisecurity.Authentication auth = AuthenticationUtil.setSystemUserAsCurrentUser();
               
                // update task
                AlfrescoServices.getWorkflowService().updateTask(taskId, updateProperties, null, null);
               
                // execute task
                String pathId = task.path.id;
               AlfrescoServices.getWorkflowService().signal(pathId, transitionId);

               NodeRef nrCompanyHome = getCompanyHomeNodeRef();
               AlfrescoServices.getPermissionService().setPermission(nrCompanyHome, userName, PermissionService.COORDINATOR, true);
               AuthenticationUtil.setCurrentUser(userName);
               // auth 1 end
                               
               // auth 2 begin
               AuthenticationUtil.setSystemUserAsCurrentUser();
               AlfrescoServices.getPermissionService().deletePermission(nrCompanyHome, userName, PermissionService.COORDINATOR);
               AuthenticationUtil.setCurrentUser(userName);
               // auth 2 end
             }

            /*return null;
         }
      };
      
      transactionService.getRetryingTransactionHelper().doInTransaction(work);*/
   }

joko71
Confirmed Champ
Confirmed Champ
I solved the problem, so this thread can be closed.

It seems that I approached this problem wrong way. My assumption that I have to set properties first before updateTask was wrong. Right approach is to signal task first, then from path end old task with endTask, and then update new task from path, especially with bpmSmiley Surprisedwner value which will transfer task to the new owner.

java
Champ in-the-making
Champ in-the-making

" Right approach is to signal task first, then from path end old task with endTask, and then update new task from path, especially with bpmSmiley Surprisedwner value which will transfer task to the new owner."

I didn't get above clarification, can you explain it in more detail.

Thanks in Advance

cjimenez2581
Champ in-the-making
Champ in-the-making
Haven't found a solution for my problems yet…

My serial workflow is working perfectly in Alfresco web client, I can assign new actor when I perform a task, but I can't do the same in Java code. Java method updateTask does not update task properties with the actor necessary for the next task.

Anyone?


how did you assign a new actor?
please Itll be useful for me Smiley Very Happy