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


Java BpmnModel.getMainProcess方法代码示例

本文整理汇总了Java中org.activiti.bpmn.model.BpmnModel.getMainProcess方法的典型用法代码示例。如果您正苦于以下问题:Java BpmnModel.getMainProcess方法的具体用法?Java BpmnModel.getMainProcess怎么用?Java BpmnModel.getMainProcess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.activiti.bpmn.model.BpmnModel的用法示例。


在下文中一共展示了BpmnModel.getMainProcess方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: assertFirstTaskIsAsync

import org.activiti.bpmn.model.BpmnModel; //导入方法依赖的package包/类
/**
 * Asserts that the first asyncable task in the given model is indeed asynchronous. Only asserts when the configuration is set to true.
 *
 * @param bpmnModel The BPMN model
 */
private void assertFirstTaskIsAsync(BpmnModel bpmnModel)
{
    if (Boolean.TRUE.equals(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_JOB_DEFINITION_ASSERT_ASYNC, Boolean.class)))
    {
        Process process = bpmnModel.getMainProcess();
        for (StartEvent startEvent : process.findFlowElementsOfType(StartEvent.class))
        {
            for (SequenceFlow sequenceFlow : startEvent.getOutgoingFlows())
            {
                String targetRef = sequenceFlow.getTargetRef();
                FlowElement targetFlowElement = process.getFlowElement(targetRef);
                if (targetFlowElement instanceof Activity)
                {
                    Assert.isTrue(((Activity) targetFlowElement).isAsynchronous(), "Element with id \"" + targetRef +
                        "\" must be set to activiti:async=true. All tasks which start the workflow must be asynchronous to prevent certain undesired " +
                        "transactional behavior, such as records of workflow not being saved on errors. Please refer to Activiti and herd documentations " +
                        "for details.");
                }
            }
        }
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:28,代码来源:JobDefinitionServiceImpl.java

示例2: testXmlToBpmnModel

import org.activiti.bpmn.model.BpmnModel; //导入方法依赖的package包/类
/**
 * 把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());
}
 
开发者ID:barudisshu,项目名称:activiti-in-action-codes,代码行数:36,代码来源:BpmnModelTest.java

示例3: processGlobal

import org.activiti.bpmn.model.BpmnModel; //导入方法依赖的package包/类
/**
 * 全局配置.
 */
public void processGlobal(BpmnModel bpmnModel, int priority,
        BpmConfBase bpmConfBase) {
    Process process = bpmnModel.getMainProcess();
    BpmConfNodeManager bpmConfNodeManager = getBpmConfNodeManager();
    BpmConfNode bpmConfNode = bpmConfNodeManager.findUnique(
            "from BpmConfNode where code=? and bpmConfBase=?",
            process.getId(), bpmConfBase);

    if (bpmConfNode == null) {
        bpmConfNode = new BpmConfNode();
        bpmConfNode.setCode(process.getId());
        bpmConfNode.setName("全局");
        bpmConfNode.setType("process");
        bpmConfNode.setConfUser(2);
        bpmConfNode.setConfListener(0);
        bpmConfNode.setConfRule(2);
        bpmConfNode.setConfForm(0);
        bpmConfNode.setConfOperation(2);
        bpmConfNode.setConfNotice(2);
        bpmConfNode.setPriority(priority);
        bpmConfNode.setBpmConfBase(bpmConfBase);
        bpmConfNodeManager.save(bpmConfNode);
    }

    // 配置监听器
    processListener(process.getExecutionListeners(), bpmConfNode);
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:31,代码来源:SyncProcessCmd.java

示例4: export

import org.activiti.bpmn.model.BpmnModel; //导入方法依赖的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

示例5: export

import org.activiti.bpmn.model.BpmnModel; //导入方法依赖的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

示例6: importModel

import org.activiti.bpmn.model.BpmnModel; //导入方法依赖的package包/类
@RequestMapping(value = "/model/import", method = RequestMethod.POST)
public void importModel(String key, String tenantId, MultipartFile file) {

	try {

		String fileName = file.getOriginalFilename();
		if (fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn")) {

			XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
			InputStreamReader in = new InputStreamReader(new ByteArrayInputStream(file.getBytes()), "UTF-8");
			XMLStreamReader xtr = xif.createXMLStreamReader(in);
			BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);

			if (bpmnModel.getMainProcess() != null && bpmnModel.getMainProcess().getId() != null) {

				if (!bpmnModel.getLocationMap().isEmpty()) {

					String processName = bpmnModel.getMainProcess().getName();
					if (StringUtils.isEmpty(processName)) {
						processName = bpmnModel.getMainProcess().getId();
					}

					Model model = repositoryService.newModel();
					ObjectNode metaInfo = new ObjectMapper().createObjectNode();
					metaInfo.put("name", processName);
					metaInfo.put("revision", 1);

					model.setMetaInfo(metaInfo.toString());
					model.setName(processName);
					if (StringUtils.isNotEmpty(tenantId)) {
						model.setTenantId(tenantId);
					}
					model.setKey(key);

					repositoryService.saveModel(model);

					ObjectNode editorNode = new BpmnJsonExConverter().convertToJson(bpmnModel);
					repositoryService.addModelEditorSource(model.getId(), editorNode.toString().getBytes("UTF-8"));
				}
			}
		}
	} catch (Exception e) {
		logger.error("Error Import Model", e);
		throw new ActivitiException("Error Import Model", e);
	}
}
 
开发者ID:KayuraTeam,项目名称:kayura-activiti,代码行数:47,代码来源:ModelRestResource.java


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