本文整理汇总了Java中org.flowable.bpmn.converter.BpmnXMLConverter类的典型用法代码示例。如果您正苦于以下问题:Java BpmnXMLConverter类的具体用法?Java BpmnXMLConverter怎么用?Java BpmnXMLConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BpmnXMLConverter类属于org.flowable.bpmn.converter包,在下文中一共展示了BpmnXMLConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getModelXml
import org.flowable.bpmn.converter.BpmnXMLConverter; //导入依赖的package包/类
@RequestMapping(value = "/model/{modelId}/xml", method = RequestMethod.GET, name="获取模型XML")
public ResponseEntity<byte[]> getModelXml(@PathVariable String modelId) {
Model model = getModelFromRequest(modelId);
try {
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(model.getId()));
BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);
ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.TEXT_XML);
return new ResponseEntity<byte[]>(IOUtils.toByteArray(in), responseHeaders,HttpStatus.OK);
} catch (Exception e) {
throw new FlowableException("Error converting resource stream", e);
}
}
示例2: processDefinitionToModel
import org.flowable.bpmn.converter.BpmnXMLConverter; //导入依赖的package包/类
@RequestMapping(value = "/process-definition/{processDefinitionId}/toModel", method = RequestMethod.PUT, produces = "application/json", name="流程定义转换模型")
@ResponseStatus(value = HttpStatus.OK)
@Transactional(propagation = Propagation.REQUIRED)
public ModelResponse processDefinitionToModel(@PathVariable String processDefinitionId) {
ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
try {
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.getName());
modelData.setCategory(processDefinition.getCategory());
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"));
repositoryService.addModelEditorSourceExtra(modelData.getId(),IOUtils.toByteArray(repositoryService.getProcessDiagram(processDefinition.getId())));
return restResponseFactory.createModelResponse(modelData);
} catch (Exception e) {
throw new FlowableException("Error converting process-definition to model", e);
}
}
示例3: execute
import org.flowable.bpmn.converter.BpmnXMLConverter; //导入依赖的package包/类
public Deployment execute(CommandContext commandContext) {
Deployment deployment = null;
RepositoryService repositoryService = commandContext.getProcessEngineConfiguration().getRepositoryService();
Model model = repositoryService.getModel(modelId);
if(model == null) {
throw new FlowableObjectNotFoundException("Could not find a model with id '" + modelId + "'.",Model.class);
}
byte[] editorSource = commandContext.getModelEntityManager().findEditorSourceByModelId(modelId);
if(editorSource == null) {
throw new FlowableObjectNotFoundException("Model with id '" + modelId + "' does not have source available.", String.class);
}
try {
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(editorSource);
BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(bpmnModel);
String fileName = model.getId()+".bpmn20.xml";
ByteArrayInputStream bis = new ByteArrayInputStream(bpmnBytes);
deploymentBuilder.addInputStream(fileName, bis);
deploymentBuilder.name(fileName);
//modelId设置为部署的分类字段作为后续关联的需要
deploymentBuilder.category(model.getId());
if(model.getTenantId() != null) {
deploymentBuilder.tenantId(model.getTenantId());
}
deployment = deploymentBuilder.deploy();
//设置模型的部署ID
model.setDeploymentId(deployment.getId());
} catch (Exception e) {
if (e instanceof FlowableException) {
throw (FlowableException) e;
}
throw new FlowableException(e.getMessage(), e);
}
return deployment;
}
示例4: testLaneExtensionElement
import org.flowable.bpmn.converter.BpmnXMLConverter; //导入依赖的package包/类
@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);
}
}
示例5: testStartEventWithExecutionListener
import org.flowable.bpmn.converter.BpmnXMLConverter; //导入依赖的package包/类
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);
FlowableListener listener = new FlowableListener();
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_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
.deploy();
repositoryService.deleteDeployment(deployment.getId());
}
示例6: testConvertXMLToModel
import org.flowable.bpmn.converter.BpmnXMLConverter; //导入依赖的package包/类
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_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
.deploy();
String processInstanceKey = runtimeService.startProcessInstanceByKey("process").getId();
Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstanceKey).messageEventSubscriptionName("InterruptMessage").singleResult();
assertNotNull(execution);
}
示例7: testWarningError
import org.flowable.bpmn.converter.BpmnXMLConverter; //导入依赖的package包/类
@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());
}
示例8: deployProcess
import org.flowable.bpmn.converter.BpmnXMLConverter; //导入依赖的package包/类
protected void deployProcess(BpmnModel bpmnModel) {
byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel);
try {
Deployment deployment = processEngine.getRepositoryService().createDeployment()
.name("test")
.deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
.addString("test.bpmn20.xml", new String(xml))
.deploy();
processEngine.getRepositoryService().deleteDeployment(deployment.getId());
} finally {
processEngine.close();
}
}
示例9: addBpmnModel
import org.flowable.bpmn.converter.BpmnXMLConverter; //导入依赖的package包/类
@Override
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 FlowableException("Error while transforming BPMN model to xml: not UTF-8 encoded", e);
}
return this;
}
示例10: testLaneExtensionElement
import org.flowable.bpmn.converter.BpmnXMLConverter; //导入依赖的package包/类
@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);
}
}
示例11: testStartEventWithExecutionListener
import org.flowable.bpmn.converter.BpmnXMLConverter; //导入依赖的package包/类
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);
FlowableListener listener = new FlowableListener();
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());
}
示例12: testWarningError
import org.flowable.bpmn.converter.BpmnXMLConverter; //导入依赖的package包/类
@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());
}
示例13: deployProcess
import org.flowable.bpmn.converter.BpmnXMLConverter; //导入依赖的package包/类
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();
}
}
示例14: getBpmnModelById
import org.flowable.bpmn.converter.BpmnXMLConverter; //导入依赖的package包/类
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;
}
示例15: addBpmnModel
import org.flowable.bpmn.converter.BpmnXMLConverter; //导入依赖的package包/类
@Override
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;
}