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


Java BpmnJsonConverter类代码示例

本文整理汇总了Java中org.flowable.editor.language.json.converter.BpmnJsonConverter的典型用法代码示例。如果您正苦于以下问题:Java BpmnJsonConverter类的具体用法?Java BpmnJsonConverter怎么用?Java BpmnJsonConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BpmnJsonConverter类属于org.flowable.editor.language.json.converter包,在下文中一共展示了BpmnJsonConverter类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getModelXml

import org.flowable.editor.language.json.converter.BpmnJsonConverter; //导入依赖的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.editor.language.json.converter.BpmnJsonConverter; //导入依赖的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: validate

import org.flowable.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
@RequestMapping(value = "/models/validate",method = RequestMethod.POST,consumes = MediaType.APPLICATION_JSON_VALUE)
public List<ValidationError> validate(@RequestBody JsonNode body){
    BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(body);
    ProcessValidator validator = new ProcessValidatorFactory().createDefaultProcessValidator();
    List<ValidationError> errors = validator.validate(bpmnModel);
    return errors;
}
 
开发者ID:wengwh,项目名称:plumdo-work,代码行数:8,代码来源:ModelValidationResource.java

示例4: execute

import org.flowable.editor.language.json.converter.BpmnJsonConverter; //导入依赖的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

示例5: validate

import org.flowable.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
@RequestMapping(value = "/rest/model/validate",method = RequestMethod.POST,consumes = MediaType.APPLICATION_JSON_VALUE)
public List<ValidationError> validate(@RequestBody JsonNode body){
    BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(body);
    ProcessValidator validator = new ProcessValidatorFactory().createDefaultProcessValidator();
    List<ValidationError> errors = validator.validate(bpmnModel);
    return errors;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:8,代码来源:ModelValidationRestResource.java

示例6: processDefinitionGetModel

import org.flowable.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
@RequestMapping(value = "/process-definition/{processDefinitionId}/getModel", method = RequestMethod.GET, produces = "application/json", name="流程定义获取对应模型")
public ModelResponse processDefinitionGetModel(@PathVariable String processDefinitionId) {
	ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
	try {
		Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(processDefinition.getDeploymentId()).singleResult();
		
		if(deployment == null){
			throw new FlowableObjectNotFoundException("Could not find a process deployment with id '"+ processDefinition.getDeploymentId() + "'.",Deployment.class);
		}
		Model modelData = null;
		
		if(deployment.getCategory()!=null){
			modelData = repositoryService.getModel(deployment.getCategory());
		}
		//如果不存在,创建对应模型
		if(modelData == null){
			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);
			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(managementService.executeCommand(new GetDeploymentProcessDiagramCmd(processDefinitionId))));

			repositoryService.setDeploymentCategory(processDefinition.getDeploymentId(), modelData.getId());
		}
		return restResponseFactory.createModelResponse(modelData);
		
	} catch (Exception e) {
		throw new FlowableException("Error  process-definition get model", e);
	}
}
 
开发者ID:wengwh,项目名称:plumdo-work,代码行数:49,代码来源:ProcessDefinitionGetModelResource.java

示例7: saveModel

import org.flowable.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
@RequestMapping(value = "/models/{modelId}/editor", method = {RequestMethod.POST}, name="模型设计器保存模型")
@ResponseStatus(value = HttpStatus.OK)
@Transactional(propagation = Propagation.REQUIRED)
public void saveModel(@PathVariable String modelId,@RequestBody ModelEditorJsonRequest values) {
	try {
		Model model = getModelFromRequest(modelId);

		ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
		modelJson.put(MODEL_NAME, values.getName());
		modelJson.put(MODEL_DESCRIPTION, values.getDescription());
		model.setMetaInfo(modelJson.toString());
		model.setName(values.getName());
		if(model.getDeploymentId()!=null){
			model.setDeploymentId(null);
		}
		if(values.isAddVersion()){
			model.setVersion(model.getVersion()+1);
		}
		
		repositoryService.saveModel(model);

		repositoryService.addModelEditorSource(model.getId(), values.getJson_xml().getBytes("utf-8"));

		ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(values.getJson_xml().getBytes("utf-8"));
		
		BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);

		ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
		InputStream resource = diagramGenerator.generateDiagram(bpmnModel,"png", 
					Collections.<String> emptyList(), Collections.<String> emptyList(), 
					processEngineConfiguration.getActivityFontName(), 
					processEngineConfiguration.getLabelFontName(), 
					processEngineConfiguration.getAnnotationFontName(),
					processEngineConfiguration.getClassLoader(), 1.0);

		repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(resource));
		
	} catch (Exception e) {
		LOGGER.error("Error saving model", e);
		throw new FlowableException("Error saving model", e);
	}
	
}
 
开发者ID:wengwh,项目名称:plumdo-work,代码行数:44,代码来源:ModelEditorResource.java

示例8: readJsonFile

import org.flowable.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
protected BpmnModel readJsonFile() throws Exception {
    InputStream jsonStream = this.getClass().getClassLoader().getResourceAsStream(getResource());
    JsonNode modelNode = new ObjectMapper().readTree(jsonStream);
    BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
    return bpmnModel;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:7,代码来源:AbstractConverterTest.java

示例9: convertToJsonAndBack

import org.flowable.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
protected BpmnModel convertToJsonAndBack(BpmnModel bpmnModel) {
    ObjectNode modelNode = new BpmnJsonConverter().convertToJson(bpmnModel);
    bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
    return bpmnModel;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:6,代码来源:AbstractConverterTest.java

示例10: importDefinition

import org.flowable.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
@Override
public void importDefinition(final String key, final WorkflowDefinitionFormat format, final String definition) {
    ProcessDefinition procDef = getProcessDefinitionByKey(key);
    String resourceName = procDef == null ? key + ".bpmn20.xml" : procDef.getResourceName();
    Deployment deployment;
    switch (format) {
        case JSON:
            JsonNode definitionNode;
            try {
                definitionNode = OBJECT_MAPPER.readTree(definition);
                if (definitionNode.has(MODEL_DATA_JSON_MODEL)) {
                    definitionNode = definitionNode.get(MODEL_DATA_JSON_MODEL);
                }
                if (!definitionNode.has(BpmnJsonConverter.EDITOR_CHILD_SHAPES)) {
                    throw new IllegalArgumentException(
                            "Could not find JSON node " + BpmnJsonConverter.EDITOR_CHILD_SHAPES);
                }

                BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(definitionNode);
                deployment = FlowableDeployUtils.deployDefinition(
                        engine,
                        resourceName,
                        new BpmnXMLConverter().convertToXML(bpmnModel));
            } catch (Exception e) {
                throw new WorkflowException("While creating or updating process " + key, e);
            }
            break;

        case XML:
        default:
            deployment = FlowableDeployUtils.deployDefinition(
                    engine,
                    resourceName,
                    definition.getBytes());
    }

    procDef = getProcessDefinitionByDeploymentId(deployment.getId());
    if (!key.equals(procDef.getKey())) {
        throw new WorkflowException("Mismatching key: expected " + key + ", found " + procDef.getKey());
    }
    FlowableDeployUtils.deployModel(engine, procDef);
}
 
开发者ID:apache,项目名称:syncope,代码行数:43,代码来源:FlowableUserWorkflowAdapter.java


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