[DEV] continue integration to support new model of data with uuid

This commit is contained in:
Edouard DUPIN 2024-03-04 00:13:14 +01:00
parent 5e8b244ebd
commit 154c825499
19 changed files with 17384 additions and 17169 deletions

View File

@ -1,16 +1,25 @@
package org.kar.karideo;
import java.io.FileWriter;
import org.kar.archidata.dataAccess.DataFactoryZod;
import org.kar.archidata.tools.ConfigBaseVariable;
import org.kar.karideo.migration.Initialization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class WebLauncherLocal extends WebLauncher {
private final static Logger LOGGER = LoggerFactory.getLogger(WebLauncherLocal.class);
private WebLauncherLocal() {}
public static void main(final String[] args) throws InterruptedException {
public static void main(final String[] args) throws Exception {
final String model = DataFactoryZod.createTables(Initialization.CLASSES_BASE);
LOGGER.info("Zod Model = {}", model);
final FileWriter writer = new FileWriter("../front/src/app/model/server-karideo-api.ts");
writer.write(model);
writer.close();
final WebLauncherLocal launcher = new WebLauncherLocal();
launcher.process();
LOGGER.info("end-configure the server & wait finish process:");

View File

@ -2,7 +2,6 @@ package org.kar.karideo.api;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
@ -99,7 +98,7 @@ public class SeasonResource {
return Response.ok(DataAccess.get(Season.class, id)).build();
}
public static Season getOrCreate(final String name, final UUID seriesId) {
public static Season getOrCreate(final String name, final Long seriesId) {
try {
Season out = DataAccess.getWhere(Season.class, new Condition(new QueryAnd(new QueryCondition("name", "=", name), new QueryCondition("parentId", "=", seriesId))));
if (out == null) {

View File

@ -2,7 +2,6 @@ package org.kar.karideo.api;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
@ -99,7 +98,7 @@ public class SeriesResource {
return Response.ok(DataAccess.get(Series.class, id)).build();
}
public static Series getOrCreate(final String name, final UUID typeId) {
public static Series getOrCreate(final String name, final Long typeId) {
try {
Series out = DataAccess.getWhere(Series.class, new Condition(new QueryAnd(new QueryCondition("name", "=", name), new QueryCondition("parentId", "=", typeId))));
if (out == null) {

View File

@ -131,7 +131,7 @@ public class VideoResource {
System.out.println("Data already exist ... all good");
System.out.flush();
}
// Fist step: retive all the Id of each parents:...
// Fist step: retieve all the Id of each parents:...
System.out.println("Find typeNode");
// check if id of type exist:
final Type typeNode = TypeResource.getId(Long.parseLong(typeId));

View File

@ -1,5 +1,7 @@
package org.kar.karideo.migration;
import java.util.List;
import org.kar.archidata.migration.MigrationSqlStep;
import org.kar.archidata.model.Data;
import org.kar.archidata.model.User;
@ -13,6 +15,7 @@ public class Initialization extends MigrationSqlStep {
public static final int KARSO_INITIALISATION_ID = 1;
public static final List<Class<?>> CLASSES_BASE = List.of(Data.class, Media.class, Type.class, Series.class, Season.class, User.class, UserMediaAdvancement.class);
@Override
public String getName() {
return "Initialization";

View File

@ -1,15 +1,18 @@
package org.kar.karideo.migration;
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.options.AccessDeletedItems;
import org.kar.archidata.dataAccess.options.OverrideTableName;
import org.kar.archidata.migration.MigrationSqlStep;
import org.kar.karideo.migration.model.UUIDConversion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Migration20240226 extends MigrationSqlStep {
private static final Logger LOGGER = LoggerFactory.getLogger(Migration20240226.class);
public static final int KARSO_INITIALISATION_ID = 1;
@ -24,21 +27,85 @@ public class Migration20240226 extends MigrationSqlStep {
@Override
public void generateStep() throws Exception {
// update migration update (last one)
/*
addAction("""
ALTER TABLE `media` ADD `uuid` binary(16) AFTER `id`;
ALTER TABLE `data` ADD `uuid` binary(16) AFTER `id`;
""");
addAction(() -> {
final List<UUIDConversion> medias = DataAccess.gets(UUIDConversion.class, new AccessDeletedItems(), new OverrideTableName("media"));
for (final UUIDConversion elem: medias) {
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);
}
for (final UUIDConversion elem: medias) {
DataAccess.update(elem, elem.id, List.of("uuid"), new OverrideTableName("media"));
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<LinkTable> links = DataAccess.gets(LinkTable.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 LinkTable 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` CHANGE `dataUUID` `dataUUID` binary(16) NOT NULL;
""");
addAction("""
ALTER TABLE `media` DROP `dataId`;
""");
*/
// 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.getFileData(data.id);
final String destination = DataResource.getFileData(data.uuid);
}
});
}
}

View File

@ -0,0 +1,15 @@
package org.kar.karideo.migration.model;
import java.util.List;
import java.util.UUID;
import org.kar.archidata.annotation.DataJson;
import jakarta.persistence.Id;
public class CoverConversion {
@Id
public Long id = null;
@DataJson
public List<UUID> covers = null;
}

View File

@ -0,0 +1,12 @@
package org.kar.karideo.migration.model;
import java.util.UUID;
import jakarta.persistence.Id;
public class MediaConversion {
@Id
public Long id = null;
public Long dataId = null;
public UUID dataUUID = null;
}

View File

@ -5,7 +5,7 @@ import java.util.UUID;
import org.kar.archidata.annotation.DataJson;
import org.kar.archidata.model.Data;
import org.kar.archidata.model.UUIDGenericDataSoftDelete;
import org.kar.archidata.model.GenericDataSoftDelete;
import com.fasterxml.jackson.annotation.JsonInclude;
@ -20,7 +20,7 @@ import jakarta.persistence.Table;
@JsonInclude(JsonInclude.Include.NON_NULL)
//@SQLDelete(sql = "UPDATE table_product SET deleted = true WHERE id=?")
//@Where(clause = "deleted=false")
public class Media extends UUIDGenericDataSoftDelete {
public class Media extends GenericDataSoftDelete {
// Name of the media (this represent the title)
@Column(nullable = false, length = 0)
public String name;
@ -33,14 +33,14 @@ public class Media extends UUIDGenericDataSoftDelete {
public UUID dataId;
// Type of the media")
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Type.class)
public UUID typeId;
public Long typeId;
// Series reference of the media
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Series.class)
public UUID seriesId;
public Long seriesId;
// Saison reference of the media
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Season.class)
public UUID seasonId;
// Episide Id
public Long seasonId;
// Episode Id
public Integer episode;
// ")
public Integer date;

View File

@ -5,7 +5,7 @@ import java.util.UUID;
import org.kar.archidata.annotation.DataIfNotExists;
import org.kar.archidata.annotation.DataJson;
import org.kar.archidata.model.UUIDGenericDataSoftDelete;
import org.kar.archidata.model.GenericDataSoftDelete;
import com.fasterxml.jackson.annotation.JsonInclude;
@ -18,7 +18,7 @@ import jakarta.persistence.Table;
@Table(name = "season")
@DataIfNotExists
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Season extends UUIDGenericDataSoftDelete {
public class Season extends GenericDataSoftDelete {
@Column(nullable = false, length = 0)
@Schema(description = "Name of the media (this represent the title)")
public String name;
@ -28,8 +28,8 @@ public class Season extends UUIDGenericDataSoftDelete {
@Column(nullable = false)
@Schema(description = "series parent ID")
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Series.class)
public UUID parentId;
@Schema(description = "List of Id of the sopecific covers")
public Long parentId;
@Schema(description = "List of Id of the specific covers")
@DataJson()
public List<UUID> covers = null;
}

View File

@ -5,7 +5,7 @@ import java.util.UUID;
import org.kar.archidata.annotation.DataIfNotExists;
import org.kar.archidata.annotation.DataJson;
import org.kar.archidata.model.UUIDGenericDataSoftDelete;
import org.kar.archidata.model.GenericDataSoftDelete;
import com.fasterxml.jackson.annotation.JsonInclude;
@ -18,7 +18,7 @@ import jakarta.persistence.Table;
@Table(name = "series")
@DataIfNotExists
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Series extends UUIDGenericDataSoftDelete {
public class Series extends GenericDataSoftDelete {
@Column(nullable = false, length = 0)
@Schema(description = "Name of the media (this represent the title)")
public String name;
@ -28,8 +28,8 @@ public class Series extends UUIDGenericDataSoftDelete {
@Column(nullable = false)
@Schema(description = "series parent ID")
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Type.class)
public UUID parentId;
@Schema(description = "List of Id of the sopecific covers")
public Long parentId;
@Schema(description = "List of Id of the specific covers")
@DataJson()
public List<UUID> covers = null;
}

View File

@ -5,7 +5,7 @@ import java.util.UUID;
import org.kar.archidata.annotation.DataIfNotExists;
import org.kar.archidata.annotation.DataJson;
import org.kar.archidata.model.UUIDGenericDataSoftDelete;
import org.kar.archidata.model.GenericDataSoftDelete;
import com.fasterxml.jackson.annotation.JsonInclude;
@ -16,14 +16,14 @@ import jakarta.persistence.Table;
@Table(name = "type")
@DataIfNotExists
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Type extends UUIDGenericDataSoftDelete {
public class Type extends GenericDataSoftDelete {
@Column(nullable = false, length = 0)
@Schema(description = "Name of the media (this represent the title)")
public String name;
@Column(length = 0)
@Schema(description = "Description of the media")
public String description;
@Schema(description = "List of Id of the sopecific covers")
@Schema(description = "List of Id of the specific covers")
@DataJson()
public List<UUID> covers = null;
}

View File

@ -24,10 +24,10 @@ public class UserMediaAdvancement extends GenericDataSoftDelete {
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Media.class)
public long mediaId;
@Column(nullable = false)
@Schema(description = "Percent of admencement in the media")
@Schema(description = "Percent of advancement in the media")
public float percent;
@Column(nullable = false)
@Schema(description = "Number of second of admencement in the media")
@Schema(description = "Number of second of advancement in the media")
public int time;
@Column(nullable = false)
@Schema(description = "Number of time this media has been read")

34231
front/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,16 @@
{
"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",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"style": "prettier --write .",
"e2e": "ng e2e",
"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",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"style": "prettier --write .",
"e2e": "ng e2e",
"update_packages": "ncu --upgrade",
"install_dependency": "npm install"
},
@ -27,7 +27,8 @@
"@angular/platform-browser-dynamic": "^17.2.0",
"@angular/router": "^17.2.0",
"rxjs": "^7.8.1",
"zone.js": "^0.14.4"
"zone.js": "^0.14.4",
"zod": "3.22.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^17.2.0",
@ -41,4 +42,4 @@
"@angular/language-service": "^17.2.0",
"npm-check-updates": "^16.14.15"
}
}
}

View File

@ -2,7 +2,7 @@ import { isNumberFinite, isString, isOptionalOf } from "common/utils";
import { isNodeData, NodeData } from "common/model/node";
export interface Media extends NodeData {
export interface Media extends NodeData {
dataId?: number;
typeId?: number;
seriesId?: number;
@ -11,7 +11,7 @@ import { isNodeData, NodeData } from "common/model/node";
date?: number;
time?: number;
ageLimit?: number;
};
};

View File

@ -0,0 +1,108 @@
/**
* Interface of the server (auto-generated code)
*/
import { z as zod } from "zod";
export const GenericTiming = zod.object({
// Create time of the object
createdAt: zod.date().readonly().optional(),
// When update the object
updatedAt: zod.date().readonly().optional()
});
export const UUIDGenericData = GenericTiming.extend({
// Unique UUID of the object
id: zod.string().uuid().readonly().optional()
});
export const UUIDGenericDataSoftDelete = UUIDGenericData.extend({
// Deleted state
deleted: zod.boolean().readonly().optional()
});
export const Data = UUIDGenericDataSoftDelete.extend({
// Sha512 of the data
sha512: zod.string().max(128).optional(),
// Mime -type of the media
mimeType: zod.string().max(128).optional(),
// Size in Byte of the data
size: zod.bigint().optional()
});
export const GenericData = GenericTiming.extend({
// Unique Id of the object
id: zod.bigint().readonly().optional()
});
export const GenericDataSoftDelete = GenericData.extend({
// Deleted state
deleted: zod.boolean().readonly().optional()
});
export const Media = GenericDataSoftDelete.extend({
name: zod.string().optional(),
description: zod.string().optional(),
dataId: zod.string().uuid().optional(),
typeId: zod.bigint().optional(),
seriesId: zod.bigint().optional(),
seasonId: zod.bigint().optional(),
episode: zod.number().safe().optional(),
date: zod.number().safe().optional(),
time: zod.number().safe().optional(),
ageLimit: zod.number().safe().optional(),
covers: zod.array(zod.string().uuid()).optional()
});
export const Type = GenericDataSoftDelete.extend({
// Name of the media (this represent the title)
name: zod.string().optional(),
// Description of the media
description: zod.string().optional(),
// List of Id of the specific covers
covers: zod.array(zod.string().uuid()).optional()
});
export const Series = GenericDataSoftDelete.extend({
// Name of the media (this represent the title)
name: zod.string().optional(),
// Description of the media
description: zod.string().optional(),
// series parent ID
parentId: zod.bigint().optional(),
// List of Id of the specific covers
covers: zod.array(zod.string().uuid()).optional()
});
export const Season = GenericDataSoftDelete.extend({
// Name of the media (this represent the title)
name: zod.string().optional(),
// Description of the media
description: zod.string().optional(),
// series parent ID
parentId: zod.bigint().optional(),
// List of Id of the specific covers
covers: zod.array(zod.string().uuid()).optional()
});
export const User = GenericDataSoftDelete.extend({
login: zod.string().max(128).optional(),
lastConnection: zod.date().optional(),
admin: zod.boolean(),
blocked: zod.boolean(),
removed: zod.boolean(),
covers: zod.array(zod.bigint()).optional()
});
export const UserMediaAdvancement = GenericDataSoftDelete.extend({
// Foreign Key Id of the user
userId: zod.bigint(),
// Id of the media
mediaId: zod.bigint(),
// Percent of advancement in the media
percent: zod.number(),
// Number of second of advancement in the media
time: zod.number().safe(),
// Number of time this media has been read
count: zod.number().safe()
});

View File

@ -3,7 +3,6 @@ import { isNumberFinite, isNumber } from "common/utils";
export interface UserMediaAdvancement {
id: number;
// Id of the media
mediaId?: number;
// Percent of advancement in the media

View File

@ -324,12 +324,6 @@ export class VideoScene implements OnInit {
this.startHideTimer();
this.playVideo = false;
this.displayVolumeMenu = false;
/*
if(this.isFullScreen === true) {
this.isFullScreen = false;
}
*/
}
changeStateToPlay() {