cancel
Showing results for 
Search instead for 
Did you mean: 

Workflow package actions - edit resource not working?

calle
Champ in-the-making
Champ in-the-making
Hi
I have defined a custom workflow similar to "review and approve". During the review, the reviewers need to edit the document being reviewd. I found the Workflow Actions Package and the bpmSmiley TongueackageItemActionGroup property. What I understood this was exactly what I wanted. I set the property in the workflow model but still only the "properties" action is available for the reviewers.

Here is a snippet from the workflow model

      <type name="my_wf:reviewTask">
         <parent>wf:reviewTask</parent>
         <overrides>
            <property name="bpm:packageActionGroup">
               <default>add_package_item_actions</default>
            </property>
         </overrides>
      </type>

and here is the processdefinition the task

   <task-node name="review">
      <task name="sgu_wf:reviewTask">
         <assignment
            class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
            <actor>#{reviewer}</actor>
         </assignment>
      </task>
      <transition name="reject" to="endreview" />
      <transition name="approve" to="endreview">
         <script>
            <variable name="wf_approveCount" access="read,write" />
            <expression>
               wf_approveCount = wf_approveCount +1;
            </expression>
         </script>
      </transition>
   </task-node>

How do I get the bpmSmiley TongueackageActionGroup to work?
6 REPLIES 6

vinaxwater
Champ in-the-making
Champ in-the-making
I see task_name in process file and model file not the same. where do you set position for this files?

Thanks and Regards.

calle
Champ in-the-making
Champ in-the-making
I found what was wrong - the assignee needs privileges to edit the document in the workflow package. Now the all the actions are visible…

thanks
//Carl

calle
Champ in-the-making
Champ in-the-making
Now I am a bit further on my way… What I want to achieve is a workflow where all assignees has permission to edit the content od bpm_package during the workflow. I have written a script to grant permission for each assignee to edit the bpm_package:


for(var i = 0; i &lt; bpm_package.children.length; i++) {
   bpm_package.children[i].setPermission("Editor", reviewer.properties.userName);
}
Note that variable reviewer is defined defined in a ForEachFork action from bpm_assignees.

This script is in the executed in the first workflow node.

When the workflow ends I would like to remove the permissions granted to each assignee. I thought this would be done in the same way but I have two problems:
1) I can remove permissions only when the owner on anyone with "ChangePermission"-privileges is executing the script. One ugly workaround would be to not only set "Editor" privileges to each assignee but also "ChangePermission"-privileges.
2) If I remove the permissions in a node executed by the owner (initiator) of the workflow, the reviewer-variable is undefined. I have to use bpm_assignees. Now, what is bpm_assignees? What is its properties and where is it defined? When I print it I get a node cmSmiley Tongueerson but I thought it was an association…

Anyone have any reference or documentation about bpm_assignees?

calle
Champ in-the-making
Champ in-the-making
I continue to post my progress here…

The bpm_assignees was an ArrayList, I found it out with a simple bpm_assignees.getClass() … So this mean I am able to get all assignees and all resources in the workflow package. Now I want to remove the permissions for each assignee. I simply loop them through. Here is a part of my process definition with the script and the node executing the script:

<task-node name="approved">
   <task name="wf:approvedParallelTask" swimlane="initiator" />
   <transition to="end">
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
             <script>
            <variable name="bpm_assignees" access="read" />
            <variable name="bpm_package" access="read, write" />
            <expression>
               for(var j = 0; j &lt; bpm_assignees.size(); j++) {
                   var userName = bpm_assignees.get(j).properties.userName;
                  for(var i = 0; i &lt; bpm_package.children.length; i++) {
                     var resource = bpm_package.children[i];
                     resource.removePermission("Editor", userName);
                  }
               }
            </expression>
         </script>
      </action>
   </transition>
</task-node>

<end-state name="end" />

Now I do not get an error from the script but what I think is an error that origins from the bpm engine. I can not understand what is the cause from the stack trace:
23:03:49,483 ERROR [ui.common.Utils] A system error happened during the operation: org.mozilla.javascript.Undefined cannot be cast to org.alfresco.repo.workflow.jbpm.JBPMNode
java.lang.ClassCastException: org.mozilla.javascript.Undefined cannot be cast to org.alfresco.repo.workflow.jbpm.JBPMNode
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.createWorkflowInstance(JBPMEngine.java:2567)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.createWorkflowPath(JBPMEngine.java:2481)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.createWorkflowTask(JBPMEngine.java:2612)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine$25.doInJbpm(JBPMEngine.java:1543)
   at org.springmodules.workflow.jbpm31.JbpmTemplate$1.doInHibernate(JbpmTemplate.java:87)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:333)
   at org.springmodules.workflow.jbpm31.JbpmTemplate.execute(JbpmTemplate.java:80)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.endTask(JBPMEngine.java:1502)
   at org.alfresco.repo.workflow.WorkflowServiceImpl.endTask(WorkflowServiceImpl.java:444)
   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:597)
   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.audit(AuditComponentImpl.java:245)
   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 $Proxy41.endTask(Unknown Source)
   at org.alfresco.web.bean.workflow.ManageTaskDialog.transition(ManageTaskDialog.java:392)
   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:597)
   at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
   at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
   at javax.faces.component.UICommand.broadcast(UICommand.java:109)
   at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
   at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
   at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
   at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
   at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:81)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
   at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
   at java.lang.Thread.run(Thread.java:619)

Doing some debugging and looking at what happens at line 2567 in JBPMEngine I see that it tries to retrieve the "bpm_package" variable from the workflow. Normally this will return a ScriptNode but now it returns an org.mozilla.javascript.Undefined (and that is what the stack trace says as well). What in my code above could possibly cause this to happen?

Another thing I noticed is that org.alfresco.repo.workflow.jbpm.JBPMEngine.createWorkflowInstance(JBPMEngine.java:2567) is called 4 consecutive times and it is the second one that causes the exception. Every time the bpm id and instance are the same, the only difference I can tell is that when the exception is thrown the workflow is not active. It should indicate that the workflow has reached its end. I do not understand why this is the case only one out of four times and how my script has affected the workflow to behave like this.

Any ideas?

francescof
Champ in-the-making
Champ in-the-making
It seems that the AlfrescoJavaScript action is trying to set the variable "bpm_package" (declared with access = write) with the result of the JS script in the <expression> block, which is undefined. Try removing write access from the bpm_package variable declaration or adding the following JS line in the code block just after the external "for" loop:

bpm_package;

The executable block in an AlfrescoJavaScript actions is simply a JS expression which is evaluated by the JS engine. The result of this evaluation is then assigned to the one and only variable declared with write access (if present). If your JS code doesn't evaluate to any defined value than errors like the one you reported may occur.

calle
Champ in-the-making
Champ in-the-making
Thanks, it solved my problems!