Compare commits
No commits in common. "main" and "v0.25.4" have entirely different histories.
46
.classpath
46
.classpath
@ -1,10 +1,30 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
|
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="test/src">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
<classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="test/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
@ -15,31 +35,5 @@
|
|||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/resources">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
<attribute name="optional" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/testResources">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
<attribute name="test" value="true"/>
|
|
||||||
<attribute name="optional" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="src" output="target/classes" path="src/main">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="optional" value="true"/>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="src" output="target/test-classes" path="src/test">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="optional" value="true"/>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
<attribute name="test" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
4
.github/workflows/maven.yml
vendored
4
.github/workflows/maven.yml
vendored
@ -19,7 +19,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Set up JDK 21
|
- name: Set up JDK 17
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
@ -32,4 +32,4 @@ jobs:
|
|||||||
|
|
||||||
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
|
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
|
||||||
- name: Update dependency graph
|
- name: Update dependency graph
|
||||||
uses: advanced-security/maven-dependency-submission-action@aeab9f885293af501bae8bdfe88c589528ea5e25
|
uses: advanced-security/maven-dependency-submission-action@4f64ddab9d742a4806eeb588d238e4c311a8397d
|
||||||
|
@ -28,4 +28,4 @@ def getEnvName(branchName) {
|
|||||||
return "dev";
|
return "dev";
|
||||||
}
|
}
|
||||||
return "other";
|
return "other";
|
||||||
}
|
}
|
132
pom.xml
132
pom.xml
@ -1,33 +1,25 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.atria-soft</groupId>
|
<groupId>kangaroo-and-rabbit</groupId>
|
||||||
<artifactId>archidata</artifactId>
|
<artifactId>archidata</artifactId>
|
||||||
<version>0.29.0</version>
|
<version>0.25.4</version>
|
||||||
<description>Wrapper to manage a simple interface for REST project to bind MySQL, SQLite or mongoDB.</description>
|
<repositories>
|
||||||
<url>https://github.com/kangaroo-and-rabbit/archidata</url>
|
<repository>
|
||||||
<licenses>
|
<id>gitea</id>
|
||||||
<license>
|
<url>https://gitea.atria-soft.org/api/packages/kangaroo-and-rabbit/maven</url>
|
||||||
<name>Mozilla Public License 2.0</name>
|
</repository>
|
||||||
<url>https://opensource.org/licenses/MPL-2.0</url>
|
</repositories>
|
||||||
<distribution>repo</distribution>
|
<distributionManagement>
|
||||||
</license>
|
<repository>
|
||||||
</licenses>
|
<id>gitea</id>
|
||||||
<developers>
|
<url>https://gitea.atria-soft.org/api/packages/kangaroo-and-rabbit/maven</url>
|
||||||
<developer>
|
</repository>
|
||||||
<id>dev1</id>
|
<snapshotRepository>
|
||||||
<name>Edouard DUPIN</name>
|
<id>gitea</id>
|
||||||
<email>edouard.dupin@proton.me</email>
|
<url>https://gitea.atria-soft.org/api/packages/kangaroo-and-rabbit/maven</url>
|
||||||
<roles>
|
</snapshotRepository>
|
||||||
<role>Lead Developer</role>
|
</distributionManagement>
|
||||||
</roles>
|
|
||||||
</developer>
|
|
||||||
</developers>
|
|
||||||
<scm>
|
|
||||||
<url>https://github.com/kangaroo-and-rabbit/archidata</url>
|
|
||||||
<connection>scm:git:git://github.com/kangaroo-and-rabbit/archidata.git</connection>
|
|
||||||
<developerConnection>scm:git:ssh:github.com/kangaroo-and-rabbit/archidata.git</developerConnection>
|
|
||||||
</scm>
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -97,6 +89,16 @@
|
|||||||
<groupId>org.glassfish.jersey.ext</groupId>
|
<groupId>org.glassfish.jersey.ext</groupId>
|
||||||
<artifactId>jersey-bean-validation</artifactId>
|
<artifactId>jersey-bean-validation</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.xml.bind</groupId>
|
||||||
|
<artifactId>jaxb-api</artifactId>
|
||||||
|
<version>2.4.0-b180830.0359</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sun.xml.bind</groupId>
|
||||||
|
<artifactId>jaxb-impl</artifactId>
|
||||||
|
<version>4.0.5</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.jaxb</groupId>
|
<groupId>org.glassfish.jaxb</groupId>
|
||||||
<artifactId>jaxb-runtime</artifactId>
|
<artifactId>jaxb-runtime</artifactId>
|
||||||
@ -107,6 +109,17 @@
|
|||||||
<artifactId>jakarta.ws.rs-api</artifactId>
|
<artifactId>jakarta.ws.rs-api</artifactId>
|
||||||
<version>4.0.0</version>
|
<version>4.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sun.istack</groupId>
|
||||||
|
<artifactId>istack-commons-runtime</artifactId>
|
||||||
|
<version>4.2.0</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-->
|
<!-- Serialize and un-serialize request in JSON-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.jersey.media</groupId>
|
<groupId>org.glassfish.jersey.media</groupId>
|
||||||
@ -149,7 +162,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.nimbusds</groupId>
|
<groupId>com.nimbusds</groupId>
|
||||||
<artifactId>nimbus-jose-jwt</artifactId>
|
<artifactId>nimbus-jose-jwt</artifactId>
|
||||||
<version>10.2</version>
|
<version>10.0.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jakarta.persistence</groupId>
|
<groupId>jakarta.persistence</groupId>
|
||||||
@ -173,15 +186,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.morphia.morphia</groupId>
|
<groupId>dev.morphia.morphia</groupId>
|
||||||
<artifactId>morphia-core</artifactId>
|
<artifactId>morphia-core</artifactId>
|
||||||
<version>2.4.16</version>
|
<version>2.4.15</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- MongoDB Java Driver -->
|
<!-- MongoDB Java Driver -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mongodb</groupId>
|
<groupId>org.mongodb</groupId>
|
||||||
<artifactId>mongodb-driver-sync</artifactId>
|
<artifactId>mongodb-driver-sync</artifactId>
|
||||||
<!--<version>5.3.1</version>-->
|
<version>5.4.0-alpha0</version>
|
||||||
<!--Morphia 2.4.x does not support version upper than 4.x-->
|
|
||||||
<version>4.11.5</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Bean Validation (JSR 303 / 380) -->
|
<!-- Bean Validation (JSR 303 / 380) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -189,6 +200,11 @@
|
|||||||
<artifactId>hibernate-validator</artifactId>
|
<artifactId>hibernate-validator</artifactId>
|
||||||
<version>9.0.0.CR1</version>
|
<version>9.0.0.CR1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.validation</groupId>
|
||||||
|
<artifactId>validation-api</artifactId>
|
||||||
|
<version>2.0.1.Final</version>
|
||||||
|
</dependency>
|
||||||
<!--
|
<!--
|
||||||
************************************************************
|
************************************************************
|
||||||
** TEST dependency **
|
** TEST dependency **
|
||||||
@ -209,7 +225,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.revelc.code.formatter</groupId>
|
<groupId>net.revelc.code.formatter</groupId>
|
||||||
<artifactId>formatter-maven-plugin</artifactId>
|
<artifactId>formatter-maven-plugin</artifactId>
|
||||||
<version>2.26.0</version>
|
<version>2.25.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
@ -218,16 +234,16 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src/main</sourceDirectory>
|
<sourceDirectory>src</sourceDirectory>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>${basedir}/src/resources</directory>
|
<directory>${basedir}/src/resources</directory>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<testSourceDirectory>src/test</testSourceDirectory>
|
<testSourceDirectory>test/src</testSourceDirectory>
|
||||||
<testResources>
|
<testResources>
|
||||||
<testResource>
|
<testResource>
|
||||||
<directory>${basedir}/src/testResources</directory>
|
<directory>${basedir}/test/resources</directory>
|
||||||
</testResource>
|
</testResource>
|
||||||
</testResources>
|
</testResources>
|
||||||
<plugins>
|
<plugins>
|
||||||
@ -249,7 +265,7 @@
|
|||||||
<execution>
|
<execution>
|
||||||
<id>attach-sources</id>
|
<id>attach-sources</id>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>jar-no-fork</goal>
|
<goal>jar</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
@ -272,7 +288,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>3.5.3</version>
|
<version>3.5.2</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
@ -292,14 +308,10 @@
|
|||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>3.3.0</version>
|
||||||
<executions>
|
<configuration>
|
||||||
<execution>
|
<show>private</show>
|
||||||
<id>attach-javadocs</id>
|
<nohelp>true</nohelp>
|
||||||
<goals>
|
</configuration>
|
||||||
<goal>jar</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- Check the style of the code -->
|
<!-- Check the style of the code -->
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -317,7 +329,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>net.revelc.code.formatter</groupId>
|
<groupId>net.revelc.code.formatter</groupId>
|
||||||
<artifactId>formatter-maven-plugin</artifactId>
|
<artifactId>formatter-maven-plugin</artifactId>
|
||||||
<version>2.26.0</version>
|
<version>2.24.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<encoding>UTF-8</encoding>
|
<encoding>UTF-8</encoding>
|
||||||
<lineEnding>LF</lineEnding>
|
<lineEnding>LF</lineEnding>
|
||||||
@ -358,29 +370,19 @@
|
|||||||
-->
|
-->
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<!-- Generate Java-docs As Part Of Project Reports -->
|
||||||
|
<reporting>
|
||||||
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-gpg-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.2.7</version>
|
<version>3.3.0</version>
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>sign-artifacts</id>
|
|
||||||
<phase>verify</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>sign</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.sonatype.central</groupId>
|
|
||||||
<artifactId>central-publishing-maven-plugin</artifactId>
|
|
||||||
<version>0.7.0</version>
|
|
||||||
<extensions>true</extensions>
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<publishingServerId>central</publishingServerId>
|
<show>public</show>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</reporting>
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,311 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<groupId>kangaroo-and-rabbit</groupId>
|
|
||||||
<artifactId>archidata</artifactId>
|
|
||||||
<version>0.6.1</version>
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.version>3.1</maven.compiler.version>
|
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
|
||||||
<maven.dependency.version>3.1.1</maven.dependency.version>
|
|
||||||
<jersey.version>3.1.5</jersey.version>
|
|
||||||
<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>
|
|
||||||
<distributionManagement>
|
|
||||||
<repository>
|
|
||||||
<id>gitea</id>
|
|
||||||
<url>https://gitea.atria-soft.org/api/packages/kangaroo-and-rabbit/maven</url>
|
|
||||||
</repository>
|
|
||||||
<snapshotRepository>
|
|
||||||
<id>gitea</id>
|
|
||||||
<url>https://gitea.atria-soft.org/api/packages/kangaroo-and-rabbit/maven</url>
|
|
||||||
</snapshotRepository>
|
|
||||||
</distributionManagement>
|
|
||||||
<dependencyManagement>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.glassfish.jersey</groupId>
|
|
||||||
<artifactId>jersey-bom</artifactId>
|
|
||||||
<version>${jersey.version}</version>
|
|
||||||
<type>pom</type>
|
|
||||||
<scope>import</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</dependencyManagement>
|
|
||||||
<dependencies>
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>2.0.9</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-simple</artifactId>
|
|
||||||
<version>2.0.9</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-multipart -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.glassfish.jersey.media</groupId>
|
|
||||||
<artifactId>jersey-media-multipart</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.glassfish.jersey.core</groupId>
|
|
||||||
<artifactId>jersey-client</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.glassfish.jersey.inject</groupId>
|
|
||||||
<artifactId>jersey-hk2</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.glassfish.jersey.containers</groupId>
|
|
||||||
<artifactId>jersey-container-grizzly2-http</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.xml.bind</groupId>
|
|
||||||
<artifactId>jaxb-api</artifactId>
|
|
||||||
<version>${jaxb.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.glassfish.jaxb</groupId>
|
|
||||||
<artifactId>jaxb-runtime</artifactId>
|
|
||||||
<version>4.0.4</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>jakarta.ws.rs</groupId>
|
|
||||||
<artifactId>jakarta.ws.rs-api</artifactId>
|
|
||||||
<version>3.1.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.sun.xml.bind</groupId>
|
|
||||||
<artifactId>jaxb-impl</artifactId>
|
|
||||||
<version>${jaxb.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.sun.istack</groupId>
|
|
||||||
<artifactId>istack-commons-runtime</artifactId>
|
|
||||||
<version>${istack.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
|
|
||||||
<artifactId>jersey-test-framework-provider-grizzly2</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.glassfish.jersey.media</groupId>
|
|
||||||
<artifactId>jersey-media-json-jackson</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
|
||||||
<artifactId>jackson-databind</artifactId>
|
|
||||||
<version>2.16.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
|
||||||
<artifactId>jackson-dataformat-csv</artifactId>
|
|
||||||
<version>2.16.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>jakarta.servlet</groupId>
|
|
||||||
<artifactId>jakarta.servlet-api</artifactId>
|
|
||||||
<version>6.1.0-M1</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<!-- Interface for My-sql & sqlite DB -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-j</artifactId>
|
|
||||||
<version>8.2.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.xerial</groupId>
|
|
||||||
<artifactId>sqlite-jdbc</artifactId>
|
|
||||||
<version>3.40.0.0</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- Interface for JWT token -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.nimbusds</groupId>
|
|
||||||
<artifactId>nimbus-jose-jwt</artifactId>
|
|
||||||
<version>9.37.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>jakarta.persistence</groupId>
|
|
||||||
<artifactId>jakarta.persistence-api</artifactId>
|
|
||||||
<version>3.2.0-M1</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- Swagger dependencies -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.swagger.core.v3</groupId>
|
|
||||||
<artifactId>swagger-jaxrs2-jakarta</artifactId>
|
|
||||||
<version>2.1.10</version>
|
|
||||||
</dependency>
|
|
||||||
<!--
|
|
||||||
************************************************************
|
|
||||||
** TEST dependency **
|
|
||||||
************************************************************
|
|
||||||
-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
|
||||||
<version>5.10.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
|
||||||
<version>5.10.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.revelc.code.formatter</groupId>
|
|
||||||
<artifactId>formatter-maven-plugin</artifactId>
|
|
||||||
<version>2.23.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
|
||||||
<version>3.3.1</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<sourceDirectory>src</sourceDirectory>
|
|
||||||
<testSourceDirectory>test/src</testSourceDirectory>
|
|
||||||
<testResources>
|
|
||||||
<testResource>
|
|
||||||
<directory>${basedir}/test/resources</directory>
|
|
||||||
</testResource>
|
|
||||||
</testResources>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>${maven.compiler.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<source>${maven.compiler.source}</source>
|
|
||||||
<target>${maven.compiler.target}</target>
|
|
||||||
<!--<encoding>${project.build.sourceEncoding}</encoding>-->
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<!-- Create the source bundle -->
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
|
||||||
<version>3.3.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>attach-sources</id>
|
|
||||||
<goals>
|
|
||||||
<goal>jar</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<!-- For dependabot plugin -->
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.servicemix.tooling</groupId>
|
|
||||||
<artifactId>depends-maven-plugin</artifactId>
|
|
||||||
<version>1.5.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>generate-depends-file</id>
|
|
||||||
<goals>
|
|
||||||
<goal>generate-depends-file</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<!-- junit results -->
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<version>3.0.0-M5</version>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<mainClass>fully.qualified.MainClass</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
<descriptorRefs>
|
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
|
||||||
</descriptorRefs>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<!-- Java-doc generation for stand-alone site -->
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
|
||||||
<version>3.2.0</version>
|
|
||||||
<configuration>
|
|
||||||
<show>private</show>
|
|
||||||
<nohelp>true</nohelp>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<!-- Check the style of the code -->
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
|
||||||
<version>3.3.1</version>
|
|
||||||
<configuration>
|
|
||||||
<configLocation>CheckStyle.xml</configLocation>
|
|
||||||
<consoleOutput>true</consoleOutput>
|
|
||||||
<failOnViolation>true</failOnViolation>
|
|
||||||
<failsOnError>true</failsOnError>
|
|
||||||
<includeTestSourceDirectory>true</includeTestSourceDirectory>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>net.revelc.code.formatter</groupId>
|
|
||||||
<artifactId>formatter-maven-plugin</artifactId>
|
|
||||||
<version>2.23.0</version>
|
|
||||||
<configuration>
|
|
||||||
<encoding>UTF-8</encoding>
|
|
||||||
<lineEnding>LF</lineEnding>
|
|
||||||
<configFile>Formatter.xml</configFile>
|
|
||||||
<directories>
|
|
||||||
<directory>src/</directory>
|
|
||||||
<directory>test/src</directory>
|
|
||||||
</directories>
|
|
||||||
<includes>
|
|
||||||
<include>**/*.java</include>
|
|
||||||
</includes>
|
|
||||||
<excludes>
|
|
||||||
<exclude>module-info.java</exclude>
|
|
||||||
</excludes>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>validate</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
<!-- Generate Java-docs As Part Of Project Reports -->
|
|
||||||
<reporting>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
|
||||||
<version>3.2.0</version>
|
|
||||||
<configuration>
|
|
||||||
<show>public</show>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</reporting>
|
|
||||||
</project>
|
|
@ -7,18 +7,18 @@ import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
|
|||||||
import org.glassfish.jersey.jackson.JacksonFeature;
|
import org.glassfish.jersey.jackson.JacksonFeature;
|
||||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||||
import org.glassfish.jersey.server.ResourceConfig;
|
import org.glassfish.jersey.server.ResourceConfig;
|
||||||
import org.atriasoft.archidata.GlobalConfiguration;
|
import org.kar.archidata.GlobalConfiguration;
|
||||||
import org.atriasoft.archidata.UpdateJwtPublicKey;
|
import org.kar.archidata.UpdateJwtPublicKey;
|
||||||
import org.atriasoft.archidata.api.DataResource;
|
import org.kar.archidata.api.DataResource;
|
||||||
import org.atriasoft.archidata.catcher.ExceptionCatcher;
|
import org.kar.archidata.catcher.ExceptionCatcher;
|
||||||
import org.atriasoft.archidata.catcher.FailExceptionCatcher;
|
import org.kar.archidata.catcher.FailExceptionCatcher;
|
||||||
import org.atriasoft.archidata.catcher.InputExceptionCatcher;
|
import org.kar.archidata.catcher.InputExceptionCatcher;
|
||||||
import org.atriasoft.archidata.catcher.SystemExceptionCatcher;
|
import org.kar.archidata.catcher.SystemExceptionCatcher;
|
||||||
import org.atriasoft.archidata.db.DBConfig;
|
import org.kar.archidata.db.DBConfig;
|
||||||
import org.atriasoft.archidata.filter.CORSFilter;
|
import org.kar.archidata.filter.CORSFilter;
|
||||||
import org.atriasoft.archidata.filter.OptionFilter;
|
import org.kar.archidata.filter.OptionFilter;
|
||||||
import org.atriasoft.archidata.migration.MigrationEngine;
|
import org.kar.archidata.migration.MigrationEngine;
|
||||||
import org.atriasoft.archidata.tools.ConfigBaseVariable;
|
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||||
import sample.archidata.basic.api.Front;
|
import sample.archidata.basic.api.Front;
|
||||||
import sample.archidata.basic.api.HealthCheck;
|
import sample.archidata.basic.api.HealthCheck;
|
||||||
import sample.archidata.basic.api.MediaResource;
|
import sample.archidata.basic.api.MediaResource;
|
||||||
|
@ -3,9 +3,9 @@ package sample.archidata.basic;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.atriasoft.archidata.api.DataResource;
|
import org.kar.archidata.api.DataResource;
|
||||||
import org.atriasoft.archidata.dataAccess.DataFactoryTsApi;
|
import org.kar.archidata.dataAccess.DataFactoryTsApi;
|
||||||
import org.atriasoft.archidata.tools.ConfigBaseVariable;
|
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -8,15 +8,15 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||||
import org.atriasoft.archidata.annotation.AsyncType;
|
import org.kar.archidata.annotation.AsyncType;
|
||||||
import org.atriasoft.archidata.annotation.TypeScriptProgress;
|
import org.kar.archidata.annotation.TypeScriptProgress;
|
||||||
import org.atriasoft.archidata.api.DataResource;
|
import org.kar.archidata.api.DataResource;
|
||||||
import org.atriasoft.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
import org.atriasoft.archidata.dataAccess.addOn.AddOnDataJson;
|
import org.kar.archidata.dataAccess.addOn.AddOnDataJson;
|
||||||
import org.atriasoft.archidata.exception.FailException;
|
import org.kar.archidata.exception.FailException;
|
||||||
import org.atriasoft.archidata.exception.InputException;
|
import org.kar.archidata.exception.InputException;
|
||||||
import org.atriasoft.archidata.model.Data;
|
import org.kar.archidata.model.Data;
|
||||||
import org.atriasoft.archidata.tools.DataTools;
|
import org.kar.archidata.tools.DataTools;
|
||||||
import sample.archidata.basic.model.MyModel;
|
import sample.archidata.basic.model.MyModel;
|
||||||
import sample.archidata.basic.model.Season;
|
import sample.archidata.basic.model.Season;
|
||||||
import sample.archidata.basic.model.Series;
|
import sample.archidata.basic.model.Series;
|
||||||
|
@ -2,7 +2,7 @@ package sample.archidata.basic.migration;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.atriasoft.archidata.migration.MigrationSqlStep;
|
import org.kar.archidata.migration.MigrationSqlStep;
|
||||||
import sample.archidata.basic.model.MyModel;
|
import sample.archidata.basic.model.MyModel;
|
||||||
|
|
||||||
public class Initialization extends MigrationSqlStep {
|
public class Initialization extends MigrationSqlStep {
|
||||||
|
@ -3,9 +3,9 @@ package sample.archidata.basic.model;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.atriasoft.archidata.annotation.DataJson;
|
import org.kar.archidata.annotation.DataJson;
|
||||||
import org.atriasoft.archidata.model.Data;
|
import org.kar.archidata.model.Data;
|
||||||
import org.atriasoft.archidata.model.GenericDataSoftDelete;
|
import org.kar.archidata.model.GenericDataSoftDelete;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
package org.atriasoft.archidata.annotation;
|
|
||||||
|
|
||||||
import static java.lang.annotation.ElementType.FIELD;
|
|
||||||
import static java.lang.annotation.ElementType.METHOD;
|
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* In NoSql entity the relation is stored in the 2 part of the entity,
|
|
||||||
* then it is needed to define the field that store the relation data value in the remote elements.
|
|
||||||
*/
|
|
||||||
@Retention(RUNTIME)
|
|
||||||
@Target({ FIELD, METHOD })
|
|
||||||
public @interface ManyToManyLocal {
|
|
||||||
/**
|
|
||||||
* The entity class that is the target of the
|
|
||||||
* association.
|
|
||||||
*/
|
|
||||||
Class<?> targetEntity();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The field that owns the revert value. empty if the relationship is unidirectional.
|
|
||||||
*/
|
|
||||||
String remoteField() default "";
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
package org.atriasoft.archidata.annotation.apiGenerator;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Annotation to explicitly define the nullability of a parameter in an API.
|
|
||||||
*
|
|
||||||
* This annotation allows marking a parameter as required (non-null) or optional (nullable),
|
|
||||||
* overriding any other nullability considerations. It is useful in API generation frameworks
|
|
||||||
* to ensure precise validation and documentation of method parameters.
|
|
||||||
*
|
|
||||||
* <p>Usage:
|
|
||||||
* - Target: This annotation can be applied to field.
|
|
||||||
* - Retention: The annotation is retained at runtime, allowing it to be
|
|
||||||
* processed by frameworks or libraries that handle code generation logic.
|
|
||||||
*
|
|
||||||
* <p>Behavior:
|
|
||||||
* - When applied to a parameter, it explicitly marks it as optional or required in the API.
|
|
||||||
* This annotation overrides all other considerations regarding nullability.
|
|
||||||
*
|
|
||||||
* <p>Example:
|
|
||||||
* <pre>{@code
|
|
||||||
* public class User {
|
|
||||||
* @ReadOnlyField
|
|
||||||
* @ApiNotNull
|
|
||||||
* public String username;
|
|
||||||
* public String email;
|
|
||||||
* }
|
|
||||||
* }</pre>
|
|
||||||
*
|
|
||||||
* In this example, the `username` field in the `User` class is explicitly marked as non-null in the generated API.
|
|
||||||
*/
|
|
||||||
@Target({ ElementType.FIELD })
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface ApiNotNull {
|
|
||||||
/**
|
|
||||||
* (Optional) Specifies whether the API element can be null.
|
|
||||||
* If set to `true`, the element is required (non-null).
|
|
||||||
* If set to `false`, the element is optional (nullable).
|
|
||||||
*/
|
|
||||||
boolean value() default true;
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
package org.atriasoft.archidata.annotation.checker;
|
|
||||||
|
|
||||||
import org.atriasoft.archidata.dataAccess.DataAccess;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import jakarta.validation.ConstraintValidator;
|
|
||||||
import jakarta.validation.ConstraintValidatorContext;
|
|
||||||
|
|
||||||
public class CheckForeignKeyValidator implements ConstraintValidator<CheckForeignKey, Object> {
|
|
||||||
Class<?> target = null;
|
|
||||||
private final static Logger LOGGER = LoggerFactory.getLogger(CheckForeignKeyValidator.class);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize(final CheckForeignKey annotation) {
|
|
||||||
this.target = annotation.target();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValid(final Object value, final ConstraintValidatorContext context) {
|
|
||||||
if (value == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
final long count = DataAccess.count(this.target, value);
|
|
||||||
if (count != 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (final Exception e) {
|
|
||||||
LOGGER.error("Fail to access to the DB");
|
|
||||||
context.buildConstraintViolationWithTemplate("fail to access on the DB").addConstraintViolation();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
package org.atriasoft.archidata.catcher;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.glassfish.jersey.server.ParamException.QueryParamException;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import jakarta.ws.rs.core.MediaType;
|
|
||||||
import jakarta.ws.rs.core.Response;
|
|
||||||
import jakarta.ws.rs.ext.ExceptionMapper;
|
|
||||||
|
|
||||||
public class QueryParamExceptionCatcher implements ExceptionMapper<QueryParamException> {
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(QueryParamExceptionCatcher.class);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Response toResponse(final QueryParamException exception) {
|
|
||||||
LOGGER.trace("Catch IllegalArgumentException: {}", exception.getLocalizedMessage());
|
|
||||||
final RestErrorResponse ret = build(exception);
|
|
||||||
LOGGER.error("Error OID={}", ret.oid);
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(ret).type(MediaType.APPLICATION_JSON).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private RestErrorResponse build(final QueryParamException exception) {
|
|
||||||
final List<RestInputError> inputError = new ArrayList<>();
|
|
||||||
inputError.add(new RestInputError("query", exception.getParameterName(), exception.getCause().getMessage()));
|
|
||||||
final String errorType = "Error on query input='" + exception.getParameterName() + "'";
|
|
||||||
return new RestErrorResponse(Response.Status.BAD_REQUEST, Instant.now().toString(), errorType,
|
|
||||||
"Input parsing fail", inputError);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
package org.atriasoft.archidata.converter.Jakarta;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.atriasoft.archidata.tools.DateTools;
|
|
||||||
|
|
||||||
import jakarta.annotation.Priority;
|
|
||||||
import jakarta.ws.rs.ext.ParamConverter;
|
|
||||||
import jakarta.ws.rs.ext.ParamConverterProvider;
|
|
||||||
import jakarta.ws.rs.ext.Provider;
|
|
||||||
|
|
||||||
@Provider
|
|
||||||
@Priority(1)
|
|
||||||
public class DateParamConverterProvider implements ParamConverterProvider {
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
|
||||||
public <T> ParamConverter<T> getConverter(
|
|
||||||
final Class<T> rawType,
|
|
||||||
final Type genericType,
|
|
||||||
final Annotation[] annotations) {
|
|
||||||
if (rawType != Date.class) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return (ParamConverter<T>) new DateParamConverter();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DateParamConverter implements ParamConverter<Date> {
|
|
||||||
@Override
|
|
||||||
public Date fromString(final String value) {
|
|
||||||
if (value == null || value.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return DateTools.parseDate(value);
|
|
||||||
} catch (final IOException e) {
|
|
||||||
throw new IllegalArgumentException("Invalid date format. Please use ISO8601", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString(final Date value) {
|
|
||||||
if (value == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return DateTools.serializeMilliWithUTCTimeZone(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
package org.atriasoft.archidata.converter.Jakarta;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
|
|
||||||
import org.atriasoft.archidata.tools.DateTools;
|
|
||||||
|
|
||||||
import jakarta.ws.rs.ext.ParamConverter;
|
|
||||||
import jakarta.ws.rs.ext.ParamConverterProvider;
|
|
||||||
import jakarta.ws.rs.ext.Provider;
|
|
||||||
|
|
||||||
@Provider
|
|
||||||
public class OffsetDateTimeParamConverterProvider implements ParamConverterProvider {
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
|
||||||
public <T> ParamConverter<T> getConverter(
|
|
||||||
final Class<T> rawType,
|
|
||||||
final Type genericType,
|
|
||||||
final Annotation[] annotations) {
|
|
||||||
if (rawType != OffsetDateTime.class) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return (ParamConverter<T>) new OffsetDateTimeParamConverter();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class OffsetDateTimeParamConverter implements ParamConverter<OffsetDateTime> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OffsetDateTime fromString(final String value) {
|
|
||||||
if (value == null || value.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return DateTools.parseOffsetDateTime(value);
|
|
||||||
} catch (final IOException e) {
|
|
||||||
throw new IllegalArgumentException("Invalid date format. Please use ISO8601", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString(final OffsetDateTime value) {
|
|
||||||
if (value == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return DateTools.serializeMilliWithUTCTimeZone(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package org.atriasoft.archidata.converter.jackson;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.atriasoft.archidata.tools.DateTools;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
|
||||||
|
|
||||||
public class DateDeserializer extends JsonDeserializer<Date> {
|
|
||||||
@Override
|
|
||||||
public Date deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
|
|
||||||
final String value = p.getText();
|
|
||||||
final Date ret = DateTools.parseDate(value);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package org.atriasoft.archidata.converter.jackson;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.atriasoft.archidata.tools.DateTools;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
|
||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
|
||||||
|
|
||||||
public class DateSerializer extends JsonSerializer<Date> {
|
|
||||||
@Override
|
|
||||||
public void serialize(final Date value, final JsonGenerator gen, final SerializerProvider serializers)
|
|
||||||
throws IOException {
|
|
||||||
gen.writeString(DateTools.serializeMilliWithUTCTimeZone(value));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package org.atriasoft.archidata.converter.jackson;
|
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.bson.types.ObjectId;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
|
||||||
|
|
||||||
public class JacksonModules {
|
|
||||||
public static SimpleModule getAllModules() {
|
|
||||||
final SimpleModule module = new SimpleModule();
|
|
||||||
module.addSerializer(ObjectId.class, new ObjectIdSerializer());
|
|
||||||
module.addDeserializer(ObjectId.class, new ObjectIdDeserializer());
|
|
||||||
module.addSerializer(Date.class, new DateSerializer());
|
|
||||||
module.addDeserializer(Date.class, new DateDeserializer());
|
|
||||||
module.addSerializer(OffsetDateTime.class, new OffsetDateTimeSerializer());
|
|
||||||
module.addDeserializer(OffsetDateTime.class, new OffsetDateTimeDeserializer());
|
|
||||||
return module;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package org.atriasoft.archidata.converter.jackson;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
|
|
||||||
import org.atriasoft.archidata.tools.DateTools;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
|
||||||
|
|
||||||
public class OffsetDateTimeDeserializer extends JsonDeserializer<OffsetDateTime> {
|
|
||||||
@Override
|
|
||||||
public OffsetDateTime deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
|
|
||||||
final String value = p.getText();
|
|
||||||
final OffsetDateTime ret = DateTools.parseOffsetDateTime(value);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package org.atriasoft.archidata.converter.jackson;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
|
|
||||||
import org.atriasoft.archidata.tools.DateTools;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
|
||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
|
||||||
|
|
||||||
public class OffsetDateTimeSerializer extends JsonSerializer<OffsetDateTime> {
|
|
||||||
@Override
|
|
||||||
public void serialize(final OffsetDateTime value, final JsonGenerator gen, final SerializerProvider serializers)
|
|
||||||
throws IOException {
|
|
||||||
gen.writeString(DateTools.serializeMilliWithUTCTimeZone(value));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,166 +0,0 @@
|
|||||||
package org.atriasoft.archidata.dataAccess.addOnMongo;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.atriasoft.archidata.annotation.AnnotationTools;
|
|
||||||
import org.atriasoft.archidata.annotation.AnnotationTools.FieldName;
|
|
||||||
import org.atriasoft.archidata.dataAccess.DBAccessMorphia;
|
|
||||||
import org.atriasoft.archidata.dataAccess.LazyGetter;
|
|
||||||
import org.atriasoft.archidata.dataAccess.QueryCondition;
|
|
||||||
import org.atriasoft.archidata.dataAccess.QueryOptions;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.Condition;
|
|
||||||
import org.bson.Document;
|
|
||||||
import org.bson.types.ObjectId;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import jakarta.persistence.OneToMany;
|
|
||||||
|
|
||||||
public class AddOnOneToMany implements DataAccessAddOn {
|
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(AddOnOneToMany.class);
|
|
||||||
static final String SEPARATOR_LONG = "-";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<?> getAnnotationClass() {
|
|
||||||
return OneToMany.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCompatibleField(final Field field) {
|
|
||||||
final OneToMany decorators = field.getDeclaredAnnotation(OneToMany.class);
|
|
||||||
return decorators != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void insertData(
|
|
||||||
final DBAccessMorphia ioDb,
|
|
||||||
final Field field,
|
|
||||||
final Object rootObject,
|
|
||||||
final QueryOptions options,
|
|
||||||
final Document docSet,
|
|
||||||
final Document docUnSet) throws Exception {
|
|
||||||
throw new IllegalAccessException("Can not generate an inset of @OneToMany");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canInsert(final Field field) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isInsertAsync(final Field field) throws Exception {
|
|
||||||
// TODO: can be implemented later...
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canRetrieve(final Field field) {
|
|
||||||
if (field.getType() != List.class) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
|
||||||
.getActualTypeArguments()[0];
|
|
||||||
if (objectClass == Long.class || objectClass == UUID.class || objectClass == ObjectId.class) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
final OneToMany decorators = field.getDeclaredAnnotation(OneToMany.class);
|
|
||||||
if (decorators == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (decorators.targetEntity() == objectClass) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// in first implementation we did not keep the data in the 2 Objects, bun we will do it after to have a faster table interactions.
|
|
||||||
@Override
|
|
||||||
public void fillFromDoc(
|
|
||||||
final DBAccessMorphia ioDb,
|
|
||||||
final Document doc,
|
|
||||||
final Field field,
|
|
||||||
final Object data,
|
|
||||||
final QueryOptions options,
|
|
||||||
final List<LazyGetter> lazyCall) throws Exception {
|
|
||||||
if (field.getType() != List.class) {
|
|
||||||
LOGGER.error("Can not OneToMany with other than List Model: {}", field.getType().getCanonicalName());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final FieldName fieldName = AnnotationTools.getFieldName(field, options);
|
|
||||||
// in step 1 the fields are not stored in the local element
|
|
||||||
// if (!doc.containsKey(fieldName.inTable())) {
|
|
||||||
// field.set(data, null);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
|
||||||
.getActualTypeArguments()[0];
|
|
||||||
final OneToMany decorators = field.getDeclaredAnnotation(OneToMany.class);
|
|
||||||
if (decorators == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (objectClass == Long.class || objectClass == UUID.class || objectClass == ObjectId.class) {
|
|
||||||
if (true) {
|
|
||||||
// DEVELOPMENT step 1 we search all the element in the list:
|
|
||||||
// get the curentObject primary key
|
|
||||||
final Field primaryField = AnnotationTools.getPrimaryKeyField(data.getClass());
|
|
||||||
final String primaryKeyName = AnnotationTools.getFieldNameRaw(primaryField);
|
|
||||||
final Object primaryKey = doc.get(primaryKeyName, primaryField.getType());
|
|
||||||
// get the remotes objects
|
|
||||||
final List<?> returnValue = ioDb.getsWhere(decorators.targetEntity(),
|
|
||||||
new Condition(new QueryCondition(decorators.mappedBy(), "=", primaryKey)));
|
|
||||||
// extract the primary key of the remote objects
|
|
||||||
final Field remotePrimaryField = AnnotationTools.getPrimaryKeyField(decorators.targetEntity());
|
|
||||||
final String remotePrimaryKeyName = AnnotationTools.getFieldNameRaw(remotePrimaryField);
|
|
||||||
final List<Object> listOfRemoteKeys = new ArrayList<>();
|
|
||||||
for (final var item : returnValue) {
|
|
||||||
listOfRemoteKeys.add(remotePrimaryField.get(item));
|
|
||||||
}
|
|
||||||
// inject in the current data field
|
|
||||||
if (listOfRemoteKeys.size() != 0) {
|
|
||||||
field.set(data, listOfRemoteKeys);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// DEVELOPMENT In step 2 this will work well:
|
|
||||||
final Object value = doc.get(fieldName.inTable(), field.getType());
|
|
||||||
field.set(data, value);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (objectClass == decorators.targetEntity()) {
|
|
||||||
// Maybe in a second step we do not like this but this way is efficient too.
|
|
||||||
// get the curentObject primary key
|
|
||||||
final Field primaryField = AnnotationTools.getPrimaryKeyField(data.getClass());
|
|
||||||
final String primaryKeyName = AnnotationTools.getFieldNameRaw(primaryField);
|
|
||||||
final Object primaryKey = doc.get(primaryKeyName, primaryField.getType());
|
|
||||||
// get the remotes objects
|
|
||||||
final List<?> returnValue = ioDb.getsWhere(decorators.targetEntity(),
|
|
||||||
new Condition(new QueryCondition(decorators.mappedBy(), "=", primaryKey)));
|
|
||||||
// inject in the current data field
|
|
||||||
if (returnValue.size() != 0) {
|
|
||||||
field.set(data, returnValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO : refacto this table to manage a generic table with dynamic name to be serialize with the default system
|
|
||||||
@Override
|
|
||||||
public void createTables(
|
|
||||||
final String tableName,
|
|
||||||
final Field primaryField,
|
|
||||||
final Field field,
|
|
||||||
final StringBuilder mainTableBuilder,
|
|
||||||
final List<String> preActionList,
|
|
||||||
final List<String> postActionList,
|
|
||||||
final boolean createIfNotExist,
|
|
||||||
final boolean createDrop,
|
|
||||||
final int fieldId,
|
|
||||||
final QueryOptions options) throws Exception {
|
|
||||||
// This is a remote field ==> nothing to generate (it is stored in the remote object
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,464 +0,0 @@
|
|||||||
package org.atriasoft.archidata.dataAccess.addOnSQL;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Types;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.atriasoft.archidata.annotation.AnnotationTools;
|
|
||||||
import org.atriasoft.archidata.annotation.AnnotationTools.FieldName;
|
|
||||||
import org.atriasoft.archidata.annotation.ManyToManyLocal;
|
|
||||||
import org.atriasoft.archidata.dataAccess.CountInOut;
|
|
||||||
import org.atriasoft.archidata.dataAccess.DBAccess;
|
|
||||||
import org.atriasoft.archidata.dataAccess.DBAccessSQL;
|
|
||||||
import org.atriasoft.archidata.dataAccess.DataFactory;
|
|
||||||
import org.atriasoft.archidata.dataAccess.LazyGetter;
|
|
||||||
import org.atriasoft.archidata.dataAccess.QueryInList;
|
|
||||||
import org.atriasoft.archidata.dataAccess.QueryOptions;
|
|
||||||
import org.atriasoft.archidata.dataAccess.addOnSQL.model.TableCoversGeneric;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.Condition;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.OptionRenameColumn;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.OptionSpecifyType;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.OverrideTableName;
|
|
||||||
import org.atriasoft.archidata.exception.SystemException;
|
|
||||||
import org.atriasoft.archidata.tools.ContextGenericTools;
|
|
||||||
import org.bson.types.ObjectId;
|
|
||||||
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.ObjectMapper;
|
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
public class AddOnManyToManyLocal implements DataAccessAddOn {
|
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(AddOnManyToManyLocal.class);
|
|
||||||
static final String SEPARATOR_LONG = "-";
|
|
||||||
static final String SEPARATOR_UUID = "_";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<?> getAnnotationClass() {
|
|
||||||
return ManyToManyLocal.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCompatibleField(final Field field) {
|
|
||||||
if (field.getType() != List.class) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
|
||||||
.getActualTypeArguments()[0];
|
|
||||||
if (objectClass == Long.class || objectClass == UUID.class || objectClass == ObjectId.class) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
final ManyToManyLocal decorators = field.getDeclaredAnnotation(ManyToManyLocal.class);
|
|
||||||
if (decorators == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (decorators.targetEntity() == objectClass) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void insertData(
|
|
||||||
final DBAccessSQL ioDb,
|
|
||||||
final PreparedStatement ps,
|
|
||||||
final Field field,
|
|
||||||
final Object rootObject,
|
|
||||||
final CountInOut iii)
|
|
||||||
throws SQLException, IllegalArgumentException, IllegalAccessException, JsonProcessingException {
|
|
||||||
final Object data = field.get(rootObject);
|
|
||||||
if (data == null) {
|
|
||||||
ps.setNull(iii.value, Types.VARCHAR);
|
|
||||||
}
|
|
||||||
final ObjectMapper objectMapper = ContextGenericTools.createObjectMapper();
|
|
||||||
final String dataString = objectMapper.writeValueAsString(data);
|
|
||||||
ps.setString(iii.value, dataString);
|
|
||||||
iii.inc();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isUpdateAsync(final Field field) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void asyncUpdate(
|
|
||||||
final DBAccessSQL ioDb,
|
|
||||||
final Object previousData,
|
|
||||||
final String tableName,
|
|
||||||
final Object primaryKeyValue,
|
|
||||||
final Field field,
|
|
||||||
final Object insertedData,
|
|
||||||
final List<LazyGetter> actions,
|
|
||||||
final QueryOptions options) throws Exception {
|
|
||||||
final Object previousDataValue = field.get(previousData);
|
|
||||||
Collection<?> previousDataCollection = new ArrayList<>();
|
|
||||||
if (previousDataValue instanceof final Collection<?> tmpCollection) {
|
|
||||||
previousDataCollection = tmpCollection;
|
|
||||||
}
|
|
||||||
final Object insertedDataValue = insertedData;
|
|
||||||
Collection<?> insertedDataCollection = new ArrayList<>();
|
|
||||||
if (insertedDataValue instanceof final Collection<?> tmpCollection) {
|
|
||||||
insertedDataCollection = tmpCollection;
|
|
||||||
}
|
|
||||||
// add new Values
|
|
||||||
for (final Object value : insertedDataCollection) {
|
|
||||||
if (previousDataCollection.contains(value)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
actions.add(() -> {
|
|
||||||
addLinkRemote(ioDb, field, primaryKeyValue, value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// remove old values:
|
|
||||||
for (final Object value : previousDataCollection) {
|
|
||||||
if (insertedDataCollection.contains(value)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
actions.add(() -> {
|
|
||||||
removeLinkRemote(ioDb, field, primaryKeyValue, value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Some action must be done asynchronously for update or remove element
|
|
||||||
* @param field
|
|
||||||
* @return */
|
|
||||||
@Override
|
|
||||||
public boolean isInsertAsync(final Field field) throws Exception {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** When insert is mark async, this function permit to create or update the data
|
|
||||||
* @param tableName Name of the Table.
|
|
||||||
* @param localId Local ID of the current table
|
|
||||||
* @param field Field that is updated.
|
|
||||||
* @param data Data that might be inserted.
|
|
||||||
* @param actions Asynchronous action to do after main request. */
|
|
||||||
@Override
|
|
||||||
public void asyncInsert(
|
|
||||||
final DBAccessSQL ioDb,
|
|
||||||
final String tableName,
|
|
||||||
final Object primaryKeyValue,
|
|
||||||
final Field field,
|
|
||||||
final Object data,
|
|
||||||
final List<LazyGetter> actions,
|
|
||||||
final QueryOptions options) throws Exception {
|
|
||||||
final Object insertedData = data;
|
|
||||||
if (insertedData == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (insertedData instanceof final Collection<?> insertedDataCollection) {
|
|
||||||
for (final Object value : insertedDataCollection) {
|
|
||||||
actions.add(() -> {
|
|
||||||
addLinkRemote(ioDb, field, primaryKeyValue, value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPreviousDataNeeded(final Field field) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canInsert(final Field field) {
|
|
||||||
return isCompatibleField(field);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canRetrieve(final Field field) {
|
|
||||||
return isCompatibleField(field);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateQuery(
|
|
||||||
@NotNull final String tableName,
|
|
||||||
@NotNull final String primaryKey,
|
|
||||||
@NotNull final Field field,
|
|
||||||
@NotNull final StringBuilder querySelect,
|
|
||||||
@NotNull final StringBuilder query,
|
|
||||||
@NotNull final String name,
|
|
||||||
@NotNull final CountInOut count,
|
|
||||||
final QueryOptions options) throws Exception {
|
|
||||||
querySelect.append(" ");
|
|
||||||
querySelect.append(tableName);
|
|
||||||
querySelect.append(".");
|
|
||||||
querySelect.append(name);
|
|
||||||
count.inc();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fillFromQuery(
|
|
||||||
final DBAccessSQL ioDb,
|
|
||||||
final ResultSet rs,
|
|
||||||
final Field field,
|
|
||||||
final Object data,
|
|
||||||
final CountInOut count,
|
|
||||||
final QueryOptions options,
|
|
||||||
final List<LazyGetter> lazyCall) throws Exception {
|
|
||||||
if (field.getType() != List.class) {
|
|
||||||
throw new SystemException("@ManyToManyLocal must contain a List");
|
|
||||||
}
|
|
||||||
final String jsonData = rs.getString(count.value);
|
|
||||||
count.inc();
|
|
||||||
if (rs.wasNull()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final ObjectMapper objectMapper = ContextGenericTools.createObjectMapper();
|
|
||||||
final ParameterizedType listType = (ParameterizedType) field.getGenericType();
|
|
||||||
final Class<?> objectClass = (Class<?>) listType.getActualTypeArguments()[0];
|
|
||||||
if (objectClass == Long.class) {
|
|
||||||
final List<Long> dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<Long>>() {});
|
|
||||||
field.set(data, dataParsed);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (objectClass == String.class) {
|
|
||||||
final List<String> dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<String>>() {});
|
|
||||||
field.set(data, dataParsed);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (objectClass == UUID.class)
|
|
||||||
|
|
||||||
{
|
|
||||||
final List<UUID> dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<UUID>>() {});
|
|
||||||
field.set(data, dataParsed);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (objectClass == ObjectId.class) {
|
|
||||||
final List<ObjectId> dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<ObjectId>>() {});
|
|
||||||
field.set(data, dataParsed);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final ManyToManyLocal decorators = field.getDeclaredAnnotation(ManyToManyLocal.class);
|
|
||||||
if (decorators == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (objectClass == decorators.targetEntity()) {
|
|
||||||
final Class<?> foreignKeyType = AnnotationTools.getPrimaryKeyField(objectClass).getType();
|
|
||||||
if (foreignKeyType == Long.class) {
|
|
||||||
final List<Long> idList = objectMapper.readValue(jsonData, new TypeReference<List<Long>>() {});
|
|
||||||
if (idList != null && idList.size() > 0) {
|
|
||||||
final FieldName idField = AnnotationTools.getFieldName(AnnotationTools.getIdField(objectClass),
|
|
||||||
options);
|
|
||||||
// In the lazy mode, the request is done in asynchronous mode, they will be done after...
|
|
||||||
final LazyGetter lambda = () -> {
|
|
||||||
// TODO: update to have get with abstract types ....
|
|
||||||
final Object foreignData = ioDb.getsWhere(decorators.targetEntity(),
|
|
||||||
new Condition(new QueryInList<>(idField.inTable(), idList)));
|
|
||||||
if (foreignData == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
field.set(data, foreignData);
|
|
||||||
};
|
|
||||||
lazyCall.add(lambda);
|
|
||||||
}
|
|
||||||
} else if (foreignKeyType == UUID.class) {
|
|
||||||
final List<UUID> idList = objectMapper.readValue(jsonData, new TypeReference<List<UUID>>() {});
|
|
||||||
if (idList != null && idList.size() > 0) {
|
|
||||||
final FieldName idField = AnnotationTools.getFieldName(AnnotationTools.getIdField(objectClass),
|
|
||||||
options);
|
|
||||||
// In the lazy mode, the request is done in asynchronous mode, they will be done after...
|
|
||||||
final LazyGetter lambda = () -> {
|
|
||||||
final List<UUID> childs = new ArrayList<>(idList);
|
|
||||||
// TODO: update to have get with abstract types ....
|
|
||||||
final Object foreignData = ioDb.getsWhere(decorators.targetEntity(),
|
|
||||||
new Condition(new QueryInList<>(idField.inTable(), childs)));
|
|
||||||
if (foreignData == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
field.set(data, foreignData);
|
|
||||||
};
|
|
||||||
lazyCall.add(lambda);
|
|
||||||
}
|
|
||||||
} else if (foreignKeyType == ObjectId.class) {
|
|
||||||
final List<ObjectId> idList = objectMapper.readValue(jsonData, new TypeReference<List<ObjectId>>() {});
|
|
||||||
if (idList != null && idList.size() > 0) {
|
|
||||||
final FieldName idField = AnnotationTools.getFieldName(AnnotationTools.getIdField(objectClass),
|
|
||||||
options);
|
|
||||||
// In the lazy mode, the request is done in asynchronous mode, they will be done after...
|
|
||||||
final LazyGetter lambda = () -> {
|
|
||||||
final List<ObjectId> childs = new ArrayList<>(idList);
|
|
||||||
// TODO: update to have get with abstract types ....
|
|
||||||
final Object foreignData = ioDb.getsWhere(decorators.targetEntity(),
|
|
||||||
new Condition(new QueryInList<>(idField.inTable(), childs)));
|
|
||||||
if (foreignData == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
field.set(data, foreignData);
|
|
||||||
};
|
|
||||||
lazyCall.add(lambda);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void createTables(
|
|
||||||
final String tableName,
|
|
||||||
final Field primaryField,
|
|
||||||
final Field field,
|
|
||||||
final StringBuilder mainTableBuilder,
|
|
||||||
final List<String> preActionList,
|
|
||||||
final List<String> postActionList,
|
|
||||||
final boolean createIfNotExist,
|
|
||||||
final boolean createDrop,
|
|
||||||
final int fieldId,
|
|
||||||
final QueryOptions options) throws Exception {
|
|
||||||
// store data as json to response like a no-sql
|
|
||||||
DataFactory.createTablesSpecificType(tableName, primaryField, field, mainTableBuilder, preActionList,
|
|
||||||
postActionList, createIfNotExist, createDrop, fieldId, JsonValue.class, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void addLinkLocal(
|
|
||||||
final DBAccess ioDb,
|
|
||||||
final Class<?> clazz,
|
|
||||||
final String clazzPrimaryKeyName,
|
|
||||||
final Object clazzPrimaryKeyValue,
|
|
||||||
final String fieldNameToUpdate,
|
|
||||||
final Object valueToAdd) throws Exception {
|
|
||||||
final String tableName = AnnotationTools.getTableName(clazz);
|
|
||||||
final QueryOptions options = new QueryOptions(new OverrideTableName(tableName),
|
|
||||||
new OptionSpecifyType("idOfTheObject", clazzPrimaryKeyValue.getClass()),
|
|
||||||
new OptionSpecifyType("filedNameOfTheObject", valueToAdd.getClass(), true));
|
|
||||||
options.add(new OptionRenameColumn("idOfTheObject", clazzPrimaryKeyName));
|
|
||||||
options.add(new OptionRenameColumn("filedNameOfTheObject", fieldNameToUpdate));
|
|
||||||
final TableCoversGeneric data = ioDb.get(TableCoversGeneric.class, clazzPrimaryKeyValue, options.getAllArray());
|
|
||||||
if (data.filedNameOfTheObject == null) {
|
|
||||||
data.filedNameOfTheObject = new ArrayList<>();
|
|
||||||
}
|
|
||||||
for (final Object elem : data.filedNameOfTheObject) {
|
|
||||||
if (elem.equals(valueToAdd)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data.filedNameOfTheObject.add(valueToAdd);
|
|
||||||
ioDb.update(data, data.idOfTheObject, List.of("filedNameOfTheObject"), options.getAllArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addLink(
|
|
||||||
final DBAccess ioDb,
|
|
||||||
final Class<?> clazz,
|
|
||||||
final Object clazzPrimaryKeyValue,
|
|
||||||
final String fieldNameToUpdate,
|
|
||||||
final Object valueToAdd) throws Exception {
|
|
||||||
final Field localField = AnnotationTools.getFieldNamed(clazz, fieldNameToUpdate);
|
|
||||||
{
|
|
||||||
//get local field to find the remote field name:
|
|
||||||
final Field primaryKeyField = AnnotationTools.getPrimaryKeyField(clazz);
|
|
||||||
final FieldName primaryKeyColomnName = AnnotationTools.getFieldName(primaryKeyField, null);
|
|
||||||
final FieldName localFieldName = AnnotationTools.getFieldName(localField, null);
|
|
||||||
addLinkLocal(ioDb, clazz, primaryKeyColomnName.inTable(), clazzPrimaryKeyValue, localFieldName.inTable(),
|
|
||||||
valueToAdd);
|
|
||||||
}
|
|
||||||
addLinkRemote(ioDb, localField, clazzPrimaryKeyValue, valueToAdd);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void addLinkRemote(
|
|
||||||
final DBAccess ioDb,
|
|
||||||
final Field localField,
|
|
||||||
final Object localPrimaryKeyValue,
|
|
||||||
final Object remotePrimaryKeyValue) throws Exception {
|
|
||||||
final ManyToManyLocal manyLocal = AnnotationTools.get(localField, ManyToManyLocal.class);
|
|
||||||
// Update the remote elements:
|
|
||||||
if (manyLocal == null || manyLocal.targetEntity() == null || manyLocal.remoteField() == null
|
|
||||||
|| manyLocal.remoteField().isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
//get local field to find the remote field name:
|
|
||||||
final Field primaryKeyField = AnnotationTools.getPrimaryKeyField(manyLocal.targetEntity());
|
|
||||||
final FieldName primaryKeyColomnName = AnnotationTools.getFieldName(primaryKeyField, null);
|
|
||||||
final Field remoteField = AnnotationTools.getFieldNamed(manyLocal.targetEntity(), manyLocal.remoteField());
|
|
||||||
final FieldName localFieldName = AnnotationTools.getFieldName(remoteField, null);
|
|
||||||
addLinkLocal(ioDb, manyLocal.targetEntity(), primaryKeyColomnName.inTable(), remotePrimaryKeyValue,
|
|
||||||
localFieldName.inTable(), localPrimaryKeyValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void removeLinkLocal(
|
|
||||||
final DBAccess ioDb,
|
|
||||||
final Class<?> clazz,
|
|
||||||
final String clazzPrimaryKeyName,
|
|
||||||
final Object clazzPrimaryKeyValue,
|
|
||||||
final String fieldNameToUpdate,
|
|
||||||
final Object valueToRemove) throws Exception {
|
|
||||||
final String tableName = AnnotationTools.getTableName(clazz);
|
|
||||||
final QueryOptions options = new QueryOptions(new OverrideTableName(tableName),
|
|
||||||
new OptionSpecifyType("idOfTheObject", clazzPrimaryKeyValue.getClass()),
|
|
||||||
new OptionSpecifyType("filedNameOfTheObject", valueToRemove.getClass(), true));
|
|
||||||
options.add(new OptionRenameColumn("idOfTheObject", clazzPrimaryKeyName));
|
|
||||||
options.add(new OptionRenameColumn("filedNameOfTheObject", fieldNameToUpdate));
|
|
||||||
final TableCoversGeneric data = ioDb.get(TableCoversGeneric.class, clazzPrimaryKeyValue, options.getAllArray());
|
|
||||||
if (data.filedNameOfTheObject == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final List<Object> newList = new ArrayList<>();
|
|
||||||
for (final Object elem : data.filedNameOfTheObject) {
|
|
||||||
if (elem.equals(valueToRemove)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
newList.add(elem);
|
|
||||||
}
|
|
||||||
data.filedNameOfTheObject = newList;
|
|
||||||
if (data.filedNameOfTheObject.isEmpty()) {
|
|
||||||
data.filedNameOfTheObject = null;
|
|
||||||
}
|
|
||||||
ioDb.update(data, data.idOfTheObject, List.of("filedNameOfTheObject"), options.getAllArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void removeLink(
|
|
||||||
final DBAccess ioDb,
|
|
||||||
final Class<?> clazz,
|
|
||||||
final Object clazzPrimaryKeyValue,
|
|
||||||
final String fieldNameToUpdate,
|
|
||||||
final Object valueToRemove) throws Exception {
|
|
||||||
|
|
||||||
final Field localField = AnnotationTools.getFieldNamed(clazz, fieldNameToUpdate);
|
|
||||||
{
|
|
||||||
//get local field to find the remote field name:
|
|
||||||
final Field primaryKeyField = AnnotationTools.getPrimaryKeyField(clazz);
|
|
||||||
final FieldName primaryKeyColomnName = AnnotationTools.getFieldName(primaryKeyField, null);
|
|
||||||
final FieldName localFieldName = AnnotationTools.getFieldName(localField, null);
|
|
||||||
removeLinkLocal(ioDb, clazz, primaryKeyColomnName.inTable(), clazzPrimaryKeyValue, localFieldName.inTable(),
|
|
||||||
valueToRemove);
|
|
||||||
}
|
|
||||||
removeLinkRemote(ioDb, localField, clazzPrimaryKeyValue, valueToRemove);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void removeLinkRemote(
|
|
||||||
final DBAccess ioDb,
|
|
||||||
final Field localField,
|
|
||||||
final Object localPrimaryKeyValue,
|
|
||||||
final Object remotePrimaryKeyValue) throws Exception {
|
|
||||||
final ManyToManyLocal manyLocal = AnnotationTools.get(localField, ManyToManyLocal.class);
|
|
||||||
// Update the remote elements:
|
|
||||||
if (manyLocal == null || manyLocal.targetEntity() == null || manyLocal.remoteField() == null
|
|
||||||
|| manyLocal.remoteField().isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
//get local field to find the remote field name:
|
|
||||||
final Field primaryKeyField = AnnotationTools.getPrimaryKeyField(manyLocal.targetEntity());
|
|
||||||
final FieldName primaryKeyColomnName = AnnotationTools.getFieldName(primaryKeyField, null);
|
|
||||||
final Field remoteField = AnnotationTools.getFieldNamed(manyLocal.targetEntity(), manyLocal.remoteField());
|
|
||||||
final FieldName localFieldName = AnnotationTools.getFieldName(remoteField, null);
|
|
||||||
removeLinkLocal(ioDb, manyLocal.targetEntity(), primaryKeyColomnName.inTable(), remotePrimaryKeyValue,
|
|
||||||
localFieldName.inTable(), localPrimaryKeyValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
package org.atriasoft.archidata.dataAccess.addOnSQL.model;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.atriasoft.archidata.annotation.DataJson;
|
|
||||||
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
|
|
||||||
public class TableCoversGeneric {
|
|
||||||
public TableCoversGeneric() {
|
|
||||||
// nothing to do...
|
|
||||||
}
|
|
||||||
|
|
||||||
public TableCoversGeneric(final Object idOfTheObject, final List<Object> filedNameOfTheObject) {
|
|
||||||
this.idOfTheObject = idOfTheObject;
|
|
||||||
this.filedNameOfTheObject = filedNameOfTheObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Id
|
|
||||||
public Object idOfTheObject;
|
|
||||||
|
|
||||||
@DataJson()
|
|
||||||
public List<Object> filedNameOfTheObject;
|
|
||||||
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
package org.atriasoft.archidata.dataAccess.options;
|
|
||||||
|
|
||||||
public class QueryOption {}
|
|
@ -1,7 +0,0 @@
|
|||||||
package org.atriasoft.archidata.migration;
|
|
||||||
|
|
||||||
import org.atriasoft.archidata.dataAccess.DBAccess;
|
|
||||||
|
|
||||||
public interface AsyncCall {
|
|
||||||
void doRequest(DBAccess da) throws Exception;
|
|
||||||
}
|
|
@ -1,170 +0,0 @@
|
|||||||
package org.atriasoft.archidata.tools;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZoneOffset;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.time.format.DateTimeParseException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class DateTools {
|
|
||||||
private final static Logger LOGGER = LoggerFactory.getLogger(DateTools.class);
|
|
||||||
|
|
||||||
// List of supported parsers for flexible date string parsing.
|
|
||||||
// Includes patterns with optional parts, slashes, and ISO standard formats.
|
|
||||||
static final List<DateTimeFormatter> FORMATTERS = Arrays.asList(
|
|
||||||
DateTimeFormatter.ofPattern("[yyyy[-MM[-dd]]]['T'][' '][HH[:mm[:ss['.'nnnnnnnnn]]]]XXXXX"),
|
|
||||||
DateTimeFormatter.ofPattern("[yyyy[/MM[/dd]]]['T'][' '][HH[:mm[:ss['.'nnnnnnnnn]]]]XXXXX"),
|
|
||||||
DateTimeFormatter.ISO_OFFSET_DATE_TIME, // e.g., 2025-04-04T15:30:00+02:00
|
|
||||||
DateTimeFormatter.ISO_ZONED_DATE_TIME, // e.g., 2025-04-04T15:30:00+02:00[Europe/Paris]
|
|
||||||
DateTimeFormatter.ISO_INSTANT // e.g., 2025-04-04T13:30:00Z
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to parse a date string into an OffsetDateTime using a flexible list of patterns.
|
|
||||||
* Supports ISO 8601 formats, optional zone, and fallback to LocalDate or LocalTime if needed.
|
|
||||||
*
|
|
||||||
* @param dateString the date string to parse
|
|
||||||
* @return OffsetDateTime representation of the parsed input
|
|
||||||
* @throws IOException if no supported format matches the input
|
|
||||||
*/
|
|
||||||
public static OffsetDateTime parseOffsetDateTime(final String dateString) throws IOException {
|
|
||||||
return parseOffsetDateTime(dateString, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to parse a date string into an OffsetDateTime using a flexible list of patterns.
|
|
||||||
* Supports ISO 8601 formats, optional zone, and fallback to LocalDate or LocalTime if needed.
|
|
||||||
*
|
|
||||||
* @param dateString the date string to parse
|
|
||||||
* @param missingAsUTC Parse date when missing the time zone consider it as a UTC Date-time
|
|
||||||
* @return OffsetDateTime representation of the parsed input
|
|
||||||
* @throws IOException if no supported format matches the input
|
|
||||||
*/
|
|
||||||
public static OffsetDateTime parseOffsetDateTime(final String dateString, final boolean missingAsUTC)
|
|
||||||
throws IOException {
|
|
||||||
if (dateString == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
for (final DateTimeFormatter formatter : FORMATTERS) {
|
|
||||||
try {
|
|
||||||
return OffsetDateTime.parse(dateString, formatter);
|
|
||||||
} catch (final DateTimeParseException ex) {
|
|
||||||
if (missingAsUTC) {
|
|
||||||
// If the date string is missing a zone, try appending "Z"
|
|
||||||
try {
|
|
||||||
if (dateString.endsWith("Z") || dateString.endsWith("z")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return OffsetDateTime.parse(dateString + "Z", formatter);
|
|
||||||
} catch (final DateTimeParseException ex2) {
|
|
||||||
// Still failed, try next pattern
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new IOException("Unrecognized DATE format: '" + dateString + "' supported format ISO8601");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses a flexible date string and returns a java.util.Date,
|
|
||||||
* using system default time-zone for conversion.
|
|
||||||
*
|
|
||||||
* @param dateString the input string to parse
|
|
||||||
* @return The parsed Date
|
|
||||||
* @throws IOException if parsing fails.
|
|
||||||
*/
|
|
||||||
public static Date parseDate(final String dateString) throws IOException {
|
|
||||||
final OffsetDateTime dateTime = parseOffsetDateTime(dateString, true);
|
|
||||||
dateTime.atZoneSameInstant(ZoneId.systemDefault());
|
|
||||||
return Date.from(dateTime.toInstant());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Formatter for date-time with milliseconds and original timezone offset (e.g., 2025-04-06T15:00:00.123+02:00)
|
|
||||||
*/
|
|
||||||
public static final DateTimeFormatter PATTERN_MS_TIME_WITH_ZONE = DateTimeFormatter
|
|
||||||
.ofPattern("yyyy-MM-dd'T'HH:mm:ss'.'SSSXXX");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serializes an OffsetDateTime to a string including milliseconds and the original timezone offset.
|
|
||||||
* Example output: 2025-04-06T15:00:00.123+02:00
|
|
||||||
*/
|
|
||||||
public static String serializeMilliWithOriginalTimeZone(final OffsetDateTime offsetDateTime) {
|
|
||||||
if (offsetDateTime == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return offsetDateTime.format(PATTERN_MS_TIME_WITH_ZONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a java.util.Date to OffsetDateTime using the system's default timezone,
|
|
||||||
* then serializes it to a string with milliseconds and original timezone offset.
|
|
||||||
*/
|
|
||||||
public static String serializeMilliWithOriginalTimeZone(final Date date) {
|
|
||||||
if (date == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return serializeMilliWithOriginalTimeZone(date.toInstant().atZone(ZoneId.systemDefault()).toOffsetDateTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Formatter for date-time with milliseconds in UTC offset (e.g., 2025-04-06T13:00:00.123Z)
|
|
||||||
*/
|
|
||||||
public static final DateTimeFormatter PATTERN_MS_TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'.'SSSX");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serializes an OffsetDateTime to a string with milliseconds in UTC.
|
|
||||||
* The offset is explicitly changed to UTC before formatting.
|
|
||||||
*/
|
|
||||||
public static String serializeMilliWithUTCTimeZone(final OffsetDateTime offsetDateTime) {
|
|
||||||
if (offsetDateTime == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return offsetDateTime.withOffsetSameInstant(ZoneOffset.UTC).format(PATTERN_MS_TIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a java.util.Date to OffsetDateTime in the system's default timezone,
|
|
||||||
* then serializes it with milliseconds in UTC.
|
|
||||||
*/
|
|
||||||
public static String serializeMilliWithUTCTimeZone(final Date date) {
|
|
||||||
if (date == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return serializeMilliWithUTCTimeZone(date.toInstant().atZone(ZoneId.systemDefault()).toOffsetDateTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Formatter for date-time with nanoseconds in UTC offset (e.g., 2025-04-06T13:00:00.123456789Z)
|
|
||||||
*/
|
|
||||||
public static final DateTimeFormatter PATTERN_NS_TIME = DateTimeFormatter
|
|
||||||
.ofPattern("yyyy-MM-dd'T'HH:mm:ss'.'nnnnnnnnnX");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serializes an OffsetDateTime to a string with nanosecond precision in UTC.
|
|
||||||
*/
|
|
||||||
public static String serializeNanoWithUTCTimeZone(final OffsetDateTime offsetDateTime) {
|
|
||||||
if (offsetDateTime == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return offsetDateTime.withOffsetSameInstant(ZoneOffset.UTC).format(PATTERN_NS_TIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a java.util.Date to OffsetDateTime in the system's default timezone,
|
|
||||||
* then serializes it with nanoseconds in UTC.
|
|
||||||
*/
|
|
||||||
public static String serializeNanoWithUTCTimeZone(final Date date) {
|
|
||||||
if (date == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return serializeNanoWithUTCTimeZone(date.toInstant().atZone(ZoneId.systemDefault()).toOffsetDateTime());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,490 +0,0 @@
|
|||||||
package org.atriasoft.archidata.tools;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.net.http.HttpClient;
|
|
||||||
import java.net.http.HttpClient.Version;
|
|
||||||
import java.net.http.HttpRequest;
|
|
||||||
import java.net.http.HttpRequest.BodyPublishers;
|
|
||||||
import java.net.http.HttpRequest.Builder;
|
|
||||||
import java.net.http.HttpResponse;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.atriasoft.archidata.exception.RESTErrorResponseException;
|
|
||||||
import org.bson.types.ObjectId;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonParseException;
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
|
|
||||||
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
|
|
||||||
|
|
||||||
import jakarta.ws.rs.core.HttpHeaders;
|
|
||||||
|
|
||||||
public class RESTApiRequest {
|
|
||||||
final static Logger LOGGER = LoggerFactory.getLogger(RESTApiRequest.class);
|
|
||||||
private final String url;
|
|
||||||
private final String token;
|
|
||||||
private final ObjectMapper mapper;
|
|
||||||
private String serializedBodyString = null;
|
|
||||||
private byte[] serializedBodyByte = null;
|
|
||||||
private String contentType = null;
|
|
||||||
private final Map<String, String> headers = new HashMap<>();
|
|
||||||
private final Map<String, String> queryParam = new HashMap<>();
|
|
||||||
private String verb = "GET";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor to initialize the RESTApiRequest with base URL and authorization token.
|
|
||||||
*
|
|
||||||
* @param url The base URL of the API.
|
|
||||||
* @param token The Bearer token for authentication.
|
|
||||||
*/
|
|
||||||
public RESTApiRequest(final String url, final String token) {
|
|
||||||
this.url = url;
|
|
||||||
this.token = token;
|
|
||||||
this.mapper = ContextGenericTools.createObjectMapper();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the HTTP method (GET, POST, etc.).
|
|
||||||
*
|
|
||||||
* @param verb The HTTP verb to use.
|
|
||||||
* @return The updated RESTApiRequest instance.
|
|
||||||
*/
|
|
||||||
public RESTApiRequest verb(final String verb) {
|
|
||||||
this.verb = verb;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the request body as a raw String.
|
|
||||||
*
|
|
||||||
* @param body The raw string body.
|
|
||||||
* @param contentType The content type of the request body.
|
|
||||||
* @return The updated RESTApiRequest instance.
|
|
||||||
*/
|
|
||||||
public <TYPE_BODY> RESTApiRequest bodyString(final String body, final String contentType) {
|
|
||||||
this.serializedBodyByte = null;
|
|
||||||
this.serializedBodyString = body;
|
|
||||||
this.contentType = contentType;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the request body as a raw String.
|
|
||||||
*
|
|
||||||
* @param body The raw string body (consider as "text/plain").
|
|
||||||
* @return The updated RESTApiRequest instance.
|
|
||||||
*/
|
|
||||||
public <TYPE_BODY> RESTApiRequest bodyString(final String body) {
|
|
||||||
this.serializedBodyByte = null;
|
|
||||||
this.serializedBodyString = body;
|
|
||||||
this.contentType = "text/plain";
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serializes a Map to a JSON string and sets it as the body.
|
|
||||||
*
|
|
||||||
* @param data A map representing the body content.
|
|
||||||
* @return The updated RESTApiRequest instance.
|
|
||||||
* @throws JsonProcessingException If the map fails to serialize.
|
|
||||||
*/
|
|
||||||
public <TYPE_BODY> RESTApiRequest bodyMap(final Map<String, Object> data) throws JsonProcessingException {
|
|
||||||
this.serializedBodyByte = null;
|
|
||||||
this.serializedBodyString = this.mapper.writeValueAsString(data);
|
|
||||||
this.contentType = "application/json";
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the request body as a byte array.
|
|
||||||
*
|
|
||||||
* @param body The byte array representing the body.
|
|
||||||
* @param contentType The content type of the body.
|
|
||||||
* @return The updated RESTApiRequest instance.
|
|
||||||
*/
|
|
||||||
public <TYPE_BODY> RESTApiRequest bodyByte(final byte[] body, final String contentType) {
|
|
||||||
this.serializedBodyByte = body;
|
|
||||||
this.serializedBodyString = null;
|
|
||||||
this.contentType = contentType;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serializes a POJO into JSON and sets it as the body.
|
|
||||||
*
|
|
||||||
* @param body A Java object to serialize.
|
|
||||||
* @return The updated RESTApiRequest instance.
|
|
||||||
* @throws JsonProcessingException If serialization fails.
|
|
||||||
*/
|
|
||||||
public <TYPE_BODY> RESTApiRequest bodyJson(final TYPE_BODY body) throws JsonProcessingException {
|
|
||||||
this.serializedBodyString = this.mapper.writeValueAsString(body);
|
|
||||||
this.contentType = "application/json";
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set data as a json body.
|
|
||||||
*
|
|
||||||
* @param body a serialized Json object.
|
|
||||||
* @return The updated RESTApiRequest instance.
|
|
||||||
*/
|
|
||||||
public <TYPE_BODY> RESTApiRequest bodyAsJson(final String body) {
|
|
||||||
this.serializedBodyString = body;
|
|
||||||
this.contentType = "application/json";
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds a multipart/form-data request body from a map of fields.
|
|
||||||
* Handles both File and standard form fields.
|
|
||||||
*
|
|
||||||
* @param body A map of key-values where values can be File or String.
|
|
||||||
* @return The updated RESTApiRequest instance.
|
|
||||||
* @throws IOException If reading files fails.
|
|
||||||
*/
|
|
||||||
public <TYPE_BODY> RESTApiRequest bodyMultipart(final Map<String, Object> body) throws IOException {
|
|
||||||
this.serializedBodyString = null;
|
|
||||||
LOGGER.trace("body (MULTIPART)");
|
|
||||||
// Create multipart key element
|
|
||||||
final String boundary = (new ObjectId()).toString();
|
|
||||||
this.contentType = "multipart/form-data; boundary=" + boundary;
|
|
||||||
// create the body;
|
|
||||||
final List<byte[]> bodyParts = new ArrayList<>();
|
|
||||||
|
|
||||||
for (final Map.Entry<String, Object> entry : body.entrySet()) {
|
|
||||||
final StringBuilder partHeader = new StringBuilder();
|
|
||||||
partHeader.append("--").append(boundary).append("\r\n");
|
|
||||||
if (entry.getValue() instanceof File) {
|
|
||||||
final File file = (File) entry.getValue();
|
|
||||||
partHeader.append("Content-Disposition: form-data; name=\"").append(entry.getKey())
|
|
||||||
.append("\"; filename=\"").append(file.getName()).append("\"\r\n");
|
|
||||||
partHeader.append("Content-Type: application/octet-stream\r\n\r\n");
|
|
||||||
bodyParts.add(partHeader.toString().getBytes());
|
|
||||||
bodyParts.add(Files.readAllBytes(file.toPath()));
|
|
||||||
bodyParts.add("\r\n".getBytes());
|
|
||||||
} else {
|
|
||||||
partHeader.append("Content-Disposition: form-data; name=\"").append(entry.getKey())
|
|
||||||
.append("\"\r\n\r\n");
|
|
||||||
if (entry.getValue() == null) {
|
|
||||||
partHeader.append("null\r\n");
|
|
||||||
} else {
|
|
||||||
partHeader.append(entry.getValue().toString()).append("\r\n");
|
|
||||||
}
|
|
||||||
bodyParts.add(partHeader.toString().getBytes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bodyParts.add(("--" + boundary + "--\r\n").getBytes());
|
|
||||||
|
|
||||||
final int totalSize = bodyParts.stream().mapToInt(b -> b.length).sum();
|
|
||||||
this.serializedBodyByte = new byte[totalSize];
|
|
||||||
int position = 0;
|
|
||||||
for (final byte[] part : bodyParts) {
|
|
||||||
System.arraycopy(part, 0, this.serializedBodyByte, position, part.length);
|
|
||||||
position += part.length;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a query parameter to the request URL.
|
|
||||||
*
|
|
||||||
* @param paramKey The parameter name.
|
|
||||||
* @param body The parameter value.
|
|
||||||
* @return The updated RESTApiRequest instance.
|
|
||||||
*/
|
|
||||||
public <TYPE_PARAM> RESTApiRequest queryParam(final String paramKey, final TYPE_PARAM body) {
|
|
||||||
this.queryParam.put(paramKey, body.toString());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the HTTP verb to GET.
|
|
||||||
*
|
|
||||||
* @return The updated RESTApiRequest instance.
|
|
||||||
*/
|
|
||||||
public RESTApiRequest get() {
|
|
||||||
verb("GET");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the HTTP verb to PUT.
|
|
||||||
*
|
|
||||||
* @return The updated RESTApiRequest instance.
|
|
||||||
*/
|
|
||||||
public RESTApiRequest put() {
|
|
||||||
verb("PUT");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the HTTP verb to POST.
|
|
||||||
*
|
|
||||||
* @return The updated RESTApiRequest instance.
|
|
||||||
*/
|
|
||||||
public RESTApiRequest post() {
|
|
||||||
verb("POST");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the HTTP verb to PATCH.
|
|
||||||
*
|
|
||||||
* @return The updated RESTApiRequest instance.
|
|
||||||
*/
|
|
||||||
public RESTApiRequest patch() {
|
|
||||||
verb("PATCH");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the HTTP verb to DELETE.
|
|
||||||
*
|
|
||||||
* @return The updated RESTApiRequest instance.
|
|
||||||
*/
|
|
||||||
public RESTApiRequest delete() {
|
|
||||||
verb("DELETE");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the HTTP verb to ARCHIVE.
|
|
||||||
*
|
|
||||||
* @return The updated RESTApiRequest instance.
|
|
||||||
*/
|
|
||||||
public RESTApiRequest archive() {
|
|
||||||
verb("ARCHIVE");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the HTTP verb to RESTORE.
|
|
||||||
*
|
|
||||||
* @return The updated RESTApiRequest instance.
|
|
||||||
*/
|
|
||||||
public RESTApiRequest restore() {
|
|
||||||
verb("RESTORE");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends the request and parses the response into a List of objects.
|
|
||||||
*
|
|
||||||
* @param clazz The class of each element in the expected response.
|
|
||||||
* @return List of parsed response objects.
|
|
||||||
* @throws RESTErrorResponseException If an error response is received.
|
|
||||||
* @throws IOException If the request fails.
|
|
||||||
* @throws InterruptedException If the request is interrupted.
|
|
||||||
*/
|
|
||||||
public <TYPE_RESPONSE> List<TYPE_RESPONSE> fetchList(final Class<TYPE_RESPONSE> clazz)
|
|
||||||
throws RESTErrorResponseException, IOException, InterruptedException {
|
|
||||||
final HttpRequest request = fetch();
|
|
||||||
return callAndParseRequestList(clazz, request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends the request and parses the response into a single object.
|
|
||||||
*
|
|
||||||
* @param clazz The class of the expected response.
|
|
||||||
* @return Parsed response object.
|
|
||||||
* @throws RESTErrorResponseException If an error response is received.
|
|
||||||
* @throws IOException If the request fails.
|
|
||||||
* @throws InterruptedException If the request is interrupted.
|
|
||||||
*/
|
|
||||||
public <TYPE_RESPONSE> TYPE_RESPONSE fetch(final Class<TYPE_RESPONSE> clazz)
|
|
||||||
throws RESTErrorResponseException, IOException, InterruptedException {
|
|
||||||
final HttpRequest request = fetch();
|
|
||||||
return callAndParseRequest(clazz, request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds a query parameter string from a map of key-value pairs.
|
|
||||||
*
|
|
||||||
* <p>This method encodes each key and value using UTF-8 encoding to ensure that
|
|
||||||
* the resulting query string is safe for use in a URL. The encoded key-value pairs
|
|
||||||
* are then joined together with `&` separators.</p>
|
|
||||||
*
|
|
||||||
* @param params A map containing query parameter names and their corresponding values.
|
|
||||||
* Both keys and values will be URL-encoded.
|
|
||||||
* @return A URL-encoded query string.
|
|
||||||
*/
|
|
||||||
public static String buildQueryParams(final Map<String, String> params) {
|
|
||||||
return params.entrySet().stream().map(entry -> URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8) + "="
|
|
||||||
+ URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8)).collect(Collectors.joining("&"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds the final HttpRequest based on method, headers, and body.
|
|
||||||
*
|
|
||||||
* @return A built HttpRequest instance.
|
|
||||||
* @throws RESTErrorResponseException If error happens during body serialization.
|
|
||||||
* @throws IOException If body serialization fails.
|
|
||||||
* @throws InterruptedException If the request is interrupted.
|
|
||||||
*/
|
|
||||||
public HttpRequest fetch() throws RESTErrorResponseException, IOException, InterruptedException {
|
|
||||||
Builder requestBuilding = null;
|
|
||||||
final String queryParams = buildQueryParams(this.queryParam);
|
|
||||||
if (queryParams == null || queryParams.isEmpty()) {
|
|
||||||
requestBuilding = createRequestBuilder("");
|
|
||||||
} else {
|
|
||||||
requestBuilding = createRequestBuilder("?" + queryParams);
|
|
||||||
}
|
|
||||||
if (this.contentType != null) {
|
|
||||||
requestBuilding.header("Content-Type", this.contentType);
|
|
||||||
}
|
|
||||||
for (final Map.Entry<String, String> entry : this.headers.entrySet()) {
|
|
||||||
requestBuilding.header(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
if (this.serializedBodyString != null) {
|
|
||||||
LOGGER.trace("publish body: {}", this.serializedBodyString);
|
|
||||||
return requestBuilding.method(this.verb, BodyPublishers.ofString(this.serializedBodyString)).build();
|
|
||||||
}
|
|
||||||
if (this.serializedBodyByte != null) {
|
|
||||||
LOGGER.trace("publish body: {}", this.serializedBodyString);
|
|
||||||
return requestBuilding.method(this.verb, BodyPublishers.ofByteArray(this.serializedBodyByte)).build();
|
|
||||||
}
|
|
||||||
return requestBuilding.method(this.verb, BodyPublishers.ofString("")).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs a raw GET request and returns the raw HttpResponse as bytes.
|
|
||||||
*
|
|
||||||
* @param urlOffset The URL path relative to the base URL.
|
|
||||||
* @return Raw HTTP response in byte array.
|
|
||||||
* @throws IOException If the request fails.
|
|
||||||
* @throws InterruptedException If the request is interrupted.
|
|
||||||
*/
|
|
||||||
protected HttpResponse<byte[]> getRaw(final String urlOffset) throws IOException, InterruptedException {
|
|
||||||
final Builder requestBuilding = createRequestBuilder(urlOffset);
|
|
||||||
final HttpRequest request = requestBuilding.method("GET", BodyPublishers.ofString("")).build();
|
|
||||||
final HttpClient client = HttpClient.newHttpClient();
|
|
||||||
// client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
|
|
||||||
return client.send(request, HttpResponse.BodyHandlers.ofByteArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes a HttpRequest.Builder with authorization and URL.
|
|
||||||
*
|
|
||||||
* @param urlOffset The URL path relative to the base URL.
|
|
||||||
* @return Initialized HttpRequest.Builder.
|
|
||||||
*/
|
|
||||||
private Builder createRequestBuilder(final String urlOffset) {
|
|
||||||
Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1)
|
|
||||||
.uri(URI.create(this.url + urlOffset));
|
|
||||||
if (this.token != null) {
|
|
||||||
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Bearer " + this.token);
|
|
||||||
}
|
|
||||||
return requestBuilding;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends the request and parses the response as a single object.
|
|
||||||
*
|
|
||||||
* @param clazzReturn The expected class of the response.
|
|
||||||
* @param request The built HttpRequest to send.
|
|
||||||
* @return Parsed object of the response.
|
|
||||||
* @throws RESTErrorResponseException If an error response is received.
|
|
||||||
* @throws IOException If the response cannot be parsed or network fails.
|
|
||||||
* @throws InterruptedException If the request is interrupted.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private <TYPE_RESPONSE> TYPE_RESPONSE callAndParseRequest(
|
|
||||||
final Class<TYPE_RESPONSE> clazzReturn,
|
|
||||||
final HttpRequest request) throws RESTErrorResponseException, IOException, InterruptedException {
|
|
||||||
final HttpClient client = HttpClient.newHttpClient();
|
|
||||||
// client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
|
|
||||||
final HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
|
||||||
if (clazzReturn == HttpResponse.class) {
|
|
||||||
return (TYPE_RESPONSE) httpResponse;
|
|
||||||
}
|
|
||||||
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
|
|
||||||
LOGGER.trace("Receive Error: {}", httpResponse.body());
|
|
||||||
try {
|
|
||||||
final RESTErrorResponseException out = this.mapper.readValue(httpResponse.body(),
|
|
||||||
RESTErrorResponseException.class);
|
|
||||||
throw out;
|
|
||||||
} catch (final InvalidDefinitionException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
LOGGER.error("body: {}", httpResponse.body());
|
|
||||||
throw new IOException("RestAPI Fail to parse the error " + ex.getClass().getName() + " ["
|
|
||||||
+ httpResponse.statusCode() + "] " + httpResponse.body());
|
|
||||||
} catch (final MismatchedInputException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
LOGGER.error("body: {}", httpResponse.body());
|
|
||||||
throw new IOException("RestAPI Fail to parse the error " + ex.getClass().getName() + " ["
|
|
||||||
+ httpResponse.statusCode() + "] " + httpResponse.body());
|
|
||||||
} catch (final JsonParseException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
LOGGER.error("body: {}", httpResponse.body());
|
|
||||||
throw new IOException("RestAPI Fail to parse the error " + ex.getClass().getName() + " ["
|
|
||||||
+ httpResponse.statusCode() + "] " + httpResponse.body());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (clazzReturn == Void.class || clazzReturn == void.class) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (clazzReturn.equals(String.class)) {
|
|
||||||
return (TYPE_RESPONSE) httpResponse.body();
|
|
||||||
}
|
|
||||||
LOGGER.trace("Receive model: {} with data: '{}'", clazzReturn.getCanonicalName(), httpResponse.body());
|
|
||||||
return this.mapper.readValue(httpResponse.body(), clazzReturn);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends the request and parses the response as a list of objects.
|
|
||||||
*
|
|
||||||
* @param clazzReturn The class of the expected response elements.
|
|
||||||
* @param request The HttpRequest to send.
|
|
||||||
* @return List of parsed response objects.
|
|
||||||
* @throws RESTErrorResponseException If an error response is received.
|
|
||||||
* @throws IOException If the response cannot be parsed or network fails.
|
|
||||||
* @throws InterruptedException If the request is interrupted.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private <TYPE_RESPONSE> List<TYPE_RESPONSE> callAndParseRequestList(
|
|
||||||
final Class<TYPE_RESPONSE> clazzReturn,
|
|
||||||
final HttpRequest request) throws IOException, InterruptedException, RESTErrorResponseException {
|
|
||||||
final HttpClient client = HttpClient.newHttpClient();
|
|
||||||
// client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
|
|
||||||
final HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
|
||||||
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
|
|
||||||
LOGGER.trace("Receive Error: {}", httpResponse.body());
|
|
||||||
try {
|
|
||||||
final RESTErrorResponseException out = this.mapper.readValue(httpResponse.body(),
|
|
||||||
RESTErrorResponseException.class);
|
|
||||||
throw out;
|
|
||||||
} catch (final InvalidDefinitionException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
LOGGER.error("body: {}", httpResponse.body());
|
|
||||||
throw new IOException("RestAPI Fail to parse the error " + ex.getClass().getName() + " ["
|
|
||||||
+ httpResponse.statusCode() + "] " + httpResponse.body());
|
|
||||||
} catch (final MismatchedInputException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
LOGGER.error("body: {}", httpResponse.body());
|
|
||||||
throw new IOException("RestAPI Fail to parse the error " + ex.getClass().getName() + " ["
|
|
||||||
+ httpResponse.statusCode() + "] " + httpResponse.body());
|
|
||||||
} catch (final JsonParseException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
LOGGER.error("body: {}", httpResponse.body());
|
|
||||||
throw new IOException("RestAPI Fail to parse the error " + ex.getClass().getName() + " ["
|
|
||||||
+ httpResponse.statusCode() + "] " + httpResponse.body());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LOGGER.trace("Receive model: List<{}> with data: '{}'", clazzReturn.getCanonicalName(), httpResponse.body());
|
|
||||||
return this.mapper.readValue(httpResponse.body(),
|
|
||||||
this.mapper.getTypeFactory().constructCollectionType(List.class, clazzReturn));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
package org.atriasoft.archidata;
|
package org.kar.archidata;
|
||||||
|
|
||||||
import org.atriasoft.archidata.tools.ConfigBaseVariable;
|
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||||
import org.atriasoft.archidata.tools.JWTWrapper;
|
import org.kar.archidata.tools.JWTWrapper;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation;
|
package org.kar.archidata.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@ -6,14 +6,14 @@ import java.lang.reflect.Parameter;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.atriasoft.archidata.annotation.checker.Checker;
|
import org.kar.archidata.annotation.checker.Checker;
|
||||||
import org.atriasoft.archidata.annotation.checker.CollectionItemNotNull;
|
import org.kar.archidata.annotation.checker.CollectionItemNotNull;
|
||||||
import org.atriasoft.archidata.annotation.checker.CollectionItemUnique;
|
import org.kar.archidata.annotation.checker.CollectionItemUnique;
|
||||||
import org.atriasoft.archidata.annotation.checker.CollectionNotEmpty;
|
import org.kar.archidata.annotation.checker.CollectionNotEmpty;
|
||||||
import org.atriasoft.archidata.dataAccess.QueryOptions;
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
import org.atriasoft.archidata.dataAccess.options.OptionRenameColumn;
|
import org.kar.archidata.dataAccess.options.OptionRenameColumn;
|
||||||
import org.atriasoft.archidata.dataAccess.options.OverrideTableName;
|
import org.kar.archidata.dataAccess.options.OverrideTableName;
|
||||||
import org.atriasoft.archidata.exception.DataAccessException;
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation;
|
package org.kar.archidata.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation;
|
package org.kar.archidata.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation;
|
package org.kar.archidata.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation;
|
package org.kar.archidata.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation;
|
package org.kar.archidata.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@ -20,7 +20,7 @@ import java.lang.annotation.Target;
|
|||||||
* - When a field is annotated with @DataNotRead, it will not be included in the
|
* - When a field is annotated with @DataNotRead, it will not be included in the
|
||||||
* default data retrieval process from the database.
|
* default data retrieval process from the database.
|
||||||
* - To override this behavior and read all columns, including those marked with
|
* - To override this behavior and read all columns, including those marked with
|
||||||
* `@DataNotRead`, the query must include the option ReadAllColumn.
|
* @DataNotRead, the query must include the option ReadAllColumn.
|
||||||
*
|
*
|
||||||
* <p>Example:
|
* <p>Example:
|
||||||
* <pre>{@code
|
* <pre>{@code
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation;
|
package org.kar.archidata.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.addOn;
|
package org.kar.archidata.annotation.addOn;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.apiGenerator;
|
package org.kar.archidata.annotation.apiGenerator;
|
||||||
|
|
||||||
import static java.lang.annotation.ElementType.FIELD;
|
import static java.lang.annotation.ElementType.FIELD;
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
@ -9,11 +9,6 @@ import java.lang.annotation.Target;
|
|||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
@Target(FIELD)
|
@Target(FIELD)
|
||||||
public @interface ApiAccessLimitation {
|
public @interface ApiAccessLimitation {
|
||||||
/**
|
|
||||||
* (Optional) The field is accessible in read (GET)
|
|
||||||
*/
|
|
||||||
boolean readable() default true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Optional) The field is accessible in creation (POST)
|
* (Optional) The field is accessible in creation (POST)
|
||||||
*/
|
*/
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.apiGenerator;
|
package org.kar.archidata.annotation.apiGenerator;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.apiGenerator;
|
package org.kar.archidata.annotation.apiGenerator;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.apiGenerator;
|
package org.kar.archidata.annotation.apiGenerator;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@ -22,8 +22,7 @@ import java.lang.annotation.Target;
|
|||||||
* more flexible API designs where certain inputs can be omitted.
|
* more flexible API designs where certain inputs can be omitted.
|
||||||
*
|
*
|
||||||
* <p>Example:
|
* <p>Example:
|
||||||
*
|
* <pre>{@code
|
||||||
* {@code
|
|
||||||
* public class AlbumService {
|
* public class AlbumService {
|
||||||
*
|
*
|
||||||
* @POST
|
* @POST
|
||||||
@ -40,8 +39,7 @@ import java.lang.annotation.Target;
|
|||||||
* // some code
|
* // some code
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
* }
|
* }</pre>
|
||||||
*
|
|
||||||
*
|
*
|
||||||
* Note: @FormDataParam must be allway at the last position.
|
* Note: @FormDataParam must be allway at the last position.
|
||||||
*
|
*
|
||||||
@ -49,8 +47,7 @@ import java.lang.annotation.Target;
|
|||||||
* marked as optional, allowing the client to omit them when calling the API.
|
* marked as optional, allowing the client to omit them when calling the API.
|
||||||
*
|
*
|
||||||
* <p>Generated TypeScript code example:
|
* <p>Generated TypeScript code example:
|
||||||
*
|
* <pre>{@code
|
||||||
* {@code
|
|
||||||
* //Add a cover on a specific album
|
* //Add a cover on a specific album
|
||||||
* export function uploadCover({
|
* export function uploadCover({
|
||||||
* restConfig,
|
* restConfig,
|
||||||
@ -67,11 +64,10 @@ import java.lang.annotation.Target;
|
|||||||
* uri?: string, // element is optional
|
* uri?: string, // element is optional
|
||||||
* },
|
* },
|
||||||
* callbacks?: RESTCallbacks,
|
* callbacks?: RESTCallbacks,
|
||||||
* }): Promise<Album> { ... }
|
* }): Promise<Album> { ...
|
||||||
* }
|
* }</pre>
|
||||||
*
|
*
|
||||||
*
|
* The generated TypeScript function reflects the optional nature of the form data parameters.
|
||||||
* The generated TypeScript function reflects the optional nature of the form data parameters
|
|
||||||
*/
|
*/
|
||||||
@Target({ ElementType.PARAMETER })
|
@Target({ ElementType.PARAMETER })
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.apiGenerator;
|
package org.kar.archidata.annotation.apiGenerator;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@ -25,7 +25,7 @@ import java.lang.annotation.Target;
|
|||||||
* the older XMLHttpRequest interface is utilized.
|
* the older XMLHttpRequest interface is utilized.
|
||||||
*
|
*
|
||||||
* <p>Example:
|
* <p>Example:
|
||||||
* {@code
|
* <pre>{@code
|
||||||
* public class SeasonService {
|
* public class SeasonService {
|
||||||
*
|
*
|
||||||
* @POST
|
* @POST
|
||||||
@ -41,13 +41,13 @@ import java.lang.annotation.Target;
|
|||||||
* // Upload logic
|
* // Upload logic
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
* }
|
* }</pre>
|
||||||
*
|
*
|
||||||
* In this example, the uploadCover method will generate a client-side API
|
* In this example, the uploadCover method will generate a client-side API
|
||||||
* with progress tracking capabilities using XMLHttpRequest.
|
* with progress tracking capabilities using XMLHttpRequest.
|
||||||
*
|
*
|
||||||
* <p>Generated TypeScript code example:
|
* <p>Generated TypeScript code example:
|
||||||
* {@code
|
* <pre>{@code
|
||||||
* export function uploadCover({
|
* export function uploadCover({
|
||||||
* restConfig,
|
* restConfig,
|
||||||
* params,
|
* params,
|
||||||
@ -62,9 +62,8 @@ import java.lang.annotation.Target;
|
|||||||
* file: File,
|
* file: File,
|
||||||
* },
|
* },
|
||||||
* callbacks?: RESTCallbacks,
|
* callbacks?: RESTCallbacks,
|
||||||
* }): Promise<Season> {...}
|
* }): Promise<Season> {...
|
||||||
* }
|
* }</pre>
|
||||||
*
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Target({ ElementType.PARAMETER, ElementType.METHOD })
|
@Target({ ElementType.PARAMETER, ElementType.METHOD })
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.checker;
|
package org.kar.archidata.annotation.checker;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@ -9,15 +9,7 @@ import jakarta.validation.Constraint;
|
|||||||
import jakarta.validation.Payload;
|
import jakarta.validation.Payload;
|
||||||
|
|
||||||
@Constraint(validatedBy = CheckForeignKeyValidator.class)
|
@Constraint(validatedBy = CheckForeignKeyValidator.class)
|
||||||
@Target({ ElementType.TYPE, //
|
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD })
|
||||||
ElementType.METHOD, //
|
|
||||||
ElementType.FIELD, //
|
|
||||||
ElementType.ANNOTATION_TYPE, //
|
|
||||||
ElementType.CONSTRUCTOR, //
|
|
||||||
ElementType.PARAMETER, //
|
|
||||||
ElementType.TYPE_USE, //
|
|
||||||
})
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface CheckForeignKey {
|
public @interface CheckForeignKey {
|
||||||
Class<?> target();
|
Class<?> target();
|
@ -0,0 +1,43 @@
|
|||||||
|
package org.kar.archidata.annotation.checker;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
|
||||||
|
import jakarta.validation.ConstraintValidator;
|
||||||
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
|
|
||||||
|
public class CheckForeignKeyValidator implements ConstraintValidator<CheckForeignKey, Object> {
|
||||||
|
Class<?> target = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(final CheckForeignKey annotation) {
|
||||||
|
this.target = annotation.target();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(final Object value, final ConstraintValidatorContext context) {
|
||||||
|
if (value != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (value instanceof final Collection<?> tmpCollection) {
|
||||||
|
final Object[] elements = tmpCollection.toArray();
|
||||||
|
for (final Object element : elements) {
|
||||||
|
if (element == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
final long count = DataAccess.count(this.target, element);
|
||||||
|
if (count != 1) {
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (final Exception e) {
|
||||||
|
// TODO ...
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,11 @@
|
|||||||
package org.atriasoft.archidata.annotation.checker;
|
package org.kar.archidata.annotation.checker;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.CheckFunctionInterface;
|
import org.kar.archidata.dataAccess.options.CheckFunctionInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Checker annotation is used to specify a checker class that automatically
|
* The Checker annotation is used to specify a checker class that automatically
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.checker;
|
package org.kar.archidata.annotation.checker;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.checker;
|
package org.kar.archidata.annotation.checker;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.checker;
|
package org.kar.archidata.annotation.checker;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.checker;
|
package org.kar.archidata.annotation.checker;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.checker;
|
package org.kar.archidata.annotation.checker;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.checker;
|
package org.kar.archidata.annotation.checker;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.checker;
|
package org.kar.archidata.annotation.checker;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.checker;
|
package org.kar.archidata.annotation.checker;
|
||||||
|
|
||||||
import jakarta.validation.ConstraintValidator;
|
import jakarta.validation.ConstraintValidator;
|
||||||
import jakarta.validation.ConstraintValidatorContext;
|
import jakarta.validation.ConstraintValidatorContext;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.method;
|
package org.kar.archidata.annotation.method;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.method;
|
package org.kar.archidata.annotation.method;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.annotation.security;
|
package org.kar.archidata.annotation.security;
|
||||||
|
|
||||||
import static java.lang.annotation.ElementType.METHOD;
|
import static java.lang.annotation.ElementType.METHOD;
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.api;
|
package org.kar.archidata.api;
|
||||||
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
@ -21,18 +21,18 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import org.atriasoft.archidata.annotation.apiGenerator.ApiInputOptional;
|
|
||||||
import org.atriasoft.archidata.annotation.security.PermitTokenInURI;
|
|
||||||
import org.atriasoft.archidata.dataAccess.DataAccess;
|
|
||||||
import org.atriasoft.archidata.dataAccess.QueryCondition;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.Condition;
|
|
||||||
import org.atriasoft.archidata.exception.FailException;
|
|
||||||
import org.atriasoft.archidata.filter.GenericContext;
|
|
||||||
import org.atriasoft.archidata.model.Data;
|
|
||||||
import org.atriasoft.archidata.tools.ConfigBaseVariable;
|
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||||
|
import org.kar.archidata.annotation.apiGenerator.ApiInputOptional;
|
||||||
|
import org.kar.archidata.annotation.security.PermitTokenInURI;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.QueryCondition;
|
||||||
|
import org.kar.archidata.dataAccess.options.Condition;
|
||||||
|
import org.kar.archidata.exception.FailException;
|
||||||
|
import org.kar.archidata.filter.GenericContext;
|
||||||
|
import org.kar.archidata.model.Data;
|
||||||
|
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -157,8 +157,13 @@ public class DataResource {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getMimeType(final String extension) throws IOException {
|
public Data createNewData(final long tmpUID, final String originalFileName, final String sha512)
|
||||||
return switch (extension.toLowerCase()) {
|
throws IOException {
|
||||||
|
// determine mime type:
|
||||||
|
Data injectedData = new Data();
|
||||||
|
String mimeType = "";
|
||||||
|
final String extension = originalFileName.substring(originalFileName.lastIndexOf('.') + 1);
|
||||||
|
mimeType = switch (extension.toLowerCase()) {
|
||||||
case "jpg", "jpeg" -> "image/jpeg";
|
case "jpg", "jpeg" -> "image/jpeg";
|
||||||
case "png" -> "image/png";
|
case "png" -> "image/png";
|
||||||
case "webp" -> "image/webp";
|
case "webp" -> "image/webp";
|
||||||
@ -167,15 +172,6 @@ public class DataResource {
|
|||||||
case "webm" -> "video/webm";
|
case "webm" -> "video/webm";
|
||||||
default -> throw new IOException("Can not find the mime type of data input: '" + extension + "'");
|
default -> throw new IOException("Can not find the mime type of data input: '" + extension + "'");
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
public Data createNewData(final long tmpUID, final String originalFileName, final String sha512)
|
|
||||||
throws IOException {
|
|
||||||
// determine mime type:
|
|
||||||
Data injectedData = new Data();
|
|
||||||
String mimeType = "";
|
|
||||||
final String extension = originalFileName.substring(originalFileName.lastIndexOf('.') + 1);
|
|
||||||
mimeType = getMimeType(extension);
|
|
||||||
injectedData.mimeType = mimeType;
|
injectedData.mimeType = mimeType;
|
||||||
injectedData.sha512 = sha512;
|
injectedData.sha512 = sha512;
|
||||||
final String tmpPath = getTmpFileInData(tmpUID);
|
final String tmpPath = getTmpFileInData(tmpUID);
|
||||||
@ -373,9 +369,10 @@ public class DataResource {
|
|||||||
}
|
}
|
||||||
LOGGER.info("input size image: {}x{} type={}", inputImage.getWidth(), inputImage.getHeight(),
|
LOGGER.info("input size image: {}x{} type={}", inputImage.getWidth(), inputImage.getHeight(),
|
||||||
inputImage.getType());
|
inputImage.getType());
|
||||||
final int scaledWidth = ConfigBaseVariable.getThumbnailWidth();
|
final int scaledWidth = 250;
|
||||||
final int scaledHeight = (int) ((float) inputImage.getHeight() / (float) inputImage.getWidth()
|
final int scaledHeight = (int) ((float) inputImage.getHeight() / (float) inputImage.getWidth()
|
||||||
* scaledWidth);
|
* scaledWidth);
|
||||||
|
|
||||||
// creates output image
|
// creates output image
|
||||||
final BufferedImage outputImage = new BufferedImage(scaledWidth, scaledHeight, inputImage.getType());
|
final BufferedImage outputImage = new BufferedImage(scaledWidth, scaledHeight, inputImage.getType());
|
||||||
|
|
||||||
@ -384,10 +381,16 @@ public class DataResource {
|
|||||||
LOGGER.info("output size image: {}x{}", scaledWidth, scaledHeight);
|
LOGGER.info("output size image: {}x{}", scaledWidth, scaledHeight);
|
||||||
g2d.drawImage(inputImage, 0, 0, scaledWidth, scaledHeight, null);
|
g2d.drawImage(inputImage, 0, 0, scaledWidth, scaledHeight, null);
|
||||||
g2d.dispose();
|
g2d.dispose();
|
||||||
|
for (final String data : ImageIO.getWriterFormatNames()) {
|
||||||
|
LOGGER.info("availlable format: {}", data);
|
||||||
|
}
|
||||||
// create the output stream:
|
// create the output stream:
|
||||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
try {
|
try {
|
||||||
ImageIO.write(outputImage, ConfigBaseVariable.getThumbnailFormat(), baos);
|
// 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);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return Response.status(500).entity("Internal Error: resize fail: " + e.getMessage()).type("text/plain")
|
return Response.status(500).entity("Internal Error: resize fail: " + e.getMessage()).type("text/plain")
|
||||||
@ -395,20 +398,12 @@ public class DataResource {
|
|||||||
}
|
}
|
||||||
final byte[] imageData = baos.toByteArray();
|
final byte[] imageData = baos.toByteArray();
|
||||||
LOGGER.info("output length {}", imageData.length);
|
LOGGER.info("output length {}", imageData.length);
|
||||||
if (imageData.length == 0) {
|
// Response.ok(new ByteArrayInputStream(imageData)).build();
|
||||||
LOGGER.error("Fail to convert image... Availlable format:");
|
|
||||||
for (final String data : ImageIO.getWriterFormatNames()) {
|
|
||||||
LOGGER.error(" - {}", data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final Response.ResponseBuilder out = Response.ok(imageData).header(HttpHeaders.CONTENT_LENGTH,
|
final Response.ResponseBuilder out = Response.ok(imageData).header(HttpHeaders.CONTENT_LENGTH,
|
||||||
imageData.length);
|
imageData.length);
|
||||||
try {
|
//out.type("image/jpeg");
|
||||||
out.type(getMimeType(ConfigBaseVariable.getThumbnailFormat()));
|
out.type("image/webp");
|
||||||
} catch (final IOException ex) {
|
//out.type("image/png");
|
||||||
throw new FailException(Response.Status.INTERNAL_SERVER_ERROR,
|
|
||||||
"Fail to convert mime type of " + ConfigBaseVariable.getThumbnailFormat(), ex);
|
|
||||||
}
|
|
||||||
// TODO: move this in a decorator !!!
|
// TODO: move this in a decorator !!!
|
||||||
final CacheControl cc = new CacheControl();
|
final CacheControl cc = new CacheControl();
|
||||||
cc.setMaxAge(3600);
|
cc.setMaxAge(3600);
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.api;
|
package org.kar.archidata.api;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.api;
|
package org.kar.archidata.api;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.api;
|
package org.kar.archidata.api;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.api;
|
package org.kar.archidata.api;
|
||||||
|
|
||||||
import io.swagger.v3.jaxrs2.integration.resources.BaseOpenApiResource;
|
import io.swagger.v3.jaxrs2.integration.resources.BaseOpenApiResource;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.backup;
|
package org.kar.archidata.backup;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.catcher;
|
package org.kar.archidata.catcher;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.catcher;
|
package org.kar.archidata.catcher;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
@ -1,6 +1,6 @@
|
|||||||
package org.atriasoft.archidata.catcher;
|
package org.kar.archidata.catcher;
|
||||||
|
|
||||||
import org.atriasoft.archidata.exception.FailException;
|
import org.kar.archidata.exception.FailException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.catcher;
|
package org.kar.archidata.catcher;
|
||||||
|
|
||||||
import org.glassfish.jersey.server.ResourceConfig;
|
import org.glassfish.jersey.server.ResourceConfig;
|
||||||
|
|
||||||
@ -11,16 +11,15 @@ public class GenericCatcher {
|
|||||||
public static void addAll(final ResourceConfig rc) {
|
public static void addAll(final ResourceConfig rc) {
|
||||||
// Generic Json parsing error
|
// Generic Json parsing error
|
||||||
rc.register(JacksonExceptionCatcher.class);
|
rc.register(JacksonExceptionCatcher.class);
|
||||||
|
// Catch jakarta generic errors
|
||||||
|
rc.register(WebApplicationExceptionCatcher.class);
|
||||||
// Archidata exceptions
|
// Archidata exceptions
|
||||||
rc.register(InputExceptionCatcher.class);
|
rc.register(InputExceptionCatcher.class);
|
||||||
rc.register(SystemExceptionCatcher.class);
|
rc.register(SystemExceptionCatcher.class);
|
||||||
rc.register(FailExceptionCatcher.class);
|
rc.register(FailExceptionCatcher.class);
|
||||||
// generic Exception catcher
|
// generic Exception catcher
|
||||||
rc.register(ConstraintViolationExceptionCatcher.class);
|
|
||||||
rc.register(QueryParamExceptionCatcher.class);
|
|
||||||
rc.register(ExceptionCatcher.class);
|
rc.register(ExceptionCatcher.class);
|
||||||
// Catch jakarta generic errors
|
rc.register(ConstraintViolationExceptionCatcher.class);
|
||||||
rc.register(WebApplicationExceptionCatcher.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package org.atriasoft.archidata.catcher;
|
package org.kar.archidata.catcher;
|
||||||
|
|
||||||
import org.atriasoft.archidata.exception.InputException;
|
import org.kar.archidata.exception.InputException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.catcher;
|
package org.kar.archidata.catcher;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
@ -1,10 +1,10 @@
|
|||||||
package org.atriasoft.archidata.catcher;
|
package org.kar.archidata.catcher;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.atriasoft.archidata.annotation.apiGenerator.ApiGenerationMode;
|
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
|
import org.kar.archidata.annotation.apiGenerator.ApiGenerationMode;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.catcher;
|
package org.kar.archidata.catcher;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -27,17 +27,6 @@ public class RestInputError {
|
|||||||
|
|
||||||
public RestInputError() {}
|
public RestInputError() {}
|
||||||
|
|
||||||
public RestInputError(final String argument, final String path, final String message) {
|
|
||||||
this.path = argument;
|
|
||||||
this.path = path;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RestInputError(final String path, final String message) {
|
|
||||||
this.path = path;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RestInputError(final Path path, final String message) {
|
public RestInputError(final Path path, final String message) {
|
||||||
final Matcher matcher = PATTERN.matcher(path.toString());
|
final Matcher matcher = PATTERN.matcher(path.toString());
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
@ -50,6 +39,11 @@ public class RestInputError {
|
|||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RestInputError(final String path, final String message) {
|
||||||
|
this.path = path;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
String getFullPath() {
|
String getFullPath() {
|
||||||
if (this.path == null) {
|
if (this.path == null) {
|
||||||
return this.argument;
|
return this.argument;
|
@ -1,6 +1,6 @@
|
|||||||
package org.atriasoft.archidata.catcher;
|
package org.kar.archidata.catcher;
|
||||||
|
|
||||||
import org.atriasoft.archidata.exception.SystemException;
|
import org.kar.archidata.exception.SystemException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.catcher;
|
package org.kar.archidata.catcher;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.checker;
|
package org.kar.archidata.checker;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
@ -14,21 +14,21 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.atriasoft.archidata.annotation.AnnotationTools;
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
import org.atriasoft.archidata.annotation.checker.CheckForeignKey;
|
import org.kar.archidata.annotation.checker.CheckForeignKey;
|
||||||
import org.atriasoft.archidata.annotation.checker.Checker;
|
import org.kar.archidata.annotation.checker.Checker;
|
||||||
import org.atriasoft.archidata.annotation.checker.CollectionItemNotNull;
|
import org.kar.archidata.annotation.checker.CollectionItemNotNull;
|
||||||
import org.atriasoft.archidata.annotation.checker.CollectionItemUnique;
|
import org.kar.archidata.annotation.checker.CollectionItemUnique;
|
||||||
import org.atriasoft.archidata.annotation.checker.CollectionNotEmpty;
|
import org.kar.archidata.annotation.checker.CollectionNotEmpty;
|
||||||
import org.atriasoft.archidata.dataAccess.DBAccess;
|
import org.kar.archidata.dataAccess.DBAccess;
|
||||||
import org.atriasoft.archidata.dataAccess.QueryCondition;
|
import org.kar.archidata.dataAccess.QueryCondition;
|
||||||
import org.atriasoft.archidata.dataAccess.QueryOptions;
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
import org.atriasoft.archidata.dataAccess.options.CheckFunctionInterface;
|
import org.kar.archidata.dataAccess.options.CheckFunctionInterface;
|
||||||
import org.atriasoft.archidata.dataAccess.options.CheckFunctionVoid;
|
import org.kar.archidata.dataAccess.options.CheckFunctionVoid;
|
||||||
import org.atriasoft.archidata.dataAccess.options.Condition;
|
import org.kar.archidata.dataAccess.options.Condition;
|
||||||
import org.atriasoft.archidata.dataAccess.options.ConditionChecker;
|
import org.kar.archidata.dataAccess.options.ConditionChecker;
|
||||||
import org.atriasoft.archidata.exception.DataAccessException;
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
import org.atriasoft.archidata.exception.InputException;
|
import org.kar.archidata.exception.InputException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
14
src/org/kar/archidata/converter/jackson/JacksonModules.java
Normal file
14
src/org/kar/archidata/converter/jackson/JacksonModules.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package org.kar.archidata.converter.jackson;
|
||||||
|
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
|
||||||
|
public class JacksonModules {
|
||||||
|
public static SimpleModule getAllModules() {
|
||||||
|
final SimpleModule module = new SimpleModule();
|
||||||
|
module.addSerializer(ObjectId.class, new ObjectIdSerializer());
|
||||||
|
module.addDeserializer(ObjectId.class, new ObjectIdDeserializer());
|
||||||
|
return module;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.converter.jackson;
|
package org.kar.archidata.converter.jackson;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -13,4 +13,4 @@ public class ObjectIdDeserializer extends JsonDeserializer<ObjectId> {
|
|||||||
public ObjectId deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
|
public ObjectId deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
|
||||||
return new ObjectId(p.getValueAsString());
|
return new ObjectId(p.getValueAsString());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.converter.jackson;
|
package org.kar.archidata.converter.jackson;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -14,4 +14,4 @@ public class ObjectIdSerializer extends JsonSerializer<ObjectId> {
|
|||||||
throws IOException {
|
throws IOException {
|
||||||
gen.writeString(value.toHexString());
|
gen.writeString(value.toHexString());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.converter.morphia;
|
package org.kar.archidata.converter.morphia;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
/** Java does not permit to set return data (eg: integer) in the function parameter. This class permit to update a value as in/out function parameters. */
|
/** Java does not permit to set return data (eg: integer) in the function parameter. This class permit to update a value as in/out function parameters. */
|
||||||
public class CountInOut {
|
public class CountInOut {
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -6,21 +6,21 @@ import java.lang.reflect.Field;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.atriasoft.archidata.annotation.AnnotationTools;
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
import org.atriasoft.archidata.annotation.AnnotationTools.FieldName;
|
import org.kar.archidata.annotation.AnnotationTools.FieldName;
|
||||||
import org.atriasoft.archidata.dataAccess.options.Condition;
|
import org.kar.archidata.dataAccess.options.Condition;
|
||||||
import org.atriasoft.archidata.dataAccess.options.FilterValue;
|
import org.kar.archidata.dataAccess.options.FilterValue;
|
||||||
import org.atriasoft.archidata.dataAccess.options.Limit;
|
import org.kar.archidata.dataAccess.options.Limit;
|
||||||
import org.atriasoft.archidata.dataAccess.options.OptionSpecifyType;
|
import org.kar.archidata.dataAccess.options.OptionSpecifyType;
|
||||||
import org.atriasoft.archidata.dataAccess.options.QueryOption;
|
import org.kar.archidata.dataAccess.options.QueryOption;
|
||||||
import org.atriasoft.archidata.dataAccess.options.TransmitKey;
|
import org.kar.archidata.dataAccess.options.TransmitKey;
|
||||||
import org.atriasoft.archidata.db.DbConfig;
|
import org.kar.archidata.db.DbConfig;
|
||||||
import org.atriasoft.archidata.db.DbIo;
|
import org.kar.archidata.db.DbIo;
|
||||||
import org.atriasoft.archidata.db.DbIoFactory;
|
import org.kar.archidata.db.DbIoFactory;
|
||||||
import org.atriasoft.archidata.db.DbIoMorphia;
|
import org.kar.archidata.db.DbIoMorphia;
|
||||||
import org.atriasoft.archidata.db.DbIoSql;
|
import org.kar.archidata.db.DbIoSql;
|
||||||
import org.atriasoft.archidata.exception.DataAccessException;
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
import org.atriasoft.archidata.tools.ContextGenericTools;
|
import org.kar.archidata.tools.ContextGenericTools;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -185,8 +185,7 @@ public abstract class DBAccess implements Closeable {
|
|||||||
/** @param <T>
|
/** @param <T>
|
||||||
* @param data
|
* @param data
|
||||||
* @param id
|
* @param id
|
||||||
* @param updateColomn
|
* @param filterValue
|
||||||
* @param option
|
|
||||||
* @return the affected rows.
|
* @return the affected rows.
|
||||||
* @throws Exception */
|
* @throws Exception */
|
||||||
public <T, ID_TYPE> long update(
|
public <T, ID_TYPE> long update(
|
||||||
@ -301,7 +300,8 @@ public abstract class DBAccess implements Closeable {
|
|||||||
|
|
||||||
/** Delete items with the specific condition and some options. If the Entity is manage as a softDeleted model, then it is flag as removed (if not already done before).
|
/** Delete items with the specific condition and some options. If the Entity is manage as a softDeleted model, then it is flag as removed (if not already done before).
|
||||||
* @param clazz Data model that might remove element.
|
* @param clazz Data model that might remove element.
|
||||||
* @param option (Optional) Options of the request.
|
* @param condition Condition to remove elements.
|
||||||
|
* @param options (Optional) Options of the request.
|
||||||
* @return Number of element that is removed. */
|
* @return Number of element that is removed. */
|
||||||
public long deleteWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
public long deleteWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
||||||
final String hasDeletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
final String hasDeletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
@ -14,26 +14,24 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.atriasoft.archidata.annotation.AnnotationTools;
|
|
||||||
import org.atriasoft.archidata.annotation.AnnotationTools.FieldName;
|
|
||||||
import org.atriasoft.archidata.annotation.CreationTimestamp;
|
|
||||||
import org.atriasoft.archidata.annotation.UpdateTimestamp;
|
|
||||||
import org.atriasoft.archidata.dataAccess.addOnMongo.AddOnManyToOne;
|
|
||||||
import org.atriasoft.archidata.dataAccess.addOnMongo.AddOnOneToMany;
|
|
||||||
import org.atriasoft.archidata.dataAccess.addOnMongo.DataAccessAddOn;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.CheckFunction;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.Condition;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.FilterValue;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.Limit;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.OptionSpecifyType;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.OrderBy;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.QueryOption;
|
|
||||||
import org.atriasoft.archidata.db.DbIoMorphia;
|
|
||||||
import org.atriasoft.archidata.exception.DataAccessException;
|
|
||||||
import org.atriasoft.archidata.tools.UuidUtils;
|
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.bson.conversions.Bson;
|
import org.bson.conversions.Bson;
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
|
import org.kar.archidata.annotation.CreationTimestamp;
|
||||||
|
import org.kar.archidata.annotation.UpdateTimestamp;
|
||||||
|
import org.kar.archidata.dataAccess.addOnMongo.AddOnManyToOne;
|
||||||
|
import org.kar.archidata.dataAccess.addOnMongo.AddOnOneToMany;
|
||||||
|
import org.kar.archidata.dataAccess.addOnMongo.DataAccessAddOn;
|
||||||
|
import org.kar.archidata.dataAccess.options.CheckFunction;
|
||||||
|
import org.kar.archidata.dataAccess.options.Condition;
|
||||||
|
import org.kar.archidata.dataAccess.options.FilterValue;
|
||||||
|
import org.kar.archidata.dataAccess.options.Limit;
|
||||||
|
import org.kar.archidata.dataAccess.options.OrderBy;
|
||||||
|
import org.kar.archidata.dataAccess.options.QueryOption;
|
||||||
|
import org.kar.archidata.db.DbIoMorphia;
|
||||||
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
|
import org.kar.archidata.tools.UuidUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -130,7 +128,7 @@ public class DBAccessMorphia extends DBAccess {
|
|||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> void setValueToDb(
|
protected <T> void setValuedb(
|
||||||
final Class<?> type,
|
final Class<?> type,
|
||||||
final T data,
|
final T data,
|
||||||
final Field field,
|
final Field field,
|
||||||
@ -138,9 +136,7 @@ public class DBAccessMorphia extends DBAccess {
|
|||||||
final Document docSet,
|
final Document docSet,
|
||||||
final Document docUnSet) throws Exception {
|
final Document docUnSet) throws Exception {
|
||||||
if (field.get(data) == null) {
|
if (field.get(data) == null) {
|
||||||
if (docUnSet != null) {
|
docUnSet.append(fieldName, "");
|
||||||
docUnSet.append(fieldName, "");
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (type == long.class) {
|
if (type == long.class) {
|
||||||
@ -155,7 +151,7 @@ public class DBAccessMorphia extends DBAccess {
|
|||||||
docSet.append(fieldName, field.getFloat(data));
|
docSet.append(fieldName, field.getFloat(data));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (type == double.class) {
|
if (type == Double.class) {
|
||||||
docSet.append(fieldName, field.getDouble(data));
|
docSet.append(fieldName, field.getDouble(data));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -200,40 +196,56 @@ public class DBAccessMorphia extends DBAccess {
|
|||||||
docSet.append(fieldName, tmp);
|
docSet.append(fieldName, tmp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (type == ObjectId.class) {
|
|
||||||
docSet.append(fieldName, tmp);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (type == UUID.class) {
|
if (type == UUID.class) {
|
||||||
docSet.append(fieldName, tmp);
|
docSet.append(fieldName, tmp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (type == Date.class) {
|
if (type == Date.class) {
|
||||||
|
// TODO ...
|
||||||
/*
|
/*
|
||||||
|
final Object tmp = field.get(data);
|
||||||
|
if (tmp == null) {
|
||||||
|
ps.setNull(iii.value, Types.INTEGER);
|
||||||
|
} else {
|
||||||
final Timestamp sqlDate = java.sql.Timestamp.from(((Date) tmp).toInstant());
|
final Timestamp sqlDate = java.sql.Timestamp.from(((Date) tmp).toInstant());
|
||||||
ps.setTimestamp(iii.value, sqlDate);
|
ps.setTimestamp(iii.value, sqlDate);
|
||||||
*/
|
}*/
|
||||||
}
|
}
|
||||||
if (type == Instant.class) {
|
if (type == Instant.class) {
|
||||||
/*
|
/*
|
||||||
|
final Object tmp = field.get(data);
|
||||||
|
if (tmp == null) {
|
||||||
|
ps.setNull(iii.value, Types.INTEGER);
|
||||||
|
} else {
|
||||||
final String sqlDate = ((Instant) tmp).toString();
|
final String sqlDate = ((Instant) tmp).toString();
|
||||||
ps.setString(iii.value, sqlDate);
|
ps.setString(iii.value, sqlDate);
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
if (type == LocalDate.class) {
|
if (type == LocalDate.class) {
|
||||||
/*
|
/*
|
||||||
|
final Object tmp = field.get(data);
|
||||||
|
if (tmp == null) {
|
||||||
|
ps.setNull(iii.value, Types.INTEGER);
|
||||||
|
} else {
|
||||||
final java.sql.Date sqlDate = java.sql.Date.valueOf((LocalDate) tmp);
|
final java.sql.Date sqlDate = java.sql.Date.valueOf((LocalDate) tmp);
|
||||||
ps.setDate(iii.value, sqlDate);
|
ps.setDate(iii.value, sqlDate);
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
if (type == LocalTime.class) {
|
if (type == LocalTime.class) {
|
||||||
/*
|
/*
|
||||||
|
final Object tmp = field.get(data);
|
||||||
|
if (tmp == null) {
|
||||||
|
ps.setNull(iii.value, Types.INTEGER);
|
||||||
|
} else {
|
||||||
final java.sql.Time sqlDate = java.sql.Time.valueOf((LocalTime) tmp);
|
final java.sql.Time sqlDate = java.sql.Time.valueOf((LocalTime) tmp);
|
||||||
ps.setTime(iii.value, sqlDate);
|
ps.setTime(iii.value, sqlDate);
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
docSet.append(fieldName, tmp);
|
throw new DataAccessException("Unknown Field Type");
|
||||||
//throw new DataAccessException("Unknown Field Type");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> void setValueFromDoc(
|
public <T> void setValueFromDoc(
|
||||||
@ -253,11 +265,6 @@ public class DBAccessMorphia extends DBAccess {
|
|||||||
field.set(data, value);
|
field.set(data, value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (type == ObjectId.class) {
|
|
||||||
final ObjectId value = doc.get(fieldName, ObjectId.class);
|
|
||||||
field.set(data, value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (type == Long.class || type == long.class) {
|
if (type == Long.class || type == long.class) {
|
||||||
final Long value = doc.getLong(fieldName);
|
final Long value = doc.getLong(fieldName);
|
||||||
field.set(data, value);
|
field.set(data, value);
|
||||||
@ -342,8 +349,8 @@ public class DBAccessMorphia extends DBAccess {
|
|||||||
final Object value = doc.get(fieldName, field.getType());
|
final Object value = doc.get(fieldName, field.getType());
|
||||||
field.set(data, value);
|
field.set(data, value);
|
||||||
} else {
|
} else {
|
||||||
final Object value = createObjectFromDocument(doc.get(fieldName, Document.class), field.getType(),
|
final Object value = createObjectFromDocument(doc.get(fieldName, Document.class), field.getType(), null,
|
||||||
new QueryOptions(), lazyCall);
|
lazyCall);
|
||||||
field.set(data, value);
|
field.set(data, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,45 +459,32 @@ public class DBAccessMorphia extends DBAccess {
|
|||||||
Object uniqueId = null;
|
Object uniqueId = null;
|
||||||
// real add in the BDD:
|
// real add in the BDD:
|
||||||
ObjectId insertedId = null;
|
ObjectId insertedId = null;
|
||||||
final List<OptionSpecifyType> specificTypes = options.get(OptionSpecifyType.class);
|
|
||||||
try {
|
try {
|
||||||
final MongoCollection<Document> collection = this.db.getDatastore().getDatabase()
|
final MongoCollection<Document> collection = this.db.getDatastore().getDatabase()
|
||||||
.getCollection(collectionName);
|
.getCollection(collectionName);
|
||||||
final Document docSet = new Document();
|
final Document doc = new Document();
|
||||||
final Document docUnSet = new Document();
|
|
||||||
for (final Field field : clazz.getFields()) {
|
for (final Field field : clazz.getFields()) {
|
||||||
// static field is only for internal global declaration ==> remove it ..
|
// static field is only for internal global declaration ==> remove it ..
|
||||||
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
|
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final FieldName tableFieldName = AnnotationTools.getFieldName(field, options);
|
final String tableFieldName = AnnotationTools.getFieldName(field, options).inTable();
|
||||||
Object currentInsertValue = field.get(data);
|
Object currentInsertValue = field.get(data);
|
||||||
if (AnnotationTools.isPrimaryKey(field)) {
|
if (AnnotationTools.isPrimaryKey(field)) {
|
||||||
primaryKeyField = field;
|
primaryKeyField = field;
|
||||||
if (primaryKeyField.getType() == UUID.class) {
|
if (primaryKeyField.getType() == UUID.class) {
|
||||||
final UUID uuid = UuidUtils.nextUUID();
|
final UUID uuid = UuidUtils.nextUUID();
|
||||||
uniqueId = uuid;
|
uniqueId = uuid;
|
||||||
docSet.append(tableFieldName.inTable(), uuid);
|
doc.append(tableFieldName, uuid);
|
||||||
continue;
|
continue;
|
||||||
} else if (primaryKeyField.getType() == Long.class || primaryKeyField.getType() == long.class) {
|
} else if (primaryKeyField.getType() == Long.class || primaryKeyField.getType() == long.class) {
|
||||||
// By default the MongoDB does not manage the
|
// By default the MongoDB does not manage the
|
||||||
final long id = getNextSequenceLongValue(collectionName, tableFieldName.inTable());
|
final long id = getNextSequenceLongValue(collectionName, tableFieldName);
|
||||||
uniqueId = id;
|
uniqueId = id;
|
||||||
docSet.append(tableFieldName.inTable(), id);
|
doc.append(tableFieldName, id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
LOGGER.error("TODO: Manage the ID primary key for type: {}=>{}", clazz.getCanonicalName(),
|
LOGGER.error("TODO: Manage the ID primary key for type: ");
|
||||||
primaryKeyField.getType());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final boolean createTime = field.getDeclaredAnnotationsByType(CreationTimestamp.class).length != 0;
|
|
||||||
if (createTime) {
|
|
||||||
docSet.append(tableFieldName.inTable(), Date.from(Instant.now()));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final boolean updateTime = field.getDeclaredAnnotationsByType(UpdateTimestamp.class).length != 0;
|
|
||||||
if (updateTime) {
|
|
||||||
docSet.append(tableFieldName.inTable(), Date.from(Instant.now()));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final DataAccessAddOn addOn = findAddOnforField(field);
|
final DataAccessAddOn addOn = findAddOnforField(field);
|
||||||
@ -501,8 +495,19 @@ public class DBAccessMorphia extends DBAccess {
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
final boolean createTime = field.getDeclaredAnnotationsByType(CreationTimestamp.class).length != 0;
|
||||||
|
if (createTime) {
|
||||||
|
doc.append(tableFieldName, Date.from(Instant.now()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final boolean updateTime = field.getDeclaredAnnotationsByType(UpdateTimestamp.class).length != 0;
|
||||||
|
if (updateTime) {
|
||||||
|
doc.append(tableFieldName, Date.from(Instant.now()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (currentInsertValue == null && !field.getClass().isPrimitive()) {
|
if (currentInsertValue == null && !field.getClass().isPrimitive()) {
|
||||||
final DefaultValue[] defaultValue = field.getDeclaredAnnotationsByType(DefaultValue.class);
|
final DefaultValue[] defaultValue = field.getDeclaredAnnotationsByType(DefaultValue.class);
|
||||||
|
LOGGER.error("TODO: convert default value in the correct value for the DB...");
|
||||||
if (defaultValue.length == 0) {
|
if (defaultValue.length == 0) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
@ -513,24 +518,9 @@ public class DBAccessMorphia extends DBAccess {
|
|||||||
currentInsertValue = convertDefaultField(value, field);
|
currentInsertValue = convertDefaultField(value, field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// conversion table ...
|
doc.append(tableFieldName, currentInsertValue);
|
||||||
//doc.append(tableFieldName, currentInsertValue);
|
|
||||||
if (addOn != null) {
|
|
||||||
addOn.insertData(this, field, data, options, docSet, docUnSet);
|
|
||||||
} else {
|
|
||||||
final Class<?> type = field.getType();
|
|
||||||
if (!type.isPrimitive()) {
|
|
||||||
if (field.get(data) == null) {
|
|
||||||
if (currentInsertValue != null) {
|
|
||||||
docSet.append(tableFieldName.inTable(), currentInsertValue);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setValueToDb(type, data, field, tableFieldName.inTable(), docSet, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
final InsertOneResult result = collection.insertOne(docSet);
|
final InsertOneResult result = collection.insertOne(doc);
|
||||||
// Get the Object of inserted object:
|
// Get the Object of inserted object:
|
||||||
insertedId = result.getInsertedId().asObjectId().getValue();
|
insertedId = result.getInsertedId().asObjectId().getValue();
|
||||||
LOGGER.info("Document inserted with ID: " + insertedId);
|
LOGGER.info("Document inserted with ID: " + insertedId);
|
||||||
@ -597,14 +587,14 @@ public class DBAccessMorphia extends DBAccess {
|
|||||||
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
|
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final FieldName fieldName = AnnotationTools.getFieldName(field, options);
|
final String fieldName = AnnotationTools.getFieldName(field, options).inTable();
|
||||||
// update field is not conditioned by filter:
|
// update field is not conditioned by filter:
|
||||||
final boolean updateTime = field.getDeclaredAnnotationsByType(UpdateTimestamp.class).length != 0;
|
final boolean updateTime = field.getDeclaredAnnotationsByType(UpdateTimestamp.class).length != 0;
|
||||||
if (updateTime) {
|
if (updateTime) {
|
||||||
docSet.append(fieldName.inTable(), Date.from(Instant.now()));
|
docSet.append(fieldName, Date.from(Instant.now()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!filterKey.getValues().contains(fieldName.inStruct())) {
|
if (!filterKey.getValues().contains(fieldName)) {
|
||||||
continue;
|
continue;
|
||||||
} else if (AnnotationTools.isGenericField(field)) {
|
} else if (AnnotationTools.isGenericField(field)) {
|
||||||
continue;
|
continue;
|
||||||
@ -634,10 +624,12 @@ public class DBAccessMorphia extends DBAccess {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setValueToDb(type, data, field, fieldName.inTable(), docSet, docUnSet);
|
setValuedb(type, data, field, fieldName, docSet, docUnSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// Do the query ...
|
// Do the query ...
|
||||||
|
|
||||||
final MongoCollection<Document> collection = this.db.getDatastore().getDatabase()
|
final MongoCollection<Document> collection = this.db.getDatastore().getDatabase()
|
||||||
.getCollection(collectionName);
|
.getCollection(collectionName);
|
||||||
final Document actions = new Document();
|
final Document actions = new Document();
|
||||||
@ -660,6 +652,7 @@ public class DBAccessMorphia extends DBAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<String> generateSelectField(final Class<?> clazz, final QueryOptions options) throws Exception {
|
public List<String> generateSelectField(final Class<?> clazz, final QueryOptions options) throws Exception {
|
||||||
|
// TODO: list of user select fields.
|
||||||
final boolean readAllfields = QueryOptions.readAllColomn(options);
|
final boolean readAllfields = QueryOptions.readAllColomn(options);
|
||||||
final List<String> fieldsName = new ArrayList<>();
|
final List<String> fieldsName = new ArrayList<>();
|
||||||
|
|
||||||
@ -783,8 +776,6 @@ public class DBAccessMorphia extends DBAccess {
|
|||||||
final Class<?> clazz,
|
final Class<?> clazz,
|
||||||
final QueryOptions options,
|
final QueryOptions options,
|
||||||
final List<LazyGetter> lazyCall) throws Exception {
|
final List<LazyGetter> lazyCall) throws Exception {
|
||||||
final List<OptionSpecifyType> specificTypes = options.get(OptionSpecifyType.class);
|
|
||||||
LOGGER.info("createObjectFromDocument: {}", clazz.getCanonicalName());
|
|
||||||
final boolean readAllfields = QueryOptions.readAllColomn(options);
|
final boolean readAllfields = QueryOptions.readAllColomn(options);
|
||||||
// TODO: manage class that is defined inside a class ==> Not manage for now...
|
// TODO: manage class that is defined inside a class ==> Not manage for now...
|
||||||
Object data = null;
|
Object data = null;
|
||||||
@ -799,37 +790,23 @@ public class DBAccessMorphia extends DBAccess {
|
|||||||
"Can not find the default constructor for the class: " + clazz.getCanonicalName());
|
"Can not find the default constructor for the class: " + clazz.getCanonicalName());
|
||||||
}
|
}
|
||||||
for (final Field elem : clazz.getFields()) {
|
for (final Field elem : clazz.getFields()) {
|
||||||
LOGGER.info(" Inspect field: name='{}' type='{}'", elem.getName(), elem.getType().getCanonicalName());
|
|
||||||
// static field is only for internal global declaration ==> remove it ..
|
// static field is only for internal global declaration ==> remove it ..
|
||||||
if (java.lang.reflect.Modifier.isStatic(elem.getModifiers())) {
|
if (java.lang.reflect.Modifier.isStatic(elem.getModifiers())) {
|
||||||
LOGGER.info(" ==> static");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final DataAccessAddOn addOn = findAddOnforField(elem);
|
final DataAccessAddOn addOn = findAddOnforField(elem);
|
||||||
if (addOn != null && !addOn.canRetrieve(elem)) {
|
if (addOn != null && !addOn.canRetrieve(elem)) {
|
||||||
LOGGER.info(" ==> Can not retreive this field");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final boolean notRead = AnnotationTools.isDefaultNotRead(elem);
|
final boolean notRead = AnnotationTools.isDefaultNotRead(elem);
|
||||||
if (!readAllfields && notRead) {
|
if (!readAllfields && notRead) {
|
||||||
LOGGER.info(" ==> Not read this element");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (addOn != null) {
|
if (addOn != null) {
|
||||||
|
LOGGER.error("TODO: Add on not managed .6. ");
|
||||||
addOn.fillFromDoc(this, doc, elem, data, options, lazyCall);
|
addOn.fillFromDoc(this, doc, elem, data, options, lazyCall);
|
||||||
} else {
|
} else {
|
||||||
Class<?> type = elem.getType();
|
setValueFromDoc(elem.getType(), data, elem, doc, lazyCall, options);
|
||||||
if (type == Object.class) {
|
|
||||||
for (final OptionSpecifyType specify : specificTypes) {
|
|
||||||
if (specify.name.equals(elem.getName())) {
|
|
||||||
type = specify.clazz;
|
|
||||||
LOGGER.info("Detect overwrite of typing var={} ... '{}' => '{}'", elem.getName(),
|
|
||||||
elem.getType().getCanonicalName(), specify.clazz.getCanonicalName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setValueFromDoc(type, data, elem, doc, lazyCall, options);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
@ -14,43 +14,37 @@ import java.sql.Types;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZoneOffset;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.atriasoft.archidata.annotation.AnnotationTools;
|
|
||||||
import org.atriasoft.archidata.annotation.AnnotationTools.FieldName;
|
|
||||||
import org.atriasoft.archidata.annotation.CreationTimestamp;
|
|
||||||
import org.atriasoft.archidata.annotation.UpdateTimestamp;
|
|
||||||
import org.atriasoft.archidata.dataAccess.addOnSQL.AddOnDataJson;
|
|
||||||
import org.atriasoft.archidata.dataAccess.addOnSQL.AddOnManyToMany;
|
|
||||||
import org.atriasoft.archidata.dataAccess.addOnSQL.AddOnManyToManyLocal;
|
|
||||||
import org.atriasoft.archidata.dataAccess.addOnSQL.AddOnManyToOne;
|
|
||||||
import org.atriasoft.archidata.dataAccess.addOnSQL.AddOnOneToMany;
|
|
||||||
import org.atriasoft.archidata.dataAccess.addOnSQL.DataAccessAddOn;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.AccessDeletedItems;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.CheckFunction;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.Condition;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.DBInterfaceRoot;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.FilterValue;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.GroupBy;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.Limit;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.OptionSpecifyType;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.OrderBy;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.QueryOption;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.ReadAllColumn;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.TransmitKey;
|
|
||||||
import org.atriasoft.archidata.db.DbIoSql;
|
|
||||||
import org.atriasoft.archidata.exception.DataAccessException;
|
|
||||||
import org.atriasoft.archidata.tools.ConfigBaseVariable;
|
|
||||||
import org.atriasoft.archidata.tools.DateTools;
|
|
||||||
import org.atriasoft.archidata.tools.UuidUtils;
|
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
|
import org.kar.archidata.annotation.AnnotationTools.FieldName;
|
||||||
|
import org.kar.archidata.annotation.CreationTimestamp;
|
||||||
|
import org.kar.archidata.annotation.UpdateTimestamp;
|
||||||
|
import org.kar.archidata.dataAccess.addOnSQL.AddOnDataJson;
|
||||||
|
import org.kar.archidata.dataAccess.addOnSQL.AddOnManyToMany;
|
||||||
|
import org.kar.archidata.dataAccess.addOnSQL.AddOnManyToOne;
|
||||||
|
import org.kar.archidata.dataAccess.addOnSQL.AddOnOneToMany;
|
||||||
|
import org.kar.archidata.dataAccess.addOnSQL.DataAccessAddOn;
|
||||||
|
import org.kar.archidata.dataAccess.options.CheckFunction;
|
||||||
|
import org.kar.archidata.dataAccess.options.Condition;
|
||||||
|
import org.kar.archidata.dataAccess.options.DBInterfaceRoot;
|
||||||
|
import org.kar.archidata.dataAccess.options.FilterValue;
|
||||||
|
import org.kar.archidata.dataAccess.options.GroupBy;
|
||||||
|
import org.kar.archidata.dataAccess.options.Limit;
|
||||||
|
import org.kar.archidata.dataAccess.options.OptionSpecifyType;
|
||||||
|
import org.kar.archidata.dataAccess.options.OrderBy;
|
||||||
|
import org.kar.archidata.dataAccess.options.QueryOption;
|
||||||
|
import org.kar.archidata.dataAccess.options.TransmitKey;
|
||||||
|
import org.kar.archidata.db.DbIoSql;
|
||||||
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
|
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||||
|
import org.kar.archidata.tools.DateTools;
|
||||||
|
import org.kar.archidata.tools.UuidUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -67,12 +61,8 @@ import jakarta.ws.rs.InternalServerErrorException;
|
|||||||
public class DBAccessSQL extends DBAccess {
|
public class DBAccessSQL extends DBAccess {
|
||||||
final static Logger LOGGER = LoggerFactory.getLogger(DBAccessSQL.class);
|
final static Logger LOGGER = LoggerFactory.getLogger(DBAccessSQL.class);
|
||||||
// by default we manage some add-on that permit to manage non-native model (like json serialization, List of external key as String list...)
|
// by default we manage some add-on that permit to manage non-native model (like json serialization, List of external key as String list...)
|
||||||
final static List<DataAccessAddOn> addOn = List.of(//
|
final static List<DataAccessAddOn> addOn = List.of(new AddOnManyToMany(), new AddOnManyToOne(),
|
||||||
new AddOnManyToMany(), //
|
new AddOnOneToMany(), new AddOnDataJson());
|
||||||
new AddOnManyToOne(), //
|
|
||||||
new AddOnOneToMany(), //
|
|
||||||
new AddOnDataJson(), //
|
|
||||||
new AddOnManyToManyLocal());
|
|
||||||
|
|
||||||
private final DbIoSql db;
|
private final DbIoSql db;
|
||||||
|
|
||||||
@ -288,81 +278,8 @@ public class DBAccessSQL extends DBAccess {
|
|||||||
final CountInOut iii,
|
final CountInOut iii,
|
||||||
final Field field,
|
final Field field,
|
||||||
final PreparedStatement ps) throws Exception {
|
final PreparedStatement ps) throws Exception {
|
||||||
if (type == long.class) {
|
if (type == ObjectId.class) {
|
||||||
ps.setLong(iii.value, field.getLong(data));
|
final Object tmp = field.get(data);
|
||||||
iii.inc();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (type == int.class) {
|
|
||||||
ps.setInt(iii.value, field.getInt(data));
|
|
||||||
iii.inc();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (type == float.class) {
|
|
||||||
ps.setFloat(iii.value, field.getFloat(data));
|
|
||||||
iii.inc();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (type == double.class) {
|
|
||||||
ps.setDouble(iii.value, field.getDouble(data));
|
|
||||||
iii.inc();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (type == boolean.class) {
|
|
||||||
ps.setBoolean(iii.value, field.getBoolean(data));
|
|
||||||
iii.inc();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Object tmp = field.get(data);
|
|
||||||
if (type.isEnum()) {
|
|
||||||
if (tmp == null) {
|
|
||||||
ps.setNull(iii.value, Types.VARCHAR);
|
|
||||||
} else {
|
|
||||||
ps.setString(iii.value, tmp.toString());
|
|
||||||
}
|
|
||||||
} else if (type == Long.class) {
|
|
||||||
if (tmp == null) {
|
|
||||||
ps.setNull(iii.value, Types.BIGINT);
|
|
||||||
} else {
|
|
||||||
ps.setLong(iii.value, (Long) tmp);
|
|
||||||
}
|
|
||||||
} else if (type == Integer.class) {
|
|
||||||
if (tmp == null) {
|
|
||||||
ps.setNull(iii.value, Types.INTEGER);
|
|
||||||
} else {
|
|
||||||
ps.setInt(iii.value, (Integer) tmp);
|
|
||||||
}
|
|
||||||
} else if (type == Float.class) {
|
|
||||||
if (tmp == null) {
|
|
||||||
ps.setNull(iii.value, Types.FLOAT);
|
|
||||||
} else {
|
|
||||||
ps.setFloat(iii.value, (Float) tmp);
|
|
||||||
}
|
|
||||||
} else if (type == Double.class) {
|
|
||||||
if (tmp == null) {
|
|
||||||
ps.setNull(iii.value, Types.DOUBLE);
|
|
||||||
} else {
|
|
||||||
ps.setDouble(iii.value, (Double) tmp);
|
|
||||||
}
|
|
||||||
} else if (type == Boolean.class) {
|
|
||||||
if (tmp == null) {
|
|
||||||
ps.setNull(iii.value, Types.INTEGER);
|
|
||||||
} else {
|
|
||||||
ps.setBoolean(iii.value, (Boolean) tmp);
|
|
||||||
}
|
|
||||||
} else if (type == String.class) {
|
|
||||||
if (tmp == null) {
|
|
||||||
ps.setNull(iii.value, Types.VARCHAR);
|
|
||||||
} else {
|
|
||||||
ps.setString(iii.value, (String) tmp);
|
|
||||||
}
|
|
||||||
} else if (type == Timestamp.class) {
|
|
||||||
if (tmp == null) {
|
|
||||||
ps.setNull(iii.value, Types.INTEGER);
|
|
||||||
} else {
|
|
||||||
ps.setTimestamp(iii.value, (Timestamp) tmp);
|
|
||||||
}
|
|
||||||
} else if (type == ObjectId.class) {
|
|
||||||
if (tmp == null) {
|
if (tmp == null) {
|
||||||
ps.setNull(iii.value, Types.BINARY);
|
ps.setNull(iii.value, Types.BINARY);
|
||||||
} else {
|
} else {
|
||||||
@ -370,31 +287,75 @@ public class DBAccessSQL extends DBAccess {
|
|||||||
ps.setBytes(iii.value, dataByte);
|
ps.setBytes(iii.value, dataByte);
|
||||||
}
|
}
|
||||||
} else if (type == UUID.class) {
|
} else if (type == UUID.class) {
|
||||||
|
final Object tmp = field.get(data);
|
||||||
if (tmp == null) {
|
if (tmp == null) {
|
||||||
ps.setNull(iii.value, Types.BINARY);
|
ps.setNull(iii.value, Types.BINARY);
|
||||||
} else {
|
} else {
|
||||||
final byte[] dataByte = UuidUtils.asBytes((UUID) tmp);
|
final byte[] dataByte = UuidUtils.asBytes((UUID) tmp);
|
||||||
ps.setBytes(iii.value, dataByte);
|
ps.setBytes(iii.value, dataByte);
|
||||||
}
|
}
|
||||||
} else if (type == Date.class) {
|
} else if (type == Long.class) {
|
||||||
|
final Object tmp = field.get(data);
|
||||||
if (tmp == null) {
|
if (tmp == null) {
|
||||||
ps.setNull(iii.value, Types.INTEGER);
|
ps.setNull(iii.value, Types.BIGINT);
|
||||||
} else {
|
} else {
|
||||||
final OffsetDateTime offsetDateTime = ((Date) tmp).toInstant().atZone(ZoneId.systemDefault())
|
ps.setLong(iii.value, (Long) tmp);
|
||||||
.toOffsetDateTime();
|
|
||||||
final Timestamp sqlDate = java.sql.Timestamp
|
|
||||||
.from(offsetDateTime.withOffsetSameInstant(ZoneOffset.UTC).toInstant());
|
|
||||||
ps.setTimestamp(iii.value, sqlDate);
|
|
||||||
}
|
}
|
||||||
} else if (type == OffsetDateTime.class) {
|
} else if (type == long.class) {
|
||||||
|
ps.setLong(iii.value, field.getLong(data));
|
||||||
|
} else if (type == Integer.class) {
|
||||||
|
final Object tmp = field.get(data);
|
||||||
if (tmp == null) {
|
if (tmp == null) {
|
||||||
ps.setNull(iii.value, Types.INTEGER);
|
ps.setNull(iii.value, Types.INTEGER);
|
||||||
} else {
|
} else {
|
||||||
final Timestamp sqlDate = java.sql.Timestamp
|
ps.setInt(iii.value, (Integer) tmp);
|
||||||
.from(((OffsetDateTime) tmp).withOffsetSameInstant(ZoneOffset.UTC).toInstant());
|
}
|
||||||
|
} else if (type == int.class) {
|
||||||
|
ps.setInt(iii.value, field.getInt(data));
|
||||||
|
} else if (type == Float.class) {
|
||||||
|
final Object tmp = field.get(data);
|
||||||
|
if (tmp == null) {
|
||||||
|
ps.setNull(iii.value, Types.FLOAT);
|
||||||
|
} else {
|
||||||
|
ps.setFloat(iii.value, (Float) tmp);
|
||||||
|
}
|
||||||
|
} else if (type == float.class) {
|
||||||
|
ps.setFloat(iii.value, field.getFloat(data));
|
||||||
|
} else if (type == Double.class) {
|
||||||
|
final Object tmp = field.get(data);
|
||||||
|
if (tmp == null) {
|
||||||
|
ps.setNull(iii.value, Types.DOUBLE);
|
||||||
|
} else {
|
||||||
|
ps.setDouble(iii.value, (Double) tmp);
|
||||||
|
}
|
||||||
|
} else if (type == Double.class) {
|
||||||
|
ps.setDouble(iii.value, field.getDouble(data));
|
||||||
|
} else if (type == Boolean.class) {
|
||||||
|
final Object tmp = field.get(data);
|
||||||
|
if (tmp == null) {
|
||||||
|
ps.setNull(iii.value, Types.INTEGER);
|
||||||
|
} else {
|
||||||
|
ps.setBoolean(iii.value, (Boolean) tmp);
|
||||||
|
}
|
||||||
|
} else if (type == boolean.class) {
|
||||||
|
ps.setBoolean(iii.value, field.getBoolean(data));
|
||||||
|
} else if (type == Timestamp.class) {
|
||||||
|
final Object tmp = field.get(data);
|
||||||
|
if (tmp == null) {
|
||||||
|
ps.setNull(iii.value, Types.INTEGER);
|
||||||
|
} else {
|
||||||
|
ps.setTimestamp(iii.value, (Timestamp) tmp);
|
||||||
|
}
|
||||||
|
} else if (type == Date.class) {
|
||||||
|
final Object tmp = field.get(data);
|
||||||
|
if (tmp == null) {
|
||||||
|
ps.setNull(iii.value, Types.INTEGER);
|
||||||
|
} else {
|
||||||
|
final Timestamp sqlDate = java.sql.Timestamp.from(((Date) tmp).toInstant());
|
||||||
ps.setTimestamp(iii.value, sqlDate);
|
ps.setTimestamp(iii.value, sqlDate);
|
||||||
}
|
}
|
||||||
} else if (type == Instant.class) {
|
} else if (type == Instant.class) {
|
||||||
|
final Object tmp = field.get(data);
|
||||||
if (tmp == null) {
|
if (tmp == null) {
|
||||||
ps.setNull(iii.value, Types.INTEGER);
|
ps.setNull(iii.value, Types.INTEGER);
|
||||||
} else {
|
} else {
|
||||||
@ -402,6 +363,7 @@ public class DBAccessSQL extends DBAccess {
|
|||||||
ps.setString(iii.value, sqlDate);
|
ps.setString(iii.value, sqlDate);
|
||||||
}
|
}
|
||||||
} else if (type == LocalDate.class) {
|
} else if (type == LocalDate.class) {
|
||||||
|
final Object tmp = field.get(data);
|
||||||
if (tmp == null) {
|
if (tmp == null) {
|
||||||
ps.setNull(iii.value, Types.INTEGER);
|
ps.setNull(iii.value, Types.INTEGER);
|
||||||
} else {
|
} else {
|
||||||
@ -409,12 +371,27 @@ public class DBAccessSQL extends DBAccess {
|
|||||||
ps.setDate(iii.value, sqlDate);
|
ps.setDate(iii.value, sqlDate);
|
||||||
}
|
}
|
||||||
} else if (type == LocalTime.class) {
|
} else if (type == LocalTime.class) {
|
||||||
|
final Object tmp = field.get(data);
|
||||||
if (tmp == null) {
|
if (tmp == null) {
|
||||||
ps.setNull(iii.value, Types.INTEGER);
|
ps.setNull(iii.value, Types.INTEGER);
|
||||||
} else {
|
} else {
|
||||||
final java.sql.Time sqlDate = java.sql.Time.valueOf((LocalTime) tmp);
|
final java.sql.Time sqlDate = java.sql.Time.valueOf((LocalTime) tmp);
|
||||||
ps.setTime(iii.value, sqlDate);
|
ps.setTime(iii.value, sqlDate);
|
||||||
}
|
}
|
||||||
|
} else if (type == String.class) {
|
||||||
|
final Object tmp = field.get(data);
|
||||||
|
if (tmp == null) {
|
||||||
|
ps.setNull(iii.value, Types.VARCHAR);
|
||||||
|
} else {
|
||||||
|
ps.setString(iii.value, (String) tmp);
|
||||||
|
}
|
||||||
|
} else if (type.isEnum()) {
|
||||||
|
final Object tmp = field.get(data);
|
||||||
|
if (tmp == null) {
|
||||||
|
ps.setNull(iii.value, Types.VARCHAR);
|
||||||
|
} else {
|
||||||
|
ps.setString(iii.value, tmp.toString());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new DataAccessException("Unknown Field Type: " + type.getCanonicalName());
|
throw new DataAccessException("Unknown Field Type: " + type.getCanonicalName());
|
||||||
}
|
}
|
||||||
@ -543,9 +520,7 @@ public class DBAccessSQL extends DBAccess {
|
|||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
field.set(data, null);
|
field.set(data, null);
|
||||||
} else {
|
} else {
|
||||||
final OffsetDateTime odt = tmp.toInstant().atOffset(ZoneOffset.UTC);
|
field.set(data, Date.from(tmp.toInstant()));
|
||||||
odt.atZoneSameInstant(ZoneId.systemDefault());
|
|
||||||
field.set(data, Date.from(odt.toInstant()));
|
|
||||||
countNotNull.inc();
|
countNotNull.inc();
|
||||||
}
|
}
|
||||||
} catch (final SQLException ex) {
|
} catch (final SQLException ex) {
|
||||||
@ -560,28 +535,6 @@ public class DBAccessSQL extends DBAccess {
|
|||||||
countNotNull.inc();
|
countNotNull.inc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (type == OffsetDateTime.class) {
|
|
||||||
try {
|
|
||||||
final Timestamp tmp = rs.getTimestamp(count.value);
|
|
||||||
if (rs.wasNull()) {
|
|
||||||
field.set(data, null);
|
|
||||||
} else {
|
|
||||||
final OffsetDateTime odt = tmp.toInstant().atOffset(ZoneOffset.UTC);
|
|
||||||
field.set(data, odt);
|
|
||||||
countNotNull.inc();
|
|
||||||
}
|
|
||||||
} catch (final SQLException ex) {
|
|
||||||
final String tmp = rs.getString(count.value);
|
|
||||||
LOGGER.error("Fail to parse the SQL time !!! {}", tmp);
|
|
||||||
if (rs.wasNull()) {
|
|
||||||
field.set(data, null);
|
|
||||||
} else {
|
|
||||||
final OffsetDateTime date = DateTools.parseOffsetDateTime(tmp);
|
|
||||||
LOGGER.error("Fail to parse the SQL time !!! {}", date);
|
|
||||||
field.set(data, date);
|
|
||||||
countNotNull.inc();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (type == Instant.class) {
|
} else if (type == Instant.class) {
|
||||||
final String tmp = rs.getString(count.value);
|
final String tmp = rs.getString(count.value);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
@ -948,13 +901,11 @@ public class DBAccessSQL extends DBAccess {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final DataAccessAddOn addOn = findAddOnforField(field);
|
final DataAccessAddOn addOn = findAddOnforField(field);
|
||||||
if (addOn != null) {
|
if (addOn != null && !addOn.canInsert(field)) {
|
||||||
if (addOn.isInsertAsync(field)) {
|
if (addOn.isInsertAsync(field)) {
|
||||||
asyncFieldUpdate.add(field);
|
asyncFieldUpdate.add(field);
|
||||||
}
|
}
|
||||||
if (!addOn.canInsert(field)) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
final boolean createTime = field.getDeclaredAnnotationsByType(CreationTimestamp.class).length != 0;
|
final boolean createTime = field.getDeclaredAnnotationsByType(CreationTimestamp.class).length != 0;
|
||||||
if (createTime) {
|
if (createTime) {
|
||||||
@ -1166,31 +1117,6 @@ public class DBAccessSQL extends DBAccess {
|
|||||||
query.append("UPDATE `");
|
query.append("UPDATE `");
|
||||||
query.append(tableName);
|
query.append(tableName);
|
||||||
query.append("` SET ");
|
query.append("` SET ");
|
||||||
//Some mode need to get the previous data to perform a correct update...
|
|
||||||
boolean needPreviousValues = false;
|
|
||||||
for (final Field field : clazz.getFields()) {
|
|
||||||
// field is only for internal global declaration ==> remove it ..
|
|
||||||
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final FieldName name = AnnotationTools.getFieldName(field, options);
|
|
||||||
if (!filter.getValues().contains(name.inStruct())) {
|
|
||||||
continue;
|
|
||||||
} else if (AnnotationTools.isGenericField(field)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final DataAccessAddOn addOn = findAddOnforField(field);
|
|
||||||
if (addOn != null && addOn.isPreviousDataNeeded(field)) {
|
|
||||||
needPreviousValues = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Object previousData = null;
|
|
||||||
if (needPreviousValues) {
|
|
||||||
final List<TransmitKey> transmitKey = options.get(TransmitKey.class);
|
|
||||||
previousData = this.get(data.getClass(), transmitKey.get(0).getKey(), new AccessDeletedItems(),
|
|
||||||
new ReadAllColumn());
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean firstField = true;
|
boolean firstField = true;
|
||||||
for (final Field field : clazz.getFields()) {
|
for (final Field field : clazz.getFields()) {
|
||||||
@ -1205,19 +1131,17 @@ public class DBAccessSQL extends DBAccess {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final DataAccessAddOn addOn = findAddOnforField(field);
|
final DataAccessAddOn addOn = findAddOnforField(field);
|
||||||
if (addOn != null) {
|
if (addOn != null && !addOn.canInsert(field)) {
|
||||||
if (addOn.isUpdateAsync(field)) {
|
if (addOn.isInsertAsync(field)) {
|
||||||
final List<TransmitKey> transmitKey = options.get(TransmitKey.class);
|
final List<TransmitKey> transmitKey = options.get(TransmitKey.class);
|
||||||
if (transmitKey.size() != 1) {
|
if (transmitKey.size() != 1) {
|
||||||
throw new DataAccessException(
|
throw new DataAccessException(
|
||||||
"Fail to transmit Key to update the async update... (must have only 1)");
|
"Fail to transmit Key to update the async update... (must have only 1)");
|
||||||
}
|
}
|
||||||
addOn.asyncUpdate(this, previousData, tableName, transmitKey.get(0).getKey(), field,
|
addOn.asyncUpdate(this, tableName, transmitKey.get(0).getKey(), field, field.get(data),
|
||||||
field.get(data), asyncActions, options);
|
asyncActions, options);
|
||||||
}
|
|
||||||
if (!addOn.canInsert(field)) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (!field.getClass().isPrimitive()) {
|
if (!field.getClass().isPrimitive()) {
|
||||||
final Object tmp = field.get(data);
|
final Object tmp = field.get(data);
|
||||||
@ -1242,6 +1166,7 @@ public class DBAccessSQL extends DBAccess {
|
|||||||
query.append(" ");
|
query.append(" ");
|
||||||
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||||
condition.whereAppendQuery(query, tableName, null, deletedFieldName);
|
condition.whereAppendQuery(query, tableName, null, deletedFieldName);
|
||||||
|
|
||||||
// If the first field is not set, then nothing to update n the main base:
|
// If the first field is not set, then nothing to update n the main base:
|
||||||
if (!firstField) {
|
if (!firstField) {
|
||||||
LOGGER.debug("generate update query: '{}'", query.toString());
|
LOGGER.debug("generate update query: '{}'", query.toString());
|
||||||
@ -1277,9 +1202,6 @@ public class DBAccessSQL extends DBAccess {
|
|||||||
addOn.insertData(this, ps, field, data, iii);
|
addOn.insertData(this, ps, field, data, iii);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final LazyGetter action : asyncActions) {
|
|
||||||
action.doRequest();
|
|
||||||
}
|
|
||||||
condition.injectQuery(this, ps, iii);
|
condition.injectQuery(this, ps, iii);
|
||||||
final int out = ps.executeUpdate();
|
final int out = ps.executeUpdate();
|
||||||
return out;
|
return out;
|
||||||
@ -1288,6 +1210,9 @@ public class DBAccessSQL extends DBAccess {
|
|||||||
} catch (final SQLException ex) {
|
} catch (final SQLException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
for (final LazyGetter action : asyncActions) {
|
||||||
|
action.doRequest();
|
||||||
|
}
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1458,7 +1383,7 @@ public class DBAccessSQL extends DBAccess {
|
|||||||
final T out = (T) data;
|
final T out = (T) data;
|
||||||
outs.add(out);
|
outs.add(out);
|
||||||
}
|
}
|
||||||
LOGGER.trace("Async calls: {}", lazyCall.size());
|
LOGGER.info("Async calls: {}", lazyCall.size());
|
||||||
for (final LazyGetter elem : lazyCall) {
|
for (final LazyGetter elem : lazyCall) {
|
||||||
elem.doRequest();
|
elem.doRequest();
|
||||||
}
|
}
|
@ -1,11 +1,11 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.Condition;
|
import org.kar.archidata.dataAccess.options.Condition;
|
||||||
import org.atriasoft.archidata.dataAccess.options.QueryOption;
|
import org.kar.archidata.dataAccess.options.QueryOption;
|
||||||
import org.atriasoft.archidata.exception.DataAccessException;
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -111,6 +111,12 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param <T>
|
||||||
|
* @param data
|
||||||
|
* @param id
|
||||||
|
* @param filterValue
|
||||||
|
* @return the affected rows.
|
||||||
|
* @throws Exception */
|
||||||
public static <T, ID_TYPE> long update(
|
public static <T, ID_TYPE> long update(
|
||||||
final T data,
|
final T data,
|
||||||
final ID_TYPE id,
|
final ID_TYPE id,
|
||||||
@ -219,6 +225,7 @@ public class DataAccess {
|
|||||||
|
|
||||||
/** Delete items with the specific condition and some options. If the Entity is manage as a softDeleted model, then it is flag as removed (if not already done before).
|
/** Delete items with the specific condition and some options. If the Entity is manage as a softDeleted model, then it is flag as removed (if not already done before).
|
||||||
* @param clazz Data model that might remove element.
|
* @param clazz Data model that might remove element.
|
||||||
|
* @param condition Condition to remove elements.
|
||||||
* @param options (Optional) Options of the request.
|
* @param options (Optional) Options of the request.
|
||||||
* @return Number of element that is removed. */
|
* @return Number of element that is removed. */
|
||||||
public static long deleteWhere(final Class<?> clazz, final QueryOption... options) throws Exception {
|
public static long deleteWhere(final Class<?> clazz, final QueryOption... options) throws Exception {
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -16,16 +16,16 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.atriasoft.archidata.dataAccess.exportTools.TableQuery;
|
import org.kar.archidata.dataAccess.exportTools.TableQuery;
|
||||||
import org.atriasoft.archidata.dataAccess.exportTools.TableQueryTypes;
|
import org.kar.archidata.dataAccess.exportTools.TableQueryTypes;
|
||||||
import org.atriasoft.archidata.dataAccess.options.Condition;
|
import org.kar.archidata.dataAccess.options.Condition;
|
||||||
import org.atriasoft.archidata.dataAccess.options.GroupBy;
|
import org.kar.archidata.dataAccess.options.GroupBy;
|
||||||
import org.atriasoft.archidata.dataAccess.options.Limit;
|
import org.kar.archidata.dataAccess.options.Limit;
|
||||||
import org.atriasoft.archidata.dataAccess.options.OrderBy;
|
import org.kar.archidata.dataAccess.options.OrderBy;
|
||||||
import org.atriasoft.archidata.dataAccess.options.QueryOption;
|
import org.kar.archidata.dataAccess.options.QueryOption;
|
||||||
import org.atriasoft.archidata.exception.DataAccessException;
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
import org.atriasoft.archidata.tools.ContextGenericTools;
|
import org.kar.archidata.tools.ContextGenericTools;
|
||||||
import org.atriasoft.archidata.tools.DateTools;
|
import org.kar.archidata.tools.DateTools;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
@ -10,16 +10,16 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.atriasoft.archidata.annotation.AnnotationTools;
|
|
||||||
import org.atriasoft.archidata.annotation.CreationTimestamp;
|
|
||||||
import org.atriasoft.archidata.annotation.DataIfNotExists;
|
|
||||||
import org.atriasoft.archidata.annotation.UpdateTimestamp;
|
|
||||||
import org.atriasoft.archidata.dataAccess.addOnSQL.DataAccessAddOn;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.CreateDropTable;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.OptionSpecifyType;
|
|
||||||
import org.atriasoft.archidata.exception.DataAccessException;
|
|
||||||
import org.atriasoft.archidata.tools.ConfigBaseVariable;
|
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
|
import org.kar.archidata.annotation.CreationTimestamp;
|
||||||
|
import org.kar.archidata.annotation.DataIfNotExists;
|
||||||
|
import org.kar.archidata.annotation.UpdateTimestamp;
|
||||||
|
import org.kar.archidata.dataAccess.addOnSQL.DataAccessAddOn;
|
||||||
|
import org.kar.archidata.dataAccess.options.CreateDropTable;
|
||||||
|
import org.kar.archidata.dataAccess.options.OptionSpecifyType;
|
||||||
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
|
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
// Mark as deprecated while the concept is not ready ...
|
// Mark as deprecated while the concept is not ready ...
|
||||||
@Deprecated
|
@Deprecated
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
public interface LazyGetter {
|
public interface LazyGetter {
|
||||||
void doRequest() throws Exception;
|
void doRequest() throws Exception;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -1,12 +1,12 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.AccessDeletedItems;
|
import org.kar.archidata.dataAccess.options.AccessDeletedItems;
|
||||||
import org.atriasoft.archidata.dataAccess.options.CreateDropTable;
|
import org.kar.archidata.dataAccess.options.CreateDropTable;
|
||||||
import org.atriasoft.archidata.dataAccess.options.QueryOption;
|
import org.kar.archidata.dataAccess.options.QueryOption;
|
||||||
import org.atriasoft.archidata.dataAccess.options.ReadAllColumn;
|
import org.kar.archidata.dataAccess.options.ReadAllColumn;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
|
174
src/org/kar/archidata/dataAccess/addOnMongo/AddOnDataJson.java
Normal file
174
src/org/kar/archidata/dataAccess/addOnMongo/AddOnDataJson.java
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
package org.kar.archidata.dataAccess.addOnMongo;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
|
import org.kar.archidata.annotation.DataJson;
|
||||||
|
import org.kar.archidata.dataAccess.CountInOut;
|
||||||
|
import org.kar.archidata.dataAccess.DBAccessMorphia;
|
||||||
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
|
import org.kar.archidata.dataAccess.LazyGetter;
|
||||||
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
public class AddOnDataJson implements DataAccessAddOn {
|
||||||
|
static final Logger LOGGER = LoggerFactory.getLogger(AddOnDataJson.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> getAnnotationClass() {
|
||||||
|
return DataJson.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSQLFieldType(final Field elem, final QueryOptions options) throws DataAccessException {
|
||||||
|
final String fieldName = AnnotationTools.getFieldName(elem, options).inTable();
|
||||||
|
return DataFactory.convertTypeInSQL(String.class, fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCompatibleField(final Field elem) {
|
||||||
|
final DataJson decorators = elem.getDeclaredAnnotation(DataJson.class);
|
||||||
|
return decorators != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertData(
|
||||||
|
final DBAccessMorphia ioDb,
|
||||||
|
final Field field,
|
||||||
|
final Object rootObject,
|
||||||
|
final QueryOptions options,
|
||||||
|
final Document docSet,
|
||||||
|
final Document docUnSet) throws Exception {
|
||||||
|
/*
|
||||||
|
final Object data = field.get(rootObject);
|
||||||
|
if (data == null) {
|
||||||
|
ps.setNull(iii.value, Types.VARCHAR);
|
||||||
|
}
|
||||||
|
final ObjectMapper objectMapper = ContextGenericTools.createObjectMapper();
|
||||||
|
final String dataString = objectMapper.writeValueAsString(data);
|
||||||
|
ps.setString(iii.value, dataString);
|
||||||
|
iii.inc();
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canInsert(final Field field) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInsertAsync(final Field field) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRetrieve(final Field field) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateQuery(
|
||||||
|
@NotNull final String tableName,
|
||||||
|
@NotNull final String primaryKey,
|
||||||
|
@NotNull final Field field,
|
||||||
|
@NotNull final StringBuilder querySelect,
|
||||||
|
@NotNull final StringBuilder query,
|
||||||
|
@NotNull final String name,
|
||||||
|
@NotNull final CountInOut count,
|
||||||
|
final QueryOptions options) throws Exception {
|
||||||
|
querySelect.append(" ");
|
||||||
|
querySelect.append(tableName);
|
||||||
|
querySelect.append(".");
|
||||||
|
querySelect.append(name);
|
||||||
|
count.inc();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fillFromDoc(
|
||||||
|
final DBAccessMorphia ioDb,
|
||||||
|
final Document doc,
|
||||||
|
final Field field,
|
||||||
|
final Object data,
|
||||||
|
final QueryOptions options,
|
||||||
|
final List<LazyGetter> lazyCall) throws Exception {
|
||||||
|
/*
|
||||||
|
final String fieldName = AnnotationTools.getFieldName(field);
|
||||||
|
if (!doc.containsKey(fieldName)) {
|
||||||
|
field.set(data, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final String jsonData = rs.getString(count.value);
|
||||||
|
if (!rs.wasNull()) {
|
||||||
|
final ObjectMapper objectMapper = ContextGenericTools.createObjectMapper();
|
||||||
|
if (field.getType() == List.class) {
|
||||||
|
final ParameterizedType listType = (ParameterizedType) field.getGenericType();
|
||||||
|
final Class<?> listClass = (Class<?>) listType.getActualTypeArguments()[0];
|
||||||
|
if (listClass == Long.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<Long>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listClass == Float.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<Float>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listClass == Double.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<Double>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listClass == Integer.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<Integer>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listClass == Short.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<Short>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listClass == String.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<String>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listClass == UUID.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<UUID>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LOGGER.warn("Maybe fail to translate Model in datajson list: List<{}>", listClass.getCanonicalName());
|
||||||
|
}
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createTables(
|
||||||
|
final String tableName,
|
||||||
|
final Field primaryField,
|
||||||
|
final Field field,
|
||||||
|
final StringBuilder mainTableBuilder,
|
||||||
|
final List<String> preActionList,
|
||||||
|
final List<String> postActionList,
|
||||||
|
final boolean createIfNotExist,
|
||||||
|
final boolean createDrop,
|
||||||
|
final int fieldId,
|
||||||
|
final QueryOptions options) throws Exception {
|
||||||
|
DataFactory.createTablesSpecificType(tableName, primaryField, field, mainTableBuilder, preActionList,
|
||||||
|
postActionList, createIfNotExist, createDrop, fieldId, JsonValue.class, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package org.atriasoft.archidata.dataAccess.addOnMongo;
|
package org.kar.archidata.dataAccess.addOnMongo;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
@ -6,23 +6,23 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.atriasoft.archidata.annotation.AnnotationTools;
|
|
||||||
import org.atriasoft.archidata.annotation.AnnotationTools.FieldName;
|
|
||||||
import org.atriasoft.archidata.dataAccess.CountInOut;
|
|
||||||
import org.atriasoft.archidata.dataAccess.DBAccess;
|
|
||||||
import org.atriasoft.archidata.dataAccess.DBAccessMorphia;
|
|
||||||
import org.atriasoft.archidata.dataAccess.DataFactory;
|
|
||||||
import org.atriasoft.archidata.dataAccess.LazyGetter;
|
|
||||||
import org.atriasoft.archidata.dataAccess.QueryAnd;
|
|
||||||
import org.atriasoft.archidata.dataAccess.QueryCondition;
|
|
||||||
import org.atriasoft.archidata.dataAccess.QueryOptions;
|
|
||||||
import org.atriasoft.archidata.dataAccess.addOnSQL.model.LinkTableGeneric;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.Condition;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.OptionSpecifyType;
|
|
||||||
import org.atriasoft.archidata.dataAccess.options.OverrideTableName;
|
|
||||||
import org.atriasoft.archidata.exception.DataAccessException;
|
|
||||||
import org.atriasoft.archidata.tools.ConfigBaseVariable;
|
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
|
import org.kar.archidata.annotation.AnnotationTools.FieldName;
|
||||||
|
import org.kar.archidata.dataAccess.CountInOut;
|
||||||
|
import org.kar.archidata.dataAccess.DBAccess;
|
||||||
|
import org.kar.archidata.dataAccess.DBAccessMorphia;
|
||||||
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
|
import org.kar.archidata.dataAccess.LazyGetter;
|
||||||
|
import org.kar.archidata.dataAccess.QueryAnd;
|
||||||
|
import org.kar.archidata.dataAccess.QueryCondition;
|
||||||
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
|
import org.kar.archidata.dataAccess.addOnSQL.model.LinkTableGeneric;
|
||||||
|
import org.kar.archidata.dataAccess.options.Condition;
|
||||||
|
import org.kar.archidata.dataAccess.options.OptionSpecifyType;
|
||||||
|
import org.kar.archidata.dataAccess.options.OverrideTableName;
|
||||||
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
|
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -173,6 +173,34 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
count.inc();
|
count.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateQuery(
|
||||||
|
@NotNull final String tableName,
|
||||||
|
@NotNull final String primaryKey,
|
||||||
|
@NotNull final Field field,
|
||||||
|
@NotNull final StringBuilder querySelect,
|
||||||
|
@NotNull final StringBuilder query,
|
||||||
|
@NotNull final String name,
|
||||||
|
@NotNull final CountInOut count,
|
||||||
|
final QueryOptions options) throws Exception {
|
||||||
|
if (field.getType() != List.class) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||||
|
.getActualTypeArguments()[0];
|
||||||
|
if (objectClass == Long.class || objectClass == UUID.class) {
|
||||||
|
generateConcatQuery(tableName, primaryKey, field, querySelect, query, name, count, options);
|
||||||
|
}
|
||||||
|
final ManyToMany decorators = field.getDeclaredAnnotation(ManyToMany.class);
|
||||||
|
if (decorators == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (objectClass == decorators.targetEntity()) {
|
||||||
|
generateConcatQuery(tableName, primaryKey, field, querySelect, query, name, count, options);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillFromDoc(
|
public void fillFromDoc(
|
||||||
final DBAccessMorphia ioDb,
|
final DBAccessMorphia ioDb,
|
@ -1,21 +1,22 @@
|
|||||||
package org.atriasoft.archidata.dataAccess.addOnMongo;
|
package org.kar.archidata.dataAccess.addOnMongo;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.atriasoft.archidata.annotation.AnnotationTools;
|
|
||||||
import org.atriasoft.archidata.annotation.AnnotationTools.FieldName;
|
|
||||||
import org.atriasoft.archidata.dataAccess.DBAccessMorphia;
|
|
||||||
import org.atriasoft.archidata.dataAccess.DataFactory;
|
|
||||||
import org.atriasoft.archidata.dataAccess.LazyGetter;
|
|
||||||
import org.atriasoft.archidata.dataAccess.QueryOptions;
|
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.bson.types.ObjectId;
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
|
import org.kar.archidata.annotation.AnnotationTools.FieldName;
|
||||||
|
import org.kar.archidata.dataAccess.CountInOut;
|
||||||
|
import org.kar.archidata.dataAccess.DBAccessMorphia;
|
||||||
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
|
import org.kar.archidata.dataAccess.LazyGetter;
|
||||||
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
public class AddOnManyToOne implements DataAccessAddOn {
|
public class AddOnManyToOne implements DataAccessAddOn {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(AddOnManyToMany.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(AddOnManyToMany.class);
|
||||||
@ -51,7 +52,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
final Document docUnSet) throws Exception {
|
final Document docUnSet) throws Exception {
|
||||||
final FieldName fieldName = AnnotationTools.getFieldName(field, options);
|
final FieldName fieldName = AnnotationTools.getFieldName(field, options);
|
||||||
final Object data = field.get(rootObject);
|
final Object data = field.get(rootObject);
|
||||||
if (data == null) {
|
if (field.get(data) == null) {
|
||||||
docUnSet.append(fieldName.inTable(), "");
|
docUnSet.append(fieldName.inTable(), "");
|
||||||
return;
|
return;
|
||||||
} else if (field.getType() == Long.class) {
|
} else if (field.getType() == Long.class) {
|
||||||
@ -69,9 +70,6 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
} else if (field.getType() == UUID.class) {
|
} else if (field.getType() == UUID.class) {
|
||||||
final UUID dataTyped = (UUID) data;
|
final UUID dataTyped = (UUID) data;
|
||||||
docSet.append(fieldName.inTable(), dataTyped);
|
docSet.append(fieldName.inTable(), dataTyped);
|
||||||
} else if (field.getType() == ObjectId.class) {
|
|
||||||
final ObjectId dataTyped = (ObjectId) data;
|
|
||||||
docSet.append(fieldName.inTable(), dataTyped);
|
|
||||||
} else {
|
} else {
|
||||||
final Field idField = AnnotationTools.getFieldOfId(field.getType());
|
final Field idField = AnnotationTools.getFieldOfId(field.getType());
|
||||||
final Object uid = idField.get(data);
|
final Object uid = idField.get(data);
|
||||||
@ -86,8 +84,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
@Override
|
@Override
|
||||||
public boolean canInsert(final Field field) {
|
public boolean canInsert(final Field field) {
|
||||||
if (field.getType() == Long.class || field.getType() == Integer.class || field.getType() == Short.class
|
if (field.getType() == Long.class || field.getType() == Integer.class || field.getType() == Short.class
|
||||||
|| field.getType() == String.class || field.getType() == UUID.class
|
|| field.getType() == String.class || field.getType() == UUID.class) {
|
||||||
|| field.getType() == ObjectId.class) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final ManyToOne decorators = field.getDeclaredAnnotation(ManyToOne.class);
|
final ManyToOne decorators = field.getDeclaredAnnotation(ManyToOne.class);
|
||||||
@ -106,7 +103,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
public boolean canRetrieve(final Field field) {
|
public boolean canRetrieve(final Field field) {
|
||||||
final Class<?> classType = field.getType();
|
final Class<?> classType = field.getType();
|
||||||
if (classType == Long.class || classType == Integer.class || classType == Short.class
|
if (classType == Long.class || classType == Integer.class || classType == Short.class
|
||||||
|| classType == String.class || classType == UUID.class || classType == ObjectId.class) {
|
|| classType == String.class || classType == UUID.class) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final ManyToOne decorators = field.getDeclaredAnnotation(ManyToOne.class);
|
final ManyToOne decorators = field.getDeclaredAnnotation(ManyToOne.class);
|
||||||
@ -116,6 +113,36 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateQuery(
|
||||||
|
@NotNull final String tableName,
|
||||||
|
@NotNull final String primaryKey,
|
||||||
|
@NotNull final Field field,
|
||||||
|
@NotNull final StringBuilder querySelect,
|
||||||
|
@NotNull final StringBuilder query,
|
||||||
|
@NotNull final String name,
|
||||||
|
@NotNull final CountInOut count,
|
||||||
|
final QueryOptions options) throws Exception {
|
||||||
|
if (field.getType() == Long.class || field.getType() == Integer.class || field.getType() == Short.class
|
||||||
|
|| field.getType() == String.class || field.getType() == UUID.class) {
|
||||||
|
querySelect.append(" ");
|
||||||
|
querySelect.append(tableName);
|
||||||
|
querySelect.append(".");
|
||||||
|
querySelect.append(name);
|
||||||
|
count.inc();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final ManyToOne decorators = field.getDeclaredAnnotation(ManyToOne.class);
|
||||||
|
if (field.getType() == decorators.targetEntity()) {
|
||||||
|
// no eager possible for no sql
|
||||||
|
querySelect.append(" ");
|
||||||
|
querySelect.append(tableName);
|
||||||
|
querySelect.append(".");
|
||||||
|
querySelect.append(name);
|
||||||
|
count.inc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillFromDoc(
|
public void fillFromDoc(
|
||||||
final DBAccessMorphia ioDb,
|
final DBAccessMorphia ioDb,
|
||||||
@ -132,8 +159,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
}
|
}
|
||||||
// local field to manage no remote object to retrieve.
|
// local field to manage no remote object to retrieve.
|
||||||
if (field.getType() == Long.class || field.getType() == Integer.class || field.getType() == Short.class
|
if (field.getType() == Long.class || field.getType() == Integer.class || field.getType() == Short.class
|
||||||
|| field.getType() == String.class || field.getType() == UUID.class
|
|| field.getType() == String.class || field.getType() == UUID.class) {
|
||||||
|| field.getType() == ObjectId.class) {
|
|
||||||
ioDb.setValueFromDoc(field.getType(), data, field, doc, lazyCall, options);
|
ioDb.setValueFromDoc(field.getType(), data, field, doc, lazyCall, options);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -148,8 +174,9 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
final Class<?> remotePrimaryKeyType = remotePrimaryKeyField.getType();
|
final Class<?> remotePrimaryKeyType = remotePrimaryKeyField.getType();
|
||||||
if (remotePrimaryKeyType == Long.class) {
|
if (remotePrimaryKeyType == Long.class) {
|
||||||
// here we have the field, the data and the the remote value ==> can create callback that generate the update of the value ...
|
// here we have the field, the data and the the remote value ==> can create callback that generate the update of the value ...
|
||||||
final Long foreignKey = doc.getLong(fieldName.inTable());
|
final Long foreignKey = doc.getLong(fieldName);
|
||||||
if (foreignKey != null) {
|
if (foreignKey != null) {
|
||||||
|
// In the lazy mode, the request is done in asynchronous mode, they will be done after...
|
||||||
final LazyGetter lambda = () -> {
|
final LazyGetter lambda = () -> {
|
||||||
// TODO: update to have get with abstract types ....
|
// TODO: update to have get with abstract types ....
|
||||||
final Object foreignData = ioDb.get(decorators.targetEntity(), foreignKey);
|
final Object foreignData = ioDb.get(decorators.targetEntity(), foreignKey);
|
||||||
@ -162,22 +189,9 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
}
|
}
|
||||||
} else if (remotePrimaryKeyType == UUID.class) {
|
} else if (remotePrimaryKeyType == UUID.class) {
|
||||||
// here we have the field, the data and the the remote value ==> can create callback that generate the update of the value ...
|
// here we have the field, the data and the the remote value ==> can create callback that generate the update of the value ...
|
||||||
final UUID foreignKey = doc.get(fieldName.inTable(), UUID.class);
|
final UUID foreignKey = doc.get(fieldName, UUID.class);
|
||||||
if (foreignKey != null) {
|
|
||||||
final LazyGetter lambda = () -> {
|
|
||||||
// TODO: update to have get with abstract types ....
|
|
||||||
final Object foreignData = ioDb.get(decorators.targetEntity(), foreignKey);
|
|
||||||
if (foreignData == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
field.set(data, foreignData);
|
|
||||||
};
|
|
||||||
lazyCall.add(lambda);
|
|
||||||
}
|
|
||||||
} else if (remotePrimaryKeyType == ObjectId.class) {
|
|
||||||
// here we have the field, the data and the the remote value ==> can create callback that generate the update of the value ...
|
|
||||||
final ObjectId foreignKey = doc.get(fieldName.inTable(), ObjectId.class);
|
|
||||||
if (foreignKey != null) {
|
if (foreignKey != null) {
|
||||||
|
// In the lazy mode, the request is done in asynchronous mode, they will be done after...
|
||||||
final LazyGetter lambda = () -> {
|
final LazyGetter lambda = () -> {
|
||||||
// TODO: update to have get with abstract types ....
|
// TODO: update to have get with abstract types ....
|
||||||
final Object foreignData = ioDb.get(decorators.targetEntity(), foreignKey);
|
final Object foreignData = ioDb.get(decorators.targetEntity(), foreignKey);
|
||||||
@ -207,7 +221,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
final QueryOptions options) throws Exception {
|
final QueryOptions options) throws Exception {
|
||||||
final Class<?> classType = field.getType();
|
final Class<?> classType = field.getType();
|
||||||
if (classType == Long.class || classType == Integer.class || classType == Short.class
|
if (classType == Long.class || classType == Integer.class || classType == Short.class
|
||||||
|| classType == String.class || classType == UUID.class || classType == ObjectId.class) {
|
|| classType == String.class || classType == UUID.class) {
|
||||||
DataFactory.createTablesSpecificType(tableName, primaryField, field, mainTableBuilder, preActionList,
|
DataFactory.createTablesSpecificType(tableName, primaryField, field, mainTableBuilder, preActionList,
|
||||||
postActionList, createIfNotExist, createDrop, fieldId, classType, options);
|
postActionList, createIfNotExist, createDrop, fieldId, classType, options);
|
||||||
} else {
|
} else {
|
312
src/org/kar/archidata/dataAccess/addOnMongo/AddOnOneToMany.java
Normal file
312
src/org/kar/archidata/dataAccess/addOnMongo/AddOnOneToMany.java
Normal file
@ -0,0 +1,312 @@
|
|||||||
|
package org.kar.archidata.dataAccess.addOnMongo;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
|
import org.kar.archidata.annotation.AnnotationTools.FieldName;
|
||||||
|
import org.kar.archidata.dataAccess.CountInOut;
|
||||||
|
import org.kar.archidata.dataAccess.DBAccessMorphia;
|
||||||
|
import org.kar.archidata.dataAccess.LazyGetter;
|
||||||
|
import org.kar.archidata.dataAccess.QueryCondition;
|
||||||
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
|
import org.kar.archidata.dataAccess.options.Condition;
|
||||||
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
|
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.OneToMany;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
public class AddOnOneToMany implements DataAccessAddOn {
|
||||||
|
static final Logger LOGGER = LoggerFactory.getLogger(AddOnOneToMany.class);
|
||||||
|
static final String SEPARATOR_LONG = "-";
|
||||||
|
|
||||||
|
/** Convert the list if external id in a string '-' separated
|
||||||
|
* @param ids List of value (null are removed)
|
||||||
|
* @return '-' string separated */
|
||||||
|
protected static String getStringOfIds(final List<Long> ids) {
|
||||||
|
final List<Long> tmp = new ArrayList<>(ids);
|
||||||
|
return tmp.stream().map(String::valueOf).collect(Collectors.joining("-"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** extract a list of "-" separated element from a SQL input data.
|
||||||
|
* @param rs Result Set of the BDD
|
||||||
|
* @param iii Id in the result set
|
||||||
|
* @return The list of Long value
|
||||||
|
* @throws SQLException if an error is generated in the sql request. */
|
||||||
|
protected static List<Long> getListOfIds(final ResultSet rs, final int iii) throws SQLException {
|
||||||
|
final String trackString = rs.getString(iii);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final List<Long> out = new ArrayList<>();
|
||||||
|
final String[] elements = trackString.split("-");
|
||||||
|
for (final String elem : elements) {
|
||||||
|
final Long tmp = Long.parseLong(elem);
|
||||||
|
out.add(tmp);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> getAnnotationClass() {
|
||||||
|
return OneToMany.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCompatibleField(final Field field) {
|
||||||
|
final OneToMany decorators = field.getDeclaredAnnotation(OneToMany.class);
|
||||||
|
return decorators != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertData(
|
||||||
|
final DBAccessMorphia ioDb,
|
||||||
|
final Field field,
|
||||||
|
final Object rootObject,
|
||||||
|
final QueryOptions options,
|
||||||
|
final Document docSet,
|
||||||
|
final Document docUnSet) throws Exception {
|
||||||
|
throw new IllegalAccessException("Can not generate an inset of @OneToMany");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canInsert(final Field field) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInsertAsync(final Field field) throws Exception {
|
||||||
|
// TODO: can be implemented later...
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRetrieve(final Field field) {
|
||||||
|
if (field.getType() != List.class) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||||
|
.getActualTypeArguments()[0];
|
||||||
|
if (objectClass == Long.class || objectClass == UUID.class) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
final OneToMany decorators = field.getDeclaredAnnotation(OneToMany.class);
|
||||||
|
if (decorators == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (decorators.targetEntity() == objectClass) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generateConcatQuery(
|
||||||
|
@NotNull final String tableName,
|
||||||
|
@NotNull final String primaryKey,
|
||||||
|
@NotNull final Field field,
|
||||||
|
@NotNull final StringBuilder querySelect,
|
||||||
|
@NotNull final StringBuilder query,
|
||||||
|
@NotNull final String name,
|
||||||
|
@NotNull final CountInOut count,
|
||||||
|
final QueryOptions options,
|
||||||
|
final Class<?> targetEntity,
|
||||||
|
final String mappedBy) throws Exception {
|
||||||
|
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||||
|
.getActualTypeArguments()[0];
|
||||||
|
final String remoteTableName = AnnotationTools.getTableName(targetEntity);
|
||||||
|
final FieldName remoteTablePrimaryKeyName = AnnotationTools
|
||||||
|
.getFieldName(AnnotationTools.getPrimaryKeyField(targetEntity), options);
|
||||||
|
final String tmpRemoteVariable = "tmp_" + Integer.toString(count.value);
|
||||||
|
final String remoteDeletedFieldName = AnnotationTools.getDeletedFieldName(targetEntity);
|
||||||
|
|
||||||
|
querySelect.append(" (SELECT GROUP_CONCAT(");
|
||||||
|
querySelect.append(tmpRemoteVariable);
|
||||||
|
querySelect.append(".");
|
||||||
|
querySelect.append(remoteTablePrimaryKeyName.inTable());
|
||||||
|
querySelect.append(" ");
|
||||||
|
if ("sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||||
|
querySelect.append(", ");
|
||||||
|
} else {
|
||||||
|
querySelect.append("SEPARATOR ");
|
||||||
|
}
|
||||||
|
querySelect.append("'");
|
||||||
|
if (objectClass == Long.class) {
|
||||||
|
querySelect.append(SEPARATOR_LONG);
|
||||||
|
}
|
||||||
|
querySelect.append("') FROM ");
|
||||||
|
querySelect.append(remoteTableName);
|
||||||
|
querySelect.append(" ");
|
||||||
|
querySelect.append(tmpRemoteVariable);
|
||||||
|
querySelect.append(" WHERE ");
|
||||||
|
if (remoteDeletedFieldName != null) {
|
||||||
|
querySelect.append(tmpRemoteVariable);
|
||||||
|
querySelect.append(".");
|
||||||
|
querySelect.append(remoteDeletedFieldName);
|
||||||
|
querySelect.append(" = false");
|
||||||
|
querySelect.append(" AND ");
|
||||||
|
}
|
||||||
|
querySelect.append(tableName);
|
||||||
|
querySelect.append(".");
|
||||||
|
querySelect.append(primaryKey);
|
||||||
|
querySelect.append(" = ");
|
||||||
|
querySelect.append(tmpRemoteVariable);
|
||||||
|
querySelect.append(".");
|
||||||
|
querySelect.append(mappedBy);
|
||||||
|
querySelect.append(" ");
|
||||||
|
querySelect.append(") AS ");
|
||||||
|
querySelect.append(name);
|
||||||
|
querySelect.append(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateQuery(
|
||||||
|
@NotNull final String tableName,
|
||||||
|
@NotNull final String primaryKey,
|
||||||
|
@NotNull final Field field,
|
||||||
|
@NotNull final StringBuilder querySelect,
|
||||||
|
@NotNull final StringBuilder query,
|
||||||
|
@NotNull final String name,
|
||||||
|
@NotNull final CountInOut count,
|
||||||
|
final QueryOptions options) throws Exception {
|
||||||
|
if (field.getType() != List.class) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||||
|
.getActualTypeArguments()[0];
|
||||||
|
final OneToMany decorators = field.getDeclaredAnnotation(OneToMany.class);
|
||||||
|
if (decorators == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// TODO: manage better the eager and lazy !!
|
||||||
|
if (objectClass == Long.class || objectClass == UUID.class) {
|
||||||
|
generateConcatQuery(tableName, primaryKey, field, querySelect, query, name, count, options,
|
||||||
|
decorators.targetEntity(), decorators.mappedBy());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (objectClass == decorators.targetEntity()) {
|
||||||
|
if (decorators.fetch() == FetchType.EAGER) {
|
||||||
|
throw new DataAccessException("EAGER is not supported for list of element...");
|
||||||
|
} else {
|
||||||
|
// Force a copy of the primaryKey to permit the async retrieve of the data
|
||||||
|
querySelect.append(" ");
|
||||||
|
querySelect.append(tableName);
|
||||||
|
querySelect.append(".");
|
||||||
|
querySelect.append(primaryKey);
|
||||||
|
querySelect.append(" AS tmp_");
|
||||||
|
querySelect.append(Integer.toString(count.value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fillFromDoc(
|
||||||
|
final DBAccessMorphia ioDb,
|
||||||
|
final Document doc,
|
||||||
|
final Field field,
|
||||||
|
final Object data,
|
||||||
|
final QueryOptions options,
|
||||||
|
final List<LazyGetter> lazyCall) throws Exception {
|
||||||
|
if (field.getType() != List.class) {
|
||||||
|
LOGGER.error("Can not OneToMany with other than List Model: {}", field.getType().getCanonicalName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String fieldName = AnnotationTools.getFieldName(field, options).inTable();
|
||||||
|
if (!doc.containsKey(fieldName)) {
|
||||||
|
field.set(data, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||||
|
.getActualTypeArguments()[0];
|
||||||
|
final OneToMany decorators = field.getDeclaredAnnotation(OneToMany.class);
|
||||||
|
if (decorators == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (objectClass == Long.class || objectClass == UUID.class) {
|
||||||
|
final Object value = doc.get(fieldName, field.getType());
|
||||||
|
field.set(data, value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (objectClass == decorators.targetEntity()) {
|
||||||
|
|
||||||
|
Long parentIdTmp = null;
|
||||||
|
UUID parendUuidTmp = null;
|
||||||
|
try {
|
||||||
|
final Object value = doc.get(fieldName);
|
||||||
|
if (value instanceof final Long valueCasted) {
|
||||||
|
parentIdTmp = valueCasted;
|
||||||
|
} else if (value instanceof final UUID valueCasted) {
|
||||||
|
parendUuidTmp = valueCasted;
|
||||||
|
}
|
||||||
|
} catch (final Exception ex) {
|
||||||
|
LOGGER.error("fail to find the correct type... {}", ex.getMessage());
|
||||||
|
}
|
||||||
|
final Long parentId = parentIdTmp;
|
||||||
|
final UUID parendUuid = parendUuidTmp;
|
||||||
|
final String mappingKey = decorators.mappedBy();
|
||||||
|
// We get the parent ID ... ==> need to request the list of elements
|
||||||
|
if (objectClass == Long.class) {
|
||||||
|
LOGGER.error("Need to retreive all primary key of all elements");
|
||||||
|
//field.set(data, idList);
|
||||||
|
return;
|
||||||
|
} else if (objectClass == UUID.class) {
|
||||||
|
LOGGER.error("Need to retreive all primary key of all elements");
|
||||||
|
//field.set(data, idList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (objectClass == decorators.targetEntity()) {
|
||||||
|
if (parentId != null) {
|
||||||
|
final LazyGetter lambda = () -> {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final Object foreignData = ioDb.getsWhere(decorators.targetEntity(),
|
||||||
|
new Condition(new QueryCondition(mappingKey, "=", parentId)));
|
||||||
|
if (foreignData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
field.set(data, foreignData);
|
||||||
|
};
|
||||||
|
lazyCall.add(lambda);
|
||||||
|
} else if (parendUuid != null) {
|
||||||
|
final LazyGetter lambda = () -> {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final Object foreignData = ioDb.getsWhere(decorators.targetEntity(),
|
||||||
|
new Condition(new QueryCondition(mappingKey, "=", parendUuid)));
|
||||||
|
if (foreignData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
field.set(data, foreignData);
|
||||||
|
};
|
||||||
|
lazyCall.add(lambda);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO : refacto this table to manage a generic table with dynamic name to be serialize with the default system
|
||||||
|
@Override
|
||||||
|
public void createTables(
|
||||||
|
final String tableName,
|
||||||
|
final Field primaryField,
|
||||||
|
final Field field,
|
||||||
|
final StringBuilder mainTableBuilder,
|
||||||
|
final List<String> preActionList,
|
||||||
|
final List<String> postActionList,
|
||||||
|
final boolean createIfNotExist,
|
||||||
|
final boolean createDrop,
|
||||||
|
final int fieldId,
|
||||||
|
final QueryOptions options) throws Exception {
|
||||||
|
// This is a remote field ==> nothing to generate (it is stored in the remote object
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user