Compare commits
1 Commits
main
...
release/1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3361e627a |
179
bom/pom.xml
179
bom/pom.xml
@@ -1,179 +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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
<artifactId>semrack-bom</artifactId>
|
||||
<name>Bom</name>
|
||||
|
||||
<properties>
|
||||
<!-- Quarkus project basics -->
|
||||
<compiler-plugin.version>3.14.0</compiler-plugin.version>
|
||||
<maven.compiler.release>21</maven.compiler.release>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
|
||||
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
|
||||
<quarkus.platform.version>${quarkus.version}</quarkus.platform.version>
|
||||
<skipITs>true</skipITs>
|
||||
<surefire-plugin.version>3.5.3</surefire-plugin.version>
|
||||
|
||||
<!-- Other properties -->
|
||||
<commons-codec.version>1.16.0</commons-codec.version>
|
||||
<jsonpath.version>2.9.0</jsonpath.version>
|
||||
<lombok.version>1.18.38</lombok.version>
|
||||
<org.mapstruct.version>1.6.3</org.mapstruct.version>
|
||||
<quarkus.version>3.31.3</quarkus.version>
|
||||
<semrack.version>${project.version}</semrack.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${quarkus.platform.group-id}</groupId>
|
||||
<artifactId>${quarkus.platform.artifact-id}</artifactId>
|
||||
<version>${quarkus.platform.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>${commons-codec.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId>
|
||||
<version>${org.mapstruct.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- SEMRACK -->
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-bom</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-core</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-core-testing</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-core-deployment</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-index-postgres</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-index-postgres-deployment</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-storage-postgres</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-storage-postgres-deployment</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-api-rest</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-api-rest-deployment</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-rest-client</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-rest-client-deployment</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jayway.jsonpath</groupId>
|
||||
<artifactId>json-path</artifactId>
|
||||
<version>${jsonpath.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-maven-plugin</artifactId>
|
||||
<version>${quarkus.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<maven.home>${maven.home}</maven.home>
|
||||
<maven.repo>${settings.localRepository}</maven.repo>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>${failsafe-plugin.version}</version>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<maven.home>${maven.home}</maven.home>
|
||||
<maven.repo>${settings.localRepository}</maven.repo>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<parameters>true</parameters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,36 +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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-bom</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../bom/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>semrack</artifactId>
|
||||
<name>Semrack</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-arc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -1,13 +0,0 @@
|
||||
package fr.codeanddata.semrack;
|
||||
|
||||
import fr.codeanddata.semrack.models.IndexSearchResult;
|
||||
import fr.codeanddata.semrack.models.Search;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
|
||||
public interface Index {
|
||||
Uni<Long> count(Search request);
|
||||
Uni<Boolean> exist(Search query);
|
||||
Uni<Void> index(String documentId);
|
||||
Uni<IndexSearchResult> search(Search search);
|
||||
Uni<Void> clear(String documentId);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package fr.codeanddata.semrack;
|
||||
|
||||
import fr.codeanddata.semrack.models.ReadContext;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
|
||||
public interface ReadInterceptor {
|
||||
Uni<Void> interceptSemdocRead(ReadContext context);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package fr.codeanddata.semrack;
|
||||
|
||||
import fr.codeanddata.semrack.models.SearchContext;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
|
||||
public interface SearchInterceptor {
|
||||
Uni<Void> interceptSemdocSearch(SearchContext context);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package fr.codeanddata.semrack;
|
||||
|
||||
import fr.codeanddata.semrack.models.Document;
|
||||
import fr.codeanddata.semrack.models.StorageGet;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Storage {
|
||||
Uni<Document> get(String uid, StorageGet request);
|
||||
Uni<List<Document>> get(List<String> uids, StorageGet request);
|
||||
Uni<Document> storeDocument(Document document);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package fr.codeanddata.semrack;
|
||||
|
||||
import fr.codeanddata.semrack.models.WriteContext;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
|
||||
public interface WriteInterceptor {
|
||||
Uni<Void> interceptSemdocWrite(WriteContext context);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package fr.codeanddata.semrack.enums;
|
||||
|
||||
public enum PathTypes {
|
||||
UNKNOWN,
|
||||
STRING,
|
||||
NUMBER,
|
||||
BOOLEAN,
|
||||
LIST,
|
||||
OBJECT
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package fr.codeanddata.semrack.enums;
|
||||
|
||||
public enum SortDirection {
|
||||
asc, desc
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package fr.codeanddata.semrack.models;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ReadContext {
|
||||
Document currentDocument;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package fr.codeanddata.semrack.models;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Search {
|
||||
Map<String, Object> filter;
|
||||
List<Sort> sort;
|
||||
Pagination paginate;
|
||||
Boolean annotations;
|
||||
Boolean metadata;
|
||||
Map<String, String> fields;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package fr.codeanddata.semrack.models;
|
||||
|
||||
import fr.codeanddata.semrack.enums.SortDirection;
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Sort {
|
||||
String field;
|
||||
SortDirection direction;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package fr.codeanddata.semrack.models;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class StorageGet {
|
||||
Boolean metadataSource;
|
||||
Boolean annotationsSource;
|
||||
Map<String, String> fields;
|
||||
}
|
||||
24
integration/semrack-integration/docker-compose.yml
Normal file
24
integration/semrack-integration/docker-compose.yml
Normal file
@@ -0,0 +1,24 @@
|
||||
services:
|
||||
postgres:
|
||||
image: postgres
|
||||
environment:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: quarkus
|
||||
ports:
|
||||
- "35532:5432"
|
||||
|
||||
semrack:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: src/main/docker/Dockerfile.native-micro
|
||||
environment:
|
||||
QUARKUS_FLYWAY_ACTIVE: true
|
||||
ports:
|
||||
- "9090:8080"
|
||||
links:
|
||||
- postgres
|
||||
volumes:
|
||||
- ./.env:/work/.env
|
||||
- ./src/main/resources/application.properties:/work/config/application.properties
|
||||
|
||||
|
||||
139
integration/semrack-integration/pom.xml
Normal file
139
integration/semrack-integration/pom.xml
Normal file
@@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<artifactId>semrack-parent</artifactId>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>semrack-integration</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-storage-postgres</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-index-postgres</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-api-rest</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-junit5</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>${quarkus.platform.group-id}</groupId>
|
||||
<artifactId>quarkus-maven-plugin</artifactId>
|
||||
<version>${quarkus.platform.version}</version>
|
||||
<extensions>true</extensions>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>build</goal>
|
||||
<goal>generate-code</goal>
|
||||
<goal>generate-code-tests</goal>
|
||||
<goal>native-image-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>${org.mapstruct.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
<parameters>true</parameters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<maven.home>${maven.home}</maven.home>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>${surefire-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
|
||||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<maven.home>${maven.home}</maven.home>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>native</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>native</name>
|
||||
</property>
|
||||
</activation>
|
||||
<properties>
|
||||
<skipITs>false</skipITs>
|
||||
<quarkus.native.enabled>true</quarkus.native.enabled>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
@@ -0,0 +1,98 @@
|
||||
####
|
||||
# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode
|
||||
#
|
||||
# Before building the container image run:
|
||||
#
|
||||
# ./mvnw package
|
||||
#
|
||||
# Then, build the image with:
|
||||
#
|
||||
# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/semrack-jvm .
|
||||
#
|
||||
# Then run the container using:
|
||||
#
|
||||
# docker run -i --rm -p 8080:8080 quarkus/semrack-jvm
|
||||
#
|
||||
# If you want to include the debug port into your docker image
|
||||
# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005.
|
||||
# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005
|
||||
# when running the container
|
||||
#
|
||||
# Then run the container using :
|
||||
#
|
||||
# docker run -i --rm -p 8080:8080 quarkus/semrack-jvm
|
||||
#
|
||||
# This image uses the `run-java.sh` script to run the application.
|
||||
# This scripts computes the command line to execute your Java application, and
|
||||
# includes memory/GC tuning.
|
||||
# You can configure the behavior using the following environment properties:
|
||||
# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") - Be aware that this will override
|
||||
# the default JVM options, use `JAVA_OPTS_APPEND` to append options
|
||||
# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options
|
||||
# in JAVA_OPTS (example: "-Dsome.property=foo")
|
||||
# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is
|
||||
# used to calculate a default maximal heap memory based on a containers restriction.
|
||||
# If used in a container without any memory constraints for the container then this
|
||||
# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio
|
||||
# of the container available memory as set here. The default is `50` which means 50%
|
||||
# of the available memory is used as an upper boundary. You can skip this mechanism by
|
||||
# setting this value to `0` in which case no `-Xmx` option is added.
|
||||
# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This
|
||||
# is used to calculate a default initial heap memory based on the maximum heap memory.
|
||||
# If used in a container without any memory constraints for the container then this
|
||||
# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio
|
||||
# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx`
|
||||
# is used as the initial heap size. You can skip this mechanism by setting this value
|
||||
# to `0` in which case no `-Xms` option is added (example: "25")
|
||||
# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS.
|
||||
# This is used to calculate the maximum value of the initial heap memory. If used in
|
||||
# a container without any memory constraints for the container then this option has
|
||||
# no effect. If there is a memory constraint then `-Xms` is limited to the value set
|
||||
# here. The default is 4096MB which means the calculated value of `-Xms` never will
|
||||
# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096")
|
||||
# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output
|
||||
# when things are happening. This option, if set to true, will set
|
||||
# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true").
|
||||
# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example:
|
||||
# true").
|
||||
# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787").
|
||||
# - CONTAINER_CORE_LIMIT: A calculated core limit as described in
|
||||
# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2")
|
||||
# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024").
|
||||
# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion.
|
||||
# (example: "20")
|
||||
# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking.
|
||||
# (example: "40")
|
||||
# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection.
|
||||
# (example: "4")
|
||||
# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus
|
||||
# previous GC times. (example: "90")
|
||||
# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20")
|
||||
# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100")
|
||||
# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should
|
||||
# contain the necessary JRE command-line options to specify the required GC, which
|
||||
# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC).
|
||||
# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080")
|
||||
# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080")
|
||||
# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be
|
||||
# accessed directly. (example: "foo.example.com,bar.example.com")
|
||||
#
|
||||
###
|
||||
FROM registry.access.redhat.com/ubi9/openjdk-21:1.21
|
||||
|
||||
ENV LANGUAGE='en_US:en'
|
||||
|
||||
|
||||
# We make four distinct layers so if there are application changes the library layers can be re-used
|
||||
COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/
|
||||
COPY --chown=185 target/quarkus-app/*.jar /deployments/
|
||||
COPY --chown=185 target/quarkus-app/app/ /deployments/app/
|
||||
COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/
|
||||
|
||||
EXPOSE 8080
|
||||
USER 185
|
||||
ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
|
||||
ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"
|
||||
|
||||
ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ]
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
####
|
||||
# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode
|
||||
#
|
||||
# Before building the container image run:
|
||||
#
|
||||
# ./mvnw package -Dquarkus.package.jar.type=legacy-jar
|
||||
#
|
||||
# Then, build the image with:
|
||||
#
|
||||
# docker build -f src/main/docker/Dockerfile.legacy-jar -t quarkus/semrack-legacy-jar .
|
||||
#
|
||||
# Then run the container using:
|
||||
#
|
||||
# docker run -i --rm -p 8080:8080 quarkus/semrack-legacy-jar
|
||||
#
|
||||
# If you want to include the debug port into your docker image
|
||||
# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005.
|
||||
# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005
|
||||
# when running the container
|
||||
#
|
||||
# Then run the container using :
|
||||
#
|
||||
# docker run -i --rm -p 8080:8080 quarkus/semrack-legacy-jar
|
||||
#
|
||||
# This image uses the `run-java.sh` script to run the application.
|
||||
# This scripts computes the command line to execute your Java application, and
|
||||
# includes memory/GC tuning.
|
||||
# You can configure the behavior using the following environment properties:
|
||||
# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") - Be aware that this will override
|
||||
# the default JVM options, use `JAVA_OPTS_APPEND` to append options
|
||||
# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options
|
||||
# in JAVA_OPTS (example: "-Dsome.property=foo")
|
||||
# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is
|
||||
# used to calculate a default maximal heap memory based on a containers restriction.
|
||||
# If used in a container without any memory constraints for the container then this
|
||||
# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio
|
||||
# of the container available memory as set here. The default is `50` which means 50%
|
||||
# of the available memory is used as an upper boundary. You can skip this mechanism by
|
||||
# setting this value to `0` in which case no `-Xmx` option is added.
|
||||
# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This
|
||||
# is used to calculate a default initial heap memory based on the maximum heap memory.
|
||||
# If used in a container without any memory constraints for the container then this
|
||||
# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio
|
||||
# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx`
|
||||
# is used as the initial heap size. You can skip this mechanism by setting this value
|
||||
# to `0` in which case no `-Xms` option is added (example: "25")
|
||||
# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS.
|
||||
# This is used to calculate the maximum value of the initial heap memory. If used in
|
||||
# a container without any memory constraints for the container then this option has
|
||||
# no effect. If there is a memory constraint then `-Xms` is limited to the value set
|
||||
# here. The default is 4096MB which means the calculated value of `-Xms` never will
|
||||
# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096")
|
||||
# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output
|
||||
# when things are happening. This option, if set to true, will set
|
||||
# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true").
|
||||
# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example:
|
||||
# true").
|
||||
# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787").
|
||||
# - CONTAINER_CORE_LIMIT: A calculated core limit as described in
|
||||
# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2")
|
||||
# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024").
|
||||
# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion.
|
||||
# (example: "20")
|
||||
# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking.
|
||||
# (example: "40")
|
||||
# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection.
|
||||
# (example: "4")
|
||||
# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus
|
||||
# previous GC times. (example: "90")
|
||||
# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20")
|
||||
# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100")
|
||||
# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should
|
||||
# contain the necessary JRE command-line options to specify the required GC, which
|
||||
# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC).
|
||||
# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080")
|
||||
# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080")
|
||||
# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be
|
||||
# accessed directly. (example: "foo.example.com,bar.example.com")
|
||||
#
|
||||
###
|
||||
FROM registry.access.redhat.com/ubi9/openjdk-21:1.21
|
||||
|
||||
ENV LANGUAGE='en_US:en'
|
||||
|
||||
|
||||
COPY target/lib/* /deployments/lib/
|
||||
COPY target/*-runner.jar /deployments/quarkus-run.jar
|
||||
|
||||
EXPOSE 8080
|
||||
USER 185
|
||||
ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
|
||||
ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"
|
||||
|
||||
ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ]
|
||||
@@ -0,0 +1,29 @@
|
||||
####
|
||||
# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode.
|
||||
#
|
||||
# Before building the container image run:
|
||||
#
|
||||
# ./mvnw package -Dnative
|
||||
#
|
||||
# Then, build the image with:
|
||||
#
|
||||
# docker build -f src/main/docker/Dockerfile.native -t quarkus/semrack .
|
||||
#
|
||||
# Then run the container using:
|
||||
#
|
||||
# docker run -i --rm -p 8080:8080 quarkus/semrack
|
||||
#
|
||||
# The ` registry.access.redhat.com/ubi9/ubi-minimal:9.5` base image is based on UBI 9.
|
||||
# To use UBI 8, switch to `quay.io/ubi8/ubi-minimal:8.10`.
|
||||
###
|
||||
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5
|
||||
WORKDIR /work/
|
||||
RUN chown 1001 /work \
|
||||
&& chmod "g+rwX" /work \
|
||||
&& chown 1001:root /work
|
||||
COPY --chown=1001:root --chmod=0755 target/*-runner /work/application
|
||||
|
||||
EXPOSE 8080
|
||||
USER 1001
|
||||
|
||||
ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"]
|
||||
@@ -0,0 +1,32 @@
|
||||
####
|
||||
# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode.
|
||||
# It uses a micro base image, tuned for Quarkus native executables.
|
||||
# It reduces the size of the resulting container image.
|
||||
# Check https://quarkus.io/guides/quarkus-runtime-base-image for further information about this image.
|
||||
#
|
||||
# Before building the container image run:
|
||||
#
|
||||
# ./mvnw package -Dnative
|
||||
#
|
||||
# Then, build the image with:
|
||||
#
|
||||
# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/semrack .
|
||||
#
|
||||
# Then run the container using:
|
||||
#
|
||||
# docker run -i --rm -p 8080:8080 quarkus/semrack
|
||||
#
|
||||
# The `quay.io/quarkus/ubi9-quarkus-micro-image:2.0` base image is based on UBI 9.
|
||||
# To use UBI 8, switch to `quay.io/quarkus/quarkus-micro-image:2.0`.
|
||||
###
|
||||
FROM quay.io/quarkus/ubi9-quarkus-micro-image:2.0
|
||||
WORKDIR /work/
|
||||
RUN chown 1001 /work \
|
||||
&& chmod "g+rwX" /work \
|
||||
&& chown 1001:root /work
|
||||
COPY --chown=1001:root --chmod=0755 target/*-runner /work/application
|
||||
|
||||
EXPOSE 8080
|
||||
USER 1001
|
||||
|
||||
ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"]
|
||||
@@ -0,0 +1,25 @@
|
||||
%dev.quarkus.log.min-level=TRACE
|
||||
|
||||
#quarkus.hibernate-orm.mapping.format.global=ignore
|
||||
|
||||
# Datasource
|
||||
quarkus.datasource.devservices.port=35432
|
||||
quarkus.hibernate-orm.scripts.generation=none
|
||||
%prod.quarkus.datasource.jdbc.url=jdbc:postgresql://${semrack.db.host}:${semrack.db.port}/${semrack.db.name}
|
||||
%prod.quarkus.datasource.reactive.url=postgresql://${semrack.db.host}:${semrack.db.port}/${semrack.db.name}
|
||||
%prod.quarkus.datasource.username=${semrack.db.user}
|
||||
%prod.quarkus.datasource.password=${semrack.db.password}
|
||||
quarkus.hibernate-orm.log.sql=true
|
||||
|
||||
## Flyway
|
||||
quarkus.flyway.active=false
|
||||
|
||||
# Security
|
||||
quarkus.keycloak.devservices.port=35180
|
||||
quarkus.oidc.client-id=m2m-client
|
||||
quarkus.oidc.credentials.secret=m2m-password
|
||||
quarkus.oidc.discovery-enabled=true
|
||||
%prod.quarkus.oidc.auth-server-url=${semrack.oidc.url}
|
||||
%prod.quarkus.oidc.client-id=${semrack.oidc.client-id}
|
||||
%prod.quarkus.oidc.credentials.secret=${semrack.oidc.client-secret}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package fr.codeanddata;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusIntegrationTest;
|
||||
|
||||
@QuarkusIntegrationTest
|
||||
class SemrackApiIT extends SemrackApiTest {
|
||||
// Execute the same tests but in packaged mode.
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package fr.codeanddata;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
@QuarkusTest
|
||||
class SemrackApiTest {
|
||||
@Test
|
||||
void testHelloEndpoint() {
|
||||
given()
|
||||
.when().get("/hello")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(is("Hello from Quarkus REST"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,9 +4,9 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-bom</artifactId>
|
||||
<artifactId>semrack-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../../bom/pom.xml</relativePath>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>semrack-api-rest-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package fr.codeanddata.semrack.api.rest;
|
||||
|
||||
import fr.codeanddata.semrack.core.repositories.DocumentRepository;
|
||||
import fr.codeanddata.semrack.models.*;
|
||||
import fr.codeanddata.semrack.core.models.PushDocumentRequest;
|
||||
import fr.codeanddata.semrack.core.models.SearchRequest;
|
||||
import fr.codeanddata.semrack.core.models.SearchResult;
|
||||
import fr.codeanddata.semrack.core.models.SemrackDocument;
|
||||
import fr.codeanddata.semrack.core.repositories.SemdocRepository;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.GET;
|
||||
@@ -12,42 +15,36 @@ import jakarta.ws.rs.core.MediaType;
|
||||
import org.jboss.resteasy.reactive.RestPath;
|
||||
|
||||
@Path("/semrack/documents")
|
||||
//@Authenticated
|
||||
public class SemrackApi {
|
||||
|
||||
@Inject
|
||||
DocumentRepository repository;
|
||||
SemdocRepository repository;
|
||||
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<Document> pushDocument(PushDocument semrackDocument) {
|
||||
public Uni<SemrackDocument> pushDocument(PushDocumentRequest semrackDocument) {
|
||||
return repository.pushDocument(semrackDocument);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/search")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<SearchResult> searchDocument(Search query) {
|
||||
public Uni<SearchResult> searchDocument(SearchRequest query) {
|
||||
return repository.searchDocument(query);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{uid}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<Document> getDocument(@RestPath String uid) {
|
||||
public Uni<SemrackDocument> getDocument(@RestPath String uid) {
|
||||
return repository.get(uid);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("{uid}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<Document> getDocument(@RestPath String uid, StorageGet request) {
|
||||
return repository.get(uid, request);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("{uid}/update")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<Document> updateDocument(@RestPath String uid, PushDocument semrackDocument) {
|
||||
public Uni<SemrackDocument> updateDocument(@RestPath String uid, PushDocumentRequest semrackDocument) {
|
||||
return repository.pushDocument(semrackDocument);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-bom</artifactId>
|
||||
<artifactId>semrack-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../../bom/pom.xml</relativePath>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>semrack-core-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
@@ -12,10 +12,6 @@
|
||||
<name>Semrack Core - Runtime</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-arc</artifactId>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package fr.codeanddata.semrack.core;
|
||||
|
||||
import fr.codeanddata.semrack.core.models.IndexSearchResult;
|
||||
import fr.codeanddata.semrack.core.models.SearchRequest;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
|
||||
public interface SemdocIndex {
|
||||
Uni<Long> count(SearchRequest request);
|
||||
Uni<Boolean> exist(SearchRequest query);
|
||||
Uni<Void> index(String documentId);
|
||||
Uni<IndexSearchResult> search(SearchRequest searchRequest);
|
||||
Uni<Void> clear(String documentId);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package fr.codeanddata.semrack.core;
|
||||
|
||||
import fr.codeanddata.semrack.core.models.SemdocReadContext;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
|
||||
public interface SemdocReadInterceptor {
|
||||
Uni<Void> interceptSemdocRead(SemdocReadContext context);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package fr.codeanddata.semrack.core;
|
||||
|
||||
import fr.codeanddata.semrack.core.models.SemdocSearchContext;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
|
||||
public interface SemdocSearchInterceptor {
|
||||
Uni<Void> interceptSemdocSearch(SemdocSearchContext context);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package fr.codeanddata.semrack.core;
|
||||
|
||||
import fr.codeanddata.semrack.core.models.SemrackDocument;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SemdocStorage {
|
||||
Uni<SemrackDocument> get(String uid);
|
||||
Uni<List<SemrackDocument>> get(List<String> uids);
|
||||
Uni<SemrackDocument> storeDocument(SemrackDocument document);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package fr.codeanddata.semrack.core;
|
||||
|
||||
import fr.codeanddata.semrack.core.models.SemdocWriteContext;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
|
||||
public interface SemdocWriteInterceptor {
|
||||
Uni<Void> interceptSemdocWrite(SemdocWriteContext context);
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package fr.codeanddata.semrack;
|
||||
package fr.codeanddata.semrack.core;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.enterprise.inject.spi.CDI;
|
||||
|
||||
public interface LookupExpression<T> {
|
||||
public interface SemrackLookupExpression<T> {
|
||||
String apply(Object params);
|
||||
|
||||
default T convert(Object params) {
|
||||
@@ -0,0 +1,5 @@
|
||||
package fr.codeanddata.semrack.core.enums;
|
||||
|
||||
public enum SemrackSortDirection {
|
||||
asc, desc
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.codeanddata.semrack.exceptions;
|
||||
package fr.codeanddata.semrack.core.exceptions;
|
||||
|
||||
public class SemrackException extends Exception {
|
||||
public SemrackException() {
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.codeanddata.semrack.exceptions;
|
||||
package fr.codeanddata.semrack.core.exceptions;
|
||||
|
||||
public class SemrackRuntimeException extends RuntimeException {
|
||||
public SemrackRuntimeException() {
|
||||
@@ -2,8 +2,8 @@ package fr.codeanddata.semrack.core.interceptors;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import fr.codeanddata.semrack.WriteInterceptor;
|
||||
import fr.codeanddata.semrack.models.WriteContext;
|
||||
import fr.codeanddata.semrack.core.SemdocWriteInterceptor;
|
||||
import fr.codeanddata.semrack.core.models.SemdocWriteContext;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -11,7 +11,7 @@ import jakarta.inject.Inject;
|
||||
import java.util.Map;
|
||||
|
||||
@ApplicationScoped
|
||||
public class AnnotateWriteInterceptor implements WriteInterceptor {
|
||||
public class AnnotateWriteInterceptor implements SemdocWriteInterceptor {
|
||||
|
||||
public static final String ANNOTATE_KEY = "annotate";
|
||||
public static final String CUSTOM_PREFIX = "custom/";
|
||||
@@ -20,7 +20,7 @@ public class AnnotateWriteInterceptor implements WriteInterceptor {
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
public Uni<Void> interceptSemdocWrite(WriteContext context) {
|
||||
public Uni<Void> interceptSemdocWrite(SemdocWriteContext context) {
|
||||
final Map<String, Object> directives = context.getDirectives();
|
||||
|
||||
if (directives.containsKey(ANNOTATE_KEY)) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package fr.codeanddata.semrack.core.interceptors;
|
||||
|
||||
import fr.codeanddata.semrack.WriteInterceptor;
|
||||
import fr.codeanddata.semrack.models.WriteContext;
|
||||
import fr.codeanddata.semrack.models.Document;
|
||||
import fr.codeanddata.semrack.core.SemdocWriteInterceptor;
|
||||
import fr.codeanddata.semrack.core.models.SemdocWriteContext;
|
||||
import fr.codeanddata.semrack.core.models.SemrackDocument;
|
||||
import fr.codeanddata.semrack.core.utils.UIDGenerator;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@ApplicationScoped
|
||||
public class PublishWriteInterceptor implements WriteInterceptor {
|
||||
public class PublishWriteInterceptor implements SemdocWriteInterceptor {
|
||||
|
||||
final String PUBLICATION_PREFIX = "publication/";
|
||||
|
||||
@@ -20,18 +20,18 @@ public class PublishWriteInterceptor implements WriteInterceptor {
|
||||
UIDGenerator uidGenerator;
|
||||
|
||||
@Override
|
||||
public Uni<Void> interceptSemdocWrite(WriteContext context) {
|
||||
public Uni<Void> interceptSemdocWrite(SemdocWriteContext context) {
|
||||
final Map<String, Object> directives = context.getDirectives();
|
||||
final Document current = context.getCurrentDocument();
|
||||
final Document next = context.getNextDocument();
|
||||
final SemrackDocument current = context.getCurrentDocument();
|
||||
final SemrackDocument next = context.getNextDocument();
|
||||
|
||||
int version = (int) Optional.ofNullable(current)
|
||||
.map(Document::getAnnotations)
|
||||
.map(SemrackDocument::getAnnotations)
|
||||
.map(annotations -> annotations.getOrDefault(PUBLICATION_PREFIX + "version", 0))
|
||||
.orElse(0);
|
||||
|
||||
next.getAnnotations().put(PUBLICATION_PREFIX + "reference", Optional.ofNullable(current)
|
||||
.map(Document::getAnnotations)
|
||||
.map(SemrackDocument::getAnnotations)
|
||||
.map(annotations -> annotations.getOrDefault(PUBLICATION_PREFIX + "reference", next.getUid()))
|
||||
.orElse(next.getUid()));
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package fr.codeanddata.semrack.core.mappers;
|
||||
|
||||
import fr.codeanddata.semrack.models.Document;
|
||||
import fr.codeanddata.semrack.models.PushDocument;
|
||||
import fr.codeanddata.semrack.core.models.SemrackDocument;
|
||||
import fr.codeanddata.semrack.core.models.PushDocumentRequest;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.MappingConstants;
|
||||
|
||||
@Mapper(componentModel = MappingConstants.ComponentModel.CDI)
|
||||
public abstract class DocumentMapper {
|
||||
public abstract class SemrackDocumentMapper {
|
||||
@Mapping(source = "uid", target = "uid")
|
||||
@Mapping(source = "metadata", target = "metadata")
|
||||
abstract Document toDocument(PushDocument document);
|
||||
abstract SemrackDocument toDocument(PushDocumentRequest document);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.codeanddata.semrack.models;
|
||||
package fr.codeanddata.semrack.core.models;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.codeanddata.semrack.models;
|
||||
package fr.codeanddata.semrack.core.models;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.codeanddata.semrack.models;
|
||||
package fr.codeanddata.semrack.core.models;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.Map;
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PushDocument {
|
||||
public class PushDocumentRequest {
|
||||
/**
|
||||
* L'identifiant unique du document.
|
||||
*/
|
||||
@@ -0,0 +1,18 @@
|
||||
package fr.codeanddata.semrack.core.models;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class SearchRequest {
|
||||
Map<String, Object> filter;
|
||||
List<SemrackSort> sort;
|
||||
SemrackPagination paginate;
|
||||
List<String> fields;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.codeanddata.semrack.models;
|
||||
package fr.codeanddata.semrack.core.models;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@@ -10,6 +10,6 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class SearchResult {
|
||||
List<Document> documents;
|
||||
List<SemrackDocument> documents;
|
||||
PaginationInfo pagination;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package fr.codeanddata.semrack.core.models;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SemdocReadContext {
|
||||
|
||||
SemrackDocument currentDocument;
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.codeanddata.semrack.models;
|
||||
package fr.codeanddata.semrack.core.models;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.Map;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SearchContext {
|
||||
public class SemdocSearchContext {
|
||||
|
||||
Map<String, Object> search;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.codeanddata.semrack.models;
|
||||
package fr.codeanddata.semrack.core.models;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@@ -9,19 +9,19 @@ import java.util.Map;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class WriteContext {
|
||||
public class SemdocWriteContext {
|
||||
|
||||
/**
|
||||
* Previous stored document
|
||||
*/
|
||||
Document currentDocument;
|
||||
SemrackDocument currentDocument;
|
||||
|
||||
/**
|
||||
* Document to be store. It initialized with :
|
||||
* - the currentDocument uid if exists, or a new one
|
||||
* - the metadata to be persisted
|
||||
*/
|
||||
Document nextDocument;
|
||||
SemrackDocument nextDocument;
|
||||
|
||||
/**
|
||||
* The directives to be applied
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.codeanddata.semrack.models;
|
||||
package fr.codeanddata.semrack.core.models;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.*;
|
||||
@@ -11,7 +11,7 @@ import java.util.Map;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@RegisterForReflection(serialization = true)
|
||||
public class Document {
|
||||
public class SemrackDocument {
|
||||
|
||||
/**
|
||||
* L'identifiant unique du document.
|
||||
@@ -29,8 +29,4 @@ public class Document {
|
||||
*/
|
||||
Map<String, Object> metadata;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
Map<String, Object> fields;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.codeanddata.semrack.models;
|
||||
package fr.codeanddata.semrack.core.models;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@@ -7,7 +7,7 @@ import lombok.*;
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Pagination {
|
||||
public class SemrackPagination {
|
||||
Integer page;
|
||||
Integer size;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package fr.codeanddata.semrack.core.models;
|
||||
|
||||
import fr.codeanddata.semrack.core.enums.SemrackSortDirection;
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class SemrackSort {
|
||||
String field;
|
||||
SemrackSortDirection direction;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package fr.codeanddata.semrack.models;
|
||||
package fr.codeanddata.semrack.core.models;
|
||||
|
||||
import fr.codeanddata.semrack.enums.PathTypes;
|
||||
import fr.codeanddata.semrack.core.utils.Traverser;
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@@ -9,7 +9,7 @@ import lombok.*;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TraverserPath {
|
||||
PathTypes type;
|
||||
Traverser.PathTypes type;
|
||||
String fullPath;
|
||||
Object value;
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package fr.codeanddata.semrack.core.repositories;
|
||||
|
||||
import fr.codeanddata.semrack.WriteInterceptor;
|
||||
import fr.codeanddata.semrack.exceptions.SemrackRuntimeException;
|
||||
import fr.codeanddata.semrack.core.storages.StorageProxy;
|
||||
import fr.codeanddata.semrack.core.SemdocWriteInterceptor;
|
||||
import fr.codeanddata.semrack.core.exceptions.SemrackRuntimeException;
|
||||
import fr.codeanddata.semrack.core.models.*;
|
||||
import fr.codeanddata.semrack.core.storages.SemdocStorageProxy;
|
||||
import fr.codeanddata.semrack.core.utils.UIDGenerator;
|
||||
import fr.codeanddata.semrack.models.*;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.enterprise.inject.Any;
|
||||
@@ -16,43 +16,35 @@ import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@ApplicationScoped
|
||||
public class DocumentRepository {
|
||||
public class SemdocRepository {
|
||||
|
||||
@Inject
|
||||
StorageProxy semdocStorage;
|
||||
SemdocStorageProxy semdocStorage;
|
||||
|
||||
@Inject
|
||||
@Any
|
||||
Instance<WriteInterceptor> writeInterceptors;
|
||||
Instance<SemdocWriteInterceptor> writeInterceptors;
|
||||
|
||||
@Inject
|
||||
UIDGenerator uidGenerator;
|
||||
|
||||
public Uni<SearchResult> searchDocument(Search query) {
|
||||
public Uni<SearchResult> searchDocument(SearchRequest query) {
|
||||
return semdocStorage.searchDocument(query);
|
||||
}
|
||||
|
||||
public Uni<Document> get(String documentId) {
|
||||
return get(documentId, StorageGet.builder().build());
|
||||
public Uni<SemrackDocument> get(String documentId) {
|
||||
return semdocStorage.readDocument(documentId);
|
||||
}
|
||||
|
||||
public Uni<Document> get(String documentId, StorageGet request) {
|
||||
return semdocStorage.readDocument(documentId, request);
|
||||
}
|
||||
|
||||
public Uni<Document> pushDocument(PushDocument pushDocument) {
|
||||
return Optional.ofNullable(pushDocument.getUid()).map(uid -> semdocStorage.readDocument(uid, StorageGet.builder()
|
||||
.annotationsSource(true)
|
||||
.metadataSource(true)
|
||||
.build()))
|
||||
.orElse(Uni.createFrom().nullItem())
|
||||
public Uni<SemrackDocument> pushDocument(PushDocumentRequest pushDocument) {
|
||||
return Optional.ofNullable(pushDocument.getUid()).map(semdocStorage::readDocument).orElse(Uni.createFrom().nullItem())
|
||||
.chain(currentDocument -> {
|
||||
|
||||
final WriteContext context = WriteContext.builder()
|
||||
final SemdocWriteContext context = SemdocWriteContext.builder()
|
||||
.directives(pushDocument.getDirectives())
|
||||
.currentDocument(currentDocument)
|
||||
.nextDocument(Document.builder()
|
||||
.uid(Optional.ofNullable(currentDocument).map(Document::getUid).orElse(uidGenerator.apply(null)))
|
||||
.nextDocument(SemrackDocument.builder()
|
||||
.uid(Optional.ofNullable(currentDocument).map(SemrackDocument::getUid).orElse(uidGenerator.apply(null)))
|
||||
.metadata(pushDocument.getMetadata())
|
||||
.annotations(new HashMap<>())
|
||||
.build())
|
||||
@@ -65,7 +57,7 @@ public class DocumentRepository {
|
||||
});
|
||||
}
|
||||
|
||||
public Uni<Document> getOrCreate(Search query, PushDocument toCreate) {
|
||||
public Uni<SemrackDocument> getOrCreate(SearchRequest query, PushDocumentRequest toCreate) {
|
||||
return searchDocument(query)
|
||||
.chain(searchResult -> {
|
||||
if (searchResult.getDocuments().isEmpty()) {
|
||||
@@ -1,35 +0,0 @@
|
||||
package fr.codeanddata.semrack.core.services;
|
||||
|
||||
import fr.codeanddata.semrack.Index;
|
||||
import fr.codeanddata.semrack.models.IndexSearchResult;
|
||||
import fr.codeanddata.semrack.models.Search;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
@ApplicationScoped
|
||||
public class IndexService {
|
||||
|
||||
@Inject
|
||||
Index index;
|
||||
|
||||
public Uni<Void> index(String documentId) {
|
||||
return index.index(documentId);
|
||||
}
|
||||
|
||||
public Uni<IndexSearchResult> search(Search search) {
|
||||
return index.search(search);
|
||||
}
|
||||
|
||||
public Uni<Long> count(Search request) {
|
||||
return index.count(request);
|
||||
}
|
||||
|
||||
public Uni<Boolean> exist(Search query) {
|
||||
return index.exist(query);
|
||||
}
|
||||
|
||||
public Uni<Void> clear(String documentId) {
|
||||
return index.clear(documentId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package fr.codeanddata.semrack.core.services;
|
||||
|
||||
import fr.codeanddata.semrack.core.SemdocIndex;
|
||||
import fr.codeanddata.semrack.core.models.IndexSearchResult;
|
||||
import fr.codeanddata.semrack.core.models.SearchRequest;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
@ApplicationScoped
|
||||
public class SemrackIndexService {
|
||||
|
||||
@Inject
|
||||
SemdocIndex semdocIndex;
|
||||
|
||||
public Uni<Void> index(String documentId) {
|
||||
return semdocIndex.index(documentId);
|
||||
}
|
||||
|
||||
public Uni<IndexSearchResult> search(SearchRequest searchRequest) {
|
||||
return semdocIndex.search(searchRequest);
|
||||
}
|
||||
|
||||
public Uni<Long> count(SearchRequest request) {
|
||||
return semdocIndex.count(request);
|
||||
}
|
||||
|
||||
public Uni<Boolean> exist(SearchRequest query) {
|
||||
return semdocIndex.exist(query);
|
||||
}
|
||||
|
||||
public Uni<Void> clear(String documentId) {
|
||||
return semdocIndex.clear(documentId);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package fr.codeanddata.semrack.core.services;
|
||||
|
||||
import fr.codeanddata.semrack.LookupExpression;
|
||||
import fr.codeanddata.semrack.core.SemrackLookupExpression;
|
||||
import io.quarkus.runtime.StartupEvent;
|
||||
import io.smallrye.common.annotation.Identifier;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -14,13 +14,13 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@ApplicationScoped
|
||||
public class LookupService {
|
||||
public class SemrackLookupService {
|
||||
|
||||
@Inject
|
||||
@Any
|
||||
Instance<LookupExpression<?>> operators;
|
||||
Instance<SemrackLookupExpression<?>> operators;
|
||||
|
||||
final Map<String, LookupExpression<?>> operatorsIndex = new HashMap<>();
|
||||
final Map<String, SemrackLookupExpression<?>> operatorsIndex = new HashMap<>();
|
||||
|
||||
void startup(@Observes StartupEvent event) {
|
||||
operators.stream()
|
||||
@@ -42,7 +42,7 @@ public class LookupService {
|
||||
if (! operatorsIndex.containsKey(lookupKey)) {
|
||||
throw new RuntimeException("Unknown lookup expression '" + lookupKey + "'");
|
||||
} else {
|
||||
final LookupExpression<?> lookup = operatorsIndex.get(lookupKey);
|
||||
final SemrackLookupExpression<?> lookup = operatorsIndex.get(lookupKey);
|
||||
final Object lookupParams = lookupExpression.get(lookupKey);
|
||||
return lookup.apply(lookupParams);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package fr.codeanddata.semrack.core.storages;
|
||||
|
||||
import fr.codeanddata.semrack.core.SemdocIndex;
|
||||
import fr.codeanddata.semrack.core.SemdocStorage;
|
||||
import fr.codeanddata.semrack.core.models.SearchRequest;
|
||||
import fr.codeanddata.semrack.core.models.SearchResult;
|
||||
import fr.codeanddata.semrack.core.models.SemrackDocument;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
@ApplicationScoped
|
||||
public class SemdocStorageProxy {
|
||||
|
||||
@Inject
|
||||
SemdocStorage storage;
|
||||
|
||||
@Inject
|
||||
SemdocIndex index;
|
||||
|
||||
public Uni<SemrackDocument> readDocument(String uid) {
|
||||
return storage.get(uid);
|
||||
}
|
||||
|
||||
public Uni<SearchResult> searchDocument(SearchRequest query) {
|
||||
return index.search(query)
|
||||
.chain(searchResult -> storage.get(searchResult.getUids())
|
||||
.map(documents -> SearchResult.builder()
|
||||
.documents(documents)
|
||||
.pagination(searchResult.getPagination())
|
||||
.build()));
|
||||
}
|
||||
|
||||
public Uni<Long> countDocuments(SearchRequest request) {
|
||||
return index.count(request);
|
||||
}
|
||||
|
||||
public Uni<Boolean> documentsExist(SearchRequest query) {
|
||||
return index.exist(query);
|
||||
}
|
||||
|
||||
public Uni<SemrackDocument> storeDocument(SemrackDocument document) {
|
||||
return storage.storeDocument(document)
|
||||
.call(x -> index.index(x.getUid()));
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package fr.codeanddata.semrack.core.storages;
|
||||
|
||||
import fr.codeanddata.semrack.Index;
|
||||
import fr.codeanddata.semrack.Storage;
|
||||
import fr.codeanddata.semrack.models.Search;
|
||||
import fr.codeanddata.semrack.models.SearchResult;
|
||||
import fr.codeanddata.semrack.models.Document;
|
||||
import fr.codeanddata.semrack.models.StorageGet;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
@ApplicationScoped
|
||||
public class StorageProxy {
|
||||
|
||||
@Inject
|
||||
Storage storage;
|
||||
|
||||
@Inject
|
||||
Index index;
|
||||
|
||||
public Uni<Document> readDocument(String uid) {
|
||||
return readDocument(uid, StorageGet.builder().build());
|
||||
}
|
||||
|
||||
public Uni<Document> readDocument(String uid, StorageGet request) {
|
||||
return storage.get(uid, request);
|
||||
}
|
||||
|
||||
public Uni<SearchResult> searchDocument(Search query) {
|
||||
return index.search(query)
|
||||
.chain(searchResult -> storage.get(searchResult.getUids(), StorageGet.builder()
|
||||
.annotationsSource(query.getAnnotations())
|
||||
.metadataSource(query.getMetadata())
|
||||
.fields(query.getFields())
|
||||
.build())
|
||||
.map(documents -> SearchResult.builder()
|
||||
.documents(documents)
|
||||
.pagination(searchResult.getPagination())
|
||||
.build()));
|
||||
}
|
||||
|
||||
public Uni<Long> countDocuments(Search request) {
|
||||
return index.count(request);
|
||||
}
|
||||
|
||||
public Uni<Boolean> documentsExist(Search query) {
|
||||
return index.exist(query);
|
||||
}
|
||||
|
||||
public Uni<Document> storeDocument(Document document) {
|
||||
return storage.storeDocument(document)
|
||||
.call(x -> index.index(x.getUid()));
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import jakarta.inject.Inject;
|
||||
import java.util.Map;
|
||||
|
||||
@ApplicationScoped
|
||||
public class DocumentUtils {
|
||||
public class SemdocUtils {
|
||||
@Inject
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
@@ -2,8 +2,8 @@ package fr.codeanddata.semrack.core.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import fr.codeanddata.semrack.enums.PathTypes;
|
||||
import fr.codeanddata.semrack.models.TraverserPath;
|
||||
import fr.codeanddata.semrack.core.models.TraverserPath;
|
||||
import io.vertx.core.json.Json;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
@@ -21,6 +21,15 @@ public class Traverser implements Function<Object, List<TraverserPath>> {
|
||||
return parse("", o);
|
||||
}
|
||||
|
||||
public enum PathTypes {
|
||||
UNKNOWN,
|
||||
STRING,
|
||||
NUMBER,
|
||||
BOOLEAN,
|
||||
LIST,
|
||||
OBJECT
|
||||
}
|
||||
|
||||
List<TraverserPath> parse(String basePath, Object data) {
|
||||
final List<TraverserPath> paths = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package fr.codeanddata.semrack.core.utils;
|
||||
|
||||
import fr.codeanddata.semrack.models.Document;
|
||||
import fr.codeanddata.semrack.core.models.SemrackDocument;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
@@ -10,10 +10,10 @@ import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
@ApplicationScoped
|
||||
public class UIDGenerator implements Function<Document, String> {
|
||||
public class UIDGenerator implements Function<SemrackDocument, String> {
|
||||
|
||||
@Override
|
||||
public String apply(Document document) {
|
||||
public String apply(SemrackDocument semrackDocument) {
|
||||
final String uuid = UUID.randomUUID().toString();
|
||||
final LocalDateTime now = LocalDateTime.now();
|
||||
final long timestamp = now.toInstant(ZoneOffset.UTC).toEpochMilli();
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-arc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-core</artifactId>
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package fr.codeanddata.semrack.core;
|
||||
|
||||
import fr.codeanddata.semrack.Index;
|
||||
import fr.codeanddata.semrack.Storage;
|
||||
import fr.codeanddata.semrack.models.IndexSearchResult;
|
||||
import fr.codeanddata.semrack.models.Search;
|
||||
import fr.codeanddata.semrack.models.Document;
|
||||
import fr.codeanddata.semrack.models.StorageGet;
|
||||
import fr.codeanddata.semrack.core.models.IndexSearchResult;
|
||||
import fr.codeanddata.semrack.core.models.SearchRequest;
|
||||
import fr.codeanddata.semrack.core.models.SemrackDocument;
|
||||
import io.quarkus.arc.DefaultBean;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.annotation.Priority;
|
||||
@@ -19,20 +16,20 @@ public class MockProducer {
|
||||
@Produces
|
||||
@DefaultBean
|
||||
@Priority(100)
|
||||
Storage produceStorage() {
|
||||
return new Storage() {
|
||||
SemdocStorage produceStorage() {
|
||||
return new SemdocStorage() {
|
||||
@Override
|
||||
public Uni<Document> get(String uid, StorageGet request) {
|
||||
public Uni<SemrackDocument> get(String uid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uni<List<Document>> get(List<String> uids, StorageGet request) {
|
||||
public Uni<List<SemrackDocument>> get(List<String> uids) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uni<Document> storeDocument(Document document) {
|
||||
public Uni<SemrackDocument> storeDocument(SemrackDocument document) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -41,15 +38,15 @@ public class MockProducer {
|
||||
@Produces
|
||||
@DefaultBean
|
||||
@Priority(100)
|
||||
Index produceIndex() {
|
||||
return new Index() {
|
||||
SemdocIndex produceIndex() {
|
||||
return new SemdocIndex() {
|
||||
@Override
|
||||
public Uni<Long> count(Search request) {
|
||||
public Uni<Long> count(SearchRequest request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uni<Boolean> exist(Search query) {
|
||||
public Uni<Boolean> exist(SearchRequest query) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -59,7 +56,7 @@ public class MockProducer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uni<IndexSearchResult> search(Search search) {
|
||||
public Uni<IndexSearchResult> search(SearchRequest searchRequest) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package fr.codeanddata.semrack.core.utils;
|
||||
|
||||
import fr.codeanddata.semrack.enums.PathTypes;
|
||||
import fr.codeanddata.semrack.models.TraverserPath;
|
||||
import fr.codeanddata.semrack.core.models.TraverserPath;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@@ -34,16 +33,16 @@ public class TraverserTest {
|
||||
Assertions.assertEquals(14, paths.size());
|
||||
|
||||
List<List<?>> expectations = List.of(
|
||||
Arrays.asList(".user", null, PathTypes.OBJECT),
|
||||
Arrays.asList(".user.age", 14, PathTypes.NUMBER),
|
||||
Arrays.asList(".user.family[0].age", 38, PathTypes.NUMBER),
|
||||
Arrays.asList(".user.family[0].isAdult", true, PathTypes.BOOLEAN),
|
||||
Arrays.asList(".user.family[0].name", "mom", PathTypes.STRING),
|
||||
Arrays.asList(".user.family[1].age", 6, PathTypes.NUMBER),
|
||||
Arrays.asList(".user.family[1].isAdult", false, PathTypes.BOOLEAN),
|
||||
Arrays.asList(".user.family[1].name", "bro", PathTypes.STRING),
|
||||
Arrays.asList(".user.isAdult", false, PathTypes.BOOLEAN),
|
||||
Arrays.asList(".user.name", "bob", PathTypes.STRING)
|
||||
Arrays.asList(".user", null, Traverser.PathTypes.OBJECT),
|
||||
Arrays.asList(".user.age", 14, Traverser.PathTypes.NUMBER),
|
||||
Arrays.asList(".user.family[0].age", 38, Traverser.PathTypes.NUMBER),
|
||||
Arrays.asList(".user.family[0].isAdult", true, Traverser.PathTypes.BOOLEAN),
|
||||
Arrays.asList(".user.family[0].name", "mom", Traverser.PathTypes.STRING),
|
||||
Arrays.asList(".user.family[1].age", 6, Traverser.PathTypes.NUMBER),
|
||||
Arrays.asList(".user.family[1].isAdult", false, Traverser.PathTypes.BOOLEAN),
|
||||
Arrays.asList(".user.family[1].name", "bro", Traverser.PathTypes.STRING),
|
||||
Arrays.asList(".user.isAdult", false, Traverser.PathTypes.BOOLEAN),
|
||||
Arrays.asList(".user.name", "bob", Traverser.PathTypes.STRING)
|
||||
);
|
||||
|
||||
for (List<?> expectation : expectations) {
|
||||
|
||||
@@ -54,7 +54,6 @@
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-core-testing</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package fr.codeanddata.semrack.index.postgres.it;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusIntegrationTest;
|
||||
|
||||
@QuarkusIntegrationTest
|
||||
public class SemrackIndexPostgresResourceIT extends SemrackIndexPostgresResourceTest {
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.codeanddata.semrack.rest.client.it;
|
||||
package fr.codeanddata.semrack.index.postgres.it;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
@@ -8,14 +8,14 @@ import org.junit.jupiter.api.Test;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
|
||||
@QuarkusTest
|
||||
public class SemrackRestClientResourceTest {
|
||||
public class SemrackIndexPostgresResourceTest {
|
||||
|
||||
@Test
|
||||
public void testHelloEndpoint() {
|
||||
given()
|
||||
.when().get("/semrack-rest-client")
|
||||
.when().get("/semrack-index-postgres")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(is("Hello semrack-rest-client"));
|
||||
.body(is("Hello semrack-index-postgres"));
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,9 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-bom</artifactId>
|
||||
<artifactId>semrack-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../../bom/pom.xml</relativePath>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>semrack-index-postgres-parent</artifactId>
|
||||
<name>Semrack Index Postgres - Parent</name>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package fr.codeanddata.semrack.index.postgres;
|
||||
|
||||
import fr.codeanddata.semrack.Index;
|
||||
import fr.codeanddata.semrack.Storage;
|
||||
import fr.codeanddata.semrack.core.services.LookupService;
|
||||
import fr.codeanddata.semrack.core.SemdocIndex;
|
||||
import fr.codeanddata.semrack.core.SemdocStorage;
|
||||
import fr.codeanddata.semrack.core.models.*;
|
||||
import fr.codeanddata.semrack.core.services.SemrackLookupService;
|
||||
import fr.codeanddata.semrack.core.utils.Traverser;
|
||||
import fr.codeanddata.semrack.index.postgres.dtos.IndexEntry;
|
||||
import fr.codeanddata.semrack.index.postgres.entities.SemrackIndexEntity;
|
||||
import fr.codeanddata.semrack.index.postgres.repositories.SemrackIndexRepository;
|
||||
import fr.codeanddata.semrack.models.*;
|
||||
import io.quarkus.hibernate.reactive.panache.PanacheRepository;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithTransaction;
|
||||
@@ -19,23 +19,23 @@ import org.hibernate.query.Page;
|
||||
import java.util.*;
|
||||
|
||||
@ApplicationScoped
|
||||
public class JpaIndex implements Index, PanacheRepository<SemrackIndexEntity> {
|
||||
public class SemdocJpaIndex implements SemdocIndex, PanacheRepository<SemrackIndexEntity> {
|
||||
|
||||
@Inject
|
||||
Traverser traverser;
|
||||
|
||||
@Inject
|
||||
LookupService lookupService;
|
||||
SemrackLookupService lookupService;
|
||||
|
||||
@Inject
|
||||
Storage storage;
|
||||
SemdocStorage storage;
|
||||
|
||||
@Inject
|
||||
SemrackIndexRepository indexRepository;
|
||||
|
||||
@Override
|
||||
@WithSession
|
||||
public Uni<Long> count(Search request) {
|
||||
public Uni<Long> count(SearchRequest request) {
|
||||
final StringBuilder query = new StringBuilder("SELECT DISTINCT count(uid) FROM semrack_index");
|
||||
|
||||
final String lookup = lookupService.lookup(request.getFilter());
|
||||
@@ -47,16 +47,14 @@ public class JpaIndex implements Index, PanacheRepository<SemrackIndexEntity> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uni<Boolean> exist(Search query) {
|
||||
public Uni<Boolean> exist(SearchRequest query) {
|
||||
return count(query).map(count -> count > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@WithTransaction
|
||||
public Uni<Void> index(String documentId) {
|
||||
return storage.get(documentId, StorageGet.builder()
|
||||
.metadataSource(true)
|
||||
.build())
|
||||
return storage.get(documentId)
|
||||
.call(document -> clear(documentId))
|
||||
.call(document -> {
|
||||
final Map<String, IndexEntry> indexes = new HashMap<>();
|
||||
@@ -80,7 +78,7 @@ public class JpaIndex implements Index, PanacheRepository<SemrackIndexEntity> {
|
||||
|
||||
@Override
|
||||
@WithSession
|
||||
public Uni<IndexSearchResult> search(Search request) {
|
||||
public Uni<IndexSearchResult> search(SearchRequest request) {
|
||||
final IndexSearchResult result = new IndexSearchResult();
|
||||
final StringBuilder query = new StringBuilder("SELECT DISTINCT uid FROM semrack_index");
|
||||
|
||||
@@ -107,11 +105,11 @@ public class JpaIndex implements Index, PanacheRepository<SemrackIndexEntity> {
|
||||
.replaceWithVoid();
|
||||
}
|
||||
|
||||
Uni<PaginationInfo> queryPaginationInfo(Search query) {
|
||||
Uni<PaginationInfo> queryPaginationInfo(SearchRequest query) {
|
||||
return count(query)
|
||||
.map(count -> PaginationInfo.builder()
|
||||
.page(Optional.ofNullable(query.getPaginate()).map(Pagination::getPage).orElse(0))
|
||||
.size(Optional.ofNullable(query.getPaginate()).map(Pagination::getSize).orElse(10))
|
||||
.page(Optional.ofNullable(query.getPaginate()).map(SemrackPagination::getPage).orElse(0))
|
||||
.size(Optional.ofNullable(query.getPaginate()).map(SemrackPagination::getSize).orElse(10))
|
||||
.total(count)
|
||||
.build());
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package fr.codeanddata.semrack.index.postgres.dtos;
|
||||
|
||||
import fr.codeanddata.semrack.enums.PathTypes;
|
||||
import fr.codeanddata.semrack.core.utils.Traverser;
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@@ -9,6 +9,6 @@ import lombok.*;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class IndexEntry {
|
||||
PathTypes type;
|
||||
Traverser.PathTypes type;
|
||||
Object value;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package fr.codeanddata.semrack.index.postgres.operators;
|
||||
|
||||
import fr.codeanddata.semrack.core.services.LookupService;
|
||||
import fr.codeanddata.semrack.core.services.SemrackLookupService;
|
||||
import io.smallrye.common.annotation.Identifier;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -10,10 +10,10 @@ import java.util.Map;
|
||||
|
||||
@Identifier("and")
|
||||
@ApplicationScoped
|
||||
public class AndLookup implements JpaLookupExpression<List<Map<String, Object>>> {
|
||||
public class AndLookup implements SemrackJpaLookupExpression<List<Map<String, Object>>> {
|
||||
|
||||
@Inject
|
||||
LookupService lookupService;
|
||||
SemrackLookupService lookupService;
|
||||
|
||||
@Override
|
||||
public String apply(Object expressions) {
|
||||
|
||||
@@ -2,7 +2,7 @@ package fr.codeanddata.semrack.index.postgres.operators;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import fr.codeanddata.semrack.exceptions.SemrackRuntimeException;
|
||||
import fr.codeanddata.semrack.core.exceptions.SemrackRuntimeException;
|
||||
import fr.codeanddata.semrack.index.postgres.EqualLookupParams;
|
||||
import io.smallrye.common.annotation.Identifier;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -10,7 +10,7 @@ import jakarta.inject.Inject;
|
||||
|
||||
@Identifier("equal")
|
||||
@ApplicationScoped
|
||||
public class EqualLookup implements JpaLookupExpression<EqualLookupParams> {
|
||||
public class EqualLookup implements SemrackJpaLookupExpression<EqualLookupParams> {
|
||||
|
||||
@Inject
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
@@ -2,7 +2,7 @@ package fr.codeanddata.semrack.index.postgres.operators;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import fr.codeanddata.semrack.exceptions.SemrackRuntimeException;
|
||||
import fr.codeanddata.semrack.core.exceptions.SemrackRuntimeException;
|
||||
import fr.codeanddata.semrack.index.postgres.InLookupParams;
|
||||
import io.smallrye.common.annotation.Identifier;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -13,7 +13,7 @@ import java.util.List;
|
||||
|
||||
@Identifier("in")
|
||||
@ApplicationScoped
|
||||
public class InLookup implements JpaLookupExpression<InLookupParams> {
|
||||
public class InLookup implements SemrackJpaLookupExpression<InLookupParams> {
|
||||
|
||||
@Inject
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package fr.codeanddata.semrack.index.postgres.operators;
|
||||
|
||||
import fr.codeanddata.semrack.LookupExpression;
|
||||
|
||||
public interface JpaLookupExpression<T> extends LookupExpression<T> {
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package fr.codeanddata.semrack.index.postgres.operators;
|
||||
|
||||
import fr.codeanddata.semrack.core.services.LookupService;
|
||||
import fr.codeanddata.semrack.core.services.SemrackLookupService;
|
||||
import io.smallrye.common.annotation.Identifier;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -10,10 +10,10 @@ import java.util.Map;
|
||||
|
||||
@Identifier("or")
|
||||
@ApplicationScoped
|
||||
public class OrLookup implements JpaLookupExpression<List<Map<String, Object>>> {
|
||||
public class OrLookup implements SemrackJpaLookupExpression<List<Map<String, Object>>> {
|
||||
|
||||
@Inject
|
||||
LookupService lookupService;
|
||||
SemrackLookupService lookupService;
|
||||
|
||||
@Override
|
||||
public String apply(Object expressions) {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package fr.codeanddata.semrack.index.postgres.operators;
|
||||
|
||||
import fr.codeanddata.semrack.core.SemrackLookupExpression;
|
||||
|
||||
public interface SemrackJpaLookupExpression<T> extends SemrackLookupExpression<T> {
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-rest-client-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>semrack-rest-client-deployment</artifactId>
|
||||
<name>Semrack Rest Client - Deployment</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-arc-deployment</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-rest-client-deployment</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-rest-client-jackson-deployment</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-rest-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-junit-internal</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-junit-mockito</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-core-testing</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-compile</id>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-extension-processor</artifactId>
|
||||
<version>${quarkus.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -1,14 +0,0 @@
|
||||
package fr.codeanddata.semrack.rest.client.deployment;
|
||||
|
||||
import io.quarkus.deployment.annotations.BuildStep;
|
||||
import io.quarkus.deployment.builditem.FeatureBuildItem;
|
||||
|
||||
class SemrackRestClientProcessor {
|
||||
|
||||
private static final String FEATURE = "semrack-rest-client";
|
||||
|
||||
@BuildStep
|
||||
FeatureBuildItem feature() {
|
||||
return new FeatureBuildItem(FEATURE);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package fr.codeanddata.semrack.rest.client.test;
|
||||
|
||||
import fr.codeanddata.semrack.rest.client.runtime.SemrackRestClient;
|
||||
import io.quarkus.test.QuarkusUnitTest;
|
||||
import org.eclipse.microprofile.rest.client.inject.RestClient;
|
||||
import org.jboss.shrinkwrap.api.ShrinkWrap;
|
||||
import org.jboss.shrinkwrap.api.spec.JavaArchive;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
public class SemrackRestClientTest {
|
||||
|
||||
@RestClient
|
||||
SemrackRestClient restClient;
|
||||
|
||||
// Start unit test with your extension loaded
|
||||
@RegisterExtension
|
||||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest()
|
||||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
|
||||
|
||||
@Test
|
||||
public void writeYourOwnUnitTest() {
|
||||
// Write your unit tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-extensions for more information
|
||||
Assertions.assertTrue(true, "Add some assertions to " + getClass().getName());
|
||||
Assertions.assertNotNull(restClient);
|
||||
}
|
||||
}
|
||||
@@ -1,98 +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>
|
||||
|
||||
<parent>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-rest-client-parent</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>semrack-rest-client-integration-tests</artifactId>
|
||||
<name>Semrack Rest Client - Integration Tests</name>
|
||||
|
||||
<properties>
|
||||
<skipITs>true</skipITs>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-rest</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-rest-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>build</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
|
||||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<maven.home>${maven.home}</maven.home>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>native-image</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>native</name>
|
||||
</property>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<skipTests>${native.surefire.skip}</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
<quarkus.package.jar.enabled>false</quarkus.package.jar.enabled>
|
||||
<skipITs>false</skipITs>
|
||||
<quarkus.native.enabled>true</quarkus.native.enabled>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package fr.codeanddata.semrack.rest.client.it;
|
||||
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
|
||||
@Path("/semrack-rest-client")
|
||||
@ApplicationScoped
|
||||
public class SemrackRestClientResource {
|
||||
// add some rest methods here
|
||||
|
||||
@GET
|
||||
public String hello() {
|
||||
return "Hello semrack-rest-client";
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package fr.codeanddata.semrack.rest.client.it;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusIntegrationTest;
|
||||
|
||||
@QuarkusIntegrationTest
|
||||
public class SemrackRestClientResourceIT extends SemrackRestClientResourceTest {
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-bom</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../../bom/pom.xml</relativePath>
|
||||
</parent>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<artifactId>semrack-rest-client-parent</artifactId>
|
||||
<name>Semrack Rest Client - Parent</name>
|
||||
|
||||
<modules>
|
||||
<module>deployment</module>
|
||||
<module>runtime</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
@@ -1,70 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-rest-client-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>semrack-rest-client</artifactId>
|
||||
<name>Semrack Rest Client - Runtime</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-arc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-rest-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-rest-client-jackson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-extension-maven-plugin</artifactId>
|
||||
<version>${quarkus.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>extension-descriptor</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<deployment>${project.groupId}:${project.artifactId}-deployment:${project.version}</deployment>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-compile</id>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-extension-processor</artifactId>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
<annotationProcessorPathsUseDepMgmt>true</annotationProcessorPathsUseDepMgmt>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -1,40 +0,0 @@
|
||||
package fr.codeanddata.semrack.rest.client.runtime;
|
||||
|
||||
import fr.codeanddata.semrack.models.*;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
|
||||
import org.jboss.resteasy.reactive.RestPath;
|
||||
|
||||
@Path("/documents")
|
||||
@RegisterRestClient(configKey="semrack-api")
|
||||
public interface SemrackRestClient {
|
||||
@POST
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
Uni<Document> pushDocument(PushDocument semrackDocument);
|
||||
|
||||
@POST
|
||||
@Path("/search")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
Uni<SearchResult> searchDocument(Search query);
|
||||
|
||||
@GET
|
||||
@Path("{uid}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
Uni<Document> getDocument(@RestPath String uid);
|
||||
|
||||
@POST
|
||||
@Path("{uid}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
Uni<Document> getDocument(@RestPath String uid, StorageGet request);
|
||||
|
||||
@POST
|
||||
@Path("{uid}/update")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
Uni<Document> updateDocument(@RestPath String uid, PushDocument semrackDocument);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
name: Semrack Rest Client
|
||||
#description: Do something useful.
|
||||
metadata:
|
||||
# keywords:
|
||||
# - semrack-rest-client
|
||||
# guide: ... # To create and publish this guide, see https://github.com/quarkiverse/quarkiverse/wiki#documenting-your-extension
|
||||
# categories:
|
||||
# - "miscellaneous"
|
||||
# status: "preview"
|
||||
@@ -1,2 +0,0 @@
|
||||
semrack.rest.client.url=http://localhost:8080/semrack
|
||||
quarkus.rest-client.semrack-api.url=semrack.rest.client.url
|
||||
@@ -45,16 +45,6 @@
|
||||
<artifactId>quarkus-junit5-internal</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-junit5</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-test-vertx</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-core-testing</artifactId>
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
package fr.codeanddata.semrack.storage.postgres.storage;
|
||||
|
||||
import fr.codeanddata.semrack.models.StorageGet;
|
||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.vertx.RunOnVertxContext;
|
||||
import io.quarkus.test.vertx.UniAsserter;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@QuarkusTest
|
||||
public class JpaStorageTest {
|
||||
@Inject
|
||||
JpaStorage jpaStorage;
|
||||
|
||||
@Test
|
||||
@RunOnVertxContext
|
||||
void testJpaStorageGetDefault(UniAsserter asserter) {
|
||||
asserter.assertThat(
|
||||
() -> Panache.withSession(() -> jpaStorage.get("doc-001", StorageGet.builder().build())),
|
||||
doc -> {
|
||||
assert doc != null;
|
||||
assert "doc-001".equals(doc.getUid());
|
||||
assert doc.getAnnotations() == null;
|
||||
assert doc.getMetadata() == null;
|
||||
assert doc.getFields() == null;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RunOnVertxContext
|
||||
void testJpaStorageGetWithAnnotationsAndMetadata(UniAsserter asserter) {
|
||||
asserter.assertThat(
|
||||
() -> Panache.withSession(() -> jpaStorage.get("doc-001", StorageGet.builder()
|
||||
.annotationsSource(true)
|
||||
.metadataSource(true)
|
||||
.build())),
|
||||
doc -> {
|
||||
assert doc != null;
|
||||
assert doc.getAnnotations() != null;
|
||||
assert doc.getMetadata() != null;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RunOnVertxContext
|
||||
void testJpaStorageGetWithFields(UniAsserter asserter) {
|
||||
asserter.assertThat(
|
||||
() -> Panache.withSession(() -> jpaStorage.get("doc-001", StorageGet.builder()
|
||||
.fields(Map.of(
|
||||
"title", "title",
|
||||
"content", "content",
|
||||
"sku", "product.sku"
|
||||
))
|
||||
.build())),
|
||||
doc -> {
|
||||
assert doc != null;
|
||||
assert doc.getFields() != null;
|
||||
assert doc.getFields().containsKey("title");
|
||||
assert "Test Document".equals(doc.getFields().get("title"));
|
||||
assert doc.getFields().containsKey("content");
|
||||
assert "Hello World".equals(doc.getFields().get("content"));
|
||||
assert doc.getFields().containsKey("sku");
|
||||
assert "001".equals(doc.getFields().get("sku"));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package fr.codeanddata.semrack.rest.client.test;
|
||||
package fr.codeanddata.semrack.storage.postgres.test;
|
||||
|
||||
import org.jboss.shrinkwrap.api.ShrinkWrap;
|
||||
import org.jboss.shrinkwrap.api.spec.JavaArchive;
|
||||
@@ -8,7 +8,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import io.quarkus.test.QuarkusDevModeTest;
|
||||
|
||||
public class SemrackRestClientDevModeTest {
|
||||
public class SemrackStoragePostgresDevModeTest {
|
||||
|
||||
// Start hot reload (DevMode) test with your extension loaded
|
||||
@RegisterExtension
|
||||
@@ -0,0 +1,23 @@
|
||||
package fr.codeanddata.semrack.storage.postgres.test;
|
||||
|
||||
import org.jboss.shrinkwrap.api.ShrinkWrap;
|
||||
import org.jboss.shrinkwrap.api.spec.JavaArchive;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import io.quarkus.test.QuarkusUnitTest;
|
||||
|
||||
public class SemrackStoragePostgresTest {
|
||||
|
||||
// Start unit test with your extension loaded
|
||||
@RegisterExtension
|
||||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest()
|
||||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
|
||||
|
||||
@Test
|
||||
public void writeYourOwnUnitTest() {
|
||||
// Write your unit tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-extensions for more information
|
||||
Assertions.assertTrue(true, "Add some assertions to " + getClass().getName());
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
quarkus.flyway.enabled=false
|
||||
quarkus.hibernate-orm.schema-management.strategy=drop-and-create
|
||||
quarkus.hibernate-orm.sql-load-script=import.sql
|
||||
@@ -1,5 +0,0 @@
|
||||
INSERT INTO semrack_document (id, uid, document)
|
||||
VALUES (nextval('semrack_document_SEQ'), 'doc-001',
|
||||
'{"uid":"doc-001","annotations":{"category":"test"},"metadata":{"product":{"sku":"001"},"title":"Test Document","content":"Hello World"}}'),
|
||||
(nextval('semrack_document_SEQ'), 'doc-002',
|
||||
'{"uid":"doc-002","annotations":{"category":"test"},"metadata":{"product":{"sku":"002"},"title":"Test Document 2","content":"Hello World 2"}}');
|
||||
@@ -4,9 +4,9 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-bom</artifactId>
|
||||
<artifactId>semrack-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../../bom/pom.xml</relativePath>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>semrack-storage-postgres-parent</artifactId>
|
||||
<name>Semrack Storage Postgres - Parent</name>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package fr.codeanddata.semrack.storage.postgres.entities;
|
||||
|
||||
import fr.codeanddata.semrack.models.Document;
|
||||
import fr.codeanddata.semrack.core.models.SemrackDocument;
|
||||
import io.quarkus.hibernate.reactive.panache.PanacheEntity;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
@@ -23,5 +23,5 @@ public class SemrackDocumentEntity extends PanacheEntity implements Serializable
|
||||
String uid;
|
||||
|
||||
@JdbcTypeCode(SqlTypes.JSON)
|
||||
Document document;
|
||||
SemrackDocument document;
|
||||
}
|
||||
|
||||
@@ -1,148 +0,0 @@
|
||||
package fr.codeanddata.semrack.storage.postgres.storage;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import fr.codeanddata.semrack.Storage;
|
||||
import fr.codeanddata.semrack.models.Document;
|
||||
import fr.codeanddata.semrack.models.StorageGet;
|
||||
import fr.codeanddata.semrack.core.utils.UIDGenerator;
|
||||
import fr.codeanddata.semrack.storage.postgres.entities.SemrackDocumentEntity;
|
||||
import io.quarkus.hibernate.reactive.panache.PanacheRepository;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithTransaction;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ApplicationScoped
|
||||
public class JpaStorage implements Storage, PanacheRepository<SemrackDocumentEntity> {
|
||||
|
||||
@Inject
|
||||
UIDGenerator generator;
|
||||
|
||||
@Inject
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
@WithSession
|
||||
public Uni<Document> get(String uid, StorageGet request) {
|
||||
final List<String> fields = selectFields(request);
|
||||
return getSession()
|
||||
.chain(session -> session.createNativeQuery("select " + String.join(",", fields) + " from semrack_document where uid = ?1")
|
||||
.setParameter(1, uid)
|
||||
.getSingleResult())
|
||||
.map(result -> mapDocument(result, request));
|
||||
}
|
||||
|
||||
@Override
|
||||
@WithSession
|
||||
public Uni<List<Document>> get(List<String> uids, StorageGet request) {
|
||||
final List<String> fields = selectFields(request);
|
||||
return getSession()
|
||||
.chain(session -> session.createNativeQuery("select " + String.join(",", fields) + " from semrack_document where uid in ?1")
|
||||
.setParameter(1, uids)
|
||||
.getResultList())
|
||||
.map(results -> mapDocuments(results, request));
|
||||
}
|
||||
|
||||
@WithTransaction
|
||||
@Override
|
||||
public Uni<Document> storeDocument(Document document) {
|
||||
if (document.getUid() == null) {
|
||||
return createDocument(document)
|
||||
.call(this::flush);
|
||||
} else {
|
||||
return find("uid = ?1", document.getUid())
|
||||
.count()
|
||||
.chain(n -> n == 0 ? createDocument(document) : updateDocument(document))
|
||||
.call(this::flush);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO err : handle existing document
|
||||
@WithTransaction
|
||||
Uni<Document> createDocument(Document document) {
|
||||
final String uid = document.getUid() == null ? generator.apply(document) : document.getUid();
|
||||
document.setUid(uid);
|
||||
final SemrackDocumentEntity entity = SemrackDocumentEntity.builder()
|
||||
.uid(uid)
|
||||
.document(document)
|
||||
.build();
|
||||
return persist(entity).map(SemrackDocumentEntity::getDocument);
|
||||
}
|
||||
|
||||
// TODO err : document not exists
|
||||
@WithTransaction
|
||||
Uni<Document> updateDocument(Document document) {
|
||||
return update("uid = ?1, document = ?2 WHERE uid = ?1", document.getUid(), document)
|
||||
.map(x -> document);
|
||||
}
|
||||
|
||||
List<String> selectFields(StorageGet request) {
|
||||
final List<String> fields = new ArrayList<>(List.of(
|
||||
"uid as _uid",
|
||||
(Optional.ofNullable(request.getAnnotationsSource()).orElse(false) ? "document->'annotations'" : "null") + " as _annotations",
|
||||
(Optional.ofNullable(request.getMetadataSource()).orElse(false) ? "document->'metadata'" : "null") + " as _metadata"
|
||||
));
|
||||
|
||||
if (request.getFields() != null) {
|
||||
int i = 0;
|
||||
for (String field : request.getFields().values()) {
|
||||
fields.add("jsonb_path_query(document, '$.metadata." + field + "') as field_" + i++);
|
||||
}
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
Document mapDocument(Object result, StorageGet request) {
|
||||
final Map<String, Integer> fieldMap = buildFieldMap(request);
|
||||
final List<Object> resultList = objectMapper.convertValue(result, new TypeReference<>() {
|
||||
});
|
||||
final Object oAnnotations = resultList.get(fieldMap.get("_annotations"));
|
||||
final Object oMetadata = resultList.get(fieldMap.get("_metadata"));
|
||||
final Map<String, Object> annotations = oAnnotations == null ? null : objectMapper.convertValue(oAnnotations, new TypeReference<>() {
|
||||
});
|
||||
final Map<String, Object> metadata = oMetadata == null ? null : objectMapper.convertValue(oMetadata, new TypeReference<>() {
|
||||
});
|
||||
|
||||
final Map<String, Object> fields = new HashMap<>();
|
||||
if (request.getFields() != null) {
|
||||
for (final String field : request.getFields().keySet()) {
|
||||
fields.put(field, resultList.get(fieldMap.get(field)));
|
||||
}
|
||||
}
|
||||
|
||||
return Document.builder()
|
||||
.uid((String) resultList.get(fieldMap.get("_uid")))
|
||||
.annotations(annotations)
|
||||
.metadata(metadata)
|
||||
.fields(fields.isEmpty() ? null : fields)
|
||||
.build();
|
||||
}
|
||||
|
||||
List<Document> mapDocuments(List<Object> results, StorageGet request) {
|
||||
return results.stream().map(doc -> mapDocument(doc, request)).toList();
|
||||
}
|
||||
|
||||
Map<String, Integer> buildFieldMap(StorageGet request) {
|
||||
final Map<String, Integer> fieldsMap = new HashMap<>(Map.of(
|
||||
"_uid", 0,
|
||||
"_annotations", 1,
|
||||
"_metadata", 2
|
||||
));
|
||||
|
||||
if (request.getFields() != null) {
|
||||
Integer i = 3;
|
||||
for (String field : request.getFields().keySet()) {
|
||||
fieldsMap.put(field, i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return fieldsMap;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package fr.codeanddata.semrack.storage.postgres.storage;
|
||||
|
||||
import fr.codeanddata.semrack.core.SemdocStorage;
|
||||
import fr.codeanddata.semrack.core.models.SemrackDocument;
|
||||
import fr.codeanddata.semrack.core.services.SemrackLookupService;
|
||||
import fr.codeanddata.semrack.core.utils.UIDGenerator;
|
||||
import fr.codeanddata.semrack.storage.postgres.entities.SemrackDocumentEntity;
|
||||
import io.quarkus.hibernate.reactive.panache.PanacheRepository;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithTransaction;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@ApplicationScoped
|
||||
public class SemdocJpaStorage implements SemdocStorage, PanacheRepository<SemrackDocumentEntity> {
|
||||
|
||||
@Inject
|
||||
UIDGenerator generator;
|
||||
|
||||
@Inject
|
||||
SemrackLookupService lookupService;
|
||||
|
||||
@Override
|
||||
@WithSession
|
||||
public Uni<SemrackDocument> get(String uid) {
|
||||
return find("uid = ?1", uid)
|
||||
.firstResult().map(d -> Optional.ofNullable(d).map(SemrackDocumentEntity::getDocument).orElse(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
@WithSession
|
||||
public Uni<List<SemrackDocument>> get(List<String> uids) {
|
||||
return find("uid in ?1", uids).list()
|
||||
.map(d -> d.stream().map(SemrackDocumentEntity::getDocument).toList());
|
||||
}
|
||||
|
||||
@WithTransaction
|
||||
@Override
|
||||
public Uni<SemrackDocument> storeDocument(SemrackDocument document) {
|
||||
if (document.getUid() == null) {
|
||||
return createDocument(document);
|
||||
} else {
|
||||
return find("uid = ?1", document.getUid())
|
||||
.count()
|
||||
.chain(n -> n == 0 ? createDocument(document) : updateDocument(document));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO err : handle existing document
|
||||
@WithTransaction
|
||||
Uni<SemrackDocument> createDocument(SemrackDocument document) {
|
||||
final String uid = document.getUid() == null ? generator.apply(document) : document.getUid();
|
||||
document.setUid(uid);
|
||||
final SemrackDocumentEntity entity = SemrackDocumentEntity.builder()
|
||||
.uid(uid)
|
||||
.document(document)
|
||||
.build();
|
||||
return persist(entity).map(SemrackDocumentEntity::getDocument);
|
||||
}
|
||||
|
||||
// TODO err : document not exists
|
||||
@WithTransaction
|
||||
Uni<SemrackDocument> updateDocument(SemrackDocument document) {
|
||||
return update("uid = ?1, document = ?2 WHERE uid = ?1", document.getUid(), document)
|
||||
.map(x -> document);
|
||||
}
|
||||
|
||||
// Uni<SearchResult> search(SearchRequest request) {
|
||||
// final String baseQuery = buildBaseQuery(request);
|
||||
//
|
||||
// final StringBuilder sorting = new StringBuilder();
|
||||
// if (request.getSort() != null && !request.getSort().isEmpty()) {
|
||||
// sorting.append(" ORDER BY ");
|
||||
// sorting.append(String.join(", ", request.getSort().stream().map(sort -> sort.getField() + " " + Optional.ofNullable(sort.getDirection()).orElse(SemrackSortDirection.asc).name()).toList()));
|
||||
// }
|
||||
//
|
||||
// final StringBuilder paginate = new StringBuilder();
|
||||
// if (request.getPaginate() != null) {
|
||||
// final SemrackPagination pagination = request.getPaginate();
|
||||
// final Integer size = pagination.getSize() == null ? 200 : pagination.getSize();
|
||||
// final Integer page = pagination.getPage() == null ? 0 : pagination.getPage();
|
||||
//
|
||||
// paginate.append(" LIMIT ").append(size).append(" OFFSET ").append(size * page);
|
||||
// }
|
||||
//
|
||||
// return getSession()
|
||||
// .chain(s -> {
|
||||
// final SearchResult searchResult = SearchResult.builder().build();
|
||||
// return countDocuments(request)
|
||||
// .invoke(count -> searchResult.setPagination(PaginationInfo.builder()
|
||||
// .page(Optional.ofNullable(request.getPaginate()).map(SemrackPagination::getPage).orElse(0))
|
||||
// .size(Optional.ofNullable(request.getPaginate()).map(SemrackPagination::getSize).orElse(0))
|
||||
// .total(count)
|
||||
// .build()))
|
||||
// .call(() -> s
|
||||
// .createNativeQuery(baseQuery + sorting + paginate, Object.class).getResultList()
|
||||
// .invoke(results -> searchResult.setDocuments(project(request.getFields(), results))))
|
||||
// .map(count -> searchResult);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// String buildBaseQuery(SearchRequest request) {
|
||||
// final String lookup = lookupService.lookup(request.getFilter());
|
||||
// final String whereClause = lookup.isEmpty() ? "" : " WHERE " + lookup;
|
||||
//
|
||||
// if (request.getFields() == null || request.getFields().isEmpty()) {
|
||||
// return "SELECT document FROM semrack_document" + whereClause;
|
||||
// } else {
|
||||
// return "SELECT " + toJsonbPathExtract(request.getFields()) + " FROM semrack_document" + whereClause;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// String toJsonbPathExtract(List<String> fields) {
|
||||
// return String.join(",", fields.stream().map(field -> {
|
||||
// final String serializedField = "'" + String.join("','", field.split("\\.")) + "'";
|
||||
// return "jsonb_extract_path(document, " + serializedField + ")";
|
||||
// }).toList());
|
||||
// }
|
||||
//
|
||||
// List<SemrackDocument> project(List<String> fields, Object results) {
|
||||
// final List<?> projectedResults = objectMapper.convertValue(results, List.class);
|
||||
// if (fields == null || fields.isEmpty()) {
|
||||
// return projectedResults.stream().map(result -> objectMapper.convertValue(result, SemrackDocument.class)).toList();
|
||||
// } else {
|
||||
// return projectedResults.stream().map(result -> {
|
||||
// final List<Object> row = fields.size() == 1 ? List.of(result) : objectMapper.convertValue(result, new TypeReference<>() {
|
||||
// });
|
||||
// final List<Object> rowMut = new ArrayList<>(row);
|
||||
// final List<String> fieldCp = new ArrayList<>(fields);
|
||||
// final Map<String, Object> document = new HashMap<>();
|
||||
// while (!fieldCp.isEmpty() && !row.isEmpty()) {
|
||||
// final String field = fieldCp.removeFirst();
|
||||
// final Object value = rowMut.removeFirst();
|
||||
// pathMapper.map(field, document, value);
|
||||
// }
|
||||
// return objectMapper.convertValue(document, SemrackDocument.class);
|
||||
// }).toList();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
147
pom.xml
147
pom.xml
@@ -6,18 +6,157 @@
|
||||
<artifactId>semrack-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Parent</name>
|
||||
|
||||
<modules>
|
||||
<module>bom</module>
|
||||
<module>domain</module>
|
||||
<module>modules/semrack-core</module>
|
||||
<module>modules/semrack-index-postgres</module>
|
||||
<module>modules/semrack-storage-postgres</module>
|
||||
<module>modules/semrack-api-rest</module>
|
||||
<module>modules/semrack-rest-client</module>
|
||||
<!-- <module>integration/semrack-integration</module>-->
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<!-- Quarkus project basics -->
|
||||
<compiler-plugin.version>3.14.0</compiler-plugin.version>
|
||||
<maven.compiler.release>21</maven.compiler.release>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
|
||||
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
|
||||
<quarkus.platform.version>${quarkus.version}</quarkus.platform.version>
|
||||
<skipITs>true</skipITs>
|
||||
<surefire-plugin.version>3.5.3</surefire-plugin.version>
|
||||
|
||||
<!-- Other properties -->
|
||||
<commons-codec.version>1.16.0</commons-codec.version>
|
||||
<jsonpath.version>2.9.0</jsonpath.version>
|
||||
<lombok.version>1.18.38</lombok.version>
|
||||
<org.mapstruct.version>1.6.3</org.mapstruct.version>
|
||||
<quarkus.version>3.29.4</quarkus.version>
|
||||
<semrack.version>${project.version}</semrack.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${quarkus.platform.group-id}</groupId>
|
||||
<artifactId>${quarkus.platform.artifact-id}</artifactId>
|
||||
<version>${quarkus.platform.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>${commons-codec.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId>
|
||||
<version>${org.mapstruct.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- SEMRACK -->
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-core</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-core-testing</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-core-deployment</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-index-postgres</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-index-postgres-deployment</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-storage-postgres</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-storage-postgres-deployment</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-api-rest</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.codeanddata.semrack</groupId>
|
||||
<artifactId>semrack-api-rest-deployment</artifactId>
|
||||
<version>${semrack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jayway.jsonpath</groupId>
|
||||
<artifactId>json-path</artifactId>
|
||||
<version>${jsonpath.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-maven-plugin</artifactId>
|
||||
<version>${quarkus.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<maven.home>${maven.home}</maven.home>
|
||||
<maven.repo>${settings.localRepository}</maven.repo>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>${failsafe-plugin.version}</version>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<maven.home>${maven.home}</maven.home>
|
||||
<maven.repo>${settings.localRepository}</maven.repo>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<parameters>true</parameters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>gitea</id>
|
||||
|
||||
Reference in New Issue
Block a user