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

Integrate workflow - business resources


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
  • 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

The unique identifier of a resource is the couple (identifier_metier, resource_type)

Description of the API

The API is lutece-core class

Initialize / get the status of a resource

// 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

WorkflowService.getInstance () .getActions (idResource, RESOURCE_TYPE, idWorkflow, getUser ());
  • Useful for displaying available actions for a list of resources.

Execute an action on a resource

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

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)

WorkflowService.getInstance () .getDisplayDocumentHistory (idResource, WORKFLOW_RESOURCE_TYPE, idWorkflow, request, getLocale ());

Get the list of all resources with a given state

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??>${}<#else>workflow desactive</#if></td>
<#if workflow_state??><#list workflow_action_list as action >
    <a href="METIER_JSP_URL?id_action=${}&id_resource=${id}">
        <img src="image?resource_type=workflow_icon_img&id=${}"
                <#if action.icon.width!=-1> width="${action.icon.width}"</#if>
                <#if action.icon.height!=-1> height="${action.icon.height}"</#if>
  • for each element of the list, the java code generating the list adds the result of:
    // 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 defined in Lutece-core / src / java / en / paris / lutece / portal / services / workflow /
  • Create workflow tasks Create a workflow module