Skip to content

Commit

Permalink
Added new experimental transporter module
Browse files Browse the repository at this point in the history
  • Loading branch information
FroMage committed Oct 11, 2023
1 parent 2ff5592 commit fd4c329
Show file tree
Hide file tree
Showing 16 changed files with 1,843 additions and 18 deletions.
5 changes: 5 additions & 0 deletions backoffice/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
<artifactId>quarkus-renarde-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.renarde</groupId>
<artifactId>quarkus-renarde-jpa-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.renarde</groupId>
<artifactId>quarkus-renarde-backoffice</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import jakarta.enterprise.context.RequestScoped;
import jakarta.persistence.Entity;
Expand All @@ -44,11 +44,11 @@
import io.quarkiverse.renarde.Controller;
import io.quarkiverse.renarde.backoffice.BackofficeController;
import io.quarkiverse.renarde.backoffice.BackofficeIndexController;
import io.quarkiverse.renarde.backoffice.deployment.ModelField.Type;
import io.quarkiverse.renarde.backoffice.impl.BackUtil;
import io.quarkiverse.renarde.backoffice.impl.CreateAction;
import io.quarkiverse.renarde.backoffice.impl.EditAction;
import io.quarkiverse.renarde.jpa.NamedBlob;
import io.quarkiverse.renarde.jpa.deployment.ModelField;
import io.quarkus.arc.Arc;
import io.quarkus.arc.ArcContainer;
import io.quarkus.arc.InstanceHandle;
Expand Down Expand Up @@ -171,14 +171,9 @@ public Optional<Variant> getVariant() {
entities.add(simpleName);

// collect fields
List<ModelField> fields = new ArrayList<>();
for (Entry<String, EntityField> entry : entityModel.fields.entrySet()) {
ModelField mf = new ModelField(entry.getValue(), entityName.toString(), metamodel.getMetamodelInfo(),
index.getIndex());
if (mf.type != Type.Ignore) {
fields.add(mf);
}
}
List<ModelField> fields = ModelField.loadModelFields(entityModel, metamodel.getMetamodelInfo(), index.getIndex());
// remove ID fields
fields = fields.stream().filter(modelField -> !modelField.id).collect(Collectors.toList());

generateEntityController(classInfo, index.getIndex(), entityName.toString(), entityController, simpleName, fields,
jaxrsOutput);
Expand Down Expand Up @@ -339,7 +334,7 @@ private boolean implementsInterface(ClassInfo entityClass, IndexView index, DotN
//
private void addBinaryFieldGetters(ClassCreator c, String controllerClass, String entityClass, List<ModelField> fields) {
for (ModelField field : fields) {
if (field.type == Type.Binary) {
if (field.type == ModelField.Type.Binary) {
// Add a method to read the binary field data
try (MethodCreator m = c.getMethodCreator(field.name + "ForBinary", Response.class, Long.class)) {
m.getParameterAnnotations(0).addAnnotation(RestPath.class).addValue("value", "id");
Expand Down Expand Up @@ -592,7 +587,7 @@ private void editOrCreateAction(ClassCreator c, String controllerClass, String e
ResultHandle value = null;
ResultHandle parameterValue = m.getMethodParam(i + offset);
i++;
if (field.type == Type.Text || field.type == Type.LargeText) {
if (field.type == ModelField.Type.Text || field.type == ModelField.Type.LargeText) {
if (field.entityField.descriptor.equals("Ljava/lang/String;")) {
value = m.invokeStaticMethod(
MethodDescriptor.ofMethod(BackUtil.class, "stringField", String.class, String.class),
Expand All @@ -605,7 +600,7 @@ private void editOrCreateAction(ClassCreator c, String controllerClass, String e
throw new RuntimeException(
"Unknown text field " + field + " descriptor: " + field.entityField.descriptor);
}
} else if (field.type == Type.Binary) {
} else if (field.type == ModelField.Type.Binary) {
// binary fields consume two parameters
ResultHandle parameterUnsetValue = parameterValue;
parameterValue = m.getMethodParam(i + offset);
Expand Down Expand Up @@ -666,7 +661,7 @@ private void editOrCreateAction(ClassCreator c, String controllerClass, String e
value = m.invokeStaticMethod(
MethodDescriptor.ofMethod(BackUtil.class, "integerWrapperField", Integer.class, String.class),
parameterValue);
} else if (field.type == Type.Number) {
} else if (field.type == ModelField.Type.Number) {
Class<?> primitiveClass;
switch (field.entityField.descriptor) {
case "B":
Expand Down
40 changes: 40 additions & 0 deletions jpa-deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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" 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.quarkiverse.renarde</groupId>
<artifactId>quarkus-renarde-parent</artifactId>
<version>3.0.5-SNAPSHOT</version>
</parent>
<artifactId>quarkus-renarde-jpa-deployment</artifactId>
<name>Quarkus - Renarde - JPA Deployment</name>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-panache-common-deployment</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>quarkus-renarde</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>quarkus-renarde-jpa</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package io.quarkiverse.renarde.backoffice.deployment;
package io.quarkiverse.renarde.jpa.deployment;

import java.lang.annotation.Annotation;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;

import jakarta.persistence.Column;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.ManyToOne;
Expand Down Expand Up @@ -48,8 +50,7 @@ public static enum Type {
Ignore,
MultiMultiRelation,
Binary,
JSON,
;
JSON;
}

private static final DotName DOTNAME_MANYTOMANY = DotName.createSimple(ManyToMany.class.getName());
Expand All @@ -63,6 +64,7 @@ public static enum Type {
private static final DotName DOTNAME_JDBC_TYPE_CODE = DotName.createSimple(JdbcTypeCode.class.getName());
private static final DotName DOTNAME_TYPES = DotName.createSimple(Types.class.getName());
private static final DotName DOTNAME_LOB = DotName.createSimple(Lob.class.getName());
private static final DotName DOTNAME_ID = DotName.createSimple(Id.class.getName());
public static final String NAMED_BLOB_DESCRIPTOR = "L" + NamedBlob.class.getName().replace('.', '/') + ";";

// For views
Expand All @@ -80,6 +82,8 @@ public static enum Type {
public List<Class<? extends Annotation>> validation = new ArrayList<>();
// use this rather than EntitiField.signature which is set later (why?)
public String signature;
public boolean relationOwner;
public boolean id;

public ModelField(EntityField entityField, String entityClass, MetamodelInfo metamodelInfo, IndexView index) {
this.name = entityField.name;
Expand All @@ -90,6 +94,7 @@ public ModelField(EntityField entityField, String entityClass, MetamodelInfo met
AnnotationInstance oneToOne = field.annotation(DOTNAME_ONETOONE);
AnnotationInstance column = field.annotation(DOTNAME_COLUMN);
AnnotationInstance jdbcTypeCode = field.annotation(DOTNAME_JDBC_TYPE_CODE);
this.id = field.annotation(DOTNAME_ID) != null;
if (jdbcTypeCode != null
&& jdbcTypeCode.value().asInt() == SqlTypes.JSON) {
this.type = Type.JSON;
Expand All @@ -109,7 +114,8 @@ public ModelField(EntityField entityField, String entityClass, MetamodelInfo met
min = Integer.MIN_VALUE;
max = Integer.MAX_VALUE;
step = 1;
} else if (entityField.descriptor.equals("J")) {
} else if (entityField.descriptor.equals("J")
|| entityField.descriptor.equals("Ljava/lang/Long;")) {
this.type = Type.Number;
min = Long.MIN_VALUE;
max = Long.MAX_VALUE;
Expand Down Expand Up @@ -169,6 +175,7 @@ public ModelField(EntityField entityField, String entityClass, MetamodelInfo met
String inverseField = mappedBy.asString();
// FIXME: inheritance
this.inverseField = relationModel.fields.get(inverseField);
this.relationOwner = false;
} else if (field.hasAnnotation(DOTNAME_MANYTOMANY)) {
this.type = Type.MultiMultiRelation;
this.relationClass = field.type().asParameterizedType().arguments().get(0).name().toString();
Expand All @@ -179,6 +186,7 @@ public ModelField(EntityField entityField, String entityClass, MetamodelInfo met
String inverseField = mappedBy.asString();
// FIXME: inheritance
this.inverseField = relationModel.fields.get(inverseField);
this.relationOwner = false;
} else {
ClassInfo relationClassInfo = index.getClassByName(DotName.createSimple(relationClass));
for (FieldInfo relationField : relationClassInfo.fields()) {
Expand All @@ -196,16 +204,19 @@ public ModelField(EntityField entityField, String entityClass, MetamodelInfo met
throw new RuntimeException(
"Failed to find owning side of @ManyToMany from " + field + " in relation type " + relationClass);
}
this.relationOwner = true;
}
} else if (oneToOne != null
&& oneToOne.value("mappedBy") != null) {
// actually we may want to support this in the future too?
this.type = Type.Ignore;
this.relationOwner = false;
} else if (field.hasAnnotation(DOTNAME_MANYTOONE)
|| (oneToOne != null
&& oneToOne.value("mappedBy") == null)) {
this.type = Type.Relation;
this.relationClass = entityField.descriptor.substring(1, entityField.descriptor.length() - 1).replace('/', '.');
this.relationOwner = true;
} else {
// see if we can find what to do with it
ClassInfo fieldClassInfo = index.getClassByName(field.type().name());
Expand All @@ -231,4 +242,28 @@ public String getClassName() {
public String toString() {
return "ModelField " + name + " of type " + entityField.descriptor;
}

public static List<ModelField> loadModelFields(EntityModel entityModel, MetamodelInfo metamodelInfo,
IndexView index) {
List<ModelField> fields = new ArrayList<>();
addFields(fields, entityModel, metamodelInfo, index);
return fields;
}

private static void addFields(List<ModelField> fields, EntityModel entityModel, MetamodelInfo metamodelInfo,
IndexView index) {
for (Entry<String, EntityField> entry : entityModel.fields.entrySet()) {
ModelField mf = new ModelField(entry.getValue(), entityModel.name, metamodelInfo,
index);
if (mf.type != Type.Ignore) {
fields.add(mf);
}
}
if (entityModel.superClassName != null) {
EntityModel superModel = metamodelInfo.getEntityModel(entityModel.superClassName);
if (superModel != null) {
addFields(fields, superModel, metamodelInfo, index);
}
}
}
}
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
<module>jpa</module>
<module>pdf</module>
<module>barcode</module>
<module>jpa-deployment</module>
<module>test</module>
<module>backoffice</module>
<module>transporter</module>
</modules>
<scm>
<connection>:git:git@github.com:quarkiverse/quarkus-renarde.git</connection>
Expand Down
128 changes: 128 additions & 0 deletions transporter/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?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" 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.quarkiverse.renarde</groupId>
<artifactId>quarkus-renarde-transporter-parent</artifactId>
<version>3.0.5-SNAPSHOT</version>
</parent>
<artifactId>quarkus-renarde-transporter-deployment</artifactId>
<name>Quarkus - Renarde - Transporter - Deployment</name>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-qute-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-qute-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-panache-hibernate-common-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-datasource-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-narayana-jta-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-caffeine-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-webjars-locator-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.renarde</groupId>
<artifactId>quarkus-renarde-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.renarde</groupId>
<artifactId>quarkus-renarde-jpa-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.renarde</groupId>
<artifactId>quarkus-renarde-transporter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-core</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkiverse.renarde</groupId>
<artifactId>quarkus-renarde-security</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit fd4c329

Please sign in to comment.