[DEV] correct the backend can not insert trach artist ... fail t in archidata model
This commit is contained in:
parent
619973459a
commit
0af1bbfb52
@ -20,7 +20,7 @@
|
||||
<dependency>
|
||||
<groupId>kangaroo-and-rabbit</groupId>
|
||||
<artifactId>archidata</artifactId>
|
||||
<version>0.6.1</version>
|
||||
<version>0.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
|
@ -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]");
|
||||
|
@ -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}")
|
||||
|
@ -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}")
|
||||
|
@ -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}")
|
||||
|
@ -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}")
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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<UserKarusic> 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);
|
||||
}
|
||||
}
|
||||
|
26
back/src/org/kar/karusic/migration/Migration20240225.java
Normal file
26
back/src/org/kar/karusic/migration/Migration20240225.java
Normal file
@ -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
|
||||
""");
|
||||
}
|
||||
|
||||
}
|
@ -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<Long> artists = null;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user