| | |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ClassUtils; |
| | | |
| | |
| | | RepositoryService service; |
| | | @Autowired |
| | | ObjectMapper objectMapper; |
| | | |
| | | @Value("${img.url}") |
| | | String basePath; |
| | | //download |
| | | public void getModelXml(HttpServletResponse response, String modelId) throws IOException { |
| | | Model model = service.getModel(modelId); |
| | |
| | | //1.3 |
| | | ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(hashMap.get("json_xml").getBytes("utf-8")); |
| | | BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode); |
| | | if (bpmnModel.getProcesses().size() == 0) { |
| | | return false; |
| | | } |
| | | byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(bpmnModel); |
| | | String processName = newModel.getName()+ ".bpmn20.xml"; |
| | | Deployment deployment = service.createDeployment().name(newModel.getName()).addString(processName,new String(bpmnBytes,"UTF-8")).deploy(); |
| | | newModel.setDeploymentId(deployment.getId()); |
| | | newModel.setCategory(deployment.getId()); |
| | | |
| | | |
| | | service.saveModel(newModel); |
| | | |
| | | //1.4 |
| | |
| | | service.addModelEditorSourceExtra(newModel.getId(), result); |
| | | String newModelId = newModel.getId(); |
| | | //TODO dir 2. |
| | | String basePath = ClassUtils.getDefaultClassLoader().getResource("").getPath(); |
| | | String path = basePath + "static/processes/" + newModelId; |
| | | String path = basePath + newModelId; |
| | | File dir = new File(path); |
| | | if (!dir.exists()) { |
| | | dir.mkdirs(); |
| | |
| | | if (file.exists()) { |
| | | file.delete(); |
| | | } |
| | | log.info(file.getAbsolutePath()); |
| | | file.createNewFile(); |
| | | fileOutputStream2 = new FileOutputStream(file); |
| | | fileOutputStream2.write(bpmnBytes); |