flowable 流程图部署

/**
 * 发布模型为流程定义
 *
 * @return
 * @throws Exception
 */
public String deployModel(String id) throws IOException {
    org.flowable.ui.modeler.domain.Model modelData = modelService.getModel(id);
    //获取模型
    byte[] bytes = modelService.getBpmnXML(modelData);

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

    BpmnModel model = modelService.getBpmnModel(modelData);
    if (model.getProcesses().size() == 0) {
        return "数据模型不符要求,请至少设计一条主线流程。";
    }
    byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model);

    //发布流程
    String processName = modelData.getName() + ".bpmn20.xml";
    repositoryService.createDeployment()
            .name(modelData.getName())
            .addString(processName, new String(bpmnBytes, "UTF-8"))
            .deploy();
    //保存模型属性
    Collection processNodes = getProcessNodes(modelData.getId());
    List modelContentList = new ArrayList<>();
    for (FlowElement flowElement : processNodes) {
        if (flowElement instanceof UserTask) {
            ModelContent modelContent = new ModelContent(modelData.getName(), flowElement.getName(), flowElement.getId());
            modelContentList.add(modelContent);
        }
    }
    modelContentService.saveBatch(modelContentList);
    return "部署成功";
}

你可能感兴趣的:(flowable,flowable,spring,boot)