AnsweredAssumed Answered

How to modify the content of bpm_package and other questions

Question asked by riogrande on Jun 3, 2009
Latest reply on Jul 9, 2009 by _sax
Hi all,

I'm working on a Workflow and I have some questions.
My workflow looks like this (in fact it's a real basic one) :

[img]http://img194.imageshack.us/img194/9379/workflow.png[/img]

So, the file come in, if the custom status is "Pending" the file enter in the validation process, otherwise it goes directly to the end (that works fine).
Then, a validator has the possibility to modify and approve the document or reject it so that the initiator has to make the corrections.
I would like to give to the Validator the possibility to valid the file directly even though the status is "Pending". The workflow has to set the file to "In" before the end (in the "IsValid" node).
Another possibility: the initiator can put directly the status to "In" to avoid the validation. 

Here is the code :

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

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="afwf:workflowTest">

   <swimlane name="initiator" />

   <swimlane name="validator">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <pooledactors>#{people.getGroup('GROUP_Administrator')}</pooledactors>
      </assignment>
   </swimlane>
   
   
   <start-state name="start">
      <task name="bpm:startTask" swimlane="initiator" />
      <transition to="IsPending">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <variable name="bpm_package" access="read" />
               <variable name="statusValue" access="read,write"/>
               <expression>
                  statusValue = bpm_package.children[0].properties["af:status"];
               </expression>
            </script>
         </action>
      </transition>
   </start-state>


   <decision name="IsPending">      
      <transition to="end" name="NoValidationNeeded">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <variable name="statusValue" access="read" />
               <expression>
                  logger.log("No validation needed, because status is set to '" + statusValue + "' need 'Pending'");
               </expression>
            </script>
         </action>         
      </transition>
      <transition to="Validation" name="ValidationNeeded">
         <condition>#{statusValue == "Pending"}</condition>   
      </transition>
   </decision>


   <task-node name="Validation">
      <task name="afwf:validation" swimlane="validator" />
      <transition to="IsValid" name="approved"></transition>
      <transition to="Correction" name="reject"></transition>
   </task-node>


   <task-node name="Correction">
      <task name="afwf:correction" swimlane="initiator" />
      <transition to="IsPending" name="done">   
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <variable name="bpm_package" access="read" />
               <variable name="statusValue" access="read,write"/>
               <expression>
                  statusValue = bpm_package.children[0].properties["af:status"];
               </expression>
            </script>
         </action>      
      </transition>
   </task-node>


   <node name="IsValid">
      <transition to="end">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <runas>admin</runas>
               <variable name="bpm_package" access="read" />
               <expression>
               logger.log("Is in IsValid");
                  if(bpm_package.children[0].properties["af:status"] == "Pending"){
                     bpm_package.children[0].properties["af:status"] = "In";
                     logger.log("Status set to 'In'");
                  }
               </expression>
            </script>
         </action>   
      </transition>
   </node>


   <end-state name="end">
      <event type="node-enter">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <expression>
                  logger.log("End of the Physical Archive Validation !");
               </expression>
            </script>
         </action>
      </event>      
   </end-state>

</process-definition>


The workflow is launched by a .js file and it works very well.

Now I have 3 problems (I couldn't put the three in the title of the topic :) )

1.- After the "Correction" task I made an update of the "statusValue" variable, but I doesn't work because it always returns to "Validation" (never get out of the loop).
2.- "bpm_package.children[0].properties["af:status"] = "In";" change noting and let the value to "Pending". Ok, you will say "easy, put read,write instead of read" but if I do so, I have this error :
19:46:30,375 ERROR [org.alfresco.web.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:2775)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.createWorkflowPath(JBPMEngine.java:2673)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.createWorkflowTask(JBPMEngine.java:2830)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine$26.doInJbpm(JBPMEngine.java:1711)
   at org.springmodules.workflow.jbpm31.JbpmTemplate$1.doInHibernate(JbpmTemplate.java:87)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:338)
   at org.springmodules.workflow.jbpm31.JbpmTemplate.execute(JbpmTemplate.java:80)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.endTask(JBPMEngine.java:1670)
   at org.alfresco.repo.workflow.WorkflowServiceImpl.endTask(WorkflowServiceImpl.java:544)
   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:296)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:301)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:229)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy51.endTask(Unknown Source)
   at org.alfresco.web.bean.workflow.ManageTaskDialog.transition(ManageTaskDialog.java:390)
   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:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:81)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Thread.java:619)

3.- I would like to launch the workflow when a file is added, the problem is that it is launch just at the moment the file is created and doesn't give the time to edit the custom properties I defined. So although if you put "In" at the creation of the file, it will goes in the Validation part because the default value at the creation is "Pending" (I hope I make it understandable).

So sorry for my bad English, I hope that some of you have one or more answer to give to me.

Thanks  :mrgreen:

Outcomes