public static Deployment deployModel(RepositoryService repositoryService, String modelId) throws IOException { Model modelData = repositoryService.getModel(modelId); //EditorSource就是XML格式的 byte[] bpmnBytes = repositoryService.getModelEditorSource(modelId); String processName = modelData.getName() + ".bpmn20.xml"; Deployment deployment = repositoryService.createDeployment().name(modelData.getName()) .addString(processName, new String(bpmnBytes, "utf-8")).deploy(); //设置部署ID modelData.setDeploymentId(deployment.getId()); repositoryService.saveModel(modelData); return deployment; }
repositoryService.setProcessDefinitionCategory(processDefinition.getId(), deployment.getCategory()); modelData.setDeploymentId(deployment.getId()); repositoryService.saveModel(modelData); return new Result(true);
@ApiOperation(value = "Create a model", tags = {"Models"}, notes = "All request values are optional. For example, you can only include the name attribute in the request body JSON-object, only setting the name of the model, leaving all other fields null.") @ApiResponses(value = { @ApiResponse(code = 200, message = "Indicates the model was created.") }) @RequestMapping(value = "/repository/models", method = RequestMethod.POST, produces = "application/json") public ModelResponse createModel(@RequestBody ModelRequest modelRequest, HttpServletRequest request, HttpServletResponse response) { Model model = repositoryService.newModel(); model.setCategory(modelRequest.getCategory()); model.setDeploymentId(modelRequest.getDeploymentId()); model.setKey(modelRequest.getKey()); model.setMetaInfo(modelRequest.getMetaInfo()); model.setName(modelRequest.getName()); model.setVersion(modelRequest.getVersion()); model.setTenantId(modelRequest.getTenantId()); repositoryService.saveModel(model); response.setStatus(HttpStatus.CREATED.value()); return restResponseFactory.createModelResponse(model); } }
@RequestMapping(value = "/model/deploy/{id}", method = RequestMethod.POST) public ResponseCode deploy(@PathVariable("id") String id) throws Exception { //获取模型 Model modelData = repositoryService.getModel(id); byte[] bytes = repositoryService.getModelEditorSource(modelData.getId()); if (bytes == null) { return ResponseCode.error("模型数据为空,请先设计流程并成功保存,再进行发布。"); } JsonNode modelNode = new ObjectMapper().readTree(bytes); BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode); if (model.getProcesses().size() == 0) { return ResponseCode.error("数据模型不符要求,请至少设计一条主线流程。"); } byte[] 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")) .deploy(); modelData.setDeploymentId(deployment.getId()); repositoryService.saveModel(modelData); return ResponseCode.ok(); }
model.setDeploymentId(modelRequest.getDeploymentId());