Java Code Examples for org.activiti.bpmn.converter.BpmnXMLConverter#convertToXML()
The following examples show how to use
org.activiti.bpmn.converter.BpmnXMLConverter#convertToXML() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActModelService.java From Shop-for-JavaWeb with MIT License | 6 votes |
/** * 导出model的xml文件 * @throws IOException * @throws JsonProcessingException */ public void export(String id, HttpServletResponse response) { try { org.activiti.engine.repository.Model modelData = repositoryService.getModel(id); 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) { throw new ActivitiException("导出model的xml文件失败,模型ID="+id, e); } }
Example 2
Source File: ModelController.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * 导出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); } }
Example 3
Source File: BpmnModelTest.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * 把BpmnModel转换为XML对象 * @throws Exception */ @Test @Deployment(resources = "chapter6/dynamic-form/leave.bpmn") public void testBpmnModelToXml() throws Exception { // 验证是否部署成功 long count = repositoryService.createProcessDefinitionQuery().count(); assertEquals(1, count); // 查询流程定义对象 ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("leave").singleResult(); // 获取BpmnModel对象 BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId()); // 创建转换对象 BpmnXMLConverter converter = new BpmnXMLConverter(); // 把BpmnModel对象转换成字符(也可以输出到文件中) byte[] bytes = converter.convertToXML(bpmnModel); String xmlContent = new String(bytes); System.out.println(xmlContent); }
Example 4
Source File: DeploymentBuilderImpl.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public DeploymentBuilder addBpmnModel(String resourceName, BpmnModel bpmnModel) { BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter(); try { String bpmn20Xml = new String(bpmnXMLConverter.convertToXML(bpmnModel), "UTF-8"); addString(resourceName, bpmn20Xml); } catch (UnsupportedEncodingException e) { throw new ActivitiException("Errot while transforming BPMN model to xml: not UTF-8 encoded", e); } return this; }
Example 5
Source File: DeploymentBuilderImpl.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public DeploymentBuilder addBpmnModel(String resourceName, BpmnModel bpmnModel) { BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter(); try { String bpmn20Xml = new String(bpmnXMLConverter.convertToXML(bpmnModel), "UTF-8"); addString(resourceName, bpmn20Xml); } catch (UnsupportedEncodingException e) { throw new ActivitiException("Error while transforming BPMN model to xml: not UTF-8 encoded", e); } return this; }
Example 6
Source File: ProcessWithCompensationConverterTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Test public void testConvertingAfterAutoLayout() { final InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("ProcessWithCompensationAssociation.bpmn20.xml"); BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter(); BpmnModel bpmnModel1 = bpmnXMLConverter.convertToBpmnModel(new InputStreamProvider() { @Override public InputStream getInputStream() { return inputStream; } }, false, false); if (bpmnModel1.getLocationMap().size() == 0) { BpmnAutoLayout bpmnLayout = new BpmnAutoLayout(bpmnModel1); bpmnLayout.execute(); } byte[] xmlByte = bpmnXMLConverter.convertToXML(bpmnModel1); final InputStream byteArrayInputStream = new ByteArrayInputStream(xmlByte); BpmnModel bpmnModel2 = bpmnXMLConverter.convertToBpmnModel(new InputStreamProvider() { @Override public InputStream getInputStream() { return byteArrayInputStream; } }, false, false); assertEquals(10, bpmnModel1.getLocationMap().size()); assertEquals(10, bpmnModel2.getLocationMap().size()); assertEquals(7, bpmnModel1.getFlowLocationMap().size()); assertEquals(7, bpmnModel2.getFlowLocationMap().size()); }
Example 7
Source File: ActModelService.java From Shop-for-JavaWeb with MIT License | 5 votes |
/** * 根据Model部署流程 */ public String deploy(String id) { String message = ""; try { org.activiti.engine.repository.Model modelData = repositoryService.getModel(id); 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); String processName = modelData.getName(); if (!StringUtils.endsWith(processName, ".bpmn20.xml")){ processName += ".bpmn20.xml"; } // System.out.println("========="+processName+"============"+modelData.getName()); ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes); Deployment deployment = repositoryService.createDeployment().name(modelData.getName()) .addInputStream(processName, in).deploy(); // .addString(processName, new String(bpmnBytes)).deploy(); // 设置流程分类 List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list(); for (ProcessDefinition processDefinition : list) { repositoryService.setProcessDefinitionCategory(processDefinition.getId(), modelData.getCategory()); message = "部署成功,流程ID=" + processDefinition.getId(); } if (list.size() == 0){ message = "部署失败,没有流程。"; } } catch (Exception e) { throw new ActivitiException("设计模型图不正确,检查模型正确性,模型ID="+id, e); } return message; }
Example 8
Source File: FlowableModelManagerController.java From hsweb-framework with Apache License 2.0 | 4 votes |
/** * 导出model对象为指定类型 * * @param modelId 模型ID * @param type 导出文件类型(bpmn\json) */ @GetMapping(value = "export/{modelId}/{type}") @ApiOperation("导出模型") @Authorize(action = "export") @SneakyThrows public void export(@PathVariable("modelId") @ApiParam("模型ID") String modelId, @PathVariable("type") @ApiParam(value = "类型", allowableValues = "bpmn,json", example = "json") ModelType type, @ApiParam(hidden = true) HttpServletResponse response) { Model modelData = repositoryService.getModel(modelId); if (modelData == null) { throw new NotFoundException("模型不存在"); } BpmnJsonConverter jsonConverter = new BpmnJsonConverter(); byte[] modelEditorSource = repositoryService.getModelEditorSource(modelData.getId()); JsonNode editorNode = new ObjectMapper().readTree(modelEditorSource); BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode); // 处理异常 if (bpmnModel.getMainProcess() == null) { throw new UnsupportedOperationException("无法导出模型文件:" + type); } String filename = ""; byte[] exportBytes = null; String mainProcessId = bpmnModel.getMainProcess().getId(); if (type == ModelType.bpmn) { BpmnXMLConverter xmlConverter = new BpmnXMLConverter(); exportBytes = xmlConverter.convertToXML(bpmnModel); filename = mainProcessId + ".bpmn20.xml"; } else if (type == ModelType.json) { exportBytes = modelEditorSource; filename = mainProcessId + ".json"; } else { throw new UnsupportedOperationException("不支持的格式:" + type); } response.setCharacterEncoding("UTF-8"); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(filename, "UTF-8")); /*创建输入流*/ try (ByteArrayInputStream in = new ByteArrayInputStream(exportBytes)) { IOUtils.copy(in, response.getOutputStream()); response.flushBuffer(); } }