AnsweredAssumed Answered

Création d'une action pour Workflow Avancé [Résolu]

Question asked by huberd on Oct 16, 2007
Latest reply on Oct 24, 2007 by huberd
J'essaie de récuperer les informations relatives au document sur lequel j'ai lancé un Workflow de validation avancé.

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

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wf:LPRvalidation">
 
   <swimlane name="initiator"/>
   
   <start-state name="start">
      <task name="lwf:submitReviewAndApprovalTask" swimlane="initiator" />
      <event type="node-leave">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               for (var i = 0; i < bpm_package.children.length; i++)
               {
                 if (!bpm_package.children[i].hasAspect("lpr:DocumentStatus"))
                 {
                   bpm_package.children[i].addAspect("lpr:DocumentStatus");
                 }
                 logger.log("Leave Start Node : " + bpm_package.children[i].properties["lpr:DocumentStatus"]);
               }
             </script>
         </action>
         <action class="lpr.alfresco.repo.workflow.jbpm.ReviewDocuments"/>
      </event>
      <transition name="" to="startreview"/>
   </start-state>
  
   <node name="startreview">
      <action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
         <foreach>#{lwf_reviewAssignees}</foreach>
         <var>reviewer</var>
      </action>
      <event type="node-enter">
         <script>
            <variable name="lwf_reviewCount" access="write" />
            <expression>
               lwf_reviewCount = 0;
            </expression>
         </script>
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <variable name="lpr_DocumentStatus" access="write" />
               <expression>
                  for (var i = 0; i < bpm_package.children.length; i++)
                  {
                    bpm_package.children[i].properties["lpr:DocumentStatus"] = "In Review";
                    bpm_package.children[i].save();
                    logger.log("Enter Node Start Review : " + bpm_package.children[i].properties["lpr:DocumentStatus"]);
               }
               </expression>
            </script>
         </action>
      </event>
      <transition name="review" to="review"/>
   </node>
  
   <task-node name="review">
      <task name="lwf_reviewTask">
         <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
            <actor>#{reviewer}</actor>
         </assignment>
      </task>
      <event type="node-enter">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               for (var i = 0; i < bpm_package.children.length; i++)
               {
                 logger.log("Enter Node Review : " + bpm_package.children[i].properties["lpr:DocumentStatus"]);
               }
            </script>
         </action>
      </event>
      <transition name="reject" to="endReview" />
      <transition name="approve" to="endReview" >
         <script>
            <variable name="lwf_reviewCount" access="read,write" />
            <expression>
               lwf_reviewCount = lwf_reviewCount + 1;
            </expression>
         </script>
      </transition>
   </task-node>
  
   <join name="endReview">
      <event type="node-enter">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               for (var i = 0; i < bpm_package.children.length; i++)
               {
                 logger.log("Enter Node End Review (Join) : " + bpm_package.children[i].properties["lpr:DocumentStatus"]);
               }
            </script>
         </action>
      </event>
      <transition to="isreviewed" />
   </join>

   <decision name="isreviewed">
      <event type="node-enter">
         <script>
            <variable name="lwf_reviewerCount" access="Write"/>
            <variable name="lwf_requiredReviewerPercent" access="Write"/>
            <variable name="lwf_actualReviewerPercent" access="Write"/>
            <expression>
               lwf_requiredReviewerPercent = lwf_requiredReviewPercent;
               lwf_reviewerCount = lwf_reviewAssignees.size();
               lwf_actualReviewerPercent = ((lwf_reviewCount * 100) / lwf_reviewerCount);
            </expression>
         </script>
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               for (var i = 0; i < bpm_package.children.length; i++)
               {
                 logger.log("Enter Node Is Reviewed : " + bpm_package.children[i].properties["lpr:DocumentStatus"]);
               }
            </script>
         </action>        
      </event>
      <transition name="reject" to="rejectedReview"/>
      <!–transition name="approve" to="approvedReview"–>
      <transition name="approve" to="startapproval">
         <condition>#{lwf_actualReviewerPercent >= lwf_requiredReviewerPercent}</condition>
      </transition>  
   </decision>
  
   <task-node name="rejectedReview">
      <task name="lwf:rejectedReviewTask" swimlane="initiator" />
      <event type="node-enter">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               for (var i = 0; i < bpm_package.children.length; i++)
               {
                 bpm_package.children[i].properties["lpr:DocumentStatus"] = "Draft";
                 bpm_package.children[i].save();
                 logger.log("Enter Node Reject Review : " + bpm_package.children[i].properties["lpr:DocumentStatus"]);
               }
            </script>
         </action>     
      </event>
      <transition to="end"/>
   </task-node>
  
   <!–task-node name="approvedReview">
      <task name="lwf:approvedReviewTask" swimlane="initiator" />
      <transition to="startapproval"/>
   </task-node–>
  
   <node name="startapproval">
      <action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
         <foreach>#{lwf_approvalAssignees}</foreach>
         <var>approval</var>
      </action>
      <event type="node-enter">
         <script>
            <variable name="lwf_approvalCount" access="write" />
            <expression>
               lwf_approvalCount = 0;
            </expression>
         </script>
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               for (var i = 0; i < bpm_package.children.length; i++)
               {
                 bpm_package.children[i].properties["lpr:DocumentStatus"] = "For Approval";
                 bpm_package.children[i].save();
                 logger.log("Enter Node Start Approval : " + bpm_package.children[i].properties["lpr:DocumentStatus"]);
               }
            </script>
         </action>   
      </event>
      <transition name="approval" to="approval"/>
   </node>
  
   <task-node name="approval">
      <task name="lwf_approvalTask">
         <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
            <actor>#{approval}</actor>
         </assignment>
      </task>
      <event type="node-enter">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               for (var i = 0; i < bpm_package.children.length; i++)
               {
                 logger.log("Enter Node Approval : " + bpm_package.children[i].properties["lpr:DocumentStatus"]);
               }
            </script>
         </action>        
      </event>
      <transition name="reject" to="endApproval" />
      <transition name="approve" to="endApproval" >
         <script>
            <variable name="lwf_approvalCount" access="read,write" />
            <expression>
               lwf_approvalCount = lwf_approvalCount + 1;
            </expression>
         </script>
      </transition>
   </task-node>  
 
   <join name="endApproval">
      <event type="node-enter">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               for (var i = 0; i < bpm_package.children.length; i++)
               {
                 logger.log("Enter Node End Approval (Join) : " + bpm_package.children[i].properties["lpr:DocumentStatus"]);
               }
            </script>
         </action>
      </event>  
      <transition to="isapproved" />
   </join>

   <decision name="isapproved">
      <event type="node-enter">
         <script>
            <variable name="lwf_approbatorCount" access="Write"/>
            <variable name="lwf_requiredApprobatorPercent" access="Write"/>
            <variable name="lwf_actualApprobatorPercent" access="Write"/>
            <expression>
               lwf_requiredApprobatorPercent = lwf_requiredApprovalPercent;
               lwf_approbatorCount = lwf_approvalAssignees.size();
               lwf_actualApprobatorPercent = ((lwf_approvalCount * 100) / lwf_approbatorCount);
            </expression>
         </script>
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               for (var i = 0; i < bpm_package.children.length; i++)
               {
                 logger.log("Enter Node Is Approved : " + bpm_package.children[i].properties["lpr:DocumentStatus"]);
               }
            </script>
         </action>               
      </event>
      <transition name="reject" to="rejectedApproval"/>
      <transition name="approve" to="approvedApproval">
         <condition>#{lwf_actualApprobatorPercent >= lwf_requiredApprobatorPercent}</condition>
      </transition>  
   </decision>  

   <task-node name="rejectedApproval">
      <task name="lwf:rejectedApprovalTask" swimlane="initiator" />
      <event type="node-enter">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               for (var i = 0; i < bpm_package.children.length; i++)
               {
                 bpm_package.children[i].properties["lpr:DocumentStatus"] = "Draft";
                 bpm_package.children[i].save();
                 logger.log("Enter Node Reject Approval : " + bpm_package.children[i].properties["lpr:DocumentStatus"]);
               }
            </script>
         </action>     
      </event>     
      <transition to="end"/>
   </task-node>
  
   <task-node name="approvedApproval">
      <task name="lwf:approvedApprovalTask" swimlane="initiator" />
      <event type="node-enter">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               for (var i = 0; i < bpm_package.children.length; i++)
               {
                 bpm_package.children[i].properties["lpr:DocumentStatus"] = "Approved";
                 bpm_package.children[i].save();
                 logger.log("Enter Node Approved Approval : " + bpm_package.children[i].properties["lpr:DocumentStatus"]);
               }
            </script>
         </action>     
      </event>     
      <transition to="end"/>
   </task-node>  
     
   <end-state name="end">
      <event type="node-enter">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               for (var i = 0; i < bpm_package.children.length; i++)
               {
                 logger.log("Enter Node End : " + bpm_package.children[i].properties["lpr:DocumentStatus"]);
               }
            </script>
         </action>
      </event>  
   </end-state>     
  
</process-definition>
La ligne de code de test excecutée est la suivante :

<action class="lpr.alfresco.repo.workflow.jbpm.ReviewDocuments"/>
le code de l'action est le suivant :

package lpr.alfresco.repo.workflow.jbpm;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.workflow.jbpm.JBPMNode;
import org.alfresco.repo.workflow.jbpm.JBPMSpringActionHandler;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.apache.log4j.Logger;
import org.jbpm.graph.exe.ExecutionContext;
import org.springframework.beans.factory.BeanFactory;


public class ReviewDocuments extends JBPMSpringActionHandler {

private static final long serialVersionUID = 1L;

private static final Logger logger = Logger.getLogger(ReviewDocuments.class);
   
   private BeanFactory factory;
  
   // Property names
   public static final QName PROP_DOCUMENT_NAME = QName.createQName("cm","name");
   public static final QName PROP_DOCUMENT_STATUS = QName.createQName("lpr.model","DocumentStatus");
   
   @Override
   protected void initialiseHandler(BeanFactory factory) {
      this.factory = factory;
   }

   public void execute(ExecutionContext executionContext) throws Exception {   
      try {
         Object res = executionContext.getContextInstance().getVariable("bpm_package");
         if(res == null) {
            //never enters here
            logger.fatal("bpm_package is null");
            return;
         }
        
         final NodeRef nodeRef = ((JBPMNode) res).getNodeRef();    
         if(nodeRef == null) {
             //never enters here
            logger.fatal("NodeRef is null");
            return;
         }
         //prints value
         logger.fatal("Node ref id:" + nodeRef.getId());
         
         NodeService nodeService = (NodeService) this.factory.getBean("nodeService");
         //prints value
         logger.fatal("Prop name = " + nodeService.getProperty(nodeRef, ContentModel.PROP_NAME));
         //prints value
         logger.fatal("Prop created= " + nodeService.getProperty(nodeRef, ContentModel.PROP_CREATED));
         //prints value
         logger.fatal("Prop uuid = " + nodeService.getProperty(nodeRef, ContentModel.PROP_NODE_UUID));
         //prints value
         logger.fatal("Prop Doc Name = " + nodeService.getProperty(nodeRef, PROP_DOCUMENT_NAME));
         // prints value
         logger.fatal("Prop Doc Status = " + nodeService.getProperty(nodeRef, PROP_DOCUMENT_STATUS));
         if(nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT) != null) {
            // never enters here
            logger.warn("Content property is not null");
         }
         ContentService contentService = (ContentService) this.factory.getBean("contentService");
         ContentReader contentReader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
         
         if(contentReader == null) {
             //always goes here
            logger.fatal("Content reader not found");
            return;
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}
Le resultat d'execution est le suivant :

15:53:00,010 WARN  [web.app.ResourceBundleWrapper] Failed to find I18N message string key: lwf_reviewers
15:53:00,010 WARN  [web.app.ResourceBundleWrapper] Failed to find I18N message string key: lwf_approvals
15:53:00,010 WARN  [web.app.ResourceBundleWrapper] Failed to find I18N message string key: lwf_review_options
15:53:25,822 DEBUG [repo.jscript.RhinoScriptProcessor] Imports resolved, adding resource '_root' content:
for (var i = 0; i < bpm_package.children.length; i++) { if (!bpm_package.children[i].hasAspect("lpr:DocumentStatus")) { bpm_package.children[i].addAspect("lpr:DocumentStatus"); } logger.log("Leave Start Node : " + bpm_package.children[i].properties["lpr:DocumentStatus"]); }
15:53:25,822 DEBUG [repo.jscript.RhinoScriptProcessor] Script content resolved to:
for (var i = 0; i < bpm_package.children.length; i++) { if (!bpm_package.children[i].hasAspect("lpr:DocumentStatus")) { bpm_package.children[i].addAspect("lpr:DocumentStatus"); } logger.log("Leave Start Node : " + bpm_package.children[i].properties["lpr:DocumentStatus"]); }
15:53:26,650 DEBUG [repo.jscript.ScriptLogger] Leave Start Node : In Review
15:53:26,650 DEBUG [repo.jscript.RhinoScriptProcessor] Time to execute script: 828ms
15:53:26,666 FATAL [workflow.jbpm.ReviewDocuments] Node ref id:29ce7ab6-7bef-11dc-9d8e-319621460cee
15:53:26,666 FATAL [workflow.jbpm.ReviewDocuments] Prop name = 29ce7ab6-7bef-11dc-9d8e-319621460cee
15:53:26,666 FATAL [workflow.jbpm.ReviewDocuments] Prop created= Tue Oct 16 15:53:24 CEST 2007
15:53:26,666 FATAL [workflow.jbpm.ReviewDocuments] Prop uuid = 29ce7ab6-7bef-11dc-9d8e-319621460cee
15:53:26,666 FATAL [workflow.jbpm.ReviewDocuments] Prop Doc Name = null
15:53:26,666 FATAL [workflow.jbpm.ReviewDocuments] Prop Doc Status = null
15:53:26,666 FATAL [workflow.jbpm.ReviewDocuments] Content reader not found
15:53:27,150 DEBUG [repo.jscript.RhinoScriptProcessor] Imports resolved, adding resource '_root' content:
for (var i = 0; i < bpm_package.children.length; i++) { bpm_package.children[i].properties["lpr:DocumentStatus"] = "In Review"; bpm_package.children[i].save(); logger.log("Enter Node Start Review : " + bpm_package.children[i].properties["lpr:DocumentStatus"]); }
15:53:27,150 DEBUG [repo.jscript.RhinoScriptProcessor] Script content resolved to:
for (var i = 0; i < bpm_package.children.length; i++) { bpm_package.children[i].properties["lpr:DocumentStatus"] = "In Review"; bpm_package.children[i].save(); logger.log("Enter Node Start Review : " + bpm_package.children[i].properties["lpr:DocumentStatus"]); }
15:53:27,291 DEBUG [repo.jscript.ScriptLogger] Enter Node Start Review : In Review
15:53:27,291 DEBUG [repo.jscript.RhinoScriptProcessor] Time to execute script: 141ms
15:53:27,307 DEBUG [repo.jscript.RhinoScriptProcessor] Imports resolved, adding resource '_root' content:
lwf_reviewAssignees
15:53:27,307 DEBUG [repo.jscript.RhinoScriptProcessor] Script content resolved to:
lwf_reviewAssignees
15:53:27,322 DEBUG [repo.jscript.RhinoScriptProcessor] Time to execute script: 15ms
15:53:27,353 DEBUG [repo.jscript.RhinoScriptProcessor] Imports resolved, adding resource '_root' content:
for (var i = 0; i < bpm_package.children.length; i++) { logger.log("Enter Node Review : " + bpm_package.children[i].properties["lpr:DocumentStatus"]); }
15:53:27,353 DEBUG [repo.jscript.RhinoScriptProcessor] Script content resolved to:
for (var i = 0; i < bpm_package.children.length; i++) { logger.log("Enter Node Review : " + bpm_package.children[i].properties["lpr:DocumentStatus"]); }
15:53:27,369 DEBUG [repo.jscript.ScriptLogger] Enter Node Review : In Review
15:53:27,369 DEBUG [repo.jscript.RhinoScriptProcessor] Time to execute script: 16ms
15:53:27,416 DEBUG [repo.jscript.RhinoScriptProcessor] Imports resolved, adding resource '_root' content:
reviewer
15:53:27,416 DEBUG [repo.jscript.RhinoScriptProcessor] Script content resolved to:
reviewer
15:53:27,432 DEBUG [repo.jscript.RhinoScriptProcessor] Time to execute script: 16ms
Dans ce résultat, je n'arrive pas à faire afficher les informations relatives au document tel que le status, le nom du document en clair et non le node ID, …

15:53:26,666 FATAL [workflow.jbpm.ReviewDocuments] Node ref id:29ce7ab6-7bef-11dc-9d8e-319621460cee
15:53:26,666 FATAL [workflow.jbpm.ReviewDocuments] Prop name = 29ce7ab6-7bef-11dc-9d8e-319621460cee
15:53:26,666 FATAL [workflow.jbpm.ReviewDocuments] Prop created= Tue Oct 16 15:53:24 CEST 2007
15:53:26,666 FATAL [workflow.jbpm.ReviewDocuments] Prop uuid = 29ce7ab6-7bef-11dc-9d8e-319621460cee
15:53:26,666 FATAL [workflow.jbpm.ReviewDocuments] Prop Doc Name = null
15:53:26,666 FATAL [workflow.jbpm.ReviewDocuments] Prop Doc Status = null
Si quelqu'un peut m'aider car je patauge sérieusement.

A terme je souhaite dans mon code Java, effectuer des opérations de déplacement de document (répertoire Drafts vers Review puis ver Approval) au fur et à mesure des étapes de validation tout cela en ayant uniquement les droits de lecture sur le document à valider.

Outcomes