org.activiti.bpmn.converter.BpmnXMLConverter Java Examples
The following examples show how to use
org.activiti.bpmn.converter.BpmnXMLConverter.
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: FlowableModelManagerController.java From hsweb-framework with Apache License 2.0 | 6 votes |
@PostMapping("/{modelId}/deploy") @ApiOperation("发布模型") @Authorize(action = "deploy") public ResponseMessage<Deployment> deployModel(@PathVariable String modelId) throws Exception { Model modelData = repositoryService.getModel(modelId); if (modelData == null) { throw new NotFoundException("模型不存在!"); } ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId())); BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode); byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model); String processName = modelData.getName() + ".bpmn20.xml"; Deployment deployment = repositoryService.createDeployment() .name(modelData.getName()) .addString(processName, new String(bpmnBytes, "utf8")) .deploy(); return ResponseMessage.ok(deployment).include(Deployment.class, "id", "name", "new"); }
Example #2
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 #3
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 #4
Source File: ModelController.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * 根据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:/chapter20/model/list"; }
Example #5
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 #6
Source File: ChineseConverterTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected void deployProcess(BpmnModel bpmnModel) { byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel); try { Deployment deployment = processEngine.getRepositoryService().createDeployment() .name("test") .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE) .addString("test.bpmn20.xml", new String(xml)) .deploy(); processEngine.getRepositoryService().deleteDeployment(deployment.getId()); } finally { processEngine.close(); } }
Example #7
Source File: DefaultProcessValidatorTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Test public void testWarningError() throws UnsupportedEncodingException, XMLStreamException { String flowWithoutConditionNoDefaultFlow = "<?xml version='1.0' encoding='UTF-8'?>" + "<definitions id='definitions' xmlns='http://www.omg.org/spec/BPMN/20100524/MODEL' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:activiti='http://activiti.org/bpmn' targetNamespace='Examples'>" + " <process id='exclusiveGwDefaultSequenceFlow'> " + " <startEvent id='theStart' /> " + " <sequenceFlow id='flow1' sourceRef='theStart' targetRef='exclusiveGw' /> " + " <exclusiveGateway id='exclusiveGw' name='Exclusive Gateway' /> " + // no default = "flow3" !! " <sequenceFlow id='flow2' sourceRef='exclusiveGw' targetRef='theTask1'> " + " <conditionExpression xsi:type='tFormalExpression'>${input == 1}</conditionExpression> " + " </sequenceFlow> " + " <sequenceFlow id='flow3' sourceRef='exclusiveGw' targetRef='theTask2'/> " + // one would be OK " <sequenceFlow id='flow4' sourceRef='exclusiveGw' targetRef='theTask2'/> " + // but two unconditional not! " <userTask id='theTask1' name='Input is one' /> " + " <userTask id='theTask2' name='Default input' /> " + " </process>" + "</definitions>"; XMLInputFactory xif = XMLInputFactory.newInstance(); InputStreamReader in = new InputStreamReader(new ByteArrayInputStream(flowWithoutConditionNoDefaultFlow.getBytes()), "UTF-8"); XMLStreamReader xtr = xif.createXMLStreamReader(in); BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr); Assert.assertNotNull(bpmnModel); List<ValidationError> allErrors = processValidator.validate(bpmnModel); Assert.assertEquals(1, allErrors.size()); Assert.assertTrue(allErrors.get(0).isWarning()); }
Example #8
Source File: FlowableDeploymentController.java From hsweb-framework with Apache License 2.0 | 5 votes |
/*** * 流程定义转换Model */ @PutMapping(value = "/convert-to-model/{processDefinitionId}") @ApiOperation("流程定义转换模型") @Authorize(action = Permission.ACTION_UPDATE) public ResponseMessage<String> convertToModel(@PathVariable("processDefinitionId") String processDefinitionId) throws UnsupportedEncodingException, XMLStreamException { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery() .processDefinitionId(processDefinitionId).singleResult(); if (null == processDefinition) { throw new NotFoundException(); } InputStream bpmnStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName()); XMLInputFactory xif = XMLInputFactory.newInstance(); InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8"); XMLStreamReader xtr = xif.createXMLStreamReader(in); BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr); BpmnJsonConverter converter = new BpmnJsonConverter(); com.fasterxml.jackson.databind.node.ObjectNode modelNode = converter.convertToJson(bpmnModel); org.activiti.engine.repository.Model modelData = repositoryService.newModel(); modelData.setKey(processDefinition.getKey()); modelData.setName(processDefinition.getResourceName().substring(0, processDefinition.getResourceName().indexOf("."))); modelData.setCategory(processDefinition.getDeploymentId()); ObjectNode modelObjectNode = new ObjectMapper().createObjectNode(); modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processDefinition.getName()); modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1); modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, processDefinition.getDescription()); modelData.setMetaInfo(modelObjectNode.toString()); repositoryService.saveModel(modelData); repositoryService.addModelEditorSource(modelData.getId(), modelNode.toString().getBytes("utf-8")); return ResponseMessage.ok(modelData.getId()); }
Example #9
Source File: ActProcessService.java From Shop-for-JavaWeb with MIT License | 5 votes |
/** * 将部署的流程转换为模型 * @param procDefId * @throws UnsupportedEncodingException * @throws XMLStreamException */ @Transactional(readOnly = false) public org.activiti.engine.repository.Model convertToModel(String procDefId) throws UnsupportedEncodingException, XMLStreamException { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult(); InputStream bpmnStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName()); XMLInputFactory xif = XMLInputFactory.newInstance(); InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8"); XMLStreamReader xtr = xif.createXMLStreamReader(in); BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr); BpmnJsonConverter converter = new BpmnJsonConverter(); ObjectNode modelNode = converter.convertToJson(bpmnModel); org.activiti.engine.repository.Model modelData = repositoryService.newModel(); modelData.setKey(processDefinition.getKey()); modelData.setName(processDefinition.getResourceName()); modelData.setCategory(processDefinition.getCategory());//.getDeploymentId()); modelData.setDeploymentId(processDefinition.getDeploymentId()); modelData.setVersion(Integer.parseInt(String.valueOf(repositoryService.createModelQuery().modelKey(modelData.getKey()).count()+1))); ObjectNode modelObjectNode = new ObjectMapper().createObjectNode(); modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processDefinition.getName()); modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, modelData.getVersion()); modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, processDefinition.getDescription()); modelData.setMetaInfo(modelObjectNode.toString()); repositoryService.saveModel(modelData); repositoryService.addModelEditorSource(modelData.getId(), modelNode.toString().getBytes("utf-8")); return modelData; }
Example #10
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 #11
Source File: ImportExportTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void testConvertXMLToModel() throws Exception { BpmnModel bpmnModel = readXMLFile(); bpmnModel = exportAndReadXMLFile(bpmnModel); byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel); processEngine.getRepositoryService().createDeployment().name("test1").addString("test1.bpmn20.xml", new String(xml)) .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE) .deploy(); String processInstanceKey = runtimeService.startProcessInstanceByKey("process").getId(); Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstanceKey).messageEventSubscriptionName("InterruptMessage").singleResult(); assertNotNull(execution); }
Example #12
Source File: EventJavaTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void testStartEventWithExecutionListener() throws Exception { BpmnModel bpmnModel = new BpmnModel(); Process process = new Process(); process.setId("simpleProcess"); process.setName("Very simple process"); bpmnModel.getProcesses().add(process); StartEvent startEvent = new StartEvent(); startEvent.setId("startEvent1"); TimerEventDefinition timerDef = new TimerEventDefinition(); timerDef.setTimeDuration("PT5M"); startEvent.getEventDefinitions().add(timerDef); ActivitiListener listener = new ActivitiListener(); listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION); listener.setImplementation("${test}"); listener.setEvent("end"); startEvent.getExecutionListeners().add(listener); process.addFlowElement(startEvent); UserTask task = new UserTask(); task.setId("reviewTask"); task.setAssignee("kermit"); process.addFlowElement(task); SequenceFlow flow1 = new SequenceFlow(); flow1.setId("flow1"); flow1.setSourceRef("startEvent1"); flow1.setTargetRef("reviewTask"); process.addFlowElement(flow1); EndEvent endEvent = new EndEvent(); endEvent.setId("endEvent1"); process.addFlowElement(endEvent); byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel); new BpmnXMLConverter().validateModel(new InputStreamSource(new ByteArrayInputStream(xml))); Deployment deployment = repositoryService.createDeployment().name("test").addString("test.bpmn20.xml", new String(xml)) .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE) .deploy(); repositoryService.deleteDeployment(deployment.getId()); }
Example #13
Source File: LaneExtensionTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Test @Deployment public void testLaneExtensionElement() { ProcessDefinition processDefinition = activitiRule.getRepositoryService().createProcessDefinitionQuery() .processDefinitionKey("swimlane-extension").singleResult(); BpmnModel bpmnModel = activitiRule.getRepositoryService().getBpmnModel(processDefinition.getId()); byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel); System.out.println(new String(xml)); Process bpmnProcess = bpmnModel.getMainProcess(); for (Lane l : bpmnProcess.getLanes()) { Map<String, List<ExtensionElement>> extensions = l.getExtensionElements(); Assert.assertTrue(extensions.size() > 0); } }
Example #14
Source File: AbstractConverterTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected BpmnModel exportAndReadXMLFile(BpmnModel bpmnModel) throws Exception { byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel); System.out.println("xml " + new String(xml, "UTF-8")); XMLInputFactory xif = XMLInputFactory.newInstance(); InputStreamReader in = new InputStreamReader(new ByteArrayInputStream(xml), "UTF-8"); XMLStreamReader xtr = xif.createXMLStreamReader(in); return new BpmnXMLConverter().convertToBpmnModel(xtr); }
Example #15
Source File: AbstractConverterTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected BpmnModel readXMLFile() throws Exception { InputStream xmlStream = this.getClass().getClassLoader().getResourceAsStream(getResource()); XMLInputFactory xif = XMLInputFactory.newInstance(); InputStreamReader in = new InputStreamReader(xmlStream, "UTF-8"); XMLStreamReader xtr = xif.createXMLStreamReader(in); return new BpmnXMLConverter().convertToBpmnModel(xtr); }
Example #16
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 #17
Source File: ChineseConverterTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected void deployProcess(BpmnModel bpmnModel) { byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel); try { Deployment deployment = processEngine.getRepositoryService().createDeployment().name("test").addString("test.bpmn20.xml", new String(xml)).deploy(); processEngine.getRepositoryService().deleteDeployment(deployment.getId()); } finally { processEngine.close(); } }
Example #18
Source File: ModelUtils.java From openwebflow with BSD 2-Clause "Simplified" License | 5 votes |
public static void importModel(RepositoryService repositoryService, File modelFile) throws IOException, XMLStreamException { InputStreamReader reader = new InputStreamReader(new FileInputStream(modelFile), "utf-8"); String fileContent = IOUtils.readStringAndClose(reader, (int) modelFile.length()); BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(new StringStreamSourceEx(fileContent), false, false); String processName = bpmnModel.getMainProcess().getName(); if (processName == null || processName.isEmpty()) { processName = bpmnModel.getMainProcess().getId(); } Model modelData = repositoryService.newModel(); ObjectNode modelObjectNode = new ObjectMapper().createObjectNode(); modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processName); modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1); modelData.setMetaInfo(modelObjectNode.toString()); modelData.setName(processName); modelData.setKey(modelFile.getName()); repositoryService.saveModel(modelData); repositoryService.addModelEditorSource(modelData.getId(), fileContent.getBytes("utf-8")); Logger.getLogger(ModelUtils.class) .info(String.format("importing model file: %s", modelFile.getCanonicalPath())); }
Example #19
Source File: DefaultProcessValidatorTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Test public void testWarningError() throws UnsupportedEncodingException, XMLStreamException { String flowWithoutConditionNoDefaultFlow = "<?xml version='1.0' encoding='UTF-8'?>" + "<definitions id='definitions' xmlns='http://www.omg.org/spec/BPMN/20100524/MODEL' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:activiti='http://activiti.org/bpmn' targetNamespace='Examples'>" + " <process id='exclusiveGwDefaultSequenceFlow'> " + " <startEvent id='theStart' /> " + " <sequenceFlow id='flow1' sourceRef='theStart' targetRef='exclusiveGw' /> " + " <exclusiveGateway id='exclusiveGw' name='Exclusive Gateway' /> " + // no default = "flow3" !! " <sequenceFlow id='flow2' sourceRef='exclusiveGw' targetRef='theTask1'> " + " <conditionExpression xsi:type='tFormalExpression'>${input == 1}</conditionExpression> " + " </sequenceFlow> " + " <sequenceFlow id='flow3' sourceRef='exclusiveGw' targetRef='theTask2'/> " + // one // would // be // OK " <sequenceFlow id='flow4' sourceRef='exclusiveGw' targetRef='theTask2'/> " + // but // two // unconditional // not! " <userTask id='theTask1' name='Input is one' /> " + " <userTask id='theTask2' name='Default input' /> " + " </process>" + "</definitions>"; XMLInputFactory xif = XMLInputFactory.newInstance(); InputStreamReader in = new InputStreamReader(new ByteArrayInputStream(flowWithoutConditionNoDefaultFlow.getBytes()), "UTF-8"); XMLStreamReader xtr = xif.createXMLStreamReader(in); BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr); Assert.assertNotNull(bpmnModel); List<ValidationError> allErrors = processValidator.validate(bpmnModel); Assert.assertEquals(1, allErrors.size()); Assert.assertTrue(allErrors.get(0).isWarning()); }
Example #20
Source File: DeploymentController.java From activiti-in-action-codes with Apache License 2.0 | 5 votes |
/** * 转换流程定义为模型 * @param processDefinitionId * @return * @throws UnsupportedEncodingException * @throws XMLStreamException */ @RequestMapping(value = "/process/convert-to-model/{processDefinitionId}") public String convertToModel(@PathVariable("processDefinitionId") String processDefinitionId) throws UnsupportedEncodingException, XMLStreamException { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery() .processDefinitionId(processDefinitionId).singleResult(); InputStream bpmnStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName()); XMLInputFactory xif = XMLInputFactory.newInstance(); InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8"); XMLStreamReader xtr = xif.createXMLStreamReader(in); BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr); BpmnJsonConverter converter = new BpmnJsonConverter(); ObjectNode modelNode = converter.convertToJson(bpmnModel); Model modelData = repositoryService.newModel(); modelData.setKey(processDefinition.getKey()); modelData.setName(processDefinition.getResourceName()); modelData.setCategory(processDefinition.getDeploymentId()); ObjectNode modelObjectNode = new ObjectMapper().createObjectNode(); modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processDefinition.getName()); modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1); modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, processDefinition.getDescription()); modelData.setMetaInfo(modelObjectNode.toString()); repositoryService.saveModel(modelData); repositoryService.addModelEditorSource(modelData.getId(), modelNode.toString().getBytes("utf-8")); return "redirect:/chapter20/model/list"; }
Example #21
Source File: BpmnModelTest.java From activiti-in-action-codes with Apache License 2.0 | 5 votes |
/** * 把XML转换成BpmnModel对象 * @throws Exception */ @Test @Deployment(resources = "chapter6/dynamic-form/leave.bpmn") public void testXmlToBpmnModel() throws Exception { // 验证是否部署成功 long count = repositoryService.createProcessDefinitionQuery().count(); assertEquals(1, count); // 根据流程定义获取XML资源文件流对象 /*ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("leave").singleResult(); String resourceName = processDefinition.getResourceName(); InputStream inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);*/ // 从classpath中获取 InputStream inputStream = getClass().getClassLoader().getResourceAsStream("chapter6/dynamic-form/leave.bpmn"); // 创建转换对象 BpmnXMLConverter converter = new BpmnXMLConverter(); // 创建XMLStreamReader读取XML资源 XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory.createXMLStreamReader(inputStream); // 把XML转换成BpmnModel对象 BpmnModel bpmnModel = converter.convertToBpmnModel(reader); // 验证BpmnModel对象不为空 assertNotNull(bpmnModel); Process process = bpmnModel.getMainProcess(); assertEquals("leave", process.getId()); }
Example #22
Source File: EventJavaTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void testStartEventWithExecutionListener() throws Exception { BpmnModel bpmnModel = new BpmnModel(); Process process = new Process(); process.setId("simpleProcess"); process.setName("Very simple process"); bpmnModel.getProcesses().add(process); StartEvent startEvent = new StartEvent(); startEvent.setId("startEvent1"); TimerEventDefinition timerDef = new TimerEventDefinition(); timerDef.setTimeDuration("PT5M"); startEvent.getEventDefinitions().add(timerDef); ActivitiListener listener = new ActivitiListener(); listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION); listener.setImplementation("${test}"); listener.setEvent("end"); startEvent.getExecutionListeners().add(listener); process.addFlowElement(startEvent); UserTask task = new UserTask(); task.setId("reviewTask"); task.setAssignee("kermit"); process.addFlowElement(task); SequenceFlow flow1 = new SequenceFlow(); flow1.setId("flow1"); flow1.setSourceRef("startEvent1"); flow1.setTargetRef("reviewTask"); process.addFlowElement(flow1); EndEvent endEvent = new EndEvent(); endEvent.setId("endEvent1"); process.addFlowElement(endEvent); byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel); new BpmnXMLConverter().validateModel(new InputStreamSource(new ByteArrayInputStream(xml))); Deployment deployment = repositoryService.createDeployment().name("test").addString("test.bpmn20.xml", new String(xml)).deploy(); repositoryService.deleteDeployment(deployment.getId()); }
Example #23
Source File: LaneExtensionTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Test @Deployment public void testLaneExtensionElement() { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("swimlane-extension").singleResult(); BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId()); byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel); System.out.println(new String(xml)); Process bpmnProcess = bpmnModel.getMainProcess(); for (Lane l : bpmnProcess.getLanes()) { Map<String, List<ExtensionElement>> extensions = l.getExtensionElements(); Assert.assertTrue(extensions.size() > 0); } }
Example #24
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 #25
Source File: BpmnImageTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected BpmnModel getBpmnModel(String file) throws Exception { BpmnXMLConverter xmlConverter = new BpmnXMLConverter(); InputStream xmlStream = this.getClass().getClassLoader().getResourceAsStream(file); XMLInputFactory xif = XMLInputFactory.newInstance(); InputStreamReader in = new InputStreamReader(xmlStream); XMLStreamReader xtr = xif.createXMLStreamReader(in); BpmnModel bpmnModel = xmlConverter.convertToBpmnModel(xtr); return bpmnModel; }
Example #26
Source File: DeploymentManager.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public BpmnModel getBpmnModelById(String processDefinitionId) { if (processDefinitionId == null) { throw new ActivitiIllegalArgumentException("Invalid process definition id : null"); } // first try the cache BpmnModel bpmnModel = bpmnModelCache.get(processDefinitionId); if (bpmnModel == null) { ProcessDefinition processDefinition = findDeployedProcessDefinitionById(processDefinitionId); if (processDefinition == null) { throw new ActivitiObjectNotFoundException("no deployed process definition found with id '" + processDefinitionId + "'", ProcessDefinition.class); } // Fetch the resource String resourceName = processDefinition.getResourceName(); ResourceEntity resource = Context.getCommandContext().getResourceEntityManager() .findResourceByDeploymentIdAndResourceName(processDefinition.getDeploymentId(), resourceName); if (resource == null) { if (Context.getCommandContext().getDeploymentEntityManager().findDeploymentById(processDefinition.getDeploymentId()) == null) { throw new ActivitiObjectNotFoundException("deployment for process definition does not exist: " + processDefinition.getDeploymentId(), Deployment.class); } else { throw new ActivitiObjectNotFoundException("no resource found with name '" + resourceName + "' in deployment '" + processDefinition.getDeploymentId() + "'", InputStream.class); } } // Convert the bpmn 2.0 xml to a bpmn model BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter(); bpmnModel = bpmnXMLConverter.convertToBpmnModel(new BytesStreamSource(resource.getBytes()), false, false); bpmnModelCache.add(processDefinition.getId(), bpmnModel); } return bpmnModel; }
Example #27
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 #28
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(); } }
Example #29
Source File: ModelerController.java From lemon with Apache License 2.0 | 4 votes |
@RequestMapping("modeler-deploy") public String deploy(@RequestParam("id") String id, org.springframework.ui.Model theModel) throws Exception { String tenantId = tenantHolder.getTenantId(); RepositoryService repositoryService = processEngine .getRepositoryService(); Model modelData = repositoryService.getModel(id); byte[] bytes = repositoryService .getModelEditorSource(modelData.getId()); if (bytes == null) { theModel.addAttribute("message", "模型数据为空,请先设计流程并成功保存,再进行发布。"); return "modeler/failure"; } JsonNode modelNode = (JsonNode) new ObjectMapper().readTree(bytes); 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, "UTF-8")) .tenantId(tenantId).deploy(); modelData.setDeploymentId(deployment.getId()); repositoryService.saveModel(modelData); List<ProcessDefinition> processDefinitions = repositoryService .createProcessDefinitionQuery() .deploymentId(deployment.getId()).list(); for (ProcessDefinition processDefinition : processDefinitions) { processEngine.getManagementService().executeCommand( new SyncProcessCmd(processDefinition.getId())); } return "redirect:/modeler/modeler-list.do"; }
Example #30
Source File: ChineseConverterTest.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
protected BpmnModel exportAndReadXMLFile(BpmnModel bpmnModel) throws Exception { byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel, processEngineConfiguration.getXmlEncoding()); StreamSource xmlSource = new InputStreamSource(new ByteArrayInputStream(xml)); BpmnModel parsedModel = new BpmnXMLConverter().convertToBpmnModel(xmlSource, false, false, processEngineConfiguration.getXmlEncoding()); return parsedModel; }