網上各種查資料,各種沒有,最多的一片文章是咖啡兔的大作,基於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());",
跳轉完成後如下圖所示,下圖已經漢化完成,預設展示的是英文版本。