Posted by Giampiero Granatella
on June 30, 2009
In this tutorial we'll learn how to use workflows in Portofino with a simplified version of the ticket tracker example.
You can find the full data model for a ticket tracker in the article& Ticket Tracker - The data model. In this example we are going to focus on one class: the "Ticket" with the following attributes:
- code, the ticket's code;
- description, a full description of the issue;
- creation date, the creation date;
- solution, a full description of the solution.
As a first step of workflow modeling, let's identify the states and transitions. There are only three states: "open", "work in progress", "closed" and three transitions: "start work", "resolve", "reopen". The following diagram shows the situation. Again, this is a simplified version of the workflow discussed in Ticket Tracker - The data model.
As usual, we implement our model in Portofino by going "upstairs"...
We create the class "Ticket" with its attributes (if you don't know how, you can read Portofino tutorial part 2: The first application). You will have a class like the one in the following picture.
Then, we must define a workflow attribute in the "Ticket" class. Its purpose is to provide the storage for the ticket's current state and is a prerequisite to define states and transitions.
Click on the "Add attribute" link and select "Workflow attribute". Enter "state" both for the attribute and the pretty name and check the flags "required", "in summary" and "in details". All of these features are well known and common to all types of attribute.
In "workflow-specific information", the "initial state" attribute is used to specify the first state of the workflow. We'll return to this later because we haven't defined any states yet. Click on "Create" tocomplete the creation.
After you return to the Ticket class page, click on the newly created attribute "state". You can see that it has a "states" tab with still no elements. We can add a new state clicking on "add workflow state" link and inserting the name. Enter "open" for the first state, then repeat the procedure for "work in progress" and "closed".
Now we can update the workflow attribute (click on "Update" button) and set the "initial state" to "open".
Click on the "open" state. In the lower part of the page are the two types of transition:
- 'This state -> transition -> other state': outbound transitions from this state to other states;
- 'Other state -> transition -> this state': inbound transitions from other states to this state.
Let's create the "start work" transition.
- click on Add workflow transition
- From state: the state this transitions originates from. It should be pre-set to "open".
- To state: the state this transition ends in. Enter "work in progress".
- Name: calculated automatically. Do no enter a value.
- Action: the name of the action. Enter "start work".
Repeat the previous steps for all the transitions with the data in the following table.
|From state||To state||Action|
|open||work in progress||start work|
|work in progress||closed||resolve|
We can test our model downstairs and we can see how to use a workflow. First of all we create a ticket and we can see that the state is set to "open" (the initial value).
In the details of the new ticket, you can see all the data of the new ticket and a new button with the name of the worflow action: "Start Work".
Click on "Start work" and you'll the state changed to "work in progress".
For a given state, each of its outbound transitions gives you a button: in the "open" state you get the "start work" button, in the "work in progress" state the "resolve" button, and in the "closed" state the "reopen" button. Clicking on a button you change the state according to the associated transition.
In one of the upcoming tutorials of the ticket tracker series, we will see data and workflow modeling discussed from the perspective of permissions.
Workflows are a broad subject, often related to custom workflow actions and integration. For a practical example, see the tutorial Integrating Portofino with Alfresco. For the theory, see the section Advanced workflows in the reference manual.