Dec 8, 2019 10:23:43 PM Thomas Dumont avatar   2813

Code with workflows > Create a workflow module

Create a workflow module


Introduction

The Lut├Ęce plugin-workflow allows to carry out a series of tasks. Each workflow module implements a particular workflow task.

Info This tutorial only applies to modules of plugin workflow from version 3.0.0.

Development of the workflow module

Dependency in POM

The workflow module must depend on the plugin-workflow. Add the dependency in the pom.xml file of the workflow module :

<dependency>
    <groupId>fr.paris.lutece.plugins</groupId>
    <artifactId>plugin-workflow</artifactId>
    <version>[3.0.0,)</version>
    <type>lutece-plugin</type>
</dependency>

Creating Java classes

Creating a workflow task

  • Create a class at the service layer (fr.paris.lutece.plugins.workflow.modules.mymodule.service.MyTask).
  • The new class must extend the Task abstract class defined in the library-workflow-core :
public class MyTask extends Task
{
    ...
}

The library-workflow-core offers another abstract class SimpleTask implementing the various methods. This class allows the implementations in the modules to do without the implementation of certain useless methods in their case.

Creating a configuration for the workflow task

It is sometimes necessary for a workflow task to require a particular configuration, such as the recipient name for a notification task. To do this, follow the following steps :

  • Create a class at the business layer (fr.paris.lutece.plugins.workflow.modules.mymodule.business.MyTaskConfig).
  • The new class must extend the abstract class TaskConfig defined in the library-workflow-core :
public class MyTaskConfig extends TaskConfig
{
    ...
}

The abstract class has the ID task attribute that corresponds to the task ID.

  • Create the CAD for database access of the business layer configuration (fr.paris.lutece.plugins.workflow.modules.mymodule.business.MyTaskConfigDAO).
  • The new class must implement the ITaskConfigDAO interface :
public class MyTaskConfigDAO implements ITaskConfigDAO<MyTaskConfig>
{
  ...
}

Creating the view of the task

  • Create a class at the web layer (fr.paris.lutece.plugins.workflow.modules.mymodule.web.MyTaskTaskComponent).
  • The new class must extend the abstract class TaskComponent defined in the plugin-workflow:
public class MyTaskTaskComponent extends TaskComponent
{
    ...
}
  • The library-workflow-core offers two abstract classes:
    • TaskComponent uses BeanUtils to populate configurations automatically.
    • SimpleTaskComponent to avoid implementing the intermediate form and configuration.
  • The plugin-workflow offers three other abstract classes:
    • AbstractTaskComponent implements a method to validate beans using JSR303 annotations.
    • NoFormTaskComponent allowing your implementation to avoid implementing methods for the intermediate form.
    • NoConfigTaskComponent allowing your implementation to avoid implementing the methods for configuring the task.

Configuring of the context file of the module

Several beans must be added in the context file of the module (file /WEB-INF/conf/plugins/workflow-mytask_context.xml) :

  • define the task and its type :
<bean id="workflow-mytask.taskTypeMyTask" class="fr.paris.lutece.plugins.workflowcore.business.task.TaskType"
		p:key="taskMyTask" 
		p:titleI18nKey="module.workflow.mytask.task_title" 
		p:beanName="workflow-mytask.taskMyTask"
		p:configBeanName="workflow-mytask.taskMyTaskConfig"
		p:configRequired="true"
		p:formTaskRequired="true"
		p:taskForAutomaticAction="true" />
<bean id="workflow-mytask.taskMyTask" class="fr.paris.lutece.plugins.workflow.modules.mytask.service.MyTask" scope="prototype" />

The type of the task must have the following attributes :

Description of the attributes of the task

Name Description Example
key The technical key of the task (must be unique) taskMyTask
titleI18nKey The i18n key of the task module.workflow.mytask.task_title
beanName The name of the task's bean (must be identical to the ID of the bean defining the task) workflow-mytask.taskMyTask
configBeanName The name of the task configuration bean (must be the same as the Bean ID defining the task configuration). Only define it if the workflow task needs a configuration workflow-mytask.taskMyTaskConfig
configRequired Attribute to know if the task needs a configuration of the technical administrator or not. Optional attribute if the task does not need configuration. true
formTaskRequired Attribute to know if the task needs an intermediate form when performing the action. Optional attribute if the task does not need an intermediate form. true
taskForAutomaticAction Attribute to know if the task can be assigned to an automatic action. Optional attribute if the task can not be assigned to an automatic action. true

Warning ! Do not forget the scope prototype in the definition of the task bean.

  • define the configuration if the task requires one :
<bean id="workflow-mytask.taskMyTaskConfig" class="fr.paris.lutece.plugins.workflow.modules.mytask.business.MyTaskConfig" 
scope="prototype" />

<bean id="workflow-mytask.taskMyTaskConfigService" class="fr.paris.lutece.plugins.workflow.modules.mytask.service.TaskMyTaskConfigService"
		p:taskConfigDAO-ref="workflow-mytask.taskMyTaskConfigDAO" />

Warning ! Do not forget the scope prototype in the bean definition of the task configuration.

  • define the view :
<bean id="workflow-mytask.myTaskTaskComponent" class="fr.paris.lutece.plugins.workflow.modules.mytask.web.MyTaskTaskComponent"
		p:taskType-ref="workflow-mytask.taskTypeMyTask"
		p:taskConfigService-ref="workflow-mytask.taskMyTaskConfigService" />

Info If the workflow task does not require a dynamic configuration, it is not necessary to set the taskConfigService attribute.

Warning ! Define the name of the task type bean in the taskType attribute

Development of a notification task

The tools presented below are tools for performing a notification task in a simple way. The developer is free to use or not these tools. The tool in question is the library-workflow-notify. To use this tool, you must :

  • Add the implementation of the workflow task (TaskNotify) in the context file of the module.
  • Create a converter that converts data into a Map <String, Object> that is passed as a model in the notification message.
  • Create a notification service for sending messages.

Info Using this tool, it is not necessary to implement a task that implements ITask nor the service that retrieves information about the notification task's configurations. The library-workflow-notify and the library-workflow-core take care of these implementations.

Dependencies in POM

The workflow module must depend on the plugin-workflow and the library-workflow-notify. Add the dependencies in the pom.xml file of the workflow module :

<dependency>
    <groupId>fr.paris.lutece.plugins</groupId>
    <artifactId>plugin-workflow</artifactId>
    <version>[3.0.0,)</version>
    <type>lutece-plugin</type>
</dependency>
<dependency>
    <groupId>fr.paris.lutece.plugins</groupId>
    <artifactId>library-workflow-notify</artifactId>
    <version>[0.0.1,)</version>
    <type>jar</type>
</dependency>

Creating Java classes

Creating the MessageConverter class

Create a class that implements the IMessageConverter interface of the library-workflow-notify :

public class MessageConverter implements IMessageConverter
{
    ...
}

This class converts an instance of MessageData into a Map<String, Object>

Creating the notification class

Create a class that implements the INotifyService interface of the library-workflow-notify :

public class NotifyService implements INotifyService
{
    ...
}

Configuration of the context file of the notification module

Several beans must be added in the context file of the module (file /WEB-INF/conf/plugins/workflow-mytask_context.xml) :

  • Create the bean corresponding to the converter created previously :
<bean id = "workflow-mytask.messageConverter" class = "en.paris.lutece.plugins.workflow.modules.mytask.service.convert.MessageConverter" />
  • Create the bean corresponding to the notification service :
<bean id = "workflow-mytask.notifyService" class = "en.paris.lutece.plugins.workflow.modules.mytask.service.notification.NotifyService" />
  • Create a bean having the TaskNotify class by specifying the converter and notification service used :
<bean id="workflow-notifycrm.taskNotifyCRM" class="fr.paris.lutece.plugins.workflownotify.service.TaskNotify" scope="prototype"
		p:converter-ref="workflow-notifycrm.messageConverter"
		p:taskConfigService-ref="workflow-notifycrm.taskNotifyCRMConfigService"
		p:notifyService-ref="workflow-notifycrm.notifyService" />