diff --git a/pom.xml b/pom.xml index 5f7893a..a794d14 100644 --- a/pom.xml +++ b/pom.xml @@ -1,12 +1,11 @@ - - + + 4.0.0 org.springframework.boot spring-boot-starter-parent 2.2.2.RELEASE - + com.yame uml @@ -19,12 +18,16 @@ + + org.springframework.boot + spring-boot-starter-logging + net.sourceforge.plantuml plantuml 1.2020.0 - + org.springframework.boot @@ -55,7 +58,6 @@ - @@ -67,4 +69,4 @@ - + \ No newline at end of file diff --git a/src/main/java/com/yame/uml/control/api.java b/src/main/java/com/yame/uml/control/api.java index ac70094..ca04103 100644 --- a/src/main/java/com/yame/uml/control/api.java +++ b/src/main/java/com/yame/uml/control/api.java @@ -13,13 +13,17 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import lombok.extern.slf4j.Slf4j; import net.sourceforge.plantuml.BlockUml; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.SourceStringReader; +import net.sourceforge.plantuml.core.Diagram; +import net.sourceforge.plantuml.error.PSystemError; @RestController @RequestMapping("/api") +@Slf4j public class api { static public String getUmlSource(String source) { @@ -52,11 +56,8 @@ public class api { if(srcblocks.size() != 0 && dstblocks.size() != 0) { - - + } - - result.setType(ResultType.ErrorMegreUML2SVG); return result; } @@ -71,15 +72,26 @@ public class api { Result result = new Result(); if(blocks.size() != 0) { for(BlockUml block: blocks) { + Diagram diagram = block.getDiagram(); + if (diagram instanceof PSystemError) { + result.setType(ResultType.ErrorSource2SVG); + int errorLine = ((PSystemError) diagram).getLineLocation().getPosition(); + result.setMsg("error line: " + errorLine); + } else { + result.setType(ResultType.Source2SVG); + } + OutputStream os = new ByteArrayOutputStream(); - block.getDiagram().exportDiagram(os, 0, new FileFormatOption(FileFormat.SVG)); - result.setType(ResultType.Source2SVG); + diagram.exportDiagram(os, 0, new FileFormatOption(FileFormat.SVG)); result.getContent().add(os.toString()); return result; } } + + result.setType(ResultType.ErrorSource2SVG); + log.debug( ResultType.ErrorSource2SVG + data); return result; } } \ No newline at end of file diff --git a/src/main/java/com/yame/uml/model/Result.java b/src/main/java/com/yame/uml/model/Result.java index 3c44ff0..49e8eed 100644 --- a/src/main/java/com/yame/uml/model/Result.java +++ b/src/main/java/com/yame/uml/model/Result.java @@ -6,10 +6,13 @@ import java.util.List; /** * result */ + public class Result { - public ResultType type; - public List content; + + private ResultType type; + private String msg; + private List content; public Result() { content = new ArrayList(); @@ -19,6 +22,14 @@ public class Result { return content; } + public void addContent(String content) { + this.content.add(content); + } + + public void delContent(int idx) { + this.content.remove(idx); + } + public ResultType getType() { return type; } @@ -26,4 +37,12 @@ public class Result { public void setType(ResultType type) { this.type = type; } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } } \ No newline at end of file diff --git a/src/main/java/com/yame/uml/model/ResultType.java b/src/main/java/com/yame/uml/model/ResultType.java index 4235abf..d9f026e 100644 --- a/src/main/java/com/yame/uml/model/ResultType.java +++ b/src/main/java/com/yame/uml/model/ResultType.java @@ -1,32 +1,36 @@ package com.yame.uml.model; -public enum ResultType { - Success("Success", 1), - Source2PNG("Source2PNG", 101), - Source2SVG("Source2SVG", 102), +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonFormat.Shape; +import com.fasterxml.jackson.annotation.JsonProperty; - MegreUML2SVG("megreUML2SVG", 202), + +@JsonFormat(shape = Shape.OBJECT) +public enum ResultType { + Success("Success", 1, true), + Source2PNG("Source2PNG", 101, true), + Source2SVG("Source2SVG", 102, true), + + MegreUML2SVG("megreUML2SVG", 202, true), - Error("Error", 0), - ErrorSource2PNG("Error Source2PNG: source format is erorr", -101), - ErrorSource2SVG("Error Source2SVG: source format is erorr", -102), - ErrorMegreUML2SVG("Error MegreUML2SVG: source format is erorr or not support format", -202), + Error("Error", 0, false), + ErrorSource2PNG("Error Source2PNG", -101, false), + ErrorSource2SVG("Error Source2SVG", -102, false), + + ErrorMegreUML2SVG("Error MegreUML2SVG", -202, false), ; - private String status; + @JsonProperty("desc") + private String desc; + @JsonProperty("code") private int code; + @JsonProperty("success") + private boolean success; - private ResultType(String status, int code) { - this.status = status; + private ResultType(String desc, int code, Boolean isSuccessed) { + this.desc = desc; this.code = code; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; + this.success = isSuccessed; } public int getCode() { @@ -36,4 +40,20 @@ public enum ResultType { public void setCode(int code) { this.code = code; } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } } \ No newline at end of file