cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with Aspects handling

samuele_atnis
Champ in-the-making
Champ in-the-making
Hi all,
I developed the following workflow:
 <?xml version="1.0" encoding="UTF-8"?>

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

    <swimlane name="initiator" />

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

        <event type="node-leave">
            <!– Call script once the workflow package exists i.e. on node-leave –>
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <!– Apply the Workflow Lifecycle Aspect (wfl:status) if not set already. Note: The default wfl:status property is draft –>
                <script>
          logger.log("LEAVING START STATE");
          var mail = actions.create("mail");
          mail.parameters.to = bpm_assignee.properties.email;
                     mail.parameters.subject = "Review request";
               mail.parameters.text = "Hi " + bpm_assignee.properties.userName +", \n a document has been edited.";
                     mail.execute(bpm_package.children[0]);
                    for (var i = 0; i &lt; bpm_package.children.length; i++)
                    {
                       if (!bpm_package.children[i].hasAspect("atnis:status"))
                       {
                          bpm_package.children[i].addAspect("atnis:status");
                          bpm_package.children[i].save();
                       }
                    }
                </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>
          logger.log("ENTER IN REVIEW");
                    for (var i = 0; i &lt; bpm_package.children.length; i++)
                    {
                       bpm_package.children[i].properties["atnis:status"] = "Redatto";
                       bpm_package.children[i].save();
                    }
                </script>
            </action>
        </event>

        <task name="atnis: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>

    <task-node name="rejected">
   
        <event type="node-enter">
            <!– Update the status to Draft when we enter this task –>
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <script>
          logger.log("REJECTED");
          logger.log("REJECTED NUM CHILD: " + bpm_package.children.length);
                    for (var i = 0; i &lt; bpm_package.children.length; i++)
                    {
                       bpm_package.children[i].properties["atnis:status"] = "Bozza";
                       bpm_package.children[i].save();
                    }
                </script>
            </action>
        </event>

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

    <task-node name="approved">
        <event type="node-enter">
            <!– Update the status to Approved when we enter this task –>
            <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
                <script>
          logger.log("APPROVED");
          logger.log("APPROVED NUM CHILD: " + bpm_package.children.length);
                    for (var i = 0; i &lt; bpm_package.children.length; i++)
                    {
                       bpm_package.children[i].properties["atnis:status"] = "Approvato";
                       bpm_package.children[i].save();
                    }
                </script>
            </action>
        </event>

        <task name="atnis:approvedTask" swimlane="initiator" />
        <transition name="" to="end" />
    </task-node>

    <end-state name="end" />

    <event type="process-end">
        <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
                if (cancelled)
                {
                    for (var i = 0; i &lt; bpm_package.children.length; i++)
                    {
                       if (bpm_package.children[0].hasAspect("atnis:status"))
                       {
                          bpm_package.children[i].properties["atnis:status"] = "Bozza";
                          bpm_package.children[i].save();
                       }
                    }
                    if (logger.isLoggingEnabled()) logger.log("Workflow cancelled, status reset to Draft");
                }
                else               
                {
                    if (logger.isLoggingEnabled()) logger.log("Workflow completed");
                }
            </script>
        </action>
    </event>

</process-definition>
and the following model in which I defined the aspect named status:

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

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

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

    <!– Imports are required to allow references to definitions in other models –>
    <imports>
        <!– 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" />
   
   <import uri="http://www.alfresco.org/model/workflow/1.0" prefix="wf"/>
    </imports>

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

    <constraints>
        <constraint name="atnis:status" type="LIST">
            <parameter name="allowedValues">
                <list>
          <value>Bozza</value> <!– <value>Draft</value> –>
                    <value>Redatto</value> <!–<value>In Review</value> –>
                    <value>Approvato</value> <!–<value>Approved</value>–>
                    <value>Verificato</value>
                    <value>Superato</value>
                </list>
            </parameter>
        </constraint>
    </constraints>

   <types>
     <type name="atnis:reviewTask">
      <title>atnis-reviewTask</title>
        <parent>wf:reviewTask</parent>
      <mandatory-aspects>
              <aspect>atnis:status</aspect>
           </mandatory-aspects>
     </type>

     <type name="atnis:rejectedTask">
      <title>atnis-rejectedTask</title>
        <parent>wf:rejectedTask</parent>
      <mandatory-aspects>
              <aspect>atnis:status</aspect>
           </mandatory-aspects>
     </type>

     <type name="atnis:approvedTask">
      <title>atnis-approvedTask</title>
        <parent>wf:approvedTask</parent>
      <mandatory-aspects>
              <aspect>atnis:status</aspect>
           </mandatory-aspects>
     </type>

   </types>

    <aspects>
        <!– Status property is used to manage workflow approval –>
        <aspect name="atnis:status">
            <title>Status</title>
       <properties>
                <property name="atnis:status">
                    <title>Status</title>
                    <type>d:text</type>
                    <default>Redatto</default>
                    <constraints>
                        <constraint ref="atnis:status" />
                    </constraints>
                </property>
           </properties>      
        </aspect>
    </aspects>

</model>
Moreover I configured the web client GUI using the following:


<alfresco-config>

   <config evaluator="node-type" condition="atnis:reviewTask" replace="true">
      <property-sheet>
         <separator name="sep1" display-label-id="general" component-generator="HeaderSeparatorGenerator" />
         <show-property name="bpm:taskId" />
         <show-property name="bpm:description" component-generator="TextAreaGenerator" read-only="true"/>
         <show-property name="bpm:dueDate" read-only="true" />
         <show-property name="bpm:priority" read-only="true" />
         <show-property name="bpm:comment" component-generator="TextAreaGenerator" />
      </property-sheet>
   </config>

   <config evaluator="node-type" condition="atnis:rejectedTask" replace="true">
   <property-sheet>
         <separator name="sep1" display-label-id="general" component-generator="HeaderSeparatorGenerator" />
         <show-property name="bpm:taskId" />
         <show-property name="bpm:description" component-generator="TextAreaGenerator" read-only="true"/>
         <show-property name="bpm:dueDate" read-only="true" />
         <show-property name="bpm:priority" read-only="true" />
         <show-property name="bpm:comment" component-generator="TextAreaGenerator" />
         <separator name="sep2" display-label-id="users_and_roles" component-generator="HeaderSeparatorGenerator" />
         <show-association name="bpm:assignee" display-label-id="wf_reviewer" read-only="true" />
      </property-sheet>
   </config>

   <config evaluator="node-type" condition="atnis:approvedTask" replace="true">
      <property-sheet>
         <separator name="sep1" display-label-id="general" component-generator="HeaderSeparatorGenerator" />
         <show-property name="bpm:taskId" />
         <show-property name="bpm:description" component-generator="TextAreaGenerator" read-only="true"/>
         <show-property name="bpm:dueDate" read-only="true" />
         <show-property name="bpm:priority" read-only="true" />
         <show-property name="bpm:comment" component-generator="TextAreaGenerator" />
         <separator name="sep2" display-label-id="users_and_roles" component-generator="HeaderSeparatorGenerator" />
         <show-association name="bpm:assignee" display-label-id="wf_reviewer" read-only="true" />
      </property-sheet>
   </config>

   <config evaluator="aspect-name" condition="atnis:status">
     <property-sheet>
        <separator name="sep3" display-label="Document state" component-generator="HeaderSeparatorGenerator" />
   <!–  <separator name="sep3" display-label-id="document_status" component-generator="HeaderSeparatorGenerator" /> –>
        <show-property name="atnis:status" read-only="true"/>
     </property-sheet>
   </config>

</alfresco-config>
.
When I execute the defined tasks, the "View Content properties" dialog shows the value of the status aspect correctly changed whereas the "Task Properties" always shows the default value of the status aspect.
Someone has any idea?
Thanks in advance,
Samuel

PS: Sorry for my poor english  Smiley Surprisedops:
2 REPLIES 2

hsohaib
Champ on-the-rise
Champ on-the-rise
you only change the property on the documents, not the task, so naturaly it will keep its default value.
To modify the task properties you might wanna add this controller to each one of them :


<task name=….>
….
  <controller>
    <variable name="bpm_package.children[i].properties["atnis:status"]" access="read,write,required" mapped-name="atnis_status" />
  </controller>
….
</task>

if for some reason it doesn't work, create a variable with value "bpm_package.children.properties["atnis:status"]" , and replace "bpm_package.children.properties["atnis:status"]" by your variable nae ine the task controller.

samuele_atnis
Champ in-the-making
Champ in-the-making
Hi,
I added the following code to each task:


       <controller>
          <variable name="document-status" access="read,write,required" mapped-name="atnis_status" />
       </controller>

but with any result.
Have I also to define the variable document-status? In this case in which part of my process I have to define such variable?
Thanks in advance for your help.

Regards,
Samuel