03.flowable 流程模板部署

1.演示

在这里插入图片描述
2.代码

@Override
    @Transactional
    public Object modelDeploy(ReqModel reqModel) throws IllegalAccessException, IntrospectionException, InstantiationException, SQLException, InvocationTargetException, ClassNotFoundException {
        /**
         * 1.根据modelId获取模型信息
         * 2.转换为xml对象
         * 3.部署对象以模型对象的名称命名
         * 4.部署转换出来的xml对象
         * */
        RetBean retbean = new RetBean();
        FlowModel model = this.queryFlowModelById(reqModel.getModelId());
        if (model == null) {
            return retbean.backError("No model found with the given id: " + reqModel.getModelId());
        }
        BpmnModel bpmnModel = getBpmnModel(model);
        for (Process process : bpmnModel.getProcesses()) {
            if (StringUtils.isNotEmpty(process.getId())) {
                char firstCharacter = process.getId().charAt(0);
                if (Character.isDigit(firstCharacter)) {
                    process.setId("a" + process.getId());
                }
            }
        }
        byte[] bytes = BPMN_XML_CONVERTER.convertToXML(bpmnModel);
        String processName = model.getName();
        if (!StringUtil.endsWithIgnoreCase(processName, FlowEngineConstant.SUFFIX)) {
            processName += FlowEngineConstant.SUFFIX;
        }
        String finalProcessName = processName;
        String[] ids = null;
        if (!StringUtil.isEmpty(reqModel.getTenantIds())) {
            ids = reqModel.getTenantIds().split(",");
        }
        if (!StringUtil.isEmpty(ids)) {
            for (String tenantId : ids) {
                Deployment deployment = repositoryService.createDeployment().addBytes(finalProcessName, bytes).name(model.getName()).key(model.getModel_key()).tenantId(tenantId).deploy();
                deploy(deployment, reqModel.getCategory());
            }
        } else {
            Deployment deployment = repositoryService.createDeployment().addBytes(finalProcessName, bytes).name(model.getName()).key(model.getModel_key()).deploy();
            deploy(deployment, reqModel.getCategory());
        }
        return retbean;
    }

	private BpmnModel getBpmnModel(FlowModel model) throws IllegalAccessException, IntrospectionException, InstantiationException, SQLException, InvocationTargetException, ClassNotFoundException {
        BpmnModel bpmnModel;
        try {
            Map<String, FlowModel> formMap = new HashMap<>(16);
            Map<String, FlowModel> decisionTableMap = new HashMap<>(16);
            List<FlowModel> referencedModels = this.findByParentModelId(model.getId());
            for (FlowModel childModel : referencedModels) {
                if (FlowModel.MODEL_TYPE_FORM == childModel.getModel_type()) {
                    formMap.put(childModel.getId(), childModel);
                } else if (FlowModel.MODEL_TYPE_DECISION_TABLE == childModel.getModel_type()) {
                    decisionTableMap.put(childModel.getId(), childModel);
                }
            }
            bpmnModel = getBpmnModel(model, formMap, decisionTableMap);
        } catch (Exception e) {
            throw new ServiceException("Could not generate BPMN 2.0 model");
        }
        return bpmnModel;
    }


    private BpmnModel getBpmnModel(FlowModel model, Map<String, FlowModel> formMap, Map<String, FlowModel> decisionTableMap) throws JsonProcessingException {
        ObjectNode editorJsonNode = (ObjectNode) objectMapper.readTree(model.getModel_editor_json());
        Map<String, String> formKeyMap = new HashMap<>(16);
        for (FlowModel formModel : formMap.values()) {
            formKeyMap.put(formModel.getId(), formModel.getModel_key());
        }
        Map<String, String> decisionTableKeyMap = new HashMap<>(16);
        for (FlowModel decisionTableModel : decisionTableMap.values()) {
            decisionTableKeyMap.put(decisionTableModel.getId(), decisionTableModel.getModel_key());
        }
        return BPMN_JSON_CONVERTER.convertToBpmnModel(editorJsonNode, formKeyMap, decisionTableKeyMap);
    }

 private boolean deploy(Deployment deployment, String category) {
        List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list();
        // 设置流程分类
        for (ProcessDefinition processDefinition : list) {
            if (StringUtil.isNotBlank(category)) {
                repositoryService.setProcessDefinitionCategory(processDefinition.getId(), category);
            }

        }
        if (list.size() == 0) {
            throw new ServiceException("部署失败,未找到流程");
        } else {
            return true;
        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值