当前位置: 首页>>代码示例>>Java>>正文


Java BpmnXMLConverter类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:wengwh,项目名称:plumdo-work,代码行数:18,代码来源:ModelXmlResource.java

示例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);
	}
}
 
开发者ID:wengwh,项目名称:plumdo-work,代码行数:35,代码来源:ProcessDefinitionToModelResource.java

示例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;
}
 
开发者ID:wengwh,项目名称:plumdo-work,代码行数:41,代码来源:DeployModelCmd.java

示例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);
    }
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:15,代码来源:LaneExtensionTest.java

示例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());
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:40,代码来源:EventJavaTest.java

示例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);
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:16,代码来源:ImportExportTest.java

示例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());
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:30,代码来源:DefaultProcessValidatorTest.java

示例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();
    }
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:14,代码来源:ChineseConverterTest.java

示例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;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:12,代码来源:DeploymentBuilderImpl.java

示例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);
    }
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:13,代码来源:LaneExtensionTest.java

示例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());
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:38,代码来源:EventJavaTest.java

示例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());
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:30,代码来源:DefaultProcessValidatorTest.java

示例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();
    }
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:10,代码来源:ChineseConverterTest.java

示例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;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:36,代码来源:DeploymentManager.java

示例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;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:12,代码来源:DeploymentBuilderImpl.java


注:本文中的org.flowable.bpmn.converter.BpmnXMLConverter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。