Reader small image

You're reading from  Alfresco One 5.x Developer???s Guide - Second Edition

Product typeBook
Published inFeb 2017
Reading LevelBeginner
PublisherPackt
ISBN-139781787128163
Edition2nd Edition
Languages
Concepts
Right arrow
Authors (2):
Benjamin Chevallereau
Benjamin Chevallereau
author image
Benjamin Chevallereau

Benjamin Chevallereau is a French software architect, based in London, who has been working on Alfresco projects for the last 8 years and Ephesoft projects for the last 3 years. He implemented solutions for small companies and global organizations in different domains such as transport, finance, and government. He has worked for different Alfresco-recognized partners in France, the UK, and USA, including Armedia LLC, Zaizi, Michelin / Wipro, and BlueXML. He is also one of the committers and PMC members of the Apache CMIS Chemistry project.
Read more about Benjamin Chevallereau

Jeff Potts
Jeff Potts
author image
Jeff Potts

Jeff Potts is the founder of Metaversant Group, Inc., a consulting firm focused on content management, search, and workflow. Jeff brings over 20 years of Enterprise Content Management implementation experience to organizations of all sizes including the Fortune 500. Throughout his consulting career he has worked on a number of projects for clients across the media and entertainment, airline, consumer packaged goods, and retail sectors. Jeff began working with and blogging about Alfresco in November of 2005. In 2006 and 2007, he published a series of Alfresco tutorials and published them on his blog, ecmarchitect.com. That work, together with other Community activity in Alfresco's forum, Wiki site, and JIRA earned him Alfresco's 2007 Community Contributor of the Year Award. In the past, Mr. Potts has worked for Alfresco Software, Inc. as Chief Community Officer, Optaros as Senior Practice Director, and Hitachi Consulting as Vice President where he ran the ECM practice.
Read more about Jeff Potts

View More author details
Right arrow

Chapter 8. Advanced Workflow

Every organization has business processes that lend themselves to automation. Often, these business processes are content-centric. In Chapter 1, The Alfresco Platform you learned that Alfresco provides an embedded workflow engine called Activiti. In this chapter, you'll explore Alfresco's advanced workflow capability provided by this embedded workflow engine. Alfresco provides as well a product called Alfresco Activiti Suite, but this product is out of the scope of this book.

Specifically, in this chapter you will learn:

  • What workflow is and why you need a workflow engine

  • How to create business process definitions using both a text editor and the Activti Graphical Process Designer

  • The steps required to expose a custom business process to Alfresco Share

  • How to add logic to workflows using expressions, JavaScript, and Java

  • How to create an asynchronous process involving the Activiti Runtime Service, Alfresco Web Scripts, and actions

  • How to debug workflows using Alfresco...

What is a workflow?


When Alfresco released version 1.4, it made a huge leap forward in enterprise readiness. That was the release when Alfresco embedded the JBoss jBPM engine into the product, which meant that enterprises could route Alfresco repository content through complex business processes. In 2010, Alfresco launched Activiti to replace JBoss JBPM. Activiti can be used embedded in Alfresco, but also as a standalone. For a while, Alfresco supported both jBPM and Activiti as an embedded workflow engine. However, from the latest 5.x version, jBoss is considered as deprecated and shouldn't be used.

Most content has some sort of process around it. That's why content repositories almost always have a mechanism to streamline, facilitate, and report against the business processes that produce, consume, or transform the content within them.

Note

The terms workflow and business process will be used interchangeably throughout this book.

But before geeking out on the wonders of graph-based execution...

Creating process definitions


Activiti is an open source, standalone workflow engine. OK, it is more than just a standalone workflow engine. Activiti calls itself a "a light-weight workflow and Business Process Management (BPM) Platform targeted at business people, developers and system admins". Workflow is one of several different domains that can be addressed with a graph-based execution language, but it is the only one this book concerns itself with.

The Activiti engine is responsible for managing deployed processes, instantiating and executing processes, persisting process state and metadata to a relational database and tracking task assignment and task lists.

Activiti is built on the idea that any process can be described as a graph or a set of connected nodes. Workflows are described with "process definitions" using an XML-based language called Business Process Model and Notation (BPMN). BPMN is a standard for modeling business processes. It's one example of a graph-based execution language...

Using the Activiti graphical process designer


One of the nice things about Activiti is that a graphical tool is available as an Eclipse plugin for creating and deploying process definitions, called the ActivitiDesigner.

There are people in the business of marketing workflow tools who love to say things such as "Using the graphical process designer, business analysts can create advanced workflows without writing any code!" Graphical process designers are definitely useful, but be realistic. Code has to be written.

The designer is most useful for quickly designing the process, setting node properties, and connecting nodes. Once that's done, you may have to switch over to the XML to finish out the definition.

The Activiti Designer is freely available from http://www.activiti.org/userguide/#activitiDesigner. It installs as an Eclipse plugin. To install the plugin, click on Help|Install New Software, then use the update site http://activiti.org/designer/update/ and select the Activiti Eclipse BPMN...

Wiring a process to the Alfresco UI


So far you've learned the definition of workflow, specifics around the Activiti engine, and how to deploy processes. But the discussion up to this point hasn't been specific to Alfresco. In Alfresco, users need to:

  • Start workflows

  • Add one or more pieces of content to a workflow ("Approve an application form", for example)

  • Assign tasks to users and/or groups, and work with the tasks assigned to them

  • Provide process-specific metadata for a specific workflow such as due dates, priority, special processing instructions, or any other custom metadata you can think of

Activiti is just an engine-it is up to the application embedding the engine to expose the capabilities of the engine to the user interface. Alfresco's already done that work for you. Figuring out how to wire your custom workflows into Alfresco Share is just a matter of following Alfresco's framework.

Alfresco uses the same mechanism to model workflow process data and the corresponding Alfresco Share interface...

Assigning tasks to users and groups


A task is a step in a workflow that requires human interaction. Activiti maintains a list of tasks assigned to each participant. How users interact with the task list is up to the application embedding the Activiti engine. In Alfresco Share out-of-the-box, you have two options.

The first one is to use the My Tasks that we used previously. The second one is to use the page using the same name My Tasks. To open it, click on the top banner to Tasks|My Tasks. It will show a to-do list for the currently logged in user. As users complete their tasks, the tasks are removed from the to-do list. An empty to do list is shown here:

If tasks are steps a human performs, how do tasks get associated with the people who need to perform them? When defining a business process, it is important to understand how the participants in the process will do the work. One specific area that needs to be considered is whether to use candidates for a given task, or assign a task directly...

Adding Logic to Workflows with Listeners and Process Variables


So far you've seen that a process can be modeled as a collection of nodes connected via paths or transitions. A common requirement is to be able to execute some code or business logic at certain points within the process. For example, maybe you want to send an e-mail or want to increment a counter that keeps track of how many times a node has been executed. We already used the concept of service tasks to execute some codes, but now we are going to use event listeners.

An event mechanism has been introduced in Activiti to get notified when various events occur within the engine. In our use case, we are going to focus on the Task Listener. A task listener is used to execute custom Java logic or an expression upon the occurrence of a certain task-related event. Using the Activiti Designer, you can create listeners on user tasks where you'll be able to configure:

  • The event nature: create, assignment, complete, or all.

  • The event type...

Using the Activiti API


In the previous example, the logic was easily handled by either expressions or JavaScript within the business process. However, there may be cases when Activiti actions are better implemented in Java. For example, there might be an API readily available in Java that isn't available in JavaScript. Or suppose you want to manipulate workflows from outside a business process. Maybe you want to complete tasks, add items to a workflow, or start a workflow from an action, a web script, or a custom dialog. You can use the Activiti Java services or the Alfresco Workflow Service. In our case, we'll use the first option.

The next example gives you a chance to try out both of these scenarios. In one, you're going to write a custom Activti Task Listener. In the other, you are going to use the ActivitiRuntimeService to signal a process.

SomeCo would like to update the Whitepaper submission workflow to optionally include review by an external third party. The third party might be a...

Using timers


Timers are a common requirement for business processes. The most common functionality is around doing something if someone doesn't respond to a task fast enough. That something might be reassigning the task or sending a nasty e-mail to the assignee's boss. Another use might be to purposefully postpone all or part of a process until a specific day and time occurs.

Timer events are events which are triggered by a defined timer. They can be used as a start event, intermediate event, or boundary event. A timer start event is used to create a process instance at given time. A timer boundary event acts as a stopwatch and alarm clock. A timer intermediate event acts as a stopwatch.

Step-by-step - adding a timer to the third-party review

In the previous example, you added the ability for the website submission workflow to incorporate an external third party in the process. SomeCo is glad that its partners will be involved in the process, but it doesn't want them to become an unnecessary...

Debugging workflows


If something goes wrong or you just want to get up close and personal with the execution of a process, you can use the workflow console. The following table shows some common commands and what they do:

Comparing Alfresco workflow options


You have now seen how Alfresco leverages the embedded Activiti engine to provide advanced workflow capability. Let's take a look at how advanced workflows compare to simple workflows, so you can make good decisions about which one is more appropriate in a given situation.

Simple workflows are nice end-user tools. Simple workflows use folders and a "forward step/backward step" model to implement serial processes. When a piece of content is dropped in a folder, a rule is triggered that associates a forward step and a backward step (one or the other or both) with the content. These steps are tied to Alfresco actions such as Set a property or Move the content to a specified folder. End users can then click on the appropriate step for a given piece of content.

For example, suppose there are requirements for a simple submit-review-approve process in which content is submitted, then reviewed, and then approved or rejected. One way to implement this with simple...

Summary


In this chapter, you learned the following:

  • A workflow is a business process and Alfresco embeds the Activiti workflow engine to execute advanced workflows.

  • Business process definitions can be created using a text editor or the Activiti Designer.

  • Logic can be added to workflows using expressions, JavaScript, and Java.

  • Workflows are well suited to long-running processes and can include asynchronous steps triggered by external programs. In the example, you used the ActivitiRuntimeService, Alfresco web scripts, and actions to implement a process involving non-Alfresco users via e-mail.

  • Timers can be added to a process using relative or absolute dates. Alfresco's workflow console and Activiti Explorer are handy debugging tools.

  • Alfresco's simple workflows are configurable by end users but aren't as powerful or flexible as advanced workflows.

When setting up an advanced workflow for the first time, there are a lot of steps involved because you have to do all the work from mapping the process...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Alfresco One 5.x Developer???s Guide - Second Edition
Published in: Feb 2017Publisher: PacktISBN-13: 9781787128163
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Benjamin Chevallereau

Benjamin Chevallereau is a French software architect, based in London, who has been working on Alfresco projects for the last 8 years and Ephesoft projects for the last 3 years. He implemented solutions for small companies and global organizations in different domains such as transport, finance, and government. He has worked for different Alfresco-recognized partners in France, the UK, and USA, including Armedia LLC, Zaizi, Michelin / Wipro, and BlueXML. He is also one of the committers and PMC members of the Apache CMIS Chemistry project.
Read more about Benjamin Chevallereau

author image
Jeff Potts

Jeff Potts is the founder of Metaversant Group, Inc., a consulting firm focused on content management, search, and workflow. Jeff brings over 20 years of Enterprise Content Management implementation experience to organizations of all sizes including the Fortune 500. Throughout his consulting career he has worked on a number of projects for clients across the media and entertainment, airline, consumer packaged goods, and retail sectors. Jeff began working with and blogging about Alfresco in November of 2005. In 2006 and 2007, he published a series of Alfresco tutorials and published them on his blog, ecmarchitect.com. That work, together with other Community activity in Alfresco's forum, Wiki site, and JIRA earned him Alfresco's 2007 Community Contributor of the Year Award. In the past, Mr. Potts has worked for Alfresco Software, Inc. as Chief Community Officer, Optaros as Senior Practice Director, and Hitachi Consulting as Vice President where he ran the ECM practice.
Read more about Jeff Potts

Command

What it does

showworkflowsall

Shows all running workflows.

use workflow <workflow id>

where <workflow id> is something like activiti$7199

Makes all subsequent commands happen in the context of the specified workflow.

show transitions

Shows all leaving transitions for the current workflow.

signal <path id><transition>

where<path id> is something like activiti$71 and <transition> is the name of the leaving transition you want to take. Leave off the transition to take the default.

Signals the token. Good when your workflow is stuck on a node or when you want to take a transition without going through the task management UI.

desc path <path id>

where <path id> is something like activiti$71

Dumps the...