盘古BPM体验地址    盘古BPM交流群盘古BPM交流群号:963222735

flowable表单上

分享牛 11941℃

摘要:Flowable表单,Flowable form

flowable框架中将表单单独抽取出来作为一个独立的的子模块进行运行。对应Flowable中的模块如下:flowable-form-engine、flowable-form-engine-configurator、org.flowable.form.spring、org.flowable.form.json.converter等。Flowable将表单分为表单的定义以及表单的运行实例两个阶段、这一点类似传统的流程开发流程,第一首先进行流程文档的部署、第二开始流程实例的启动;第三查询个人待办任务;第四完成个人任务;依次循环第三第四步骤进行。

表单的开发流程也是类似传统的流程开发;第一定义流程表单;第二部署流程表单,第三开始表单的运转。

首先我们看一下如何操作表单怎么去部署表单呢?我们来看一下流程的配置如下所示:

1、流程配置信息

<bean id="processEngineConfiguration"

class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration">

<property name="dataSource" ref="dataSource"></property>

<property name="databaseSchemaUpdate" value="true"></property>

<property name="configurators">

<list>

<ref bean="formEngineConfigurator" />

</list>

</property>

</bean>

<bean id="formEngineConfiguration"

class="org.flowable.form.engine.impl.cfg.StandaloneFormEngineConfiguration">

<property name="jdbcUrl"

value="jdbc:mysql://127.0.0.1:3306/shareniu-flowable?useUnicode=true&amp;characterEncoding=UTF-8" />

<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />

<property name="jdbcUsername" value="root" />

<property name="jdbcPassword" value="123" />

</bean>

<bean id="formEngineConfigurator"

class="org.flowable.form.engine.configurator.FormEngineConfigurator">

<property name="formEngineConfiguration" ref="formEngineConfiguration" />

</bean>

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">

<property name="driverClassName">

<value>com.mysql.jdbc.Driver</value>

</property>

<property name="url">

<value>jdbc:mysql://127.0.0.1:3306/shareniu-flowable?useUnicode=true&amp;characterEncoding=UTF-8

</value>

</property>

<property name="username">

<value>root</value>

</property>

<property name="password" value="123" />

</bean>

说明:

1、我们需要配置一个formEngineConfiguration类,具体的类为StandaloneFormEngineConfiguration。我们可以在表单配置类中配置数据源、事务等。需要注意一点流程表单配置类所配置的数据库可以是单独的

2、我们在processEngineConfiguration类中配置了一个配置器formEngineConfigurator,这个配置器位于org-flowable-form-engine-configurator包中。我们使用该类需要引入如下的maven依赖。

<dependency>

<groupId>org.flowable</groupId>

<artifactId>flowable-form-engine-configurator</artifactId>

</dependency>

2、流程引擎以及表单引擎的职责

接下来,我们看一下如何获取FormEngineConfiguration以及通过该实例对象可以获取到什么示例代码如下:

ProcessEngine processEngine;

RuntimeService runtimeService;

RepositoryService repositoryService;

TaskService taskService;

HistoryService historyService;

IdentityService identityService;

FormEngine formEngine;

FormService formService;

FormRepositoryService formRepositoryService;

FormManagementService formManagementService;

@Before

public void init() {

         InputStream inputStream = StartProcessTest.class.getClassLoader()

         .getResourceAsStream("com/shareniu/shareniu_network_flowable/test/flowable.cfg3.xml");

         processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(inputStream)

                                  .buildProcessEngine();

         inputStream = StartProcessTest.class.getClassLoader()

         .getResourceAsStream("com/shareniu/shareniu_network_flowable/test/flowable.cfg3.xml");

         FormEngineConfiguration createFormEngineConfigurationFromInputStream = FormEngineConfiguration

                                     .createFormEngineConfigurationFromInputStream(inputStream);

         formEngine = createFormEngineConfigurationFromInputStream.buildFormEngine();

         runtimeService = processEngine.getRuntimeService();

         repositoryService = processEngine.getRepositoryService();

         taskService = processEngine.getTaskService();

         historyService = processEngine.getHistoryService();

         identityService = processEngine.getIdentityService();

         formService = processEngine.getFormService();

         formRepositoryService = formEngine.getFormRepositoryService();

         formManagementService = formEngine.getFormManagementService();

}

说明:

1、我们直接通过FormEngineConfiguration类中的createFormEngineConfigurationFromInputStream方法来构造一个FormEngineConfiguration类,这个类顾名思义就是表单引擎配置类;那我们就可以通过表单引擎配置类来获取表单引擎类

FormEngine。FormEngine类可以获取一系列的服务类,具体的服务类如下:

FormManagementService :获取表单相关表的元数据信息、查询表元数据信息等。

FormRepositoryService:部署表单、获取表单的定义信息。

FormService :创建表单实例信息、获取表单的模型、查询表单的实例等。

2、formService我们可以通过processEngine获取,也可以通过formEngine获取。

3、表单文件的定义

假如我们现在有一个学生的请假流程,学生可以进行请假,班主任或者辅导员可以对学生的请假进行审批。这个时候我们对于请假的表单该怎么配置呢?我们沉思一下。首先我需要填写请假的开始时间、结束时间、请假的原因等等。那好我们来看一下最终的表单定义(名称是test.form),实例代码如下:

                {

                "key": "form1",

                "name": "学生请假流程",

                "fields": [

                                {

                                "id": "startTime",

                                "name": "开始时间",

                                "type": "text",

                                "required": false,

                                "placeholder": "empty"

                                },

                                {

                                "id": "endTime",

                                "name": "结束时间",

                                "type": "text",

                                "required": false,

                                "placeholder": "empty"

                                },

                                {

                                "id": "reason",

                                "name": "请假原因",

                                "type": "text",

                                "required": false,

                                "placeholder": "empty"

                                }

                             ]

                }

说明:

1、key:对应表单的key

2、name:表单的名称。

3、fields:该表单中定义的所有字段。注意:该字段是一个数组对象,可以定义多个。

4、表单的部署

接下来,我们看一下怎么去部署一个表单模板,前面我们获取到了一系列的表单服务类,其中有一个FormRepositoryService类,该类可以去部署表单。实例代码如下:

/**

* 1、部署表单

*/

@Test

public void deployForm() {

String resource = "com/shareniu/shareniu_network_flowable/test/test.form";

FormDeployment deploy = formRepositoryService.createDeployment().addClasspathResource(resource)

.deploy();

System.out.println(deploy);

}

执行完毕上述的代码之后,数据库的表以及数据如下:

mysql> SELECT * from ACT_FO_FORM_DEPLOYMENT;

+--------------------------------------+-------+-----------+---------------------+------------+-----------------------+

| ID_                                  | NAME_ | CATEGORY_ | DEPLOY_TIME_        | TENANT_ID_ | PARENT_DEPLOYMENT_ID_ |

+--------------------------------------+-------+-----------+---------------------+------------+-----------------------+

| 6ef25259-2d78-11e8-a80a-46920083fa77 | NULL  | NULL      | 2018-03-22 10:26:32 |            | NULL                  |

+--------------------------------------+-------+-----------+---------------------+------------+-----------------------+

1 row in set (0.00 sec)

ACT_FO_FORM_DEPLOYMENT表存储的是表单的相关信息,有表单的名称、部署的时间、租户的id、父级的部署id(这一个其实关联的是流程文档的部署id)、分类。

mysql> select * from ACT_FO_FORM_DEFINITION;

+--------------------------------------+--------------------+----------+-------+-----------+--------------------------------------+-----------------------+------------+-------------------------------------------------------+--------------+

| ID_                                  | NAME_              | VERSION_ | KEY_  | CATEGORY_ | DEPLOYMENT_ID_                       | PARENT_DEPLOYMENT_ID_ | TENANT_ID_ | RESOURCE_NAME_                                        | DESCRIPTION_ |

+--------------------------------------+--------------------+----------+-------+-----------+--------------------------------------+-----------------------+------------+-------------------------------------------------------+--------------+

| 6f0a472b-2d78-11e8-a80a-46920083fa77 | 学生请假流程 |        1 | form1 | NULL      | 6ef25259-2d78-11e8-a80a-46920083fa77 | NULL                  |            | com/shareniu/shareniu_network_flowable/test/test.form | NULL         |

+--------------------------------------+--------------------+----------+-------+-----------+--------------------------------------+-----------------------+------------+-------------------------------------------------------+--------------+

1 row in set (0.00 sec)

ACT_FO_FORM_DEFINITION:表单定义表、存储了表单定义的名称、版本、分类、部署id等核心数据。

mysql> select * from ACT_FO_FORM_RESOURCE;

| ID_                                  | NAME_                                                 | DEPLOYMENT_ID_                       | RESOURCE_BYTES_                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |

| 6ef2525a-2d78-11e8-a80a-46920083fa77 | com/shareniu/shareniu_network_flowable/test/test.form | 6ef25259-2d78-11e8-a80a-46920083fa77 | {

            "key": "form1",

            "name": "学生请假流程",

            "fields": [

                    {

                    "id": "startTime",

                    "name": "开始时间",

                    "type": "text",

                    "required": false,

                    "placeholder": "empty"

                    },

                    {

                    "id": "endTime",

                    "name": "结束时间",

                    "type": "text",

                    "required": false,

                    "placeholder": "empty"

                    },

                    {

                    "id": "reason",

                    "name": "请假原因",

                    "type": "text",

                    "required": false,

                    "placeholder": "empty"

                    }

                  ]

            }

|

1 row in set (0.00 sec)

ACT_FO_FORM_RESOURCE:表单资源表,存储的是我们定义的表单,对于上面的例子而言,存储的是test.form中的内容。

关于表单文件的设置、部署以及表单引擎相关的APi和表,我们已经讲解的差不多了,后面的课程我们看一下表单的运转过程。


转载请注明:分享牛 » flowable表单上