cancel
Showing results for 
Search instead for 
Did you mean: 

How to modify the content of bpm_package and other questions

riogrande
Champ in-the-making
Champ in-the-making
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 Smiley Happy )

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:
16 REPLIES 16

riogrande
Champ in-the-making
Champ in-the-making
The point 1.- works after all (I didn't know way not yesterday). The two other point are still open.

riogrande
Champ in-the-making
Champ in-the-making
3.- solved… in fact it was very easy too :roll:, instead of "inbound" I put "update" for the rule type.

On the other hand, the point 2 is still a big problem 😕

_sax
Champ in-the-making
Champ in-the-making
Did you try to leave out runas, variable and expression?

   <node name="IsValid">
      <transition to="end">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               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'");
                  }
            </script>
         </action>  
      </transition>
   </node>

I don't know, if your files have the property you try to access, "undefined" would point to that.
If not, just add it:

                   for (var i = 0; i &lt; bpm_package.children.length; i++)
                   {
                      if (!bpm_package.children.hasAspect("af:NameOfAspectContainingFieldStatus"))
                      {
                           bpm_package.children.addAspect("af:NameOfAspectContainingFieldStatus");
                           bpm_package.children.save();
                           if (logger.isLoggingEnabled()) logger.log ("Aspect NameOfAspectContainingFieldStatus added");
                      }

riogrande
Champ in-the-making
Champ in-the-making
Yes, I find last Friday how to manage it, here there is the working code :


   <script>
      <variable name="bpm_package" access="read" />
      <expression>
         if(bpm_package.children[0].properties["af:status"] == "Pending"){
            bpm_package.children[0].properties["af:status"] = "In";
             bpm_package.children[0].save();
         }
      </expression>
   </script>

But now I have an order error :

14:57:53,515 ERROR [org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl] Failed to execute asynchronous action: Action[ id=9a7858e3-0dc4-4752-8b3b-8e436b43cd0f, node=workspace://SpacesStore/9a7858e3-0dc4-4752-8b3b-8e436b43cd0f ]
org.alfresco.scripts.ScriptException: Failed to execute script 'workspace://SpacesStore/6eec7f56-58c6-4d2e-b68e-c34c32574c03': Access Denied.  You do not have the appropriate permissions to perform this operation.
   at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:184)
   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 $Proxy180.executeScript(Unknown Source)
   at org.alfresco.repo.action.executer.ScriptActionExecuter.executeImpl(ScriptActionExecuter.java:157)
   at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:127)
   at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:592)
   at org.alfresco.repo.action.executer.CompositeActionExecuter.executeImpl(CompositeActionExecuter.java:72)
   at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:127)
   at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:592)
   at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionServiceImpl.java:529)
   at org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl$ActionExecutionWrapper$1$1.execute(AsynchronousActionExecutionQueueImpl.java:369)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:320)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:227)
   at org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl$ActionExecutionWrapper$1.doWork(AsynchronousActionExecutionQueueImpl.java:378)
   at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:437)
   at org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl$ActionExecutionWrapper.run(AsynchronousActionExecutionQueueImpl.java:381)
   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
   at java.lang.Thread.run(Thread.java:619)
Caused by: org.alfresco.repo.security.permissions.AccessDeniedException: Access Denied.  You do not have the appropriate permissions to perform this operation.
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:53)
   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 $Proxy7.getProperty(Unknown Source)
   at org.alfresco.repo.processor.ScriptServiceImpl.getScriptProcessor(ScriptServiceImpl.java:339)
   at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:175)
   … 35 more
Caused by: net.sf.acegisecurity.AccessDeniedException: Access is denied.
   at net.sf.acegisecurity.vote.AffirmativeBased.decide(AffirmativeBased.java:86)
   at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:394)
   at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   … 46 more

I find out that it's generated by the action rule that I defined. When I turn it off it works fine. But now, I have no way to launch the workflow. In fact, the ideal case would be to deactivate the rule on a file if a workflow is running on it, but I don't know if it's possible  :?

Edit : the question is : how to know if a workflow is runing on a file ?

_sax
Champ in-the-making
Champ in-the-making
Your action shouldn't interfere with workflows, or is it looking for updated documents? You do update them while you're applying the status field. According to your log, it is the action, that gets no access, while yout workflow seems to work. So the action maybe tries to write something to the document in the workflow. If your action is using a script, you could check in that script the status field of your workflow documents. Or you let the rule check for the aspect that is containing your fields.

riogrande
Champ in-the-making
Champ in-the-making
Yes I'm trying to find a way to check before he launches the script if there is a workflow running on it. But for the moment I didn't find anything. 😕

_sax
Champ in-the-making
Champ in-the-making
Well you could check it in your script. And you can access the variables the way you did in your workflow. Just ask, if (Dokument.hasAspect("af:whatever")) or if (af_Variable == "WhatItShouldNotBeToBeAbleToRunTheScript").

riogrande
Champ in-the-making
Champ in-the-making
Unfortunately, the status is not enough to determine if the workflow can be started or not. The Workflow starts when you make any modification on a specific type of file, if the status is "Pending" you go throw the validation process, else the workflow ended.

Imagine that I modify something in the file during the workflow with the status still set to "Pending". It will launch a new workflow on the same file.

Perhaps can I set a "dummy" aspect (or with just something like "workflow runing" = true) when I start a workflow and then put it away at the end. But why should I do so whereas it would be so simple to have something like document.workflow.count() Smiley Tongue

_sax
Champ in-the-making
Champ in-the-making
Now I got ya!  Smiley Happy  So your rule does automatically start your workflow processdefinition
(maybe it was derived from here http://wiki.alfresco.com/wiki/WorkflowAdministration#Step_7:_Integration_with_Rules_.28Optional.29).

As far as I know, there is nothing like a workflow count - aspect for the documents in a workflow. Actually this could be a good improvement (filable at issues.alfresco.com). But then you would have the need to determine the kind of workflow, the document is in, too.
That bit (in/out of workflow) and its kind would make up an aspect on its own.
There is a workflow console, letting you follow the status and task-ids, the workflows are in (http://wiki.alfresco.com/wiki/Workflow_Console).
But I doubt that this could be read out by your script.

The problem is, that you are working in documents, that aren't yet ready for workflow, but you have a folder, that assumes, that it contains only review-ready documents. Tends to be more of a logic problem, then an issue with Alfresco.

So an imaginable workaround would be to just let documents get into your workflow-starting-folder, after they are finished and ready for review by the workflow. You could insert them manually to that folder, maybe via CIFS or you do set the status "ready" manually: This could be done by an action, displayed next to every document, linking to a script, that sets your variable to "ready". Relatively easy to implement.