网上各种查资料,各种没有,最多的一片文章是咖啡兔的大作,基于spring MVC与marven,与我集成的业务系统差别较大,且activiti是5.12版本,其他文章基本都是抄来抄去,后面终于自己整了出来,集成内容存在冗余,目录结构不合理,本文暂不考虑,我还没整理清楚,记录下整理步骤:
(1)下载activiti 5.14,下载完成后,找到此文件,activiti-5.14\wars\activiti-explorer.war,解压后目录结构如下,(war包解压java cvf 命令)
(2)把除“WEB_INFO”以外的文件先不加处理的仍到项目的WebRoot文件夹下
(3)后修改spring配置文件
添加如下配置:
<!-- 流程引擎基础配置开始 -->
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSource" />
<!-- Database configurations -->
<property name="databaseSchemaUpdate" value="true" />
<!-- job executor configurations -->
<property name="jobExecutorActivate" value="false" />
<property name="transactionManager" ref="transactionManager"/>
<property name="deploymentResources" value="classpath*:/diagrams/*/*.bpmn"/>
<!-- font -->
<property name="activityFontName" value="宋体"/>
<property name="labelFontName" value="宋体"/>
</bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration"/>
</bean>
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
<bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService"/>
<bean id="formService" factory-bean="processEngine" factory-method="getFormService" />
<!-- 流程引擎基础配置结束 -->
(4)再次打开解压出来的war包文件,找到“WEB-INF\classes”下面的所有配置文件,不加修改的仍到项目系统对应的目录下,保证项目编译完成后在WEB-INF\classes下能找到该文件。
(5)修改web.xml文件
activiti modeler采用servlet的方式,可以采用自己手写过滤器的方式进行过滤拦截,也可以直接修改struts在web.xml的配置实现,个人直接修改配置文件
如上图所示,添加过滤拦截,此处根据不同的原系统配置需要做不同的实现,目前本人业务系统action之间的跳转都是通过.action的方式。
(6)在web.xml下添加如下内容
<servlet>
<servlet-name>RestletServlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<!-- Application class name -->
<param-name>org.restlet.application</param-name>
<param-value>org.activiti.rest.explorer.application.ExplorerRestApplication</param-value>
</init-param>
</servlet>
<!-- Catch all service requests -->
<servlet-mapping>
<servlet-name>RestletServlet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
(7)添加jar文件,将下载到的activiti包activiti-5.14\libs下的所有jar文件导入到业务系统中。
(8)反编译WEB-INF\classes下相关类,总共没几个很好反编译。还原war包下此处的所有class文件,最终将相关文件按照原目录结构全部copy到业务系统中,结构如下
(9)写一个action类,创建流程
package com.boyun.activiti.base.action;
import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.activiti.explorer.demo.DemoDataGenerator;
import java.io.ByteArrayInputStream;
import java.util.List;
import org.activiti.editor.constants.ModelDataJsonConstants;
import org.activiti.engine.repository.Model;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.node.ObjectNode;
import com.boyun.action.BaseAction;
@Scope("prototype")
@Controller("baseActivitiAction")
public class BaseActivitiAction extends BaseAction{
/**
*
*/
private static final long serialVersionUID = 1L;
@Autowired
ProcessEngine processEngine;
@Autowired
RepositoryService repositoryService;
@Autowired
TaskService taskService;
@Autowired
RuntimeService runtimeService;
@Autowired
protected IdentityService identityService;
@Autowired
private FormService formService;
@Autowired
private HistoryService historyService;
public String createActiviti(){
try {
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode editorNode = objectMapper.createObjectNode();
editorNode.put("id", "canvas");
editorNode.put("resourceId", "canvas");
ObjectNode stencilSetNode = objectMapper.createObjectNode();
stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
editorNode.put("stencilset", stencilSetNode);
Model modelData = repositoryService.newModel();
ObjectNode modelObjectNode = objectMapper.createObjectNode();
modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, "name");
modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
String description = StringUtils.defaultString("description");
modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);
modelData.setMetaInfo(modelObjectNode.toString());
modelData.setName("name");
modelData.setKey(StringUtils.defaultString("key"));
repositoryService.saveModel(modelData);
repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
this.getResponse().sendRedirect(this.getRequest().getContextPath() + "/service/editor?id=" + modelData.getId());
}catch(Exception e){
e.printStackTrace();
}
return null;
}
private String modelId;
}
(10)将此类按照正常struts配置,完成后访问此类,创建完成,后直接跳转到编辑页面" this.getResponse().sendRedirect(this.getRequest().getContextPath() + "/service/editor?id=" + modelData.getId());",
跳转完成后如下图所示,下图已经汉化完成,默认展示的是英文版本。