Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
6ccce206b9 |
15
.classpath
15
.classpath
@ -30,19 +30,16 @@
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="ignore_optional_problems" value="true"/>
|
||||
<attribute name="m2e-apt" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="target/generated-sources/annotations">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
16
.github/workflows/assign-pr-author.yml
vendored
16
.github/workflows/assign-pr-author.yml
vendored
@ -1,16 +0,0 @@
|
||||
---
|
||||
name: "Assign PR Author as Assignee"
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
|
||||
jobs:
|
||||
assign-pr-author-as-assignee:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Assign Author as Assignee"
|
||||
uses: itsOliverBott/assign-pr-author-as-assignee@latest
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
33
.github/workflows/check-title.yml
vendored
33
.github/workflows/check-title.yml
vendored
@ -1,33 +0,0 @@
|
||||
---
|
||||
name: "Check PR title"
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
- edited
|
||||
- synchronize
|
||||
- ready_for_review
|
||||
- reopened
|
||||
|
||||
jobs:
|
||||
check-title:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Check title"
|
||||
uses: Slashgear/action-check-pr-title@v4.3.0
|
||||
with:
|
||||
regexp: "\\[(API,)?(API|DEV-OPS|DOC|FEAT|FIX|FIX\\-CI|STYLE)\\]( \\([A-Za-z0-9.\\-]+\\))? [A-Za-z0-9 ,.'\\-!]+$"
|
||||
helpMessage: |
|
||||
Title of the PR MUST respect format: "[{TYPE}] clear description without typos in english" with {TYPE}:
|
||||
* [API] Change API that permit to access on the application (un-compatibility only). This one can specifically added with [API,{TYPE}]
|
||||
* [DEV-OPS] Update automatic build system, method to deliver application/packages, ...
|
||||
* [DOC] Update or add some documentation.
|
||||
* [FEAT] Develop a new feature
|
||||
* [FIX] When fixing issue
|
||||
* [FIX-CI] When the CI fail to build and we apply a correction to set it work again.
|
||||
* [STYLE] Update of the style tools/checker, or add/remove rules.
|
||||
Examples:
|
||||
[FEAT] My beautiful feature
|
||||
[API,FIX] Change API to fix typo
|
||||
[FIX] (module) Correct part of ...
|
12
.github/workflows/maven.yml
vendored
12
.github/workflows/maven.yml
vendored
@ -10,17 +10,19 @@ name: Java CI with Maven
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- develop
|
||||
branches: [ "develop" ]
|
||||
pull_request:
|
||||
branches: [ "develop" ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '21'
|
||||
distribution: 'temurin'
|
||||
@ -32,4 +34,4 @@ jobs:
|
||||
|
||||
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
|
||||
- name: Update dependency graph
|
||||
uses: advanced-security/maven-dependency-submission-action@4f64ddab9d742a4806eeb588d238e4c311a8397d
|
||||
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
|
||||
|
4
.project
4
.project
@ -11,12 +11,12 @@
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>edu.umd.cs.findbugs.plugin.eclipse.findbugsBuilder</name>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<name>edu.umd.cs.findbugs.plugin.eclipse.findbugsBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
|
87
pom.xml
87
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>kangaroo-and-rabbit</groupId>
|
||||
<artifactId>archidata</artifactId>
|
||||
<version>0.19.0</version>
|
||||
<version>0.11.0</version>
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
<maven.compiler.version>3.1</maven.compiler.version>
|
||||
@ -14,13 +14,36 @@
|
||||
<jaxb.version>2.3.1</jaxb.version>
|
||||
<istack.version>4.1.1</istack.version>
|
||||
</properties>
|
||||
<!--
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>gitea</id>
|
||||
<url>https://gitea.atria-soft.org/api/packages/kangaroo-and-rabbit/maven</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
-->
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>gitea-neofarm</id>
|
||||
<url>https://gitea.neo.farm/api/packages/kangaroo-and-rabbit/maven</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>gitea-neofarm</id>
|
||||
<url>https://gitea.neo.farm/api/packages/kangaroo-and-rabbit/maven</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>gitea-neofarm</id>
|
||||
<url>https://gitea.neo.farm/api/packages/kangaroo-and-rabbit/maven</url>
|
||||
</snapshotRepository>
|
||||
<!--
|
||||
<repository>
|
||||
<id>gitea-neofarm</id>
|
||||
<url>https://gitea.neo.farm/api/packages/kangaroo-and-rabbit/maven</url>
|
||||
</repository>
|
||||
-->
|
||||
<!--
|
||||
<repository>
|
||||
<id>gitea</id>
|
||||
<url>https://gitea.atria-soft.org/api/packages/kangaroo-and-rabbit/maven</url>
|
||||
@ -29,6 +52,15 @@
|
||||
<id>gitea</id>
|
||||
<url>https://gitea.atria-soft.org/api/packages/kangaroo-and-rabbit/maven</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>github</id>
|
||||
<url>https://maven.pkg.github.com/kangaroo-and-rabbit/archidata</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>github</id>
|
||||
<url>https://maven.pkg.github.com/kangaroo-and-rabbit/archidata</url>
|
||||
</snapshotRepository>
|
||||
-->
|
||||
</distributionManagement>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
@ -54,30 +86,6 @@
|
||||
<version>2.1.0-alpha1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- Decode webP images -->
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-webp</artifactId>
|
||||
<version>3.11.0</version>
|
||||
</dependency>
|
||||
<!-- Decode JPEG image -->
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-jpeg</artifactId>
|
||||
<version>3.11.0</version>
|
||||
</dependency>
|
||||
<!-- Encode file in webp -->
|
||||
<dependency>
|
||||
<groupId>com.github.gotson</groupId>
|
||||
<artifactId>webp-imageio</artifactId>
|
||||
<version>0.2.2</version>
|
||||
</dependency>
|
||||
<!-- Detect type of a file with mime type -->
|
||||
<dependency>
|
||||
<groupId>org.apache.tika</groupId>
|
||||
<artifactId>tika-core</artifactId>
|
||||
<version>3.0.0-BETA2</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-multipart -->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
@ -120,13 +128,11 @@
|
||||
<artifactId>istack-commons-runtime</artifactId>
|
||||
<version>${istack.version}</version>
|
||||
</dependency>
|
||||
<!-- continu to be needed ??? -->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
|
||||
<artifactId>jersey-test-framework-provider-grizzly2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- Serialize and un-serialize request in JSON-->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
@ -134,41 +140,40 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.18.0-rc1</version>
|
||||
<version>2.17.1</version>
|
||||
</dependency>
|
||||
<!-- encode output in CSV -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-csv</artifactId>
|
||||
<version>2.18.0-rc1</version>
|
||||
<version>2.17.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<version>2.18.0-rc1</version>
|
||||
<version>2.17.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.servlet</groupId>
|
||||
<artifactId>jakarta.servlet-api</artifactId>
|
||||
<version>6.1.0</version>
|
||||
<version>6.1.0-M2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Interface for My-sql & sqlite DB -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>9.0.0</version>
|
||||
<version>8.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.46.1.0</version>
|
||||
<version>3.46.0.0</version>
|
||||
</dependency>
|
||||
<!-- Interface for JWT token -->
|
||||
<dependency>
|
||||
<groupId>com.nimbusds</groupId>
|
||||
<artifactId>nimbus-jose-jwt</artifactId>
|
||||
<version>9.41.1</version>
|
||||
<version>9.39.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.persistence</groupId>
|
||||
@ -179,13 +184,13 @@
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-jaxrs2-jakarta</artifactId>
|
||||
<version>2.2.23</version>
|
||||
<version>2.2.22</version>
|
||||
</dependency>
|
||||
<!-- spotbug tooling -->
|
||||
<dependency>
|
||||
<groupId>com.github.spotbugs</groupId>
|
||||
<artifactId>spotbugs-annotations</artifactId>
|
||||
<version>4.8.6</version>
|
||||
<version>4.8.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!--
|
||||
@ -196,24 +201,24 @@
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.11.0</version>
|
||||
<version>5.11.0-M2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.11.0</version>
|
||||
<version>5.11.0-M2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.revelc.code.formatter</groupId>
|
||||
<artifactId>formatter-maven-plugin</artifactId>
|
||||
<version>2.24.1</version>
|
||||
<version>2.24.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
<version>3.3.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
@ -1,19 +0,0 @@
|
||||
package org.kar.archidata.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import jakarta.ws.rs.HttpMethod;
|
||||
|
||||
/**
|
||||
* Indicates that the annotated method responds to HTTP ARCHIVE requests.
|
||||
*
|
||||
* @author Edouard DUPIN
|
||||
* @see HttpMethod
|
||||
*/
|
||||
@Target({ ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@HttpMethod("ARCHIVE")
|
||||
public @interface ARCHIVE {}
|
@ -17,11 +17,8 @@ import jakarta.persistence.Column;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@ -83,14 +80,6 @@ public class AnnotationTools {
|
||||
return ((Schema) annotation[0]).example();
|
||||
}
|
||||
|
||||
public static boolean getNoWriteSpecificMode(final Class<?> element) {
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(NoWriteSpecificMode.class);
|
||||
if (annotation.length == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String getSchemaDescription(final Class<?> element) throws DataAccessException {
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Schema.class);
|
||||
if (annotation.length == 0) {
|
||||
@ -139,30 +128,18 @@ public class AnnotationTools {
|
||||
return ((DefaultValue) annotation[0]).value();
|
||||
}
|
||||
|
||||
public static ManyToOne getManyToOne(final Field element) {
|
||||
public static ManyToOne getManyToOne(final Field element) throws DataAccessException {
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ManyToOne.class);
|
||||
if (annotation.length == 0) {
|
||||
return null;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new DataAccessException(
|
||||
"Must not have more than 1 element @ManyToOne on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
return (ManyToOne) annotation[0];
|
||||
}
|
||||
|
||||
public static ManyToMany getManyToMany(final Field element) {
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ManyToMany.class);
|
||||
if (annotation.length == 0) {
|
||||
return null;
|
||||
}
|
||||
return (ManyToMany) annotation[0];
|
||||
}
|
||||
|
||||
public static OneToMany getOneToMany(final Field element) {
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(OneToMany.class);
|
||||
if (annotation.length == 0) {
|
||||
return null;
|
||||
}
|
||||
return (OneToMany) annotation[0];
|
||||
}
|
||||
|
||||
public static DataJson getDataJson(final Field element) throws DataAccessException {
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(DataJson.class);
|
||||
if (annotation.length == 0) {
|
||||
@ -236,14 +213,6 @@ public class AnnotationTools {
|
||||
return ((Pattern) annotation[0]).regexp();
|
||||
}
|
||||
|
||||
public static boolean getConstraintsEmail(final Field element) throws DataAccessException {
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Email.class);
|
||||
if (annotation.length == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isAnnotationGroup(final Field field, final Class<?> annotationType) {
|
||||
try {
|
||||
final Annotation[] anns = field.getAnnotations();
|
||||
@ -267,11 +236,15 @@ public class AnnotationTools {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getFieldName(final Field element) {
|
||||
public static String getFieldName(final Field element) throws DataAccessException {
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Column.class);
|
||||
if (annotation.length == 0) {
|
||||
return element.getName();
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new DataAccessException(
|
||||
"Must not have more than 1 element @Column on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
final String name = ((Column) annotation[0]).name();
|
||||
if (name.isBlank()) {
|
||||
return element.getName();
|
||||
|
@ -1,13 +0,0 @@
|
||||
package org.kar.archidata.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/** When we wend to have only One type for read and write mode (Wrapping API). */
|
||||
@Target({ ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface NoWriteSpecificMode {
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package org.kar.archidata.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import jakarta.ws.rs.HttpMethod;
|
||||
|
||||
/**
|
||||
* Indicates that the annotated method responds to HTTP RESTORE requests.
|
||||
*
|
||||
* @author Edouard DUPIN
|
||||
* @see HttpMethod
|
||||
*/
|
||||
@Target({ ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@HttpMethod("RESTORE")
|
||||
public @interface RESTORE {}
|
@ -5,8 +5,8 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ ElementType.PARAMETER })
|
||||
@Target({ ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface FormDataOptional {
|
||||
|
||||
public @interface SQLWhere {
|
||||
String clause();
|
||||
}
|
@ -304,11 +304,9 @@ public class DataResource {
|
||||
// logger.info("===================================================");
|
||||
final Data value = getSmall(uuid);
|
||||
if (value == null) {
|
||||
LOGGER.warn("Request data that does not exist : {}", uuid);
|
||||
return Response.status(404).entity("media NOT FOUND: " + uuid).type("text/plain").build();
|
||||
}
|
||||
try {
|
||||
LOGGER.warn("Generate stream : {}", uuid);
|
||||
return buildStream(getFileData(uuid), range,
|
||||
value.mimeType == null ? "application/octet-stream" : value.mimeType);
|
||||
} catch (final Exception ex) {
|
||||
@ -328,10 +326,10 @@ public class DataResource {
|
||||
@QueryParam(HttpHeaders.AUTHORIZATION) final String token,
|
||||
@HeaderParam("Range") final String range,
|
||||
@PathParam("uuid") final UUID uuid) throws FailException {
|
||||
final GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
||||
LOGGER.info("===================================================");
|
||||
LOGGER.info("== DATA retrieveDataThumbnailId ? {}", (gc == null ? "null" : gc.userByToken));
|
||||
LOGGER.info("===================================================");
|
||||
// GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
||||
// logger.info("===================================================");
|
||||
// logger.info("== DATA retrieveDataThumbnailId ? {}", (gc==null?"null":gc.user));
|
||||
// logger.info("===================================================");
|
||||
final Data value = getSmall(uuid);
|
||||
if (value == null) {
|
||||
return Response.status(404).entity("media NOT FOUND: " + uuid).type("text/plain").build();
|
||||
@ -352,43 +350,31 @@ public class DataResource {
|
||||
} catch (final IOException ex) {
|
||||
throw new FailException(Response.Status.INTERNAL_SERVER_ERROR, "Fail to READ the image", ex);
|
||||
}
|
||||
LOGGER.info("input size image: {}x{} type={}", inputImage.getWidth(), inputImage.getHeight(),
|
||||
inputImage.getType());
|
||||
final int scaledWidth = 250;
|
||||
final int scaledHeight = (int) ((float) inputImage.getHeight() / (float) inputImage.getWidth()
|
||||
* scaledWidth);
|
||||
|
||||
// creates output image
|
||||
final BufferedImage outputImage = new BufferedImage(scaledWidth, scaledHeight, inputImage.getType());
|
||||
|
||||
// scales the input image to the output image
|
||||
final Graphics2D g2d = outputImage.createGraphics();
|
||||
LOGGER.info("output size image: {}x{}", scaledWidth, scaledHeight);
|
||||
g2d.drawImage(inputImage, 0, 0, scaledWidth, scaledHeight, null);
|
||||
g2d.dispose();
|
||||
for (final String data : ImageIO.getWriterFormatNames()) {
|
||||
LOGGER.info("availlable format: {}", data);
|
||||
}
|
||||
// create the output stream:
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
// TODO: check how to remove buffer file !!! here, it is not needed at all...
|
||||
//ImageIO.write(outputImage, "JPEG", baos);
|
||||
//ImageIO.write(outputImage, "png", baos);
|
||||
ImageIO.write(outputImage, "WebP", baos);
|
||||
ImageIO.write(outputImage, "JPG", baos);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
return Response.status(500).entity("Internal Error: resize fail: " + e.getMessage()).type("text/plain")
|
||||
.build();
|
||||
}
|
||||
final byte[] imageData = baos.toByteArray();
|
||||
LOGGER.info("output length {}", imageData.length);
|
||||
// Response.ok(new ByteArrayInputStream(imageData)).build();
|
||||
final Response.ResponseBuilder out = Response.ok(imageData).header(HttpHeaders.CONTENT_LENGTH,
|
||||
imageData.length);
|
||||
//out.type("image/jpeg");
|
||||
out.type("image/webp");
|
||||
//out.type("image/png");
|
||||
out.type("image/jpeg");
|
||||
// TODO: move this in a decorator !!!
|
||||
final CacheControl cc = new CacheControl();
|
||||
cc.setMaxAge(3600);
|
||||
@ -480,9 +466,8 @@ public class DataResource {
|
||||
to = file.length() - 1;
|
||||
}
|
||||
final String responseRange = String.format("bytes %d-%d/%d", from, to, file.length());
|
||||
// LOGGER.info("responseRange: {}", responseRange);
|
||||
try {
|
||||
final RandomAccessFile raf = new RandomAccessFile(file, "r");
|
||||
// logger.info("responseRange: {}", responseRange);
|
||||
try (final RandomAccessFile raf = new RandomAccessFile(file, "r")) {
|
||||
raf.seek(from);
|
||||
|
||||
final long len = to - from + 1;
|
||||
|
@ -58,4 +58,5 @@ public class MediaStreamer implements StreamingOutput {
|
||||
public long getLenth() {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,43 +0,0 @@
|
||||
package org.kar.archidata.api;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.client.Client;
|
||||
import jakarta.ws.rs.client.ClientBuilder;
|
||||
import jakarta.ws.rs.client.WebTarget;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.Response.Status;
|
||||
|
||||
@Path("/proxy")
|
||||
//@Produces(MediaType.APPLICATION_JSON)
|
||||
public class ProxyResource {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ProxyResource.class);
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
public Response getImageFromUrl(@QueryParam("url") final String url) {
|
||||
if (url == null || url.isEmpty()) {
|
||||
return Response.status(Status.BAD_REQUEST).entity("URL manquante").build();
|
||||
}
|
||||
final Client client = ClientBuilder.newClient();
|
||||
try {
|
||||
final WebTarget target = client.target(url);
|
||||
final Response response = target.request().get();
|
||||
if (response.getStatus() != 200) {
|
||||
return Response.status(Status.BAD_GATEWAY).entity("Can not get the image : " + response.getStatus())
|
||||
.build();
|
||||
}
|
||||
return Response.ok(response.readEntity(byte[].class)).header("Access-Control-Allow-Origin", "*")
|
||||
.header("Content-Type", response.getHeaderString("Content-Type")).build();
|
||||
} catch (final Exception e) {
|
||||
return Response.status(Status.INTERNAL_SERVER_ERROR).entity("SERVER internal error : " + e.getMessage())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
@ -3,14 +3,12 @@ package org.kar.archidata.catcher;
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.kar.archidata.annotation.NoWriteSpecificMode;
|
||||
import org.kar.archidata.tools.UuidUtils;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
@NoWriteSpecificMode
|
||||
public class RestErrorResponse {
|
||||
public UUID uuid = UuidUtils.nextUUID();
|
||||
@NotNull
|
||||
|
@ -20,7 +20,6 @@ public class WebApplicationExceptionCatcher implements ExceptionMapper<WebApplic
|
||||
}
|
||||
|
||||
private RestErrorResponse build(final WebApplicationException exception) {
|
||||
exception.printStackTrace();
|
||||
return new RestErrorResponse(exception.getResponse().getStatusInfo().toEnum(), "Catch system exception",
|
||||
exception.getMessage());
|
||||
}
|
||||
|
@ -1246,10 +1246,6 @@ public class DataAccess {
|
||||
|
||||
public static void addElement(final PreparedStatement ps, final Object value, final CountInOut iii)
|
||||
throws Exception {
|
||||
if (value == null) {
|
||||
ps.setNull(iii.value, Types.INTEGER);
|
||||
return;
|
||||
}
|
||||
if (value instanceof final UUID tmp) {
|
||||
final byte[] dataByte = UuidUtils.asBytes(tmp);
|
||||
ps.setBytes(iii.value, dataByte);
|
||||
@ -1301,7 +1297,6 @@ public class DataAccess {
|
||||
throws SQLException, IOException {
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||
LOGGER.info("Query : '{}'", query);
|
||||
try (final Statement stmt = entry.connection.createStatement()) {
|
||||
return stmt.executeUpdate(query);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ import jakarta.persistence.GenerationType;
|
||||
public class DataFactory {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(DataFactory.class);
|
||||
|
||||
public static String convertTypeInSQL(final Class<?> type, final String fieldName) throws DataAccessException {
|
||||
public static String convertTypeInSQL(final Class<?> type, final String fieldName) throws Exception {
|
||||
if (!"sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||
if (type == UUID.class) {
|
||||
return "binary(16)";
|
||||
@ -165,7 +165,7 @@ public class DataFactory {
|
||||
final String comment = AnnotationTools.getComment(elem);
|
||||
final String defaultValue = AnnotationTools.getDefault(elem);
|
||||
|
||||
if (mainTableBuilder.toString().length() == 0) {
|
||||
if (fieldId == 0) {
|
||||
mainTableBuilder.append("\n\t\t`");
|
||||
} else {
|
||||
mainTableBuilder.append(",\n\t\t`");
|
||||
@ -404,7 +404,6 @@ public class DataFactory {
|
||||
}
|
||||
final boolean dataInThisObject = tmpOut.toString().length() > 0;
|
||||
if (dataInThisObject) {
|
||||
LOGGER.info("Previous Object : '{}'", reverseOut.toString());
|
||||
final boolean dataInPreviousObject = reverseOut.toString().length() > 0;
|
||||
if (dataInPreviousObject) {
|
||||
tmpOut.append(", ");
|
||||
|
@ -23,16 +23,13 @@ import org.kar.archidata.dataAccess.addOn.model.TableCoversLongUUID;
|
||||
import org.kar.archidata.dataAccess.addOn.model.TableCoversUUIDLong;
|
||||
import org.kar.archidata.dataAccess.addOn.model.TableCoversUUIDUUID;
|
||||
import org.kar.archidata.dataAccess.options.OverrideTableName;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
@ -45,7 +42,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLFieldType(final Field elem) throws DataAccessException {
|
||||
public String getSQLFieldType(final Field elem) throws Exception {
|
||||
final String fieldName = AnnotationTools.getFieldName(elem);
|
||||
return DataFactory.convertTypeInSQL(String.class, fieldName);
|
||||
}
|
||||
@ -154,10 +151,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
LOGGER.warn("Maybe fail to translate Model in datajson list: List<{}>", listClass.getCanonicalName());
|
||||
}
|
||||
final TypeFactory typeFactory = objectMapper.getTypeFactory();
|
||||
final JavaType fieldType = typeFactory.constructType(field.getGenericType());
|
||||
final Object dataParsed = objectMapper.readValue(jsonData, fieldType);
|
||||
//final Object dataParsed = objectMapper.readValue(jsonData, field.getType());
|
||||
final Object dataParsed = objectMapper.readValue(jsonData, field.getType());
|
||||
field.set(data, dataParsed);
|
||||
}
|
||||
}
|
||||
@ -194,21 +188,9 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a remoteKey to the covers list of a data entry identified by the given class type and ID.
|
||||
* If the covers list is null, it initializes it. If the remoteKey already exists in the list,
|
||||
* the method returns without making any changes.
|
||||
*
|
||||
* @param clazz The class type to retrieve the table name from.
|
||||
* @param id The ID of the data object to fetch.
|
||||
* @param column The name of the column (currently not used, but may be used for specifying a field name).
|
||||
* @param remoteKey The UUID to add to the covers list.
|
||||
* @throws Exception If an error occurs during data retrieval or update.
|
||||
*/
|
||||
public static void addLink(final Class<?> clazz, final Long id, final String column, final UUID remoteKey)
|
||||
throws Exception {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
// TODO: Get primary key name
|
||||
final TableCoversLongUUID data = DataAccess.get(TableCoversLongUUID.class, id,
|
||||
new OverrideTableName(tableName));
|
||||
if (data.covers == null) {
|
||||
@ -223,21 +205,10 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));// TODO: ,new OverrideFieldName("covers", column));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a remoteKey to the covers list of a data entry identified by the given class type and ID.
|
||||
* If the covers list is null, it initializes it. If the remoteKey already exists in the list,
|
||||
* the method returns without making any changes.
|
||||
*
|
||||
* @param clazz The class type to retrieve the table name from.
|
||||
* @param id The ID of the data object to fetch.
|
||||
* @param column The name of the column (currently not used, but may be used for specifying a field name).
|
||||
* @param remoteKey The UUID to add to the covers list.
|
||||
* @throws Exception If an error occurs during data retrieval or update.
|
||||
*/
|
||||
public static void addLink(final Class<?> clazz, final UUID uuid, final String column, final UUID remoteKey)
|
||||
public static void addLink(final Class<?> clazz, final UUID id, final String column, final UUID remoteKey)
|
||||
throws Exception {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversUUIDUUID data = DataAccess.get(TableCoversUUIDUUID.class, uuid,
|
||||
final TableCoversUUIDUUID data = DataAccess.get(TableCoversUUIDUUID.class, id,
|
||||
new OverrideTableName(tableName));
|
||||
if (data.covers == null) {
|
||||
data.covers = new ArrayList<>();
|
||||
@ -248,13 +219,13 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
}
|
||||
data.covers.add(remoteKey);
|
||||
DataAccess.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
||||
}
|
||||
|
||||
public static void addLink(final Class<?> clazz, final UUID uuid, final String column, final Long remoteKey)
|
||||
public static void addLink(final Class<?> clazz, final UUID id, final String column, final Long remoteKey)
|
||||
throws Exception {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversUUIDLong data = DataAccess.get(TableCoversUUIDLong.class, uuid,
|
||||
final TableCoversUUIDLong data = DataAccess.get(TableCoversUUIDLong.class, id,
|
||||
new OverrideTableName(tableName));
|
||||
if (data.covers == null) {
|
||||
data.covers = new ArrayList<>();
|
||||
@ -265,13 +236,13 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
}
|
||||
data.covers.add(remoteKey);
|
||||
DataAccess.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
||||
}
|
||||
|
||||
public static void removeLink(final Class<?> clazz, final UUID uuid, final String column, final Long remoteKey)
|
||||
public static void removeLink(final Class<?> clazz, final UUID id, final String column, final Long remoteKey)
|
||||
throws Exception {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversUUIDLong data = DataAccess.get(TableCoversUUIDLong.class, uuid,
|
||||
final TableCoversUUIDLong data = DataAccess.get(TableCoversUUIDLong.class, id,
|
||||
new OverrideTableName(tableName));
|
||||
if (data.covers == null) {
|
||||
return;
|
||||
@ -284,13 +255,13 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
newList.add(elem);
|
||||
}
|
||||
data.covers = newList;
|
||||
DataAccess.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
||||
}
|
||||
|
||||
public static void removeLink(final Class<?> clazz, final UUID uuid, final String column, final UUID remoteKey)
|
||||
public static void removeLink(final Class<?> clazz, final UUID id, final String column, final UUID remoteKey)
|
||||
throws Exception {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversUUIDUUID data = DataAccess.get(TableCoversUUIDUUID.class, uuid,
|
||||
final TableCoversUUIDUUID data = DataAccess.get(TableCoversUUIDUUID.class, id,
|
||||
new OverrideTableName(tableName));
|
||||
if (data.covers == null) {
|
||||
return;
|
||||
@ -303,7 +274,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
newList.add(elem);
|
||||
}
|
||||
data.covers = newList;
|
||||
DataAccess.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
||||
}
|
||||
|
||||
public static void removeLink(final Class<?> clazz, final Long id, final String column, final Long remoteKey)
|
||||
@ -343,4 +314,9 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
data.covers = newList;
|
||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
||||
}
|
||||
/* public static <TYPE> void addLink(final Class<TYPE> clazz, final Object localKey, final String column, final Object remoteKey) throws Exception { final String tableName =
|
||||
* AnnotationTools.getTableName(clazz); final TYPE data = DataAccess.get(clazz, localKey); // TODO: add filter of the "column" // find the field column: // add the remoteKey in the list: // post
|
||||
* new data in the DB final String linkTableName = generateLinkTableName(this.tableName, this.column); final LinkTable insertElement = new LinkTable(this.localKey, this.remoteKey);
|
||||
* DataAccess.insert(insertElement, new OverrideTableName(linkTableName)); } */
|
||||
|
||||
}
|
||||
|
@ -108,28 +108,16 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
@NotNull final String name,
|
||||
@NotNull final CountInOut count,
|
||||
final QueryOptions options) throws Exception {
|
||||
final ManyToMany manyToMany = AnnotationTools.getManyToMany(field);
|
||||
String linkTableName = generateLinkTableName(tableName, name);
|
||||
if (manyToMany.mappedBy() != null && manyToMany.mappedBy().length() != 0) {
|
||||
// TODO: get the remote table name .....
|
||||
final String remoteTableName = AnnotationTools.getTableName(manyToMany.targetEntity());
|
||||
linkTableName = generateLinkTableName(remoteTableName, manyToMany.mappedBy());
|
||||
}
|
||||
final String linkTableName = generateLinkTableName(tableName, name);
|
||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||
.getActualTypeArguments()[0];
|
||||
final String tmpVariable = "tmp_" + Integer.toString(count.value);
|
||||
querySelect.append(" (SELECT GROUP_CONCAT(");
|
||||
querySelect.append(tmpVariable);
|
||||
final boolean mode = manyToMany.mappedBy() == null || manyToMany.mappedBy().length() == 0;
|
||||
if (mode) {
|
||||
querySelect.append(".object2Id ");
|
||||
} else {
|
||||
querySelect.append(".object1Id ");
|
||||
}
|
||||
querySelect.append(".object2Id ");
|
||||
if ("sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||
querySelect.append(", ");
|
||||
} else {
|
||||
querySelect.append("ORDER BY uuid ASC ");
|
||||
querySelect.append("SEPARATOR ");
|
||||
}
|
||||
querySelect.append("'");
|
||||
@ -155,19 +143,11 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
querySelect.append(" = ");
|
||||
querySelect.append(tmpVariable);
|
||||
querySelect.append(".");
|
||||
if (mode) {
|
||||
querySelect.append("object1Id ");
|
||||
} else {
|
||||
querySelect.append("object2Id ");
|
||||
}
|
||||
querySelect.append("object1Id ");
|
||||
if (!"sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||
querySelect.append(" GROUP BY ");
|
||||
querySelect.append(tmpVariable);
|
||||
if (mode) {
|
||||
querySelect.append(".object1Id");
|
||||
} else {
|
||||
querySelect.append(".object2Id");
|
||||
}
|
||||
querySelect.append(".object1Id");
|
||||
}
|
||||
querySelect.append(") AS ");
|
||||
querySelect.append(name);
|
||||
@ -529,12 +509,6 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
final boolean createIfNotExist,
|
||||
final boolean createDrop,
|
||||
final int fieldId) throws Exception {
|
||||
|
||||
final ManyToMany manyToMany = AnnotationTools.getManyToMany(field);
|
||||
if (manyToMany.mappedBy() != null && manyToMany.mappedBy().length() != 0) {
|
||||
// not the reference model to create base:
|
||||
return;
|
||||
}
|
||||
final String linkTableName = generateLinkTableNameField(tableName, field);
|
||||
final QueryOptions options = new QueryOptions(new OverrideTableName(linkTableName));
|
||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||
@ -553,6 +527,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
postActionList.addAll(sqlCommand);
|
||||
}
|
||||
} else if (primaryType == UUID.class) {
|
||||
|
||||
if (objectClass == Long.class) {
|
||||
final List<String> sqlCommand = DataFactory.createTable(LinkTableUUIDLong.class, options);
|
||||
postActionList.addAll(sqlCommand);
|
||||
|
@ -3,10 +3,11 @@ package org.kar.archidata.dataAccess.addOn.model;
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.annotation.DataJson;
|
||||
import org.kar.archidata.model.GenericDataSoftDelete;
|
||||
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Column;
|
||||
|
||||
public class TableCoversLongLong {
|
||||
public class TableCoversLongLong extends GenericDataSoftDelete {
|
||||
public TableCoversLongLong() {
|
||||
// nothing to do...
|
||||
}
|
||||
@ -16,10 +17,8 @@ public class TableCoversLongLong {
|
||||
this.covers = covers;
|
||||
}
|
||||
|
||||
@Id
|
||||
public Long id;
|
||||
|
||||
@DataJson()
|
||||
@Column(nullable = false)
|
||||
public List<Long> covers;
|
||||
|
||||
}
|
||||
|
@ -1,27 +1,25 @@
|
||||
package org.kar.archidata.dataAccess.addOn.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.kar.archidata.annotation.DataJson;
|
||||
import org.kar.archidata.model.GenericDataSoftDelete;
|
||||
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Column;
|
||||
|
||||
public class TableCoversLongUUID {
|
||||
public class TableCoversLongUUID extends GenericDataSoftDelete {
|
||||
public TableCoversLongUUID() {
|
||||
// nothing to do...
|
||||
}
|
||||
|
||||
public TableCoversLongUUID(final Long id, final List<UUID> covers) {
|
||||
this.id = id;
|
||||
this.covers = new ArrayList<>(covers);
|
||||
this.covers = covers;
|
||||
}
|
||||
|
||||
@Id
|
||||
public Long id;
|
||||
|
||||
@DataJson()
|
||||
@Column(nullable = false)
|
||||
public List<UUID> covers;
|
||||
|
||||
}
|
||||
|
@ -1,26 +1,29 @@
|
||||
package org.kar.archidata.dataAccess.addOn.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.kar.archidata.annotation.DataJson;
|
||||
import org.kar.archidata.model.GenericDataSoftDelete;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
public class TableCoversUUIDLong {
|
||||
public class TableCoversUUIDLong extends GenericDataSoftDelete {
|
||||
public TableCoversUUIDLong() {
|
||||
// nothing to do...
|
||||
}
|
||||
|
||||
public TableCoversUUIDLong(final UUID uuid, final List<Long> covers) {
|
||||
this.uuid = uuid;
|
||||
this.covers = new ArrayList<>(covers);
|
||||
public TableCoversUUIDLong(final UUID id, final List<Long> covers) {
|
||||
this.id = id;
|
||||
this.covers = covers;
|
||||
}
|
||||
|
||||
@Column(nullable = false)
|
||||
@Id
|
||||
public UUID uuid;
|
||||
public UUID id;
|
||||
@DataJson()
|
||||
@Column(nullable = false)
|
||||
public List<Long> covers;
|
||||
|
||||
}
|
||||
|
@ -4,22 +4,26 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.kar.archidata.annotation.DataJson;
|
||||
import org.kar.archidata.model.GenericDataSoftDelete;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
public class TableCoversUUIDUUID {
|
||||
public class TableCoversUUIDUUID extends GenericDataSoftDelete {
|
||||
public TableCoversUUIDUUID() {
|
||||
// nothing to do...
|
||||
}
|
||||
|
||||
public TableCoversUUIDUUID(final UUID uuid, final List<UUID> covers) {
|
||||
this.uuid = uuid;
|
||||
public TableCoversUUIDUUID(final UUID id, final List<UUID> covers) {
|
||||
this.id = id;
|
||||
this.covers = covers;
|
||||
}
|
||||
|
||||
@Column(nullable = false)
|
||||
@Id
|
||||
public UUID uuid;
|
||||
public UUID id;
|
||||
@DataJson()
|
||||
@Column(nullable = false)
|
||||
public List<UUID> covers;
|
||||
|
||||
}
|
||||
|
@ -10,9 +10,9 @@ public interface CheckFunctionInterface {
|
||||
/** This function implementation is design to check if the updated class is valid of not for insertion
|
||||
* @param baseName NAme of the object to be precise with the use of what fail.
|
||||
* @param data The object that might be injected.
|
||||
* @param modifiedValue List of fields that might be check. If null, then all column must be checked.
|
||||
* @param filterValue List of fields that might be check. If null, then all column must be checked.
|
||||
* @throws Exception Exception is generate if the data are incorrect. */
|
||||
void check(final String baseName, Object data, List<String> modifiedValue, final QueryOptions options)
|
||||
void check(final String baseName, Object data, List<String> filterValue, final QueryOptions options)
|
||||
throws Exception;
|
||||
|
||||
default void checkAll(final String baseName, final Object data, final QueryOptions options) throws Exception {
|
||||
|
@ -35,13 +35,10 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
/** By default some element are not read like createAt and UpdatedAt. This option permit to read it. */
|
||||
public interface CheckInterface<K> {
|
||||
/** This function implementation is design to check if the updated class is valid of not for insertion
|
||||
* @param baseName Base of the name input that is displayed in exception generated.
|
||||
* @param data The object that might be injected.
|
||||
* @param modifiedValue List of fields that modification is requested.
|
||||
* @param options Some query option that the checker can need to generate basic check.
|
||||
* @param filterValue List of fields that might be check. If null, then all column must be checked.
|
||||
* @throws Exception Exception is generate if the data are incorrect. */
|
||||
void check(final String baseName, final K data, List<String> modifiedValue, final QueryOptions options)
|
||||
throws Exception;
|
||||
void check(final String baseName, final K data, final QueryOptions options) throws Exception;
|
||||
}
|
||||
|
||||
protected Map<String, List<CheckInterface<T>>> checking = null;
|
||||
@ -70,182 +67,128 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
for (final Field field : this.clazz.getFields()) {
|
||||
final String fieldName = field.getName(); // AnnotationTools.getFieldName(field);
|
||||
if (AnnotationTools.isPrimaryKey(field)) {
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"This is a '@Id' (primaryKey) ==> can not be change");
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"This is a '@Id' (primaryKey) ==> can not be change");
|
||||
});
|
||||
}
|
||||
if (AnnotationTools.getConstraintsNotNull(field)) {
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
if (field.get(data) == null) {
|
||||
throw new InputException(baseName + fieldName, "Can not be null");
|
||||
}
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
if (field.get(data) == null) {
|
||||
throw new InputException(baseName + fieldName, "Can not be null");
|
||||
}
|
||||
});
|
||||
}
|
||||
if (AnnotationTools.isCreatedAtField(field) || AnnotationTools.isUpdateAtField(field)) {
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
throw new InputException(baseName + fieldName, "It is forbidden to change this field");
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
throw new InputException(baseName + fieldName, "It is forbidden to change this field");
|
||||
});
|
||||
}
|
||||
|
||||
final Class<?> type = field.getType();
|
||||
if (type == Long.class || type == long.class) {
|
||||
final Long maxValue = AnnotationTools.getConstraintsMax(field);
|
||||
if (maxValue != null) {
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final Long elemTyped = (Long) elem;
|
||||
if (elemTyped > maxValue) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Value too height max: " + maxValue);
|
||||
}
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final Long elemTyped = (Long) elem;
|
||||
if (elemTyped > maxValue) {
|
||||
throw new InputException(baseName + fieldName, "Value too height max: " + maxValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
final Long minValue = AnnotationTools.getConstraintsMin(field);
|
||||
if (minValue != null) {
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final Long elemTyped = (Long) elem;
|
||||
if (elemTyped < minValue) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Value too Low min: " + minValue);
|
||||
}
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final Long elemTyped = (Long) elem;
|
||||
if (elemTyped < minValue) {
|
||||
throw new InputException(baseName + fieldName, "Value too Low min: " + minValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
||||
final Condition conditionCheck = condCheckers.isEmpty() ? null
|
||||
: condCheckers.get(0).toCondition();
|
||||
final long count = DataAccess.count(annotationManyToOne.targetEntity(), elem,
|
||||
conditionCheck);
|
||||
if (count == 0) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Foreign element does not exist in the DB:" + elem);
|
||||
}
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
||||
final Condition conditionCheck = condCheckers.isEmpty() ? null
|
||||
: condCheckers.get(0).toCondition();
|
||||
final long count = DataAccess.count(annotationManyToOne.targetEntity(), elem,
|
||||
conditionCheck);
|
||||
if (count == 0) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Foreign element does not exist in the DB:" + elem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} else if (type == Integer.class || type == int.class) {
|
||||
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
||||
if (maxValueRoot != null) {
|
||||
final int maxValue = maxValueRoot.intValue();
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final Integer elemTyped = (Integer) elem;
|
||||
if (elemTyped > maxValue) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Value too height max: " + maxValue);
|
||||
}
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final Integer elemTyped = (Integer) elem;
|
||||
if (elemTyped > maxValue) {
|
||||
throw new InputException(baseName + fieldName, "Value too height max: " + maxValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
||||
if (minValueRoot != null) {
|
||||
final int minValue = minValueRoot.intValue();
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final Integer elemTyped = (Integer) elem;
|
||||
if (elemTyped < minValue) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Value too Low min: " + minValue);
|
||||
}
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final Integer elemTyped = (Integer) elem;
|
||||
if (elemTyped < minValue) {
|
||||
throw new InputException(baseName + fieldName, "Value too Low min: " + minValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final long count = DataAccess.count(annotationManyToOne.targetEntity(), elem);
|
||||
if (count == 0) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Foreign element does not exist in the DB:" + elem);
|
||||
}
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final long count = DataAccess.count(annotationManyToOne.targetEntity(), elem);
|
||||
if (count == 0) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Foreign element does not exist in the DB:" + elem);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (type == UUID.class) {
|
||||
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final long count = DataAccess.count(annotationManyToOne.targetEntity(), elem);
|
||||
if (count == 0) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Foreign element does not exist in the DB:" + elem);
|
||||
}
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final long count = DataAccess.count(annotationManyToOne.targetEntity(), elem);
|
||||
if (count == 0) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Foreign element does not exist in the DB:" + elem);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (type == Boolean.class || type == boolean.class) {
|
||||
|
||||
@ -253,83 +196,59 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
||||
if (maxValueRoot != null) {
|
||||
final float maxValue = maxValueRoot.floatValue();
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final Float elemTyped = (Float) elem;
|
||||
if (elemTyped > maxValue) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Value too height max: " + maxValue);
|
||||
}
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final Float elemTyped = (Float) elem;
|
||||
if (elemTyped > maxValue) {
|
||||
throw new InputException(baseName + fieldName, "Value too height max: " + maxValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
||||
if (minValueRoot != null) {
|
||||
final float minValue = minValueRoot.floatValue();
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final Float elemTyped = (Float) elem;
|
||||
if (elemTyped < minValue) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Value too Low min: " + minValue);
|
||||
}
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final Float elemTyped = (Float) elem;
|
||||
if (elemTyped < minValue) {
|
||||
throw new InputException(baseName + fieldName, "Value too Low min: " + minValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (type == Double.class || type == double.class) {
|
||||
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
||||
if (maxValueRoot != null) {
|
||||
final double maxValue = maxValueRoot.doubleValue();
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final Double elemTyped = (Double) elem;
|
||||
if (elemTyped > maxValue) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Value too height max: " + maxValue);
|
||||
}
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final Double elemTyped = (Double) elem;
|
||||
if (elemTyped > maxValue) {
|
||||
throw new InputException(baseName + fieldName, "Value too height max: " + maxValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
||||
if (minValueRoot != null) {
|
||||
final double minValue = minValueRoot.doubleValue();
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final Double elemTyped = (Double) elem;
|
||||
if (elemTyped < minValue) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Value too Low min: " + minValue);
|
||||
}
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final Double elemTyped = (Double) elem;
|
||||
if (elemTyped < minValue) {
|
||||
throw new InputException(baseName + fieldName, "Value too Low min: " + minValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (type == Date.class || type == Timestamp.class) {
|
||||
|
||||
@ -340,87 +259,51 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
} else if (type == String.class) {
|
||||
final int maxSizeString = AnnotationTools.getLimitSize(field);
|
||||
if (maxSizeString > 0) {
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final String elemTyped = (String) elem;
|
||||
if (elemTyped.length() > maxSizeString) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Too long size must be <= " + maxSizeString);
|
||||
}
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final String elemTyped = (String) elem;
|
||||
if (elemTyped.length() > maxSizeString) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Too long size must be <= " + maxSizeString);
|
||||
}
|
||||
});
|
||||
}
|
||||
final Size limitSize = AnnotationTools.getConstraintsSize(field);
|
||||
if (limitSize != null) {
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final String elemTyped = (String) elem;
|
||||
if (elemTyped.length() > limitSize.max()) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Too long size (constraints) must be <= " + limitSize.max());
|
||||
}
|
||||
if (elemTyped.length() < limitSize.min()) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Too small size (constraints) must be >= " + limitSize.min());
|
||||
}
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final String elemTyped = (String) elem;
|
||||
if (elemTyped.length() > limitSize.max()) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Too long size (constraints) must be <= " + limitSize.max());
|
||||
}
|
||||
if (elemTyped.length() < limitSize.min()) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"Too small size (constraints) must be >= " + limitSize.min());
|
||||
}
|
||||
});
|
||||
}
|
||||
final String patternString = AnnotationTools.getConstraintsPattern(field);
|
||||
if (patternString != null) {
|
||||
final Pattern pattern = Pattern.compile(patternString);
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final String elemTyped = (String) elem;
|
||||
if (!pattern.matcher(elemTyped).find()) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"does not match the required pattern (constraints) must be '"
|
||||
+ patternString + "'");
|
||||
}
|
||||
});
|
||||
}
|
||||
if (AnnotationTools.getConstraintsEmail(field)) {
|
||||
final String emailPattern = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
|
||||
final Pattern pattern = Pattern.compile(emailPattern);
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final String elemTyped = (String) elem;
|
||||
if (!pattern.matcher(elemTyped).find()) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"does not match the required pattern[email] (constraints) must be '"
|
||||
+ emailPattern + "'");
|
||||
}
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
final Object elem = field.get(data);
|
||||
if (elem == null) {
|
||||
return;
|
||||
}
|
||||
final String elemTyped = (String) elem;
|
||||
if (!pattern.matcher(elemTyped).find()) {
|
||||
throw new InputException(baseName + fieldName,
|
||||
"does not match the required pattern (constraints) must be '" + patternString
|
||||
+ "'");
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (type == JsonValue.class) {
|
||||
final DataJson jsonAnnotation = AnnotationTools.getDataJson(field);
|
||||
@ -428,14 +311,9 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
// Here if we have an error it crash at start and no new instance after creation...
|
||||
final CheckFunctionInterface instance = jsonAnnotation.checker().getDeclaredConstructor()
|
||||
.newInstance();
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
instance.checkAll(baseName + fieldName + ".", field.get(data), options);
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
instance.checkAll(baseName + fieldName + ".", field.get(data), options);
|
||||
});
|
||||
}
|
||||
} else if (type.isEnum()) {
|
||||
// nothing to do.
|
||||
@ -443,26 +321,21 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
// keep this is last ==> take more time...
|
||||
if (AnnotationTools.isUnique(field)) {
|
||||
// Create the request ...
|
||||
add(fieldName,
|
||||
(
|
||||
final String baseName,
|
||||
final T data,
|
||||
final List<String> modifiedValue,
|
||||
final QueryOptions options) -> {
|
||||
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
||||
Object other = null;
|
||||
if (condCheckers.isEmpty()) {
|
||||
other = DataAccess.getWhere(this.clazz,
|
||||
new Condition(new QueryCondition(fieldName, "==", field.get(data))));
|
||||
} else {
|
||||
other = DataAccess.getWhere(this.clazz,
|
||||
new Condition(new QueryCondition(fieldName, "==", field.get(data))),
|
||||
condCheckers.get(0).toCondition());
|
||||
}
|
||||
if (other != null) {
|
||||
throw new InputException(baseName + fieldName, "Name already exist in the DB");
|
||||
}
|
||||
});
|
||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
||||
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
||||
Object other = null;
|
||||
if (condCheckers.isEmpty()) {
|
||||
other = DataAccess.getWhere(this.clazz,
|
||||
new Condition(new QueryCondition(fieldName, "==", field.get(data))));
|
||||
} else {
|
||||
other = DataAccess.getWhere(this.clazz,
|
||||
new Condition(new QueryCondition(fieldName, "==", field.get(data))),
|
||||
condCheckers.get(0).toCondition());
|
||||
}
|
||||
if (other != null) {
|
||||
throw new InputException(baseName + fieldName, "Name already exist in the DB");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@ -476,7 +349,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
public void check(
|
||||
final String baseName,
|
||||
final Object data,
|
||||
final List<String> modifiedValue,
|
||||
final List<String> filterValue,
|
||||
final QueryOptions options) throws Exception {
|
||||
if (this.checking == null) {
|
||||
initialize();
|
||||
@ -486,20 +359,19 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
final T dataCasted = (T) data;
|
||||
for (final String filter : modifiedValue) {
|
||||
for (final String filter : filterValue) {
|
||||
final List<CheckInterface<T>> actions = this.checking.get(filter);
|
||||
if (actions == null) {
|
||||
continue;
|
||||
}
|
||||
for (final CheckInterface<T> action : actions) {
|
||||
action.check(baseName, dataCasted, modifiedValue, options);
|
||||
action.check(baseName, dataCasted, options);
|
||||
}
|
||||
}
|
||||
checkTyped(dataCasted, modifiedValue, options);
|
||||
checkTyped(dataCasted, filterValue, options);
|
||||
}
|
||||
|
||||
public void checkTyped(final T data, final List<String> modifiedValue, final QueryOptions options)
|
||||
throws Exception {
|
||||
public void checkTyped(final T data, final List<String> filterValue, final QueryOptions options) throws Exception {
|
||||
// nothing to do ...
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,6 @@ public class DBEntry implements Closeable {
|
||||
this.connection = DriverManager.getConnection(this.config.getUrl(), this.config.getLogin(),
|
||||
this.config.getPassword());
|
||||
} catch (final SQLException ex) {
|
||||
LOGGER.error("Connection db fail: " + ex.getMessage() + " On URL: " + this.config.getUrl(true));
|
||||
throw new IOException("Connection db fail: " + ex.getMessage() + " On URL: " + this.config.getUrl(true));
|
||||
}
|
||||
|
||||
|
@ -71,25 +71,4 @@ public class AnalyzeApi {
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public void displayAllApi() {
|
||||
LOGGER.info("List all API:");
|
||||
for (final ApiGroupModel model : getAllApi()) {
|
||||
LOGGER.info(" - {}: {}", model.name, model.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void displayAllModel() {
|
||||
LOGGER.info("List all Model:");
|
||||
for (final ClassModel model : getAllModel()) {
|
||||
final StringBuilder out = new StringBuilder();
|
||||
for (final ClassModel classModel : model.getAlls()) {
|
||||
out.append(classModel.getOriginClasses().getCanonicalName());
|
||||
out.append(",");
|
||||
}
|
||||
LOGGER.info(" - {}", out.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,232 +0,0 @@
|
||||
package org.kar.archidata.externalRestApi;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.glassfish.jersey.media.multipart.ContentDisposition;
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
import org.kar.archidata.catcher.RestErrorResponse;
|
||||
import org.kar.archidata.externalRestApi.dot.DotApiGeneration;
|
||||
import org.kar.archidata.externalRestApi.dot.DotClassElement;
|
||||
import org.kar.archidata.externalRestApi.dot.DotClassElement.DefinedPosition;
|
||||
import org.kar.archidata.externalRestApi.dot.DotClassElementGroup;
|
||||
import org.kar.archidata.externalRestApi.model.ApiGroupModel;
|
||||
import org.kar.archidata.externalRestApi.model.ClassModel;
|
||||
|
||||
public class DotGenerateApi {
|
||||
|
||||
public static void generateApi(final AnalyzeApi api, final String pathDotFile) throws Exception {
|
||||
final List<DotClassElement> localModel = generateApiModel(api);
|
||||
final DotClassElementGroup dotGroup = new DotClassElementGroup(localModel);
|
||||
|
||||
try (final FileWriter myWriter = new FileWriter(pathDotFile)) {
|
||||
myWriter.write("""
|
||||
# Architecture auto-generated file
|
||||
digraph UML_Class_diagram {
|
||||
#rankdir=NS;
|
||||
graph [
|
||||
pad="0.5"
|
||||
nodesep="1"
|
||||
#ranksep="2"
|
||||
label="Rest API server Model"
|
||||
labelloc="t"
|
||||
fontname="FreeMono,Sans-Mono,Helvetica,Arial,sans-serif"
|
||||
]
|
||||
node [
|
||||
fontname="FreeMono,Sans-Mono,Helvetica,Arial,sans-serif"
|
||||
shape=record
|
||||
style=filled
|
||||
fillcolor=gray95
|
||||
]
|
||||
edge [fontname="FreeMono,Sans-Mono,Helvetica,Arial,sans-serif"]
|
||||
""");
|
||||
/*
|
||||
myWriter.write("""
|
||||
subgraph REST_API {
|
||||
style=filled;
|
||||
color=lightgrey;
|
||||
label="REST API";
|
||||
rankdir=LR;
|
||||
""");
|
||||
*/
|
||||
for (final ApiGroupModel element : api.apiModels) {
|
||||
final String tmp = DotApiGeneration.generateApiFile(element, dotGroup);
|
||||
myWriter.write(tmp);
|
||||
myWriter.write("\n");
|
||||
}
|
||||
// create an invisible link to force all element to be link together:
|
||||
if (false) {
|
||||
String previous = null;
|
||||
for (final ApiGroupModel element : api.apiModels) {
|
||||
if (previous == null) {
|
||||
previous = element.name;
|
||||
continue;
|
||||
}
|
||||
myWriter.write("\t{ ");
|
||||
myWriter.write(previous);
|
||||
myWriter.write(":s -> ");
|
||||
previous = element.name;
|
||||
myWriter.write(previous);
|
||||
myWriter.write(":n [style=invis]}\n");
|
||||
}
|
||||
}
|
||||
/*
|
||||
myWriter.write("""
|
||||
}
|
||||
""");
|
||||
myWriter.write("""
|
||||
subgraph Models {
|
||||
style=filled;
|
||||
color=lightgrey;
|
||||
label="Models";
|
||||
rankdir=NS;
|
||||
""");
|
||||
*/
|
||||
// Generates all MODEL files
|
||||
for (final DotClassElement element : localModel) {
|
||||
final String tmp = element.generateFile(dotGroup);
|
||||
myWriter.write(tmp);
|
||||
myWriter.write("\n");
|
||||
}
|
||||
/*
|
||||
myWriter.write("""
|
||||
}
|
||||
""");
|
||||
*/
|
||||
myWriter.write("""
|
||||
}
|
||||
""");
|
||||
}
|
||||
}
|
||||
|
||||
private static List<DotClassElement> generateApiModel(final AnalyzeApi api) throws Exception {
|
||||
// First step is to add all specific basic elements the wrap correctly the model
|
||||
final List<DotClassElement> dotModels = new ArrayList<>();
|
||||
List<ClassModel> models = api.getCompatibleModels(List.of(Void.class, void.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "void", "void", null, null, DefinedPosition.NATIVE));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(Object.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "Object", "object", null, "Object", DefinedPosition.NATIVE));
|
||||
}
|
||||
// Map is binded to any ==> can not determine this complex model for now
|
||||
models = api.getCompatibleModels(List.of(Map.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "Object", "any", null, null, DefinedPosition.NATIVE));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(String.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "String", "string", null, "String", DefinedPosition.NATIVE));
|
||||
}
|
||||
models = api.getCompatibleModels(
|
||||
List.of(InputStream.class, FormDataContentDisposition.class, ContentDisposition.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "File", "File", null, "File", DefinedPosition.NATIVE));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(Boolean.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "Boolean", "boolean", null, "Boolean", DefinedPosition.NATIVE));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(boolean.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "boolean", "boolean", null, "boolean", DefinedPosition.NATIVE));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(UUID.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "UUID", "UUID", "isUUID", "UUID", DefinedPosition.BASIC));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(long.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "long", "Long", "isLong", "long", DefinedPosition.BASIC));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(Long.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "Long", "Long", "isLong", "Long", DefinedPosition.BASIC));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(short.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "short", "Short", "isShort", "short", DefinedPosition.BASIC));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(Short.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "Short", "Short", "isShort", "Short", DefinedPosition.BASIC));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(int.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "int", "Integer", "isInteger", "int", DefinedPosition.BASIC));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(Integer.class));
|
||||
if (models != null) {
|
||||
dotModels.add(
|
||||
new DotClassElement(models, "Integer", "Integer", "isInteger", "Integer", DefinedPosition.BASIC));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(double.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "Double", "Double", "isDouble", "double", DefinedPosition.BASIC));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(Double.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "Double", "Double", "isDouble", "Double", DefinedPosition.BASIC));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(float.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "float", "Float", "isFloat", "float", DefinedPosition.BASIC));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(Float.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "Float", "Float", "isFloat", "Float", DefinedPosition.BASIC));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(Instant.class));
|
||||
if (models != null) {
|
||||
dotModels.add(
|
||||
new DotClassElement(models, "Instant", "Instant", "isInstant", "Instant", DefinedPosition.BASIC));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(Date.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "Date", "IsoDate", "isIsoDate", "Date", DefinedPosition.BASIC));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(Timestamp.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "Timestamp", "Timestamp", "isTimestamp", "Timestamp",
|
||||
DefinedPosition.BASIC));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(LocalDate.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "LocalDate", "LocalDate", "isLocalDate", "LocalDate",
|
||||
DefinedPosition.BASIC));
|
||||
}
|
||||
models = api.getCompatibleModels(List.of(LocalTime.class));
|
||||
if (models != null) {
|
||||
dotModels.add(new DotClassElement(models, "LocalTime", "LocalTime", "isLocalTime", "LocalTime",
|
||||
DefinedPosition.BASIC));
|
||||
}
|
||||
// needed for Rest interface
|
||||
api.addModel(RestErrorResponse.class);
|
||||
for (final ClassModel model : api.getAllModel()) {
|
||||
boolean alreadyExist = false;
|
||||
for (final DotClassElement elem : dotModels) {
|
||||
if (elem.isCompatible(model)) {
|
||||
alreadyExist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (alreadyExist) {
|
||||
continue;
|
||||
}
|
||||
dotModels.add(new DotClassElement(model));
|
||||
}
|
||||
return dotModels;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -30,7 +30,7 @@ import org.kar.archidata.externalRestApi.typescript.TsClassElementGroup;
|
||||
public class TsGenerateApi {
|
||||
/**
|
||||
* Generate a full API tree for Typescript in a specific folder.
|
||||
* This generate a folder containing a full API with "model" folder and "api" folder.
|
||||
* This generate a folder containing a full API with "model" filder and "api" folder.
|
||||
* The generation depend of Zod and can be strict compile.
|
||||
* @param api Data model to generate the api
|
||||
* @param pathPackage Path to store the api.
|
||||
@ -118,8 +118,6 @@ public class TsGenerateApi {
|
||||
}
|
||||
|
||||
private static List<TsClassElement> generateApiModel(final AnalyzeApi api) throws Exception {
|
||||
// needed for Rest interface
|
||||
api.addModel(RestErrorResponse.class);
|
||||
// First step is to add all specific basic elements the wrap correctly the model
|
||||
final List<TsClassElement> tsModels = new ArrayList<>();
|
||||
List<ClassModel> models = api.getCompatibleModels(List.of(Void.class, void.class));
|
||||
@ -207,6 +205,8 @@ public class TsGenerateApi {
|
||||
tsModels.add(new TsClassElement(models, "ZodLocalTime", "LocalTime", "isLocalTime", "zod.string().time()",
|
||||
DefinedPosition.BASIC));
|
||||
}
|
||||
// needed for Rest interface
|
||||
api.addModel(RestErrorResponse.class);
|
||||
for (final ClassModel model : api.getAllModel()) {
|
||||
boolean alreadyExist = false;
|
||||
for (final TsClassElement elem : tsModels) {
|
||||
|
@ -1,415 +0,0 @@
|
||||
package org.kar.archidata.externalRestApi.dot;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.kar.archidata.externalRestApi.dot.DotClassElement.DefinedPosition;
|
||||
import org.kar.archidata.externalRestApi.model.ApiGroupModel;
|
||||
import org.kar.archidata.externalRestApi.model.ApiModel;
|
||||
import org.kar.archidata.externalRestApi.model.ApiModel.OptionalClassModel;
|
||||
import org.kar.archidata.externalRestApi.model.ClassEnumModel;
|
||||
import org.kar.archidata.externalRestApi.model.ClassListModel;
|
||||
import org.kar.archidata.externalRestApi.model.ClassMapModel;
|
||||
import org.kar.archidata.externalRestApi.model.ClassModel;
|
||||
import org.kar.archidata.externalRestApi.model.ClassObjectModel;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class DotApiGeneration {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(DotApiGeneration.class);
|
||||
|
||||
public static String generateClassEnumModelTypescript(
|
||||
final ClassEnumModel model,
|
||||
final DotClassElementGroup dotGroup,
|
||||
final Set<ClassModel> imports) throws IOException {
|
||||
imports.add(model);
|
||||
final DotClassElement dotModel = dotGroup.find(model);
|
||||
return dotModel.dotTypeName;
|
||||
}
|
||||
|
||||
public static String generateClassObjectModelTypescript(
|
||||
final ClassObjectModel model,
|
||||
final DotClassElementGroup dotGroup,
|
||||
final Set<ClassModel> imports) throws IOException {
|
||||
final DotClassElement dotModel = dotGroup.find(model);
|
||||
if (dotModel.nativeType != DefinedPosition.NATIVE) {
|
||||
imports.add(model);
|
||||
}
|
||||
if (dotModel.nativeType != DefinedPosition.NORMAL) {
|
||||
return dotModel.dotTypeName;
|
||||
}
|
||||
return dotModel.dotTypeName;
|
||||
}
|
||||
|
||||
public static String generateClassMapModelTypescript(
|
||||
final ClassMapModel model,
|
||||
final DotClassElementGroup dotGroup,
|
||||
final Set<ClassModel> imports) throws IOException {
|
||||
final StringBuilder out = new StringBuilder();
|
||||
out.append("Map<");
|
||||
out.append(generateClassModelTypescript(model.keyModel, dotGroup, imports));
|
||||
out.append(", ");
|
||||
out.append(generateClassModelTypescript(model.valueModel, dotGroup, imports));
|
||||
out.append(">");
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public static String generateClassListModelTypescript(
|
||||
final ClassListModel model,
|
||||
final DotClassElementGroup dotGroup,
|
||||
final Set<ClassModel> imports) throws IOException {
|
||||
final StringBuilder out = new StringBuilder();
|
||||
out.append("List<");
|
||||
out.append(generateClassModelTypescript(model.valueModel, dotGroup, imports));
|
||||
out.append(">");
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public static String generateClassModelTypescript(
|
||||
final ClassModel model,
|
||||
final DotClassElementGroup dotGroup,
|
||||
final Set<ClassModel> imports) throws IOException {
|
||||
if (model instanceof final ClassObjectModel objectModel) {
|
||||
return generateClassObjectModelTypescript(objectModel, dotGroup, imports);
|
||||
}
|
||||
if (model instanceof final ClassListModel listModel) {
|
||||
return generateClassListModelTypescript(listModel, dotGroup, imports);
|
||||
}
|
||||
if (model instanceof final ClassMapModel mapModel) {
|
||||
return generateClassMapModelTypescript(mapModel, dotGroup, imports);
|
||||
}
|
||||
if (model instanceof final ClassEnumModel enumModel) {
|
||||
return generateClassEnumModelTypescript(enumModel, dotGroup, imports);
|
||||
}
|
||||
throw new IOException("Impossible model:" + model);
|
||||
}
|
||||
|
||||
public static String generateClassModelsTypescript(
|
||||
final List<ClassModel> models,
|
||||
final DotClassElementGroup dotGroup) throws IOException {
|
||||
if (models.size() == 0) {
|
||||
return "void";
|
||||
}
|
||||
final StringBuilder out = new StringBuilder();
|
||||
if (models.size() > 1) {
|
||||
out.append("Union<");
|
||||
}
|
||||
boolean isFirst = true;
|
||||
for (final ClassModel model : models) {
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
} else {
|
||||
out.append(", ");
|
||||
}
|
||||
final String data = DotClassElement.generateClassModelTypescript(model, dotGroup);
|
||||
out.append(data);
|
||||
}
|
||||
if (models.size() > 1) {
|
||||
out.append(">");
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public static List<String> generateClassModelsLinks(
|
||||
final List<ClassModel> models,
|
||||
final DotClassElementGroup dotGroup) throws IOException {
|
||||
if (models.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
final List<String> out = new ArrayList<>();
|
||||
final boolean isFirst = true;
|
||||
for (final ClassModel model : models) {
|
||||
final String data = DotClassElement.generateClassModelTypescriptLink(model, dotGroup);
|
||||
if (data != null) {
|
||||
out.add(data);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static String capitalizeFirstLetter(final String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return str;
|
||||
}
|
||||
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
||||
}
|
||||
|
||||
public static String generateApiFile(final ApiGroupModel element, final DotClassElementGroup dotGroup)
|
||||
throws IOException {
|
||||
final StringBuilder data = new StringBuilder();
|
||||
final StringBuilder outLinks = new StringBuilder();
|
||||
data.append("""
|
||||
%s [
|
||||
shape=plain
|
||||
label=<<table color="#FF3333" border="2" cellborder="1" cellspacing="0" cellpadding="4">
|
||||
<tr>
|
||||
<td><b>%s</b><br/>(REST)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<table border="0" cellborder="0" cellspacing="0" >
|
||||
""".formatted(element.name, element.name));
|
||||
final Set<ClassModel> imports = new HashSet<>();
|
||||
final Set<ClassModel> zodImports = new HashSet<>();
|
||||
final Set<ClassModel> isImports = new HashSet<>();
|
||||
final Set<ClassModel> writeImports = new HashSet<>();
|
||||
final Set<String> toolImports = new HashSet<>();
|
||||
for (final ApiModel interfaceElement : element.interfaces) {
|
||||
final List<String> consumes = interfaceElement.consumes;
|
||||
final List<String> produces = interfaceElement.produces;
|
||||
final boolean needGenerateProgress = interfaceElement.needGenerateProgress;
|
||||
/*
|
||||
if (returnComplexModel != null) {
|
||||
data.append(returnComplexModel.replaceAll("(?m)^", "\t"));
|
||||
for (final ClassModel elem : interfaceElement.returnTypes) {
|
||||
zodImports.addAll(elem.getDependencyGroupModels());
|
||||
}
|
||||
}
|
||||
*/
|
||||
data.append("\t\t\t\t\t<tr><td align=\"left\" port=\"");
|
||||
data.append(interfaceElement.name);
|
||||
data.append("\"><b> + ");
|
||||
data.append(interfaceElement.name);
|
||||
data.append("(");
|
||||
boolean hasParam = false;
|
||||
/*
|
||||
if (!interfaceElement.queries.isEmpty()) {
|
||||
data.append("\n\t\tqueries: {");
|
||||
for (final Entry<String, List<ClassModel>> queryEntry : interfaceElement.queries.entrySet()) {
|
||||
data.append("\n\t\t\t");
|
||||
data.append(queryEntry.getKey());
|
||||
data.append("?: ");
|
||||
data.append(generateClassModelsTypescript(queryEntry.getValue(), dotGroup, imports, false));
|
||||
data.append(",");
|
||||
}
|
||||
data.append("\n\t\t},");
|
||||
}
|
||||
*/
|
||||
/* fonctionnel mais trop de donnée
|
||||
if (!interfaceElement.parameters.isEmpty()) {
|
||||
//data.append("params: {");
|
||||
for (final Entry<String, List<ClassModel>> paramEntry : interfaceElement.parameters.entrySet()) {
|
||||
data.append("");
|
||||
data.append(paramEntry.getKey());
|
||||
data.append(": ");
|
||||
data.append(generateClassModelsTypescript(paramEntry.getValue(), dotGroup, imports, false));
|
||||
data.append(",");
|
||||
}
|
||||
//data.append("},");
|
||||
}
|
||||
*/
|
||||
if (interfaceElement.unnamedElement.size() == 1) {
|
||||
if (hasParam) {
|
||||
data.append(", ");
|
||||
}
|
||||
hasParam = true;
|
||||
data.append("data: ");
|
||||
data.append(
|
||||
generateClassModelTypescript(interfaceElement.unnamedElement.get(0), dotGroup, writeImports));
|
||||
} else if (interfaceElement.multiPartParameters.size() != 0) {
|
||||
if (hasParam) {
|
||||
data.append(", ");
|
||||
}
|
||||
hasParam = true;
|
||||
boolean hasParam2 = false;
|
||||
data.append("data: {");
|
||||
for (final Entry<String, OptionalClassModel> pathEntry : interfaceElement.multiPartParameters
|
||||
.entrySet()) {
|
||||
if (hasParam2) {
|
||||
data.append(", ");
|
||||
}
|
||||
hasParam2 = true;
|
||||
data.append(pathEntry.getKey());
|
||||
data.append(": ");
|
||||
data.append(generateClassModelsTypescript(pathEntry.getValue().model(), dotGroup));
|
||||
}
|
||||
data.append("}");
|
||||
}
|
||||
data.append("): ");
|
||||
/*
|
||||
String tmp = DotClassElement.generateLocalModel(
|
||||
final String ModelName,
|
||||
final List<ClassModel> models,
|
||||
final DotClassElementGroup dotGroup)
|
||||
public static String generateClassModelsTypescript(
|
||||
final List<ClassModel> models,
|
||||
final DotClassElementGroup dotGroup,
|
||||
final Set<ClassModel> imports) throws IOException {
|
||||
*/
|
||||
final String returnType = generateClassModelsTypescript(interfaceElement.returnTypes, dotGroup);
|
||||
data.append(returnType);
|
||||
final List<String> returnLinks = generateClassModelsLinks(interfaceElement.returnTypes, dotGroup);
|
||||
for (final String link : returnLinks) {
|
||||
outLinks.append("\t");
|
||||
outLinks.append(element.name);
|
||||
outLinks.append(":");
|
||||
outLinks.append(interfaceElement.name);
|
||||
outLinks.append(":e -> ");
|
||||
outLinks.append(link);
|
||||
outLinks.append(":NAME:w\n");
|
||||
}
|
||||
data.append("</b>");
|
||||
//data.append("<br align=\"left\"/> ");
|
||||
data.append("</td></tr>\n\t\t\t\t\t\t\t<tr><td align=\"left\"> ");
|
||||
/*
|
||||
data.append("\n\t\t\trestModel: {");
|
||||
data.append("\n\t\t\t\tendPoint: \"");
|
||||
*/
|
||||
data.append(interfaceElement.restEndPoint);
|
||||
/*
|
||||
data.append("\",");
|
||||
data.append("\n\t\t\t\trequestType: HTTPRequestModel.");
|
||||
toolImports.add("HTTPRequestModel");
|
||||
data.append(interfaceElement.restTypeRequest);
|
||||
data.append(",");
|
||||
if (consumes != null) {
|
||||
for (final String elem : consumes) {
|
||||
if (MediaType.APPLICATION_JSON.equals(elem)) {
|
||||
data.append("\n\t\t\t\tcontentType: HTTPMimeType.JSON,");
|
||||
toolImports.add("HTTPMimeType");
|
||||
break;
|
||||
} else if (MediaType.MULTIPART_FORM_DATA.equals(elem)) {
|
||||
data.append("\n\t\t\t\tcontentType: HTTPMimeType.MULTIPART,");
|
||||
toolImports.add("HTTPMimeType");
|
||||
break;
|
||||
} else if (MediaType.TEXT_PLAIN.equals(elem)) {
|
||||
data.append("\n\t\t\t\tcontentType: HTTPMimeType.TEXT_PLAIN,");
|
||||
toolImports.add("HTTPMimeType");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (RestTypeRequest.DELETE.equals(interfaceElement.restTypeRequest)) {
|
||||
data.append("\n\t\t\t\tcontentType: HTTPMimeType.TEXT_PLAIN,");
|
||||
toolImports.add("HTTPMimeType");
|
||||
}
|
||||
if (produces != null) {
|
||||
if (produces.size() > 1) {
|
||||
data.append("\n\t\t\t\taccept: produce,");
|
||||
} else {
|
||||
final String returnType = generateClassModelsTypescript(interfaceElement.returnTypes, dotGroup,
|
||||
imports, false);
|
||||
if (!"void".equals(returnType)) {
|
||||
for (final String elem : produces) {
|
||||
if (MediaType.APPLICATION_JSON.equals(elem)) {
|
||||
data.append("\n\t\t\t\taccept: HTTPMimeType.JSON,");
|
||||
toolImports.add("HTTPMimeType");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
data.append("\n\t\t\t},");
|
||||
data.append("\n\t\t\trestConfig,");
|
||||
if (!interfaceElement.parameters.isEmpty()) {
|
||||
data.append("\n\t\t\tparams,");
|
||||
}
|
||||
if (!interfaceElement.queries.isEmpty()) {
|
||||
data.append("\n\t\t\tqueries,");
|
||||
}
|
||||
if (interfaceElement.unnamedElement.size() == 1) {
|
||||
data.append("\n\t\t\tdata,");
|
||||
} else if (interfaceElement.multiPartParameters.size() != 0) {
|
||||
data.append("\n\t\t\tdata,");
|
||||
}
|
||||
if (needGenerateProgress) {
|
||||
data.append("\n\t\t\tcallback,");
|
||||
}
|
||||
data.append("\n\t\t}");
|
||||
if (returnComplexModel != null) {
|
||||
data.append(", is");
|
||||
data.append(returnModelNameIfComplex);
|
||||
} else {
|
||||
final DotClassElement retType = dotGroup.find(interfaceElement.returnTypes.get(0));
|
||||
if (retType.dotCheckType != null) {
|
||||
data.append(", ");
|
||||
data.append(retType.dotCheckType);
|
||||
imports.add(interfaceElement.returnTypes.get(0));
|
||||
}
|
||||
}
|
||||
*/
|
||||
data.append("</td></tr>\n");
|
||||
}
|
||||
/*
|
||||
data.append("\n}\n");
|
||||
|
||||
final StringBuilder out = new StringBuilder();
|
||||
|
||||
final List<String> toolImportsList = new ArrayList<>(toolImports);
|
||||
Collections.sort(toolImportsList);
|
||||
if (toolImportsList.size() != 0) {
|
||||
out.append("import {");
|
||||
for (final String elem : toolImportsList) {
|
||||
out.append("\n\t");
|
||||
out.append(elem);
|
||||
out.append(",");
|
||||
}
|
||||
out.append("\n} from \"../rest-tools\";\n\n");
|
||||
}
|
||||
|
||||
if (zodImports.size() != 0) {
|
||||
out.append("import { z as zod } from \"zod\"\n");
|
||||
}
|
||||
|
||||
final Set<String> finalImportSet = new TreeSet<>();
|
||||
|
||||
for (final ClassModel model : imports) {
|
||||
final DotClassElement dotModel = dotGroup.find(model);
|
||||
if (dotModel.nativeType == DefinedPosition.NATIVE) {
|
||||
continue;
|
||||
}
|
||||
finalImportSet.add(dotModel.dotTypeName);
|
||||
}
|
||||
for (final ClassModel model : isImports) {
|
||||
final DotClassElement dotModel = dotGroup.find(model);
|
||||
if (dotModel.nativeType == DefinedPosition.NATIVE) {
|
||||
continue;
|
||||
}
|
||||
if (dotModel.dotCheckType != null) {
|
||||
finalImportSet.add(dotModel.dotCheckType);
|
||||
}
|
||||
}
|
||||
for (final ClassModel model : zodImports) {
|
||||
final DotClassElement dotModel = dotGroup.find(model);
|
||||
if (dotModel.nativeType == DefinedPosition.NATIVE) {
|
||||
continue;
|
||||
}
|
||||
finalImportSet.add("Zod" + dotModel.dotTypeName);
|
||||
}
|
||||
for (final ClassModel model : writeImports) {
|
||||
final DotClassElement dotModel = dotGroup.find(model);
|
||||
if (dotModel.nativeType == DefinedPosition.NATIVE) {
|
||||
continue;
|
||||
}
|
||||
finalImportSet.add(dotModel.dotTypeName + "Write");
|
||||
}
|
||||
|
||||
if (finalImportSet.size() != 0) {
|
||||
out.append("import {");
|
||||
for (final String elem : finalImportSet) {
|
||||
out.append("\n\t");
|
||||
out.append(elem);
|
||||
out.append(",");
|
||||
}
|
||||
out.append("\n} from \"../model\";\n\n");
|
||||
}
|
||||
|
||||
out.append(data.toString());
|
||||
*/
|
||||
|
||||
data.append("""
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>>
|
||||
]
|
||||
""");
|
||||
data.append(outLinks.toString());
|
||||
return data.toString();
|
||||
}
|
||||
|
||||
}
|
@ -1,485 +0,0 @@
|
||||
package org.kar.archidata.externalRestApi.dot;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.kar.archidata.externalRestApi.model.ClassEnumModel;
|
||||
import org.kar.archidata.externalRestApi.model.ClassListModel;
|
||||
import org.kar.archidata.externalRestApi.model.ClassMapModel;
|
||||
import org.kar.archidata.externalRestApi.model.ClassModel;
|
||||
import org.kar.archidata.externalRestApi.model.ClassObjectModel;
|
||||
import org.kar.archidata.externalRestApi.model.ClassObjectModel.FieldProperty;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class DotClassElement {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(DotClassElement.class);
|
||||
|
||||
public enum DefinedPosition {
|
||||
NATIVE, // Native element of dot language.
|
||||
BASIC, // basic wrapping for JAVA type.
|
||||
NORMAL // Normal Object to interpret.
|
||||
}
|
||||
|
||||
public List<ClassModel> models;
|
||||
public String zodName;
|
||||
public String dotTypeName;
|
||||
public String dotCheckType;
|
||||
public String declaration;
|
||||
public String fileName = null;
|
||||
public String comment = null;
|
||||
public DefinedPosition nativeType = DefinedPosition.NORMAL;
|
||||
|
||||
public static String determineFileName(final String className) {
|
||||
return className.replaceAll("([a-z])([A-Z])", "$1-$2").replaceAll("([A-Z])([A-Z][a-z])", "$1-$2").toLowerCase();
|
||||
}
|
||||
|
||||
public DotClassElement(final List<ClassModel> model, final String zodName, final String dotTypeName,
|
||||
final String dotCheckType, final String declaration, final DefinedPosition nativeType) {
|
||||
this.models = model;
|
||||
this.zodName = zodName;
|
||||
this.dotTypeName = dotTypeName;
|
||||
this.declaration = declaration;
|
||||
this.nativeType = nativeType;
|
||||
}
|
||||
|
||||
public DotClassElement(final ClassModel model) {
|
||||
this.models = List.of(model);
|
||||
this.dotTypeName = model.getOriginClasses().getSimpleName();
|
||||
this.declaration = null;
|
||||
}
|
||||
|
||||
public boolean isCompatible(final ClassModel model) {
|
||||
return this.models.contains(model);
|
||||
}
|
||||
|
||||
public String generateEnum(final ClassEnumModel model, final DotClassElementGroup dotGroup) throws IOException {
|
||||
final StringBuilder out = new StringBuilder();
|
||||
out.append("""
|
||||
%s [
|
||||
shape=plain
|
||||
label=<<table color="#33FF33" border="2" cellborder="1" cellspacing="0" cellpadding="4">
|
||||
<tr>
|
||||
<td port="NAME"><b>%s</b><br/>(ENUM)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<table border="0" cellborder="0" cellspacing="0" >
|
||||
""".formatted(this.dotTypeName, this.dotTypeName));
|
||||
final boolean first = true;
|
||||
for (final Entry<String, Object> elem : model.getListOfValues().entrySet()) {
|
||||
out.append("\t\t\t\t\t\t<tr><td align=\"left\"><b> + ");
|
||||
out.append(elem.getKey());
|
||||
out.append("</b> = ");
|
||||
if (elem.getValue() instanceof final Integer value) {
|
||||
out.append(value);
|
||||
} else {
|
||||
out.append("'");
|
||||
out.append(elem.getValue());
|
||||
out.append("'");
|
||||
}
|
||||
out.append("</td></tr>\n");
|
||||
}
|
||||
out.append("""
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>>
|
||||
]
|
||||
""");
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public String generateImporDot(final List<ClassModel> depModels, final DotClassElementGroup dotGroup)
|
||||
throws IOException {
|
||||
final StringBuilder out = new StringBuilder();
|
||||
for (final ClassModel depModel : depModels) {
|
||||
final DotClassElement dotModel = dotGroup.find(depModel);
|
||||
if (dotModel.nativeType != DefinedPosition.NATIVE) {
|
||||
out.append("import {");
|
||||
out.append(dotModel.zodName);
|
||||
out.append("} from \"./");
|
||||
out.append(dotModel.fileName);
|
||||
out.append("\";\n");
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
private Object generateComment(final ClassObjectModel model) {
|
||||
final StringBuilder out = new StringBuilder();
|
||||
if (model.getDescription() != null || model.getExample() != null) {
|
||||
out.append("/**\n");
|
||||
if (model.getDescription() != null) {
|
||||
for (final String elem : model.getDescription().split("\n")) {
|
||||
out.append(" * ");
|
||||
out.append(elem);
|
||||
out.append("\n");
|
||||
}
|
||||
}
|
||||
if (model.getExample() != null) {
|
||||
out.append(" * Example:\n");
|
||||
out.append(" * ```\n");
|
||||
for (final String elem : model.getExample().split("\n")) {
|
||||
out.append(" * ");
|
||||
out.append(elem);
|
||||
out.append("\n");
|
||||
}
|
||||
out.append(" * ```\n");
|
||||
}
|
||||
out.append(" */\n");
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public String optionalTypeZod(final FieldProperty field) {
|
||||
// Common checking element (apply to List, Map, ...)
|
||||
if (field.nullable()) {
|
||||
return ".optional()";
|
||||
}
|
||||
if (field.notNull()) {
|
||||
return "";
|
||||
}
|
||||
// Other object:
|
||||
if (field.model().getOriginClasses() == null || field.model().getOriginClasses().isPrimitive()) {
|
||||
return "";
|
||||
}
|
||||
if (field.columnNotNull()) {
|
||||
return "";
|
||||
}
|
||||
return ".optional()";
|
||||
}
|
||||
|
||||
public String maxSizeZod(final FieldProperty field) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final Class<?> clazz = field.model().getOriginClasses();
|
||||
if (clazz == String.class) {
|
||||
if (field.sizeMin() > 0) {
|
||||
builder.append(".min(");
|
||||
builder.append(field.sizeMin());
|
||||
builder.append(")");
|
||||
}
|
||||
if (field.sizeMax() > 0) {
|
||||
builder.append(".max(");
|
||||
builder.append(field.sizeMax());
|
||||
builder.append(")");
|
||||
}
|
||||
}
|
||||
if (clazz == short.class || clazz == Short.class || clazz == int.class || clazz == Integer.class
|
||||
|| clazz == long.class || clazz == Long.class || clazz == float.class || clazz == Float.class
|
||||
|| clazz == double.class || clazz == Double.class) {
|
||||
if (field.min() != null && field.min() > 0) {
|
||||
builder.append(".min(");
|
||||
builder.append(field.min());
|
||||
builder.append(")");
|
||||
}
|
||||
if (field.max() != null && field.max() > 0) {
|
||||
builder.append(".max(");
|
||||
builder.append(field.max());
|
||||
builder.append(")");
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public String readOnlyZod(final FieldProperty field) {
|
||||
if (field.readOnly()) {
|
||||
return ".readonly()";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String generateBaseObject() {
|
||||
final StringBuilder out = new StringBuilder();
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public String convertHtml(final String data) {
|
||||
return data.replace("<", "<").replace(">", ">");
|
||||
}
|
||||
|
||||
public static String generateClassModelTypescript(final ClassModel model, final DotClassElementGroup dotGroup)
|
||||
throws IOException {
|
||||
if (model instanceof ClassEnumModel) {
|
||||
final DotClassElement dotFieldModel = dotGroup.find(model);
|
||||
return dotFieldModel.dotTypeName;
|
||||
} else if (model instanceof ClassObjectModel) {
|
||||
final DotClassElement dotFieldModel = dotGroup.find(model);
|
||||
return dotFieldModel.dotTypeName;
|
||||
} else if (model instanceof final ClassListModel fieldListModel) {
|
||||
return generateDotList(fieldListModel, dotGroup);
|
||||
} else if (model instanceof final ClassMapModel fieldMapModel) {
|
||||
return generateDotMap(fieldMapModel, dotGroup);
|
||||
}
|
||||
throw new IOException("Impossible model:" + model);
|
||||
}
|
||||
|
||||
public static String generateClassModelTypescriptLink(final ClassModel model, final DotClassElementGroup dotGroup)
|
||||
throws IOException {
|
||||
if (model instanceof ClassEnumModel) {
|
||||
final DotClassElement dotFieldModel = dotGroup.find(model);
|
||||
return dotFieldModel.dotTypeName;
|
||||
} else if (model instanceof ClassObjectModel) {
|
||||
final DotClassElement dotFieldModel = dotGroup.find(model);
|
||||
if (dotFieldModel.nativeType == DefinedPosition.NORMAL) {
|
||||
return dotFieldModel.dotTypeName;
|
||||
}
|
||||
} else if (model instanceof final ClassListModel fieldListModel) {
|
||||
final String className = generateDotListClassName(fieldListModel, dotGroup);
|
||||
if (className != null) {
|
||||
return className;
|
||||
}
|
||||
} else if (model instanceof final ClassMapModel fieldMapModel) {
|
||||
final String className = generateDotMapClassName(fieldMapModel, dotGroup);
|
||||
if (className != null) {
|
||||
return className;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String generateObject(final ClassObjectModel model, final DotClassElementGroup dotGroup) throws IOException {
|
||||
final StringBuilder out = new StringBuilder();
|
||||
final StringBuilder outLinks = new StringBuilder();
|
||||
out.append("""
|
||||
%s [
|
||||
shape=plain
|
||||
ranksep="2"
|
||||
label=<<table color="#000000" border="2" cellborder="1" cellspacing="0" cellpadding="4">
|
||||
<tr>
|
||||
<td port="NAME"><b>%s</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<table border="0" cellborder="0" cellspacing="0" >
|
||||
""".formatted(this.dotTypeName, this.dotTypeName));
|
||||
String inheritence = null;
|
||||
if (model.getExtendsClass() != null) {
|
||||
final ClassModel parentClass = model.getExtendsClass();
|
||||
final DotClassElement dotParentModel = dotGroup.find(parentClass);
|
||||
inheritence = dotParentModel.dotTypeName;
|
||||
}
|
||||
if (model.getFields().size() == 0) {
|
||||
out.append("\t\t\t\t\t\t<tr><td> <i>(empty)</i> </td></tr>");
|
||||
}
|
||||
for (final FieldProperty field : model.getFields()) {
|
||||
final ClassModel fieldModel = field.model();
|
||||
if (field.comment() != null) {
|
||||
out.append("\t\t\t\t\t\t<tr><td align=\"left\"><i> // ");
|
||||
out.append(convertHtml(field.comment()));
|
||||
out.append("</i></td></tr>\n");
|
||||
}
|
||||
out.append("\t\t\t\t\t\t<tr><td align=\"left\" port=\"");
|
||||
out.append(field.name());
|
||||
out.append("\"><b> + ");
|
||||
out.append(field.name());
|
||||
out.append("</b>: ");
|
||||
|
||||
out.append(generateClassModelTypescript(fieldModel, dotGroup));
|
||||
final String remoteType = generateClassModelTypescriptLink(fieldModel, dotGroup);
|
||||
if (remoteType != null) {
|
||||
outLinks.append("\t");
|
||||
outLinks.append(this.dotTypeName);
|
||||
outLinks.append(":");
|
||||
outLinks.append(field.name());
|
||||
outLinks.append(":e -> ");
|
||||
outLinks.append(remoteType);
|
||||
outLinks.append(":NAME:w\n");
|
||||
} else if (field.linkClass() != null) {
|
||||
final String remoteLinkType = generateClassModelTypescriptLink(field.linkClass(), dotGroup);
|
||||
if (remoteLinkType != null) {
|
||||
outLinks.append("\t");
|
||||
outLinks.append(this.dotTypeName);
|
||||
outLinks.append(":");
|
||||
outLinks.append(field.name());
|
||||
outLinks.append(":e -> ");
|
||||
outLinks.append(remoteLinkType);
|
||||
outLinks.append(":NAME:w\n");
|
||||
}
|
||||
}
|
||||
out.append("</td></tr>\n");
|
||||
}
|
||||
out.append("""
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>>
|
||||
]
|
||||
""");
|
||||
if (inheritence != null) {
|
||||
out.append("\tedge [dir=back arrowtail=empty arrowsize=2]\n");
|
||||
out.append("\t");
|
||||
out.append(inheritence);
|
||||
// heritage stop link on the "s" South
|
||||
out.append(":s -> ");
|
||||
out.append(this.dotTypeName);
|
||||
// heritage start link on the "n" North
|
||||
out.append(":n\n");
|
||||
}
|
||||
if (!outLinks.isEmpty()) {
|
||||
out.append("\tedge [dir=back arrowtail=diamond arrowsize=2]\n");
|
||||
//out.append("\tedge [arrowhead=diamond arrowsize=2]\n");
|
||||
out.append(outLinks.toString());
|
||||
|
||||
}
|
||||
return out.toString();
|
||||
|
||||
}
|
||||
|
||||
private static String generateDotMap(final ClassMapModel model, final DotClassElementGroup dotGroup) {
|
||||
final StringBuilder out = new StringBuilder();
|
||||
out.append("Map<");
|
||||
if (model.keyModel instanceof final ClassListModel fieldListModel) {
|
||||
final String tmp = generateDotList(fieldListModel, dotGroup);
|
||||
out.append(tmp);
|
||||
} else if (model.keyModel instanceof final ClassMapModel fieldMapModel) {
|
||||
final String tmp = generateDotMap(fieldMapModel, dotGroup);
|
||||
out.append(tmp);
|
||||
} else if (model.keyModel instanceof final ClassObjectModel fieldObjectModel) {
|
||||
final String tmp = generateDotObject(fieldObjectModel, dotGroup);
|
||||
out.append(tmp);
|
||||
} else if (model.keyModel instanceof final ClassEnumModel fieldEnumModel) {
|
||||
final String tmp = generateDotEnum(fieldEnumModel, dotGroup);
|
||||
out.append(tmp);
|
||||
}
|
||||
out.append(", ");
|
||||
if (model.valueModel instanceof final ClassListModel fieldListModel) {
|
||||
final String tmp = generateDotList(fieldListModel, dotGroup);
|
||||
out.append(tmp);
|
||||
} else if (model.valueModel instanceof final ClassMapModel fieldMapModel) {
|
||||
final String tmp = generateDotMap(fieldMapModel, dotGroup);
|
||||
out.append(tmp);
|
||||
} else if (model.valueModel instanceof final ClassObjectModel fieldObjectModel) {
|
||||
final String tmp = generateDotObject(fieldObjectModel, dotGroup);
|
||||
out.append(tmp);
|
||||
} else if (model.valueModel instanceof final ClassEnumModel fieldEnumModel) {
|
||||
final String tmp = generateDotEnum(fieldEnumModel, dotGroup);
|
||||
out.append(tmp);
|
||||
}
|
||||
out.append(">");
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
private static String generateDotEnum(final ClassEnumModel model, final DotClassElementGroup dotGroup) {
|
||||
final DotClassElement dotParentModel = dotGroup.find(model);
|
||||
return dotParentModel.dotTypeName;
|
||||
}
|
||||
|
||||
private static String generateDotObject(final ClassObjectModel model, final DotClassElementGroup dotGroup) {
|
||||
final DotClassElement dotParentModel = dotGroup.find(model);
|
||||
return dotParentModel.dotTypeName;
|
||||
}
|
||||
|
||||
private static String generateDotObjectClassName(
|
||||
final ClassObjectModel model,
|
||||
final DotClassElementGroup dotGroup) {
|
||||
final DotClassElement dotParentModel = dotGroup.find(model);
|
||||
if (dotParentModel.nativeType == DefinedPosition.NORMAL) {
|
||||
return dotParentModel.dotTypeName;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String generateDotListClassName(final ClassListModel model, final DotClassElementGroup dotGroup) {
|
||||
if (model.valueModel instanceof final ClassListModel fieldListModel) {
|
||||
return generateDotListClassName(fieldListModel, dotGroup);
|
||||
} else if (model.valueModel instanceof final ClassMapModel fieldMapModel) {
|
||||
return generateDotMapClassName(fieldMapModel, dotGroup);
|
||||
} else if (model.valueModel instanceof final ClassObjectModel fieldObjectModel) {
|
||||
return generateDotObjectClassName(fieldObjectModel, dotGroup);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String generateDotMapClassName(final ClassMapModel model, final DotClassElementGroup dotGroup) {
|
||||
if (model.valueModel instanceof final ClassListModel fieldListModel) {
|
||||
return generateDotListClassName(fieldListModel, dotGroup);
|
||||
} else if (model.valueModel instanceof final ClassMapModel fieldMapModel) {
|
||||
return generateDotMapClassName(fieldMapModel, dotGroup);
|
||||
} else if (model.valueModel instanceof final ClassObjectModel fieldObjectModel) {
|
||||
return generateDotObjectClassName(fieldObjectModel, dotGroup);
|
||||
} else if (model.valueModel instanceof final ClassEnumModel fieldEnumModel) {
|
||||
return generateDotEnum(fieldEnumModel, dotGroup);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String generateDotList(final ClassListModel model, final DotClassElementGroup dotGroup) {
|
||||
final StringBuilder out = new StringBuilder();
|
||||
out.append("List<");
|
||||
if (model.valueModel instanceof final ClassListModel fieldListModel) {
|
||||
final String tmp = generateDotList(fieldListModel, dotGroup);
|
||||
out.append(tmp);
|
||||
} else if (model.valueModel instanceof final ClassMapModel fieldMapModel) {
|
||||
final String tmp = generateDotMap(fieldMapModel, dotGroup);
|
||||
out.append(tmp);
|
||||
} else if (model.valueModel instanceof final ClassObjectModel fieldObjectModel) {
|
||||
final String tmp = generateDotObject(fieldObjectModel, dotGroup);
|
||||
out.append(tmp);
|
||||
}
|
||||
out.append(">");
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public String generateFile(final DotClassElementGroup dotGroup) throws IOException {
|
||||
if (this.nativeType == DefinedPosition.NATIVE) {
|
||||
return "";
|
||||
}
|
||||
final ClassModel model = this.models.get(0);
|
||||
String data = "";
|
||||
if (this.nativeType == DefinedPosition.BASIC && model instanceof ClassObjectModel) {
|
||||
// nothing to do___ data = generateBaseObject();
|
||||
} else if (model instanceof final ClassEnumModel modelEnum) {
|
||||
data = generateEnum(modelEnum, dotGroup);
|
||||
} else if (model instanceof final ClassObjectModel modelObject) {
|
||||
data = generateObject(modelObject, dotGroup);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private static String generateLocalModelBase(final ClassModel model, final DotClassElementGroup dotGroup)
|
||||
throws IOException {
|
||||
if (model instanceof final ClassObjectModel objectModel) {
|
||||
return generateDotObject(objectModel, dotGroup);
|
||||
}
|
||||
if (model instanceof final ClassEnumModel enumModel) {
|
||||
return generateDotEnum(enumModel, dotGroup);
|
||||
}
|
||||
if (model instanceof final ClassListModel listModel) {
|
||||
return generateDotList(listModel, dotGroup);
|
||||
}
|
||||
if (model instanceof final ClassMapModel mapModel) {
|
||||
return generateDotMap(mapModel, dotGroup);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String generateLocalModel(
|
||||
final String ModelName,
|
||||
final List<ClassModel> models,
|
||||
final DotClassElementGroup dotGroup) throws IOException {
|
||||
if (models.size() == 1) {
|
||||
if (models.get(0) instanceof ClassObjectModel) {
|
||||
return null;
|
||||
}
|
||||
if (models.get(0) instanceof ClassEnumModel) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
final StringBuilder out = new StringBuilder();
|
||||
if (models.size() == 1) {
|
||||
out.append(generateLocalModelBase(models.get(0), dotGroup));
|
||||
} else {
|
||||
out.append("Union<");
|
||||
for (final ClassModel model : models) {
|
||||
out.append("\t");
|
||||
out.append(generateLocalModelBase(models.get(0), dotGroup));
|
||||
out.append(",\n");
|
||||
}
|
||||
out.append(">");
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.kar.archidata.externalRestApi.dot;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.externalRestApi.model.ClassModel;
|
||||
|
||||
public class DotClassElementGroup {
|
||||
private final List<DotClassElement> dotElements;
|
||||
|
||||
public List<DotClassElement> getDotElements() {
|
||||
return this.dotElements;
|
||||
}
|
||||
|
||||
public DotClassElementGroup(final List<DotClassElement> tsElements) {
|
||||
this.dotElements = tsElements;
|
||||
}
|
||||
|
||||
public DotClassElement find(final ClassModel model) {
|
||||
for (final DotClassElement elem : this.dotElements) {
|
||||
if (elem.isCompatible(model)) {
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -15,10 +15,6 @@ import org.slf4j.LoggerFactory;
|
||||
public class ApiModel {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(ApiModel.class);
|
||||
|
||||
public record OptionalClassModel(
|
||||
List<ClassModel> model,
|
||||
boolean optional) {}
|
||||
|
||||
Class<?> originClass;
|
||||
Method orignMethod;
|
||||
|
||||
@ -40,7 +36,7 @@ public class ApiModel {
|
||||
// list of all query (?key...)
|
||||
public final Map<String, List<ClassModel>> queries = new HashMap<>();
|
||||
// when request multi-part, need to separate it.
|
||||
public final Map<String, OptionalClassModel> multiPartParameters = new HashMap<>();
|
||||
public final Map<String, List<ClassModel>> multiPartParameters = new HashMap<>();
|
||||
// model of data available
|
||||
public final List<ClassModel> unnamedElement = new ArrayList<>();
|
||||
|
||||
@ -157,7 +153,6 @@ public class ApiModel {
|
||||
final String pathParam = ApiTool.apiAnnotationGetPathParam(parameter);
|
||||
final String queryParam = ApiTool.apiAnnotationGetQueryParam(parameter);
|
||||
final String formDataParam = ApiTool.apiAnnotationGetFormDataParam(parameter);
|
||||
final boolean formDataParamOptional = ApiTool.apiAnnotationGetFormDataOptional(parameter);
|
||||
if (queryParam != null) {
|
||||
if (!this.queries.containsKey(queryParam)) {
|
||||
this.queries.put(queryParam, parameterModel);
|
||||
@ -168,8 +163,7 @@ public class ApiModel {
|
||||
}
|
||||
} else if (formDataParam != null) {
|
||||
if (!this.multiPartParameters.containsKey(formDataParam)) {
|
||||
this.multiPartParameters.put(formDataParam,
|
||||
new OptionalClassModel(parameterModel, formDataParamOptional));
|
||||
this.multiPartParameters.put(formDataParam, parameterModel);
|
||||
}
|
||||
} else {
|
||||
this.unnamedElement.addAll(parameterModel);
|
||||
|
@ -7,10 +7,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||
import org.kar.archidata.annotation.ARCHIVE;
|
||||
import org.kar.archidata.annotation.AsyncType;
|
||||
import org.kar.archidata.annotation.FormDataOptional;
|
||||
import org.kar.archidata.annotation.RESTORE;
|
||||
import org.kar.archidata.annotation.TypeScriptProgress;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@ -109,12 +106,6 @@ public class ApiTool {
|
||||
if (element.getDeclaredAnnotationsByType(DELETE.class).length == 1) {
|
||||
return "DELETE";
|
||||
}
|
||||
if (element.getDeclaredAnnotationsByType(RESTORE.class).length == 1) {
|
||||
return "RESTORE";
|
||||
}
|
||||
if (element.getDeclaredAnnotationsByType(ARCHIVE.class).length == 1) {
|
||||
return "ARCHIVE";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -134,12 +125,6 @@ public class ApiTool {
|
||||
if (element.getDeclaredAnnotationsByType(DELETE.class).length == 1) {
|
||||
return RestTypeRequest.DELETE;
|
||||
}
|
||||
if (element.getDeclaredAnnotationsByType(RESTORE.class).length == 1) {
|
||||
return RestTypeRequest.RESTORE;
|
||||
}
|
||||
if (element.getDeclaredAnnotationsByType(ARCHIVE.class).length == 1) {
|
||||
return RestTypeRequest.ARCHIVE;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -159,14 +144,6 @@ public class ApiTool {
|
||||
return ((QueryParam) annotation[0]).value();
|
||||
}
|
||||
|
||||
public static boolean apiAnnotationGetFormDataOptional(final Parameter element) throws Exception {
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(FormDataOptional.class);
|
||||
if (annotation.length == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String apiAnnotationGetFormDataParam(final Parameter element) throws Exception {
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(FormDataParam.class);
|
||||
if (annotation.length == 0) {
|
||||
|
@ -10,7 +10,6 @@ public class ClassEnumModel extends ClassModel {
|
||||
|
||||
protected ClassEnumModel(final Class<?> clazz) {
|
||||
this.originClasses = clazz;
|
||||
this.noWriteSpecificMode = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,17 +11,12 @@ import java.util.Set;
|
||||
public abstract class ClassModel {
|
||||
protected boolean analyzeDone = false;
|
||||
protected Class<?> originClasses = null;
|
||||
protected boolean noWriteSpecificMode = false;
|
||||
protected List<ClassModel> dependencyModels = new ArrayList<>();
|
||||
|
||||
public Class<?> getOriginClasses() {
|
||||
return this.originClasses;
|
||||
}
|
||||
|
||||
public boolean isNoWriteSpecificMode() {
|
||||
return this.noWriteSpecificMode;
|
||||
}
|
||||
|
||||
protected boolean isCompatible(final Class<?> clazz) {
|
||||
return this.originClasses == clazz;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.kar.archidata.externalRestApi.model;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDate;
|
||||
@ -11,15 +10,9 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.kar.archidata.annotation.AnnotationTools;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
public class ClassObjectModel extends ClassModel {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(ClassObjectModel.class);
|
||||
|
||||
@ -59,28 +52,19 @@ public class ClassObjectModel extends ClassModel {
|
||||
public record FieldProperty(
|
||||
String name,
|
||||
ClassModel model,
|
||||
ClassModel linkClass, // link class when use remote ID (ex: list<UUID>)
|
||||
String comment,
|
||||
int sizeMin, // String SizeMin
|
||||
int sizeMax, // String SizeMax
|
||||
Long min, // number min value
|
||||
Long max, // number max value
|
||||
int limitSize,
|
||||
Boolean readOnly,
|
||||
Boolean notNull,
|
||||
Boolean columnNotNull,
|
||||
Boolean nullable) {
|
||||
|
||||
public FieldProperty(final String name, final ClassModel model, final ClassModel linkClass,
|
||||
final String comment, final int sizeMin, final int sizeMax, final Long min, final Long max,
|
||||
public FieldProperty(final String name, final ClassModel model, final String comment, final int limitSize,
|
||||
final Boolean readOnly, final Boolean notNull, final Boolean columnNotNull, final Boolean nullable) {
|
||||
this.name = name;
|
||||
this.model = model;
|
||||
this.linkClass = linkClass;
|
||||
this.comment = comment;
|
||||
this.sizeMin = sizeMin;
|
||||
this.sizeMax = sizeMax;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.limitSize = limitSize;
|
||||
this.readOnly = readOnly;
|
||||
this.notNull = notNull;
|
||||
this.columnNotNull = columnNotNull;
|
||||
@ -88,59 +72,11 @@ public class ClassObjectModel extends ClassModel {
|
||||
|
||||
}
|
||||
|
||||
private static int getStringMinSize(final Field field) throws DataAccessException {
|
||||
final Size size = AnnotationTools.getConstraintsSize(field);
|
||||
return size != null ? size.min() : 0;
|
||||
}
|
||||
|
||||
private static int getStringMaxSize(final Field field) throws DataAccessException {
|
||||
final Size size = AnnotationTools.getConstraintsSize(field);
|
||||
final int colomnLimitSize = AnnotationTools.getLimitSize(field);
|
||||
return size == null ? colomnLimitSize : colomnLimitSize < size.max() ? colomnLimitSize : size.max();
|
||||
}
|
||||
|
||||
private static Class<?> getSubModelIfExist2(final Field field) {
|
||||
final ManyToOne manyToOne = AnnotationTools.getManyToOne(field);
|
||||
if (manyToOne != null) {
|
||||
if (manyToOne.targetEntity() != null && manyToOne.targetEntity() != void.class) {
|
||||
return manyToOne.targetEntity();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
final ManyToMany manyToMany = AnnotationTools.getManyToMany(field);
|
||||
if (manyToMany != null) {
|
||||
if (manyToMany.targetEntity() != null && manyToMany.targetEntity() != void.class) {
|
||||
return manyToMany.targetEntity();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
final OneToMany oneToMany = AnnotationTools.getOneToMany(field);
|
||||
if (oneToMany != null) {
|
||||
if (oneToMany.targetEntity() != null && oneToMany.targetEntity() != void.class) {
|
||||
return oneToMany.targetEntity();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ClassModel getSubModelIfExist(final Field field, final ModelGroup previous) throws IOException {
|
||||
final Class<?> tmp = getSubModelIfExist2(field);
|
||||
if (tmp == null) {
|
||||
return null;
|
||||
}
|
||||
return ClassModel.getModel(tmp, previous);
|
||||
}
|
||||
|
||||
public FieldProperty(final Field field, final ModelGroup previous) throws DataAccessException, IOException {
|
||||
public FieldProperty(final Field field, final ModelGroup previous) throws Exception {
|
||||
this(field.getName(), //
|
||||
ClassModel.getModel(field.getGenericType(), previous), //
|
||||
getSubModelIfExist(field, previous), //
|
||||
AnnotationTools.getComment(field), //
|
||||
getStringMinSize(field), //
|
||||
getStringMaxSize(field), //
|
||||
AnnotationTools.getConstraintsMin(field), //
|
||||
AnnotationTools.getConstraintsMax(field), //
|
||||
AnnotationTools.getLimitSize(field), //
|
||||
AnnotationTools.getSchemaReadOnly(field), //
|
||||
AnnotationTools.getConstraintsNotNull(field), //
|
||||
AnnotationTools.getColumnNotNull(field), //
|
||||
@ -187,7 +123,6 @@ public class ClassObjectModel extends ClassModel {
|
||||
}
|
||||
this.analyzeDone = true;
|
||||
final Class<?> clazz = this.originClasses;
|
||||
this.noWriteSpecificMode = AnnotationTools.getNoWriteSpecificMode(clazz);
|
||||
this.isPrimitive = clazz.isPrimitive();
|
||||
if (this.isPrimitive) {
|
||||
return;
|
||||
|
@ -1,5 +1,5 @@
|
||||
package org.kar.archidata.externalRestApi.model;
|
||||
|
||||
public enum RestTypeRequest {
|
||||
GET, POST, PUT, PATCH, DELETE, RESTORE, ARCHIVE
|
||||
GET, POST, PUT, PATCH, DELETE
|
||||
}
|
||||
|
@ -3,9 +3,6 @@ package org.kar.archidata.externalRestApi.typescript;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@ -17,7 +14,6 @@ import java.util.TreeSet;
|
||||
import org.kar.archidata.dataAccess.DataExport;
|
||||
import org.kar.archidata.externalRestApi.model.ApiGroupModel;
|
||||
import org.kar.archidata.externalRestApi.model.ApiModel;
|
||||
import org.kar.archidata.externalRestApi.model.ApiModel.OptionalClassModel;
|
||||
import org.kar.archidata.externalRestApi.model.ClassEnumModel;
|
||||
import org.kar.archidata.externalRestApi.model.ClassListModel;
|
||||
import org.kar.archidata.externalRestApi.model.ClassMapModel;
|
||||
@ -45,7 +41,7 @@ public class TsApiGeneration {
|
||||
final ClassEnumModel model,
|
||||
final TsClassElementGroup tsGroup,
|
||||
final Set<ClassModel> imports,
|
||||
final Set<ClassModel> importWrite) throws IOException {
|
||||
final boolean writeMode) throws IOException {
|
||||
imports.add(model);
|
||||
final TsClassElement tsModel = tsGroup.find(model);
|
||||
return tsModel.tsTypeName;
|
||||
@ -55,19 +51,15 @@ public class TsApiGeneration {
|
||||
final ClassObjectModel model,
|
||||
final TsClassElementGroup tsGroup,
|
||||
final Set<ClassModel> imports,
|
||||
final Set<ClassModel> importWrite) throws IOException {
|
||||
final boolean writeMode) throws IOException {
|
||||
final TsClassElement tsModel = tsGroup.find(model);
|
||||
if (tsModel.nativeType != DefinedPosition.NATIVE) {
|
||||
if (importWrite == null || tsModel.models.get(0).isNoWriteSpecificMode()) {
|
||||
imports.add(model);
|
||||
} else {
|
||||
importWrite.add(model);
|
||||
}
|
||||
imports.add(model);
|
||||
}
|
||||
if (tsModel.nativeType != DefinedPosition.NORMAL) {
|
||||
return tsModel.tsTypeName;
|
||||
}
|
||||
if (importWrite != null && !tsModel.models.get(0).isNoWriteSpecificMode()) {
|
||||
if (writeMode) {
|
||||
return tsModel.tsTypeName + "Write";
|
||||
}
|
||||
return tsModel.tsTypeName;
|
||||
@ -77,12 +69,12 @@ public class TsApiGeneration {
|
||||
final ClassMapModel model,
|
||||
final TsClassElementGroup tsGroup,
|
||||
final Set<ClassModel> imports,
|
||||
final Set<ClassModel> importWrite) throws IOException {
|
||||
final boolean writeMode) throws IOException {
|
||||
final StringBuilder out = new StringBuilder();
|
||||
out.append("{[key: ");
|
||||
out.append(generateClassModelTypescript(model.keyModel, tsGroup, imports, importWrite));
|
||||
out.append(generateClassModelTypescript(model.keyModel, tsGroup, imports, writeMode));
|
||||
out.append("]: ");
|
||||
out.append(generateClassModelTypescript(model.valueModel, tsGroup, imports, importWrite));
|
||||
out.append(generateClassModelTypescript(model.valueModel, tsGroup, imports, writeMode));
|
||||
out.append(";}");
|
||||
return out.toString();
|
||||
}
|
||||
@ -91,9 +83,9 @@ public class TsApiGeneration {
|
||||
final ClassListModel model,
|
||||
final TsClassElementGroup tsGroup,
|
||||
final Set<ClassModel> imports,
|
||||
final Set<ClassModel> importWrite) throws IOException {
|
||||
final boolean writeMode) throws IOException {
|
||||
final StringBuilder out = new StringBuilder();
|
||||
out.append(generateClassModelTypescript(model.valueModel, tsGroup, imports, importWrite));
|
||||
out.append(generateClassModelTypescript(model.valueModel, tsGroup, imports, writeMode));
|
||||
out.append("[]");
|
||||
return out.toString();
|
||||
}
|
||||
@ -102,18 +94,18 @@ public class TsApiGeneration {
|
||||
final ClassModel model,
|
||||
final TsClassElementGroup tsGroup,
|
||||
final Set<ClassModel> imports,
|
||||
final Set<ClassModel> importWrite) throws IOException {
|
||||
final boolean writeMode) throws IOException {
|
||||
if (model instanceof final ClassObjectModel objectModel) {
|
||||
return generateClassObjectModelTypescript(objectModel, tsGroup, imports, importWrite);
|
||||
return generateClassObjectModelTypescript(objectModel, tsGroup, imports, writeMode);
|
||||
}
|
||||
if (model instanceof final ClassListModel listModel) {
|
||||
return generateClassListModelTypescript(listModel, tsGroup, imports, importWrite);
|
||||
return generateClassListModelTypescript(listModel, tsGroup, imports, writeMode);
|
||||
}
|
||||
if (model instanceof final ClassMapModel mapModel) {
|
||||
return generateClassMapModelTypescript(mapModel, tsGroup, imports, importWrite);
|
||||
return generateClassMapModelTypescript(mapModel, tsGroup, imports, writeMode);
|
||||
}
|
||||
if (model instanceof final ClassEnumModel enumModel) {
|
||||
return generateClassEnumModelTypescript(enumModel, tsGroup, imports, importWrite);
|
||||
return generateClassEnumModelTypescript(enumModel, tsGroup, imports, writeMode);
|
||||
}
|
||||
throw new IOException("Impossible model:" + model);
|
||||
}
|
||||
@ -122,7 +114,7 @@ public class TsApiGeneration {
|
||||
final List<ClassModel> models,
|
||||
final TsClassElementGroup tsGroup,
|
||||
final Set<ClassModel> imports,
|
||||
final Set<ClassModel> importWrite) throws IOException {
|
||||
final boolean writeMode) throws IOException {
|
||||
if (models.size() == 0) {
|
||||
return "void";
|
||||
}
|
||||
@ -134,7 +126,7 @@ public class TsApiGeneration {
|
||||
} else {
|
||||
out.append(" | ");
|
||||
}
|
||||
final String data = generateClassModelTypescript(model, tsGroup, imports, importWrite);
|
||||
final String data = generateClassModelTypescript(model, tsGroup, imports, writeMode);
|
||||
out.append(data);
|
||||
}
|
||||
return out.toString();
|
||||
@ -196,7 +188,7 @@ public class TsApiGeneration {
|
||||
data.append("\n\t\t\tdata,");
|
||||
}
|
||||
if (needGenerateProgress) {
|
||||
data.append("\n\t\t\tcallbacks,");
|
||||
data.append("\n\t\t\tcallback,");
|
||||
}
|
||||
data.append("\n\t\t}: {");
|
||||
data.append("\n\t\trestConfig: RESTConfig,");
|
||||
@ -207,7 +199,7 @@ public class TsApiGeneration {
|
||||
data.append("\n\t\t\t");
|
||||
data.append(queryEntry.getKey());
|
||||
data.append("?: ");
|
||||
data.append(generateClassModelsTypescript(queryEntry.getValue(), tsGroup, imports, null));
|
||||
data.append(generateClassModelsTypescript(queryEntry.getValue(), tsGroup, imports, false));
|
||||
data.append(",");
|
||||
}
|
||||
data.append("\n\t\t},");
|
||||
@ -218,28 +210,24 @@ public class TsApiGeneration {
|
||||
data.append("\n\t\t\t");
|
||||
data.append(paramEntry.getKey());
|
||||
data.append(": ");
|
||||
data.append(generateClassModelsTypescript(paramEntry.getValue(), tsGroup, imports, null));
|
||||
data.append(generateClassModelsTypescript(paramEntry.getValue(), tsGroup, imports, false));
|
||||
data.append(",");
|
||||
}
|
||||
data.append("\n\t\t},");
|
||||
}
|
||||
if (interfaceElement.unnamedElement.size() == 1) {
|
||||
data.append("\n\t\tdata: ");
|
||||
data.append(generateClassModelTypescript(interfaceElement.unnamedElement.get(0), tsGroup, imports,
|
||||
writeImports));
|
||||
data.append(generateClassModelTypescript(interfaceElement.unnamedElement.get(0), tsGroup, writeImports,
|
||||
true));
|
||||
data.append(",");
|
||||
} else if (interfaceElement.multiPartParameters.size() != 0) {
|
||||
data.append("\n\t\tdata: {");
|
||||
for (final Entry<String, OptionalClassModel> pathEntry : interfaceElement.multiPartParameters
|
||||
for (final Entry<String, List<ClassModel>> pathEntry : interfaceElement.multiPartParameters
|
||||
.entrySet()) {
|
||||
data.append("\n\t\t\t");
|
||||
data.append(pathEntry.getKey());
|
||||
if (pathEntry.getValue().optional()) {
|
||||
data.append("?");
|
||||
}
|
||||
data.append(": ");
|
||||
data.append(generateClassModelsTypescript(pathEntry.getValue().model(), tsGroup, imports,
|
||||
writeImports));
|
||||
data.append(generateClassModelsTypescript(pathEntry.getValue(), tsGroup, writeImports, true));
|
||||
data.append(",");
|
||||
}
|
||||
data.append("\n\t\t},");
|
||||
@ -276,7 +264,7 @@ public class TsApiGeneration {
|
||||
data.append(",");
|
||||
}
|
||||
if (needGenerateProgress) {
|
||||
data.append("\n\t\tcallbacks?: RESTCallbacks,");
|
||||
data.append("\n\t\tcallback?: RESTCallbacks,");
|
||||
toolImports.add("RESTCallbacks");
|
||||
}
|
||||
data.append("\n\t}): Promise<");
|
||||
@ -287,7 +275,7 @@ public class TsApiGeneration {
|
||||
toolImports.add("RESTRequestJson");
|
||||
} else {
|
||||
final String returnType = generateClassModelsTypescript(interfaceElement.returnTypes, tsGroup, imports,
|
||||
null);
|
||||
false);
|
||||
data.append(returnType);
|
||||
data.append("> {");
|
||||
if ("void".equals(returnType)) {
|
||||
@ -332,7 +320,7 @@ public class TsApiGeneration {
|
||||
data.append("\n\t\t\t\taccept: produce,");
|
||||
} else {
|
||||
final String returnType = generateClassModelsTypescript(interfaceElement.returnTypes, tsGroup,
|
||||
imports, null);
|
||||
imports, false);
|
||||
if (!"void".equals(returnType)) {
|
||||
for (final String elem : produces) {
|
||||
if (MediaType.APPLICATION_JSON.equals(elem)) {
|
||||
@ -358,7 +346,7 @@ public class TsApiGeneration {
|
||||
data.append("\n\t\t\tdata,");
|
||||
}
|
||||
if (needGenerateProgress) {
|
||||
data.append("\n\t\t\tcallbacks,");
|
||||
data.append("\n\t\t\tcallback,");
|
||||
}
|
||||
data.append("\n\t\t}");
|
||||
if (returnComplexModel != null) {
|
||||
@ -423,10 +411,7 @@ public class TsApiGeneration {
|
||||
}
|
||||
for (final ClassModel model : writeImports) {
|
||||
final TsClassElement tsModel = tsGroup.find(model);
|
||||
if (tsModel.nativeType != DefinedPosition.NORMAL) {
|
||||
continue;
|
||||
}
|
||||
if (tsModel.models.get(0).isNoWriteSpecificMode()) {
|
||||
if (tsModel.nativeType == DefinedPosition.NATIVE) {
|
||||
continue;
|
||||
}
|
||||
finalImportSet.add(tsModel.tsTypeName + "Write");
|
||||
@ -444,10 +429,6 @@ public class TsApiGeneration {
|
||||
|
||||
out.append(data.toString());
|
||||
|
||||
final Path path = Paths.get(pathPackage + File.separator + "api");
|
||||
if (Files.notExists(path)) {
|
||||
Files.createDirectories(path);
|
||||
}
|
||||
final String fileName = TsClassElement.determineFileName(element.name);
|
||||
final FileWriter myWriter = new FileWriter(
|
||||
pathPackage + File.separator + "api" + File.separator + fileName + ".ts");
|
||||
|
@ -181,18 +181,12 @@ public class TsClassElement {
|
||||
if (tsModel.nativeType != DefinedPosition.NATIVE) {
|
||||
out.append("import {");
|
||||
out.append(tsModel.zodName);
|
||||
if (tsModel.nativeType == DefinedPosition.NORMAL && !(tsModel.models.get(0).isNoWriteSpecificMode())) {
|
||||
out.append(", ");
|
||||
out.append(tsModel.zodName);
|
||||
out.append("Write ");
|
||||
}
|
||||
out.append("} from \"./");
|
||||
out.append(tsModel.fileName);
|
||||
out.append("\";\n");
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
|
||||
}
|
||||
|
||||
private Object generateComment(final ClassObjectModel model) {
|
||||
@ -221,68 +215,31 @@ public class TsClassElement {
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public boolean isOptionalTypeZod(final FieldProperty field) {
|
||||
public String optionalTypeZod(final FieldProperty field) {
|
||||
// Common checking element (apply to List, Map, ...)
|
||||
if (field.nullable()) {
|
||||
return true;
|
||||
return ".optional()";
|
||||
}
|
||||
if (field.notNull()) {
|
||||
return false;
|
||||
return "";
|
||||
}
|
||||
// Other object:
|
||||
if (field.model().getOriginClasses() == null || field.model().getOriginClasses().isPrimitive()) {
|
||||
return false;
|
||||
return "";
|
||||
}
|
||||
if (field.columnNotNull()) {
|
||||
return false;
|
||||
return "";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String optionalTypeZod(final FieldProperty field) {
|
||||
// Common checking element (apply to List, Map, ...)
|
||||
if (isOptionalTypeZod(field)) {
|
||||
return ".optional()";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String optionalWriteTypeZod(final FieldProperty field) {
|
||||
// Common checking element (apply to List, Map, ...)
|
||||
if (isOptionalTypeZod(field)) {
|
||||
return ".nullable()";
|
||||
}
|
||||
return "";
|
||||
return ".optional()";
|
||||
}
|
||||
|
||||
public String maxSizeZod(final FieldProperty field) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
final Class<?> clazz = field.model().getOriginClasses();
|
||||
if (clazz == String.class) {
|
||||
if (field.sizeMin() > 0) {
|
||||
builder.append(".min(");
|
||||
builder.append(field.sizeMin());
|
||||
builder.append(")");
|
||||
}
|
||||
if (field.sizeMax() > 0) {
|
||||
builder.append(".max(");
|
||||
builder.append(field.sizeMax());
|
||||
builder.append(")");
|
||||
}
|
||||
}
|
||||
if (clazz == short.class || clazz == Short.class || clazz == int.class || clazz == Integer.class
|
||||
|| clazz == long.class || clazz == Long.class || clazz == float.class || clazz == Float.class
|
||||
|| clazz == double.class || clazz == Double.class) {
|
||||
if (field.min() != null && field.min() > 0) {
|
||||
builder.append(".min(");
|
||||
builder.append(field.min());
|
||||
builder.append(")");
|
||||
}
|
||||
if (field.max() != null && field.max() > 0) {
|
||||
builder.append(".max(");
|
||||
builder.append(field.max());
|
||||
builder.append(")");
|
||||
}
|
||||
if (field.limitSize() > 0 && clazz == String.class) {
|
||||
builder.append(".max(");
|
||||
builder.append(field.limitSize());
|
||||
builder.append(")");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
@ -313,9 +270,7 @@ public class TsClassElement {
|
||||
out.append(getBaseHeader());
|
||||
out.append(generateImports(model.getDependencyModels(), tsGroup));
|
||||
out.append("\n");
|
||||
// ------------------------------------------------------------------------
|
||||
// -- Generate read mode
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
out.append(generateComment(model));
|
||||
out.append("export const ");
|
||||
out.append(this.zodName);
|
||||
@ -360,85 +315,27 @@ public class TsClassElement {
|
||||
out.append("\n});\n");
|
||||
out.append(generateZodInfer(this.tsTypeName, this.zodName));
|
||||
out.append(generateExportCheckFunctionWrite(""));
|
||||
// check if we need to generate write mode :
|
||||
if (!model.isNoWriteSpecificMode()) {
|
||||
// ------------------------------------------------------------------------
|
||||
// -- Generate write mode
|
||||
// ------------------------------------------------------------------------
|
||||
//out.append(generateComment(model));
|
||||
out.append("export const ");
|
||||
out.append(this.zodName);
|
||||
out.append("Write = ");
|
||||
|
||||
if (model.getExtendsClass() != null) {
|
||||
final ClassModel parentClass = model.getExtendsClass();
|
||||
final TsClassElement tsParentModel = tsGroup.find(parentClass);
|
||||
out.append(tsParentModel.zodName);
|
||||
out.append("Write");
|
||||
out.append(".extend({");
|
||||
} else {
|
||||
out.append("zod.object({");
|
||||
}
|
||||
out.append("\n");
|
||||
for (final FieldProperty field : model.getFields()) {
|
||||
// remove all readOnly field
|
||||
if (field.readOnly()) {
|
||||
continue;
|
||||
}
|
||||
final ClassModel fieldModel = field.model();
|
||||
if (field.comment() != null) {
|
||||
out.append("\t/**\n");
|
||||
out.append("\t * ");
|
||||
out.append(field.comment());
|
||||
out.append("\n\t */\n");
|
||||
}
|
||||
// Generate the Write Type associated.
|
||||
out.append("\nexport const ");
|
||||
out.append(this.zodName);
|
||||
out.append("Write = ");
|
||||
out.append(this.zodName);
|
||||
if (omitField.size() != 0) {
|
||||
out.append(".omit({\n");
|
||||
for (final String elem : omitField) {
|
||||
out.append("\t");
|
||||
out.append(field.name());
|
||||
out.append(": ");
|
||||
if (fieldModel instanceof ClassEnumModel || fieldModel instanceof ClassObjectModel) {
|
||||
final TsClassElement tsFieldModel = tsGroup.find(fieldModel);
|
||||
out.append(tsFieldModel.zodName);
|
||||
} else if (fieldModel instanceof final ClassListModel fieldListModel) {
|
||||
final String data = generateTsList(fieldListModel, tsGroup);
|
||||
out.append(data);
|
||||
} else if (fieldModel instanceof final ClassMapModel fieldMapModel) {
|
||||
final String data = generateTsMap(fieldMapModel, tsGroup);
|
||||
out.append(data);
|
||||
}
|
||||
out.append(maxSizeZod(field));
|
||||
out.append(optionalWriteTypeZod(field));
|
||||
// all write field are optional
|
||||
if (field.model() instanceof final ClassObjectModel plop) {
|
||||
if (!plop.isPrimitive()) {
|
||||
out.append(".optional()");
|
||||
}
|
||||
} else {
|
||||
out.append(".optional()");
|
||||
}
|
||||
out.append(",\n");
|
||||
out.append(elem);
|
||||
out.append(": true,\n");
|
||||
}
|
||||
out.append("\n});\n");
|
||||
out.append(generateZodInfer(this.tsTypeName + "Write", this.zodName + "Write"));
|
||||
// Check only the input value ==> no need of the output
|
||||
out.append(generateExportCheckFunctionWrite("Write"));
|
||||
// Generate the Write Type associated.
|
||||
/*
|
||||
out.append("\nexport const ");
|
||||
out.append(this.zodName);
|
||||
out.append("Write = ");
|
||||
out.append(this.zodName);
|
||||
if (omitField.size() != 0) {
|
||||
out.append(".omit({\n");
|
||||
for (final String elem : omitField) {
|
||||
out.append("\t");
|
||||
out.append(elem);
|
||||
out.append(": true,\n");
|
||||
}
|
||||
out.append("\n})");
|
||||
}
|
||||
out.append(".partial();\n");
|
||||
*/
|
||||
out.append("\n})");
|
||||
}
|
||||
out.append(".partial();\n");
|
||||
out.append(generateZodInfer(this.tsTypeName + "Write", this.zodName + "Write"));
|
||||
|
||||
// Check only the input value ==> no need of the output
|
||||
out.append(generateExportCheckFunctionWrite("Write"));
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,6 @@ import java.util.Map.Entry;
|
||||
|
||||
import org.kar.archidata.annotation.security.PermitTokenInURI;
|
||||
import org.kar.archidata.catcher.RestErrorResponse;
|
||||
import org.kar.archidata.exception.SystemException;
|
||||
import org.kar.archidata.model.UserByToken;
|
||||
import org.kar.archidata.tools.JWTWrapper;
|
||||
import org.slf4j.Logger;
|
||||
@ -24,7 +23,6 @@ import jakarta.annotation.Priority;
|
||||
import jakarta.annotation.security.DenyAll;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Priorities;
|
||||
import jakarta.ws.rs.container.ContainerRequestContext;
|
||||
import jakarta.ws.rs.container.ContainerRequestFilter;
|
||||
@ -44,40 +42,18 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
||||
@Context
|
||||
private ResourceInfo resourceInfo;
|
||||
protected final String applicationName;
|
||||
protected final String issuer;
|
||||
|
||||
public static final String AUTHENTICATION_SCHEME = "Bearer";
|
||||
public static final String APIKEY = "ApiKey";
|
||||
|
||||
public AuthenticationFilter(final String applicationName) {
|
||||
this.applicationName = applicationName;
|
||||
this.issuer = "KarAuth";
|
||||
}
|
||||
|
||||
public AuthenticationFilter(final String applicationName, final String issuer) {
|
||||
this.applicationName = applicationName;
|
||||
this.issuer = issuer;
|
||||
}
|
||||
|
||||
public String getRequestedPath(final ContainerRequestContext requestContext) {
|
||||
final Class<?> resourceClass = this.resourceInfo.getResourceClass();
|
||||
final Method resourceMethod = this.resourceInfo.getResourceMethod();
|
||||
final String classPath = resourceClass.isAnnotationPresent(Path.class)
|
||||
? resourceClass.getAnnotation(Path.class).value()
|
||||
: "";
|
||||
final String methodPath = resourceMethod.isAnnotationPresent(Path.class)
|
||||
? resourceMethod.getAnnotation(Path.class).value()
|
||||
: "";
|
||||
final String fullPath = (classPath.startsWith("/") ? "" : "/") + classPath
|
||||
+ (methodPath.startsWith("/") ? "" : "/") + methodPath;
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void filter(final ContainerRequestContext requestContext) throws IOException {
|
||||
/* logger.debug("-----------------------------------------------------"); logger.debug("---- Check if have authorization ----");
|
||||
* logger.debug("-----------------------------------------------------"); logger.debug(" for:{}", requestContext.getUriInfo().getPath()); */
|
||||
|
||||
final Method method = this.resourceInfo.getResourceMethod();
|
||||
// Access denied for all
|
||||
if (method.isAnnotationPresent(DenyAll.class)) {
|
||||
@ -164,13 +140,12 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
||||
final List<String> roles = Arrays.asList(rolesAnnotation.value());
|
||||
// check if the user have the right:
|
||||
boolean haveRight = false;
|
||||
try {
|
||||
haveRight = checkRight(requestContext, userContext, roles);
|
||||
} catch (final SystemException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
for (final String role : roles) {
|
||||
if (userContext.isUserInRole(role)) {
|
||||
haveRight = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Is user valid?
|
||||
if (!haveRight) {
|
||||
LOGGER.error("REJECTED not enought right : {} require: {}", requestContext.getUriInfo().getPath(), roles);
|
||||
@ -182,18 +157,6 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
||||
// logger.debug("Get local user : {} / {}", user, userByToken);
|
||||
}
|
||||
|
||||
protected boolean checkRight(
|
||||
final ContainerRequestContext requestContext,
|
||||
final MySecurityContext userContext,
|
||||
final List<String> roles) throws SystemException {
|
||||
for (final String role : roles) {
|
||||
if (userContext.isUserInRole(this.applicationName + "/" + role)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isTokenBasedAuthentication(final String authorizationHeader) {
|
||||
// Check if the Authorization header is valid
|
||||
// It must not be null and must be prefixed with "Bearer" plus a whitespace
|
||||
@ -230,7 +193,7 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
||||
// must be override to be good implementation
|
||||
protected UserByToken validateJwtToken(final String authorization) throws Exception {
|
||||
// logger.debug(" validate token : " + authorization);
|
||||
final JWTClaimsSet ret = JWTWrapper.validateToken(authorization, this.issuer, null);
|
||||
final JWTClaimsSet ret = JWTWrapper.validateToken(authorization, "KarAuth", null);
|
||||
// check the token is valid !!! (signed and coherent issuer...
|
||||
if (ret == null) {
|
||||
LOGGER.error("The token is not valid: '{}'", authorization);
|
||||
@ -245,16 +208,13 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
||||
user.type = UserByToken.TYPE_USER;
|
||||
final Object rowRight = ret.getClaim("right");
|
||||
if (rowRight != null) {
|
||||
LOGGER.info("Detect right in Authentication Filter: {}", rowRight);
|
||||
user.right = (Map<String, Map<String, Object>>) ret.getClaim("right");
|
||||
/*
|
||||
final Map<String, Map<String, Object>> rights = (Map<String, Map<String, Object>>) ret.getClaim("right");
|
||||
if (rights.containsKey(this.applicationName)) {
|
||||
user.right = rights.get(this.applicationName);
|
||||
} else {
|
||||
LOGGER.error("Connect with no right for this application='{}' full Right='{}'", this.applicationName,
|
||||
rights);
|
||||
}
|
||||
*/
|
||||
}
|
||||
// logger.debug("request user: '{}' right: '{}' row='{}'", userUID, user.right, rowRight);
|
||||
return user;
|
||||
|
@ -16,12 +16,9 @@ public class CORSFilter implements ContainerResponseFilter {
|
||||
// System.err.println("filter cors ..." + request.toString());
|
||||
|
||||
response.getHeaders().add("Access-Control-Allow-Origin", "*");
|
||||
response.getHeaders().add("Access-Control-Allow-Range", "bytes");
|
||||
response.getHeaders().add("access-control-expose-headers", "range");
|
||||
response.getHeaders().add("Access-Control-Allow-Headers",
|
||||
"Origin, content-type, Content-type, Accept, Authorization, mime-type, filename, Range");
|
||||
"Origin, content-type, Content-type, Accept, Authorization, mime-type, filename");
|
||||
response.getHeaders().add("Access-Control-Allow-Credentials", "true");
|
||||
response.getHeaders().add("Access-Control-Allow-Methods",
|
||||
"GET, POST, PUT, PATCH, DELETE, ARCHIVE, RESTORE, OPTIONS, HEAD");
|
||||
response.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD");
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,13 @@
|
||||
package org.kar.archidata.filter;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Set;
|
||||
|
||||
import org.kar.archidata.model.UserByToken;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.core.SecurityContext;
|
||||
|
||||
// https://simplapi.wordpress.com/2015/09/19/jersey-jax-rs-securitycontext-in-action/
|
||||
public class MySecurityContext implements SecurityContext {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MySecurityContext.class);
|
||||
class MySecurityContext implements SecurityContext {
|
||||
|
||||
private final GenericContext contextPrincipale;
|
||||
private final String sheme;
|
||||
@ -26,126 +22,15 @@ public class MySecurityContext implements SecurityContext {
|
||||
return this.contextPrincipale;
|
||||
}
|
||||
|
||||
public Object getRightOfRoleInGroup(final String group, final String role) {
|
||||
if (this.contextPrincipale.userByToken != null) {
|
||||
return this.contextPrincipale.userByToken.getRight(group, role);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Set<String> getGroups() {
|
||||
if (this.contextPrincipale.userByToken != null) {
|
||||
return this.contextPrincipale.userByToken.getGroups();
|
||||
}
|
||||
return Set.of();
|
||||
}
|
||||
|
||||
public boolean groupExist(final String group) {
|
||||
if (this.contextPrincipale.userByToken != null) {
|
||||
return this.contextPrincipale.userByToken.groupExist(group);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Not sure the Long type is definitive.
|
||||
public Long getUserID() {
|
||||
if (this.contextPrincipale.userByToken != null) {
|
||||
return this.contextPrincipale.userByToken.id;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean checkRightInGroup(
|
||||
final String group,
|
||||
final String role,
|
||||
final boolean needRead,
|
||||
final boolean needWrite) {
|
||||
if ("USER".equals(role)) {
|
||||
if (groupExist(group)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// get associated Roles:
|
||||
final Object rightPart = getRightOfRoleInGroup(group, role);
|
||||
LOGGER.info("detect : {}", rightPart);
|
||||
long dataRight = 0;
|
||||
if (rightPart instanceof final Long rightPartCasted) {
|
||||
dataRight = rightPartCasted;
|
||||
} else if (rightPart instanceof final Integer rightPartCasted) {
|
||||
dataRight = rightPartCasted;
|
||||
}
|
||||
if (dataRight == PartRight.READ_WRITE.getValue()) {
|
||||
return true;
|
||||
}
|
||||
if (!needRead && needWrite && dataRight == PartRight.WRITE.getValue()) {
|
||||
return true;
|
||||
}
|
||||
if (needRead && !needWrite && dataRight == PartRight.READ.getValue()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUserInRole(final String role) {
|
||||
String roleEdit = role;
|
||||
boolean needRead = false;
|
||||
boolean needWrite = false;
|
||||
// Check if the API overwrite the right needed for this API.
|
||||
if (roleEdit.contains(":")) {
|
||||
if (roleEdit.endsWith(":w")) {
|
||||
try {
|
||||
roleEdit = roleEdit.substring(0, roleEdit.length() - 2);
|
||||
} catch (final IndexOutOfBoundsException ex) {
|
||||
LOGGER.error("Fail to extract role of '{}'", role);
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
needWrite = true;
|
||||
} else if (roleEdit.endsWith(":r")) {
|
||||
try {
|
||||
roleEdit = roleEdit.substring(0, roleEdit.length() - 2);
|
||||
} catch (final IndexOutOfBoundsException ex) {
|
||||
LOGGER.error("Fail to extract role of '{}'", role);
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
needRead = true;
|
||||
} else if (roleEdit.endsWith(":rw")) {
|
||||
try {
|
||||
roleEdit = roleEdit.substring(0, roleEdit.length() - 3);
|
||||
} catch (final IndexOutOfBoundsException ex) {
|
||||
LOGGER.error("Fail to extract role of '{}'", role);
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
needRead = true;
|
||||
needWrite = true;
|
||||
} else {
|
||||
LOGGER.error("Request check right of an unknow right mode: {} (after ':')", roleEdit);
|
||||
return false;
|
||||
if (this.contextPrincipale.userByToken != null) {
|
||||
final Object value = this.contextPrincipale.userByToken.right.get(role);
|
||||
if (value instanceof final Boolean ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
if (roleEdit.contains("/")) {
|
||||
final String[] elements = roleEdit.split("/");
|
||||
return checkRightInGroup(elements[0], elements[1], needRead, needWrite);
|
||||
}
|
||||
// Special case, if the token is valid, it is an USER ...
|
||||
if ("USER".equals(roleEdit)) {
|
||||
return true;
|
||||
}
|
||||
return checkRightInGroup("?system?", roleEdit, needRead, needWrite);
|
||||
}
|
||||
|
||||
public Object getRole(final String role) {
|
||||
LOGGER.info("contextPrincipale={}", this.contextPrincipale);
|
||||
if (this.contextPrincipale.userByToken != null) {
|
||||
LOGGER.info("contextPrincipale.userByToken={}", this.contextPrincipale.userByToken);
|
||||
LOGGER.info("contextPrincipale.userByToken.right={}", this.contextPrincipale.userByToken.right);
|
||||
return this.contextPrincipale.userByToken.right.get(role);
|
||||
}
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,30 +0,0 @@
|
||||
package org.kar.archidata.filter;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
public enum PartRight {
|
||||
NONE(0), //
|
||||
READ(1), //
|
||||
WRITE(2), //
|
||||
READ_WRITE(3);
|
||||
|
||||
private final int value;
|
||||
|
||||
PartRight(final int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public static PartRight fromValue(final int value) {
|
||||
for (final PartRight element : values()) {
|
||||
if (element.getValue() == value) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("PartRight: Unknown value: " + value);
|
||||
}
|
||||
}
|
@ -28,29 +28,26 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.annotation.Nullable;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import jakarta.ws.rs.DefaultValue;
|
||||
|
||||
@Table(name = "user")
|
||||
@DataIfNotExists
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class User extends GenericDataSoftDelete {
|
||||
@NotNull
|
||||
@Column(length = 128)
|
||||
@Size(min = 3, max = 128)
|
||||
@Pattern(regexp = "^[a-zA-Z0-9-_ \\.]+$")
|
||||
public String login = null;
|
||||
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
|
||||
public Timestamp lastConnection = null;
|
||||
|
||||
@DefaultValue("'0'")
|
||||
@Column(nullable = false)
|
||||
public boolean admin = false;
|
||||
@DefaultValue("'0'")
|
||||
@Column(nullable = false)
|
||||
public boolean blocked = false;
|
||||
@Column(length = 512)
|
||||
public String blockedReason;
|
||||
@DefaultValue("'0'")
|
||||
@Column(nullable = false)
|
||||
public boolean removed = false;
|
||||
|
||||
@Schema(description = "List of Id of the specific covers")
|
||||
@DataJson(targetEntity = Data.class)
|
||||
@ -59,8 +56,7 @@ public class User extends GenericDataSoftDelete {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User [login=" + this.login + ", last=" + this.lastConnection + ", blocked=" + this.blocked
|
||||
+ ", blockedReason=" + this.blockedReason + "]";
|
||||
return "User [login=" + this.login + ", last=" + this.lastConnection + ", admin=" + this.admin + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package org.kar.archidata.model;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class UserByToken {
|
||||
public static final int TYPE_USER = -1;
|
||||
@ -14,35 +13,13 @@ public class UserByToken {
|
||||
public Long parentId = null; // FOr application, this is the id of the application, and of user token, this is the USERID
|
||||
public String name = null;
|
||||
// Right map
|
||||
public Map<String, Map<String, Object>> right = new HashMap<>();
|
||||
public Map<String, Object> right = new HashMap<>();
|
||||
|
||||
public Set<String> getGroups() {
|
||||
return this.right.keySet();
|
||||
}
|
||||
|
||||
public boolean groupExist(final String group) {
|
||||
if (!this.right.containsKey(group)) {
|
||||
return false;
|
||||
}
|
||||
return this.right.containsKey(group);
|
||||
}
|
||||
|
||||
public Object getRight(final String group, final String key) {
|
||||
if (!this.right.containsKey(group)) {
|
||||
return null;
|
||||
}
|
||||
final Map<String, Object> rightGroup = this.right.get(group);
|
||||
if (!rightGroup.containsKey(key)) {
|
||||
return null;
|
||||
}
|
||||
return rightGroup.get(key);
|
||||
}
|
||||
|
||||
public boolean hasRight(final String group, final String key, final Object value) {
|
||||
final Object data = getRight(group, key);
|
||||
if (data == null) {
|
||||
public boolean hasRight(final String key, final Object value) {
|
||||
if (!this.right.containsKey(key)) {
|
||||
return false;
|
||||
}
|
||||
final Object data = this.right.get(key);
|
||||
if (data instanceof final Boolean elem) {
|
||||
if (value instanceof final Boolean castVal) {
|
||||
if (elem.equals(castVal)) {
|
||||
|
@ -11,11 +11,9 @@ import java.nio.file.StandardCopyOption;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.tika.Tika;
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
import org.kar.archidata.api.DataResource;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
@ -24,15 +22,10 @@ import org.kar.archidata.dataAccess.QueryCondition;
|
||||
import org.kar.archidata.dataAccess.addOn.AddOnDataJson;
|
||||
import org.kar.archidata.dataAccess.options.Condition;
|
||||
import org.kar.archidata.dataAccess.options.ReadAllColumn;
|
||||
import org.kar.archidata.exception.FailException;
|
||||
import org.kar.archidata.exception.InputException;
|
||||
import org.kar.archidata.model.Data;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.client.Client;
|
||||
import jakarta.ws.rs.client.ClientBuilder;
|
||||
import jakarta.ws.rs.client.WebTarget;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
public class DataTools {
|
||||
@ -42,9 +35,6 @@ public class DataTools {
|
||||
public final static int CHUNK_SIZE_IN = 50 * 1024 * 1024; // 1MB chunks
|
||||
/** Upload some data */
|
||||
private static long tmpFolderId = 1;
|
||||
public final static String[] SUPPORTED_IMAGE_MIME_TYPE = { "image/jpeg", "image/png", "image/webp" };
|
||||
public final static String[] SUPPORTED_AUDIO_MIME_TYPE = { "audio/x-matroska" };
|
||||
public final static String[] SUPPORTED_VIDEO_MIME_TYPE = { "video/x-matroska", "video/webm" };
|
||||
|
||||
public static void createFolder(final String path) throws IOException {
|
||||
if (!Files.exists(java.nio.file.Path.of(path))) {
|
||||
@ -99,12 +89,20 @@ public class DataTools {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Data createNewData(
|
||||
final long tmpUID,
|
||||
final String originalFileName,
|
||||
final String sha512,
|
||||
final String mimeType) throws IOException, SQLException {
|
||||
|
||||
public static Data createNewData(final long tmpUID, final String originalFileName, final String sha512)
|
||||
throws IOException, SQLException {
|
||||
// determine mime type:
|
||||
String mimeType = "";
|
||||
final String extension = originalFileName.substring(originalFileName.lastIndexOf('.') + 1);
|
||||
mimeType = switch (extension.toLowerCase()) {
|
||||
case "jpg", "jpeg" -> "image/jpeg";
|
||||
case "png" -> "image/png";
|
||||
case "webp" -> "image/webp";
|
||||
case "mka" -> "audio/x-matroska";
|
||||
case "mkv" -> "video/x-matroska";
|
||||
case "webm" -> "video/webm";
|
||||
default -> throw new IOException("Can not find the mime type of data input: '" + extension + "'");
|
||||
};
|
||||
final String tmpPath = getTmpFileInData(tmpUID);
|
||||
final long fileSize = Files.size(Paths.get(tmpPath));
|
||||
Data out = new Data();
|
||||
@ -130,23 +128,6 @@ public class DataTools {
|
||||
return out;
|
||||
}
|
||||
|
||||
public static Data createNewData(final long tmpUID, final String originalFileName, final String sha512)
|
||||
throws IOException, SQLException {
|
||||
// determine mime type:
|
||||
String mimeType = "";
|
||||
final String extension = originalFileName.substring(originalFileName.lastIndexOf('.') + 1);
|
||||
mimeType = switch (extension.toLowerCase()) {
|
||||
case "jpg", "jpeg" -> "image/jpeg";
|
||||
case "png" -> "image/png";
|
||||
case "webp" -> "image/webp";
|
||||
case "mka" -> "audio/x-matroska";
|
||||
case "mkv" -> "video/x-matroska";
|
||||
case "webm" -> "video/webm";
|
||||
default -> throw new IOException("Can not find the mime type of data input: '" + extension + "'");
|
||||
};
|
||||
return createNewData(tmpUID, originalFileName, sha512, mimeType);
|
||||
}
|
||||
|
||||
public static void undelete(final UUID id) {
|
||||
try {
|
||||
DataAccess.unsetDelete(Data.class, id);
|
||||
@ -160,10 +141,6 @@ public class DataTools {
|
||||
return saveFile(uploadedInputStream, getTmpFileInData(idData));
|
||||
}
|
||||
|
||||
public static String saveTemporaryFile(final byte[] uploadedInputStream, final long idData) {
|
||||
return saveFile(uploadedInputStream, getTmpFileInData(idData));
|
||||
}
|
||||
|
||||
public static void removeTemporaryFile(final long idData) {
|
||||
final String filepath = getTmpFileInData(idData);
|
||||
if (Files.exists(Paths.get(filepath))) {
|
||||
@ -209,31 +186,6 @@ public class DataTools {
|
||||
return out;
|
||||
}
|
||||
|
||||
public static String saveFile(final byte[] bytes, final String serverLocation) {
|
||||
String out = "";
|
||||
try {
|
||||
final OutputStream outpuStream = new FileOutputStream(new File(serverLocation));
|
||||
final MessageDigest md = MessageDigest.getInstance("SHA-512");
|
||||
md.update(bytes, 0, bytes.length);
|
||||
outpuStream.write(bytes, 0, bytes.length);
|
||||
|
||||
LOGGER.info("Flush input stream ... {}", serverLocation);
|
||||
outpuStream.flush();
|
||||
outpuStream.close();
|
||||
// create the end of sha512
|
||||
final byte[] sha512Digest = md.digest();
|
||||
// convert in hexadecimal
|
||||
out = bytesToHex(sha512Digest);
|
||||
} catch (final IOException ex) {
|
||||
LOGGER.error("Can not write in temporary file ... ");
|
||||
ex.printStackTrace();
|
||||
} catch (final NoSuchAlgorithmException ex) {
|
||||
LOGGER.error("Can not find sha512 algorithms");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// curl http://localhost:9993/api/users/3
|
||||
// @Secured
|
||||
/* @GET
|
||||
@ -259,144 +211,67 @@ public class DataTools {
|
||||
if (data.contentEquals("null")) {
|
||||
return null;
|
||||
}
|
||||
if (data.contentEquals("undefined")) {
|
||||
return null;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static String getMimeType(final byte[] data) {
|
||||
final Tika tika = new Tika();
|
||||
final String mimeType = tika.detect(data);
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
public static <CLASS_TYPE, ID_TYPE> void uploadCoverFromUri(
|
||||
final Class<CLASS_TYPE> clazz,
|
||||
final ID_TYPE id,
|
||||
final String url) throws Exception {
|
||||
|
||||
LOGGER.info(" - id: {}", id);
|
||||
LOGGER.info(" - url: {} ", url);
|
||||
final CLASS_TYPE media = DataAccess.get(clazz, id);
|
||||
if (media == null) {
|
||||
throw new InputException(clazz.getCanonicalName(),
|
||||
"[" + id.toString() + "] Id does not exist or removed...");
|
||||
}
|
||||
// Download data:
|
||||
|
||||
final Client client = ClientBuilder.newClient();
|
||||
byte[] dataResponse = null;
|
||||
try {
|
||||
final WebTarget target = client.target(url);
|
||||
final Response response = target.request().get();
|
||||
if (response.getStatus() != 200) {
|
||||
throw new FailException(Response.Status.BAD_GATEWAY,
|
||||
clazz.getCanonicalName() + "[" + id.toString() + "] Can not download the media");
|
||||
}
|
||||
dataResponse = response.readEntity(byte[].class);
|
||||
} catch (final Exception ex) {
|
||||
throw new FailException(Response.Status.INTERNAL_SERVER_ERROR,
|
||||
clazz.getCanonicalName() + "[" + id.toString() + "] can not create input media", ex);
|
||||
}
|
||||
if (dataResponse == null) {
|
||||
throw new FailException(Response.Status.NOT_ACCEPTABLE,
|
||||
clazz.getCanonicalName() + "[" + id.toString() + "] Data does not exist");
|
||||
}
|
||||
if (dataResponse.length == 0 || dataResponse.length == 50 * 1024 * 1024) {
|
||||
throw new FailException(Response.Status.NOT_ACCEPTABLE, clazz.getCanonicalName() + "[" + id.toString()
|
||||
+ "] Data size is not correct " + dataResponse.length);
|
||||
}
|
||||
|
||||
final long tmpUID = getTmpDataId();
|
||||
final String sha512 = saveTemporaryFile(dataResponse, tmpUID);
|
||||
Data data = getWithSha512(sha512);
|
||||
final String mimeType = getMimeType(dataResponse);
|
||||
if (!Arrays.asList(SUPPORTED_IMAGE_MIME_TYPE).contains(mimeType)) {
|
||||
throw new FailException(Response.Status.NOT_ACCEPTABLE,
|
||||
clazz.getCanonicalName() + "[" + id.toString() + "] Data CoverType is not accesptable: " + mimeType
|
||||
+ "support only: " + String.join(", ", SUPPORTED_IMAGE_MIME_TYPE));
|
||||
|
||||
}
|
||||
if (data == null) {
|
||||
LOGGER.info("Need to add the data in the BDD ... ");
|
||||
try {
|
||||
data = createNewData(tmpUID, url, sha512, mimeType);
|
||||
} catch (final IOException ex) {
|
||||
removeTemporaryFile(tmpUID);
|
||||
throw new FailException(Response.Status.NOT_MODIFIED,
|
||||
clazz.getCanonicalName() + "[" + id.toString() + "] can not create input media", ex);
|
||||
} catch (final SQLException ex) {
|
||||
removeTemporaryFile(tmpUID);
|
||||
throw new FailException(Response.Status.NOT_MODIFIED,
|
||||
clazz.getCanonicalName() + "[" + id.toString() + "] Error in SQL insertion", ex);
|
||||
}
|
||||
} else if (data.deleted) {
|
||||
LOGGER.error("Data already exist but deleted");
|
||||
undelete(data.uuid);
|
||||
data.deleted = false;
|
||||
} else {
|
||||
LOGGER.error("Data already exist ... all good");
|
||||
}
|
||||
// Fist step: retrieve all the Id of each parents:...
|
||||
LOGGER.info("Find typeNode");
|
||||
if (id instanceof final Long idLong) {
|
||||
AddOnDataJson.addLink(clazz, idLong, "covers", data.uuid);
|
||||
} else if (id instanceof final UUID idUUID) {
|
||||
AddOnDataJson.addLink(clazz, idUUID, "covers", data.uuid);
|
||||
} else {
|
||||
throw new IOException("Fail to add Cover can not detect type...");
|
||||
}
|
||||
}
|
||||
|
||||
public static <CLASS_TYPE, ID_TYPE> void uploadCover(
|
||||
public static <CLASS_TYPE, ID_TYPE> Response uploadCover(
|
||||
final Class<CLASS_TYPE> clazz,
|
||||
final ID_TYPE id,
|
||||
String fileName,
|
||||
final InputStream fileInputStream,
|
||||
final FormDataContentDisposition fileMetaData) throws Exception {
|
||||
// public NodeSmall uploadFile(final FormDataMultiPart form) {
|
||||
LOGGER.info("Upload media file: {}", fileMetaData);
|
||||
LOGGER.info(" - id: {}", id);
|
||||
LOGGER.info(" - file_name: {} ", fileMetaData.getFileName());
|
||||
LOGGER.info(" - fileInputStream: {}", fileInputStream);
|
||||
LOGGER.info(" - fileMetaData: {}", fileMetaData);
|
||||
final CLASS_TYPE media = DataAccess.get(clazz, id);
|
||||
if (media == null) {
|
||||
throw new InputException(clazz.getCanonicalName(),
|
||||
"[" + id.toString() + "] Id does not exist or removed...");
|
||||
}
|
||||
final FormDataContentDisposition fileMetaData) {
|
||||
try {
|
||||
// correct input string stream :
|
||||
fileName = multipartCorrection(fileName);
|
||||
|
||||
final long tmpUID = getTmpDataId();
|
||||
final String sha512 = saveTemporaryFile(fileInputStream, tmpUID);
|
||||
Data data = getWithSha512(sha512);
|
||||
if (data == null) {
|
||||
LOGGER.info("Need to add the data in the BDD ... ");
|
||||
try {
|
||||
data = createNewData(tmpUID, fileMetaData.getFileName(), sha512);
|
||||
} catch (final IOException ex) {
|
||||
removeTemporaryFile(tmpUID);
|
||||
throw new FailException(Response.Status.NOT_MODIFIED,
|
||||
clazz.getCanonicalName() + "[" + id.toString() + "] can not create input media", ex);
|
||||
} catch (final SQLException ex) {
|
||||
removeTemporaryFile(tmpUID);
|
||||
throw new FailException(Response.Status.NOT_MODIFIED,
|
||||
clazz.getCanonicalName() + "[" + id.toString() + "] Error in SQL insertion", ex);
|
||||
// public NodeSmall uploadFile(final FormDataMultiPart form) {
|
||||
LOGGER.info("Upload media file: {}", fileMetaData);
|
||||
LOGGER.info(" - id: {}", id);
|
||||
LOGGER.info(" - file_name: ", fileName);
|
||||
LOGGER.info(" - fileInputStream: {}", fileInputStream);
|
||||
LOGGER.info(" - fileMetaData: {}", fileMetaData);
|
||||
final CLASS_TYPE media = DataAccess.get(clazz, id);
|
||||
if (media == null) {
|
||||
return Response.notModified("Media Id does not exist or removed...").build();
|
||||
}
|
||||
} else if (data.deleted) {
|
||||
LOGGER.error("Data already exist but deleted");
|
||||
undelete(data.uuid);
|
||||
data.deleted = false;
|
||||
} else {
|
||||
LOGGER.error("Data already exist ... all good");
|
||||
}
|
||||
// Fist step: retrieve all the Id of each parents:...
|
||||
LOGGER.info("Find typeNode");
|
||||
if (id instanceof final Long idLong) {
|
||||
AddOnDataJson.addLink(clazz, idLong, "covers", data.uuid);
|
||||
} else if (id instanceof final UUID idUUID) {
|
||||
AddOnDataJson.addLink(clazz, idUUID, "covers", data.uuid);
|
||||
} else {
|
||||
throw new IOException("Fail to add Cover can not detect type...");
|
||||
|
||||
final long tmpUID = getTmpDataId();
|
||||
final String sha512 = saveTemporaryFile(fileInputStream, tmpUID);
|
||||
Data data = getWithSha512(sha512);
|
||||
if (data == null) {
|
||||
LOGGER.info("Need to add the data in the BDD ... ");
|
||||
try {
|
||||
data = createNewData(tmpUID, fileName, sha512);
|
||||
} catch (final IOException ex) {
|
||||
removeTemporaryFile(tmpUID);
|
||||
ex.printStackTrace();
|
||||
return Response.notModified("can not create input media").build();
|
||||
} catch (final SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
removeTemporaryFile(tmpUID);
|
||||
return Response.notModified("Error in SQL insertion ...").build();
|
||||
}
|
||||
} else if (data.deleted) {
|
||||
LOGGER.error("Data already exist but deleted");
|
||||
undelete(data.uuid);
|
||||
data.deleted = false;
|
||||
} else {
|
||||
LOGGER.error("Data already exist ... all good");
|
||||
}
|
||||
// Fist step: retrieve all the Id of each parents:...
|
||||
LOGGER.info("Find typeNode");
|
||||
if (id instanceof final Long idLong) {
|
||||
AddOnDataJson.addLink(clazz, idLong, "covers", data.uuid);
|
||||
} else if (id instanceof final UUID idUUID) {
|
||||
AddOnDataJson.addLink(clazz, idUUID, "covers", data.uuid);
|
||||
} else {
|
||||
throw new IOException("Fail to add Cover can not detect type...");
|
||||
}
|
||||
return Response.ok(DataAccess.get(clazz, id)).build();
|
||||
} catch (final Exception ex) {
|
||||
System.out.println("Cat ann unexpected error ... ");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return Response.serverError().build();
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ public class JWTWrapper {
|
||||
}
|
||||
in.close();
|
||||
// print result
|
||||
LOGGER.debug(response.toString());
|
||||
// LOGGER.debug(response.toString());
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
final PublicKey values = mapper.readValue(response.toString(), PublicKey.class);
|
||||
rsaPublicJWK = RSAKey.parse(values.key);
|
||||
|
@ -120,8 +120,7 @@ public class RESTApi {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T, U> T modelSendJson(final String model, final Class<T> clazz, final String urlOffset, String body)
|
||||
protected <T, U> T modelSendJson(final String model, final Class<T> clazz, final String urlOffset, String body)
|
||||
throws RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
final HttpClient client = HttpClient.newHttpClient();
|
||||
// client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
|
||||
@ -165,8 +164,7 @@ public class RESTApi {
|
||||
return this.mapper.readValue(httpResponse.body(), clazz);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T modelSendMap(
|
||||
protected <T> T modelSendMap(
|
||||
final String model,
|
||||
final Class<T> clazz,
|
||||
final String urlOffset,
|
||||
@ -222,66 +220,13 @@ public class RESTApi {
|
||||
*/
|
||||
public <T> T delete(final Class<T> clazz, final String urlOffset)
|
||||
throws RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
return simpleRequest("DELETE", clazz, urlOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call an ARCHIVE on a REST API
|
||||
* @param urlOffset Offset to call the API
|
||||
*/
|
||||
public void archive(final String urlOffset) throws RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
archive(Void.class, urlOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a ARCHIVE on a REST API with retrieving some data
|
||||
* @param <T> Type of data that might be received.
|
||||
* @param clazz Class model of the data that might be parsed.
|
||||
* @param urlOffset Offset to call the API
|
||||
* @return The parsed object received.
|
||||
*/
|
||||
public <T> T archive(final Class<T> clazz, final String urlOffset)
|
||||
throws RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
return simpleRequest("ARCHIVE", clazz, urlOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call an RESTORE on a REST API
|
||||
* @param urlOffset Offset to call the API
|
||||
*/
|
||||
public void restore(final String urlOffset) throws RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
restore(Void.class, urlOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a RESTORE on a REST API with retrieving some data
|
||||
* @param <T> Type of data that might be received.
|
||||
* @param clazz Class model of the data that might be parsed.
|
||||
* @param urlOffset Offset to call the API
|
||||
* @return The parsed object received.
|
||||
*/
|
||||
public <T> T restore(final Class<T> clazz, final String urlOffset)
|
||||
throws RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
return simpleRequest("RESTORE", clazz, urlOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a key on a REST API with retrieving some data
|
||||
* @param <T> Type of data that might be received.
|
||||
* @param model name of the key for the REST call
|
||||
* @param clazz Class model of the data that might be parsed.
|
||||
* @param urlOffset Offset to call the API
|
||||
* @return The parsed object received.
|
||||
*/
|
||||
public <T> T simpleRequest(final String model, final Class<T> clazz, final String urlOffset)
|
||||
throws RESTErrorResponseExeption, IOException, InterruptedException {
|
||||
final HttpClient client = HttpClient.newHttpClient();
|
||||
Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1)
|
||||
.uri(URI.create(this.baseUrl + urlOffset));
|
||||
if (this.token != null) {
|
||||
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Bearer " + this.token);
|
||||
}
|
||||
final HttpRequest request = requestBuilding.method(model, BodyPublishers.ofString("")).build();
|
||||
final HttpRequest request = requestBuilding.DELETE().build();
|
||||
final HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
|
||||
try {
|
||||
|
@ -7,15 +7,11 @@
|
||||
import { RestErrorResponse, isRestErrorResponse } from "./model";
|
||||
|
||||
export enum HTTPRequestModel {
|
||||
ARCHIVE = "ARCHIVE",
|
||||
DELETE = "DELETE",
|
||||
HEAD = "HEAD",
|
||||
GET = "GET",
|
||||
OPTION = "OPTION",
|
||||
PATCH = "PATCH",
|
||||
POST = "POST",
|
||||
PUT = "PUT",
|
||||
RESTORE = "RESTORE",
|
||||
}
|
||||
export enum HTTPMimeType {
|
||||
ALL = "*/*",
|
||||
@ -78,7 +74,7 @@ export interface RESTRequestType {
|
||||
data?: any;
|
||||
params?: object;
|
||||
queries?: object;
|
||||
callbacks?: RESTCallbacks;
|
||||
callback?: RESTCallbacks;
|
||||
}
|
||||
|
||||
function replaceAll(input, searchValue, replaceValue) {
|
||||
@ -241,7 +237,7 @@ export function RESTRequest({
|
||||
data,
|
||||
params,
|
||||
queries,
|
||||
callbacks,
|
||||
callback,
|
||||
}: RESTRequestType): Promise<ModelResponseHttp> {
|
||||
// Create the URL PATH:
|
||||
let generateUrl = RESTUrl({ restModel, restConfig, data, params, queries });
|
||||
@ -252,14 +248,9 @@ export function RESTRequest({
|
||||
if (restModel.accept !== undefined) {
|
||||
headers["Accept"] = restModel.accept;
|
||||
}
|
||||
if (restModel.requestType !== HTTPRequestModel.GET &&
|
||||
restModel.requestType !== HTTPRequestModel.ARCHIVE &&
|
||||
restModel.requestType !== HTTPRequestModel.RESTORE
|
||||
) {
|
||||
if (restModel.requestType !== HTTPRequestModel.GET) {
|
||||
// if Get we have not a content type, the body is empty
|
||||
if (restModel.contentType !== HTTPMimeType.MULTIPART &&
|
||||
restModel.contentType !== undefined
|
||||
) {
|
||||
if (restModel.contentType !== HTTPMimeType.MULTIPART) {
|
||||
// special case of multi-part ==> no content type otherwise the browser does not set the ";bundary=--****"
|
||||
headers["Content-Type"] = restModel.contentType;
|
||||
}
|
||||
@ -277,10 +268,10 @@ export function RESTRequest({
|
||||
return new Promise((resolve, reject) => {
|
||||
let action: undefined | Promise<Response> = undefined;
|
||||
if (
|
||||
isNullOrUndefined(callbacks) ||
|
||||
(isNullOrUndefined(callbacks.progressDownload) &&
|
||||
isNullOrUndefined(callbacks.progressUpload) &&
|
||||
isNullOrUndefined(callbacks.abortHandle))
|
||||
isNullOrUndefined(callback) ||
|
||||
(isNullOrUndefined(callback.progressDownload) &&
|
||||
isNullOrUndefined(callback.progressUpload) &&
|
||||
isNullOrUndefined(callback.abortHandle))
|
||||
) {
|
||||
// No information needed: call the generic fetch interface
|
||||
action = fetch(generateUrl, {
|
||||
@ -297,7 +288,7 @@ export function RESTRequest({
|
||||
headers,
|
||||
body,
|
||||
},
|
||||
callbacks
|
||||
callback
|
||||
);
|
||||
}
|
||||
action
|
||||
|
@ -1,40 +0,0 @@
|
||||
package test.kar.archidata;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ConfigureDb {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(ConfigureDb.class);
|
||||
|
||||
public static void configure() throws IOException {
|
||||
if (true) {
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
} else {
|
||||
// Enable this if you want to access to a local MySQL base to test with an adminer
|
||||
ConfigBaseVariable.bdDatabase = "test_db";
|
||||
ConfigBaseVariable.dbPort = "3906";
|
||||
ConfigBaseVariable.dbUser = "root";
|
||||
//ConfigBaseVariable.dbPassword = "password";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
}
|
||||
|
||||
public static void clear() throws IOException {
|
||||
LOGGER.info("Remove the test db");
|
||||
DBEntry.closeAllForceMode();
|
||||
ConfigBaseVariable.clearAllValue();
|
||||
|
||||
}
|
||||
}
|
@ -11,8 +11,11 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -26,12 +29,22 @@ public class TestJson {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void removeDataBase() throws IOException {
|
||||
ConfigureDb.clear();
|
||||
LOGGER.info("Remove the test db");
|
||||
DBEntry.closeAllForceMode();
|
||||
ConfigBaseVariable.clearAllValue();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
|
@ -12,8 +12,11 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -26,12 +29,22 @@ public class TestListJson {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void removeDataBase() throws IOException {
|
||||
ConfigureDb.clear();
|
||||
LOGGER.info("Remove the test db");
|
||||
DBEntry.closeAllForceMode();
|
||||
ConfigBaseVariable.clearAllValue();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
|
@ -11,9 +11,12 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -28,12 +31,22 @@ public class TestManyToMany {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void removeDataBase() throws IOException {
|
||||
ConfigureDb.clear();
|
||||
LOGGER.info("Remove the test db");
|
||||
DBEntry.closeAllForceMode();
|
||||
ConfigBaseVariable.clearAllValue();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@ -116,7 +129,7 @@ public class TestManyToMany {
|
||||
Assertions.assertNotNull(retrieve.otherData);
|
||||
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
||||
Assertions.assertNotNull(retrieve.remote);
|
||||
Assertions.assertEquals(2, retrieve.remote.size());
|
||||
Assertions.assertEquals(retrieve.remote.size(), 2);
|
||||
Assertions.assertEquals(retrieve.remote.get(0), insertedRemote1.id);
|
||||
Assertions.assertEquals(retrieve.remote.get(1), insertedRemote2.id);
|
||||
|
||||
@ -128,7 +141,7 @@ public class TestManyToMany {
|
||||
Assertions.assertNotNull(retrieveExpand.otherData);
|
||||
Assertions.assertEquals(insertedData.otherData, retrieveExpand.otherData);
|
||||
Assertions.assertNotNull(retrieveExpand.remote);
|
||||
Assertions.assertEquals(2, retrieveExpand.remote.size());
|
||||
Assertions.assertEquals(retrieveExpand.remote.size(), 2);
|
||||
Assertions.assertEquals(retrieveExpand.remote.get(0).id, insertedRemote1.id);
|
||||
Assertions.assertEquals(retrieveExpand.remote.get(1).id, insertedRemote2.id);
|
||||
|
||||
|
@ -11,8 +11,11 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -30,12 +33,22 @@ public class TestManyToOne {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void removeDataBase() throws IOException {
|
||||
ConfigureDb.clear();
|
||||
LOGGER.info("Remove the test db");
|
||||
DBEntry.closeAllForceMode();
|
||||
ConfigBaseVariable.clearAllValue();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
|
@ -11,8 +11,11 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -30,12 +33,22 @@ public class TestOneToMany {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void removeDataBase() throws IOException {
|
||||
ConfigureDb.clear();
|
||||
LOGGER.info("Remove the test db");
|
||||
DBEntry.closeAllForceMode();
|
||||
ConfigBaseVariable.clearAllValue();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
|
@ -11,8 +11,11 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -25,12 +28,22 @@ public class TestRawQuery {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void removeDataBase() throws IOException {
|
||||
ConfigureDb.clear();
|
||||
LOGGER.info("Remove the test db");
|
||||
DBEntry.closeAllForceMode();
|
||||
ConfigBaseVariable.clearAllValue();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@ -70,13 +83,13 @@ public class TestRawQuery {
|
||||
test.floatData = 7.0F;
|
||||
DataAccess.insert(test);
|
||||
{
|
||||
final String query = """
|
||||
String query = """
|
||||
SELECT *
|
||||
FROM TypesTable
|
||||
WHERE `intData` = ?
|
||||
ORDER BY id DESC
|
||||
""";
|
||||
final List<Object> parameters = List.of(Integer.valueOf(99));
|
||||
List<Object> parameters = List.of(Integer.valueOf(99));
|
||||
// Try to retrieve all the data:
|
||||
final List<TypesTable> retrieve = DataAccess.query(TypesTable.class, query, parameters);
|
||||
|
||||
@ -89,13 +102,13 @@ public class TestRawQuery {
|
||||
}
|
||||
{
|
||||
|
||||
final String query = """
|
||||
String query = """
|
||||
SELECT DISTINCT intData
|
||||
FROM TypesTable
|
||||
WHERE `intData` = ?
|
||||
ORDER BY id DESC
|
||||
""";
|
||||
final List<Object> parameters = List.of(Integer.valueOf(99));
|
||||
List<Object> parameters = List.of(Integer.valueOf(99));
|
||||
// Try to retrieve all the data:
|
||||
final List<TypesTable> retrieve = DataAccess.query(TypesTable.class, query, parameters);
|
||||
|
||||
|
@ -14,9 +14,12 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -33,15 +36,26 @@ public class TestSimpleTable {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Clear the static test:
|
||||
idOfTheObject = null;
|
||||
startAction = null;
|
||||
ConfigureDb.configure();
|
||||
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void removeDataBase() throws IOException {
|
||||
ConfigureDb.clear();
|
||||
LOGGER.info("Remove the test db");
|
||||
DBEntry.closeAllForceMode();
|
||||
ConfigBaseVariable.clearAllValue();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
|
@ -14,9 +14,11 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -34,16 +36,26 @@ public class TestSimpleTableSoftDelete {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Clear the static test:
|
||||
idOfTheObject = null;
|
||||
startAction = null;
|
||||
|
||||
ConfigureDb.configure();
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void removeDataBase() throws IOException {
|
||||
ConfigureDb.clear();
|
||||
LOGGER.info("Remove the test db");
|
||||
DBEntry.closeAllForceMode();
|
||||
ConfigBaseVariable.clearAllValue();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
|
@ -11,8 +11,11 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -26,12 +29,22 @@ public class TestTypeEnum1 {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void removeDataBase() throws IOException {
|
||||
ConfigureDb.clear();
|
||||
LOGGER.info("Remove the test db");
|
||||
DBEntry.closeAllForceMode();
|
||||
ConfigBaseVariable.clearAllValue();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
|
@ -11,8 +11,11 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -26,12 +29,22 @@ public class TestTypeEnum2 {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void removeDataBase() throws IOException {
|
||||
ConfigureDb.clear();
|
||||
LOGGER.info("Remove the test db");
|
||||
DBEntry.closeAllForceMode();
|
||||
ConfigBaseVariable.clearAllValue();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
|
@ -16,8 +16,11 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -30,12 +33,22 @@ public class TestTypes {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigureDb.configure();
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void removeDataBase() throws IOException {
|
||||
ConfigureDb.clear();
|
||||
LOGGER.info("Remove the test db");
|
||||
DBEntry.closeAllForceMode();
|
||||
ConfigBaseVariable.clearAllValue();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
|
@ -1,15 +1,8 @@
|
||||
package test.kar.archidata.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.model.GenericData;
|
||||
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
|
||||
public class TypeManyToManyRemote extends GenericData {
|
||||
@ManyToMany(fetch = FetchType.LAZY, targetEntity = TypeManyToManyRoot.class, mappedBy = "remote")
|
||||
public List<Long> remoteToParent;
|
||||
public String data;
|
||||
|
||||
public String data;
|
||||
}
|
@ -1 +1 @@
|
||||
0.19.0
|
||||
0.11.0
|
||||
|
Loading…
Reference in New Issue
Block a user