[DEV] (back) update the progress and the migration

This commit is contained in:
Edouard DUPIN 2024-04-15 00:58:02 +02:00
parent e0b81d2122
commit e4831e1a17
7 changed files with 46 additions and 18 deletions

View File

@ -9,6 +9,7 @@ import java.util.UUID;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam; import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.annotation.AsyncType; import org.kar.archidata.annotation.AsyncType;
import org.kar.archidata.annotation.TypeScriptProgress;
import org.kar.archidata.api.DataResource; import org.kar.archidata.api.DataResource;
import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataAccess;
import org.kar.archidata.dataAccess.addOn.AddOnDataJson; 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.MediaType;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
@Path("/video") @Path("/media")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public class MediaResource { public class MediaResource {
static final Logger LOGGER = LoggerFactory.getLogger(MediaResource.class); static final Logger LOGGER = LoggerFactory.getLogger(MediaResource.class);
@ -85,6 +86,7 @@ public class MediaResource {
@Consumes({ MediaType.MULTIPART_FORM_DATA }) @Consumes({ MediaType.MULTIPART_FORM_DATA })
@Operation(description = "Create a new Media", tags = "GLOBAL") @Operation(description = "Create a new Media", tags = "GLOBAL")
@AsyncType(Media.class) @AsyncType(Media.class)
@TypeScriptProgress
public Response uploadFile(@FormDataParam("fileName") String fileName, @FormDataParam("universe") String universe, @FormDataParam("series") String series, public Response uploadFile(@FormDataParam("fileName") String fileName, @FormDataParam("universe") String universe, @FormDataParam("series") String series,
//@FormDataParam("seriesId") String seriesId, Not used ... //@FormDataParam("seriesId") String seriesId, Not used ...
@FormDataParam("season") String season, @FormDataParam("episode") String episode, @FormDataParam("title") String title, @FormDataParam("typeId") String typeId, @FormDataParam("season") String season, @FormDataParam("episode") String episode, @FormDataParam("title") String title, @FormDataParam("typeId") String typeId,
@ -128,7 +130,7 @@ public class MediaResource {
ex.printStackTrace(); ex.printStackTrace();
throw new FailException("can not create input media (the data model has an internal error"); throw new FailException("can not create input media (the data model has an internal error");
} }
} else if (data.deleted) { } else if (data!= null && data.deleted) {
System.out.println("Data already exist but deleted"); System.out.println("Data already exist but deleted");
System.out.flush(); System.out.flush();
DataTools.undelete(data.id); DataTools.undelete(data.id);
@ -209,6 +211,7 @@ public class MediaResource {
@Consumes({ MediaType.MULTIPART_FORM_DATA }) @Consumes({ MediaType.MULTIPART_FORM_DATA })
@AsyncType(Media.class) @AsyncType(Media.class)
@Operation(description = "Upload a new season cover media", tags = "GLOBAL") @Operation(description = "Upload a new season cover media", tags = "GLOBAL")
@TypeScriptProgress
public Media uploadCover( // public Media uploadCover( //
@PathParam("id") final Long id, // @PathParam("id") final Long id, //
@FormDataParam("fileName") final String fileName, // @FormDataParam("fileName") final String fileName, //

View File

@ -7,6 +7,7 @@ import java.util.UUID;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam; import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.annotation.AsyncType; import org.kar.archidata.annotation.AsyncType;
import org.kar.archidata.annotation.TypeScriptProgress;
import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataAccess;
import org.kar.archidata.dataAccess.QueryAnd; import org.kar.archidata.dataAccess.QueryAnd;
import org.kar.archidata.dataAccess.QueryCondition; import org.kar.archidata.dataAccess.QueryCondition;
@ -82,10 +83,11 @@ public class SeasonResource {
} }
@POST @POST
@Path("{id}/add_cover") @Path("{id}/cover")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA }) @Consumes(MediaType.MULTIPART_FORM_DATA)
@Operation(description = "Upload a new season cover season", tags = "GLOBAL") @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, 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 { @FormDataParam("file") final FormDataContentDisposition fileMetaData) throws Exception {
DataTools.uploadCover(Season.class, id, fileName, fileInputStream, fileMetaData); DataTools.uploadCover(Season.class, id, fileName, fileInputStream, fileMetaData);

View File

@ -7,6 +7,7 @@ import java.util.UUID;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam; import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.annotation.AsyncType; import org.kar.archidata.annotation.AsyncType;
import org.kar.archidata.annotation.TypeScriptProgress;
import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataAccess;
import org.kar.archidata.dataAccess.QueryAnd; import org.kar.archidata.dataAccess.QueryAnd;
import org.kar.archidata.dataAccess.QueryCondition; import org.kar.archidata.dataAccess.QueryCondition;
@ -85,6 +86,7 @@ public class SeriesResource {
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA }) @Consumes({ MediaType.MULTIPART_FORM_DATA })
@Operation(description = "Upload a new season cover Series", tags = "GLOBAL") @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, 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 { @FormDataParam("file") final FormDataContentDisposition fileMetaData) throws Exception {
DataTools.uploadCover(Series.class, id, fileName, fileInputStream, fileMetaData); DataTools.uploadCover(Series.class, id, fileName, fileInputStream, fileMetaData);

View File

@ -7,6 +7,7 @@ import java.util.UUID;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam; import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.annotation.AsyncType; import org.kar.archidata.annotation.AsyncType;
import org.kar.archidata.annotation.TypeScriptProgress;
import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataAccess;
import org.kar.archidata.dataAccess.QueryCondition; import org.kar.archidata.dataAccess.QueryCondition;
import org.kar.archidata.dataAccess.addOn.AddOnDataJson; import org.kar.archidata.dataAccess.addOn.AddOnDataJson;
@ -89,6 +90,7 @@ public class TypeResource {
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA }) @Consumes({ MediaType.MULTIPART_FORM_DATA })
@Operation(description = "Upload a new season cover Type", tags = "GLOBAL") @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, 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 { @FormDataParam("file") final FormDataContentDisposition fileMetaData) throws Exception {
DataTools.uploadCover(Type.class, id, fileName, fileInputStream, fileMetaData); DataTools.uploadCover(Type.class, id, fileName, fileInputStream, fileMetaData);

View File

@ -1,15 +1,22 @@
package org.kar.karideo.migration; package org.kar.karideo.migration;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
import org.kar.archidata.api.DataResource; import org.kar.archidata.api.DataResource;
import org.kar.archidata.dataAccess.DataAccess; 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.AccessDeletedItems;
import org.kar.archidata.dataAccess.options.OverrideTableName; import org.kar.archidata.dataAccess.options.OverrideTableName;
import org.kar.archidata.migration.MigrationSqlStep; 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.kar.karideo.migration.model.UUIDConversion;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -30,15 +37,13 @@ public class Migration20240226 extends MigrationSqlStep {
@Override @Override
public void generateStep() throws Exception { public void generateStep() throws Exception {
/*
addAction(""" addAction("""
ALTER TABLE `data` ADD `uuid` binary(16) AFTER `id`; ALTER TABLE `data` ADD `uuid` binary(16) AFTER `id`;
"""); """);
addAction(() -> { addAction(() -> {
final List<UUIDConversion> datas = DataAccess.gets(UUIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data")); final List<UUIDConversion> datas = DataAccess.gets(UUIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data"));
for (final UUIDConversion elem: datas) { for (final UUIDConversion elem: datas) {
elem.uuid = UUID.randomUUID(); elem.uuid = UuidUtils.nextUUID();
//elem.uuid = new UUID(elem.id * (long)Math.pow(2, 32), 0);
} }
for (final UUIDConversion elem: datas) { for (final UUIDConversion elem: datas) {
DataAccess.update(elem, elem.id, List.of("uuid"), new OverrideTableName("data")); 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(""" addAction("""
ALTER TABLE `media` DROP `dataId`; ALTER TABLE `media` DROP `dataId`;
"""); """);
*/ addAction("""
ALTER TABLE `media` CHANGE `dataUUID` `dataId` binary(16) NOT NULL;
""");
// Move the files... // Move the files...
addAction(() -> { addAction(() -> {
final List<UUIDConversion> datas = DataAccess.gets(UUIDConversion.class, new AccessDeletedItems(), new OverrideTableName("data")); final List<UUIDConversion> 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); final String destination = DataResource.getFileData(data.uuid);
LOGGER.info("move file = {}", origin); LOGGER.info("move file = {}", origin);
LOGGER.info(" ==> {}", destination); LOGGER.info(" ==> {}", destination);
try {
Files.move(Paths.get(origin), Paths.get(destination), StandardCopyOption.ATOMIC_MOVE); 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`);
""");
} }
} }

View File

@ -35,7 +35,7 @@ public class Media extends GenericDataSoftDelete {
// Series reference of the media // Series reference of the media
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Series.class) @ManyToOne(fetch = FetchType.LAZY, targetEntity = Series.class)
public Long seriesId; public Long seriesId;
// Saison reference of the media // Season reference of the media
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Season.class) @ManyToOne(fetch = FetchType.LAZY, targetEntity = Season.class)
public Long seasonId; public Long seasonId;
// Episode Id // Episode Id

View File

@ -1,6 +1,7 @@
package org.kar.karideo.model; package org.kar.karideo.model;
import org.kar.archidata.annotation.DataIfNotExists; import org.kar.archidata.annotation.DataIfNotExists;
import org.kar.archidata.annotation.DataNotRead;
import org.kar.archidata.model.GenericDataSoftDelete; import org.kar.archidata.model.GenericDataSoftDelete;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
@ -15,21 +16,22 @@ import jakarta.persistence.Table;
@DataIfNotExists @DataIfNotExists
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class UserMediaAdvancement extends GenericDataSoftDelete { public class UserMediaAdvancement extends GenericDataSoftDelete {
@DataNotRead
@Column(nullable = false) @Column(nullable = false)
@Schema(description = "Foreign Key Id of the user") @Schema(description = "Foreign Key Id of the user")
@ManyToOne(fetch = FetchType.LAZY, targetEntity = UserKarideo.class) @ManyToOne(fetch = FetchType.LAZY, targetEntity = UserKarideo.class)
public long userId; public Long userId;
@Column(nullable = false) @Column(nullable = false)
@Schema(description = "Id of the media") @Schema(description = "Id of the media")
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Media.class) @ManyToOne(fetch = FetchType.LAZY, targetEntity = Media.class)
public long mediaId; public Long mediaId;
@Column(nullable = false) @Column(nullable = false)
@Schema(description = "Percent of advancement in the media") @Schema(description = "Percent of advancement in the media")
public float percent; public Float percent;
@Column(nullable = false) @Column(nullable = false)
@Schema(description = "Number of second of advancement in the media") @Schema(description = "Number of second of advancement in the media")
public int time; public Integer time;
@Column(nullable = false) @Column(nullable = false)
@Schema(description = "Number of time this media has been read") @Schema(description = "Number of time this media has been read")
public int count; public Integer count;
} }