[DEV] add simple test and update archidata refacto
This commit is contained in:
parent
9c8def3341
commit
2e24175899
7
back/.checkstyle
Normal file
7
back/.checkstyle
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
|
||||||
|
<fileset name="all" enabled="true" check-config-name="Google Checks" local="false">
|
||||||
|
<file-match-pattern match-pattern="." include-pattern="true"/>
|
||||||
|
</fileset>
|
||||||
|
</fileset-config>
|
@ -5,11 +5,11 @@ COPY src /tmp/src/
|
|||||||
WORKDIR /tmp/
|
WORKDIR /tmp/
|
||||||
RUN mvn clean compile assembly:single
|
RUN mvn clean compile assembly:single
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FROM bellsoft/liberica-openjdk-alpine:latest
|
FROM bellsoft/liberica-openjdk-alpine:latest
|
||||||
ENV LANG=C.UTF-8
|
ENV LANG=C.UTF-8
|
||||||
|
|
||||||
|
# add wget to manage the health check...
|
||||||
|
RUN apk add --no-cache wget
|
||||||
|
|
||||||
RUN mkdir /application/
|
RUN mkdir /application/
|
||||||
COPY --from=build /tmp/out/maven/*.jar /application/application.jar
|
COPY --from=build /tmp/out/maven/*.jar /application/application.jar
|
||||||
|
@ -2,10 +2,18 @@ Generic backend for karideo in java
|
|||||||
===================================
|
===================================
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mvn install
|
mvn install
|
||||||
|
|
||||||
|
mvn compile
|
||||||
|
|
||||||
|
mvn package
|
||||||
|
|
||||||
|
// download all dependency in out/maven/dependency
|
||||||
|
mvn dependency:copy-dependencies
|
||||||
|
|
||||||
|
java -cp out/maven/kar-karideo-0.1.0.jar org.kar.karideo.WebLauncher
|
||||||
|
|
||||||
|
|
||||||
// create a single package jar
|
// create a single package jar
|
||||||
mvn clean compile assembly:single
|
mvn clean compile assembly:single
|
||||||
|
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_14">
|
|
||||||
<output url="file://$MODULE_DIR$/out/maven/classes" />
|
|
||||||
<output-test url="file://$MODULE_DIR$/out/maven/test-classes" />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/test/src" isTestSource="true" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/out/maven" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.jersey.media:jersey-media-multipart:2.32" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-common:2.32" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: jakarta.annotation:jakarta.annotation-api:1.3.5" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.hk2:osgi-resource-locator:1.0.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.sun.activation:jakarta.activation:1.2.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.jvnet.mimepull:mimepull:1.9.13" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.jersey.inject:jersey-hk2:2.32" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-locator:2.6.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.hk2.external:aopalliance-repackaged:2.6.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-api:2.6.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-utils:2.6.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.javassist:javassist:3.25.0-GA" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.32" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.hk2.external:jakarta.inject:2.6.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.grizzly:grizzly-http-server:2.4.4" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.grizzly:grizzly-http:2.4.4" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.grizzly:grizzly-framework:2.4.4" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-server:2.32" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-client:2.32" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.jersey.media:jersey-media-jaxb:2.32" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: jakarta.validation:jakarta.validation-api:2.0.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: jakarta.xml.bind:jakarta.xml.bind-api:2.3.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: jakarta.ws.rs:jakarta.ws.rs-api:2.1.6" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: javax.xml.bind:jaxb-api:2.3.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: javax.activation:javax.activation-api:1.2.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: javax.ws.rs:javax.ws.rs-api:2.1.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-impl:2.3.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.sun.istack:istack-commons-runtime:3.0.7" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-grizzly2:2.32" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: jakarta.servlet:jakarta.servlet-api:4.0.3" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.jersey.test-framework:jersey-test-framework-core:2.32" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.jersey.containers:jersey-container-servlet-core:2.32" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.jersey.containers:jersey-container-grizzly2-servlet:2.32" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.jersey.containers:jersey-container-servlet:2.32" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.grizzly:grizzly-http-servlet:2.4.4" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.45" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.jersey.media:jersey-media-json-jackson:2.32" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.glassfish.jersey.ext:jersey-entity-filtering:2.32" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.10.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.10.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: jakarta.activation:jakarta.activation-api:1.2.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.10" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.10" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:3.0.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.jetbrains:annotations:20.1.0" level="project" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@ -1,12 +0,0 @@
|
|||||||
/** Basic module interface.
|
|
||||||
*
|
|
||||||
* @author Edouard DUPIN */
|
|
||||||
|
|
||||||
open module io.scenarium.store {
|
|
||||||
exports io.scenarium.oauth;
|
|
||||||
requires java.util;
|
|
||||||
requires javax.ws.rs.api;
|
|
||||||
requires java.xml.bind;
|
|
||||||
requires jackson.annotations;
|
|
||||||
requires jersey.server;
|
|
||||||
}
|
|
119
back/pom.xml
119
back/pom.xml
@ -1,8 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>kar</groupId>
|
<groupId>org.kar</groupId>
|
||||||
<artifactId>karideo</artifactId>
|
<artifactId>karideo</artifactId>
|
||||||
<version>0.2.0</version>
|
<version>0.2.0</version>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.version>3.1</maven.compiler.version>
|
<maven.compiler.version>3.1</maven.compiler.version>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
@ -15,7 +16,6 @@
|
|||||||
<url>https://gitea.atria-soft.org/api/packages/kangaroo-and-rabbit/maven</url>
|
<url>https://gitea.atria-soft.org/api/packages/kangaroo-and-rabbit/maven</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>kangaroo-and-rabbit</groupId>
|
<groupId>kangaroo-and-rabbit</groupId>
|
||||||
@ -26,20 +26,39 @@
|
|||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-simple</artifactId>
|
<artifactId>slf4j-simple</artifactId>
|
||||||
<version>2.0.7</version>
|
<version>2.0.7</version>
|
||||||
<!--<scope>test</scope>-->
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
<!--
|
||||||
|
************************************************************
|
||||||
|
** TEST dependency **
|
||||||
|
************************************************************
|
||||||
|
-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<version>5.10.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>5.10.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src</sourceDirectory>
|
<sourceDirectory>src</sourceDirectory>
|
||||||
<testSourceDirectory>test/src</testSourceDirectory>
|
<testSourceDirectory>test/src</testSourceDirectory>
|
||||||
<directory>${project.basedir}/out/maven/</directory>
|
<directory>${project.basedir}/out/maven/</directory>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>src/resources</directory>
|
<directory>src/resources</directory>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
<testResources>
|
||||||
|
<testResource>
|
||||||
|
<directory>${basedir}/test/resources</directory>
|
||||||
|
</testResource>
|
||||||
|
</testResources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
@ -48,16 +67,15 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<source>${maven.compiler.source}</source>
|
<source>${maven.compiler.source}</source>
|
||||||
<target>${maven.compiler.target}</target>
|
<target>${maven.compiler.target}</target>
|
||||||
<!--<encoding>${project.build.sourceEncoding}</encoding>-->
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
<version>1.4.0</version>
|
<version>1.4.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<mainClass>org.kar.karideo.WebLauncher</mainClass>
|
<mainClass>org.kar.karideo.WebLauncher</mainClass>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- Create the source bundle -->
|
<!-- Create the source bundle -->
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -79,27 +97,28 @@
|
|||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>3.0.0-M5</version>
|
<version>3.0.0-M5</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
<mainClass>fully.qualified.MainClass</mainClass>
|
<mainClass>fully.qualified.MainClass</mainClass>
|
||||||
</manifest>
|
</manifest>
|
||||||
</archive>
|
</archive>
|
||||||
<descriptorRefs>
|
<descriptorRefs>
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
</descriptorRefs>
|
</descriptorRefs>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- Create coverage -->
|
<!-- Create coverage -->
|
||||||
<!--
|
<!--
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.jacoco</groupId>
|
<groupId>org.jacoco</groupId>
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
<version>0.8.5</version>
|
<version>0.8.10</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
|
<id>prepare-agent</id>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>prepare-agent</goal>
|
<goal>prepare-agent</goal>
|
||||||
</goals>
|
</goals>
|
||||||
@ -111,6 +130,26 @@
|
|||||||
<goal>report</goal>
|
<goal>report</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>jacoco-check</id>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<rules>
|
||||||
|
<rule>
|
||||||
|
<element>PACKAGE</element>
|
||||||
|
<limits>
|
||||||
|
<limit>
|
||||||
|
<counter>LINE</counter>
|
||||||
|
<value>COVEREDRATIO</value>
|
||||||
|
<minimum>0.50</minimum>
|
||||||
|
</limit>
|
||||||
|
</limits>
|
||||||
|
</rule>
|
||||||
|
</rules>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
-->
|
-->
|
||||||
@ -124,6 +163,23 @@
|
|||||||
<nohelp>true</nohelp>
|
<nohelp>true</nohelp>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>exec-application</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>java</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<mainClass>org.kar.karideo.WebLauncher</mainClass>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
<!-- Check the style of the code -->
|
<!-- Check the style of the code -->
|
||||||
<!--
|
<!--
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -181,5 +237,4 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</reporting>
|
</reporting>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -40,6 +40,7 @@ public class WebLauncher {
|
|||||||
final static Logger LOGGER = LoggerFactory.getLogger(WebLauncher.class);
|
final static Logger LOGGER = LoggerFactory.getLogger(WebLauncher.class);
|
||||||
public static DBConfig dbConfig;
|
public static DBConfig dbConfig;
|
||||||
protected UpdateJwtPublicKey keyUpdater = null;
|
protected UpdateJwtPublicKey keyUpdater = null;
|
||||||
|
protected HttpServer server = null;
|
||||||
|
|
||||||
public WebLauncher() {
|
public WebLauncher() {
|
||||||
ConfigBaseVariable.bdDatabase = "karideo";
|
ConfigBaseVariable.bdDatabase = "karideo";
|
||||||
@ -51,7 +52,7 @@ public class WebLauncher {
|
|||||||
|
|
||||||
public void migrateDB() throws Exception {
|
public void migrateDB() throws Exception {
|
||||||
WebLauncher.LOGGER.info("Create migration engine");
|
WebLauncher.LOGGER.info("Create migration engine");
|
||||||
MigrationEngine migrationEngine = new MigrationEngine();
|
final MigrationEngine migrationEngine = new MigrationEngine();
|
||||||
WebLauncher.LOGGER.info("Add initialization");
|
WebLauncher.LOGGER.info("Add initialization");
|
||||||
migrationEngine.setInit(new Initialization());
|
migrationEngine.setInit(new Initialization());
|
||||||
WebLauncher.LOGGER.info("Add migration since last version");
|
WebLauncher.LOGGER.info("Add migration since last version");
|
||||||
@ -62,9 +63,9 @@ public class WebLauncher {
|
|||||||
WebLauncher.LOGGER.info("Migrate the DB [STOP]");
|
WebLauncher.LOGGER.info("Migrate the DB [STOP]");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(final String[] args) throws Exception {
|
||||||
WebLauncher.LOGGER.info("[START] application wake UP");
|
WebLauncher.LOGGER.info("[START] application wake UP");
|
||||||
WebLauncher launcher = new WebLauncher();
|
final WebLauncher launcher = new WebLauncher();
|
||||||
launcher.migrateDB();
|
launcher.migrateDB();
|
||||||
launcher.process();
|
launcher.process();
|
||||||
WebLauncher.LOGGER.info("end-configure the server & wait finish process:");
|
WebLauncher.LOGGER.info("end-configure the server & wait finish process:");
|
||||||
@ -79,7 +80,7 @@ public class WebLauncher {
|
|||||||
// ===================================================================
|
// ===================================================================
|
||||||
// Configure resources
|
// Configure resources
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
ResourceConfig rc = new ResourceConfig();
|
final ResourceConfig rc = new ResourceConfig();
|
||||||
|
|
||||||
// add multi-part models ..
|
// add multi-part models ..
|
||||||
rc.register(MultiPartFeature.class);
|
rc.register(MultiPartFeature.class);
|
||||||
@ -111,12 +112,13 @@ public class WebLauncher {
|
|||||||
// enable this to show low level request
|
// enable this to show low level request
|
||||||
//rc.property(LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_SERVER, Level.WARNING.getName());
|
//rc.property(LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_SERVER, Level.WARNING.getName());
|
||||||
|
|
||||||
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc);
|
this.server = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc);
|
||||||
|
final HttpServer serverLink = this.server;
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
System.out.println("Stopping server..");
|
System.out.println("Stopping server..");
|
||||||
server.shutdownNow();
|
serverLink.shutdownNow();
|
||||||
}
|
}
|
||||||
}, "shutdownHook"));
|
}, "shutdownHook"));
|
||||||
|
|
||||||
@ -124,25 +126,32 @@ public class WebLauncher {
|
|||||||
// start periodic update of the token ...
|
// start periodic update of the token ...
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
this.keyUpdater = new UpdateJwtPublicKey();
|
this.keyUpdater = new UpdateJwtPublicKey();
|
||||||
keyUpdater.start();
|
this.keyUpdater.start();
|
||||||
|
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
// run JERSEY
|
// run JERSEY
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
try {
|
try {
|
||||||
server.start();
|
this.server.start();
|
||||||
LOGGER.info("Jersey app started at {}", getBaseURI());
|
LOGGER.info("Jersey app started at {}", getBaseURI());
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
LOGGER.error("There was an error while starting Grizzly HTTP server.");
|
LOGGER.error("There was an error while starting Grizzly HTTP server.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
if (this.server != null) {
|
||||||
|
this.server.shutdownNow();
|
||||||
|
this.server = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void stopOther() {
|
public void stopOther() {
|
||||||
keyUpdater.kill();
|
this.keyUpdater.kill();
|
||||||
try {
|
try {
|
||||||
keyUpdater.join(4000, 0);
|
this.keyUpdater.join(4000, 0);
|
||||||
} catch (InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,32 @@
|
|||||||
package org.kar.karideo.api;
|
package org.kar.karideo.api;
|
||||||
|
|
||||||
import org.kar.archidata.annotation.security.PermitAll;
|
import org.kar.archidata.exception.FailException;
|
||||||
|
import org.kar.archidata.util.ConfigBaseVariable;
|
||||||
import jakarta.ws.rs.*;
|
|
||||||
import jakarta.ws.rs.core.MediaType;
|
|
||||||
import jakarta.ws.rs.core.Response;
|
|
||||||
|
|
||||||
import org.kar.archidata.util.JWTWrapper;
|
import org.kar.archidata.util.JWTWrapper;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import jakarta.annotation.security.PermitAll;
|
||||||
|
import jakarta.ws.rs.GET;
|
||||||
|
import jakarta.ws.rs.Path;
|
||||||
|
import jakarta.ws.rs.Produces;
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
|
||||||
@Path("/health_check")
|
@Path("/health_check")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public class HealthCheck {
|
public class HealthCheck {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(HealthCheck.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(HealthCheck.class);
|
||||||
public class HealthResult {
|
|
||||||
public String value;
|
public record HealthResult(
|
||||||
public HealthResult(String value) {
|
String value) {};
|
||||||
this.value = value;
|
|
||||||
|
@GET
|
||||||
|
@PermitAll
|
||||||
|
public HealthResult getHealth() throws FailException {
|
||||||
|
if (JWTWrapper.getPublicKeyJson() == null && !ConfigBaseVariable.getTestMode()) {
|
||||||
|
throw new FailException(Response.Status.INTERNAL_SERVER_ERROR, "Missing Jwt public token");
|
||||||
}
|
}
|
||||||
|
return new HealthResult("alive and kicking");
|
||||||
}
|
}
|
||||||
// todo : do it better...
|
|
||||||
@GET
|
|
||||||
@PermitAll
|
|
||||||
public Response getHealth() {
|
|
||||||
if (JWTWrapper.getPublicKeyJson() == null) {
|
|
||||||
return Response.status(500).entity(new HealthResult("Missing Jwt public token")).build();
|
|
||||||
}
|
|
||||||
return Response.status(200).entity(new HealthResult("alive and kicking")).build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,16 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||||
import org.kar.archidata.annotation.security.RolesAllowed;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
import org.kar.archidata.sqlWrapper.QuerryAnd;
|
import org.kar.archidata.dataAccess.QueryAnd;
|
||||||
import org.kar.archidata.sqlWrapper.QuerryCondition;
|
import org.kar.archidata.dataAccess.QueryCondition;
|
||||||
import org.kar.archidata.sqlWrapper.SqlWrapper;
|
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
|
||||||
import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
|
|
||||||
import org.kar.archidata.util.DataTools;
|
import org.kar.archidata.util.DataTools;
|
||||||
import org.kar.karideo.model.Season;
|
import org.kar.karideo.model.Season;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import jakarta.annotation.security.RolesAllowed;
|
||||||
import jakarta.ws.rs.Consumes;
|
import jakarta.ws.rs.Consumes;
|
||||||
import jakarta.ws.rs.DELETE;
|
import jakarta.ws.rs.DELETE;
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
@ -34,22 +34,22 @@ public class SeasonResource {
|
|||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public static Season getWithId(@PathParam("id") Long id) throws Exception {
|
public static Season getWithId(@PathParam("id") final Long id) throws Exception {
|
||||||
return SqlWrapper.get(Season.class, id);
|
return DataAccess.get(Season.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public List<Season> get() throws Exception {
|
public List<Season> get() throws Exception {
|
||||||
return SqlWrapper.gets(Season.class);
|
return DataAccess.gets(Season.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Season get(@PathParam("id") Long id) throws Exception {
|
public Season get(@PathParam("id") final Long id) throws Exception {
|
||||||
return SqlWrapper.get(Season.class, id);
|
return DataAccess.get(Season.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =============================================================================
|
/* =============================================================================
|
||||||
@ -59,24 +59,24 @@ public class SeasonResource {
|
|||||||
@POST
|
@POST
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Season put(String jsonRequest) throws Exception {
|
public Season put(final String jsonRequest) throws Exception {
|
||||||
return SqlWrapper.insertWithJson(Season.class, jsonRequest);
|
return DataAccess.insertWithJson(Season.class, jsonRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Season put(@PathParam("id") Long id, String jsonRequest) throws Exception {
|
public Season put(@PathParam("id") final Long id, final String jsonRequest) throws Exception {
|
||||||
SqlWrapper.update(Season.class, id, jsonRequest);
|
DataAccess.updateWithJson(Season.class, id, jsonRequest);
|
||||||
return SqlWrapper.get(Season.class, id);
|
return DataAccess.get(Season.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
public Response delete(@PathParam("id") Long id) throws Exception {
|
public Response delete(@PathParam("id") final Long id) throws Exception {
|
||||||
SqlWrapper.delete(Season.class, id);
|
DataAccess.delete(Season.class, id);
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,30 +84,30 @@ public class SeasonResource {
|
|||||||
@Path("{id}/add_cover")
|
@Path("{id}/add_cover")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes({ MediaType.MULTIPART_FORM_DATA })
|
@Consumes({ MediaType.MULTIPART_FORM_DATA })
|
||||||
public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
|
public Response uploadCover(@PathParam("id") final Long id, @FormDataParam("fileName") final String fileName, @FormDataParam("file") final InputStream fileInputStream,
|
||||||
@FormDataParam("file") FormDataContentDisposition fileMetaData) {
|
@FormDataParam("file") final FormDataContentDisposition fileMetaData) {
|
||||||
return DataTools.uploadCover(Season.class, id, fileName, fileInputStream, fileMetaData);
|
return DataTools.uploadCover(Season.class, id, fileName, fileInputStream, fileMetaData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}/rm_cover/{coverId}")
|
@Path("{id}/rm_cover/{coverId}")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
|
public Response removeCover(@PathParam("id") final Long id, @PathParam("coverId") final Long coverId) throws Exception {
|
||||||
AddOnManyToMany.removeLink(Season.class, id, "cover", coverId);
|
AddOnManyToMany.removeLink(Season.class, id, "cover", coverId);
|
||||||
return Response.ok(SqlWrapper.get(Season.class, id)).build();
|
return Response.ok(DataAccess.get(Season.class, id)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Season getOrCreate(String name, Long seriesId) {
|
public static Season getOrCreate(final String name, final Long seriesId) {
|
||||||
try {
|
try {
|
||||||
Season out = SqlWrapper.getWhere(Season.class, new QuerryAnd(new QuerryCondition("name", "=", name), new QuerryCondition("parentId", "=", seriesId)));
|
Season out = DataAccess.getWhere(Season.class, new QueryAnd(new QueryCondition("name", "=", name), new QueryCondition("parentId", "=", seriesId)));
|
||||||
if (out == null) {
|
if (out == null) {
|
||||||
out = new Season();
|
out = new Season();
|
||||||
out.name = name;
|
out.name = name;
|
||||||
out.parentId = seriesId;
|
out.parentId = seriesId;
|
||||||
out = SqlWrapper.insert(out);
|
out = DataAccess.insert(out);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,16 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||||
import org.kar.archidata.annotation.security.RolesAllowed;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
import org.kar.archidata.sqlWrapper.QuerryAnd;
|
import org.kar.archidata.dataAccess.QueryAnd;
|
||||||
import org.kar.archidata.sqlWrapper.QuerryCondition;
|
import org.kar.archidata.dataAccess.QueryCondition;
|
||||||
import org.kar.archidata.sqlWrapper.SqlWrapper;
|
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
|
||||||
import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
|
|
||||||
import org.kar.archidata.util.DataTools;
|
import org.kar.archidata.util.DataTools;
|
||||||
import org.kar.karideo.model.Series;
|
import org.kar.karideo.model.Series;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import jakarta.annotation.security.RolesAllowed;
|
||||||
import jakarta.ws.rs.Consumes;
|
import jakarta.ws.rs.Consumes;
|
||||||
import jakarta.ws.rs.DELETE;
|
import jakarta.ws.rs.DELETE;
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
@ -34,22 +34,22 @@ public class SeriesResource {
|
|||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public static Series getWithId(@PathParam("id") Long id) throws Exception {
|
public static Series getWithId(@PathParam("id") final Long id) throws Exception {
|
||||||
return SqlWrapper.get(Series.class, id);
|
return DataAccess.get(Series.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public List<Series> get() throws Exception {
|
public List<Series> get() throws Exception {
|
||||||
return SqlWrapper.gets(Series.class);
|
return DataAccess.gets(Series.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Series get(@PathParam("id") Long id) throws Exception {
|
public Series get(@PathParam("id") final Long id) throws Exception {
|
||||||
return SqlWrapper.get(Series.class, id);
|
return DataAccess.get(Series.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =============================================================================
|
/* =============================================================================
|
||||||
@ -59,24 +59,24 @@ public class SeriesResource {
|
|||||||
@POST
|
@POST
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Series put(String jsonRequest) throws Exception {
|
public Series put(final String jsonRequest) throws Exception {
|
||||||
return SqlWrapper.insertWithJson(Series.class, jsonRequest);
|
return DataAccess.insertWithJson(Series.class, jsonRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Series put(@PathParam("id") Long id, String jsonRequest) throws Exception {
|
public Series put(@PathParam("id") final Long id, final String jsonRequest) throws Exception {
|
||||||
SqlWrapper.update(Series.class, id, jsonRequest);
|
DataAccess.updateWithJson(Series.class, id, jsonRequest);
|
||||||
return SqlWrapper.get(Series.class, id);
|
return DataAccess.get(Series.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
public Response delete(@PathParam("id") Long id) throws Exception {
|
public Response delete(@PathParam("id") final Long id) throws Exception {
|
||||||
SqlWrapper.delete(Series.class, id);
|
DataAccess.delete(Series.class, id);
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,30 +84,30 @@ public class SeriesResource {
|
|||||||
@Path("{id}/add_cover")
|
@Path("{id}/add_cover")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes({ MediaType.MULTIPART_FORM_DATA })
|
@Consumes({ MediaType.MULTIPART_FORM_DATA })
|
||||||
public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
|
public Response uploadCover(@PathParam("id") final Long id, @FormDataParam("fileName") final String fileName, @FormDataParam("file") final InputStream fileInputStream,
|
||||||
@FormDataParam("file") FormDataContentDisposition fileMetaData) {
|
@FormDataParam("file") final FormDataContentDisposition fileMetaData) {
|
||||||
return DataTools.uploadCover(Series.class, id, fileName, fileInputStream, fileMetaData);
|
return DataTools.uploadCover(Series.class, id, fileName, fileInputStream, fileMetaData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}/rm_cover/{coverId}")
|
@Path("{id}/rm_cover/{coverId}")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
|
public Response removeCover(@PathParam("id") final Long id, @PathParam("coverId") final Long coverId) throws Exception {
|
||||||
AddOnManyToMany.removeLink(Series.class, id, "cover", coverId);
|
AddOnManyToMany.removeLink(Series.class, id, "cover", coverId);
|
||||||
return Response.ok(SqlWrapper.get(Series.class, id)).build();
|
return Response.ok(DataAccess.get(Series.class, id)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Series getOrCreate(String name, Long typeId) {
|
public static Series getOrCreate(final String name, final Long typeId) {
|
||||||
try {
|
try {
|
||||||
Series out = SqlWrapper.getWhere(Series.class, new QuerryAnd(new QuerryCondition("name", "=", name), new QuerryCondition("parentId", "=", typeId)));
|
Series out = DataAccess.getWhere(Series.class, new QueryAnd(new QueryCondition("name", "=", name), new QueryCondition("parentId", "=", typeId)));
|
||||||
if (out == null) {
|
if (out == null) {
|
||||||
out = new Series();
|
out = new Series();
|
||||||
out.name = name;
|
out.name = name;
|
||||||
out.parentId = typeId;
|
out.parentId = typeId;
|
||||||
out = SqlWrapper.insert(out);
|
out = DataAccess.insert(out);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,15 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||||
import org.kar.archidata.annotation.security.RolesAllowed;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
import org.kar.archidata.sqlWrapper.QuerryCondition;
|
import org.kar.archidata.dataAccess.QueryCondition;
|
||||||
import org.kar.archidata.sqlWrapper.SqlWrapper;
|
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
|
||||||
import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
|
|
||||||
import org.kar.archidata.util.DataTools;
|
import org.kar.archidata.util.DataTools;
|
||||||
import org.kar.karideo.model.Type;
|
import org.kar.karideo.model.Type;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import jakarta.annotation.security.RolesAllowed;
|
||||||
import jakarta.ws.rs.Consumes;
|
import jakarta.ws.rs.Consumes;
|
||||||
import jakarta.ws.rs.DELETE;
|
import jakarta.ws.rs.DELETE;
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
@ -33,26 +33,26 @@ public class TypeResource {
|
|||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public static Type getWithId(@PathParam("id") Long id) throws Exception {
|
public static Type getWithId(@PathParam("id") final Long id) throws Exception {
|
||||||
return SqlWrapper.get(Type.class, id);
|
return DataAccess.get(Type.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public List<Type> get() throws Exception {
|
public List<Type> get() throws Exception {
|
||||||
return SqlWrapper.gets(Type.class);
|
return DataAccess.gets(Type.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Type get(@PathParam("id") Long id) throws Exception {
|
public Type get(@PathParam("id") final Long id) throws Exception {
|
||||||
return SqlWrapper.get(Type.class, id);
|
return DataAccess.get(Type.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Type getId(Long id) throws Exception {
|
public static Type getId(final Long id) throws Exception {
|
||||||
return SqlWrapper.get(Type.class, id);
|
return DataAccess.get(Type.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =============================================================================
|
/* =============================================================================
|
||||||
@ -62,24 +62,24 @@ public class TypeResource {
|
|||||||
@POST
|
@POST
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Type put(String jsonRequest) throws Exception {
|
public Type put(final String jsonRequest) throws Exception {
|
||||||
return SqlWrapper.insertWithJson(Type.class, jsonRequest);
|
return DataAccess.insertWithJson(Type.class, jsonRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Type put(@PathParam("id") Long id, String jsonRequest) throws Exception {
|
public Type put(@PathParam("id") final Long id, final String jsonRequest) throws Exception {
|
||||||
SqlWrapper.update(Type.class, id, jsonRequest);
|
DataAccess.updateWithJson(Type.class, id, jsonRequest);
|
||||||
return SqlWrapper.get(Type.class, id);
|
return DataAccess.get(Type.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
public Response delete(@PathParam("id") Long id) throws Exception {
|
public Response delete(@PathParam("id") final Long id) throws Exception {
|
||||||
SqlWrapper.delete(Type.class, id);
|
DataAccess.delete(Type.class, id);
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,29 +87,29 @@ public class TypeResource {
|
|||||||
@Path("{id}/add_cover")
|
@Path("{id}/add_cover")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes({ MediaType.MULTIPART_FORM_DATA })
|
@Consumes({ MediaType.MULTIPART_FORM_DATA })
|
||||||
public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
|
public Response uploadCover(@PathParam("id") final Long id, @FormDataParam("fileName") final String fileName, @FormDataParam("file") final InputStream fileInputStream,
|
||||||
@FormDataParam("file") FormDataContentDisposition fileMetaData) {
|
@FormDataParam("file") final FormDataContentDisposition fileMetaData) {
|
||||||
return DataTools.uploadCover(Type.class, id, fileName, fileInputStream, fileMetaData);
|
return DataTools.uploadCover(Type.class, id, fileName, fileInputStream, fileMetaData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}/rm_cover/{coverId}")
|
@Path("{id}/rm_cover/{coverId}")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
|
public Response removeCover(@PathParam("id") final Long id, @PathParam("coverId") final Long coverId) throws Exception {
|
||||||
AddOnManyToMany.removeLink(Type.class, id, "cover", coverId);
|
AddOnManyToMany.removeLink(Type.class, id, "cover", coverId);
|
||||||
return Response.ok(SqlWrapper.get(Type.class, id)).build();
|
return Response.ok(DataAccess.get(Type.class, id)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Type getOrCreate(String name) {
|
public static Type getOrCreate(final String name) {
|
||||||
try {
|
try {
|
||||||
Type out = SqlWrapper.getWhere(Type.class, new QuerryCondition("name", "=", name));
|
Type out = DataAccess.getWhere(Type.class, new QueryCondition("name", "=", name));
|
||||||
if (out == null) {
|
if (out == null) {
|
||||||
out = new Type();
|
out = new Type();
|
||||||
out.name = name;
|
out.name = name;
|
||||||
out = SqlWrapper.insert(out);
|
out = DataAccess.insert(out);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,15 @@ package org.kar.karideo.api;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.kar.archidata.annotation.security.RolesAllowed;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.QueryAnd;
|
||||||
|
import org.kar.archidata.dataAccess.QueryCondition;
|
||||||
import org.kar.archidata.filter.GenericContext;
|
import org.kar.archidata.filter.GenericContext;
|
||||||
import org.kar.archidata.sqlWrapper.QuerryAnd;
|
|
||||||
import org.kar.archidata.sqlWrapper.QuerryCondition;
|
|
||||||
import org.kar.archidata.sqlWrapper.SqlWrapper;
|
|
||||||
import org.kar.karideo.model.UserMediaAdvancement;
|
import org.kar.karideo.model.UserMediaAdvancement;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import jakarta.annotation.security.RolesAllowed;
|
||||||
import jakarta.ws.rs.Consumes;
|
import jakarta.ws.rs.Consumes;
|
||||||
import jakarta.ws.rs.DELETE;
|
import jakarta.ws.rs.DELETE;
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
@ -31,16 +31,16 @@ public class UserMediaAdvancementResource {
|
|||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public UserMediaAdvancement getWithId(@Context SecurityContext sc, @PathParam("id") Long id) throws Exception {
|
public UserMediaAdvancement getWithId(@Context final SecurityContext sc, @PathParam("id") final Long id) throws Exception {
|
||||||
GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
final GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
||||||
return SqlWrapper.getWhere(UserMediaAdvancement.class, new QuerryAnd(new QuerryCondition("mediaId", "=", id), new QuerryCondition("userId", "=", gc.userByToken.id)));
|
return DataAccess.getWhere(UserMediaAdvancement.class, new QueryAnd(new QueryCondition("mediaId", "=", id), new QueryCondition("userId", "=", gc.userByToken.id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public List<UserMediaAdvancement> gets(@Context SecurityContext sc) throws Exception {
|
public List<UserMediaAdvancement> gets(@Context final SecurityContext sc) throws Exception {
|
||||||
GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
final GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
||||||
return SqlWrapper.getsWhere(UserMediaAdvancement.class, new QuerryCondition("userId", "=", gc.userByToken.id));
|
return DataAccess.getsWhere(UserMediaAdvancement.class, new QueryCondition("userId", "=", gc.userByToken.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =============================================================================
|
/* =============================================================================
|
||||||
@ -56,15 +56,15 @@ public class UserMediaAdvancementResource {
|
|||||||
//@Path("{id}")
|
//@Path("{id}")
|
||||||
//@RolesAllowed("USER")
|
//@RolesAllowed("USER")
|
||||||
//@Consumes(MediaType.APPLICATION_JSON)
|
//@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public UserMediaAdvancement post(@Context SecurityContext sc, @PathParam("id") Long id, MediaInformations data) throws Exception {
|
public UserMediaAdvancement post(@Context final SecurityContext sc, @PathParam("id") final Long id, final MediaInformations data) throws Exception {
|
||||||
GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
final GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
||||||
UserMediaAdvancement elem = new UserMediaAdvancement();
|
final UserMediaAdvancement elem = new UserMediaAdvancement();
|
||||||
elem.userId = gc.userByToken.id;
|
elem.userId = gc.userByToken.id;
|
||||||
elem.mediaId = id;
|
elem.mediaId = id;
|
||||||
elem.time = data.time;
|
elem.time = data.time;
|
||||||
elem.percent = data.percent;
|
elem.percent = data.percent;
|
||||||
elem.count = data.count;
|
elem.count = data.count;
|
||||||
return SqlWrapper.insert(elem);
|
return DataAccess.insert(elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
public record MediaInformationsDelta(
|
public record MediaInformationsDelta(
|
||||||
@ -76,14 +76,14 @@ public class UserMediaAdvancementResource {
|
|||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public UserMediaAdvancement put(@Context SecurityContext sc, @PathParam("id") Long id, MediaInformationsDelta data) throws Exception {
|
public UserMediaAdvancement put(@Context final SecurityContext sc, @PathParam("id") final Long id, final MediaInformationsDelta data) throws Exception {
|
||||||
UserMediaAdvancement elem = this.getWithId(sc, id);
|
final UserMediaAdvancement elem = getWithId(sc, id);
|
||||||
if (elem == null) {
|
if (elem == null) {
|
||||||
// insert element
|
// insert element
|
||||||
if (data.addCount) {
|
if (data.addCount) {
|
||||||
return this.post(sc, id, new MediaInformations(data.time(), data.percent(), 1));
|
return post(sc, id, new MediaInformations(data.time(), data.percent(), 1));
|
||||||
} else {
|
} else {
|
||||||
return this.post(sc, id, new MediaInformations(data.time(), data.percent(), 0));
|
return post(sc, id, new MediaInformations(data.time(), data.percent(), 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elem.time = data.time;
|
elem.time = data.time;
|
||||||
@ -92,18 +92,18 @@ public class UserMediaAdvancementResource {
|
|||||||
elem.count++;
|
elem.count++;
|
||||||
}
|
}
|
||||||
LOGGER.info("{},{},{}", elem.time, elem.percent, elem.count);
|
LOGGER.info("{},{},{}", elem.time, elem.percent, elem.count);
|
||||||
int nbAfected = SqlWrapper.update(elem, elem.id, List.of("time", "percent", "count"));
|
final int nbAfected = DataAccess.update(elem, elem.id, List.of("time", "percent", "count"));
|
||||||
// TODO: manage the fact that no element has been updated ...
|
// TODO: manage the fact that no element has been updated ...
|
||||||
UserMediaAdvancement ret = SqlWrapper.get(UserMediaAdvancement.class, elem.id);
|
final UserMediaAdvancement ret = DataAccess.get(UserMediaAdvancement.class, elem.id);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public Response delete(@Context SecurityContext sc, @PathParam("id") Long id) throws Exception {
|
public Response delete(@Context final SecurityContext sc, @PathParam("id") final Long id) throws Exception {
|
||||||
UserMediaAdvancement elem = this.getWithId(sc, id);
|
final UserMediaAdvancement elem = getWithId(sc, id);
|
||||||
SqlWrapper.delete(UserMediaAdvancement.class, elem.id);
|
DataAccess.delete(UserMediaAdvancement.class, elem.id);
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,15 +2,15 @@ package org.kar.karideo.api;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.kar.archidata.annotation.security.RolesAllowed;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
import org.kar.archidata.filter.GenericContext;
|
import org.kar.archidata.filter.GenericContext;
|
||||||
import org.kar.archidata.sqlWrapper.SqlWrapper;
|
|
||||||
import org.kar.karideo.model.UserKarideo;
|
import org.kar.karideo.model.UserKarideo;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
|
import jakarta.annotation.security.RolesAllowed;
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
import jakarta.ws.rs.PathParam;
|
import jakarta.ws.rs.PathParam;
|
||||||
@ -29,8 +29,7 @@ public class UserResource {
|
|||||||
public long id;
|
public long id;
|
||||||
public String login;
|
public String login;
|
||||||
|
|
||||||
public UserOut(long id, String login) {
|
public UserOut(final long id, final String login) {
|
||||||
super();
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.login = login;
|
this.login = login;
|
||||||
}
|
}
|
||||||
@ -45,8 +44,8 @@ public class UserResource {
|
|||||||
public List<UserKarideo> getUsers() {
|
public List<UserKarideo> getUsers() {
|
||||||
System.out.println("getUsers");
|
System.out.println("getUsers");
|
||||||
try {
|
try {
|
||||||
return SqlWrapper.gets(UserKarideo.class);
|
return DataAccess.gets(UserKarideo.class);
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -57,15 +56,15 @@ public class UserResource {
|
|||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
public UserKarideo getUsers(@Context SecurityContext sc, @PathParam("id") long userId) {
|
public UserKarideo getUsers(@Context final SecurityContext sc, @PathParam("id") final long userId) {
|
||||||
System.out.println("getUser " + userId);
|
System.out.println("getUser " + userId);
|
||||||
GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
final GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
||||||
System.out.println("===================================================");
|
System.out.println("===================================================");
|
||||||
System.out.println("== USER ? " + gc.userByToken.name);
|
System.out.println("== USER ? " + gc.userByToken.name);
|
||||||
System.out.println("===================================================");
|
System.out.println("===================================================");
|
||||||
try {
|
try {
|
||||||
return SqlWrapper.get(UserKarideo.class, userId);
|
return DataAccess.get(UserKarideo.class, userId);
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -75,9 +74,9 @@ public class UserResource {
|
|||||||
@GET
|
@GET
|
||||||
@Path("me")
|
@Path("me")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public UserOut getMe(@Context SecurityContext sc) {
|
public UserOut getMe(@Context final SecurityContext sc) {
|
||||||
LOGGER.debug("getMe()");
|
LOGGER.debug("getMe()");
|
||||||
GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
final GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
||||||
LOGGER.debug("== USER ? {}", gc.userByToken);
|
LOGGER.debug("== USER ? {}", gc.userByToken);
|
||||||
return new UserOut(gc.userByToken.id, gc.userByToken.name);
|
return new UserOut(gc.userByToken.id, gc.userByToken.name);
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,12 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||||
import org.kar.archidata.annotation.security.RolesAllowed;
|
|
||||||
import org.kar.archidata.api.DataResource;
|
import org.kar.archidata.api.DataResource;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
|
||||||
import org.kar.archidata.exception.FailException;
|
import org.kar.archidata.exception.FailException;
|
||||||
import org.kar.archidata.exception.InputException;
|
import org.kar.archidata.exception.InputException;
|
||||||
import org.kar.archidata.model.Data;
|
import org.kar.archidata.model.Data;
|
||||||
import org.kar.archidata.sqlWrapper.SqlWrapper;
|
|
||||||
import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
|
|
||||||
import org.kar.archidata.util.DataTools;
|
import org.kar.archidata.util.DataTools;
|
||||||
import org.kar.karideo.model.Media;
|
import org.kar.karideo.model.Media;
|
||||||
import org.kar.karideo.model.Season;
|
import org.kar.karideo.model.Season;
|
||||||
@ -22,6 +21,7 @@ import org.kar.karideo.model.Type;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import jakarta.annotation.security.RolesAllowed;
|
||||||
import jakarta.ws.rs.Consumes;
|
import jakarta.ws.rs.Consumes;
|
||||||
import jakarta.ws.rs.DELETE;
|
import jakarta.ws.rs.DELETE;
|
||||||
import jakarta.ws.rs.GET;
|
import jakarta.ws.rs.GET;
|
||||||
@ -41,27 +41,27 @@ public class VideoResource {
|
|||||||
@GET
|
@GET
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public List<Media> get() throws Exception {
|
public List<Media> get() throws Exception {
|
||||||
return SqlWrapper.gets(Media.class);
|
return DataAccess.gets(Media.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public Media get(@PathParam("id") Long id) throws Exception {
|
public Media get(@PathParam("id") final Long id) throws Exception {
|
||||||
return SqlWrapper.get(Media.class, id);
|
return DataAccess.get(Media.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Media put(@PathParam("id") Long id, String jsonRequest) throws Exception {
|
public Media put(@PathParam("id") final Long id, final String jsonRequest) throws Exception {
|
||||||
System.out.println("update video " + id + " ==> '" + jsonRequest + "'");
|
System.out.println("update video " + id + " ==> '" + jsonRequest + "'");
|
||||||
SqlWrapper.update(Media.class, id, jsonRequest);
|
DataAccess.updateWithJson(Media.class, id, jsonRequest);
|
||||||
return SqlWrapper.get(Media.class, id);
|
return DataAccess.get(Media.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String multipartCorrection(String data) {
|
private String multipartCorrection(final String data) {
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ public class VideoResource {
|
|||||||
public Response uploadFile(@FormDataParam("fileName") String fileName, @FormDataParam("universe") String universe, @FormDataParam("series") String series,
|
public Response uploadFile(@FormDataParam("fileName") String fileName, @FormDataParam("universe") String universe, @FormDataParam("series") String series,
|
||||||
//@FormDataParam("seriesId") String seriesId, Not used ...
|
//@FormDataParam("seriesId") String seriesId, Not used ...
|
||||||
@FormDataParam("season") String season, @FormDataParam("episode") String episode, @FormDataParam("title") String title, @FormDataParam("typeId") String typeId,
|
@FormDataParam("season") String season, @FormDataParam("episode") String episode, @FormDataParam("title") String title, @FormDataParam("typeId") String typeId,
|
||||||
@FormDataParam("file") InputStream fileInputStream, @FormDataParam("file") FormDataContentDisposition fileMetaData) throws FailException {
|
@FormDataParam("file") final InputStream fileInputStream, @FormDataParam("file") final FormDataContentDisposition fileMetaData) throws FailException {
|
||||||
try {
|
try {
|
||||||
// correct input string stream :
|
// correct input string stream :
|
||||||
fileName = multipartCorrection(fileName);
|
fileName = multipartCorrection(fileName);
|
||||||
@ -108,20 +108,20 @@ public class VideoResource {
|
|||||||
throw new InputException("typeId", "TypiId is not specified");
|
throw new InputException("typeId", "TypiId is not specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
long tmpUID = DataResource.getTmpDataId();
|
final long tmpUID = DataResource.getTmpDataId();
|
||||||
String sha512 = DataResource.saveTemporaryFile(fileInputStream, tmpUID);
|
final String sha512 = DataResource.saveTemporaryFile(fileInputStream, tmpUID);
|
||||||
Data data = DataResource.getWithSha512(sha512);
|
Data data = DataResource.getWithSha512(sha512);
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
System.out.println("Need to add the data in the BDD ... ");
|
System.out.println("Need to add the data in the BDD ... ");
|
||||||
System.out.flush();
|
System.out.flush();
|
||||||
try {
|
try {
|
||||||
data = DataResource.createNewData(tmpUID, fileName, sha512);
|
data = DataResource.createNewData(tmpUID, fileName, sha512);
|
||||||
} catch (IOException ex) {
|
} catch (final IOException ex) {
|
||||||
DataResource.removeTemporaryFile(tmpUID);
|
DataResource.removeTemporaryFile(tmpUID);
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
throw new FailException("can not create input media (the data model has an internal error");
|
throw new FailException("can not create input media (the data model has an internal error");
|
||||||
}
|
}
|
||||||
} else if (data.deleted == true) {
|
} else if (data.deleted) {
|
||||||
System.out.println("Data already exist but deleted");
|
System.out.println("Data already exist but deleted");
|
||||||
System.out.flush();
|
System.out.flush();
|
||||||
DataResource.undelete(data.id);
|
DataResource.undelete(data.id);
|
||||||
@ -133,7 +133,7 @@ public class VideoResource {
|
|||||||
// Fist step: retive all the Id of each parents:...
|
// Fist step: retive all the Id of each parents:...
|
||||||
System.out.println("Find typeNode");
|
System.out.println("Find typeNode");
|
||||||
// check if id of type exist:
|
// check if id of type exist:
|
||||||
Type typeNode = TypeResource.getId(Long.parseLong(typeId));
|
final Type typeNode = TypeResource.getId(Long.parseLong(typeId));
|
||||||
if (typeNode == null) {
|
if (typeNode == null) {
|
||||||
DataResource.removeTemporaryFile(tmpUID);
|
DataResource.removeTemporaryFile(tmpUID);
|
||||||
throw new InputException("typeId", "TypeId does not exist ...");
|
throw new InputException("typeId", "TypeId does not exist ...");
|
||||||
@ -161,9 +161,9 @@ public class VideoResource {
|
|||||||
System.out.println(" ==> " + seasonNode);
|
System.out.println(" ==> " + seasonNode);
|
||||||
System.out.println("add media");
|
System.out.println("add media");
|
||||||
|
|
||||||
long uniqueSQLID = -1;
|
final long uniqueSQLID = -1;
|
||||||
try {
|
try {
|
||||||
Media media = new Media();
|
final Media media = new Media();
|
||||||
media.name = title;
|
media.name = title;
|
||||||
media.dataId = data.id;
|
media.dataId = data.id;
|
||||||
media.typeId = typeNode.id;
|
media.typeId = typeNode.id;
|
||||||
@ -179,17 +179,17 @@ public class VideoResource {
|
|||||||
if (episode != null && !episode.contentEquals("")) {
|
if (episode != null && !episode.contentEquals("")) {
|
||||||
media.episode = Integer.parseInt(episode);
|
media.episode = Integer.parseInt(episode);
|
||||||
}
|
}
|
||||||
Media out = SqlWrapper.insert(media);
|
final Media out = DataAccess.insert(media);
|
||||||
DataResource.removeTemporaryFile(tmpUID);
|
DataResource.removeTemporaryFile(tmpUID);
|
||||||
System.out.println("uploaded .... compleate: " + uniqueSQLID);
|
System.out.println("uploaded .... compleate: " + uniqueSQLID);
|
||||||
Media creation = get(uniqueSQLID);
|
final Media creation = get(uniqueSQLID);
|
||||||
return Response.ok(creation).build();
|
return Response.ok(creation).build();
|
||||||
} catch (SQLException ex) {
|
} catch (final SQLException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
System.out.println("Catch error:" + ex.getMessage());
|
System.out.println("Catch error:" + ex.getMessage());
|
||||||
throw new FailException("Catch SQLerror ==> check server logs");
|
throw new FailException("Catch SQLerror ==> check server logs");
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (final Exception ex) {
|
||||||
System.out.println("Catch an unexpected error ... " + ex.getMessage());
|
System.out.println("Catch an unexpected error ... " + ex.getMessage());
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
throw new FailException("Catch Exception ==> check server logs");
|
throw new FailException("Catch Exception ==> check server logs");
|
||||||
@ -200,24 +200,24 @@ public class VideoResource {
|
|||||||
@Path("{id}/add_cover")
|
@Path("{id}/add_cover")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes({ MediaType.MULTIPART_FORM_DATA })
|
@Consumes({ MediaType.MULTIPART_FORM_DATA })
|
||||||
public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
|
public Response uploadCover(@PathParam("id") final Long id, @FormDataParam("fileName") final String fileName, @FormDataParam("file") final InputStream fileInputStream,
|
||||||
@FormDataParam("file") FormDataContentDisposition fileMetaData) {
|
@FormDataParam("file") final FormDataContentDisposition fileMetaData) {
|
||||||
return DataTools.uploadCover(Media.class, id, fileName, fileInputStream, fileMetaData);
|
return DataTools.uploadCover(Media.class, id, fileName, fileInputStream, fileMetaData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}/rm_cover/{coverId}")
|
@Path("{id}/rm_cover/{coverId}")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
|
public Response removeCover(@PathParam("id") final Long id, @PathParam("coverId") final Long coverId) throws Exception {
|
||||||
AddOnManyToMany.removeLink(Media.class, id, "cover", coverId);
|
AddOnManyToMany.removeLink(Media.class, id, "cover", coverId);
|
||||||
return Response.ok(SqlWrapper.get(Media.class, id)).build();
|
return Response.ok(DataAccess.get(Media.class, id)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
public Response delete(@PathParam("id") Long id) throws Exception {
|
public Response delete(@PathParam("id") final Long id) throws Exception {
|
||||||
SqlWrapper.delete(Media.class, id);
|
DataAccess.delete(Media.class, id);
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,22 +43,22 @@ public class Initialization extends MigrationSqlStep {
|
|||||||
// set start increment element to permit to add after default elements
|
// set start increment element to permit to add after default elements
|
||||||
addAction("""
|
addAction("""
|
||||||
ALTER TABLE `data` AUTO_INCREMENT = 1000;
|
ALTER TABLE `data` AUTO_INCREMENT = 1000;
|
||||||
""");
|
""", "mysql");
|
||||||
addAction("""
|
addAction("""
|
||||||
ALTER TABLE `media` AUTO_INCREMENT = 1000;
|
ALTER TABLE `media` AUTO_INCREMENT = 1000;
|
||||||
""");
|
""", "mysql");
|
||||||
addAction("""
|
addAction("""
|
||||||
ALTER TABLE `type` AUTO_INCREMENT = 1000;
|
ALTER TABLE `type` AUTO_INCREMENT = 1000;
|
||||||
""");
|
""", "mysql");
|
||||||
addAction("""
|
addAction("""
|
||||||
ALTER TABLE `series` AUTO_INCREMENT = 1000;
|
ALTER TABLE `series` AUTO_INCREMENT = 1000;
|
||||||
""");
|
""", "mysql");
|
||||||
addAction("""
|
addAction("""
|
||||||
ALTER TABLE `season` AUTO_INCREMENT = 1000;
|
ALTER TABLE `season` AUTO_INCREMENT = 1000;
|
||||||
""");
|
""", "mysql");
|
||||||
addAction("""
|
addAction("""
|
||||||
ALTER TABLE `userMediaAdvencement` AUTO_INCREMENT = 1000;
|
ALTER TABLE `userMediaAdvencement` AUTO_INCREMENT = 1000;
|
||||||
""");
|
""", "mysql");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package org.kar.karideo.model;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.kar.archidata.model.Data;
|
import org.kar.archidata.model.Data;
|
||||||
import org.kar.archidata.model.GenericTable;
|
import org.kar.archidata.model.GenericDataSoftDelete;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ import jakarta.persistence.Table;
|
|||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
//@SQLDelete(sql = "UPDATE table_product SET deleted = true WHERE id=?")
|
//@SQLDelete(sql = "UPDATE table_product SET deleted = true WHERE id=?")
|
||||||
//@Where(clause = "deleted=false")
|
//@Where(clause = "deleted=false")
|
||||||
public class Media extends GenericTable {
|
public class Media extends GenericDataSoftDelete {
|
||||||
// Name of the media (this represent the title)
|
// Name of the media (this represent the title)
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
public String name;
|
public String name;
|
||||||
|
@ -2,10 +2,10 @@ package org.kar.karideo.model;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.kar.archidata.annotation.SQLComment;
|
import org.kar.archidata.annotation.DataComment;
|
||||||
import org.kar.archidata.annotation.SQLIfNotExists;
|
import org.kar.archidata.annotation.DataIfNotExists;
|
||||||
import org.kar.archidata.model.Data;
|
import org.kar.archidata.model.Data;
|
||||||
import org.kar.archidata.model.GenericTable;
|
import org.kar.archidata.model.GenericDataSoftDelete;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
@ -16,19 +16,19 @@ import jakarta.persistence.ManyToOne;
|
|||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Table(name = "season")
|
@Table(name = "season")
|
||||||
@SQLIfNotExists
|
@DataIfNotExists
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class Season extends GenericTable {
|
public class Season extends GenericDataSoftDelete {
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@SQLComment("Name of the media (this represent the title)")
|
@DataComment("Name of the media (this represent the title)")
|
||||||
public String name;
|
public String name;
|
||||||
@SQLComment("Description of the media")
|
@DataComment("Description of the media")
|
||||||
public String description;
|
public String description;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@SQLComment("series parent ID")
|
@DataComment("series parent ID")
|
||||||
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Series.class)
|
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Series.class)
|
||||||
public Long parentId;
|
public Long parentId;
|
||||||
@SQLComment("List of Id of the sopecific covers")
|
@DataComment("List of Id of the sopecific covers")
|
||||||
@ManyToMany(fetch = FetchType.LAZY, targetEntity = Data.class)
|
@ManyToMany(fetch = FetchType.LAZY, targetEntity = Data.class)
|
||||||
public List<Long> covers = null;
|
public List<Long> covers = null;
|
||||||
}
|
}
|
@ -2,10 +2,10 @@ package org.kar.karideo.model;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.kar.archidata.annotation.SQLComment;
|
import org.kar.archidata.annotation.DataComment;
|
||||||
import org.kar.archidata.annotation.SQLIfNotExists;
|
import org.kar.archidata.annotation.DataIfNotExists;
|
||||||
import org.kar.archidata.model.Data;
|
import org.kar.archidata.model.Data;
|
||||||
import org.kar.archidata.model.GenericTable;
|
import org.kar.archidata.model.GenericDataSoftDelete;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
@ -16,19 +16,19 @@ import jakarta.persistence.ManyToOne;
|
|||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Table(name = "series")
|
@Table(name = "series")
|
||||||
@SQLIfNotExists
|
@DataIfNotExists
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class Series extends GenericTable {
|
public class Series extends GenericDataSoftDelete {
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@SQLComment("Name of the media (this represent the title)")
|
@DataComment("Name of the media (this represent the title)")
|
||||||
public String name;
|
public String name;
|
||||||
@SQLComment("Description of the media")
|
@DataComment("Description of the media")
|
||||||
public String description;
|
public String description;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@SQLComment("series parent ID")
|
@DataComment("series parent ID")
|
||||||
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Type.class)
|
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Type.class)
|
||||||
public Long parentId;
|
public Long parentId;
|
||||||
@SQLComment("List of Id of the sopecific covers")
|
@DataComment("List of Id of the sopecific covers")
|
||||||
@ManyToMany(fetch = FetchType.LAZY, targetEntity = Data.class)
|
@ManyToMany(fetch = FetchType.LAZY, targetEntity = Data.class)
|
||||||
public List<Long> covers = null;
|
public List<Long> covers = null;
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,10 @@ package org.kar.karideo.model;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.kar.archidata.annotation.SQLComment;
|
import org.kar.archidata.annotation.DataComment;
|
||||||
import org.kar.archidata.annotation.SQLIfNotExists;
|
import org.kar.archidata.annotation.DataIfNotExists;
|
||||||
import org.kar.archidata.model.Data;
|
import org.kar.archidata.model.Data;
|
||||||
import org.kar.archidata.model.GenericTable;
|
import org.kar.archidata.model.GenericDataSoftDelete;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
@ -15,15 +15,15 @@ import jakarta.persistence.ManyToMany;
|
|||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Table(name = "type")
|
@Table(name = "type")
|
||||||
@SQLIfNotExists
|
@DataIfNotExists
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class Type extends GenericTable {
|
public class Type extends GenericDataSoftDelete {
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@SQLComment("Name of the media (this represent the title)")
|
@DataComment("Name of the media (this represent the title)")
|
||||||
public String name;
|
public String name;
|
||||||
@SQLComment("Description of the media")
|
@DataComment("Description of the media")
|
||||||
public String description;
|
public String description;
|
||||||
@SQLComment("List of Id of the sopecific covers")
|
@DataComment("List of Id of the sopecific covers")
|
||||||
@ManyToMany(fetch = FetchType.LAZY, targetEntity = Data.class)
|
@ManyToMany(fetch = FetchType.LAZY, targetEntity = Data.class)
|
||||||
public List<Long> covers = null;
|
public List<Long> covers = null;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package org.kar.karideo.model;
|
package org.kar.karideo.model;
|
||||||
|
|
||||||
import org.kar.archidata.annotation.SQLIfNotExists;
|
import org.kar.archidata.annotation.DataIfNotExists;
|
||||||
import org.kar.archidata.model.User;
|
import org.kar.archidata.model.User;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
@ -8,7 +8,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Table(name = "user")
|
@Table(name = "user")
|
||||||
@SQLIfNotExists
|
@DataIfNotExists
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class UserKarideo extends User {
|
public class UserKarideo extends User {
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package org.kar.karideo.model;
|
package org.kar.karideo.model;
|
||||||
|
|
||||||
import org.kar.archidata.annotation.SQLComment;
|
import org.kar.archidata.annotation.DataComment;
|
||||||
import org.kar.archidata.annotation.SQLIfNotExists;
|
import org.kar.archidata.annotation.DataIfNotExists;
|
||||||
import org.kar.archidata.model.GenericTable;
|
import org.kar.archidata.model.GenericDataSoftDelete;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
@ -12,24 +12,24 @@ import jakarta.persistence.ManyToOne;
|
|||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Table(name = "userMediaAdvancement")
|
@Table(name = "userMediaAdvancement")
|
||||||
@SQLIfNotExists
|
@DataIfNotExists
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class UserMediaAdvancement extends GenericTable {
|
public class UserMediaAdvancement extends GenericDataSoftDelete {
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@SQLComment("Foreign Key Id of the user")
|
@DataComment("Foreign Key Id of the user")
|
||||||
@ManyToOne(fetch = FetchType.LAZY, targetEntity = UserKarideo.class)
|
@ManyToOne(fetch = FetchType.LAZY, targetEntity = UserKarideo.class)
|
||||||
public long userId;
|
public long userId;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@SQLComment("Id of the media")
|
@DataComment("Id of the media")
|
||||||
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Media.class)
|
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Media.class)
|
||||||
public long mediaId;
|
public long mediaId;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@SQLComment("Percent of admencement in the media")
|
@DataComment("Percent of admencement in the media")
|
||||||
public float percent;
|
public float percent;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@SQLComment("Number of second of admencement in the media")
|
@DataComment("Number of second of admencement in the media")
|
||||||
public int time;
|
public int time;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@SQLComment("Number of time this media has been read")
|
@DataComment("Number of time this media has been read")
|
||||||
public int count;
|
public int count;
|
||||||
}
|
}
|
||||||
|
35
back/test/resources/simplelogger.properties
Normal file
35
back/test/resources/simplelogger.properties
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# SLF4J's SimpleLogger configuration file
|
||||||
|
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
|
||||||
|
# Default logging detail level for all instances of SimpleLogger.
|
||||||
|
# Must be one of ("trace", "debug", "info", "warn", or "error").
|
||||||
|
# If not specified, defaults to "info".
|
||||||
|
org.slf4j.simpleLogger.defaultLogLevel=debug
|
||||||
|
|
||||||
|
# Logging detail level for a SimpleLogger instance named "xxxxx".
|
||||||
|
# Must be one of ("trace", "debug", "info", "warn", or "error").
|
||||||
|
# If not specified, the default logging detail level is used.
|
||||||
|
#org.slf4j.simpleLogger.log.xxxxx=
|
||||||
|
|
||||||
|
# Set to true if you want the current date and time to be included in output messages.
|
||||||
|
# Default is false, and will output the number of milliseconds elapsed since startup.
|
||||||
|
#org.slf4j.simpleLogger.showDateTime=false
|
||||||
|
|
||||||
|
# The date and time format to be used in the output messages.
|
||||||
|
# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
|
||||||
|
# If the format is not specified or is invalid, the default format is used.
|
||||||
|
# The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
|
||||||
|
#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z
|
||||||
|
|
||||||
|
# Set to true if you want to output the current thread name.
|
||||||
|
# Defaults to true.
|
||||||
|
org.slf4j.simpleLogger.showThreadName=true
|
||||||
|
|
||||||
|
# Set to true if you want the Logger instance name to be included in output messages.
|
||||||
|
# Defaults to true.
|
||||||
|
#org.slf4j.simpleLogger.showLogName=true
|
||||||
|
|
||||||
|
# Set to true if you want the last component of the name to be included in output messages.
|
||||||
|
# Defaults to false.
|
||||||
|
#org.slf4j.simpleLogger.showShortLogName=false
|
||||||
|
|
||||||
|
|
11
back/test/src/test/kar/karideo/Common.java
Normal file
11
back/test/src/test/kar/karideo/Common.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package test.kar.karideo;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.kar.archidata.util.JWTWrapper;
|
||||||
|
|
||||||
|
public class Common {
|
||||||
|
static String userToken = JWTWrapper.createJwtTestToken(16512, "test_user_login", "KarAuth", "karideo", Map.of("USER", Boolean.TRUE));
|
||||||
|
static String adminToken = JWTWrapper.createJwtTestToken(16512, "test_admin_login", "KarAuth", "karideo", Map.of("USER", Boolean.TRUE, "ADMIN", Boolean.TRUE));
|
||||||
|
|
||||||
|
}
|
33
back/test/src/test/kar/karideo/StepwiseExtension.java
Normal file
33
back/test/src/test/kar/karideo/StepwiseExtension.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package test.kar.karideo;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
|
||||||
|
import org.junit.jupiter.api.extension.ExecutionCondition;
|
||||||
|
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
|
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;
|
||||||
|
|
||||||
|
class StepwiseExtension implements ExecutionCondition, TestExecutionExceptionHandler {
|
||||||
|
@Override
|
||||||
|
public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext extensionContext) {
|
||||||
|
final ExtensionContext.Namespace namespace = namespaceFor(extensionContext);
|
||||||
|
final ExtensionContext.Store store = storeFor(extensionContext, namespace);
|
||||||
|
final String value = store.get(StepwiseExtension.class, String.class);
|
||||||
|
return value == null ? ConditionEvaluationResult.enabled("No test failures in stepwise tests")
|
||||||
|
: ConditionEvaluationResult.disabled(String.format("Stepwise test disabled due to previous failure in '%s'", value));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleTestExecutionException(final ExtensionContext extensionContext, final Throwable throwable) throws Throwable {
|
||||||
|
final ExtensionContext.Namespace namespace = namespaceFor(extensionContext);
|
||||||
|
final ExtensionContext.Store store = storeFor(extensionContext, namespace);
|
||||||
|
store.put(StepwiseExtension.class, extensionContext.getDisplayName());
|
||||||
|
throw throwable;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExtensionContext.Namespace namespaceFor(final ExtensionContext extensionContext) {
|
||||||
|
return ExtensionContext.Namespace.create(StepwiseExtension.class, extensionContext.getParent());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExtensionContext.Store storeFor(final ExtensionContext extensionContext, final ExtensionContext.Namespace namespace) {
|
||||||
|
return extensionContext.getParent().get().getStore(namespace);
|
||||||
|
}
|
||||||
|
}
|
70
back/test/src/test/kar/karideo/TestHealthCheck.java
Normal file
70
back/test/src/test/kar/karideo/TestHealthCheck.java
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
package test.kar.karideo;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.AfterAll;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.MethodOrderer;
|
||||||
|
import org.junit.jupiter.api.Order;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.kar.archidata.db.DBEntry;
|
||||||
|
import org.kar.archidata.exception.RESTErrorResponseExeption;
|
||||||
|
import org.kar.archidata.util.ConfigBaseVariable;
|
||||||
|
import org.kar.archidata.util.RESTApi;
|
||||||
|
import org.kar.karideo.api.HealthCheck.HealthResult;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ExtendWith(StepwiseExtension.class)
|
||||||
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
|
public class TestHealthCheck {
|
||||||
|
private final static Logger LOGGER = LoggerFactory.getLogger(TestHealthCheck.class);
|
||||||
|
|
||||||
|
static WebLauncherTest webInterface = null;
|
||||||
|
static RESTApi api = null;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void configureWebServer() throws Exception {
|
||||||
|
LOGGER.info("configure server ...");
|
||||||
|
webInterface = new WebLauncherTest();
|
||||||
|
LOGGER.info("Create DB");
|
||||||
|
try {
|
||||||
|
webInterface.migrateDB();
|
||||||
|
} catch (final Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
LOGGER.error("Detect an error: {}", ex.getMessage());
|
||||||
|
}
|
||||||
|
LOGGER.info("Start REST (BEGIN)");
|
||||||
|
webInterface.process();
|
||||||
|
LOGGER.info("Start REST (DONE)");
|
||||||
|
api = new RESTApi(ConfigBaseVariable.apiAdress);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
public static void stopWebServer() throws InterruptedException, IOException {
|
||||||
|
LOGGER.info("Kill the web server");
|
||||||
|
webInterface.stop();
|
||||||
|
webInterface = null;
|
||||||
|
LOGGER.info("Remove the test db");
|
||||||
|
DBEntry.closeAllForceMode();
|
||||||
|
ConfigBaseVariable.clearAllValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Order(1)
|
||||||
|
@Test
|
||||||
|
//@RepeatedTest(10)
|
||||||
|
public void checkHealthCheck() throws Exception {
|
||||||
|
final HealthResult result = api.get(HealthResult.class, "health_check");
|
||||||
|
Assertions.assertEquals(result.value(), "alive and kicking");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Order(2)
|
||||||
|
@Test
|
||||||
|
public void checkHealthCheckWrongAPI() throws Exception {
|
||||||
|
Assertions.assertThrows(RESTErrorResponseExeption.class, () -> api.get(HealthResult.class, "health_checks"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
28
back/test/src/test/kar/karideo/WebLauncherTest.java
Executable file
28
back/test/src/test/kar/karideo/WebLauncherTest.java
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
package test.kar.karideo;
|
||||||
|
|
||||||
|
import org.kar.archidata.util.ConfigBaseVariable;
|
||||||
|
import org.kar.karideo.WebLauncher;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class WebLauncherTest extends WebLauncher {
|
||||||
|
final private static Logger LOGGER = LoggerFactory.getLogger(WebLauncherTest.class);
|
||||||
|
|
||||||
|
public WebLauncherTest() {
|
||||||
|
LOGGER.debug("Configure REST system");
|
||||||
|
// for local test:
|
||||||
|
ConfigBaseVariable.apiAdress = "http://127.0.0.1:12345/test/api/";
|
||||||
|
ConfigBaseVariable.testMode = "true";
|
||||||
|
//ConfigBaseVariable.dbPort = "3306";
|
||||||
|
// for the test we a in memory sqlite..
|
||||||
|
ConfigBaseVariable.dbType = "sqlite";
|
||||||
|
ConfigBaseVariable.dbHost = "memory";
|
||||||
|
// for test we need to connect all time the DB
|
||||||
|
ConfigBaseVariable.dbKeepConnected = "true";
|
||||||
|
|
||||||
|
//ConfigBaseVariable.dbHost = "localhost";
|
||||||
|
//ConfigBaseVariable.dbUser = "root";
|
||||||
|
//ConfigBaseVariable.dbPassword = "ZERTYSDGFVHSDFGHJYZSDFGSQxfgsqdfgsqdrf4564654";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user