use of com.plumdo.flow.cmd.SaveModelEditorCmd in project plumdo-work by wengwh.
the class ModelEditorResource method saveModelEditor.
@PostMapping(value = "/models/{modelId}/editor", name = "模型设计器保存模型")
@ResponseStatus(value = HttpStatus.OK)
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void saveModelEditor(@PathVariable String modelId, @RequestBody ModelEditorJsonRequest values) {
Model model = getModel(modelId, values.isNewVersion());
if (!model.getKey().equals(values.getKey())) {
checkModelKeyExists(values.getKey());
managementService.executeCommand(new UpdateModelKeyCmd(modelId, values.getKey()));
}
try {
ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
modelJson.put("name", values.getName());
modelJson.put("description", values.getDescription());
model.setMetaInfo(modelJson.toString());
model.setName(values.getName());
model.setKey(values.getKey());
repositoryService.saveModel(model);
managementService.executeCommand(new SaveModelEditorCmd(model.getId(), values.getJsonXml()));
} catch (Exception e) {
logger.error("保存模型设计信息异常", e);
exceptionFactory.throwDefinedException(ErrorConstant.MODEL_GET_EDITOR_ERROR, e.getMessage());
}
}
use of com.plumdo.flow.cmd.SaveModelEditorCmd in project plumdo-work by wengwh.
the class ModelImportResource method importModel.
@PostMapping(value = "/models/import", name = "流程模型导入")
@ResponseStatus(value = HttpStatus.CREATED)
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public ModelResponse importModel(HttpServletRequest request) {
if (!(request instanceof MultipartHttpServletRequest)) {
exceptionFactory.throwIllegalArgument(ErrorConstant.REQUEST_NOT_MULTIPART);
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
if (multipartRequest.getFileMap().size() == 0) {
exceptionFactory.throwIllegalArgument(ErrorConstant.MULTIPART_CONTENT_EMPTY);
}
MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
String fileName = file.getOriginalFilename();
if (fileName == null || (!fileName.endsWith(".bpmn") && !fileName.endsWith(".bpmn20.xml"))) {
exceptionFactory.throwIllegalArgument(ErrorConstant.FILE_NOT_BPMN, fileName);
}
try {
XMLInputFactory xif = XMLInputFactory.newInstance();
InputStreamReader xmlIn = new InputStreamReader(file.getInputStream(), "UTF-8");
XMLStreamReader xtr = xif.createXMLStreamReader(xmlIn);
BpmnModel bpmnModel = bpmnXmlConverter.convertToBpmnModel(xtr);
if (ObjectUtils.isEmpty(bpmnModel.getProcesses())) {
exceptionFactory.throwObjectNotFound(ErrorConstant.MODEL_NOT_FOUND_PROCESS, fileName);
}
Process process = bpmnModel.getMainProcess();
Model modelData = repositoryService.newModel();
modelData.setKey(process.getId());
Model lastModel = repositoryService.createModelQuery().modelKey(modelData.getKey()).latestVersion().singleResult();
if (lastModel == null) {
modelData.setVersion(TableConstant.MODEL_VESION_START);
} else {
modelData.setVersion(lastModel.getVersion() + 1);
}
if (ObjectUtils.isNotEmpty(process.getName())) {
modelData.setName(process.getName());
} else {
modelData.setName(process.getId());
}
ObjectNode metaInfo = new ObjectMapper().createObjectNode();
metaInfo.put("name", modelData.getName());
metaInfo.put("description", process.getDocumentation());
modelData.setMetaInfo(metaInfo.toString());
repositoryService.saveModel(modelData);
managementService.executeCommand(new SaveModelEditorCmd(modelData.getId(), bpmnJsonConverter.convertToJson(bpmnModel).toString()));
return restResponseFactory.createModelResponse(modelData);
} catch (Exception e) {
logger.error("导入流程文件异常", e);
exceptionFactory.throwDefinedException(ErrorConstant.MODEL_IMPORT_FILE_ERROR, fileName, e.getMessage());
}
return null;
}
use of com.plumdo.flow.cmd.SaveModelEditorCmd in project plumdo-work by wengwh.
the class ModelResource method createModel.
@PostMapping(value = "/models", name = "模型创建")
@ResponseStatus(value = HttpStatus.CREATED)
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public ModelResponse createModel(@RequestBody ModelRequest modelRequest) {
checkModelKeyExists(modelRequest.getKey());
Model model = repositoryService.newModel();
model.setCategory(modelRequest.getCategory());
model.setKey(modelRequest.getKey());
model.setName(modelRequest.getName());
model.setVersion(TableConstant.MODEL_VESION_START);
model.setMetaInfo(modelRequest.getMetaInfo());
model.setTenantId(modelRequest.getTenantId());
repositoryService.saveModel(model);
managementService.executeCommand(new SaveModelEditorCmd(model.getId(), createModelJson(model)));
return restResponseFactory.createModelResponse(model);
}
Aggregations