From e4831e1a175e8dcca58756e826077a2413f8c9b7 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 15 Apr 2024 00:58:02 +0200 Subject: [PATCH] [DEV] (back) update the progress and the migration --- .../org/kar/karideo/api/MediaResource.java | 7 ++-- .../org/kar/karideo/api/SeasonResource.java | 6 ++-- .../org/kar/karideo/api/SeriesResource.java | 2 ++ .../src/org/kar/karideo/api/TypeResource.java | 2 ++ .../karideo/migration/Migration20240226.java | 33 ++++++++++++++----- back/src/org/kar/karideo/model/Media.java | 2 +- .../karideo/model/UserMediaAdvancement.java | 12 ++++--- 7 files changed, 46 insertions(+), 18 deletions(-) diff --git a/back/src/org/kar/karideo/api/MediaResource.java b/back/src/org/kar/karideo/api/MediaResource.java index 868926f..38eaec7 100644 --- a/back/src/org/kar/karideo/api/MediaResource.java +++ b/back/src/org/kar/karideo/api/MediaResource.java @@ -9,6 +9,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.annotation.TypeScriptProgress; import org.kar.archidata.api.DataResource; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.addOn.AddOnDataJson; @@ -36,7 +37,7 @@ import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; -@Path("/video") +@Path("/media") @Produces(MediaType.APPLICATION_JSON) public class MediaResource { static final Logger LOGGER = LoggerFactory.getLogger(MediaResource.class); @@ -85,6 +86,7 @@ public class MediaResource { @Consumes({ MediaType.MULTIPART_FORM_DATA }) @Operation(description = "Create a new Media", tags = "GLOBAL") @AsyncType(Media.class) + @TypeScriptProgress public Response uploadFile(@FormDataParam("fileName") String fileName, @FormDataParam("universe") String universe, @FormDataParam("series") String series, //@FormDataParam("seriesId") String seriesId, Not used ... @FormDataParam("season") String season, @FormDataParam("episode") String episode, @FormDataParam("title") String title, @FormDataParam("typeId") String typeId, @@ -128,7 +130,7 @@ public class MediaResource { ex.printStackTrace(); throw new FailException("can not create input media (the data model has an internal error"); } - } else if (data.deleted) { + } else if (data!= null && data.deleted) { System.out.println("Data already exist but deleted"); System.out.flush(); DataTools.undelete(data.id); @@ -209,6 +211,7 @@ public class MediaResource { @Consumes({ MediaType.MULTIPART_FORM_DATA }) @AsyncType(Media.class) @Operation(description = "Upload a new season cover media", tags = "GLOBAL") + @TypeScriptProgress public Media uploadCover( // @PathParam("id") final Long id, // @FormDataParam("fileName") final String fileName, // diff --git a/back/src/org/kar/karideo/api/SeasonResource.java b/back/src/org/kar/karideo/api/SeasonResource.java index 1618caf..6ed952a 100644 --- a/back/src/org/kar/karideo/api/SeasonResource.java +++ b/back/src/org/kar/karideo/api/SeasonResource.java @@ -7,6 +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.annotation.TypeScriptProgress; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.QueryAnd; import org.kar.archidata.dataAccess.QueryCondition; @@ -82,10 +83,11 @@ public class SeasonResource { } @POST - @Path("{id}/add_cover") + @Path("{id}/cover") @RolesAllowed("ADMIN") - @Consumes({ MediaType.MULTIPART_FORM_DATA }) + @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); diff --git a/back/src/org/kar/karideo/api/SeriesResource.java b/back/src/org/kar/karideo/api/SeriesResource.java index 478efa4..cbf53c5 100644 --- a/back/src/org/kar/karideo/api/SeriesResource.java +++ b/back/src/org/kar/karideo/api/SeriesResource.java @@ -7,6 +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.annotation.TypeScriptProgress; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.QueryAnd; import org.kar.archidata.dataAccess.QueryCondition; @@ -85,6 +86,7 @@ public class SeriesResource { @RolesAllowed("ADMIN") @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); diff --git a/back/src/org/kar/karideo/api/TypeResource.java b/back/src/org/kar/karideo/api/TypeResource.java index 83761bc..2b4ee5d 100644 --- a/back/src/org/kar/karideo/api/TypeResource.java +++ b/back/src/org/kar/karideo/api/TypeResource.java @@ -7,6 +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.annotation.TypeScriptProgress; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.QueryCondition; import org.kar.archidata.dataAccess.addOn.AddOnDataJson; @@ -89,6 +90,7 @@ public class TypeResource { @RolesAllowed("ADMIN") @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); diff --git a/back/src/org/kar/karideo/migration/Migration20240226.java b/back/src/org/kar/karideo/migration/Migration20240226.java index 9c24961..ceda4f8 100644 --- a/back/src/org/kar/karideo/migration/Migration20240226.java +++ b/back/src/org/kar/karideo/migration/Migration20240226.java @@ -1,15 +1,22 @@ 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.LinkTable; 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; @@ -30,15 +37,13 @@ public class Migration20240226 extends MigrationSqlStep { @Override public void generateStep() throws Exception { - /* addAction(""" ALTER TABLE `data` ADD `uuid` binary(16) AFTER `id`; """); addAction(() -> { final List datas = DataAccess.gets(UUIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data")); for (final UUIDConversion elem: datas) { - elem.uuid = UUID.randomUUID(); - //elem.uuid = new UUID(elem.id * (long)Math.pow(2, 32), 0); + elem.uuid = UuidUtils.nextUUID(); } for (final UUIDConversion elem: datas) { DataAccess.update(elem, elem.id, List.of("uuid"), new OverrideTableName("data")); @@ -93,13 +98,12 @@ public class Migration20240226 extends MigrationSqlStep { } } }); - addAction(""" - ALTER TABLE `media` CHANGE `dataUUID` `dataUUID` binary(16) NOT NULL; - """); addAction(""" ALTER TABLE `media` DROP `dataId`; """); - */ + addAction(""" + ALTER TABLE `media` CHANGE `dataUUID` `dataId` binary(16) NOT NULL; + """); // Move the files... addAction(() -> { final List datas = DataAccess.gets(UUIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data")); @@ -108,9 +112,22 @@ public class Migration20240226 extends MigrationSqlStep { final String destination = DataResource.getFileData(data.uuid); LOGGER.info("move file = {}", origin); LOGGER.info(" ==> {}", destination); - Files.move(Paths.get(origin), Paths.get(destination), StandardCopyOption.ATOMIC_MOVE); + try { + Files.move(Paths.get(origin), Paths.get(destination), StandardCopyOption.ATOMIC_MOVE); + } catch (final NoSuchFileException ex) { + LOGGER.error("MOVE_ERROR : {} -> {}", origin, destination); + } } }); + addAction(""" + ALTER TABLE `data` DROP `id`; + """); + addAction(""" + ALTER TABLE `data` CHANGE `uuid` `id` binary(16) DEFAULT (UUID_TO_BIN(UUID(), TRUE)); + """); + addAction(""" + ALTER TABLE `data` ADD PRIMARY KEY `id` (`id`); + """); } } diff --git a/back/src/org/kar/karideo/model/Media.java b/back/src/org/kar/karideo/model/Media.java index 2a35fc5..b8aeada 100644 --- a/back/src/org/kar/karideo/model/Media.java +++ b/back/src/org/kar/karideo/model/Media.java @@ -35,7 +35,7 @@ public class Media extends GenericDataSoftDelete { // Series reference of the media @ManyToOne(fetch = FetchType.LAZY, targetEntity = Series.class) public Long seriesId; - // Saison reference of the media + // Season reference of the media @ManyToOne(fetch = FetchType.LAZY, targetEntity = Season.class) public Long seasonId; // Episode Id diff --git a/back/src/org/kar/karideo/model/UserMediaAdvancement.java b/back/src/org/kar/karideo/model/UserMediaAdvancement.java index 3e72614..915e36f 100644 --- a/back/src/org/kar/karideo/model/UserMediaAdvancement.java +++ b/back/src/org/kar/karideo/model/UserMediaAdvancement.java @@ -1,6 +1,7 @@ package org.kar.karideo.model; import org.kar.archidata.annotation.DataIfNotExists; +import org.kar.archidata.annotation.DataNotRead; import org.kar.archidata.model.GenericDataSoftDelete; import com.fasterxml.jackson.annotation.JsonInclude; @@ -15,21 +16,22 @@ import jakarta.persistence.Table; @DataIfNotExists @JsonInclude(JsonInclude.Include.NON_NULL) public class UserMediaAdvancement extends GenericDataSoftDelete { + @DataNotRead @Column(nullable = false) @Schema(description = "Foreign Key Id of the user") @ManyToOne(fetch = FetchType.LAZY, targetEntity = UserKarideo.class) - public long userId; + public Long userId; @Column(nullable = false) @Schema(description = "Id of the media") @ManyToOne(fetch = FetchType.LAZY, targetEntity = Media.class) - public long mediaId; + public Long mediaId; @Column(nullable = false) @Schema(description = "Percent of advancement in the media") - public float percent; + public Float percent; @Column(nullable = false) @Schema(description = "Number of second of advancement in the media") - public int time; + public Integer time; @Column(nullable = false) @Schema(description = "Number of time this media has been read") - public int count; + public Integer count; }