diff --git a/back/pom.xml b/back/pom.xml
index f75aa90..ae1ad41 100644
--- a/back/pom.xml
+++ b/back/pom.xml
@@ -20,7 +20,7 @@
kangaroo-and-rabbit
archidata
- 0.6.1
+ 0.6.3
org.slf4j
diff --git a/back/src/org/kar/karusic/WebLauncher.java b/back/src/org/kar/karusic/WebLauncher.java
index e301330..62f79ea 100755
--- a/back/src/org/kar/karusic/WebLauncher.java
+++ b/back/src/org/kar/karusic/WebLauncher.java
@@ -29,6 +29,7 @@ import org.kar.karusic.api.UserResource;
import org.kar.karusic.filter.KarusicAuthenticationFilter;
import org.kar.karusic.migration.Initialization;
import org.kar.karusic.migration.Migration20231126;
+import org.kar.karusic.migration.Migration20240225;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,6 +55,7 @@ public class WebLauncher {
migrationEngine.setInit(new Initialization());
WebLauncher.LOGGER.info("Add migration since last version");
migrationEngine.add(new Migration20231126());
+ migrationEngine.add(new Migration20240225());
WebLauncher.LOGGER.info("Migrate the DB [START]");
migrationEngine.migrateWaitAdmin(GlobalConfiguration.dbConfig);
WebLauncher.LOGGER.info("Migrate the DB [STOP]");
diff --git a/back/src/org/kar/karusic/api/AlbumResource.java b/back/src/org/kar/karusic/api/AlbumResource.java
index bf22c04..e385f87 100644
--- a/back/src/org/kar/karusic/api/AlbumResource.java
+++ b/back/src/org/kar/karusic/api/AlbumResource.java
@@ -9,6 +9,8 @@ import org.kar.archidata.dataAccess.DataAccess;
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
import org.kar.archidata.tools.DataTools;
import org.kar.karusic.model.Album;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ws.rs.Consumes;
@@ -25,6 +27,7 @@ import jakarta.ws.rs.core.Response;
@Path("/album")
@Produces({ MediaType.APPLICATION_JSON })
public class AlbumResource {
+ private static final Logger LOGGER = LoggerFactory.getLogger(AlbumResource.class);
@GET
@Path("{id}")
diff --git a/back/src/org/kar/karusic/api/ArtistResource.java b/back/src/org/kar/karusic/api/ArtistResource.java
index 415ace9..3d21875 100644
--- a/back/src/org/kar/karusic/api/ArtistResource.java
+++ b/back/src/org/kar/karusic/api/ArtistResource.java
@@ -9,6 +9,8 @@ import org.kar.archidata.dataAccess.DataAccess;
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
import org.kar.archidata.tools.DataTools;
import org.kar.karusic.model.Artist;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ws.rs.Consumes;
@@ -25,6 +27,7 @@ import jakarta.ws.rs.core.Response;
@Path("/artist")
@Produces({ MediaType.APPLICATION_JSON })
public class ArtistResource {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ArtistResource.class);
@GET
@Path("{id}")
diff --git a/back/src/org/kar/karusic/api/GenderResource.java b/back/src/org/kar/karusic/api/GenderResource.java
index 93fff2f..fbee6c0 100644
--- a/back/src/org/kar/karusic/api/GenderResource.java
+++ b/back/src/org/kar/karusic/api/GenderResource.java
@@ -9,6 +9,8 @@ import org.kar.archidata.dataAccess.DataAccess;
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
import org.kar.archidata.tools.DataTools;
import org.kar.karusic.model.Gender;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ws.rs.Consumes;
@@ -25,6 +27,7 @@ import jakarta.ws.rs.core.Response;
@Path("/gender")
@Produces({ MediaType.APPLICATION_JSON })
public class GenderResource {
+ private static final Logger LOGGER = LoggerFactory.getLogger(GenderResource.class);
@GET
@Path("{id}")
diff --git a/back/src/org/kar/karusic/api/PlaylistResource.java b/back/src/org/kar/karusic/api/PlaylistResource.java
index df6e0d6..6a4308b 100644
--- a/back/src/org/kar/karusic/api/PlaylistResource.java
+++ b/back/src/org/kar/karusic/api/PlaylistResource.java
@@ -9,6 +9,8 @@ import org.kar.archidata.dataAccess.DataAccess;
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
import org.kar.archidata.tools.DataTools;
import org.kar.karusic.model.Playlist;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ws.rs.Consumes;
@@ -25,6 +27,7 @@ import jakarta.ws.rs.core.Response;
@Path("/playlist")
@Produces({ MediaType.APPLICATION_JSON })
public class PlaylistResource {
+ private static final Logger LOGGER = LoggerFactory.getLogger(PlaylistResource.class);
@GET
@Path("{id}")
diff --git a/back/src/org/kar/karusic/api/TrackResource.java b/back/src/org/kar/karusic/api/TrackResource.java
index eb713df..f685140 100644
--- a/back/src/org/kar/karusic/api/TrackResource.java
+++ b/back/src/org/kar/karusic/api/TrackResource.java
@@ -18,6 +18,8 @@ import org.kar.karusic.model.Album;
import org.kar.karusic.model.Artist;
import org.kar.karusic.model.Gender;
import org.kar.karusic.model.Track;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ws.rs.Consumes;
@@ -34,6 +36,7 @@ import jakarta.ws.rs.core.Response;
@Path("/track")
@Produces({ MediaType.APPLICATION_JSON })
public class TrackResource {
+ private static final Logger LOGGER = LoggerFactory.getLogger(TrackResource.class);
@GET
@Path("{id}")
@@ -110,10 +113,18 @@ public class TrackResource {
@Path("/upload/")
@RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
- public Response uploadFile(@FormDataParam("fileName") String fileName, @FormDataParam("gender") String gender, @FormDataParam("artist") String artist,
+ // Formatter:off
+ public Response uploadFile(
+ @FormDataParam("fileName") String fileName,
+ @FormDataParam("gender") String gender,
+ @FormDataParam("artist") String artist,
//@FormDataParam("seriesId") String seriesId, Not used ...
- @FormDataParam("album") String album, @FormDataParam("trackId") String trackId, @FormDataParam("title") String title, @FormDataParam("file") final InputStream fileInputStream,
+ @FormDataParam("album") String album,
+ @FormDataParam("trackId") String trackId,
+ @FormDataParam("title") String title,
+ @FormDataParam("file") final InputStream fileInputStream,
@FormDataParam("file") final FormDataContentDisposition fileMetaData) {
+ // Formatter:on
try {
// correct input string stream :
fileName = DataTools.multipartCorrection(fileName);
@@ -124,16 +135,15 @@ public class TrackResource {
title = DataTools.multipartCorrection(title);
//public NodeSmall uploadFile(final FormDataMultiPart form) {
- System.out.println("Upload media file: " + fileMetaData);
- System.out.println(" - fileName: " + fileName);
- System.out.println(" - gender: " + gender);
- System.out.println(" - artist: " + artist);
- System.out.println(" - album: " + album);
- System.out.println(" - trackId: " + trackId);
- System.out.println(" - title: " + title);
- System.out.println(" - fileInputStream: " + fileInputStream);
- System.out.println(" - fileMetaData: " + fileMetaData);
- System.out.flush();
+ LOGGER.info("Upload media file: " + fileMetaData);
+ LOGGER.info(" > fileName: " + fileName);
+ LOGGER.info(" > gender: " + gender);
+ LOGGER.info(" > artist: " + artist);
+ LOGGER.info(" > album: " + album);
+ LOGGER.info(" > trackId: " + trackId);
+ LOGGER.info(" > title: " + title);
+ LOGGER.info(" > fileInputStream: " + fileInputStream);
+ LOGGER.info(" > fileMetaData: " + fileMetaData);
/*
if (typeId == null) {
return Response.status(406).
@@ -147,8 +157,8 @@ public class TrackResource {
final String sha512 = DataTools.saveTemporaryFile(fileInputStream, tmpUID);
Data data = DataTools.getWithSha512(sha512);
if (data == null) {
- System.out.println("Need to add the data in the BDD ... ");
- System.out.flush();
+ LOGGER.info("Need to add the data in the BDD ... ");
+
try {
data = DataTools.createNewData(tmpUID, fileName, sha512);
} catch (final IOException ex) {
@@ -161,16 +171,14 @@ public class TrackResource {
return Response.notModified("Error in SQL insertion ...").build();
}
} else if (data.deleted) {
- System.out.println("Data already exist but deleted");
- System.out.flush();
+ LOGGER.info("Data already exist but deleted");
DataTools.undelete(data.id);
data.deleted = false;
} else {
- System.out.println("Data already exist ... all good");
- System.out.flush();
+ LOGGER.info("Data already exist ... all good");
}
// Fist step: retrieve all the Id of each parents:...
- System.out.println("Find typeNode");
+ LOGGER.info("Find typeNode");
Gender genderElem = null;
if (gender != null) {
genderElem = DataAccess.getWhere(Gender.class, new Condition(new QueryCondition("name", "=", gender)));
@@ -185,18 +193,20 @@ public class TrackResource {
// DataTools.removeTemporaryFile(tmpUID);
// return Response.notModified("TypeId does not exist ...").build();
// }
- System.out.println(" ==> " + genderElem);
+ LOGGER.info(" ==> genderElem={}", genderElem);
Artist artistElem = null;
if (artist != null) {
+ LOGGER.info(" Try to find Artist: '{}'", artist);
artistElem = DataAccess.getWhere(Artist.class, new Condition(new QueryCondition("name", "=", artist)));
if (artistElem == null) {
+ LOGGER.info(" ** Create a new one...");
artistElem = new Artist();
artistElem.name = artist;
artistElem = DataAccess.insert(artistElem);
}
}
- System.out.println(" ==> " + artistElem);
+ LOGGER.info(" ==> artistElem={}", artistElem);
Album albumElem = null;
if (album != null) {
@@ -207,9 +217,9 @@ public class TrackResource {
albumElem = DataAccess.insert(albumElem);
}
}
- System.out.println(" ==> " + album);
+ LOGGER.info(" ==> " + album);
- System.out.println("add media");
+ LOGGER.info("add media");
Track trackElem = new Track();
trackElem.name = title;
@@ -231,7 +241,7 @@ public class TrackResource {
*/
return Response.ok(trackElem).build();
} catch (final Exception ex) {
- System.out.println("Catch an unexpected error ... " + ex.getMessage());
+ LOGGER.info("Catch an unexpected error ... {}", ex.getMessage());
ex.printStackTrace();
return Response.status(417).entity("Back-end error : " + ex.getMessage()).type("text/plain").build();
}
diff --git a/back/src/org/kar/karusic/api/UserResource.java b/back/src/org/kar/karusic/api/UserResource.java
index 9c2b896..1fed5f2 100755
--- a/back/src/org/kar/karusic/api/UserResource.java
+++ b/back/src/org/kar/karusic/api/UserResource.java
@@ -22,7 +22,7 @@ import jakarta.ws.rs.core.SecurityContext;
@Path("/users")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public class UserResource {
- final Logger logger = LoggerFactory.getLogger(UserResource.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(UserResource.class);
@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserOut {
@@ -42,7 +42,7 @@ public class UserResource {
@GET
@RolesAllowed("ADMIN")
public List getUsers() {
- System.out.println("getUsers");
+ LOGGER.info("getUsers");
try {
return DataAccess.gets(UserKarusic.class);
} catch (final Exception e) {
@@ -57,11 +57,11 @@ public class UserResource {
@Path("{id}")
@RolesAllowed("ADMIN")
public UserKarusic getUsers(@Context final SecurityContext sc, @PathParam("id") final long userId) {
- System.out.println("getUser " + userId);
+ LOGGER.info("getUser {}", userId);
final GenericContext gc = (GenericContext) sc.getUserPrincipal();
- System.out.println("===================================================");
- System.out.println("== USER ? " + gc.userByToken.name);
- System.out.println("===================================================");
+ LOGGER.info("===================================================");
+ LOGGER.info("== USER {} ", gc.userByToken.name);
+ LOGGER.info("===================================================");
try {
return DataAccess.get(UserKarusic.class, userId);
} catch (final Exception e) {
@@ -75,9 +75,9 @@ public class UserResource {
@Path("me")
@RolesAllowed("USER")
public UserOut getMe(@Context final SecurityContext sc) {
- this.logger.debug("getMe()");
+ LOGGER.debug("getMe()");
final GenericContext gc = (GenericContext) sc.getUserPrincipal();
- this.logger.debug("== USER ? {}", gc.userByToken);
+ LOGGER.debug("== USER ? {}", gc.userByToken);
return new UserOut(gc.userByToken.id, gc.userByToken.name);
}
}
diff --git a/back/src/org/kar/karusic/migration/Migration20240225.java b/back/src/org/kar/karusic/migration/Migration20240225.java
new file mode 100644
index 0000000..0714681
--- /dev/null
+++ b/back/src/org/kar/karusic/migration/Migration20240225.java
@@ -0,0 +1,26 @@
+package org.kar.karusic.migration;
+
+import org.kar.archidata.migration.MigrationSqlStep;
+
+public class Migration20240225 extends MigrationSqlStep {
+
+ public static final int KARSO_INITIALISATION_ID = 1;
+
+ @Override
+ public String getName() {
+ return "migration-2024-02-25: change model of thrack to use real json";
+ }
+
+ public Migration20240225() {
+
+ }
+
+ @Override
+ public void generateStep() throws Exception {
+ // update migration update (last one)
+ addAction("""
+ UPDATE `track` SET artists = CONCAT('[', artists, ']') WHERE artists IS NOT NULL
+ """);
+ }
+
+}
diff --git a/back/src/org/kar/karusic/model/Track.java b/back/src/org/kar/karusic/model/Track.java
index 7fe6481..bf7b513 100644
--- a/back/src/org/kar/karusic/model/Track.java
+++ b/back/src/org/kar/karusic/model/Track.java
@@ -15,7 +15,7 @@ CREATE TABLE `node` (
import java.util.List;
import org.kar.archidata.annotation.DataIfNotExists;
-import org.kar.archidata.annotation.addOn.SQLTableExternalForeinKeyAsList;
+import org.kar.archidata.annotation.DataJson;
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -31,7 +31,7 @@ public class Track extends NodeSmall {
public Long track = null;
public Long dataId = null;
//@ManyToMany(fetch = FetchType.LAZY, targetEntity = Artist.class)
- @SQLTableExternalForeinKeyAsList
+ @DataJson
@Column(length = 0)
public List artists = null;