|
@@ -1,5 +1,6 @@
|
|
|
package org.hswebframework.web.workflow.web;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
@@ -15,7 +16,12 @@ import org.activiti.engine.RepositoryService;
|
|
|
import org.activiti.engine.repository.Deployment;
|
|
|
import org.activiti.engine.repository.Model;
|
|
|
import org.activiti.engine.repository.ModelQuery;
|
|
|
+import org.apache.batik.transcoder.TranscoderException;
|
|
|
+import org.apache.batik.transcoder.TranscoderInput;
|
|
|
+import org.apache.batik.transcoder.TranscoderOutput;
|
|
|
+import org.apache.batik.transcoder.image.PNGTranscoder;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.hswebframework.ezorm.core.PropertyWrapper;
|
|
|
import org.hswebframework.ezorm.core.SimplePropertyWrapper;
|
|
|
import org.hswebframework.ezorm.core.param.TermType;
|
|
@@ -32,11 +38,15 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
|
-@RequestMapping("/workflow/model/")
|
|
|
+@RequestMapping("/workflow/model")
|
|
|
@Api(tags = "工作流-模型管理", description = "工作流模型管理")
|
|
|
@Authorize(permission = "workflow-model", description = "工作流模型管理")
|
|
|
@Slf4j
|
|
@@ -45,11 +55,11 @@ public class FlowableModelManagerController {
|
|
|
@Autowired
|
|
|
private RepositoryService repositoryService;
|
|
|
|
|
|
- private final static String MODEL_ID = "modelId";
|
|
|
- private final static String MODEL_NAME = "name";
|
|
|
- private final static String MODEL_REVISION = "revision";
|
|
|
+ private final static String MODEL_ID = "modelId";
|
|
|
+ private final static String MODEL_NAME = "name";
|
|
|
+ private final static String MODEL_REVISION = "revision";
|
|
|
private final static String MODEL_DESCRIPTION = "description";
|
|
|
- private final static String MODEL_KEY = "key";
|
|
|
+ private final static String MODEL_KEY = "key";
|
|
|
|
|
|
@GetMapping
|
|
|
@Authorize(action = Permission.ACTION_QUERY)
|
|
@@ -128,10 +138,10 @@ public class FlowableModelManagerController {
|
|
|
modelData.setKey(model.getKey());
|
|
|
repositoryService.saveModel(modelData);
|
|
|
repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
|
|
|
- return ResponseMessage.ok(modelData);
|
|
|
+ return ResponseMessage.ok(modelData).status(201);
|
|
|
}
|
|
|
|
|
|
- @PostMapping("{modelId}/deploy")
|
|
|
+ @PostMapping("/{modelId}/deploy")
|
|
|
@ApiOperation("发布模型")
|
|
|
@Authorize(action = "deploy")
|
|
|
public ResponseMessage<Deployment> deployModel(@PathVariable String modelId) throws Exception {
|
|
@@ -213,4 +223,60 @@ public class FlowableModelManagerController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @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();
|
|
|
+ }
|
|
|
+
|
|
|
+ @DeleteMapping("/{modelId}")
|
|
|
+ @Authorize(action = Permission.ACTION_DELETE)
|
|
|
+ public ResponseMessage<Void> delete(@PathVariable String modelId) {
|
|
|
+ repositoryService.deleteModel(modelId);
|
|
|
+ return ResponseMessage.ok();
|
|
|
+ }
|
|
|
}
|