[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.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, //

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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<UUIDConversion> 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<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);
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`);
""");
}
}

View File

@ -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

View File

@ -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;
}