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