Java Code Examples for org.activiti.bpmn.converter.BpmnXMLConverter#convertToBpmnModel()
The following examples show how to use
org.activiti.bpmn.converter.BpmnXMLConverter#convertToBpmnModel() .
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: 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 2
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 3
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 4
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 5
Source File: BpmnParse.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
public BpmnParse execute() { try { ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); BpmnXMLConverter converter = new BpmnXMLConverter(); boolean enableSafeBpmnXml = false; String encoding = null; if (processEngineConfiguration != null) { enableSafeBpmnXml = processEngineConfiguration.isEnableSafeBpmnXml(); encoding = processEngineConfiguration.getXmlEncoding(); } if (encoding != null) { bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml, encoding); } else { bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml); } // XSD validation goes first, then process/semantic validation if (validateProcess) { ProcessValidator processValidator = processEngineConfiguration.getProcessValidator(); if (processValidator == null) { LOGGER.warn("Process should be validated, but no process validator is configured on the process engine configuration!"); } else { List<ValidationError> validationErrors = processValidator.validate(bpmnModel); if(validationErrors != null && !validationErrors.isEmpty()) { StringBuilder warningBuilder = new StringBuilder(); StringBuilder errorBuilder = new StringBuilder(); for (ValidationError error : validationErrors) { if (error.isWarning()) { warningBuilder.append(error.toString()); warningBuilder.append("\n"); } else { errorBuilder.append(error.toString()); errorBuilder.append("\n"); } } // Throw exception if there is any error if (errorBuilder.length() > 0) { throw new ActivitiException("Errors while parsing:\n" + errorBuilder.toString()); } // Write out warnings (if any) if (warningBuilder.length() > 0) { LOGGER.warn("Following warnings encountered during process validation: " + warningBuilder.toString()); } } } } bpmnModel.setEventSupport(new ActivitiEventSupport()); // Validation successful (or no validation) createImports(); createItemDefinitions(); createMessages(); createOperations(); transformProcessDefinitions(); } catch (Exception e) { if (e instanceof ActivitiException) { throw (ActivitiException) e; } else if (e instanceof XMLException) { throw (XMLException) e; } else { throw new ActivitiException("Error parsing XML", e); } } return this; }
Example 6
Source File: BpmnParse.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
public BpmnParse execute() { try { ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); BpmnXMLConverter converter = new BpmnXMLConverter(); boolean enableSafeBpmnXml = false; String encoding = null; if (processEngineConfiguration != null) { enableSafeBpmnXml = processEngineConfiguration.isEnableSafeBpmnXml(); encoding = processEngineConfiguration.getXmlEncoding(); } if (encoding != null) { bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml, encoding); } else { bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml); } // XSD validation goes first, then process/semantic validation if (validateProcess) { ProcessValidator processValidator = processEngineConfiguration.getProcessValidator(); if (processValidator == null) { LOGGER.warn("Process should be validated, but no process validator is configured on the process engine configuration!"); } else { List<ValidationError> validationErrors = processValidator.validate(bpmnModel); if (validationErrors != null && !validationErrors.isEmpty()) { StringBuilder warningBuilder = new StringBuilder(); StringBuilder errorBuilder = new StringBuilder(); for (ValidationError error : validationErrors) { if (error.isWarning()) { warningBuilder.append(error.toString()); warningBuilder.append("\n"); } else { errorBuilder.append(error.toString()); errorBuilder.append("\n"); } } // Throw exception if there is any error if (errorBuilder.length() > 0) { throw new ActivitiException("Errors while parsing:\n" + errorBuilder.toString()); } // Write out warnings (if any) if (warningBuilder.length() > 0) { LOGGER.warn("Following warnings encountered during process validation: " + warningBuilder.toString()); } } } } bpmnModel.setSourceSystemId(sourceSystemId); bpmnModel.setEventSupport(new ActivitiEventSupport()); // Validation successful (or no validation) // Attach logic to the processes (eg. map ActivityBehaviors to bpmn model elements) applyParseHandlers(); // Finally, process the diagram interchange info processDI(); } catch (Exception e) { if (e instanceof ActivitiException) { throw (ActivitiException) e; } else if (e instanceof XMLException) { throw (XMLException) e; } else { throw new ActivitiException("Error parsing XML", e); } } return this; }