generated from giis-uniovi/samples-giis-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63cd358
commit 984c81c
Showing
79 changed files
with
9,936 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> | ||
<attributes> | ||
<attribute name="test" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="optional" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
<attribute name="optional" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>tdrules-client-oa</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
eclipse.preferences.version=1 | ||
encoding//src/main/java=UTF-8 | ||
encoding//src/test/java=UTF-8 | ||
encoding//src/test/resources=UTF-8 | ||
encoding/<project>=UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore | ||
org.eclipse.jdt.core.compiler.release=disabled | ||
org.eclipse.jdt.core.compiler.source=1.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.giis-uniovi</groupId> | ||
<artifactId>tdrules</artifactId> | ||
<version>4.2.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>tdrules-client-oa</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>tdrules-client-oa</name> | ||
<description>Client api to generate the data store schema from an OpenApi specification</description> | ||
<url>http://github.com/giis-uniovi/tdrules</url> | ||
<organization> | ||
<name>Software Engineering Research Group (GIIS) - Universidad de Oviedo, ES</name> | ||
<url>http://giis.uniovi.es/</url> | ||
</organization> | ||
|
||
<properties> | ||
<!--additional dependencies for openapi client apache http + jackson --> | ||
<swagger-annotations-version>1.6.6</swagger-annotations-version> | ||
|
||
<jackson-databind-nullable-version>0.2.6</jackson-databind-nullable-version> | ||
|
||
<jakarta-annotation-version>2.1.1</jakarta-annotation-version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.github.giis-uniovi</groupId> | ||
<artifactId>tdrules-model</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.giis-uniovi</groupId> | ||
<artifactId>tdrules-store-shared</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.swagger.parser.v3</groupId> | ||
<artifactId>swagger-parser</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.javiertuya</groupId> | ||
<artifactId>visual-assert</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.javiertuya</groupId> | ||
<artifactId>portable-java</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-slf4j2-impl</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-report-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-antrun-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
119 changes: 119 additions & 0 deletions
119
tdrules-client-oa/src/main/java/giis/tdrules/client/oa/MermaidWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package giis.tdrules.client.oa; | ||
|
||
import java.util.HashSet; | ||
|
||
import java.util.Set; | ||
|
||
import giis.tdrules.client.oa.transform.UpstreamAttribute; | ||
import giis.tdrules.openapi.model.Ddl; | ||
import giis.tdrules.openapi.model.TdAttribute; | ||
import giis.tdrules.openapi.model.TdEntity; | ||
import giis.tdrules.openapi.model.TdSchema; | ||
|
||
/** | ||
* Produces a Mermaid string with a graphical representation of a TdSchema | ||
*/ | ||
public class MermaidWriter { | ||
|
||
private TdSchema schema; | ||
private StringBuilder sb; // Accumulates the mermaid written text | ||
private Set<String> drawn; // Already drawn entities | ||
|
||
public MermaidWriter(TdSchema schema) { | ||
this.schema = schema; | ||
} | ||
|
||
/** | ||
* Returns the Mermaid representation of the TdSchema indicated in the instantiation. | ||
* This string can be pasted in the mermaid live editor https://mermaid.live/ | ||
* or inserted in a Markdown documentation file | ||
*/ | ||
public String getMermaid() { | ||
sb = new StringBuilder(); | ||
drawn = new HashSet<>(); | ||
sb.append("classDiagram"); | ||
// First all entity relations and later the type definitios | ||
// to allow better separation in the mermaid display | ||
for (TdEntity entity : schema.getEntities()) | ||
drawEntityRelations(entity); | ||
for (TdEntity entity : schema.getEntities()) | ||
drawTypeDefinitions(entity); | ||
// If there is any entity not connected to any other, it is drawn at the end | ||
drawUnreferenced(schema); | ||
|
||
// Schema may contain information about the paths for POST operations, | ||
// add them to the mermaid diagram as methods | ||
for (TdEntity entity : schema.getEntities()) | ||
drawPostOperations(entity); | ||
|
||
return sb.toString(); | ||
} | ||
|
||
private void drawEntityRelations(TdEntity entity) { | ||
for (TdAttribute attribute : giis.tdrules.model.ModelUtil.safe(entity.getAttributes())) { | ||
if (attribute.isRid()) { | ||
// relation to another entity is drawn differently if it is from an array | ||
if (entity.isArray()) { | ||
// When the rid entity is not the immediate adjacent upstream, arrays have an extended attribute | ||
// to force drawing the visually correct relation that overrides the rid attribute | ||
String rid = attribute.getRidEntity(); | ||
String drawRid = new UpstreamAttribute(schema).getMermaidRidEntity(entity); | ||
if (drawRid != null && !"".equals(drawRid)) | ||
rid = drawRid; | ||
drawReferenceFromArray(entity.getName(), rid); | ||
} else { | ||
drawReferenceToEntity(entity.getName(), attribute.getRidEntity()); | ||
} | ||
} else if (attribute.isType()) | ||
drawCompositeType(attribute.getDatatype(), entity.getName()); | ||
} | ||
} | ||
|
||
private void drawTypeDefinitions(TdEntity entity) { | ||
if ((entity.isArray() || entity.isType()) | ||
&& (!"".equals(entity.getSubtype()))) | ||
drawCompositeDefinition(entity.getName(), entity.getSubtype()); | ||
} | ||
|
||
private void drawPostOperations(TdEntity entity) { | ||
for (Ddl operation : giis.tdrules.model.ModelUtil.safe(entity.getDdls())) | ||
drawMethod(entity.getName(), operation.getCommand(), operation.getQuery()); | ||
} | ||
|
||
private void drawCompositeType(String contained, String container) { | ||
sb.append("\n ").append(container).append(" *--\"1\" ").append(contained); | ||
drawnAdd(container, contained); | ||
} | ||
|
||
private void drawReferenceToEntity(String referencing, String referenced) { | ||
sb.append("\n ").append(referenced).append(" <--\"*\" ").append(referencing); | ||
drawnAdd(referencing, referenced); | ||
} | ||
|
||
private void drawReferenceFromArray(String referencing, String referenced) { | ||
sb.append("\n ").append(referenced).append(" *--\"*\" ").append(referencing); | ||
drawnAdd(referencing, referenced); | ||
} | ||
|
||
private void drawCompositeDefinition(String contained, String container) { | ||
sb.append("\n ").append(contained).append(" ..|> ").append(container); | ||
drawnAdd(container, contained); | ||
} | ||
|
||
private void drawMethod(String entity, String operation, String arguments) { | ||
sb.append("\n ").append(entity).append(": +") | ||
.append(operation).append("(").append(arguments).append(")"); | ||
} | ||
|
||
private void drawUnreferenced(TdSchema schema) { | ||
for (TdEntity entity : schema.getEntities()) | ||
if (!drawn.contains(entity.getName())) | ||
sb.append("\n class ").append(entity.getName()); | ||
} | ||
|
||
private void drawnAdd(String ref1, String ref2) { | ||
drawn.add(ref1); | ||
drawn.add(ref2); | ||
} | ||
|
||
} |
Oops, something went wrong.