Metadonnees et Workflow

cancel
Showing results for 
Search instead for 
Did you mean: 
delaruelle
Member II

Metadonnees et Workflow

Bonjour

Comment assigner une valeur à une méta donnée pendant le déroulement d'un Workflow
La date est bien récupérée mais pas le nom du valideur !

Si quelqu'un a une solution  :idea:

J'utilise Alfresco 3.3g et voici mon code :

- <transition to="endValidation" name="validate">
- <script>
  <variable name="dps_validateOK" access="read,write" />
  <expression>dps_validateOK = dps_validateOK +1;</expression>
  </script>
  </transition>
  </task-node>
- <join name="endValidation">
  <transition to="isValidated" />
  </join>
- <decision name="isValidated">
- <event type="node-enter">
- <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
- <script>
  <variable name="dps_validatorsCount" access="write" />
  <expression>dps_validators.size();</expression>
  </script>
  </action>
  </event>
- <transition to="validated" name="validated">
  <condition>#{dps_validateOK == dps_validatorsCount}</condition>
- <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
  <runas>admin</runas>
- <script>
bpm_package.children[0].properties["custom:validationDate"] = new Date(); bpm_package.children[0].assocs["custom:validators"][0].properties["cm:person"] = dps_validators; bpm_package.children[0].save();

  </script>
  </action>
  </transition>


Merci pour votre aide.

Cordialement
3 Replies
jayjayecl
Active Member II

Re: Metadonnees et Workflow

Le validateur est bien les reponsable d'une des tâches du workflow ?
Pourriez-vous fournir le processdefinition.xml et le model.xml ?

MErci
delaruelle
Member II

Re: Metadonnees et Workflow

Bonjour.

Oui, le validateur est bien les reponsable d'une des tâches du workflow.

Les codes :

Web Client Config Custom

<!–
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at
   
    http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
   
–>
<!–
   |
   | Default configuration for showing the few types defined
   | in the model.
   | A number of typical use cases commented samples is also available
   |
    –>
<alfresco-config>
   <!– English is the default language.  Add additional languages to the list in the login page –>
   <config evaluator="string-compare" condition="Languages">
      <languages>
         <language locale="fr_FR">French</language>
      </languages>
   </config>
  
   <!– ********************************** –>
   <!–               DPS RQSE             –>
   <!– ********************************** –>
   <config evaluator="node-type" condition="dps:validationTask" replace="true">
      <property-sheet>
         <separator name="sep1" display-label-id="general" component-generator="HeaderSeparatorGenerator" />
         <show-property name="bpm:taskId" />
         <show-property name="bpm:comment" component-generator="TextAreaGenerator" />
      </property-sheet>
   </config>
   <config evaluator="node-type" condition="dps:approvalTask" replace="true">
      <property-sheet>
         <separator name="sep1" display-label-id="general" component-generator="HeaderSeparatorGenerator" />
         <show-property name="bpm:taskId" />
         <show-property name="bpm:comment" component-generator="TextAreaGenerator" />
      </property-sheet>
   </config>  
   <config evaluator="node-type" condition="dps:submitValidationTask" replace="true">
      <property-sheet>
         <separator name="sep1" display-label-id="general" component-generator="HeaderSeparatorGenerator" />
         <separator name="sep2" display-label-id="users_and_roles" component-generator="HeaderSeparatorGenerator" />
         <show-association name="dps:validators" display-label="Valideurs" />
      </property-sheet>
   </config>   
   <config evaluator="node-type" condition="dps:submitApprovalTask" replace="true">
      <property-sheet>
         <separator name="sep1" display-label-id="general" component-generator="HeaderSeparatorGenerator" />
         <separator name="sep2" display-label-id="users_and_roles" component-generator="HeaderSeparatorGenerator" />
         <show-association name="dps:approvers" display-label="Approbateurs" />
      </property-sheet>
   </config>          
  
   <!– ********************************** –>
   <!–           DOCUMENT  DETAILS        –>
   <!– ********************************** –>
   <!– Lists the custom aspect in business rules Action wizard –>
   <config evaluator="string-compare" condition="Action Wizards">
      <aspects>
         <aspect name="custom:DocumentDetails"/>
      </aspects>
   </config>

   <!– Displays the properties in view details page –>
   <config evaluator="aspect-name" condition="custom:DocumentDetails">
      <property-sheet>
          <show-property name="custom:reference"/>
         <show-property name="custom:keyWords"/>
         <show-property name="custom:versionDate"/>
         <show-property name="custom:versionObject"/>
         <separator name="sep1" display-label="Validation" component-generator="HeaderSeparatorGenerator" />
         <show-property name="custom:validationDate"/>
         <show-association name="custom:validators" display-label="Valideurs" />
         <separator name="sep2" display-label="Approbation" component-generator="HeaderSeparatorGenerator" />
         <show-property name="custom:approvalDate"/>
         <show-association name="custom:approvers" display-label="Approbateurs" />
         <separator name="sep3" display-label="Mise en ligne" component-generator="HeaderSeparatorGenerator" />
         <show-property name="custom:publishDate"/>
         <show-association name="custom:publisher" display-label="Publieur" />
      </property-sheet>
   </config>

</alfresco-config>

Process Definition

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

<process-definition xmlns="urn:jbpm.org:jpdl-3.2"
   name="dps:rqsereview">
   <swimlane name="initiator" />

   <start-state name="start">
      <task name="dps:submitValidationTask" swimlane="initiator" />
      <event type="node-leave">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               if (!bpm_package.children[0].hasAspect("cm:versionable")){
                  bpm_package.children[0].addAspect("cm:versionable");
                  bpm_package.children[0].save();
               }
               </script>
         </action>
      </event>
      <transition to="startValidation" name="startValidation"/>
   </start-state>


   <node name="startValidation">
      <action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
         <foreach>#{dps_validators}</foreach>
         <var>validator</var>
      </action>
      <event type="node-enter">
         <script>
            <variable name="dps_validateOK" access="write" />
            <variable name="dps_validateKO" access="write" />
            <expression>
               dps_validateOK = 0;
               dps_validateKO = 0;
            </expression>
            
         </script>
      </event>
      <transition to="validation">
      <!–
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <runas>admin</runas>
            <script>
               var mail = actions.create("mail");
               mail.parameters.to = validator.properties.email;
               mail.parameters.subject = "Validation d'un document";
               mail.parameters.from =   "noreply@docapost-dps.com";
               mail.parameters.text = initiator.properties.firstName + " " +
               initiator.properties.lastName +
               " Vous a envoyé un document pour validation, " +
               " \n Merci d'aller sur la GED pour valider le document";
               mail.execute(bpm_package);
                </script>
         </action>
      –>
      </transition>
   </node>

   <task-node name="validation">
      <task name="dps:validationTask">
         <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
            <actor>#{validator}</actor>
         </assignment>
      </task>
      <transition to="endValidation" name="reject">
         <script>
            <variable name="dps_validateKO" access="read,write" />
            <expression>
               dps_validateKO = dps_validateKO +1;
                 </expression>
         </script>
      </transition>
      <transition to="endValidation" name="validate">
         <script>
            <variable name="dps_validateOK" access="read,write" />
            <expression>
               dps_validateOK = dps_validateOK +1;
                 </expression>
         </script>
      </transition>
   </task-node>

   <join name="endValidation">
      <transition to="isValidated"></transition>
   </join>

   <decision name="isValidated">
      <event type="node-enter">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <variable name="dps_validatorsCount" access="write" />
               <expression>dps_validators.size();</expression>
            </script>
         </action>
      </event>
      <transition to="validated" name="validated">
         <condition>#{dps_validateOK == dps_validatorsCount}</condition>
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <runas>admin</runas>
              <script>
                 bpm_package.children[0].properties["custom:validationDate"] = new Date();
                 bpm_package.children[0].assocs["custom:validators"][0].properties["cm:person"] = dps_validators;
                 bpm_package.children[0].save();
                 <!–
                  var mail = actions.create("mail");
                  mail.parameters.to = initiator.properties.email;
                  mail.parameters.subject = "Document validé";
                  mail.parameters.from = "noreply@docapost-dps.com";
                  mail.parameters.text = "Document est validé  \n https://srvdps14.dap.lan:8443/alfresco/faces/jsp/login.jsp";
                  mail.execute(bpm_package);
                   –>
              </script>
            </action>
      </transition>
      <transition to="rejected" name="rejected">
         <condition>#{dps_validateKO > 0}</condition>
         <!–
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <runas>admin</runas>
              <script>
                  var mail = actions.create("mail");
                  mail.parameters.to = initiator.properties.email;
                  mail.parameters.subject = "Document rejeté";
                  mail.parameters.from = "noreply@docapost-dps.com";
                  mail.parameters.text = "Document est rejeté  \n https://srvdps14.dap.lan:8443/alfresco/faces/jsp/login.jsp";
                  mail.execute(bpm_package);
              </script>
            </action>
      –>
      </transition>
   </decision>
   <task-node name="validated">
      <task name="dps:submitApprovalTask" swimlane="initiator" />
      <transition to="startApproval" name="startApproval"/>
   </task-node>

   <node name="startApproval">
      <action class="org.alfresco.repo.workflow.jbpm.ForEachFork">
         <foreach>#{dps_approvers}</foreach>
         <var>approver</var>
      </action>
      <event type="node-enter">
         <script>
            <variable name="dps_approveOK" access="write" />
            <variable name="dps_approveKO" access="write" />
            <expression>
               dps_approveOK = 0;
               dps_approveKO = 0;
                </expression>
            </script>
      </event>
      <transition to="approval">
      <!–
      <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <runas>admin</runas>
            <script>
               var mail = actions.create("mail");
               mail.parameters.to = approver.properties.email;
               mail.parameters.subject = "Approbation d'un document";
               mail.parameters.from =   "noreply@docapost-dps.com";
               mail.parameters.text = initiator.properties.firstName + " " +
               initiator.properties.lastName +
               " Vous a envoyé un document pour approbation, " +
               " \n Merci d'aller sur la GED pour approuver le document";
               mail.execute(bpm_package);
                </script>
         </action>
      –>
      </transition>
   </node>

   <task-node name="approval">
      <task name="dps:approvalTask">
         <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
            <actor>#{approver}</actor>
         </assignment>
      </task>
      <transition to="endApproval" name="approve">
         <script>
            <variable name="dps_approveOK" access="read,write" />
            <expression>
               dps_approveOK = dps_approveOK +1;
                 </expression>
         </script>
      </transition>
      <transition to="endApproval" name="reject">
         <script>
            <variable name="dps_approveKO" access="read,write" />
            <expression>
               dps_approveKO = dps_approveKO +1;
                 </expression>
         </script>

      </transition>
   </task-node>

   <join name="endApproval">
      <transition to="isApproved"></transition>
   </join>

   <decision name="isApproved">
      <event type="node-enter">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
               <variable name="dps_approversCount" access="write" />
               <expression>dps_approvers.size();</expression>
            </script>
         </action>
      </event>
      <transition to="approved" name="approved">
         <condition>#{dps_approveOK == dps_approversCount}</condition>
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <runas>admin</runas>
              <script>
                 bpm_package.children[0].properties["custom:approvalDate"] = new Date();
                 bpm_package.children[0].assocs["custom:approvers"][0].properties["cm:person"]  = dps_approvers;
                 bpm_package.children[0].save();
              <!–
                  var mail = actions.create("mail");
                  mail.parameters.to = initiator.properties.email;
                  mail.parameters.subject = "Document approuvé";
                  mail.parameters.from = "noreply@docapost-dps.com";
                  mail.parameters.text = "Document est approuvé  \n https://srvdps14.dap.lan:8443/alfresco/faces/jsp/login.jsp";
                  mail.execute(bpm_package);
              –>
              </script>
            </action>
      </transition>
      <transition to="rejected" name="rejected">
         <condition>#{dps_approveKO > 0}</condition>
         <!–
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <runas>admin</runas>
              <script>
                  var mail = actions.create("mail");
                  mail.parameters.to = initiator.properties.email;
                  mail.parameters.subject = "Document rejeté";
                  mail.parameters.from = "noreply@docapost-dps.com";
                  mail.parameters.text = "Document est rejeté  \n https://srvdps14.dap.lan:8443/alfresco/faces/jsp/login.jsp";
                  mail.execute(bpm_package);
              </script>
            </action>
      –>
      </transition>
   </decision>

   <task-node name="rejected">
      <task name="dps:rejectedTask" swimlane="initiator" />
      <transition to="end"/>
   </task-node>


   <task-node name="approved">
      <task name="dps:approvedTask" swimlane="initiator" />
      <event type="node-leave">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
                 bpm_package.children[0].properties["custom:publishDate"] = new Date();
                 bpm_package.children[0].assocs["custom:publisher"][0].properties["cm:person"]  = initiator;
                 bpm_package.children[0].save();
                 
               <!– The document name –>
               var documentname = bpm_package.children[0].properties.name;
               <!– The root folder of the space –>
               var rootfolder = bpm_package.children[0].parent.parent;
               <!– Remove the old document from the roor folder–>
               var olddocument = rootfolder.childByNamePath(documentname);
               if(olddocument != null){
                  olddocument.remove();
               }
               <!– Copy the new document to the root folder of the space–>
               bpm_package.children[0].copy(rootfolder);
               
               <!– Remove the versionable aspect from copy document–>
               var newdocument = rootfolder.childByNamePath(documentname);
               if(newdocument != null){
                  if (newdocument.hasAspect("cm:versionable")){
                     newdocument.removeAspect("cm:versionable");
                     newdocument.save();
                  }
               }
               
            </script>
         </action>
      </event>
      <transition to="end" name="publish"/>
   </task-node>
   
   <end-state name="end"/>
</process-definition>

Custom Model

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

   <!– Custom Model –>

   <!–
      Note: This model is pre-configured to load at startup of the
      Repository. So, all custom
   –>
   <!–
      types and aspects added here will automatically be registered
   –>

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

   <!– Optional meta-data about the model –>
   <description>Custom Model</description>
   <author></author>
   <version>1.0</version>

   <imports>
      <import uri="http://www.alfresco.org/model/bpm/1.0" prefix="bpm" />
      <!– Import Alfresco Dictionary Definitions –>
      <import uri="http://www.alfresco.org/model/dictionary/1.0"
         prefix="d" />
      <!– Import Alfresco Content Domain Model Definitions –>
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
   </imports>

   <!– Introduction of new namespaces defined by this model –>
   <!–
      NOTE: The following namespace custom.model should be changed to
      reflect your own namespace
   –>
   <namespaces>
      <namespace uri="custom.model" prefix="custom" />
   </namespaces>


   <aspects>

      <!– Definition of new Content Aspect: Customer Details –>
      <aspect name="custom:DocumentDetails">
         <title>Document details</title>
         <properties>
            <property name="custom:reference">
               <title>Reference</title>
               <type>d:text</type>
            </property>
            <property name="custom:keyWords">
               <title>Key words</title>
               <type>d:text</type>
            </property>
            <property name="custom:versionDate">
               <title>Date of version</title>
               <type>d:date</type>
            </property>
            <property name="custom:versionObject">
               <title>Object of version</title>
               <type>d:text</type>
            </property>
            <property name="custom:validationDate">
               <title>Validation date</title>
               <type>d:date</type>
            </property>
            <property name="custom:approvalDate">
               <title>Approval date</title>
               <type>d:date</type>
            </property>
            <property name="custom:publishDate">
               <title>Publish date</title>
               <type>d:date</type>
            </property>
         </properties>
         <associations>
            <association name="custom:validators">
               <target>
                  <class>cm:person</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
            <association name="custom:approvers">
               <target>
                  <class>cm:person</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
            <association name="custom:publisher">
               <target>
                  <class>cm:person</class>
                  <mandatory>false</mandatory>
                  <many>false</many>
               </target>
            </association>
         </associations>
      </aspect>

   </aspects>

</model>


Voyez vous une erreur ?

Merci pour votre aide  Smiley Happy


Cordialement
cleseach
Active Member II

Re: Metadonnees et Workflow

Bonjour,

Je suppose que c'est cette ligne qui vous pose problème :
bpm_package.children[0].assocs["custom:validators"][0].properties["cm:person"] = dps_validators;

D'après ce que je vois de vos scripts, dps_validators est un tableau d'acteurs. Vous essayez donc d'affecter un tableau dans une propriété qui attend un noeud "person".
Avez-vous essayé l'expression :
bpm_package.children[0].assocs["custom:validators"][0].properties["cm:person"] = validator;

Si oui, quels sont les résultats ? Quelles sont les éventuelles erreurs remontées ?

Cordialement,
Charles Le Seac'h