• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java BpmnJsonConverter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: deploy

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
/**
 * 根据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:/workflow/model/list";
}
 
开发者ID:batizhao,项目名称:microservice,代码行数:22,代码来源:ModelController.java


示例2: deployModel

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
@PutMapping("{modelId}/deploy")
public ResponseMessage 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");
}
 
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:17,代码来源:FlowableModelManagerController.java


示例3: convertToModel

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
/***
 * 流程定义转换Model
 * @param processDefinitionId
 * @return
 * @throws UnsupportedEncodingException
 * @throws XMLStreamException
 */
@PutMapping(value = "/convert-to-model/{processDefinitionId}")
public ResponseMessage<Map<String, Object>> 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(Collections.singletonMap(MODEL_ID, modelData.getId()));
}
 
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:41,代码来源:FlowableDeploymentController.java


示例4: deploy

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
/**
	 * 根据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;
	}
 
开发者ID:EleTeam,项目名称:Shop-for-JavaWeb,代码行数:38,代码来源:ActModelService.java


示例5: export

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
/**
 * 导出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);
	}
	
}
 
开发者ID:EleTeam,项目名称:Shop-for-JavaWeb,代码行数:25,代码来源:ActModelService.java


示例6: deploy

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
/**
 * 根据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";
}
 
开发者ID:shawn-gogh,项目名称:myjavacode,代码行数:22,代码来源:ModelController.java


示例7: export

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
/**
 * 导出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);
    }
}
 
开发者ID:shawn-gogh,项目名称:myjavacode,代码行数:23,代码来源:ModelController.java


示例8: xml2json

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
@RequestMapping("xml2json")
public String xml2json(
        @RequestParam("processDefinitionId") String processDefinitionId)
        throws Exception {
    RepositoryService repositoryService = processEngine
            .getRepositoryService();

    ProcessDefinition processDefinition = repositoryService
            .getProcessDefinition(processDefinitionId);

    Model model = repositoryService.newModel();
    model.setName(processDefinition.getName());
    model.setDeploymentId(processDefinition.getDeploymentId());
    repositoryService.saveModel(model);

    BpmnModel bpmnModel = repositoryService
            .getBpmnModel(processDefinitionId);
    ObjectNode objectNode = new BpmnJsonConverter()
            .convertToJson(bpmnModel);

    String json = objectNode.toString();

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

    return "redirect:/modeler/modeler-list.do";
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:28,代码来源:ModelerController.java


示例9: export

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
/**
 * 导出model对象为指定类型
 *
 * @param modelId 模型ID
 * @param type    导出文件类型(bpmn\json)
 */
@RequestMapping(value = "export/{modelId}/{type}")
public void export(@PathVariable("modelId") String modelId,
                   @PathVariable("type") String type,
                   HttpServletResponse response) {
    try {
        Model modelData = repositoryService.getModel(modelId);
        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) {
            response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
            response.getOutputStream().println("no main process, can't export for type: " + type);
            response.flushBuffer();
            return;
        }

        String filename = "";
        byte[] exportBytes = null;

        String mainProcessId = bpmnModel.getMainProcess().getId();

        if (type.equals("bpmn")) {

            BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
            exportBytes = xmlConverter.convertToXML(bpmnModel);

            filename = mainProcessId + ".bpmn20.xml";
        } else if (type.equals("json")) {

            exportBytes = modelEditorSource;
            filename = mainProcessId + ".json";

        }

        ByteArrayInputStream in = new ByteArrayInputStream(exportBytes);
        IOUtils.copy(in, response.getOutputStream());

        response.setHeader("Content-Disposition", "attachment; filename=" + filename);
        response.flushBuffer();
    } catch (Exception e) {
        logger.error("导出model的xml文件失败:modelId={}, type={}", modelId, type, e);
    }
}
 
开发者ID:batizhao,项目名称:microservice,代码行数:54,代码来源:ModelController.java


示例10: convertToModel

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
/**
 * 将部署的流程转换为模型
 * @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;
}
 
开发者ID:EleTeam,项目名称:Shop-for-JavaWeb,代码行数:39,代码来源:ActProcessService.java


示例11: jsonToModelTest

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
@Test
public void jsonToModelTest() throws Exception {

	BpmnModel bpmnModel = buildModel();
	BpmnJsonConverter jsonConverter = new BpmnJsonExConverter();
	ObjectNode objectNode = jsonConverter.convertToJson(bpmnModel);
	System.out.println(objectNode.toString());

	bpmnModel = jsonConverter.convertToBpmnModel(objectNode);
	BpmnXMLConverter converter = new BpmnXMLConverter();
	String xml = new String(converter.convertToXML(bpmnModel), "UTF-8");

	System.out.println(xml);
}
 
开发者ID:KayuraTeam,项目名称:kayura-activiti,代码行数:15,代码来源:BpmnModelTest.java


示例12: exportXml

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
/**
 * 导出model的xml文件
 */
@RequestMapping(value = "/model/export/xml/{modelId}", method = RequestMethod.GET)
public void exportXml(@PathVariable("modelId") String modelId, HttpServletResponse response) {
    try {
        Model modelData = repositoryService.getModel(modelId);
        BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
        JsonNode editorNode = objectMapper.readTree(repositoryService.getModelEditorSource(modelData.getId()));
        BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
        BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
        //没有xml
        if (bpmnModel.getProcesses().isEmpty()) {
            response.setCharacterEncoding("utf-8");
            response.getWriter().print("<script>modals.error('xml文件不存在,生成错误');</script>");
            response.flushBuffer();
            return;
        }
        byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);

        ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
        IOUtils.copy(in, response.getOutputStream());
        String filename = bpmnModel.getMainProcess().getId() + ".bpmn20.model.xml";
        response.setHeader("Content-Disposition", "attachment; filename=" + filename);
        response.flushBuffer();
    } catch (Exception e) {
        LOGGER.error("导出model的xml文件失败:modelId={}", modelId, e);

    }
}
 
开发者ID:bill1012,项目名称:AdminEAP,代码行数:31,代码来源:ModelOperationController.java


示例13: resourceExist

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
/**
 * 校验资源文件是否存在
 *
 * @param type    xml image 类型
 * @param modelId 模型id
 * @return
 * @throws IOException
 */
@RequestMapping(value = "/model/exist/{type}/{modelId}", method = RequestMethod.POST)
@ResponseBody
public Result resourceExist(@PathVariable("type") String type, @PathVariable("modelId") String modelId) throws IOException {
    Model modelData = repositoryService.getModel(modelId);
    if (type.equals("xml")) {
        BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
        JsonNode editorNode = objectMapper.readTree(repositoryService.getModelEditorSource(modelData.getId()));
        BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
        return new Result(!bpmnModel.getProcesses().isEmpty());
    } else {
        byte[] pngBytes = repositoryService.getModelEditorSourceExtra(modelData.getId());
        return new Result(pngBytes.length > 0);
    }
}
 
开发者ID:bill1012,项目名称:AdminEAP,代码行数:23,代码来源:ModelOperationController.java


示例14: convertToModel

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
/**
 * 转换流程定义为模型
 * @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";
}
 
开发者ID:shawn-gogh,项目名称:myjavacode,代码行数:39,代码来源:DeploymentController.java


示例15: deploy

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
@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";
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:42,代码来源:ModelerController.java


示例16: export

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
/**
     * 导出model对象为指定类型
     *
     * @param modelId 模型ID
     * @param type    导出文件类型(bpmn\json)
     */
    @RequestMapping(value = "export/{modelId}/{type}", method = RequestMethod.GET)
    public void export(@PathVariable("modelId") String modelId,
                       @PathVariable("type") String type,
                       HttpServletResponse response) {
        try {
            Model modelData = repositoryService.getModel(modelId);
            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) {
                response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
                response.getOutputStream().println("no main process, can't export for type: " + type);
                response.flushBuffer();
                return;
            }

            String filename = "";
            byte[] exportBytes = null;

            String mainProcessId = bpmnModel.getMainProcess().getId();

            if ("bpmn".equals(type)) {

                BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
                exportBytes = xmlConverter.convertToXML(bpmnModel);

                filename = mainProcessId + ".bpmn20.xml";
            } else if ("json".equals(type)) {

                exportBytes = modelEditorSource;
                filename = mainProcessId + ".json";

            }

            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(filename, "UTF-8"));

            /*创建输入流*/
            ByteArrayInputStream in = new ByteArrayInputStream(exportBytes);
            IOUtils.copy(in, response.getOutputStream());

            response.flushBuffer();
            in.close();
        } catch (Exception e) {
//            logger.error("导出model的xml文件失败:modelId={}, type={}", modelId, type, e);
        }
    }
 
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:59,代码来源:FlowableModelManagerController.java


示例17: convertToJsonTest

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
public void convertToJsonTest() {

		BpmnModel bpmnModel = buildModel();

		BpmnJsonConverter jsonConverter = new BpmnJsonExConverter();
		ObjectNode objectNode = jsonConverter.convertToJson(bpmnModel);

		System.out.println(objectNode.toString());
	}
 
开发者ID:KayuraTeam,项目名称:kayura-activiti,代码行数:10,代码来源:BpmnModelTest.java


示例18: deploy

import org.activiti.editor.language.json.converter.BpmnJsonConverter; //导入依赖的package包/类
/**
 * 发布模型为流程定义
 *
 * @param id
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/model/deploy/{id}", method = RequestMethod.POST)
@ResponseBody
public Result deploy(@PathVariable("id") String id, HttpServletRequest request) throws Exception {

    //获取模型
    Model modelData = repositoryService.getModel(id);
    byte[] bytes = repositoryService.getModelEditorSource(modelData.getId());

    if (bytes == null) {
        return new Result(false, id, "模型数据为空,请先设计流程并成功保存,再进行发布。");
    }

    JsonNode modelNode = objectMapper.readTree(bytes);

    BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
    if (model.getProcesses().size() == 0) {
        return new Result(false, id, "数据模型不符要求,请至少设计一条主线流程。");
    }
    try {
        //----------------生成zip文件-------------------------
        byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model);
        Result xml = generateResource("xml", id, request);
        Result image = generateResource("image", id, request);
        if (xml.getData() == null || image.getData() == null) {
            return new Result(false, "部署失败", "流程尚未定义或定义错误,不能生成有效的xml和png文件");
        }
        String basePath = request.getRealPath("/");
        String fileName = modelData.getKey() + ".bpmn20.model.zip";
        String zipFileName = DIR_PATH + File.separator + fileName;
        File file = new File(basePath + File.separator + zipFileName);
        if (file.exists()) {
            file.delete();
        }
        String zipPath = FileUtil.generateZipFile(basePath, zipFileName, xml.getData().toString(),
                image.getData().toString());
        InputStream inputStream = new FileInputStream(zipPath);
        ZipInputStream zipInputStream = new ZipInputStream(inputStream);
        //---------------------------------------------------
        //发布流程
        String processName = modelData.getKey() + ".bpmn20.xml";
        DeploymentBuilder deploymentBuilder = repositoryService.createDeployment()
                .name(modelData.getName())
                .category(modelData.getCategory())
                .tenantId(modelData.getTenantId())
                //使用addZipInputStream后可以预防flow连线文字丢失的问题
                .addZipInputStream(zipInputStream);
                //.addString(processName, new String(bpmnBytes, "UTF-8"))
                

        List<JsonNode> forms=modelNode.findValues("formkeydefinition");
        for (JsonNode form : forms) {
            String formName=form.textValue();
            if(!StrUtil.isEmpty(formName)){
                InputStream stream=this.getClass().getClassLoader().getResourceAsStream(formName);
                deploymentBuilder.addInputStream(formName,stream);
            }
        }
        Deployment deployment=deploymentBuilder.deploy();
        
        //更新流程定义类别,替换掉页面的定义
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId
                (deployment.getId()).singleResult();
        if (processDefinition != null)
            repositoryService.setProcessDefinitionCategory(processDefinition.getId(), deployment.getCategory());

        modelData.setDeploymentId(deployment.getId());
        repositoryService.saveModel(modelData);
        return new Result(true);
    } catch (Exception ex) {
        return new Result(false, "部署失败", ex.getMessage().toString());
    }
}
 
开发者ID:bill1012,项目名称:AdminEAP,代码行数:80,代码来源:ModelOperationController.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java GPUImageKuwaharaFilter类代码示例发布时间:2022-05-22
下一篇:
Java CallTarget类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap