Merge branch 'release/v0.0.1'
This commit is contained in:
commit
d6194985c4
18
pom.xml
18
pom.xml
|
@ -1,30 +1,33 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.2.2.RELEASE</version>
|
<version>2.2.2.RELEASE</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath /> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.yame</groupId>
|
<groupId>com.yame</groupId>
|
||||||
<artifactId>uml</artifactId>
|
<artifactId>uml</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<name>demo</name>
|
<name>umlserver</name>
|
||||||
<description>Demo project for Spring Boot</description>
|
<description>Demo umlserver project for Spring Boot</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-logging</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.sourceforge.plantuml</groupId>
|
<groupId>net.sourceforge.plantuml</groupId>
|
||||||
<artifactId>plantuml</artifactId>
|
<artifactId>plantuml</artifactId>
|
||||||
<version>1.2020.0</version>
|
<version>1.2020.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -55,7 +58,6 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.yame.uml;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.annotation.ComponentScans;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class Application {
|
public class Application {
|
||||||
|
|
|
@ -1,41 +1,29 @@
|
||||||
package com.yame.uml.control;
|
package com.yame.uml.control;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import com.yame.uml.model.Result;
|
import com.yame.uml.model.Result;
|
||||||
import com.yame.uml.model.ResultType;
|
import com.yame.uml.model.ResultType;
|
||||||
|
|
||||||
import net.sourceforge.plantuml.BlockUml;
|
|
||||||
import net.sourceforge.plantuml.FileFormat;
|
|
||||||
import net.sourceforge.plantuml.FileFormatOption;
|
|
||||||
import net.sourceforge.plantuml.LineLocation;
|
|
||||||
import net.sourceforge.plantuml.SourceStringReader;
|
|
||||||
import net.sourceforge.plantuml.api.PlantumlUtils;
|
|
||||||
import net.sourceforge.plantuml.code.Transcoder;
|
|
||||||
import net.sourceforge.plantuml.code.TranscoderUtil;
|
|
||||||
import net.sourceforge.plantuml.core.*;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestHeader;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
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
|
@RestController
|
||||||
@RequestMapping("/api")
|
@RequestMapping("/api")
|
||||||
|
@Slf4j
|
||||||
public class api {
|
public class api {
|
||||||
|
|
||||||
static public String getUmlSource(String source) {
|
static public String getUmlSource(String source) {
|
||||||
|
@ -57,7 +45,25 @@ public class api {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/v1/megreflow")
|
@PostMapping("/v1/megreflow")
|
||||||
public Result megreSVG(@RequestParam("data") String data) throws IOException {
|
public Result megreSVG(@RequestParam("src") String src, @RequestParam("dst") String dst) throws IOException {
|
||||||
|
String source = getUmlSource(src);
|
||||||
|
List<BlockUml> srcblocks = new SourceStringReader(source).getBlocks();
|
||||||
|
|
||||||
|
String destination = getUmlSource(dst);
|
||||||
|
List<BlockUml> dstblocks = new SourceStringReader(destination).getBlocks();
|
||||||
|
|
||||||
|
Result result = new Result();
|
||||||
|
|
||||||
|
if(srcblocks.size() != 0 && dstblocks.size() != 0) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
result.setType(ResultType.ErrorMegreUML2SVG);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/v1/uml2svg")
|
||||||
|
public Result uml2SVG(@RequestParam("data") String data) throws IOException {
|
||||||
String source = getUmlSource(data);
|
String source = getUmlSource(data);
|
||||||
List<BlockUml> blocks = new SourceStringReader(source).getBlocks();
|
List<BlockUml> blocks = new SourceStringReader(source).getBlocks();
|
||||||
// FileOutputStream os = new FileOutputStream(new File("./t.svg"));
|
// FileOutputStream os = new FileOutputStream(new File("./t.svg"));
|
||||||
|
@ -66,15 +72,26 @@ public class api {
|
||||||
Result result = new Result();
|
Result result = new Result();
|
||||||
if(blocks.size() != 0) {
|
if(blocks.size() != 0) {
|
||||||
for(BlockUml block: blocks) {
|
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();
|
OutputStream os = new ByteArrayOutputStream();
|
||||||
block.getDiagram().exportDiagram(os, 0, new FileFormatOption(FileFormat.SVG));
|
diagram.exportDiagram(os, 0, new FileFormatOption(FileFormat.SVG));
|
||||||
result.setType(ResultType.Source2SVG);
|
|
||||||
result.getContent().add(os.toString());
|
result.getContent().add(os.toString());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
result.setType(ResultType.ErrorSource2SVG);
|
result.setType(ResultType.ErrorSource2SVG);
|
||||||
|
log.debug( ResultType.ErrorSource2SVG + data);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,18 +1,18 @@
|
||||||
package com.yame.uml.model;
|
package com.yame.uml.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* result
|
* result
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Result {
|
public class Result {
|
||||||
|
|
||||||
public ResultType type;
|
|
||||||
public List<String> content;
|
|
||||||
|
|
||||||
|
private ResultType type;
|
||||||
|
private String msg;
|
||||||
|
private List<String> content;
|
||||||
|
|
||||||
public Result() {
|
public Result() {
|
||||||
content = new ArrayList<String>();
|
content = new ArrayList<String>();
|
||||||
|
@ -22,6 +22,14 @@ public class Result {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addContent(String content) {
|
||||||
|
this.content.add(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delContent(int idx) {
|
||||||
|
this.content.remove(idx);
|
||||||
|
}
|
||||||
|
|
||||||
public ResultType getType() {
|
public ResultType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
@ -29,4 +37,12 @@ public class Result {
|
||||||
public void setType(ResultType type) {
|
public void setType(ResultType type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getMsg() {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMsg(String msg) {
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,29 +1,36 @@
|
||||||
package com.yame.uml.model;
|
package com.yame.uml.model;
|
||||||
|
|
||||||
public enum ResultType {
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
Success("Success", 1),
|
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
|
||||||
Source2PNG("Source2PNG", 101),
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
Source2SVG("Source2SVG", 102),
|
|
||||||
|
|
||||||
Error("Error", 0),
|
|
||||||
ErrorSource2PNG("Error Source2PNG: source format is erorr", -101),
|
@JsonFormat(shape = Shape.OBJECT)
|
||||||
ErrorSource2SVG("Error Source2SVG: source format is erorr", -102),
|
public enum ResultType {
|
||||||
|
Success("Success", 1, true),
|
||||||
|
Source2PNG("Source2PNG", 101, true),
|
||||||
|
Source2SVG("Source2SVG", 102, true),
|
||||||
|
|
||||||
|
MegreUML2SVG("megreUML2SVG", 202, true),
|
||||||
|
|
||||||
|
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;
|
private int code;
|
||||||
|
@JsonProperty("success")
|
||||||
|
private boolean success;
|
||||||
|
|
||||||
private ResultType(String status, int code) {
|
private ResultType(String desc, int code, Boolean isSuccessed) {
|
||||||
this.status = status;
|
this.desc = desc;
|
||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
this.success = isSuccessed;
|
||||||
|
|
||||||
public String getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(String status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCode() {
|
public int getCode() {
|
||||||
|
@ -33,4 +40,20 @@ public enum ResultType {
|
||||||
public void setCode(int code) {
|
public void setCode(int code) {
|
||||||
this.code = 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;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user