AnsweredAssumed Answered

Workflow : Status on Versions

Question asked by kogangel on May 4, 2009
Hi !

I'm working to rely a task to documents version.

I need
- a status property on each version
- to change this status in workflow states
- to display this status into version history

My idea
- Create an aspect version and add it to the task node
- This aspect will save a version table of all ressources
- Create an aspect status and add it to the version node
- After a transition or an event I will find the document version node with my table and I will change the status to a new one

I tried something but when I start the workflow
- I can't see the task into "My Alfresco" (when i start another workflow it's ok)
- I don't know how to display the status into version properties or into version history
- I have some problems with addAspect(), sometime it raise an error (on version Node)

My process definition file :

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

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

   <swimlane name="initiator" />

   <start-state name="start">
       <task name="wf:submitReviewTask" swimlane="initiator" />

       <event type="node-leave">
           <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
           
               if (logger.isLoggingEnabled()) logger.log("—=== START ===—");
              
               /* Creation de l aspect versions dans la tache si il n existe pas deja */
               if (!bpm_package.hasAspect("wfl:versions")){
                  bpm_package.addAspect("wfl:versions");
                  if (logger.isLoggingEnabled())logger.log("Aspect version ajoute !");
               }
           
               /* Declaration du tableau dans lequel on stockera les versions */
               var verTable = new Array();
               if (logger.isLoggingEnabled())logger.log("Array version cree !");
           
               /* Parcours des noeuds documents */
               for (var i = 0; i &lt; bpm_package.children.length; i++){
               
                  var child = bpm_package.children[i];
                  var versions = child.getVersionHistory();
               
                  /* On recupere la version du document */
                  verTable[i] = child.properties["cm:versionLabel"];
               
                  /* Recuperation de la derniere version du document */
                  var version = child.getVersion(verTable[i]);
                  var verNode = version.getNode();
               
                  if (logger.isLoggingEnabled())logger.log("Version " + version.getLabel());
               
                  /* Creation de l aspect status de la version si il n existe pas deja */
                  try {
                     if (!verNode.hasAspect("wfl:status")){
                        verNode.addAspect("wfl:status");
                     }
                  } catch (error) { if (logger.isLoggingEnabled())logger.log("Erreur addAspect wfl:status");}
            
                  /* Acces aux properties */   
                  try{
                     logger.log("Version status : " + verNode.properties["wfl:status"]);
                  } catch (error) { if (logger.isLoggingEnabled())logger.log("Erreur acces properties");}
         
                  /* Mise a jour de l aspect versions qui prend le tableau de versions */
                  bpm_package.properties["wfl:versions"] = verTable;
                  bpm_package.save();
                  if (logger.isLoggingEnabled())logger.log("Version mise a jour !");
            
               }
               
               </script>
           </action>
       </event>

       <transition name="" to="review" />
   </start-state>

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

   <task-node name="review">
       <event type="node-enter">
           <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
           
               if (logger.isLoggingEnabled()) logger.log("—=== REVIEW : node-enter ===—");
           
               /* Recuperation du tableau de version dans la tache */
               var verTable = bpm_package.properties["wfl:versions"];
               if (logger.isLoggingEnabled())logger.log("Tableau des versions recupere !");
           
               /* Parcours des noeuds documents */
               for (var i = 0; i &lt; bpm_package.children.length; i++){
           
                  var child = bpm_package.children[i];
                  var versions = child.getVersionHistory();
            
                  /* Recuperation de la bonne version du document */
                  var version = child.getVersion(verTable[i]);
                  var verNode = version.getNode();
             
                  if (logger.isLoggingEnabled())logger.log("Version url : " + verNode.getUrl());
               
                  verNode.properties["wfl:status"] = "In Review";
                  verNode.save();
               
                  try{
                     logger.log("Version status : " + verNode.properties["wfl:status"]);
                  }    catch (error) { logger.log("Erreur acces properties");}

               }
               
               </script>
           </action>
       </event>

       <task name="wf:reviewTask" swimlane="reviewer">
           <event type="task-create">
               <script>
                   if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
                   if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
               </script>
           </event>
       </task>
       
       <transition name="reject" to="rejected" />
       <transition name="approve" to="approved" />
   </task-node>

My model file :
<?xml version="1.0" encoding="UTF-8"?>

<model name="wfl:workflowlifecyclemodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <description>Workflow Lifecycle Model</description>
   <author></author>
   <version>1.0</version>

   <imports>
       <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
       <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
      <import uri="http://www.alfresco.org/model/bpm/1.0" prefix="bpm"/>
   </imports>

   <namespaces>
       <namespace uri="wfl.model" prefix="wfl" />
   </namespaces>

   <constraints>
       <constraint name="wfl:status" type="LIST">
           <parameter name="allowedValues">
               <list>
                   <value>Draft</value>
                   <value>In Review</value>
                   <value>Approved</value>
               </list>
           </parameter>
       </constraint>
   </constraints>

   <aspects>
       <aspect name="wfl:status">
           <title>Status</title>
           <properties>
               <property name="wfl:status">
                   <title>Status</title>
                   <type>d:text</type>
                   <default>Draft</default>
                   <constraints>
                       <constraint ref="wfl:status" />
                   </constraints>
               </property>
           </properties>
       </aspect>
     
      <aspect name="wfl:versions">
           <title>Version Tache</title>
           <properties>
               <property name="wfl:versions">
                   <title>Version Tache</title>
                   <type>d:any</type>
               </property>
           </properties>
       </aspect>
     
   </aspects>
  
</model>

Any help will be welcome
And I'm sorry in advance for my poor english

Thx :mrgreen:

Outcomes