整合Activiti Modeler到业务系统(或BPM平台)
http://www.kafeitu.me/activiti/2013/03/10/integrate-activiti-modeler.html
activit 5.12.1集成activiti-modeler 到 自己的业务系统(集成流程跟踪-完美支持IE)http://jhaij.iteye.com/blog/1871635
根据第二篇文章,整合成功;
FAQ:
1. 无法进入editor.
http://localhost:8080/YouPRJ/modeler/service/editor?id=2050,前提是这个id必需存在与act_re_model表里面,
那么,在调用这个之前,如何插入一条记录到这个表么?
待解决........
-------------
看到咖啡兔的例子,是先使用java保存到数据库,然后再打开editor, 保存的代码:
javascript: 一边保存,一边打开,同时保存后的页面又做reload, 很特别很有趣的做法,值得学习....
- $(function() {
- $('#create').button({
- icons: {
- primary: 'ui-icon-plus'
- }
- }).click(function() {
- $('#createModelTemplate').dialog({
- modal: true,
- width: 500,
- buttons: [{
- text: '创建',
- click: function() {
- if (!$('#name').val()) {
- alert('请填写名称!');
- $('#name').focus();
- return;
- }
- setTimeout(function() {
- location.reload();
- }, 1000);
- $('#modelForm').submit();
- }
- }]
- });
- });
- });
- @RequestMapping(value = "create", method = RequestMethod.POST)
- public void create(@RequestParam("name") String name, @RequestParam("key") String key, @RequestParam("description") String description,
- HttpServletRequest request, HttpServletResponse response) {
- 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);
- 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"));
- response.sendRedirect(request.getContextPath() + "/service/editor?id=" + modelData.getId());
- } catch (Exception e) {
- logger.error("创建模型失败:", e);
- }
- }
2. web editor保存的bpmn20文件到哪里去了?
会更新ACT_RE_MODEL和ACT_GE_BYTEARRAY表,ACT_GE_BYTEARRAY表保存了图片和xml文件信息(其实是json格式的字符串),并关联到ACT_RE_MODEL表。
ACT_RE_MODEL
说明:流程设计器设计流程后,保存数据到该表。
EDITOR_SOURCE_VALUE_ID(流程文件放在ACT_GE_BYTEARRAY中的ID);
EDITOR_SOURCE_EXTRA_VALUE_ID(流程文件图像放在ACT_GE_BYTEARRAY中的ID)。
3. 如何去部署保存在数据库里面的ACT_RE_MODEL表里面的工作流?
咖啡兔的源码: 创建,部署,删除,导出,遍历
- package me.kafeitu.demo.activiti.web.workflow;
- import java.io.ByteArrayInputStream;
- import java.util.List;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.activiti.bpmn.converter.BpmnXMLConverter;
- import org.activiti.bpmn.model.BpmnModel;
- import org.activiti.editor.constants.ModelDataJsonConstants;
- import org.activiti.editor.language.json.converter.BpmnJsonConverter;
- import org.activiti.engine.RepositoryService;
- import org.activiti.engine.repository.Deployment;
- import org.activiti.engine.repository.Model;
- import org.apache.commons.io.IOUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.codehaus.jackson.JsonNode;
- import org.codehaus.jackson.map.ObjectMapper;
- import org.codehaus.jackson.node.ObjectNode;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.servlet.ModelAndView;
- import org.springframework.web.servlet.mvc.support.RedirectAttributes;
- /**
- * 流程模型控制器
- *
- * @author henryyan
- */
- @Controller
- @RequestMapping(value = "/workflow/model")
- public class ModelController {
- protected Logger logger = LoggerFactory.getLogger(getClass());
- @Autowired
- RepositoryService repositoryService;
- /**
- * 模型列表
- */
- @RequestMapping(value = "list")
- public ModelAndView modelList() {
- ModelAndView mav = new ModelAndView("workflow/model-list");
- List<Model> list = repositoryService.createModelQuery().list();
- mav.addObject("list", list);
- return mav;
- }
- /**
- * 创建模型
- */
- @RequestMapping(value = "create", method = RequestMethod.POST)
- public void create(@RequestParam("name") String name, @RequestParam("key") String key, @RequestParam("description") String description,
- HttpServletRequest request, HttpServletResponse response) {
- 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);
- 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"));
- response.sendRedirect(request.getContextPath() + "/service/editor?id=" + modelData.getId());
- } catch (Exception e) {
- logger.error("创建模型失败:", e);
- }
- }
- /**
- * 根据Model部署流程
- */
- @RequestMapping(value = "deploy/{modelId}")
- public String deploy(@PathVariable("modelId") String modelId, RedirectAttributes redirectAttributes) {
- try {
- Model modelData = repositoryService.getModel(modelId);
- ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
- byte[] bpmnBytes = null;
- BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
- bpmnBytes = new BpmnXMLConverter().convertToXML(model);
- String processName = modelData.getName() + ".bpmn20.xml";
- Deployment deployment = repositoryService.createDeployment().name(modelData.getName()).addString(processName, new String(bpmnBytes)).deploy();
- redirectAttributes.addFlashAttribute("message", "部署成功,部署ID=" + deployment.getId());
- } catch (Exception e) {
- logger.error("根据模型部署流程失败:modelId={}", modelId, e);
- }
- return "redirect:/workflow/model/list";
- }
- /**
- * 导出model的xml文件
- */
- @RequestMapping(value = "export/{modelId}")
- public void export(@PathVariable("modelId") String modelId, HttpServletResponse response) {
- try {
- Model modelData = repositoryService.getModel(modelId);
- BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
- JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
- BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
- BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
- byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);
- ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
- IOUtils.copy(in, response.getOutputStream());
- String filename = bpmnModel.getMainProcess().getId() + ".bpmn20.xml";
- response.setHeader("Content-Disposition", "attachment; filename=" + filename);
- response.flushBuffer();
- } catch (Exception e) {
- logger.error("导出model的xml文件失败:modelId={}", modelId, e);
- }
- }
- @RequestMapping(value = "delete/{modelId}")
- public String delete(@PathVariable("modelId") String modelId) {
- repositoryService.deleteModel(modelId);
- return "redirect:/workflow/model/list";
- }
- }
问题:
1. java.lang.NoSuchMethodError: org.activiti.engine.impl.bpmn.diagram.ProcessDiagramCanvas.drawSequenceflowWithoutArrow(IIIIZZ)V
应为本地有两个工程的pom.xml都使用了
- <dependency>
- <groupId>org.activiti</groupId>
- <artifactId>activiti-engine</artifactId>
- <version>${activiti.version}</version>
- </dependency>
临时关闭或者删除一个工程,就不会提示这个错误了,至于为什么?我也搞不清楚。。。网上几乎没有人碰到这个错误,莫非是我太幸运???