From a503aa95a936a791f5f3b21b7ed38730f2749fe0 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sun, 22 Dec 2024 10:31:29 +0100 Subject: [PATCH] [IX] continue integration of mango --- back/src/org/kar/karusic/MorphiaService.java | 4 +- back/src/org/kar/karusic/WebLauncher.java | 47 ++++++++++--------- .../org/kar/karusic/api/AlbumResource.java | 4 +- .../org/kar/karusic/api/ArtistResource.java | 4 +- .../org/kar/karusic/api/GenderResource.java | 4 +- .../org/kar/karusic/api/PlaylistResource.java | 4 +- .../org/kar/karusic/api/TrackResource.java | 4 +- .../src/org/kar/karusic/api/UserResource.java | 4 +- .../kar/karusic/migration/Initialization.java | 8 ++-- .../karusic/migration/Migration20240226.java | 22 ++++----- env_dev/docker-compose.yaml | 1 + 11 files changed, 56 insertions(+), 50 deletions(-) diff --git a/back/src/org/kar/karusic/MorphiaService.java b/back/src/org/kar/karusic/MorphiaService.java index f6bfa78..f7a9033 100644 --- a/back/src/org/kar/karusic/MorphiaService.java +++ b/back/src/org/kar/karusic/MorphiaService.java @@ -1,13 +1,13 @@ package org.kar.karusic; -import org.kar.archidata.db.DbInterfaceMorphia; +import org.kar.archidata.db.DbIoMorphia; import org.kar.karusic.model.Album; import org.kar.karusic.model.Artist; import org.kar.karusic.model.Gender; import org.kar.karusic.model.Playlist; import org.kar.karusic.model.Track; -public class MorphiaService extends DbInterfaceMorphia { +public class MorphiaService extends DbIoMorphia { public MorphiaService() { super("mongodb://root:base_db_password@localhost:27017", "karusic", Album.class, Artist.class, Gender.class, Playlist.class, Track.class); diff --git a/back/src/org/kar/karusic/WebLauncher.java b/back/src/org/kar/karusic/WebLauncher.java index b9b32eb..8356ca6 100755 --- a/back/src/org/kar/karusic/WebLauncher.java +++ b/back/src/org/kar/karusic/WebLauncher.java @@ -17,9 +17,11 @@ import org.kar.archidata.UpdateJwtPublicKey; import org.kar.archidata.api.DataResource; import org.kar.archidata.api.ProxyResource; import org.kar.archidata.catcher.GenericCatcher; -import org.kar.archidata.dataAccess.DataAccess; +import org.kar.archidata.dataAccess.DBAccess; +import org.kar.archidata.filter.ArchiveHttpMethodFilter; import org.kar.archidata.filter.CORSFilter; import org.kar.archidata.filter.OptionFilter; +import org.kar.archidata.filter.RestoreHttpMethodFilter; import org.kar.archidata.migration.MigrationEngine; import org.kar.archidata.tools.ConfigBaseVariable; import org.kar.karusic.api.AlbumResource; @@ -45,18 +47,18 @@ public class WebLauncher { final static Logger LOGGER = LoggerFactory.getLogger(WebLauncher.class); protected UpdateJwtPublicKey keyUpdater = null; protected HttpServer server = null; - - private final DataAccess da; - + + private final DBAccess da; + public WebLauncher() { ConfigBaseVariable.bdDatabase = "karusic"; - this.da = DataAccess.createInterface(); + this.da = DBAccess.createInterface(); } - + private static URI getBaseURI() { return UriBuilder.fromUri(ConfigBaseVariable.getlocalAddress()).build(); } - + public void migrateDB() throws Exception { WebLauncher.LOGGER.info("Create migration engine"); final MigrationEngine migrationEngine = new MigrationEngine(this.da); @@ -71,12 +73,12 @@ public class WebLauncher { migrationEngine.migrateWaitAdmin(GlobalConfiguration.getDbconfig()); WebLauncher.LOGGER.info("Migrate the DB [STOP]"); } - + public static void main(final String[] args) throws Exception { WebLauncher.LOGGER.info("[START] application wake UP"); final WebLauncher launcher = new WebLauncher(); launcher.migrateDB(); - + launcher.process(); WebLauncher.LOGGER.info("end-configure the server & wait finish process:"); Thread.currentThread().join(); @@ -84,7 +86,7 @@ public class WebLauncher { launcher.stopOther(); WebLauncher.LOGGER.info("STOP the REST server:"); } - + public void plop(final String aaa) { // List available Image Readers System.out.println("Available Image Readers:"); @@ -95,7 +97,7 @@ public class WebLauncher { System.out.println("Reader CN: " + reader.getOriginatingProvider().getPluginClassName()); // ImageIO.deregisterServiceProvider(reader.getOriginatingProvider()); } - + // List available Image Writers System.out.println("\nAvailable Image Writers:"); final Iterator writers = ImageIO.getImageWritersByFormatName(aaa); @@ -105,9 +107,9 @@ public class WebLauncher { System.out.println("Writer CN: " + writer.getOriginatingProvider().getPluginClassName()); } } - + public void process() throws InterruptedException { - + ImageIO.scanForPlugins(); plop("jpeg"); plop("png"); @@ -117,7 +119,7 @@ public class WebLauncher { // Configure resources // =================================================================== final ResourceConfig rc = new ResourceConfig(); - + // add multipart models .. rc.register(MultiPartFeature.class); // global authentication system @@ -126,6 +128,9 @@ public class WebLauncher { rc.register(CORSFilter.class); // global authentication system rc.register(KarusicAuthenticationFilter.class); + // add dependency of restore and archive + rc.register(RestoreHttpMethodFilter.class); + rc.register(ArchiveHttpMethodFilter.class); // register exception catcher GenericCatcher.addAll(rc); // add default resource: @@ -137,15 +142,15 @@ public class WebLauncher { rc.register(TrackResource.class); rc.register(DataResource.class); rc.register(ProxyResource.class); - + rc.register(HealthCheck.class); rc.register(Front.class); - + // add jackson to be discover when we are ins standalone server rc.register(JacksonFeature.class); // enable this to show low level request // rc.property(LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_SERVER, Level.WARNING.getName()); - + // System.out.println("Connect on the BDD:"); // System.out.println(" getDBHost: '" + ConfigVariable.getDBHost() + "'"); // System.out.println(" getDBPort: '" + ConfigVariable.getDBPort() + "'"); @@ -163,13 +168,13 @@ public class WebLauncher { serverLink.shutdownNow(); } }, "shutdownHook")); - + // =================================================================== // start periodic update of the token ... // =================================================================== this.keyUpdater = new UpdateJwtPublicKey(); this.keyUpdater.start(); - + // =================================================================== // run JERSEY // =================================================================== @@ -181,14 +186,14 @@ public class WebLauncher { e.printStackTrace(); } } - + public void stop() { if (this.server != null) { this.server.shutdownNow(); this.server = null; } } - + public void stopOther() { this.keyUpdater.kill(); try { diff --git a/back/src/org/kar/karusic/api/AlbumResource.java b/back/src/org/kar/karusic/api/AlbumResource.java index bf69871..668248a 100644 --- a/back/src/org/kar/karusic/api/AlbumResource.java +++ b/back/src/org/kar/karusic/api/AlbumResource.java @@ -9,7 +9,7 @@ import org.glassfish.jersey.media.multipart.FormDataParam; import org.kar.archidata.annotation.AsyncType; import org.kar.archidata.annotation.FormDataOptional; import org.kar.archidata.annotation.TypeScriptProgress; -import org.kar.archidata.dataAccess.DataAccess; +import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.addOn.AddOnDataJson; import org.kar.archidata.dataAccess.options.CheckFunction; import org.kar.archidata.tools.DataTools; @@ -36,7 +36,7 @@ public class AlbumResource { private static final Logger LOGGER = LoggerFactory.getLogger(AlbumResource.class); static final AlbumChecker CHECKER = new AlbumChecker(); - private final DataAccess da = DataAccess.createInterface(); + private final DBAccess da = DBAccess.createInterface(); @GET @Path("{id}") diff --git a/back/src/org/kar/karusic/api/ArtistResource.java b/back/src/org/kar/karusic/api/ArtistResource.java index 5c3ef12..3d297a5 100644 --- a/back/src/org/kar/karusic/api/ArtistResource.java +++ b/back/src/org/kar/karusic/api/ArtistResource.java @@ -9,7 +9,7 @@ import org.glassfish.jersey.media.multipart.FormDataParam; import org.kar.archidata.annotation.AsyncType; import org.kar.archidata.annotation.FormDataOptional; import org.kar.archidata.annotation.TypeScriptProgress; -import org.kar.archidata.dataAccess.DataAccess; +import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.addOn.AddOnDataJson; import org.kar.archidata.dataAccess.options.CheckFunction; import org.kar.archidata.tools.DataTools; @@ -34,7 +34,7 @@ import jakarta.ws.rs.core.MediaType; public class ArtistResource { private static final Logger LOGGER = LoggerFactory.getLogger(ArtistResource.class); static final ArtistChecker CHECKER = new ArtistChecker(); - private final DataAccess da = DataAccess.createInterface(); + private final DBAccess da = DBAccess.createInterface(); @GET @Path("{id}") diff --git a/back/src/org/kar/karusic/api/GenderResource.java b/back/src/org/kar/karusic/api/GenderResource.java index 6120112..9937df0 100644 --- a/back/src/org/kar/karusic/api/GenderResource.java +++ b/back/src/org/kar/karusic/api/GenderResource.java @@ -9,7 +9,7 @@ import org.glassfish.jersey.media.multipart.FormDataParam; import org.kar.archidata.annotation.AsyncType; import org.kar.archidata.annotation.FormDataOptional; import org.kar.archidata.annotation.TypeScriptProgress; -import org.kar.archidata.dataAccess.DataAccess; +import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.addOn.AddOnDataJson; import org.kar.archidata.dataAccess.options.CheckFunction; import org.kar.archidata.tools.DataTools; @@ -34,7 +34,7 @@ import jakarta.ws.rs.core.MediaType; public class GenderResource { private static final Logger LOGGER = LoggerFactory.getLogger(GenderResource.class); static final GenderChecker CHECKER = new GenderChecker(); - private final DataAccess da = DataAccess.createInterface(); + private final DBAccess da = DBAccess.createInterface(); @GET @Path("{id}") diff --git a/back/src/org/kar/karusic/api/PlaylistResource.java b/back/src/org/kar/karusic/api/PlaylistResource.java index 597c220..2cdc8b9 100644 --- a/back/src/org/kar/karusic/api/PlaylistResource.java +++ b/back/src/org/kar/karusic/api/PlaylistResource.java @@ -7,7 +7,7 @@ import java.util.UUID; import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataParam; import org.kar.archidata.annotation.AsyncType; -import org.kar.archidata.dataAccess.DataAccess; +import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.addOn.AddOnDataJson; import org.kar.archidata.dataAccess.options.CheckFunction; import org.kar.archidata.tools.DataTools; @@ -32,7 +32,7 @@ import jakarta.ws.rs.core.MediaType; public class PlaylistResource { private static final Logger LOGGER = LoggerFactory.getLogger(PlaylistResource.class); static final TrackChecker CHECKER = new TrackChecker(); - private final DataAccess da = DataAccess.createInterface(); + private final DBAccess da = DBAccess.createInterface(); @GET @Path("{id}") diff --git a/back/src/org/kar/karusic/api/TrackResource.java b/back/src/org/kar/karusic/api/TrackResource.java index 79dcf80..cece377 100644 --- a/back/src/org/kar/karusic/api/TrackResource.java +++ b/back/src/org/kar/karusic/api/TrackResource.java @@ -12,7 +12,7 @@ import org.glassfish.jersey.media.multipart.FormDataParam; import org.kar.archidata.annotation.AsyncType; import org.kar.archidata.annotation.FormDataOptional; import org.kar.archidata.annotation.TypeScriptProgress; -import org.kar.archidata.dataAccess.DataAccess; +import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.addOn.AddOnDataJson; import org.kar.archidata.dataAccess.options.CheckFunction; import org.kar.archidata.model.Data; @@ -39,7 +39,7 @@ import jakarta.ws.rs.core.Response; public class TrackResource { private static final Logger LOGGER = LoggerFactory.getLogger(TrackResource.class); static final TrackChecker CHECKER = new TrackChecker(); - private final DataAccess da = DataAccess.createInterface(); + private final DBAccess da = DBAccess.createInterface(); @GET @Path("{id}") diff --git a/back/src/org/kar/karusic/api/UserResource.java b/back/src/org/kar/karusic/api/UserResource.java index 140373c..fb5665b 100755 --- a/back/src/org/kar/karusic/api/UserResource.java +++ b/back/src/org/kar/karusic/api/UserResource.java @@ -3,7 +3,7 @@ package org.kar.karusic.api; import java.util.List; import java.util.Map; -import org.kar.archidata.dataAccess.DataAccess; +import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.filter.GenericContext; import org.kar.karusic.api.UserResourceModel.PartRight; import org.kar.karusic.api.UserResourceModel.UserMe; @@ -26,7 +26,7 @@ import jakarta.ws.rs.core.SecurityContext; @Produces(MediaType.APPLICATION_JSON) public class UserResource { private static final Logger LOGGER = LoggerFactory.getLogger(UserResource.class); - private final DataAccess da = DataAccess.createInterface(); + private final DBAccess da = DBAccess.createInterface(); @JsonInclude(JsonInclude.Include.NON_NULL) public class UserOut { diff --git a/back/src/org/kar/karusic/migration/Initialization.java b/back/src/org/kar/karusic/migration/Initialization.java index 4dcfbcf..9b497ea 100644 --- a/back/src/org/kar/karusic/migration/Initialization.java +++ b/back/src/org/kar/karusic/migration/Initialization.java @@ -2,7 +2,7 @@ package org.kar.karusic.migration; import java.util.List; -import org.kar.archidata.dataAccess.DataAccess; +import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.migration.MigrationSqlStep; import org.kar.archidata.model.Data; import org.kar.archidata.model.User; @@ -35,7 +35,7 @@ public class Initialization extends MigrationSqlStep { addClass(elem); } - addAction((final DataAccess da) -> { + addAction((final DBAccess da) -> { final List data = List.of(// new Gender(1L, "Variété française"), // new Gender(2L, "Pop"), // @@ -85,7 +85,7 @@ public class Initialization extends MigrationSqlStep { """, "mysql"); } - public static void dropAll(final DataAccess da) { + public static void dropAll(final DBAccess da) { for (final Class element : CLASSES_BASE) { try { da.drop(element); @@ -96,7 +96,7 @@ public class Initialization extends MigrationSqlStep { } } - public static void cleanAll(final DataAccess da) { + public static void cleanAll(final DBAccess da) { for (final Class element : CLASSES_BASE) { try { da.cleanAll(element); diff --git a/back/src/org/kar/karusic/migration/Migration20240226.java b/back/src/org/kar/karusic/migration/Migration20240226.java index 8e189c0..fe3b11d 100644 --- a/back/src/org/kar/karusic/migration/Migration20240226.java +++ b/back/src/org/kar/karusic/migration/Migration20240226.java @@ -8,7 +8,7 @@ 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.DBAccess; import org.kar.archidata.dataAccess.addOn.model.LinkTableLongLong; import org.kar.archidata.dataAccess.options.AccessDeletedItems; import org.kar.archidata.dataAccess.options.OverrideTableName; @@ -40,12 +40,12 @@ public class Migration20240226 extends MigrationSqlStep { ALTER TABLE `data` ADD `uuid` binary(16) AFTER `id`; """); addAction(() -> { - final List datas = DataAccess.gets(UUIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data")); + final List datas = DBAccess.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")); + DBAccess.update(elem, elem.id, List.of("uuid"), new OverrideTableName("data")); } }); addAction(""" @@ -55,9 +55,9 @@ public class Migration20240226 extends MigrationSqlStep { for (final String tableName : tableToTransform) { addAction("ALTER TABLE `" + tableName + "` ADD `covers` text NULL;"); addAction(() -> { - final List datas = DataAccess.gets(UUIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data")); - final List medias = DataAccess.gets(CoverConversion.class, new AccessDeletedItems(), new OverrideTableName(tableName)); - final List links = DataAccess.gets(LinkTableLongLong.class, new OverrideTableName(tableName + "_link_cover")); + final List datas = DBAccess.gets(UUIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data")); + final List medias = DBAccess.gets(CoverConversion.class, new AccessDeletedItems(), new OverrideTableName(tableName)); + final List links = DBAccess.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 values = new ArrayList<>(); @@ -75,7 +75,7 @@ public class Migration20240226 extends MigrationSqlStep { 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)); + DBAccess.update(media, media.id, List.of("covers"), new OverrideTableName(tableName)); } } }); @@ -85,13 +85,13 @@ public class Migration20240226 extends MigrationSqlStep { ALTER TABLE `track` ADD `dataUUID` binary(16) AFTER dataId; """); addAction(() -> { - final List datas = DataAccess.gets(UUIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data")); - final List medias = DataAccess.gets(MediaConversion.class, new AccessDeletedItems(), new OverrideTableName("track")); + final List datas = DBAccess.gets(UUIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data")); + final List medias = DBAccess.gets(MediaConversion.class, new AccessDeletedItems(), new OverrideTableName("track")); 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("track")); + DBAccess.update(media, media.id, List.of("dataUUID"), new OverrideTableName("track")); break; } } @@ -112,7 +112,7 @@ public class Migration20240226 extends MigrationSqlStep { """); // Move the files... addAction(() -> { - final List datas = DataAccess.gets(UUIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data")); + final List datas = DBAccess.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); diff --git a/env_dev/docker-compose.yaml b/env_dev/docker-compose.yaml index 8fa492d..c09d871 100644 --- a/env_dev/docker-compose.yaml +++ b/env_dev/docker-compose.yaml @@ -19,6 +19,7 @@ services: kar_mongodb_service: image: mongo:latest + restart: always environment: MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: base_db_password