[DEV] update new archidata

This commit is contained in:
Edouard DUPIN 2024-01-17 20:20:31 +01:00
parent a538da73ce
commit 511c6d0bc7
2 changed files with 22 additions and 21 deletions

View File

@ -20,7 +20,7 @@
<dependency> <dependency>
<groupId>kangaroo-and-rabbit</groupId> <groupId>kangaroo-and-rabbit</groupId>
<artifactId>archidata</artifactId> <artifactId>archidata</artifactId>
<version>0.5.0</version> <version>0.6.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>

View File

@ -11,6 +11,7 @@ import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataAccess;
import org.kar.archidata.dataAccess.QueryCondition; import org.kar.archidata.dataAccess.QueryCondition;
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany; import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
import org.kar.archidata.dataAccess.options.Condition;
import org.kar.archidata.model.Data; import org.kar.archidata.model.Data;
import org.kar.archidata.tools.DataTools; import org.kar.archidata.tools.DataTools;
import org.kar.karusic.model.Album; import org.kar.karusic.model.Album;
@ -33,27 +34,27 @@ import jakarta.ws.rs.core.Response;
@Path("/track") @Path("/track")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public class TrackResource { public class TrackResource {
@GET @GET
@Path("{id}") @Path("{id}")
@RolesAllowed("USER") @RolesAllowed("USER")
public static Track getWithId(@PathParam("id") final Long id) throws Exception { public static Track getWithId(@PathParam("id") final Long id) throws Exception {
return DataAccess.get(Track.class, id); return DataAccess.get(Track.class, id);
} }
@GET @GET
@RolesAllowed("USER") @RolesAllowed("USER")
public List<Track> get() throws Exception { public List<Track> get() throws Exception {
return DataAccess.gets(Track.class); return DataAccess.gets(Track.class);
} }
@POST @POST
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public Track create(final String jsonRequest) throws Exception { public Track create(final String jsonRequest) throws Exception {
return DataAccess.insertWithJson(Track.class, jsonRequest); return DataAccess.insertWithJson(Track.class, jsonRequest);
} }
@PUT @PUT
@Path("{id}") @Path("{id}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@ -62,7 +63,7 @@ public class TrackResource {
DataAccess.updateWithJson(Track.class, id, jsonRequest); DataAccess.updateWithJson(Track.class, id, jsonRequest);
return DataAccess.get(Track.class, id); return DataAccess.get(Track.class, id);
} }
@DELETE @DELETE
@Path("{id}") @Path("{id}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@ -70,7 +71,7 @@ public class TrackResource {
DataAccess.delete(Track.class, id); DataAccess.delete(Track.class, id);
return Response.ok().build(); return Response.ok().build();
} }
@POST @POST
@Path("{id}/add_artist/{artistId}") @Path("{id}/add_artist/{artistId}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@ -79,7 +80,7 @@ public class TrackResource {
AddOnManyToMany.removeLink(Track.class, id, "artist", artistId); AddOnManyToMany.removeLink(Track.class, id, "artist", artistId);
return DataAccess.get(Track.class, id); return DataAccess.get(Track.class, id);
} }
@GET @GET
@Path("{id}/rm_artist/{trackId}") @Path("{id}/rm_artist/{trackId}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@ -87,7 +88,7 @@ public class TrackResource {
AddOnManyToMany.removeLink(Track.class, id, "artist", artistId); AddOnManyToMany.removeLink(Track.class, id, "artist", artistId);
return DataAccess.get(Track.class, id); return DataAccess.get(Track.class, id);
} }
@POST @POST
@Path("{id}/add_cover") @Path("{id}/add_cover")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@ -96,7 +97,7 @@ public class TrackResource {
@FormDataParam("file") final FormDataContentDisposition fileMetaData) { @FormDataParam("file") final FormDataContentDisposition fileMetaData) {
return DataTools.uploadCover(Track.class, id, fileName, fileInputStream, fileMetaData); return DataTools.uploadCover(Track.class, id, fileName, fileInputStream, fileMetaData);
} }
@GET @GET
@Path("{id}/rm_cover/{coverId}") @Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@ -104,7 +105,7 @@ public class TrackResource {
AddOnManyToMany.removeLink(Track.class, id, "cover", coverId); AddOnManyToMany.removeLink(Track.class, id, "cover", coverId);
return Response.ok(DataAccess.get(Track.class, id)).build(); return Response.ok(DataAccess.get(Track.class, id)).build();
} }
@POST @POST
@Path("/upload/") @Path("/upload/")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@ -121,7 +122,7 @@ public class TrackResource {
album = DataTools.multipartCorrection(album); album = DataTools.multipartCorrection(album);
trackId = DataTools.multipartCorrection(trackId); trackId = DataTools.multipartCorrection(trackId);
title = DataTools.multipartCorrection(title); title = DataTools.multipartCorrection(title);
//public NodeSmall uploadFile(final FormDataMultiPart form) { //public NodeSmall uploadFile(final FormDataMultiPart form) {
System.out.println("Upload media file: " + fileMetaData); System.out.println("Upload media file: " + fileMetaData);
System.out.println(" - fileName: " + fileName); System.out.println(" - fileName: " + fileName);
@ -141,7 +142,7 @@ public class TrackResource {
build(); build();
} }
*/ */
final long tmpUID = DataTools.getTmpDataId(); final long tmpUID = DataTools.getTmpDataId();
final String sha512 = DataTools.saveTemporaryFile(fileInputStream, tmpUID); final String sha512 = DataTools.saveTemporaryFile(fileInputStream, tmpUID);
Data data = DataTools.getWithSha512(sha512); Data data = DataTools.getWithSha512(sha512);
@ -172,7 +173,7 @@ public class TrackResource {
System.out.println("Find typeNode"); System.out.println("Find typeNode");
Gender genderElem = null; Gender genderElem = null;
if (gender != null) { if (gender != null) {
genderElem = DataAccess.getWhere(Gender.class, new QueryCondition("name", "=", gender)); genderElem = DataAccess.getWhere(Gender.class, new Condition(new QueryCondition("name", "=", gender)));
if (genderElem == null) { if (genderElem == null) {
genderElem = new Gender(); genderElem = new Gender();
genderElem.name = gender; genderElem.name = gender;
@ -185,10 +186,10 @@ public class TrackResource {
// return Response.notModified("TypeId does not exist ...").build(); // return Response.notModified("TypeId does not exist ...").build();
// } // }
System.out.println(" ==> " + genderElem); System.out.println(" ==> " + genderElem);
Artist artistElem = null; Artist artistElem = null;
if (artist != null) { if (artist != null) {
artistElem = DataAccess.getWhere(Artist.class, new QueryCondition("name", "=", artist)); artistElem = DataAccess.getWhere(Artist.class, new Condition(new QueryCondition("name", "=", artist)));
if (artistElem == null) { if (artistElem == null) {
artistElem = new Artist(); artistElem = new Artist();
artistElem.name = artist; artistElem.name = artist;
@ -196,10 +197,10 @@ public class TrackResource {
} }
} }
System.out.println(" ==> " + artistElem); System.out.println(" ==> " + artistElem);
Album albumElem = null; Album albumElem = null;
if (album != null) { if (album != null) {
albumElem = DataAccess.getWhere(Album.class, new QueryCondition("name", "=", album)); albumElem = DataAccess.getWhere(Album.class, new Condition(new QueryCondition("name", "=", album)));
if (albumElem == null) { if (albumElem == null) {
albumElem = new Album(); albumElem = new Album();
albumElem.name = album; albumElem.name = album;
@ -207,9 +208,9 @@ public class TrackResource {
} }
} }
System.out.println(" ==> " + album); System.out.println(" ==> " + album);
System.out.println("add media"); System.out.println("add media");
Track trackElem = new Track(); Track trackElem = new Track();
trackElem.name = title; trackElem.name = title;
trackElem.track = trackId != null ? Long.parseLong(trackId) : null; trackElem.track = trackId != null ? Long.parseLong(trackId) : null;
@ -235,5 +236,5 @@ public class TrackResource {
return Response.status(417).entity("Back-end error : " + ex.getMessage()).type("text/plain").build(); return Response.status(417).entity("Back-end error : " + ex.getMessage()).type("text/plain").build();
} }
} }
} }