Skip to content

Commit

Permalink
Migrate OpenApi Client module
Browse files Browse the repository at this point in the history
  • Loading branch information
javiertuya committed Jun 22, 2024
1 parent 63cd358 commit f8d7d6d
Show file tree
Hide file tree
Showing 72 changed files with 9,930 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<module>tdrules-store-shared</module>
<module>tdrules-store-rdb</module>
<module>tdrules-client-rdb</module>
<module>tdrules-client-oa</module>
</modules>

<dependencyManagement>
Expand Down
5 changes: 5 additions & 0 deletions tdrules-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
<artifactId>tdrules-client-rdb</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.github.giis-uniovi</groupId>
<artifactId>tdrules-client-oa</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
40 changes: 40 additions & 0 deletions tdrules-client-oa/.classpath
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>
23 changes: 23 additions & 0 deletions tdrules-client-oa/.project
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>
5 changes: 5 additions & 0 deletions tdrules-client-oa/.settings/org.eclipse.core.resources.prefs
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
8 changes: 8 additions & 0 deletions tdrules-client-oa/.settings/org.eclipse.jdt.core.prefs
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
4 changes: 4 additions & 0 deletions tdrules-client-oa/.settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
97 changes: 97 additions & 0 deletions tdrules-client-oa/pom.xml
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.1.2-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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package giis.tdrules.client.oa;

import java.util.HashSet;

import java.util.Set;

import giis.tdrules.client.oa.transform.UpstreamAttribute;
import giis.tdrules.model.EntityTypes;
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 (EntityTypes.DT_ARRAY.equals(entity.getEntitytype())) {
// 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 (EntityTypes.DT_TYPE.equals(attribute.getCompositetype()))
drawCompositeType(attribute.getDatatype(), entity.getName());
}
}

private void drawTypeDefinitions(TdEntity entity) {
if ((EntityTypes.DT_ARRAY.equals(entity.getEntitytype()) || EntityTypes.DT_TYPE.equals(entity.getEntitytype()))
&& (!"".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);
}

}
Loading

0 comments on commit f8d7d6d

Please sign in to comment.