Activiti5.22开发 整合spring和整合编辑器插件(上)

1   下载 5.22 安装包 ,activiti-5.22.0.rar
    https://github.com/Activiti/Activiti/releases
2 配置项目maven依赖 
         < dependency >
         < groupId >org.activiti groupId >
         < artifactId >activiti-spring artifactId >
         < version >${activitti.version} version >
         dependency >   
        
         < dependency >
         < groupId >org.activiti groupId >
         < artifactId >activiti-engine artifactId >
         < version >${activitti.version} version >
         dependency >       
         < dependency >
         < groupId >org.activiti groupId >
         < artifactId >activiti-modeler artifactId >
         < version >${activitti.version} version >
         dependency >       
         < dependency >
         < groupId >org.activiti groupId >
         < artifactId >activiti-diagram-rest artifactId >
         < version >${activitti.version} version >
         dependency >
3 从activiti-5.22.0.rar中解压 activiti-explorer.war (解压war方法直接改rar) 
 
4 将 activiti-explorer.war 中以下文件夹和文件拷贝到项目webapp中
  
5 从activiti-5.22.0.rar中目录lib中解压出 activiti-bpmn-model-5.22.0-sources.jar  备用

6 从activiti-explorer.war 目录中 \WEB-INF\classes\stencilset.json  拷贝文件到项目resources 中
 7 修改项目webapp\editor-app\app-cfg.js 文件, 配置项目url,url是编辑器相关的后台服务的url。 myspringmvc是项目名称
'use strict';
var ACTIVITI = ACTIVITI || {};
ACTIVITI.CONFIG = {
     //'contextRoot' : '/activiti-explorer/service',
'contextRoot' : '/myspringmvc/service',
};
 8 整合 modeler模块, activiti-bpmn-model-5.22.0-sources.jar , 一共只有三个Controller类,对应着三个URL,分别是:

 StencilsetRestResource /editor/stencilset 用来加载并返回stencilset.json文件的内容

 ModelEditorJsonRestResource /model/{modelId}/json 这个就是访问的那个url了,通过部署的modelId模型编辑源

 ModelSaveRestResource /model/{modelId}/save 这个是用来保存编辑的模型

 9 修改三个 Controller类
      在每个Controller类上加上@RequestMapping注解,并指定值为"service"(对应前台app-cfg.js中配置的url),例如: StencilsetRestResource类

@RestController
@RequestMapping( "/service")
public class StencilsetRestResource {
@RequestMapping(value= "/editor/stencilset", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
public @ ResponseBody String getStencilset() {
InputStream stencilsetStream = this.getClass().getClassLoader().getResourceAsStream( "stencilset.json");
try {
return IOUtils.toString(stencilsetStream, "utf-8");
} catch ( Exception e) {
throw new ActivitiException( "Error while loading stencil set", e);
}
}
}
10 编写  ModelerController 类,提供新建模型的接口 model/newModel
RestController
@RequestMapping( "models")
public class ModelerController implements RestServiceController< Model, String>{

@Autowired
RepositoryService repositoryService;
@Autowired
ObjectMapper objectmapper;

/**
* 新建一个空模型
* @return
* @throws UnsupportedEncodingException
*/
@GetMapping( "newModel")
public void newModel( HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
     //初始化一个空模型
Model model = repositoryService.newModel();

//设置一些默认信息
String name = "new-process";
String description = "";
int revision = 1;
String key = "process";

ObjectNode modelNode = objectmapper.createObjectNode();
modelNode.put(ModelDataJsonConstants.MODEL_NAME, name);
modelNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);
modelNode.put(ModelDataJsonConstants.MODEL_REVISION, revision);

model.setName(name);
model.setKey(key);
model.setMetaInfo(modelNode.toString());

repositoryService.saveModel(model);
String id = model.getId();

//完善ModelEditorSource
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);
repositoryService.addModelEditorSource(id,editorNode.toString().getBytes( "utf-8"));
try {
            response.sendRedirect(request.getContextPath() + "/modeler.html?modelId=" +id);
        } catch ( IOException e) {           
            e.printStackTrace();
        }
}
}

     
Activiti5.22开发 <2> 整合spring和整合编辑器插件(下)

你可能感兴趣的:(Activiti)