@GetMapping(value = "/{modelId}/json") @Authorize(action = Permission.ACTION_GET) public Object getEditorJson(@PathVariable String modelId) { JSONObject modelNode; Model model = repositoryService.getModel(modelId); if (model == null) throw new NullPointerException("模型不存在"); if (StringUtils.isNotEmpty(model.getMetaInfo())) { modelNode = JSON.parseObject(model.getMetaInfo()); } else { modelNode = new JSONObject(); modelNode.put(MODEL_NAME, model.getName()); } modelNode.put(MODEL_ID, model.getId()); modelNode.put("model", JSON.parse(new String(repositoryService.getModelEditorSource(model.getId())))); return modelNode; }
@PutMapping(value = "/{modelId}") @ResponseStatus(value = HttpStatus.OK) @Authorize(action = Permission.ACTION_UPDATE) public void saveModel(@PathVariable String modelId, @RequestParam Map<String, String> values) throws TranscoderException, IOException { Model model = repositoryService.getModel(modelId); JSONObject modelJson = JSON.parseObject(model.getMetaInfo()); modelJson.put(MODEL_NAME, values.get("name")); modelJson.put(MODEL_DESCRIPTION, values.get("description")); model.setMetaInfo(modelJson.toString()); model.setName(values.get("name")); repositoryService.saveModel(model); repositoryService.addModelEditorSource(model.getId(), values.get("json_xml").getBytes("utf-8")); InputStream svgStream = new ByteArrayInputStream(values.get("svg_xml").getBytes("utf-8")); TranscoderInput input = new TranscoderInput(svgStream); PNGTranscoder transcoder = new PNGTranscoder(); // Setup output ByteArrayOutputStream outStream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(outStream); // Do the transformation transcoder.transcode(input, output); final byte[] result = outStream.toByteArray(); repositoryService.addModelEditorSourceExtra(model.getId(), result); outStream.close(); }
@RequestMapping(value="/model/{modelId}/json", method = RequestMethod.GET, produces = "application/json") @ResponseBody public ObjectNode getEditorJson(@PathVariable("modelId") String modelId) { ObjectNode modelNode = null; Model model = repositoryService.getModel(modelId); if (model != null) { try { if (StringUtils.isNotEmpty(model.getMetaInfo())) { modelNode = (ObjectNode) objectMapper.readTree(model.getMetaInfo()); } else { modelNode = objectMapper.createObjectNode(); modelNode.put(MODEL_NAME, model.getName()); } modelNode.put(MODEL_ID, model.getId()); ObjectNode editorJsonNode = (ObjectNode) objectMapper.readTree( new String(repositoryService.getModelEditorSource(model.getId()), "utf-8")); modelNode.put("model", editorJsonNode); } catch (Exception e) { LOGGER.error("Error creating model JSON", e); throw new ActivitiException("Error creating model JSON", e); } } return modelNode; } }
ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
@GetMapping(value = "/{modelId}/json") @Authorize(action = Permission.ACTION_GET) public Object getEditorJson(@PathVariable String modelId) { JSONObject modelNode; Model model = repositoryService.getModel(modelId); if (model == null) throw new NullPointerException("模型不存在"); if (StringUtils.isNotEmpty(model.getMetaInfo())) { modelNode = JSON.parseObject(model.getMetaInfo()); } else { modelNode = new JSONObject(); modelNode.put(MODEL_NAME, model.getName()); } modelNode.put(MODEL_ID, model.getId()); modelNode.put("model", JSON.parse(new String(repositoryService.getModelEditorSource(model.getId())))); return modelNode; }
@RequestMapping(value = "/model/{modelId}/json", method = {RequestMethod.GET}) public ObjectNode getEditorJson(@PathVariable String modelId) { ObjectNode modelNode = null; Model model = repositoryService.getModel(modelId); if (model != null) { try { if (StringUtils.isNotEmpty(model.getMetaInfo())) { modelNode = (ObjectNode) objectMapper.readTree(model.getMetaInfo()); } else { modelNode = objectMapper.createObjectNode(); modelNode.put(MODEL_NAME, model.getName()); } modelNode.put(MODEL_ID, model.getId()); ObjectNode editorJsonNode = (ObjectNode) objectMapper.readTree( new String(repositoryService.getModelEditorSource(model.getId()), "utf-8")); modelNode.put("model", editorJsonNode); } catch (Exception e) { LOGGER.error("Error creating model JSON", e); throw new ActivitiException("Error creating model JSON", e); } } return modelNode; }
@RequestMapping(value="/model/{modelId}/json", method = RequestMethod.GET, produces = "application/json") public ObjectNode getEditorJson(@PathVariable String modelId) { ObjectNode modelNode = null; Model model = repositoryService.getModel(modelId); if (model != null) { try { if (StringUtils.isNotEmpty(model.getMetaInfo())) { modelNode = (ObjectNode) objectMapper.readTree(model.getMetaInfo()); } else { modelNode = objectMapper.createObjectNode(); modelNode.put(MODEL_NAME, model.getName()); } modelNode.put(MODEL_ID, model.getId()); ObjectNode editorJsonNode = (ObjectNode) objectMapper.readTree( new String(repositoryService.getModelEditorSource(model.getId()), "utf-8")); modelNode.put("model", editorJsonNode); } catch (Exception e) { LOGGER.error("Error creating model JSON", e); throw new ActivitiException("Error creating model JSON", e); } } return modelNode; } }
@PutMapping(value = "/{modelId}") @ResponseStatus(value = HttpStatus.OK) @Authorize(action = Permission.ACTION_UPDATE) public void saveModel(@PathVariable String modelId, @RequestParam Map<String, String> values) throws TranscoderException, IOException { Model model = repositoryService.getModel(modelId); JSONObject modelJson = JSON.parseObject(model.getMetaInfo()); modelJson.put(MODEL_NAME, values.get("name")); modelJson.put(MODEL_DESCRIPTION, values.get("description")); model.setMetaInfo(modelJson.toString()); model.setName(values.get("name")); repositoryService.saveModel(model); repositoryService.addModelEditorSource(model.getId(), values.get("json_xml").getBytes("utf-8")); InputStream svgStream = new ByteArrayInputStream(values.get("svg_xml").getBytes("utf-8")); TranscoderInput input = new TranscoderInput(svgStream); PNGTranscoder transcoder = new PNGTranscoder(); // Setup output ByteArrayOutputStream outStream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(outStream); // Do the transformation transcoder.transcode(input, output); final byte[] result = outStream.toByteArray(); repositoryService.addModelEditorSourceExtra(model.getId(), result); outStream.close(); }
@RequestMapping(value = "/model/{modelId}/save", method = RequestMethod.PUT) @ResponseStatus(value = HttpStatus.OK) public void saveModel(@PathVariable String modelId , String name, String description , String json_xml, String svg_xml) { try { Model model = repositoryService.getModel(modelId); ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo()); modelJson.put(MODEL_NAME, name); modelJson.put(MODEL_DESCRIPTION, description); model.setMetaInfo(modelJson.toString()); model.setName(name); repositoryService.saveModel(model); repositoryService.addModelEditorSource(model.getId(), json_xml.getBytes("utf-8")); InputStream svgStream = new ByteArrayInputStream(svg_xml.getBytes("utf-8")); TranscoderInput input = new TranscoderInput(svgStream); PNGTranscoder transcoder = new PNGTranscoder(); // Setup output ByteArrayOutputStream outStream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(outStream); // Do the transformation transcoder.transcode(input, output); final byte[] result = outStream.toByteArray(); repositoryService.addModelEditorSourceExtra(model.getId(), result); outStream.close(); } catch (Exception e) { LOGGER.error("Error saving model", e); throw new ActivitiException("Error saving model", e); } }
ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
public ModelResponse createModelResponse(Model model, RestUrlBuilder urlBuilder) { ModelResponse response = new ModelResponse(); response.setCategory(model.getCategory()); response.setCreateTime(model.getCreateTime()); response.setId(model.getId()); response.setKey(model.getKey()); response.setLastUpdateTime(model.getLastUpdateTime()); response.setMetaInfo(model.getMetaInfo()); response.setName(model.getName()); response.setDeploymentId(model.getDeploymentId()); response.setVersion(model.getVersion()); response.setTenantId(model.getTenantId()); response.setUrl(urlBuilder.buildUrl(RestUrls.URL_MODEL, model.getId())); if (model.getDeploymentId() != null) { response.setDeploymentUrl(urlBuilder.buildUrl(RestUrls.URL_DEPLOYMENT, model.getDeploymentId())); } if (model.hasEditorSource()) { response.setSourceUrl(urlBuilder.buildUrl(RestUrls.URL_MODEL_SOURCE, model.getId())); } if (model.hasEditorSourceExtra()) { response.setSourceExtraUrl(urlBuilder.buildUrl(RestUrls.URL_MODEL_SOURCE_EXTRA, model.getId())); } return response; }