[DEV] move angular folder

This commit is contained in:
Edouard DUPIN 2025-02-14 23:25:42 +01:00
parent 1fc1b5d35d
commit 6f16bffe31
187 changed files with 1091 additions and 600 deletions

View File

@ -1,7 +1,8 @@
FROM maven:3.6.3-openjdk-16 AS build
FROM maven:3-openjdk-23 AS build
COPY pom.xml /tmp/
COPY src /tmp/src/
COPY Formatter.xml /tmp/
WORKDIR /tmp/
RUN mvn clean compile assembly:single

View File

@ -5,9 +5,9 @@
<artifactId>karideo</artifactId>
<version>0.3.0</version>
<properties>
<maven.compiler.version>3.1</maven.compiler.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.version>3.13.0</maven.compiler.version>
<maven.compiler.source>23</maven.compiler.source>
<maven.compiler.target>23</maven.compiler.target>
<maven.dependency.version>3.1.1</maven.dependency.version>
</properties>
<repositories>
@ -20,17 +20,34 @@
<dependency>
<groupId>kangaroo-and-rabbit</groupId>
<artifactId>archidata</artifactId>
<version>0.12.0</version>
<version>0.23.6</version>
</dependency>
<!-- Loopback of logger JDK logging API to SLF4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.1.0-alpha1</version>
<artifactId>jul-to-slf4j</artifactId>
<version>2.0.9</version>
</dependency>
<!-- generic logger of SLF4J to console (in color) -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.11</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>3.1.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.17.1</version>
<version>2.18.1</version>
</dependency>
<!--
************************************************************
@ -40,24 +57,24 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.0-M2</version>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.11.0-M2</version>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
<version>3.5.0</version>
</dependency>
</dependencies>
<build>
@ -87,16 +104,45 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<version>3.2.0</version>
<executions>
<execution>
<id>prod-mode</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.kar.karideo.WebLauncher</mainClass>
</configuration>
</execution>
<execution>
<id>dev-mode</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.kar.karideo.WebLauncherLocal</mainClass>
</configuration>
</execution>
<execution>
<id>generate-api</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.kar.karideo.GenerateApi</mainClass>
</configuration>
</execution>
</executions>
<configuration>
<mainClass>org.kar.karideo.WebLauncher</mainClass>
<mainClass/>
</configuration>
</plugin>
<!-- Create the source bundle -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>4.0.0-beta-1</version>
<executions>
<execution>
<id>attach-sources</id>
@ -110,10 +156,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<version>3.2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.7.1</version>
<configuration>
<archive>
<manifest>
@ -125,80 +173,21 @@
</descriptorRefs>
</configuration>
</plugin>
<!-- Create coverage -->
<!--
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</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>
</plugin>
-->
<!-- Java-doc generation for stand-alone site -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
</configuration>
</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 -->
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.23.0</version>
<version>2.24.1</version>
<configuration>
<encoding>UTF-8</encoding>
<lineEnding>LF</lineEnding>
@ -229,14 +218,6 @@
<configuration>
<includeFilterFile>spotbugs-security-include.xml</includeFilterFile>
<excludeFilterFile>spotbugs-security-exclude.xml</excludeFilterFile>
<!--<plugins>
<plugin>
<groupId>com.h3xstream.findsecbugs</groupId>
<artifactId>findsecbugs-plugin</artifactId>
<version>1.12.0</version>
</plugin>
</plugins>
-->
</configuration>
</plugin>
</plugins>
@ -247,7 +228,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
<configuration>
<show>public</show>
</configuration>

View File

@ -0,0 +1,17 @@
package org.kar.karideo;
import org.kar.karideo.migration.Initialization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class GenerateApi {
private final static Logger LOGGER = LoggerFactory.getLogger(GenerateApi.class);
private GenerateApi() {}
public static void main(final String[] args) throws Exception {
LOGGER.info("Generate API");
Initialization.generateObjects();
LOGGER.info("STOP the REST server.");
}
}

View File

@ -1,21 +1,22 @@
package org.kar.karideo;
import java.net.URI;
import java.util.logging.LogManager;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.kar.archidata.GlobalConfiguration;
import org.kar.archidata.UpdateJwtPublicKey;
import org.kar.archidata.api.DataResource;
import org.kar.archidata.catcher.GenericCatcher;
import org.kar.archidata.db.DBConfig;
import org.kar.archidata.db.DbConfig;
import org.kar.archidata.filter.CORSFilter;
import org.kar.archidata.filter.OptionFilter;
import org.kar.archidata.migration.MigrationEngine;
import org.kar.archidata.tools.ConfigBaseVariable;
import org.kar.archidata.tools.ContextGenericTools;
import org.kar.karideo.api.Front;
import org.kar.karideo.api.HealthCheck;
import org.kar.karideo.api.MediaResource;
@ -30,14 +31,16 @@ import org.kar.karideo.migration.Migration20230810;
import org.kar.karideo.migration.Migration20231015;
import org.kar.karideo.migration.Migration20231126;
import org.kar.karideo.migration.Migration20240226;
import org.kar.karideo.migration.Migration20240611;
import org.kar.karideo.migration.Migration20250214;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;
import jakarta.ws.rs.core.UriBuilder;
public class WebLauncher {
final static Logger LOGGER = LoggerFactory.getLogger(WebLauncher.class);
public static DBConfig dbConfig;
protected UpdateJwtPublicKey keyUpdater = null;
protected HttpServer server = null;
@ -59,12 +62,18 @@ public class WebLauncher {
migrationEngine.add(new Migration20231015());
migrationEngine.add(new Migration20231126());
migrationEngine.add(new Migration20240226());
migrationEngine.add(new Migration20240611());
migrationEngine.add(new Migration20250214());
WebLauncher.LOGGER.info("Migrate the DB [START]");
migrationEngine.migrateWaitAdmin(GlobalConfiguration.dbConfig);
migrationEngine.migrateWaitAdmin(new DbConfig());
WebLauncher.LOGGER.info("Migrate the DB [STOP]");
}
public static void main(final String[] args) throws Exception {
// Loop-back of logger JDK logging API to SLF4J
LogManager.getLogManager().reset();
SLF4JBridgeHandler.install();
WebLauncher.LOGGER.info("[START] application wake UP");
final WebLauncher launcher = new WebLauncher();
launcher.migrateDB();
@ -104,7 +113,7 @@ public class WebLauncher {
rc.register(HealthCheck.class);
rc.register(Front.class);
ContextGenericTools.addJsr310(rc);
// add jackson to be discover when we are ins stand-alone server
rc.register(JacksonFeature.class);
// enable this to show low level request

View File

@ -1,40 +1,25 @@
package org.kar.karideo;
import java.util.List;
import java.util.logging.LogManager;
import org.kar.archidata.api.DataResource;
import org.kar.archidata.externalRestApi.AnalyzeApi;
import org.kar.archidata.externalRestApi.TsGenerateApi;
import org.kar.archidata.tools.ConfigBaseVariable;
import org.kar.karideo.api.Front;
import org.kar.karideo.api.HealthCheck;
import org.kar.karideo.api.MediaResource;
import org.kar.karideo.api.SeasonResource;
import org.kar.karideo.api.SeriesResource;
import org.kar.karideo.api.TypeResource;
import org.kar.karideo.api.UserMediaAdvancementResource;
import org.kar.karideo.api.UserResource;
import org.kar.karideo.migration.Initialization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;
public class WebLauncherLocal extends WebLauncher {
private final static Logger LOGGER = LoggerFactory.getLogger(WebLauncherLocal.class);
private static final Logger LOGGER = LoggerFactory.getLogger(WebLauncherLocal.class);
private WebLauncherLocal() {}
public static void generateObjects() throws Exception {
LOGGER.info("Generate APIs");
final List<Class<?>> listOfResources = List.of(Front.class, HealthCheck.class, SeasonResource.class, SeriesResource.class, TypeResource.class, UserMediaAdvancementResource.class,
UserResource.class, MediaResource.class, DataResource.class);
final AnalyzeApi api = new AnalyzeApi();
api.addAllApi(listOfResources);
TsGenerateApi.generateApi(api, "../front/src/app/back-api/");
LOGGER.info("Generate APIs (DONE)");
}
public static void main(final String[] args) throws Exception {
generateObjects();
// Loop-back of logger JDK logging API to SLF4J
LogManager.getLogManager().reset();
SLF4JBridgeHandler.install();
// Generate the APIs in type-script
Initialization.generateObjects();
final WebLauncherLocal launcher = new WebLauncherLocal();
launcher.process();
LOGGER.info("end-configure the server & wait finish process:");
@ -48,6 +33,7 @@ public class WebLauncherLocal extends WebLauncher {
// for local test:
ConfigBaseVariable.apiAdress = "http://0.0.0.0:18080/karideo/api/";
ConfigBaseVariable.dbPort = "3906";
ConfigBaseVariable.testMode = "true";
}
try {
super.migrateDB();

View File

@ -11,8 +11,9 @@ import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.annotation.AsyncType;
import org.kar.archidata.annotation.TypeScriptProgress;
import org.kar.archidata.api.DataResource;
import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.DataAccess;
import org.kar.archidata.dataAccess.addOn.AddOnDataJson;
import org.kar.archidata.dataAccess.addOnSQL.AddOnDataJson;
import org.kar.archidata.exception.FailException;
import org.kar.archidata.exception.InputException;
import org.kar.archidata.model.Data;
@ -97,7 +98,7 @@ public class MediaResource {
@FormDataParam("file") final InputStream fileInputStream, //
@FormDataParam("file") final FormDataContentDisposition fileMetaData //
) throws FailException {
try {
try (DBAccess db = DBAccess.createInterface()) {
// correct input string stream :
fileName = multipartCorrection(fileName);
universe = multipartCorrection(universe);
@ -125,12 +126,12 @@ public class MediaResource {
final long tmpUID = DataResource.getTmpDataId();
final String sha512 = DataResource.saveTemporaryFile(fileInputStream, tmpUID);
Data data = DataResource.getWithSha512(sha512);
Data data = DataTools.getWithSha512(db, sha512);
if (data == null) {
LOGGER.info("Need to add the data in the BDD ... ");
System.out.flush();
try {
data = DataResource.createNewData(tmpUID, fileName, sha512);
data = DataTools.createNewData(db, tmpUID, fileName, sha512);
} catch (final IOException ex) {
DataResource.removeTemporaryFile(tmpUID);
ex.printStackTrace();
@ -139,7 +140,7 @@ public class MediaResource {
} else if (data != null && data.deleted != null && data.deleted) {
LOGGER.info("Data already exist but deleted");
System.out.flush();
DataTools.undelete(data.uuid);
DataTools.undelete(db, data.oid);
data.deleted = false;
} else {
LOGGER.info("Data already exist ... all good");
@ -179,7 +180,7 @@ public class MediaResource {
try {
final Media media = new Media();
media.name = title;
media.dataId = data.uuid;
media.dataId = data.oid;
media.typeId = typeNode.id;
media.seriesId = null;
if (seriesNode != null) {
@ -193,7 +194,7 @@ public class MediaResource {
if (episode != null && !episode.contentEquals("")) {
media.episode = Integer.parseInt(episode);
}
final Media out = DataAccess.insert(media);
final Media out = db.insert(media);
LOGGER.info("Generate new media {}", out);
return out;
} catch (final SQLException ex) {
@ -219,12 +220,13 @@ public class MediaResource {
@TypeScriptProgress
public Media uploadCover( //
@PathParam("id") final Long id, //
@FormDataParam("fileName") final String fileName, //
@FormDataParam("file") final InputStream fileInputStream, //
@FormDataParam("file") final FormDataContentDisposition fileMetaData//
) throws Exception {
DataTools.uploadCover(Media.class, id, fileName, fileInputStream, fileMetaData);
return DataAccess.get(Media.class, id);
try (DBAccess dbIo = DBAccess.createInterface()) {
DataTools.uploadCover(dbIo, Media.class, id, fileInputStream, fileMetaData);
return dbIo.get(Media.class, id);
}
}
@DELETE
@ -235,8 +237,10 @@ public class MediaResource {
@PathParam("id") final Long id, //
@PathParam("coverId") final UUID coverId //
) throws Exception {
AddOnDataJson.removeLink(Media.class, id, "covers", coverId);
return DataAccess.get(Media.class, id);
try (DBAccess dbIo = DBAccess.createInterface()) {
AddOnDataJson.removeLink(dbIo, Media.class, "id", id, "covers", coverId);
return dbIo.get(Media.class, id);
}
}
@DELETE

View File

@ -8,10 +8,11 @@ import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.annotation.AsyncType;
import org.kar.archidata.annotation.TypeScriptProgress;
import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.DataAccess;
import org.kar.archidata.dataAccess.QueryAnd;
import org.kar.archidata.dataAccess.QueryCondition;
import org.kar.archidata.dataAccess.addOn.AddOnDataJson;
import org.kar.archidata.dataAccess.addOnSQL.AddOnDataJson;
import org.kar.archidata.dataAccess.options.Condition;
import org.kar.archidata.tools.DataTools;
import org.kar.karideo.model.Season;
@ -85,10 +86,12 @@ public class SeasonResource {
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Operation(description = "Upload a new season cover season", tags = "GLOBAL")
@TypeScriptProgress
public Season uploadCover(@PathParam("id") final Long id, @FormDataParam("fileName") final String fileName, @FormDataParam("file") final InputStream fileInputStream,
@FormDataParam("file") final FormDataContentDisposition fileMetaData) throws Exception {
DataTools.uploadCover(Season.class, id, fileName, fileInputStream, fileMetaData);
return DataAccess.get(Season.class, id);
public Season uploadCover(@PathParam("id") final Long id, @FormDataParam("file") final InputStream fileInputStream, @FormDataParam("file") final FormDataContentDisposition fileMetaData)
throws Exception {
try (DBAccess dbIo = DBAccess.createInterface()) {
DataTools.uploadCover(dbIo, Season.class, id, fileInputStream, fileMetaData);
return dbIo.get(Season.class, id);
}
}
@DELETE
@ -96,8 +99,10 @@ public class SeasonResource {
@RolesAllowed("ADMIN")
@Operation(description = "Remove a specific cover of a season", tags = "GLOBAL")
public Season removeCover(@PathParam("id") final Long id, @PathParam("coverId") final UUID coverId) throws Exception {
AddOnDataJson.removeLink(Season.class, id, "covers", coverId);
return DataAccess.get(Season.class, id);
try (DBAccess dbIo = DBAccess.createInterface()) {
AddOnDataJson.removeLink(dbIo, Season.class, "id", id, "covers", coverId);
return dbIo.get(Season.class, id);
}
}
public static Season getOrCreate(final String name, final Long seriesId) {

View File

@ -8,10 +8,11 @@ import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.annotation.AsyncType;
import org.kar.archidata.annotation.TypeScriptProgress;
import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.DataAccess;
import org.kar.archidata.dataAccess.QueryAnd;
import org.kar.archidata.dataAccess.QueryCondition;
import org.kar.archidata.dataAccess.addOn.AddOnDataJson;
import org.kar.archidata.dataAccess.addOnSQL.AddOnDataJson;
import org.kar.archidata.dataAccess.options.Condition;
import org.kar.archidata.tools.DataTools;
import org.kar.karideo.model.Series;
@ -85,10 +86,12 @@ public class SeriesResource {
@Consumes({ MediaType.MULTIPART_FORM_DATA })
@Operation(description = "Upload a new season cover Series", tags = "GLOBAL")
@TypeScriptProgress
public Series uploadCover(@PathParam("id") final Long id, @FormDataParam("fileName") final String fileName, @FormDataParam("file") final InputStream fileInputStream,
@FormDataParam("file") final FormDataContentDisposition fileMetaData) throws Exception {
DataTools.uploadCover(Series.class, id, fileName, fileInputStream, fileMetaData);
return DataAccess.get(Series.class, id);
public Series uploadCover(@PathParam("id") final Long id, @FormDataParam("file") final InputStream fileInputStream, @FormDataParam("file") final FormDataContentDisposition fileMetaData)
throws Exception {
try (DBAccess dbIo = DBAccess.createInterface()) {
DataTools.uploadCover(dbIo, Series.class, id, fileInputStream, fileMetaData);
return dbIo.get(Series.class, id);
}
}
@DELETE
@ -96,8 +99,10 @@ public class SeriesResource {
@RolesAllowed("ADMIN")
@Operation(description = "Remove a specific Series of a season", tags = "GLOBAL")
public Series removeCover(@PathParam("id") final Long id, @PathParam("coverId") final UUID coverId) throws Exception {
AddOnDataJson.removeLink(Series.class, id, "covers", coverId);
return DataAccess.get(Series.class, id);
try (DBAccess dbIo = DBAccess.createInterface()) {
AddOnDataJson.removeLink(dbIo, Series.class, "id", id, "covers", coverId);
return dbIo.get(Series.class, id);
}
}
public static Series getOrCreate(final String name, final Long typeId) {

View File

@ -8,9 +8,10 @@ import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.annotation.AsyncType;
import org.kar.archidata.annotation.TypeScriptProgress;
import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.DataAccess;
import org.kar.archidata.dataAccess.QueryCondition;
import org.kar.archidata.dataAccess.addOn.AddOnDataJson;
import org.kar.archidata.dataAccess.addOnSQL.AddOnDataJson;
import org.kar.archidata.dataAccess.options.Condition;
import org.kar.archidata.tools.DataTools;
import org.kar.karideo.model.Type;
@ -88,10 +89,12 @@ public class TypeResource {
@Consumes({ MediaType.MULTIPART_FORM_DATA })
@Operation(description = "Upload a new season cover Type", tags = "GLOBAL")
@TypeScriptProgress
public Type uploadCover(@PathParam("id") final Long id, @FormDataParam("fileName") final String fileName, @FormDataParam("file") final InputStream fileInputStream,
@FormDataParam("file") final FormDataContentDisposition fileMetaData) throws Exception {
DataTools.uploadCover(Type.class, id, fileName, fileInputStream, fileMetaData);
return DataAccess.get(Type.class, id);
public Type uploadCover(@PathParam("id") final Long id, @FormDataParam("file") final InputStream fileInputStream, @FormDataParam("file") final FormDataContentDisposition fileMetaData)
throws Exception {
try (DBAccess dbIo = DBAccess.createInterface()) {
DataTools.uploadCover(dbIo, Type.class, id, fileInputStream, fileMetaData);
return dbIo.get(Type.class, id);
}
}
@DELETE
@ -99,8 +102,11 @@ public class TypeResource {
@RolesAllowed("ADMIN")
@Operation(description = "Remove a specific cover of a type", tags = "GLOBAL")
public Type removeCover(@PathParam("id") final Long id, @PathParam("coverId") final UUID coverId) throws Exception {
AddOnDataJson.removeLink(Type.class, id, "covers", coverId);
return DataAccess.get(Type.class, id);
try (DBAccess dbIo = DBAccess.createInterface()) {
AddOnDataJson.removeLink(dbIo, Type.class, "id", id, "covers", coverId);
return dbIo.get(Type.class, id);
}
}
public static Type getOrCreate(final String name) {

View File

@ -90,7 +90,7 @@ public class UserMediaAdvancementResource {
elem.count++;
}
LOGGER.info("{},{},{}", elem.time, elem.percent, elem.count);
final int nbAfected = DataAccess.update(elem, elem.id, List.of("time", "percent", "count"));
final long nbAfected = DataAccess.update(elem, elem.id, List.of("time", "percent", "count"));
return DataAccess.get(UserMediaAdvancement.class, elem.id);
}

View File

@ -2,10 +2,21 @@ package org.kar.karideo.migration;
import java.util.List;
import org.kar.archidata.dataAccess.DataAccess;
import org.kar.archidata.api.DataResource;
import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.externalRestApi.AnalyzeApi;
import org.kar.archidata.externalRestApi.TsGenerateApi;
import org.kar.archidata.migration.MigrationSqlStep;
import org.kar.archidata.model.Data;
import org.kar.archidata.model.User;
import org.kar.karideo.api.Front;
import org.kar.karideo.api.HealthCheck;
import org.kar.karideo.api.MediaResource;
import org.kar.karideo.api.SeasonResource;
import org.kar.karideo.api.SeriesResource;
import org.kar.karideo.api.TypeResource;
import org.kar.karideo.api.UserMediaAdvancementResource;
import org.kar.karideo.api.UserResource;
import org.kar.karideo.model.Media;
import org.kar.karideo.model.Season;
import org.kar.karideo.model.Series;
@ -26,8 +37,14 @@ public class Initialization extends MigrationSqlStep {
return "Initialization";
}
public Initialization() {
public static void generateObjects() throws Exception {
LOGGER.info("Generate APIs");
final List<Class<?>> listOfResources = List.of(Front.class, HealthCheck.class, SeasonResource.class, SeriesResource.class, TypeResource.class, UserMediaAdvancementResource.class,
UserResource.class, MediaResource.class, DataResource.class);
final AnalyzeApi api = new AnalyzeApi();
api.addAllApi(listOfResources);
TsGenerateApi.generateApi(api, "../front/src/app/back-api/");
LOGGER.info("Generate APIs (DONE)");
}
@Override
@ -36,19 +53,21 @@ public class Initialization extends MigrationSqlStep {
addClass(clazz);
}
addAction("""
INSERT INTO `type` (`id`, `name`, `description`) VALUES
(UUID_TO_BIN('15237fd7-d4ee-11ee-a8dd-02420a030203'), 'Documentary', 'Documentary (animals, space, earth...)'),
(UUID_TO_BIN('553146c1-d4ee-11ee-a8dd-02420a030203'), 'Movie', 'Movie with real humans (film)'),
(UUID_TO_BIN('59c430a3-d4ee-11ee-a8dd-02420a030203'), 'Animation', 'Animation movies (film)'),
(UUID_TO_BIN('5cd619e3-d4ee-11ee-a8dd-02420a030203'), 'Short movie', 'Small movies (less 2 minutes)'),
(UUID_TO_BIN('5fbbf085-d4ee-11ee-a8dd-02420a030203'), 'TV show', 'TV show for old peoples'),
(UUID_TO_BIN('66dcb6ba-d4ee-11ee-a8dd-02420a030203'), 'Animation TV show', 'TV show for young peoples'),
(UUID_TO_BIN('69ee5c15-d4ee-11ee-a8dd-02420a030203'), 'Theater', 'Theater play'),
(UUID_TO_BIN('6ce72530-d4ee-11ee-a8dd-02420a030203'), 'One man show', 'Recorded stand up'),
(UUID_TO_BIN('6ff1691a-d4ee-11ee-a8dd-02420a030203'), 'Concert', 'Recorded concert'),
(UUID_TO_BIN('730815ef-d4ee-11ee-a8dd-02420a030203'), 'Opera', 'Recorded opera');
""");
addAction((final DBAccess da) -> {
final List<Type> data = List.of(//
new Type("Documentary", "Documentary (animals, space, earth...)"), //
new Type("Movie", "Movie with real humans (film)"), //
new Type("Animation", "Animation movies (film)"), //
new Type("Short movie", "Small movies (less 2 minutes)"), //
new Type("TV show", "TV show for old peoples"), //
new Type("Animation TV show", "TV show for young peoples"), //
new Type("Theater", "Theater play"), //
new Type("One man show", "Recorded stand up"), //
new Type("Concert", "Recorded concert"), //
new Type("Opera", "Recorded opera") //
);
da.insertMultiple(data);
});
// set start increment element to permit to add after default elements
addAction("""
ALTER TABLE `media` AUTO_INCREMENT = 1000;
@ -67,10 +86,10 @@ public class Initialization extends MigrationSqlStep {
""", "mysql");
}
public static void dropAll() {
public static void dropAll(final DBAccess da) {
for (final Class<?> element : CLASSES_BASE) {
try {
DataAccess.drop(element);
da.drop(element);
} catch (final Exception ex) {
LOGGER.error("Fail to drop table !!!!!!");
ex.printStackTrace();
@ -78,10 +97,10 @@ public class Initialization extends MigrationSqlStep {
}
}
public static void cleanAll() {
public static void cleanAll(final DBAccess da) {
for (final Class<?> element : CLASSES_BASE) {
try {
DataAccess.cleanAll(element);
da.cleanAll(element);
} catch (final Exception ex) {
LOGGER.error("Fail to clean table !!!!!!");
ex.printStackTrace();

View File

@ -1,23 +1,6 @@
package org.kar.karideo.migration;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.kar.archidata.api.DataResource;
import org.kar.archidata.dataAccess.DataAccess;
import org.kar.archidata.dataAccess.addOn.model.LinkTableLongLong;
import org.kar.archidata.dataAccess.options.AccessDeletedItems;
import org.kar.archidata.dataAccess.options.OverrideTableName;
import org.kar.archidata.migration.MigrationSqlStep;
import org.kar.archidata.tools.UuidUtils;
import org.kar.karideo.migration.model.CoverConversion;
import org.kar.karideo.migration.model.MediaConversion;
import org.kar.karideo.migration.model.UUIDConversion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -36,102 +19,6 @@ public class Migration20240226 extends MigrationSqlStep {
}
@Override
public void generateStep() throws Exception {
addAction("""
ALTER TABLE `data` ADD `uuid` binary(16) AFTER `id`;
""");
addAction(() -> {
final List<UUIDConversion> datas = DataAccess.gets(UUIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data"));
for (final UUIDConversion elem : datas) {
elem.uuid = UuidUtils.nextUUID();
}
for (final UUIDConversion elem : datas) {
DataAccess.update(elem, elem.id, List.of("uuid"), new OverrideTableName("data"));
}
});
addAction("""
ALTER TABLE `data` CHANGE `uuid` `uuid` binary(16) DEFAULT (UUID_TO_BIN(UUID(), TRUE));
""");
final List<String> tableToTransform = List.of("media", "season", "series", "type", "user");
for (final String tableName : tableToTransform) {
addAction("ALTER TABLE `" + tableName + "` ADD `covers` text NULL;");
addAction(() -> {
final List<UUIDConversion> datas = DataAccess.gets(UUIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data"));
final List<CoverConversion> medias = DataAccess.gets(CoverConversion.class, new AccessDeletedItems(), new OverrideTableName(tableName));
final List<LinkTableLongLong> links = DataAccess.gets(LinkTableLongLong.class, new OverrideTableName(tableName + "_link_cover"));
LOGGER.info("Get somes data: {} {} {}", datas.size(), medias.size(), links.size());
for (final CoverConversion media : medias) {
final List<UUID> values = new ArrayList<>();
for (final LinkTableLongLong link : links) {
if (link.object1Id.equals(media.id)) {
for (final UUIDConversion data : datas) {
if (data.id.equals(link.object2Id)) {
values.add(data.uuid);
break;
}
}
break;
}
}
if (values.size() != 0) {
media.covers = values;
LOGGER.info(" update: {} => {}", media.id, media.covers);
DataAccess.update(media, media.id, List.of("covers"), new OverrideTableName(tableName));
}
}
});
addAction("DROP TABLE `" + tableName + "_link_cover`;");
}
addAction("""
ALTER TABLE `media` ADD `dataUUID` binary(16) AFTER dataId;
""");
addAction(() -> {
final List<UUIDConversion> datas = DataAccess.gets(UUIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data"));
final List<MediaConversion> medias = DataAccess.gets(MediaConversion.class, new AccessDeletedItems(), new OverrideTableName("media"));
for (final MediaConversion media : medias) {
for (final UUIDConversion data : datas) {
if (data.id.equals(media.dataId)) {
media.dataUUID = data.uuid;
DataAccess.update(media, media.id, List.of("dataUUID"), new OverrideTableName("media"));
break;
}
}
}
});
addAction("""
ALTER TABLE `media` DROP `dataId`;
""");
addAction("""
ALTER TABLE `media` CHANGE `dataUUID` `dataId` binary(16) NOT NULL;
""");
// Move the files...
addAction(() -> {
final List<UUIDConversion> datas = DataAccess.gets(UUIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data"));
for (final UUIDConversion data : datas) {
final String origin = DataResource.getFileDataOld(data.id);
final String destination = DataResource.getFileData(data.uuid);
LOGGER.info("move file = {}", origin);
LOGGER.info(" ==> {}", destination);
try {
Files.move(Paths.get(origin), Paths.get(destination), StandardCopyOption.ATOMIC_MOVE);
} catch (final NoSuchFileException ex) {
LOGGER.error("MOVE_ERROR : {} -> {}", origin, destination);
}
}
});
/* I am not sure then I prefer keep the primary key for the moment addAction(""" ALTER TABLE `data` DROP `id`; """); */
addAction("""
ALTER TABLE `data` CHANGE `id` `idOld` bigint NOT NULL DEFAULT 0;
""");
addAction("""
ALTER TABLE `data` DROP PRIMARY KEY;
""");
addAction("""
ALTER TABLE `data` CHANGE `uuid` `id` binary(16) DEFAULT (UUID_TO_BIN(UUID(), TRUE));
""");
addAction("""
ALTER TABLE `data` ADD PRIMARY KEY `id` (`id`);
""");
}
public void generateStep() throws Exception {}
}

View File

@ -0,0 +1,28 @@
package org.kar.karideo.migration;
import org.kar.archidata.migration.MigrationSqlStep;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Migration20240611 extends MigrationSqlStep {
private static final Logger LOGGER = LoggerFactory.getLogger(Migration20240226.class);
public static final int KARSO_INITIALISATION_ID = 1;
@Override
public String getName() {
return "migration-2024-06-11: corect data uuid";
}
public Migration20240611() {
}
@Override
public void generateStep() throws Exception {
addAction("""
ALTER TABLE `data` CHANGE `id` `uuid` binary(16) DEFAULT (UUID_TO_BIN(UUID(), TRUE));
""");
}
}

View File

@ -0,0 +1,126 @@
package org.kar.karideo.migration;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bson.types.ObjectId;
import org.kar.archidata.api.DataResource;
import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.options.AccessDeletedItems;
import org.kar.archidata.dataAccess.options.OverrideTableName;
import org.kar.archidata.migration.MigrationSqlStep;
import org.kar.karideo.migration.model.CoverConversion;
import org.kar.karideo.migration.model.MediaConversion;
import org.kar.karideo.migration.model.OIDConversion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Migration20250214 extends MigrationSqlStep {
private static final Logger LOGGER = LoggerFactory.getLogger(Migration20240226.class);
public static final int KARSO_INITIALISATION_ID = 1;
@Override
public String getName() {
return "migration-2025-01-04: convert base from UUID to OID";
}
@Override
public void generateStep() throws Exception {
addAction("""
ALTER TABLE `data` ADD `_id` binary(12) AFTER `uuid`;
""");
addAction((final DBAccess da) -> {
final List<OIDConversion> datas = da.gets(OIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data"));
for (final OIDConversion elem : datas) {
elem._id = new ObjectId();
}
for (final OIDConversion elem : datas) {
da.update(elem, elem.uuid, List.of("_id"), new OverrideTableName("data"));
}
});
final List<String> tableToTransform = List.of("media", "season", "series", "type", "user");
for (final String tableName : tableToTransform) {
addAction("ALTER TABLE `" + tableName + "` ADD `covers_oid` text NULL;");
addAction((final DBAccess da) -> {
final List<OIDConversion> datas = da.gets(OIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data"));
final List<CoverConversion> tableCoverTransforms = da.gets(CoverConversion.class, new AccessDeletedItems(), new OverrideTableName(tableName));
LOGGER.info("Get somes data: {} {}", datas.size(), tableCoverTransforms.size());
for (final CoverConversion tableTransform : tableCoverTransforms) {
final List<ObjectId> values = new ArrayList<>();
if (tableTransform.covers == null) {
continue;
}
for (final UUID link : tableTransform.covers) {
for (final OIDConversion data : datas) {
if (data.uuid.equals(link)) {
values.add(data._id);
break;
}
}
}
if (values.size() != 0) {
tableTransform.covers_oid = values;
LOGGER.info(" update: {}: {} => {}", tableTransform.id, tableTransform.covers, tableTransform.covers_oid);
da.update(tableTransform, tableTransform.id, List.of("covers_oid"), new OverrideTableName(tableName));
}
}
});
addAction("ALTER TABLE `" + tableName + "` DROP `covers`;");
addAction("ALTER TABLE `" + tableName + "` CHANGE `covers_oid` `covers` text NULL;");
}
addAction("""
ALTER TABLE `media` ADD `dataOid` binary(12) AFTER dataId;
""");
addAction((final DBAccess da) -> {
final List<OIDConversion> datas = da.gets(OIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data"));
final List<MediaConversion> medias = da.gets(MediaConversion.class, new AccessDeletedItems(), new OverrideTableName("media"));
for (final MediaConversion media : medias) {
for (final OIDConversion data : datas) {
if (data.uuid.equals(media.dataId)) {
media.dataOid = data._id;
da.update(media, media.id, List.of("dataOid"), new OverrideTableName("media"));
break;
}
}
}
});
addAction("""
ALTER TABLE `media` DROP `dataId`;
""");
addAction("""
ALTER TABLE `media` CHANGE `dataOid` `dataId` binary(12) NOT NULL;
""");
// Move the files...
addAction((final DBAccess da) -> {
final List<OIDConversion> datas = da.gets(OIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data"));
for (final OIDConversion data : datas) {
final String origin = DataResource.getFileDataOld(data.uuid);
final String destination = DataResource.getFileData(data._id);
LOGGER.info("move file = {}", origin);
LOGGER.info(" ==> {}", destination);
try {
Files.move(Paths.get(origin), Paths.get(destination), StandardCopyOption.ATOMIC_MOVE);
} catch (final NoSuchFileException ex) {
LOGGER.warn("Fail to move file : {}", ex.getMessage());
}
}
});
addAction("""
ALTER TABLE `data` DROP INDEX `PRIMARY`;
""");
// addAction("""
// ALTER TABLE `data` DROP `uuid`;
// """);
addAction("""
ALTER TABLE `data` ADD PRIMARY KEY `_id` (`_id`);
""");
}
}

View File

@ -3,6 +3,7 @@ package org.kar.karideo.migration.model;
import java.util.List;
import java.util.UUID;
import org.bson.types.ObjectId;
import org.kar.archidata.annotation.DataJson;
import jakarta.persistence.Id;
@ -12,4 +13,6 @@ public class CoverConversion {
public Long id = null;
@DataJson
public List<UUID> covers = null;
@DataJson
public List<ObjectId> covers_oid = null;
}

View File

@ -2,11 +2,12 @@ package org.kar.karideo.migration.model;
import java.util.UUID;
import org.bson.types.ObjectId;
import jakarta.persistence.Id;
public class MediaConversion {
@Id
public Long id = null;
public Long dataId = null;
public UUID dataUUID = null;
public UUID dataId = null;
public ObjectId dataOid = null;
}

View File

@ -2,10 +2,12 @@ package org.kar.karideo.migration.model;
import java.util.UUID;
import org.bson.types.ObjectId;
import jakarta.persistence.Id;
public class UUIDConversion {
public class OIDConversion {
@Id
public Long id = null;
public UUID uuid = null;
public ObjectId _id = null;
}

View File

@ -1,8 +1,8 @@
package org.kar.karideo.model;
import java.util.List;
import java.util.UUID;
import org.bson.types.ObjectId;
import org.kar.archidata.annotation.DataJson;
import org.kar.archidata.model.Data;
import org.kar.archidata.model.GenericDataSoftDelete;
@ -10,6 +10,7 @@ import org.kar.archidata.model.GenericDataSoftDelete;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Nullable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
@ -29,7 +30,7 @@ public class Media extends GenericDataSoftDelete {
@Schema(description = "Foreign Key Id of the data")
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Data.class)
@Column(nullable = false)
public UUID dataId;
public ObjectId dataId;
@Schema(description = "Type of the media")
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Type.class)
public Long typeId;
@ -49,7 +50,8 @@ public class Media extends GenericDataSoftDelete {
public Integer ageLimit;
@Schema(description = "List of Id of the specific covers")
@DataJson(targetEntity = Data.class)
public List<UUID> covers = null;
@Nullable
public List<ObjectId> covers = null;
@Override
public String toString() {

View File

@ -1,8 +1,8 @@
package org.kar.karideo.model;
import java.util.List;
import java.util.UUID;
import org.bson.types.ObjectId;
import org.kar.archidata.annotation.DataIfNotExists;
import org.kar.archidata.annotation.DataJson;
import org.kar.archidata.model.GenericDataSoftDelete;
@ -10,6 +10,7 @@ import org.kar.archidata.model.GenericDataSoftDelete;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Nullable;
import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToOne;
@ -31,5 +32,6 @@ public class Season extends GenericDataSoftDelete {
public Long parentId;
@Schema(description = "List of Id of the specific covers")
@DataJson()
public List<UUID> covers = null;
@Nullable
public List<ObjectId> covers = null;
}

View File

@ -1,8 +1,8 @@
package org.kar.karideo.model;
import java.util.List;
import java.util.UUID;
import org.bson.types.ObjectId;
import org.kar.archidata.annotation.DataIfNotExists;
import org.kar.archidata.annotation.DataJson;
import org.kar.archidata.model.GenericDataSoftDelete;
@ -10,6 +10,7 @@ import org.kar.archidata.model.GenericDataSoftDelete;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Nullable;
import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToOne;
@ -31,5 +32,6 @@ public class Series extends GenericDataSoftDelete {
public Long parentId;
@Schema(description = "List of Id of the specific covers")
@DataJson()
public List<UUID> covers = null;
@Nullable
public List<ObjectId> covers = null;
}

View File

@ -1,8 +1,8 @@
package org.kar.karideo.model;
import java.util.List;
import java.util.UUID;
import org.bson.types.ObjectId;
import org.kar.archidata.annotation.DataIfNotExists;
import org.kar.archidata.annotation.DataJson;
import org.kar.archidata.model.GenericDataSoftDelete;
@ -10,6 +10,7 @@ import org.kar.archidata.model.GenericDataSoftDelete;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Nullable;
import jakarta.persistence.Column;
import jakarta.persistence.Table;
@ -25,5 +26,14 @@ public class Type extends GenericDataSoftDelete {
public String description;
@Schema(description = "List of Id of the specific covers")
@DataJson()
public List<UUID> covers = null;
@Nullable
public List<ObjectId> covers = null;
public Type() {}
public Type(final String name, final String description) {
this.name = name;
this.description = description;
}
}

View File

@ -7,6 +7,7 @@ import org.kar.archidata.model.GenericDataSoftDelete;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Nullable;
import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToOne;
@ -20,6 +21,7 @@ public class UserMediaAdvancement extends GenericDataSoftDelete {
@Column(nullable = false)
@Schema(description = "Foreign Key Id of the user")
@ManyToOne(fetch = FetchType.LAZY, targetEntity = UserKarideo.class)
@Nullable
public Long userId;
@Column(nullable = false)
@Schema(description = "Id of the media")

View File

@ -0,0 +1,128 @@
package test.kar.karideo;
import java.io.IOException;
import java.util.List;
import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.db.DbConfig;
import org.kar.archidata.db.DbIoFactory;
import org.kar.archidata.exception.DataAccessException;
import org.kar.archidata.tools.ConfigBaseVariable;
import org.kar.karideo.model.Media;
import org.kar.karideo.model.Season;
import org.kar.karideo.model.Series;
import org.kar.karideo.model.Type;
import org.kar.karideo.model.UserKarideo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
public class ConfigureDb {
final static private Logger LOGGER = LoggerFactory.getLogger(ConfigureDb.class);
final static private String modeTestForced = null;// "MONGO";
public static DBAccess da = null;
public static void configure() throws IOException, InternalServerErrorException, DataAccessException {
String modeTest = System.getenv("TEST_E2E_MODE");
if (modeTest == null || modeTest.isEmpty() || "false".equalsIgnoreCase(modeTest)) {
modeTest = "SQLITE-MEMORY";
} else if ("true".equalsIgnoreCase(modeTest)) {
modeTest = "MY-SQL";
}
// override the local test:
if (modeTestForced != null) {
modeTest = modeTestForced;
}
// for local test:
ConfigBaseVariable.apiAdress = "http://127.0.0.1:12342/test/api/";
// Enable the test mode permit to access to the test token (never use it in production).
ConfigBaseVariable.testMode = "true";
final List<Class<?>> listObject = List.of( //
Media.class, //
Season.class, //
Series.class, //
Type.class, //
UserKarideo.class //
);
if ("SQLITE-MEMORY".equalsIgnoreCase(modeTest)) {
ConfigBaseVariable.dbType = "sqlite";
ConfigBaseVariable.bdDatabase = null;
ConfigBaseVariable.dbHost = "memory";
// for test we need to connect all time the DB
ConfigBaseVariable.dbKeepConnected = "true";
} else if ("SQLITE".equalsIgnoreCase(modeTest)) {
ConfigBaseVariable.dbType = "sqlite";
ConfigBaseVariable.bdDatabase = null;
ConfigBaseVariable.dbKeepConnected = "true";
} else if ("MY-SQL".equalsIgnoreCase(modeTest)) {
ConfigBaseVariable.dbType = "mysql";
ConfigBaseVariable.bdDatabase = "test_Karideo_db";
ConfigBaseVariable.dbPort = "3906";
ConfigBaseVariable.dbUser = "root";
} else if ("MONGO".equalsIgnoreCase(modeTest)) {
ConfigBaseVariable.dbType = "mongo";
ConfigBaseVariable.bdDatabase = "test_Karideo_db";
} else {
// User local modification ...
ConfigBaseVariable.bdDatabase = "test_Karideo_db";
ConfigBaseVariable.dbPort = "3906";
ConfigBaseVariable.dbUser = "root";
}
removeDB();
// Connect the dataBase...
da = DBAccess.createInterface();
}
public static void removeDB() {
String modeTest = System.getenv("TEST_E2E_MODE");
if (modeTest == null || modeTest.isEmpty() || "false".equalsIgnoreCase(modeTest)) {
modeTest = "SQLITE-MEMORY";
} else if ("true".equalsIgnoreCase(modeTest)) {
modeTest = "MY-SQL";
}
// override the local test:
if (modeTestForced != null) {
modeTest = modeTestForced;
}
DbConfig config = null;
try {
config = new DbConfig();
} catch (final DataAccessException e) {
e.printStackTrace();
LOGGER.error("Fail to clean the DB");
return;
}
config.setDbName(null);
LOGGER.info("Remove the DB and create a new one '{}'", config.getDbName());
try (final DBAccess daRoot = DBAccess.createInterface(config)) {
if ("SQLITE-MEMORY".equalsIgnoreCase(modeTest)) {
// nothing to do ...
} else if ("SQLITE".equalsIgnoreCase(modeTest)) {
daRoot.deleteDB(ConfigBaseVariable.bdDatabase);
} else if ("MY-SQL".equalsIgnoreCase(modeTest)) {
daRoot.deleteDB(ConfigBaseVariable.bdDatabase);
} else if ("MONGO".equalsIgnoreCase(modeTest)) {
daRoot.deleteDB(ConfigBaseVariable.bdDatabase);
}
daRoot.createDB(ConfigBaseVariable.bdDatabase);
} catch (final InternalServerErrorException e) {
e.printStackTrace();
LOGGER.error("Fail to clean the DB");
return;
} catch (final IOException e) {
e.printStackTrace();
LOGGER.error("Fail to clean the DB");
return;
}
}
public static void clear() throws IOException {
LOGGER.info("Remove the test db");
removeDB();
// The connection is by default open ==> close it at the end of test:
da.close();
DbIoFactory.closeAllForceMode();
ConfigBaseVariable.clearAllValue();
}
}

View File

@ -0,0 +1,48 @@
package test.kar.karideo;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.kar.archidata.tools.ConfigBaseVariable;
import org.kar.archidata.tools.RESTApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ExtendWith(StepwiseExtension.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class TestBase {
private final static Logger LOGGER = LoggerFactory.getLogger(TestBase.class);
public final static String ENDPOINT_NAME = "species/";
static WebLauncherTest webInterface = null;
static RESTApi api = null;
@BeforeAll
public static void configureWebServer() throws Exception {
ConfigureDb.configure();
LOGGER.info("configure server ...");
webInterface = new WebLauncherTest();
LOGGER.info("Start REST (BEGIN)");
webInterface.process();
LOGGER.info("Start REST (DONE)");
api = new RESTApi(ConfigBaseVariable.apiAdress);
api.setToken(Common.ADMIN_TOKEN);
}
@AfterAll
public static void stopWebServer() throws Exception {
LOGGER.info("Kill the web server");
webInterface.stop();
webInterface = null;
ConfigureDb.clear();
}
@Test
public static void TestEmpty() throws Exception {
}
}

View File

@ -10,8 +10,7 @@ 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.exception.RESTErrorResponseException;
import org.kar.archidata.tools.ConfigBaseVariable;
import org.kar.archidata.tools.RESTApi;
import org.kar.karideo.api.HealthCheck.HealthResult;
@ -49,7 +48,7 @@ public class TestHealthCheck {
webInterface.stop();
webInterface = null;
LOGGER.info("Remove the test db");
DBEntry.closeAllForceMode();
// DBEntry.closeAllForceMode();
ConfigBaseVariable.clearAllValue();
}
@ -64,7 +63,7 @@ public class TestHealthCheck {
@Order(2)
@Test
public void checkHealthCheckWrongAPI() throws Exception {
Assertions.assertThrows(RESTErrorResponseExeption.class, () -> api.get(HealthResult.class, "health_checks"));
Assertions.assertThrows(RESTErrorResponseException.class, () -> api.get(HealthResult.class, "health_checks"));
}
}

View File

@ -1,7 +1,6 @@
package test.kar.karideo;
import org.kar.archidata.tools.ConfigBaseVariable;
import org.kar.karideo.WebLauncher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -9,26 +8,5 @@ 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:12342/test/api/";
// Enable the test mode permit to access to the test token (never use it in production).
ConfigBaseVariable.testMode = "true";
// for the test we a in memory sqlite..
if (true) {
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
ConfigBaseVariable.dbType = "sqlite";
ConfigBaseVariable.dbHost = "memory";
// for test we need to connect all time the DB
ConfigBaseVariable.dbKeepConnected = "true";
}
} else {
// Enable this if you want to access to a local MySQL base to test with an adminer
ConfigBaseVariable.bdDatabase = "test_db";
ConfigBaseVariable.dbPort = "3309";
ConfigBaseVariable.dbUser = "root";
ConfigBaseVariable.dbPassword = "password";
}
}
public WebLauncherTest() {}
}

View File

@ -1,50 +0,0 @@
{
"name": "karideo",
"version": "0.0.0",
"license": "MPL-2",
"scripts": {
"all": "npm run build && npm run test",
"ng": "ng",
"dev": "ng serve --configuration=develop --watch --port 4202",
"dev-hot-update": "ng serve --configuration=develop --watch --hmr --port 4202",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"style": "prettier --write .",
"e2e": "ng e2e",
"update_packages": "ncu --upgrade",
"install_dependency": "pnpm install --force",
"link_kar_cw": "pnpm link ../../kar-cw/dist/kar-cw/",
"unlink_kar_cw": "pnpm unlink ../../kar-cw/dist/kar-cw/"
},
"private": true,
"dependencies": {
"@angular/animations": "^18.0.2",
"@angular/cdk": "^18.0.2",
"@angular/common": "^18.0.2",
"@angular/compiler": "^18.0.2",
"@angular/core": "^18.0.2",
"@angular/forms": "^18.0.2",
"@angular/material": "^18.0.2",
"@angular/platform-browser": "^18.0.2",
"@angular/platform-browser-dynamic": "^18.0.2",
"@angular/router": "^18.0.2",
"rxjs": "^7.8.1",
"zone.js": "^0.14.6",
"zod": "3.23.8",
"@kangaroo-and-rabbit/kar-cw": "^0.4.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "^18.0.3",
"@angular-eslint/builder": "18.0.1",
"@angular-eslint/eslint-plugin": "18.0.1",
"@angular-eslint/eslint-plugin-template": "18.0.1",
"@angular-eslint/schematics": "18.0.1",
"@angular-eslint/template-parser": "18.0.1",
"@angular/cli": "^18.0.3",
"@angular/compiler-cli": "^18.0.2",
"@angular/language-service": "^18.0.2",
"npm-check-updates": "^16.14.20",
"tslib": "^2.6.3"
}
}

View File

@ -0,0 +1,50 @@
{
"name": "karideo",
"version": "0.0.0",
"license": "MPL-2",
"scripts": {
"all": "npm run build && npm run test",
"ng": "ng",
"dev": "ng serve --configuration=develop --watch --port 4202",
"dev-hot-update": "ng serve --configuration=develop --watch --hmr --port 4202",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"style": "prettier --write .",
"e2e": "ng e2e",
"update_packages": "ncu --upgrade",
"install_dependency": "pnpm install --force",
"link_kar_cw": "pnpm link ../../kar-cw/dist/kar-cw/",
"unlink_kar_cw": "pnpm unlink ../../kar-cw/dist/kar-cw/"
},
"private": true,
"dependencies": {
"@angular/animations": "^18.1.3",
"@angular/cdk": "^18.1.3",
"@angular/common": "^18.1.3",
"@angular/compiler": "^18.1.3",
"@angular/core": "^18.1.3",
"@angular/forms": "^18.1.3",
"@angular/material": "^18.1.3",
"@angular/platform-browser": "^18.1.3",
"@angular/platform-browser-dynamic": "^18.1.3",
"@angular/router": "^18.1.3",
"rxjs": "^7.8.1",
"zone.js": "^0.14.8",
"zod": "3.23.8",
"@kangaroo-and-rabbit/kar-cw": "^0.4.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "^18.1.3",
"@angular-eslint/builder": "18.2.0",
"@angular-eslint/eslint-plugin": "18.2.0",
"@angular-eslint/eslint-plugin-template": "18.2.0",
"@angular-eslint/schematics": "18.2.0",
"@angular-eslint/template-parser": "18.2.0",
"@angular/cli": "^18.1.3",
"@angular/compiler-cli": "^18.1.3",
"@angular/language-service": "^18.1.3",
"npm-check-updates": "^17.0.0",
"tslib": "^2.6.3"
}
}

View File

@ -10,7 +10,7 @@ import {
} from "../rest-tools";
import {
UUID,
ObjectId,
} from "../model";
export namespace DataResource {
@ -30,13 +30,13 @@ export namespace DataResource {
},
params: {
name: string,
uuid: UUID,
oid: ObjectId,
},
data: string,
}): Promise<object> {
return RESTRequestJson({
restModel: {
endPoint: "/data/{uuid}/{name}",
endPoint: "/data/{oid}/{name}",
requestType: HTTPRequestModel.GET,
},
restConfig,
@ -59,13 +59,13 @@ export namespace DataResource {
Authorization?: string,
},
params: {
uuid: UUID,
oid: ObjectId,
},
data: string,
}): Promise<object> {
return RESTRequestJson({
restModel: {
endPoint: "/data/{uuid}",
endPoint: "/data/{oid}",
requestType: HTTPRequestModel.GET,
},
restConfig,
@ -88,13 +88,13 @@ export namespace DataResource {
Authorization?: string,
},
params: {
uuid: UUID,
oid: ObjectId,
},
data: string,
}): Promise<object> {
return RESTRequestJson({
restModel: {
endPoint: "/data/thumbnail/{uuid}",
endPoint: "/data/thumbnail/{oid}",
requestType: HTTPRequestModel.GET,
},
restConfig,

View File

@ -154,17 +154,16 @@ export namespace MediaResource {
restConfig,
params,
data,
callback,
callbacks,
}: {
restConfig: RESTConfig,
params: {
id: Long,
},
data: {
fileName: string,
file: File,
},
callback?: RESTCallbacks,
callbacks?: RESTCallbacks,
}): Promise<Media> {
return RESTRequestJson({
restModel: {
@ -176,7 +175,7 @@ export namespace MediaResource {
restConfig,
params,
data,
callback,
callbacks,
}, isMedia);
};
/**
@ -185,7 +184,7 @@ export namespace MediaResource {
export function uploadFile({
restConfig,
data,
callback,
callbacks,
}: {
restConfig: RESTConfig,
data: {
@ -198,7 +197,7 @@ export namespace MediaResource {
typeId: string,
title: string,
},
callback?: RESTCallbacks,
callbacks?: RESTCallbacks,
}): Promise<Media> {
return RESTRequestJson({
restModel: {
@ -209,7 +208,7 @@ export namespace MediaResource {
},
restConfig,
data,
callback,
callbacks,
}, isMedia);
};
}

View File

@ -176,17 +176,16 @@ export namespace SeasonResource {
restConfig,
params,
data,
callback,
callbacks,
}: {
restConfig: RESTConfig,
params: {
id: Long,
},
data: {
fileName: string,
file: File,
},
callback?: RESTCallbacks,
callbacks?: RESTCallbacks,
}): Promise<Season> {
return RESTRequestJson({
restModel: {
@ -198,7 +197,7 @@ export namespace SeasonResource {
restConfig,
params,
data,
callback,
callbacks,
}, isSeason);
};
}

View File

@ -176,17 +176,16 @@ export namespace SeriesResource {
restConfig,
params,
data,
callback,
callbacks,
}: {
restConfig: RESTConfig,
params: {
id: Long,
},
data: {
fileName: string,
file: File,
},
callback?: RESTCallbacks,
callbacks?: RESTCallbacks,
}): Promise<Series> {
return RESTRequestJson({
restModel: {
@ -198,7 +197,7 @@ export namespace SeriesResource {
restConfig,
params,
data,
callback,
callbacks,
}, isSeries);
};
}

View File

@ -176,17 +176,16 @@ export namespace TypeResource {
restConfig,
params,
data,
callback,
callbacks,
}: {
restConfig: RESTConfig,
params: {
id: Long,
},
data: {
fileName: string,
file: File,
},
callback?: RESTCallbacks,
callbacks?: RESTCallbacks,
}): Promise<Type> {
return RESTRequestJson({
restModel: {
@ -198,7 +197,7 @@ export namespace TypeResource {
restConfig,
params,
data,
callback,
callbacks,
}, isType);
};
}

View File

@ -0,0 +1,67 @@
/**
* Interface of the server (auto-generated code)
*/
import { z as zod } from "zod";
import {ZodLong} from "./long";
import {ZodObjectId} from "./object-id";
import {ZodOIDGenericDataSoftDelete, ZodOIDGenericDataSoftDeleteWrite } from "./oid-generic-data-soft-delete";
export const ZodData = ZodOIDGenericDataSoftDelete.extend({
/**
* Sha512 of the data
*/
sha512: zod.string().max(512),
/**
* Mime -type of the media
*/
mimeType: zod.string().max(512),
/**
* Size in Byte of the data
*/
size: ZodLong,
/**
* Unique ObjectID of the object
*/
oid: ZodObjectId.readonly(),
});
export type Data = zod.infer<typeof ZodData>;
export function isData(data: any): data is Data {
try {
ZodData.parse(data);
return true;
} catch (e: any) {
console.log(`Fail to parse data type='ZodData' error=${e}`);
return false;
}
}
export const ZodDataWrite = ZodOIDGenericDataSoftDeleteWrite.extend({
/**
* Sha512 of the data
*/
sha512: zod.string().max(512).optional(),
/**
* Mime -type of the media
*/
mimeType: zod.string().max(512).optional(),
/**
* Size in Byte of the data
*/
size: ZodLong.optional(),
});
export type DataWrite = zod.infer<typeof ZodDataWrite>;
export function isDataWrite(data: any): data is DataWrite {
try {
ZodDataWrite.parse(data);
return true;
} catch (e: any) {
console.log(`Fail to parse data type='ZodDataWrite' error=${e}`);
return false;
}
}

View File

@ -3,7 +3,7 @@
*/
import { z as zod } from "zod";
import {ZodGenericData} from "./generic-data";
import {ZodGenericData, ZodGenericDataWrite } from "./generic-data";
export const ZodGenericDataSoftDelete = ZodGenericData.extend({
/**
@ -24,14 +24,7 @@ export function isGenericDataSoftDelete(data: any): data is GenericDataSoftDelet
return false;
}
}
export const ZodGenericDataSoftDeleteWrite = ZodGenericDataSoftDelete.omit({
deleted: true,
id: true,
createdAt: true,
updatedAt: true,
}).partial();
export const ZodGenericDataSoftDeleteWrite = ZodGenericDataWrite;
export type GenericDataSoftDeleteWrite = zod.infer<typeof ZodGenericDataSoftDeleteWrite>;

View File

@ -4,7 +4,7 @@
import { z as zod } from "zod";
import {ZodLong} from "./long";
import {ZodGenericTiming} from "./generic-timing";
import {ZodGenericTiming, ZodGenericTimingWrite } from "./generic-timing";
export const ZodGenericData = ZodGenericTiming.extend({
/**
@ -25,13 +25,7 @@ export function isGenericData(data: any): data is GenericData {
return false;
}
}
export const ZodGenericDataWrite = ZodGenericData.omit({
id: true,
createdAt: true,
updatedAt: true,
}).partial();
export const ZodGenericDataWrite = ZodGenericTimingWrite;
export type GenericDataWrite = zod.infer<typeof ZodGenericDataWrite>;

View File

@ -28,12 +28,9 @@ export function isGenericTiming(data: any): data is GenericTiming {
return false;
}
}
export const ZodGenericTimingWrite = zod.object({
export const ZodGenericTimingWrite = ZodGenericTiming.omit({
createdAt: true,
updatedAt: true,
}).partial();
});
export type GenericTimingWrite = zod.infer<typeof ZodGenericTimingWrite>;

View File

@ -19,8 +19,9 @@ export function isHealthResult(data: any): data is HealthResult {
return false;
}
}
export const ZodHealthResultWrite = zod.object({
export const ZodHealthResultWrite = ZodHealthResult.partial();
});
export type HealthResultWrite = zod.infer<typeof ZodHealthResultWrite>;

View File

@ -1,17 +1,20 @@
/**
* Interface of the server (auto-generated code)
*/
export * from "./data"
export * from "./float"
export * from "./generic-data"
export * from "./generic-data-soft-delete"
export * from "./generic-timing"
export * from "./health-result"
export * from "./int"
export * from "./integer"
export * from "./iso-date"
export * from "./long"
export * from "./media"
export * from "./media-informations-delta"
export * from "./object-id"
export * from "./oid-generic-data"
export * from "./oid-generic-data-soft-delete"
export * from "./rest-error-response"
export * from "./season"
export * from "./series"

View File

@ -19,8 +19,9 @@ export function isint(data: any): data is int {
return false;
}
}
export const ZodintWrite = zod.object({
export const ZodintWrite = Zodint.partial();
});
export type intWrite = zod.infer<typeof ZodintWrite>;

View File

@ -19,8 +19,9 @@ export function isMediaInformationsDelta(data: any): data is MediaInformationsDe
return false;
}
}
export const ZodMediaInformationsDeltaWrite = zod.object({
export const ZodMediaInformationsDeltaWrite = ZodMediaInformationsDelta.partial();
});
export type MediaInformationsDeltaWrite = zod.infer<typeof ZodMediaInformationsDeltaWrite>;

View File

@ -3,10 +3,10 @@
*/
import { z as zod } from "zod";
import {ZodUUID} from "./uuid";
import {ZodObjectId} from "./object-id";
import {ZodLong} from "./long";
import {ZodInteger} from "./integer";
import {ZodGenericDataSoftDelete} from "./generic-data-soft-delete";
import {ZodGenericDataSoftDelete, ZodGenericDataSoftDeleteWrite } from "./generic-data-soft-delete";
export const ZodMedia = ZodGenericDataSoftDelete.extend({
/**
@ -20,7 +20,7 @@ export const ZodMedia = ZodGenericDataSoftDelete.extend({
/**
* Foreign Key Id of the data
*/
dataId: ZodUUID,
dataId: ZodObjectId,
/**
* Type of the media
*/
@ -49,7 +49,7 @@ export const ZodMedia = ZodGenericDataSoftDelete.extend({
/**
* List of Id of the specific covers
*/
covers: zod.array(ZodUUID),
covers: zod.array(ZodObjectId).optional(),
});
@ -64,14 +64,50 @@ export function isMedia(data: any): data is Media {
return false;
}
}
export const ZodMediaWrite = ZodGenericDataSoftDeleteWrite.extend({
/**
* Name of the media (this represent the title)
*/
name: zod.string().optional(),
/**
* Description of the media
*/
description: zod.string().nullable().optional(),
/**
* Foreign Key Id of the data
*/
dataId: ZodObjectId.optional(),
/**
* Type of the media
*/
typeId: ZodLong.nullable().optional(),
/**
* Series reference of the media
*/
seriesId: ZodLong.nullable().optional(),
/**
* Season reference of the media
*/
seasonId: ZodLong.nullable().optional(),
/**
* Episode Id
*/
episode: ZodInteger.nullable().optional(),
date: ZodInteger.nullable().optional(),
/**
* Creation years of the media
*/
time: ZodInteger.nullable().optional(),
/**
* Limitation Age of the media
*/
ageLimit: ZodInteger.nullable().optional(),
/**
* List of Id of the specific covers
*/
covers: zod.array(ZodObjectId).nullable().optional(),
export const ZodMediaWrite = ZodMedia.omit({
deleted: true,
id: true,
createdAt: true,
updatedAt: true,
}).partial();
});
export type MediaWrite = zod.infer<typeof ZodMediaWrite>;

View File

@ -0,0 +1,8 @@
/**
* Interface of the server (auto-generated code)
*/
import { z as zod } from "zod";
export const ZodObjectId = zod.string().length(24, "Invalid ObjectId length").regex(/^[a-fA-F0-9]{24}$/, "Invalid ObjectId format");
export type ObjectId = zod.infer<typeof ZodObjectId>;

View File

@ -0,0 +1,44 @@
/**
* Interface of the server (auto-generated code)
*/
import { z as zod } from "zod";
import {ZodObjectId} from "./object-id";
import {ZodOIDGenericData, ZodOIDGenericDataWrite } from "./oid-generic-data";
export const ZodOIDGenericDataSoftDelete = ZodOIDGenericData.extend({
/**
* Deleted state
*/
deleted: zod.boolean().readonly().optional(),
/**
* Unique ObjectID of the object
*/
oid: ZodObjectId.readonly(),
});
export type OIDGenericDataSoftDelete = zod.infer<typeof ZodOIDGenericDataSoftDelete>;
export function isOIDGenericDataSoftDelete(data: any): data is OIDGenericDataSoftDelete {
try {
ZodOIDGenericDataSoftDelete.parse(data);
return true;
} catch (e: any) {
console.log(`Fail to parse data type='ZodOIDGenericDataSoftDelete' error=${e}`);
return false;
}
}
export const ZodOIDGenericDataSoftDeleteWrite = ZodOIDGenericDataWrite;
export type OIDGenericDataSoftDeleteWrite = zod.infer<typeof ZodOIDGenericDataSoftDeleteWrite>;
export function isOIDGenericDataSoftDeleteWrite(data: any): data is OIDGenericDataSoftDeleteWrite {
try {
ZodOIDGenericDataSoftDeleteWrite.parse(data);
return true;
} catch (e: any) {
console.log(`Fail to parse data type='ZodOIDGenericDataSoftDeleteWrite' error=${e}`);
return false;
}
}

View File

@ -0,0 +1,40 @@
/**
* Interface of the server (auto-generated code)
*/
import { z as zod } from "zod";
import {ZodObjectId} from "./object-id";
import {ZodGenericTiming, ZodGenericTimingWrite } from "./generic-timing";
export const ZodOIDGenericData = ZodGenericTiming.extend({
/**
* Unique ObjectID of the object
*/
oid: ZodObjectId.readonly(),
});
export type OIDGenericData = zod.infer<typeof ZodOIDGenericData>;
export function isOIDGenericData(data: any): data is OIDGenericData {
try {
ZodOIDGenericData.parse(data);
return true;
} catch (e: any) {
console.log(`Fail to parse data type='ZodOIDGenericData' error=${e}`);
return false;
}
}
export const ZodOIDGenericDataWrite = ZodGenericTimingWrite;
export type OIDGenericDataWrite = zod.infer<typeof ZodOIDGenericDataWrite>;
export function isOIDGenericDataWrite(data: any): data is OIDGenericDataWrite {
try {
ZodOIDGenericDataWrite.parse(data);
return true;
} catch (e: any) {
console.log(`Fail to parse data type='ZodOIDGenericDataWrite' error=${e}`);
return false;
}
}

View File

@ -3,15 +3,15 @@
*/
import { z as zod } from "zod";
import {ZodUUID} from "./uuid";
import {Zodint} from "./int";
import {ZodObjectId} from "./object-id";
import {ZodInteger} from "./integer";
export const ZodRestErrorResponse = zod.object({
uuid: ZodUUID.optional(),
oid: ZodObjectId.optional(),
name: zod.string(),
message: zod.string(),
time: zod.string(),
status: Zodint,
status: ZodInteger,
statusMessage: zod.string(),
});
@ -27,17 +27,3 @@ export function isRestErrorResponse(data: any): data is RestErrorResponse {
return false;
}
}
export const ZodRestErrorResponseWrite = ZodRestErrorResponse.partial();
export type RestErrorResponseWrite = zod.infer<typeof ZodRestErrorResponseWrite>;
export function isRestErrorResponseWrite(data: any): data is RestErrorResponseWrite {
try {
ZodRestErrorResponseWrite.parse(data);
return true;
} catch (e: any) {
console.log(`Fail to parse data type='ZodRestErrorResponseWrite' error=${e}`);
return false;
}
}

View File

@ -4,8 +4,8 @@
import { z as zod } from "zod";
import {ZodLong} from "./long";
import {ZodUUID} from "./uuid";
import {ZodGenericDataSoftDelete} from "./generic-data-soft-delete";
import {ZodObjectId} from "./object-id";
import {ZodGenericDataSoftDelete, ZodGenericDataSoftDeleteWrite } from "./generic-data-soft-delete";
export const ZodSeason = ZodGenericDataSoftDelete.extend({
/**
@ -23,7 +23,7 @@ export const ZodSeason = ZodGenericDataSoftDelete.extend({
/**
* List of Id of the specific covers
*/
covers: zod.array(ZodUUID),
covers: zod.array(ZodObjectId).optional(),
});
@ -38,14 +38,25 @@ export function isSeason(data: any): data is Season {
return false;
}
}
export const ZodSeasonWrite = ZodGenericDataSoftDeleteWrite.extend({
/**
* Name of the media (this represent the title)
*/
name: zod.string().optional(),
/**
* Description of the media
*/
description: zod.string().nullable().optional(),
/**
* series parent ID
*/
parentId: ZodLong.optional(),
/**
* List of Id of the specific covers
*/
covers: zod.array(ZodObjectId).nullable().optional(),
export const ZodSeasonWrite = ZodSeason.omit({
deleted: true,
id: true,
createdAt: true,
updatedAt: true,
}).partial();
});
export type SeasonWrite = zod.infer<typeof ZodSeasonWrite>;

View File

@ -4,8 +4,8 @@
import { z as zod } from "zod";
import {ZodLong} from "./long";
import {ZodUUID} from "./uuid";
import {ZodGenericDataSoftDelete} from "./generic-data-soft-delete";
import {ZodObjectId} from "./object-id";
import {ZodGenericDataSoftDelete, ZodGenericDataSoftDeleteWrite } from "./generic-data-soft-delete";
export const ZodSeries = ZodGenericDataSoftDelete.extend({
/**
@ -23,7 +23,7 @@ export const ZodSeries = ZodGenericDataSoftDelete.extend({
/**
* List of Id of the specific covers
*/
covers: zod.array(ZodUUID),
covers: zod.array(ZodObjectId).optional(),
});
@ -38,14 +38,25 @@ export function isSeries(data: any): data is Series {
return false;
}
}
export const ZodSeriesWrite = ZodGenericDataSoftDeleteWrite.extend({
/**
* Name of the media (this represent the title)
*/
name: zod.string().optional(),
/**
* Description of the media
*/
description: zod.string().nullable().optional(),
/**
* series parent ID
*/
parentId: ZodLong.optional(),
/**
* List of Id of the specific covers
*/
covers: zod.array(ZodObjectId).nullable().optional(),
export const ZodSeriesWrite = ZodSeries.omit({
deleted: true,
id: true,
createdAt: true,
updatedAt: true,
}).partial();
});
export type SeriesWrite = zod.infer<typeof ZodSeriesWrite>;

View File

@ -3,8 +3,8 @@
*/
import { z as zod } from "zod";
import {ZodUUID} from "./uuid";
import {ZodGenericDataSoftDelete} from "./generic-data-soft-delete";
import {ZodObjectId} from "./object-id";
import {ZodGenericDataSoftDelete, ZodGenericDataSoftDeleteWrite } from "./generic-data-soft-delete";
export const ZodType = ZodGenericDataSoftDelete.extend({
/**
@ -18,7 +18,7 @@ export const ZodType = ZodGenericDataSoftDelete.extend({
/**
* List of Id of the specific covers
*/
covers: zod.array(ZodUUID),
covers: zod.array(ZodObjectId).optional(),
});
@ -33,14 +33,21 @@ export function isType(data: any): data is Type {
return false;
}
}
export const ZodTypeWrite = ZodGenericDataSoftDeleteWrite.extend({
/**
* Name of the media (this represent the title)
*/
name: zod.string().optional(),
/**
* Description of the media
*/
description: zod.string().nullable().optional(),
/**
* List of Id of the specific covers
*/
covers: zod.array(ZodObjectId).nullable().optional(),
export const ZodTypeWrite = ZodType.omit({
deleted: true,
id: true,
createdAt: true,
updatedAt: true,
}).partial();
});
export type TypeWrite = zod.infer<typeof ZodTypeWrite>;

View File

@ -3,11 +3,9 @@
*/
import { z as zod } from "zod";
import {ZodUser} from "./user";
import {ZodUser, ZodUserWrite } from "./user";
export const ZodUserKarideo = ZodUser.extend({
});
export const ZodUserKarideo = ZodUser;
export type UserKarideo = zod.infer<typeof ZodUserKarideo>;
@ -20,14 +18,7 @@ export function isUserKarideo(data: any): data is UserKarideo {
return false;
}
}
export const ZodUserKarideoWrite = ZodUserKarideo.omit({
deleted: true,
id: true,
createdAt: true,
updatedAt: true,
}).partial();
export const ZodUserKarideoWrite = ZodUserWrite;
export type UserKarideoWrite = zod.infer<typeof ZodUserKarideoWrite>;

View File

@ -6,13 +6,13 @@ import { z as zod } from "zod";
import {ZodLong} from "./long";
import {ZodFloat} from "./float";
import {ZodInteger} from "./integer";
import {ZodGenericDataSoftDelete} from "./generic-data-soft-delete";
import {ZodGenericDataSoftDelete, ZodGenericDataSoftDeleteWrite } from "./generic-data-soft-delete";
export const ZodUserMediaAdvancement = ZodGenericDataSoftDelete.extend({
/**
* Foreign Key Id of the user
*/
userId: ZodLong,
userId: ZodLong.optional(),
/**
* Id of the media
*/
@ -43,14 +43,29 @@ export function isUserMediaAdvancement(data: any): data is UserMediaAdvancement
return false;
}
}
export const ZodUserMediaAdvancementWrite = ZodGenericDataSoftDeleteWrite.extend({
/**
* Foreign Key Id of the user
*/
userId: ZodLong.nullable().optional(),
/**
* Id of the media
*/
mediaId: ZodLong.optional(),
/**
* Percent of advancement in the media
*/
percent: ZodFloat.optional(),
/**
* Number of second of advancement in the media
*/
time: ZodInteger.optional(),
/**
* Number of time this media has been read
*/
count: ZodInteger.optional(),
export const ZodUserMediaAdvancementWrite = ZodUserMediaAdvancement.omit({
deleted: true,
id: true,
createdAt: true,
updatedAt: true,
}).partial();
});
export type UserMediaAdvancementWrite = zod.infer<typeof ZodUserMediaAdvancementWrite>;

View File

@ -7,7 +7,7 @@ import {ZodLong} from "./long";
export const ZodUserOut = zod.object({
id: ZodLong,
login: zod.string().max(255).optional(),
login: zod.string().optional(),
});
@ -22,8 +22,11 @@ export function isUserOut(data: any): data is UserOut {
return false;
}
}
export const ZodUserOutWrite = zod.object({
id: ZodLong,
login: zod.string().nullable().optional(),
export const ZodUserOutWrite = ZodUserOut.partial();
});
export type UserOutWrite = zod.infer<typeof ZodUserOutWrite>;

View File

@ -5,14 +5,13 @@ import { z as zod } from "zod";
import {ZodTimestamp} from "./timestamp";
import {ZodUUID} from "./uuid";
import {ZodGenericDataSoftDelete} from "./generic-data-soft-delete";
import {ZodGenericDataSoftDelete, ZodGenericDataSoftDeleteWrite } from "./generic-data-soft-delete";
export const ZodUser = ZodGenericDataSoftDelete.extend({
login: zod.string().max(128).optional(),
login: zod.string().min(3).max(128),
lastConnection: ZodTimestamp.optional(),
admin: zod.boolean(),
blocked: zod.boolean(),
removed: zod.boolean(),
blocked: zod.boolean().optional(),
blockedReason: zod.string().max(512).optional(),
/**
* List of Id of the specific covers
*/
@ -31,14 +30,17 @@ export function isUser(data: any): data is User {
return false;
}
}
export const ZodUserWrite = ZodGenericDataSoftDeleteWrite.extend({
login: zod.string().min(3).max(128).optional(),
lastConnection: ZodTimestamp.nullable().optional(),
blocked: zod.boolean().nullable().optional(),
blockedReason: zod.string().max(512).nullable().optional(),
/**
* List of Id of the specific covers
*/
covers: zod.array(ZodUUID).nullable().optional(),
export const ZodUserWrite = ZodUser.omit({
deleted: true,
id: true,
createdAt: true,
updatedAt: true,
}).partial();
});
export type UserWrite = zod.infer<typeof ZodUserWrite>;

View File

@ -0,0 +1,41 @@
/**
* Interface of the server (auto-generated code)
*/
import { z as zod } from "zod";
import {ZodUUIDGenericData, ZodUUIDGenericDataWrite } from "./uuid-generic-data";
export const ZodUUIDGenericDataSoftDelete = ZodUUIDGenericData.extend({
/**
* Deleted state
*/
deleted: zod.boolean().readonly().optional(),
});
export type UUIDGenericDataSoftDelete = zod.infer<typeof ZodUUIDGenericDataSoftDelete>;
export function isUUIDGenericDataSoftDelete(data: any): data is UUIDGenericDataSoftDelete {
try {
ZodUUIDGenericDataSoftDelete.parse(data);
return true;
} catch (e: any) {
console.log(`Fail to parse data type='ZodUUIDGenericDataSoftDelete' error=${e}`);
return false;
}
}
export const ZodUUIDGenericDataSoftDeleteWrite = ZodUUIDGenericDataWrite.extend({
});
export type UUIDGenericDataSoftDeleteWrite = zod.infer<typeof ZodUUIDGenericDataSoftDeleteWrite>;
export function isUUIDGenericDataSoftDeleteWrite(data: any): data is UUIDGenericDataSoftDeleteWrite {
try {
ZodUUIDGenericDataSoftDeleteWrite.parse(data);
return true;
} catch (e: any) {
console.log(`Fail to parse data type='ZodUUIDGenericDataSoftDeleteWrite' error=${e}`);
return false;
}
}

View File

@ -0,0 +1,42 @@
/**
* Interface of the server (auto-generated code)
*/
import { z as zod } from "zod";
import {ZodUUID} from "./uuid";
import {ZodGenericTiming, ZodGenericTimingWrite } from "./generic-timing";
export const ZodUUIDGenericData = ZodGenericTiming.extend({
/**
* Unique UUID of the object
*/
uuid: ZodUUID.readonly(),
});
export type UUIDGenericData = zod.infer<typeof ZodUUIDGenericData>;
export function isUUIDGenericData(data: any): data is UUIDGenericData {
try {
ZodUUIDGenericData.parse(data);
return true;
} catch (e: any) {
console.log(`Fail to parse data type='ZodUUIDGenericData' error=${e}`);
return false;
}
}
export const ZodUUIDGenericDataWrite = ZodGenericTimingWrite.extend({
});
export type UUIDGenericDataWrite = zod.infer<typeof ZodUUIDGenericDataWrite>;
export function isUUIDGenericDataWrite(data: any): data is UUIDGenericDataWrite {
try {
ZodUUIDGenericDataWrite.parse(data);
return true;
} catch (e: any) {
console.log(`Fail to parse data type='ZodUUIDGenericDataWrite' error=${e}`);
return false;
}
}

View File

@ -7,11 +7,15 @@
import { RestErrorResponse, isRestErrorResponse } from "./model";
export enum HTTPRequestModel {
ARCHIVE = "ARCHIVE",
DELETE = "DELETE",
HEAD = "HEAD",
GET = "GET",
OPTION = "OPTION",
PATCH = "PATCH",
POST = "POST",
PUT = "PUT",
RESTORE = "RESTORE",
}
export enum HTTPMimeType {
ALL = "*/*",
@ -74,7 +78,7 @@ export interface RESTRequestType {
data?: any;
params?: object;
queries?: object;
callback?: RESTCallbacks;
callbacks?: RESTCallbacks;
}
function replaceAll(input, searchValue, replaceValue) {
@ -237,7 +241,7 @@ export function RESTRequest({
data,
params,
queries,
callback,
callbacks,
}: RESTRequestType): Promise<ModelResponseHttp> {
// Create the URL PATH:
let generateUrl = RESTUrl({ restModel, restConfig, data, params, queries });
@ -248,9 +252,14 @@ export function RESTRequest({
if (restModel.accept !== undefined) {
headers["Accept"] = restModel.accept;
}
if (restModel.requestType !== HTTPRequestModel.GET) {
if (restModel.requestType !== HTTPRequestModel.GET &&
restModel.requestType !== HTTPRequestModel.ARCHIVE &&
restModel.requestType !== HTTPRequestModel.RESTORE
) {
// if Get we have not a content type, the body is empty
if (restModel.contentType !== HTTPMimeType.MULTIPART) {
if (restModel.contentType !== HTTPMimeType.MULTIPART &&
restModel.contentType !== undefined
) {
// special case of multi-part ==> no content type otherwise the browser does not set the ";bundary=--****"
headers["Content-Type"] = restModel.contentType;
}
@ -268,10 +277,10 @@ export function RESTRequest({
return new Promise((resolve, reject) => {
let action: undefined | Promise<Response> = undefined;
if (
isNullOrUndefined(callback) ||
(isNullOrUndefined(callback.progressDownload) &&
isNullOrUndefined(callback.progressUpload) &&
isNullOrUndefined(callback.abortHandle))
isNullOrUndefined(callbacks) ||
(isNullOrUndefined(callbacks.progressDownload) &&
isNullOrUndefined(callbacks.progressUpload) &&
isNullOrUndefined(callbacks.abortHandle))
) {
// No information needed: call the generic fetch interface
action = fetch(generateUrl, {
@ -288,7 +297,7 @@ export function RESTRequest({
headers,
body,
},
callback
callbacks
);
}
action

Some files were not shown because too many files have changed in this diff Show More