Monday, February 8, 2010

Advanced Workflow in Alfresco Share

Alfresco Share 3.2 is shaping up to be a great development platform.  Prior to 3.1, Share's access to standard Alfresco repository capabilities were disappointingly weak.  But with the 3.2 release, many repository features have been migrated from the older Alfresco JSF client (aka the 'explorer' client) to the Share Document Library.

Unfortunately, Alfresco's Advanced Workflow, the ability to create complex workflows using jBPM and to use them within Alfresco, is still not quite prime time.  There's talk that Advanced Workflow will be ready to ship as part of the 3.3 release of Share.  On the Alfresco wiki, a series of goals for implementing Advanced Workflow in Share are listed.

But...  the current state of Alfresco 3.2 Share makes it look like a full integration of Advanced Workflow with Share may not be that far off.  One promising sign is that two built-in Advanced Workflows already ship with Share 3.2: "Adhoc Tasks" and "Review and Approve".  The negative is that only these two workflows are available -- and they are hardcoded. Also assigning a document to one of those workflows throws some errors at the server.

We're anxious to see general Advanced Workflow working in Share, so I decided to investigate a bit to see what could be done to make a general workflow work in Share 3.2.

As a starting point, I adopted the workflow example code from the Alfresco wiki that describes an Approve/Reject Lifecycle workflow.  The flow for the workflow looks as follows:

To install the new workflow for use within Share, copy the following files with contents as defined on the wiki into the exploded alfresco repository file area:
alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\extension\lifecycle-workflow-context.xml
alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\extension\workflows\lifecycle
      lifecycle_processdefinition.xml
      lifecycle-messages.properties
      lifecycleModel.xml

In the lifecycle_processdefinition.xml file, you need to make sure that the use of the < ("less than") operator in the embedded Javascript is replaced with <.  For example, on the line:
    for (var i = 0; i < bpm_package.children.length; i++)
To make the workflow available within Share, add a line to define the lifecycleapproval workflow to the file
alfresco\tomcat\webaps\share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\modules\documentlibrary\workflow.get.html.ftl:

The name of the workflow "wfl:lifecycleapproval" corresponds to the name of the process definition defined in the file  lifecycle_processdefinition.xml:


With these files in place, the web application server can be restarted.
Then by going to the workflow console in the Alfresco repository application, you can see that the workflow has been defined.

The workflow console is located at this URL: http://localhost:8080/alfresco/faces/jsp/admin/workflow-console.jsp.  And the defined workflow definitions can be queried.  In this example, the new workflowid is jbpm$8:

The new workflow is also now visible from the Share Document Library.  When a workflow is selected to be assigned to a document from within Share, the following dialog can now be seen with a "Lifecyle Approval" option now available (with spelling typo):



That's all good.  Now, by clicking on "Assign Workflow", the workflow will be assigned to the document.  Now, after logging into Share as the workflow assignee, the following can be seen in the Task List:



From the workflow console screen, you can check the status of the newly created instance of the workflow.  First, specify which workflow definition id you will be querying.



And then query the workflow id of the current instance of the workflow.



The workflow id of the workflow instance is jbpm$11.


And the path id for this workflow instance is jbpm$11-@.
The current task for the path is as follows:





Going back into the Share task window, after approving the review/lifecycle item and then again checking the properties for the task in the workflow console, the following can be seen:



So it looks like the workflow is working.  But a glance at the tomcat console shows that there are errors being reported each time a workflow is assigned to a document.  With a little bit of investigation, the problem can be traced to the file alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\org\alfresco\slingshot\documentlibrary\action\assign-workflow.post.json.ftl.
The variable 'results' is entering the Freemarker macro as undefined.  I'm not sure how serious a problem this is, but making the following change to this file avoids the error.



This test seems to indicate that while Workflow within Alfresco Share in the 3.2 release is not officially ready, it may be close enough for at least creating simple workflows like the one described here.

7 comments:

  1. >In the lifecycle_processdefinition.xml file, you >need to make sure that the use of the < ("less >than") operator in the embedded Javascript is >replaced with <. For example, on the line:

    > for (var i = 0; i < >bpm_package.children.length; i++)


    what should we replace < with? < ? &lt?

    ReplyDelete
  2. Is there a limit to the number of custom workflows that can be deployed? Alfresco recognized my first custom workflow, but not subsequent new workflows that were added in the same way.

    ReplyDelete
  3. It should work with any number of workflows.
    I've tried with two and had no problem.
    Check in the WF console to see that your workflows are deployed and make sure you edit the Share workflow.get.html.ftl file to expose the workflows in Share.
    Better Share WF capabilities are planned for Alfresco 3.3.

    ReplyDelete
  4. Hi Dick,
    Thanks for this walk through. The bit I still find confusing is the replace '<' bit in lifecycle_processdefinition.xml.

    Should the code use "<" or "& l t ;" (sorry the html entity isn't allowed in comments).

    Alternatively could you not wrap the javascript in "<![CDATA[" tags & still use '<'?

    Thanks for your contributions,
    Eddie

    ReplyDelete
  5. It should be & lt;
    (with no space after the ampersand)

    ReplyDelete
  6. Hi Dick

    Advanced Workflow support isn't in v3.3 - sorry. I have moved the two workflow definitions out into share-config.xml though, so it should be easier to add your own. We've also fixed the "double submission" bug that caused the benign exception on the server (benign because it's the 2nd submission which causes the issue).

    The good news is that full Task and Workflow support for Share is in the process of being designed for "Project Swift" - the end-of-year release.

    Thanks,
    Mike

    ReplyDelete