modeler与activiti进行整合

整合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, 很特别很有趣的做法,值得学习....

  1. $(function() {
  2. $('#create').button({
  3. icons: {
  4. primary: 'ui-icon-plus'
  5. }
  6. }).click(function() {
  7. $('#createModelTemplate').dialog({
  8. modal: true,
  9. width: 500,
  10. buttons: [{
  11. text: '创建',
  12. click: function() {
  13. if (!$('#name').val()) {
  14. alert('请填写名称!');
  15. $('#name').focus();
  16. return;
  17. }
  18. setTimeout(function() {
  19. location.reload();
  20. }, 1000);
  21. $('#modelForm').submit();
  22. }
  23. }]
  24. });
  25. });
  26. });
  1. @RequestMapping(value = "create", method = RequestMethod.POST)
  2. public void create(@RequestParam("name") String name, @RequestParam("key") String key, @RequestParam("description") String description,
  3. HttpServletRequest request, HttpServletResponse response) {
  4. try {
  5. ObjectMapper objectMapper = new ObjectMapper();
  6. ObjectNode editorNode = objectMapper.createObjectNode();
  7. editorNode.put("id", "canvas");
  8. editorNode.put("resourceId", "canvas");
  9. ObjectNode stencilSetNode = objectMapper.createObjectNode();
  10. stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
  11. editorNode.put("stencilset", stencilSetNode);
  12. Model modelData = repositoryService.newModel();
  13. ObjectNode modelObjectNode = objectMapper.createObjectNode();
  14. modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, name);
  15. modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
  16. description = StringUtils.defaultString(description);
  17. modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);
  18. modelData.setMetaInfo(modelObjectNode.toString());
  19. modelData.setName(name);
  20. modelData.setKey(StringUtils.defaultString(key));
  21. repositoryService.saveModel(modelData);
  22. repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
  23. response.sendRedirect(request.getContextPath() + "/service/editor?id=" + modelData.getId());
  24. } catch (Exception e) {
  25. logger.error("创建模型失败:", e);
  26. }
  27. }

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表里面的工作流? 
    咖啡兔的源码: 创建,部署,删除,导出,遍历

  1. package me.kafeitu.demo.activiti.web.workflow;
  2. import java.io.ByteArrayInputStream;
  3. import java.util.List;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.activiti.bpmn.converter.BpmnXMLConverter;
  7. import org.activiti.bpmn.model.BpmnModel;
  8. import org.activiti.editor.constants.ModelDataJsonConstants;
  9. import org.activiti.editor.language.json.converter.BpmnJsonConverter;
  10. import org.activiti.engine.RepositoryService;
  11. import org.activiti.engine.repository.Deployment;
  12. import org.activiti.engine.repository.Model;
  13. import org.apache.commons.io.IOUtils;
  14. import org.apache.commons.lang3.StringUtils;
  15. import org.codehaus.jackson.JsonNode;
  16. import org.codehaus.jackson.map.ObjectMapper;
  17. import org.codehaus.jackson.node.ObjectNode;
  18. import org.slf4j.Logger;
  19. import org.slf4j.LoggerFactory;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.stereotype.Controller;
  22. import org.springframework.web.bind.annotation.PathVariable;
  23. import org.springframework.web.bind.annotation.RequestMapping;
  24. import org.springframework.web.bind.annotation.RequestMethod;
  25. import org.springframework.web.bind.annotation.RequestParam;
  26. import org.springframework.web.servlet.ModelAndView;
  27. import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  28. /**
  29. * 流程模型控制器
  30. *
  31. * @author henryyan
  32. */
  33. @Controller
  34. @RequestMapping(value = "/workflow/model")
  35. public class ModelController {
  36. protected Logger logger = LoggerFactory.getLogger(getClass());
  37. @Autowired
  38. RepositoryService repositoryService;
  39. /**
  40. * 模型列表
  41. */
  42. @RequestMapping(value = "list")
  43. public ModelAndView modelList() {
  44. ModelAndView mav = new ModelAndView("workflow/model-list");
  45. List<Model> list = repositoryService.createModelQuery().list();
  46. mav.addObject("list", list);
  47. return mav;
  48. }
  49. /**
  50. * 创建模型
  51. */
  52. @RequestMapping(value = "create", method = RequestMethod.POST)
  53. public void create(@RequestParam("name") String name, @RequestParam("key") String key, @RequestParam("description") String description,
  54. HttpServletRequest request, HttpServletResponse response) {
  55. try {
  56. ObjectMapper objectMapper = new ObjectMapper();
  57. ObjectNode editorNode = objectMapper.createObjectNode();
  58. editorNode.put("id", "canvas");
  59. editorNode.put("resourceId", "canvas");
  60. ObjectNode stencilSetNode = objectMapper.createObjectNode();
  61. stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
  62. editorNode.put("stencilset", stencilSetNode);
  63. Model modelData = repositoryService.newModel();
  64. ObjectNode modelObjectNode = objectMapper.createObjectNode();
  65. modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, name);
  66. modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
  67. description = StringUtils.defaultString(description);
  68. modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);
  69. modelData.setMetaInfo(modelObjectNode.toString());
  70. modelData.setName(name);
  71. modelData.setKey(StringUtils.defaultString(key));
  72. repositoryService.saveModel(modelData);
  73. repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
  74. response.sendRedirect(request.getContextPath() + "/service/editor?id=" + modelData.getId());
  75. } catch (Exception e) {
  76. logger.error("创建模型失败:", e);
  77. }
  78. }
  79. /**
  80. * 根据Model部署流程
  81. */
  82. @RequestMapping(value = "deploy/{modelId}")
  83. public String deploy(@PathVariable("modelId") String modelId, RedirectAttributes redirectAttributes) {
  84. try {
  85. Model modelData = repositoryService.getModel(modelId);
  86. ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
  87. byte[] bpmnBytes = null;
  88. BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
  89. bpmnBytes = new BpmnXMLConverter().convertToXML(model);
  90. String processName = modelData.getName() + ".bpmn20.xml";
  91. Deployment deployment = repositoryService.createDeployment().name(modelData.getName()).addString(processName, new String(bpmnBytes)).deploy();
  92. redirectAttributes.addFlashAttribute("message", "部署成功,部署ID=" + deployment.getId());
  93. } catch (Exception e) {
  94. logger.error("根据模型部署流程失败:modelId={}", modelId, e);
  95. }
  96. return "redirect:/workflow/model/list";
  97. }
  98. /**
  99. * 导出model的xml文件
  100. */
  101. @RequestMapping(value = "export/{modelId}")
  102. public void export(@PathVariable("modelId") String modelId, HttpServletResponse response) {
  103. try {
  104. Model modelData = repositoryService.getModel(modelId);
  105. BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
  106. JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
  107. BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
  108. BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
  109. byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);
  110. ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
  111. IOUtils.copy(in, response.getOutputStream());
  112. String filename = bpmnModel.getMainProcess().getId() + ".bpmn20.xml";
  113. response.setHeader("Content-Disposition", "attachment; filename=" + filename);
  114. response.flushBuffer();
  115. } catch (Exception e) {
  116. logger.error("导出model的xml文件失败:modelId={}", modelId, e);
  117. }
  118. }
  119. @RequestMapping(value = "delete/{modelId}")
  120. public String delete(@PathVariable("modelId") String modelId) {
  121. repositoryService.deleteModel(modelId);
  122. return "redirect:/workflow/model/list";
  123. }
  124. }

问题: 
1. java.lang.NoSuchMethodError: org.activiti.engine.impl.bpmn.diagram.ProcessDiagramCanvas.drawSequenceflowWithoutArrow(IIIIZZ)V 
应为本地有两个工程的pom.xml都使用了

  1. <dependency>
  2. <groupId>org.activiti</groupId>
  3. <artifactId>activiti-engine</artifactId>
  4. <version>${activiti.version}</version>
  5. </dependency>

临时关闭或者删除一个工程,就不会提示这个错误了,至于为什么?我也搞不清楚。。。网上几乎没有人碰到这个错误,莫非是我太幸运???

上一篇:oracle session数激增排查过程


下一篇:使用PLSQL Developer和DbVisualizer、SQLDBx查询oracle数据库时出现乱码