Workflow

Implementing Workflow in Resources

Workflows can be implemented for all resources that implement the WorkflowableV1 interface, although in practice it is more common to have the implementation delegate to WorkflowHelper (see org.wyona.yanel.impl.resources.XMLResource for example).

WorkflowableV1 interfaces require that a resource has also the VersionableV2 interface implemented. (NOTE re Yarep: In order to
create revisions one must implement Node.checkout() and Node.checkin() when modifying the content of nodes!)

Workflow Schemas

Worflow schemas define what actions, or transitions, may be made from instances of a resource in a given state, and to what state those transitions move. For example, one can define that a resource in state "draft" can be changed to state "review", and that from "review" it can either enter state "draft" (i.e. it is rejected by the reviewer) or "approved" (i.e. it is accepted by the reviewer).

There are, essentially, two steps involved in this. First, a schema may be created, and secondly a resource may be associated with that schema. Neither step is compulsory, because if no specific schema is associated with a resource then the schema located within the default data repository of the corresponding realm will be used. That is, if a resource is workflowable by virtue of it implementing a Workflowable interface then there will always be a workflow associated with resources of that type.

 

Creating a Workflow Schema

As already mentioned, a workflow consists of a set of known states, and a set of transitions between those states.

A typical schema file looks something like this:

<?xml version="1.0" encoding="UTF-8"?>
<workflow xmlns="http://www.wyona.org/yanel/workflow/1.0">
<states>
<!-- some known set of states -->
</states>

<transitions>
<!-- some known set of transitions -->
</transitions>
</workflow>


and is placed in some directory below the realm's data-repo/data directory.

States

Let us assume that we wish to set up a schema like that describe in the first paragraph of this section, with "draft", "review", and "approved" states, and some transitions between some of these states. We would declare our states like this:

<states>
<state id="draft" initial="true"/>
<state id="review"/>
<state id="approved"/>
</states>

Note the 'initial="true"' next to the "draft" state. This indicates that new instances of the resources that are associated with this schema will initially be in the "draft" state.

Transitions

A transition entry is required for each transition that should be possible from one state to another. A transition consists of an id, for example "submit", a specification of the "from" and "to" states, possibly one or more extra conditions which must be satisfied in order for the transition to be succesful, one or more textual descriptions of the transition, and one or more actions which are executed during the transition. For example:

<transition id="submit" from="draft" to="review">
<condition class="org.wyona.yanel.impl.workflow.RoleCondition">write</condition>
<description xml:lang="en">Submit for Review</description>
<action class="org.wyona.yanel.impl.workflow.EmailAction">yanel-development@wyona.com</action>
</transition>

Complete example

The following specifies the states and transitions described in the first paragraph of this section:

<?xml version="1.0" encoding="UTF-8"?>
<workflow xmlns="http://www.wyona.org/yanel/workflow/1.0">

<states>
<state id="draft" initial="true"/>
<state id="review"/>
<state id="approved"/>
</states>

<transitions>
<transition id="submit" from="draft" to="review">
<condition class="org.wyona.yanel.impl.workflow.RoleCondition">write</condition>
<description xml:lang="en">Submit for Review</description>
</transition>

<transition id="reject" from="review" to="draft">
<condition class="org.wyona.yanel.impl.workflow.RoleCondition">workflow.approve</condition>
<description xml:lang="en">Reject</description>
</transition>

<transition id="approve-only" from="review" to="approved">
<condition class="org.wyona.yanel.impl.workflow.RoleCondition">workflow.approve</condition>
<description xml:lang="en">Approve</description>
</transition>
</transitions>

</workflow>

Note on conditions:

Conditions are references to Java classes which implement the org.wyona.yanel.core.workflow.Condition.interface.

RoleConditions mean that for the user to perform the transition, he or she must be allowed by access policies to perform that operation.

 

Associate the Resource with the Schema

A workflow schema is associated with a resource by adding such a reference to the resource configuration file.

For example, adding

<yanel:property name="workflow-schema" value="/app/workflow/workflow-with-review.xml"/>

to the file RES-CONFIGS_REPO:/some-page.html.yanel-rc so that it looks something like this:

<?xml version="1.0"?>
<yanel:resource-config xmlns:yanel="http://www.wyona.org/yanel/rti/1.0">
<yanel:rti name="some-page" namespace="http://www.example.com/yanel/resource/1.0"/>
<yanel:property name="workflow-schema" value="/app/workflow/workflow-with-review.xml"/>
<yanel:custom-config>
...
</yanel:custom-config>
</yanel:resource-config>


would mean that the system will lookup the schema in DATA_REPO:/app/workflow/workflow-with-review.xml when it is needed.



Your comments are much appreciated

Is the content of this page unclear or you think it could be improved? Please add a comment and we will try to improve it accordingly.