Mar 8, 2018 12:24:23 PM seb leridon avatar   1255

Integrate workflow - business resources

Prerequisite

To use the plugin-workflow with business resources, you must first:

  • ensure that the plugin-workflow is installed and activated (for example on jsp / admin / system / ManagePlugins.jsp). For example, the dependency in pom.xml
    <dependency>
            <groupId>fr.paris.lutece.plugins</groupId>
            <artifactId>plugin-workflow</artifactId>
            <version>[3.0.0,)</version>
            <type>lutece-plugin</type>
    </dependency>
  • create a workflow, states and actions (jsp / admin / plugins / workflow / ManageWorkflow.jsp? plugin_name = workflow)
  • have a unique unique identifier for each resource.

Resource types are identified by a string of characters. For example, for the standard resources of a directory lutece, the string is

public static final String WORKFLOW_RESOURCE_TYPE = "DIRECTORY_RECORD";
The unique identifier of a resource is the couple (identifier_metier, resource_type)

Description of the API

The API is lutece-core class en.paris.lutece.portal.service.workflow.WorkflowService

Initialize / get the status of a resource

import en.paris.lutece.portal.service.workflow.WorkflowService;
// Initialize the workflow, this creates the state for our resource
WorkflowService.getInstance () .getState (idResource, WORKFLOW_RESOURCE_TYPE, idWorkflow, -1);
  • We get the id of the workflow for example by looking in the database. We can simplify define a property that can be changed if the plugin has to coexist with other plugins using different workflow in a file <plugin-trade> .properties:
    pluginmetier.idWorkflow = 1
  • If the state of the resource does not exist, it is created and takes the initial value.

Get actions available for a resource

import en.paris.lutece.portal.service.workflow.WorkflowService;
WorkflowService.getInstance () .getActions (idResource, RESOURCE_TYPE, idWorkflow, getUser ());
  • Useful for displaying available actions for a list of resources.

Execute an action on a resource

import en.paris.lutece.portal.service.workflow.WorkflowService;
WorkflowService.getInstance () .doProcessAction (idResource, WORKFLOW_RESOURCE_TYPE, idAction, -1, request, locale, isAutomatic);
  • To obtain the id of the action, we can simplify to use the same mechanism as for the id of the workflow in a file properties if the workflow does not change.
  • If isAutomatic is true, the user ID of the backoffice user is not verified.

Force the execution of automatic actions

import en.paris.lutece.portal.service.workflow.WorkflowService;
WorkflowService.getInstance () .executeActionAutomatic (idResource, WORKFLOW_RESOURCE_TYPE, idWorkflow, -1);
  • If not forced, a daemon looks for eligible resources and performs actions regularly.

View the history of a resource (HTML)

import en.paris.lutece.portal.service.workflow.WorkflowService;
WorkflowService.getInstance () .getDisplayDocumentHistory (idResource, WORKFLOW_RESOURCE_TYPE, idWorkflow, request, getLocale ());

Get the list of all resources with a given state

import en.paris.lutece.portal.service.workflow.WorkflowService;
WorkflowService.getInstance () .getResourceIdListByIdState (idState, WORKFLOW_RESOURCE_TYPE);
  • To get the id of the state, we can simplify to use the same mechanism as for the id of the workflow in a file properties if the workflow does not change.

Use in an HTML list with freemarker

To display the name of the status and the icons corresponding to the actions in html with freemarker, one can take inspiration from the following example:

<td><#if workflow_state??>${workflow_state.name}<#else>workflow desactive</#if></td>
<td>
<#if workflow_state??><#list workflow_action_list as action >
    <a href="METIER_JSP_URL?id_action=${action.id}&id_resource=${id}">
        <img src="image?resource_type=workflow_icon_img&id=${action.icon.id}"
                <#if action.icon.width!=-1> width="${action.icon.width}"</#if>
                <#if action.icon.height!=-1> height="${action.icon.height}"</#if>
                title="${action.name}"
                alt="${action.name}"/>
     </a>
</#list></#if>
</td>
  • for each element of the list, the java code generating the list adds the result of:
    import en.paris.lutece.portal.service.workflow.WorkflowService;
    // Put these in the freemarker model with model.put (..)
    WorkflowService.getInstance () .getActions (idResource, WORKFLOW_RESOURCE_TYPE, idWorkflow, getUser ());
    WorkflowService.getInstance () .getState (idResource, WORKFLOW_RESOURCE_TYPE, idWorkflow, -1);
  • METIER_JSP_URL must parse the arguments and call doProcessAction

Advanced use

  • Look at the other methods of the class fr.paris.lutece.portal.service.workflow.WorkflowService defined in Lutece-core / src / java / en / paris / lutece / portal / services / workflow / WorkflowService.java
  • Create workflow tasks Create a workflow module