From e05fe70f80ec888d81c8ee5939aaee41d6ef4008 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 19 Mar 2024 23:17:05 +0100 Subject: [PATCH] [DEV] ready for deply new model of data UUID --- back/pom.xml | 2 +- .../src/org/kar/karusic/WebLauncherLocal.java | 6 +-- .../karusic/migration/Migration20240226.java | 43 +++++++++++------ front/src/app/back-api/track-resource.ts | 46 +++++++++---------- .../element-season/element-season.ts | 2 +- front/src/app/scene/artist/artists.ts | 2 - front/src/app/service/GenericDataService.ts | 4 +- front/src/app/service/data.ts | 6 +-- 8 files changed, 62 insertions(+), 49 deletions(-) diff --git a/back/pom.xml b/back/pom.xml index ff0b08d..3deeb76 100644 --- a/back/pom.xml +++ b/back/pom.xml @@ -20,7 +20,7 @@ kangaroo-and-rabbit archidata - 0.7.0 + 0.7.1 org.slf4j diff --git a/back/src/org/kar/karusic/WebLauncherLocal.java b/back/src/org/kar/karusic/WebLauncherLocal.java index 1384a7d..546bec6 100755 --- a/back/src/org/kar/karusic/WebLauncherLocal.java +++ b/back/src/org/kar/karusic/WebLauncherLocal.java @@ -18,7 +18,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class WebLauncherLocal extends WebLauncher { - final Logger logger = LoggerFactory.getLogger(WebLauncherLocal.class); + private static final Logger LOGGER = LoggerFactory.getLogger(WebLauncherLocal.class); private WebLauncherLocal() {} @@ -36,9 +36,9 @@ public class WebLauncherLocal extends WebLauncher { Initialization.CLASSES_BASE, "../front/src/app/back-api/"); final WebLauncherLocal launcher = new WebLauncherLocal(); launcher.process(); - launcher.logger.info("end-configure the server & wait finish process:"); + launcher.LOGGER.info("end-configure the server & wait finish process:"); Thread.currentThread().join(); - launcher.logger.info("STOP the REST server:"); + launcher.LOGGER.info("STOP the REST server:"); } @Override diff --git a/back/src/org/kar/karusic/migration/Migration20240226.java b/back/src/org/kar/karusic/migration/Migration20240226.java index db4c50b..73d52ee 100644 --- a/back/src/org/kar/karusic/migration/Migration20240226.java +++ b/back/src/org/kar/karusic/migration/Migration20240226.java @@ -1,6 +1,22 @@ package org.kar.karusic.migration; +import java.nio.file.Files; +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.karusic.migration.model.CoverConversion; +import org.kar.karusic.migration.model.MediaConversion; +import org.kar.karusic.migration.model.UUIDConversion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,15 +36,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,10 +107,20 @@ public class Migration20240226 extends MigrationSqlStep { addAction(""" ALTER TABLE `track` DROP `dataId`; """); - */ addAction(""" ALTER TABLE `track` CHANGE `dataUUID` `dataId` binary(16) NOT NULL; """); + // Move the files... + addAction(() -> { + final List datas = DataAccess.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); + LOGGER.info("move file = {}", origin); + LOGGER.info(" ==> {}", destination); + Files.move(Paths.get(origin), Paths.get(destination), StandardCopyOption.ATOMIC_MOVE); + } + }); addAction(""" ALTER TABLE `data` DROP `id`; """); @@ -106,17 +130,6 @@ public class Migration20240226 extends MigrationSqlStep { addAction(""" ALTER TABLE `data` ADD PRIMARY KEY `id` (`id`); """); - /* - // Move the files... - addAction(() -> { - final List 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); - } - }); - */ } } diff --git a/front/src/app/back-api/track-resource.ts b/front/src/app/back-api/track-resource.ts index bf7dd40..07f08ff 100644 --- a/front/src/app/back-api/track-resource.ts +++ b/front/src/app/back-api/track-resource.ts @@ -72,29 +72,6 @@ export namespace TrackResource { data, }, isTrack); }; - export function uploadTrack({ restConfig, data, }: { - restConfig: RESTConfig, - data: { - fileName: string, - file: File, - gender: string, - artist: string, - album: string, - trackId: Long, - title: string, - }, - }): Promise { - return RESTRequestJson({ - restModel: { - endPoint: "/track/upload/", - requestType: HTTPRequestModel.POST, - contentType: HTTPMimeType.MULTIPART, - accept: HTTPMimeType.JSON, - }, - restConfig, - data, - }, isTrack); - }; export function gets({ restConfig, }: { restConfig: RESTConfig, }): Promise { @@ -183,4 +160,27 @@ export namespace TrackResource { params, }, isTrack); }; + export function uploadTrack({ restConfig, data, }: { + restConfig: RESTConfig, + data: { + fileName: string, + file: File, + gender: string, + artist: string, + album: string, + trackId: Long, + title: string, + }, + }): Promise { + return RESTRequestJson({ + restModel: { + endPoint: "/track/upload/", + requestType: HTTPRequestModel.POST, + contentType: HTTPMimeType.MULTIPART, + accept: HTTPMimeType.JSON, + }, + restConfig, + data, + }, isTrack); + }; } diff --git a/front/src/app/component/element-season/element-season.ts b/front/src/app/component/element-season/element-season.ts index cafd606..9b0d607 100644 --- a/front/src/app/component/element-season/element-season.ts +++ b/front/src/app/component/element-season/element-season.ts @@ -54,7 +54,7 @@ export class ElementSeasonComponent implements OnInit { this.description = this.element.description; console.log(`covers: ${this.element.covers}`); this.covers = this.dataService.getListThumbnailUrl(this.element.covers); - console.log(`covers >> : ${this.covers}`); + console.log(`covers ${this.element.covers} >> : ${this.covers}`); let self = this; if (!isNullOrUndefined(this.countSubTypeCallBack)) { this.countSubTypeCallBack(this.element.id) diff --git a/front/src/app/scene/artist/artists.ts b/front/src/app/scene/artist/artists.ts index 950ee59..50f7ee9 100644 --- a/front/src/app/scene/artist/artists.ts +++ b/front/src/app/scene/artist/artists.ts @@ -36,8 +36,6 @@ export class ArtistsScene implements OnInit { let self = this; this.countTrack = (id: number) => { return self.countTrackCallback(id); }; this.countAlbum = (id: number) => { return self.countAlbumCallback(id); }; - // this.idPlaylist = parseInt(this.route.snapshot.paramMap.get('universId')); - // this.idType = parseInt(this.route.snapshot.paramMap.get('typeId')); this.artistService.getOrder() .then((response: Artist[]) => { self.artists = response; diff --git a/front/src/app/service/GenericDataService.ts b/front/src/app/service/GenericDataService.ts index aa0c82f..2392648 100644 --- a/front/src/app/service/GenericDataService.ts +++ b/front/src/app/service/GenericDataService.ts @@ -84,7 +84,9 @@ export class GenericDataService { key: 'id', value: [undefined, null], }, - ]); + ], + ["name", "id"], + ); resolve(data); }).catch((response) => { console.log(`[E] ${self.constructor.name}: can not retrieve BDD values`); diff --git a/front/src/app/service/data.ts b/front/src/app/service/data.ts index 3697334..172fe6f 100644 --- a/front/src/app/service/data.ts +++ b/front/src/app/service/data.ts @@ -5,7 +5,7 @@ */ import { Injectable } from '@angular/core'; -import { isArrayOf, isNullOrUndefined, isNumberFinite } from 'common/utils'; +import { isArrayOf, isNullOrUndefined, isNumberFinite, isString } from 'common/utils'; import { SessionService } from 'common/service'; import { RESTConfig, RESTUrl } from 'app/back-api/rest-tools'; @@ -65,7 +65,7 @@ export class DataService { * @returns the url of the cover */ getListUrl(dataIds?: string[]): string[] | undefined { - if (!isArrayOf(dataIds, isNumberFinite) || dataIds.length === 0) { + if (!isArrayOf(dataIds, isString) || dataIds.length === 0) { return undefined; } let covers: string[] = []; @@ -97,7 +97,7 @@ export class DataService { * @returns the url of the cover */ getListThumbnailUrl(dataIds?: string[]): string[] | undefined { - if (!isArrayOf(dataIds, isNumberFinite) || dataIds.length === 0) { + if (!isArrayOf(dataIds, isString) || dataIds.length === 0) { return undefined; } let covers: string[] = [];