activiti6官方示例笔记

概述

要想学习 activiti工作流, 入门便是学习官方的示例。下边我将基于官方的demo做一遍流程,考虑自己的业务该如何基于 activiti 设计逻辑。

工作流要素:

  • 流程
  • 表单
  • 用户

有了以上3大要素,流程便可以流转。

  • 表单绑定在流程节点上,用来输入当前流程信息
  • 用户绑定在流程节点上,用来处理当前流程任务

下载安装

首先到 官方 下载activiti6.0.0。

activiti7 感兴趣的可以看 这里

然后将war包置于 tomcat/webapps 目录下,启动tomcat即可。

应用 说明 地址 帐号/密码
activiti-app 流程、表单、用户、发布、任务… http://localhost:8080/activiti-app admin/test
activiti-admin 平台管理查看流程平台运行详情 http://localhost:8080/activiti-admin admin/admin
activiti-rest rest-api接口应用 http://localhost:8080/activiti-rest kermit/kermit

用户管理

登录 http://localhost:8080/activiti-app/#/

  • Kickstart App:主要用于流程模型管理、表单管理及应用(App)管理,一个应用可以包含多个流程模型,应用可发布给其他用户使用。
  • Task App:用于管理整个activiti-app的任务,在该功能里面也可以启动流程
  • Idenity management:身份信息管理,可以管理用户、用户组等数据

创建用户

创建过程如下,注意id即是登录帐号。依次分别创建3个帐号用户审批流程。

流程定义

在主界面点击 Kickstart App 进入流程定义页面。

上图中模拟了一个请假流程,但是流程的执行需要人来参与,所以下边我们进行流程和帐号绑定。
选定流程节点后点击 Assignment 属性,会有弹窗进行绑定。

同理,将其他节点进行绑定。然后保存关闭即可,可以看到一个流程已创建完毕。

动态表单

之前的都是基本演示,假设我们需要复杂的表单,那么可以在流程节点上绑定表单即可,这里做下动态表单的基本演示。

  1. 选中流程节点,编辑 Referenced form, 动态创建节点关联表单。

  1. 编辑表单字段

  1. 保存表单

这样在流程中我们就可以通过表单流转复杂的信息了,大家可以实践下,下边的流程就不演示了。

流程发布

将应用和我们之前创建的流程绑定。

然后点击发布流程

发布完成后回到首页可以看到发布结果

流程测试

  1. 登录 zhangsan 帐号创建请假任务

查看流程当前流转状态。

点击 complete, 任务流转到下一个流程节点。

  1. 登录 lisi 审批

  1. 同理,登录 wangwu 审批,流程结束。

流程管理

登录 http://localhost:8080/activiti-admin/#/login

配置应用服务节点

配置后即可查看历史流程记录

持久化

tomcat 重启后,activiti 相关的数据会重置,如果想持久化,可以把数据持久化到 MySQL

首先删除3个war包,避免重启覆盖我们修改的配置

activiti-app持久化

修改 activiti-app/WEB-INF/classes/META-INF/activiti-app/activiti-app.properties。修改后的配置文件如下(需要手动创建activiti6ui库,下边几个项目类似):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#
# SECURITY
#
security.rememberme.key=testkey

#
# DATABASE
#

# datasource.driver=org.h2.Driver
# datasource.url=jdbc:h2:mem:activiti;DB_CLOSE_DELAY=-1

datasource.driver=com.mysql.jdbc.Driver
datasource.url=jdbc:mysql://127.0.0.1:3306/activiti6ui?characterEncoding=UTF-8

datasource.username=root
datasource.password=root

# hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.dialect=org.hibernate.dialect.MySQLDialect
#hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
#hibernate.dialect=org.hibernate.dialect.SQLServerDialect
#hibernate.dialect=org.hibernate.dialect.DB2Dialect
#hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

#
# EMAIL
#

#email.enabled=true
#email.host=localhost
#email.port=1025
#email.useCredentials=false
#email.username=
#email.password=

# The base url that will be used to create urls in emails.
#email.base.url=http://localhost:9999/activiti-app

#email.from.default=no-reply@activiti.alfresco.com
#email.from.default.name=Activiti
#email.feedback.default=activiti@alfresco.com

#
# ACTIVITI
#

activiti.process-definitions.cache.max=500

#
# DEFAULT ADMINISTRATOR ACCOUNT
#

admin.email=admin
admin.password=test
admin.lastname=Administrator

admin.group=Superusers

# The maximum file upload limit. Set to -1 to set to 'no limit'. Expressed in bytes
file.upload.max.size=104857600

# For development purposes, data folder is created inside the sources ./data folder
contentstorage.fs.rootFolder=data/
contentstorage.fs.createRoot=true
contentstorage.fs.depth=4
contentstorage.fs.blockSize=1024

activiti-admin持久化

修改 activiti-admin/WEB-INF/classes/META-INF/activiti-admin/activiti-admin.properties。修改后的配置文件如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# security configuration (this key should be unique for your application, and kept secret)
security.rememberme.key=activitis3cr3tk3y



# H2 example (default)

#datasource.driver=org.h2.Driver
#datasource.url=jdbc:h2:tcp://localhost/activitiadmin

# MySQL example

datasource.driver=com.mysql.jdbc.Driver
datasource.url=jdbc:mysql://127.0.0.1:3306/activitiadmin?characterEncoding=UTF-8

#datasource.driver=org.postgresql.Driver
#datasource.url=jdbc:postgresql://localhost:5432/activitiadmin

#datasource.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
#datasource.url=jdbc:sqlserver://localhost:1433;databaseName=activitiadmin

#datasource.driver=oracle.jdbc.driver.OracleDriver
#datasource.url=jdbc:oracle:thin:@localhost:1521:ACTIVITIADMIN

#datasource.driver=com.ibm.db2.jcc.DB2Driver
#datasource.url=jdbc:db2://localhost:50000/activitiadmin

datasource.username=root
datasource.password=root

# JNDI CONFIG

# If uncommented, the datasource will be looked up using the configured JNDI name.
# This will have preference over any datasource configuration done below that doesn't use JNDI
#
# Eg for JBoss: java:jboss/datasources/activitiDS
#
#datasource.jndi.name=jdbc/activitiDS

# Set whether the lookup occurs in a J2EE container, i.e. if the prefix "java:comp/env/" needs to be added if the JNDI
# name doesn't already contain it. Default is "true".
#datasource.jndi.resourceRef=true

#hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.dialect=org.hibernate.dialect.MySQLDialect
#hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
#hibernate.dialect=org.hibernate.dialect.SQLServerDialect
#hibernate.dialect=org.hibernate.dialect.DB2Dialect
#hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
#hibernate.show_sql=false
#hibernate.generate_statistics=false

#
# Connection pool (see http://www.mchange.com/projects/c3p0/#configuration)
#

#datasource.min-pool-size=5
#datasource.max-pool-size=100
#datasource.acquire-increment=5
# test query for H2, MySQL, PostgreSQL and Microsoft SQL Server
#datasource.preferred-test-query=select 1
# test query for Oracle
#datasource.preferred-test-query=SELECT 1 FROM DUAL
# test query for DB2
#datasource.preferred-test-query=SELECT current date FROM sysibm.sysdummy1
#datasource.test-connection-on-checkin=true
#datasource.test-connection-on-checkout=true
#datasource.max-idle-time=1800
#datasource.max-idle-time-excess-connections=1800

#
# Cluster settings
#

# This a period of time, expressed in milliseconds, that indicates
# when a node is deemed to be inactive and is removed from the list
# of nodes of a cluster (nor will it appear in the 'monitoring' section of the application).
#
# When a node is properly shut down, it will send out an event indicating
# it is shut down. From that point on, the data will be kept in memory for the amount
# of time indicated here.
# When a node is not properly shut down (eg hardware failure), this is the period of time
# before removal, since the time the last event is received.
#
# Make sure the value here is higher than the sending interval of the nodes, to avoid
# that nodes incorrectly removed.
#
# By default 10 minutes
cluster.monitoring.max.inactive.time=600000

# A cron expression that configures when the check for inactive nodes is made.
# When executed, this will mark any node that hasn't been active for 'cluster.monitoring.max.inactive.time'
# seconds, as an inactive node. Default: every 5 minutes.
cluster.monitoring.inactive.check.cronexpression=0 0/5 * * * ?

# REST endpoint config
rest.app.name=Activiti app
rest.app.description=Activiti app Rest config
rest.app.host=http://localhost
rest.app.port=8080
rest.app.contextroot=activiti-app
rest.app.restroot=api
rest.app.user=admin
rest.app.password=test

# Passwords for rest endpoints and master configs are stored encrypted in the database using AES/CBC/PKCS5PADDING
# It needs a 128-bit initialization vector (http://en.wikipedia.org/wiki/Initialization_vector)
# and a 128-bit secret key represented as 16 ascii characters below
#
# Do note that if these properties are changed after passwords have been saved, all existing passwords
# will not be able to be decrypted and the password would need to be reset in the UI.
security.encryption.credentialsIVSpec=j8kdO2hejA9lKmm6
security.encryption.credentialsSecretSpec=9FGl73ngxcOoJvmL

# BPMN 2.0 Modeler config

modeler.url=https://activiti.alfresco.com/activiti-app/api/

# Enable multi tenant support, disabled by default
#multi-tenant.enabled=true

由于该项目下没有mysql驱动包,手动复制 activiti-app/WEB-INF/lib/mysql-connector-java-5.1.30.jaractiviti-admin/WEB-INF/lib 下。

activiti-rest持久化

修改 activiti-rest/WEB-INF/classes/db.properties, 修改后的配置文件如下:

1
2
3
4
5
6
7
8
9
10
11
12
# db=h2
# jdbc.driver=org.h2.Driver
# jdbc.url=jdbc:h2:mem:activiti;DB_CLOSE_DELAY=-1
# jdbc.username=sa
# jdbc.password=

db=MySQL
datasource.driver=com.mysql.jdbc.Driver
datasource.url=jdbc:mysql://127.0.0.1:3306/activiti6ui?characterEncoding=UTF-8
datasource.username=root
datasource.password=root
hibernate.dialect=org.hibernate.dialect.MySQLDialect

同样,将 activiti-app/WEB-INF/lib/mysql-connector-java-5.1.30.jar 复制到 activiti-rest/WEB-INF/lib

文档路径: http://127.0.0.1:8080/activiti-rest/docs/

启动Tomcat, 按照默认url和帐号访问3个项目即可

最后

官方 activiti6 前端是基于 angular 编写的,UI也不太符合国人习惯,大家可以基于官方设计重写UI即可。