[DEV] udpate to the new JPA (not finished...)

This commit is contained in:
Edouard DUPIN 2023-10-15 23:39:25 +02:00
parent f04ea20c30
commit 1897fac53a
17 changed files with 701 additions and 765 deletions

View File

@ -22,7 +22,7 @@
<dependency> <dependency>
<groupId>kangaroo-and-rabbit</groupId> <groupId>kangaroo-and-rabbit</groupId>
<artifactId>archidata</artifactId> <artifactId>archidata</artifactId>
<version>0.3.7</version> <version>0.4.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>

View File

@ -1,96 +1,99 @@
package org.kar.karusic.api; package org.kar.karusic.api;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.SqlWrapper;
import org.kar.archidata.util.DataTools;
import org.kar.karusic.model.Album;
import org.kar.karusic.model.Track;
import org.kar.archidata.annotation.security.RolesAllowed;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.annotation.security.RolesAllowed;
import org.kar.archidata.sqlWrapper.SqlWrapper;
import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
import org.kar.archidata.util.DataTools;
import org.kar.karusic.model.Album;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
@Path("/album") @Path("/album")
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public class AlbumResource { public class AlbumResource {
@GET @GET
@Path("{id}") @Path("{id}")
@RolesAllowed("USER") @RolesAllowed("USER")
public static Album getWithId(@PathParam("id") Long id) throws Exception { public static Album getWithId(@PathParam("id") Long id) throws Exception {
return SqlWrapper.get(Album.class, id); return SqlWrapper.get(Album.class, id);
} }
@GET @GET
@RolesAllowed("USER") @RolesAllowed("USER")
public List<Album> get() throws Exception { public List<Album> get() throws Exception {
return SqlWrapper.gets(Album.class, false); return SqlWrapper.gets(Album.class);
} }
@POST @POST
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public Album post(String jsonRequest) throws Exception { public Album post(String jsonRequest) throws Exception {
return SqlWrapper.insertWithJson(Album.class, jsonRequest); return SqlWrapper.insertWithJson(Album.class, jsonRequest);
} }
@PUT @PUT
@Path("{id}") @Path("{id}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public Album put(@PathParam("id") Long id, String jsonRequest) throws Exception { public Album put(@PathParam("id") Long id, String jsonRequest) throws Exception {
SqlWrapper.update(Album.class, id, jsonRequest); SqlWrapper.update(Album.class, id, jsonRequest);
return SqlWrapper.get(Album.class, id); return SqlWrapper.get(Album.class, id);
} }
@DELETE @DELETE
@Path("{id}") @Path("{id}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception { public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.setDelete(Album.class, id); SqlWrapper.delete(Album.class, id);
return Response.ok().build(); return Response.ok().build();
} }
@POST @POST
@Path("{id}/add_track/{trackId}") @Path("{id}/add_track/{trackId}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes({MediaType.MULTIPART_FORM_DATA}) @Consumes({ MediaType.MULTIPART_FORM_DATA })
public Album addTrack(@PathParam("id") Long id,@PathParam("trackId") Long trackId) throws Exception { public Album addTrack(@PathParam("id") Long id, @PathParam("trackId") Long trackId) throws Exception {
SqlWrapper.removeLink(Album.class, id, "track", trackId); AddOnManyToMany.removeLink(Album.class, id, "track", trackId);
return SqlWrapper.get(Album.class, id); return SqlWrapper.get(Album.class, id);
} }
@GET @GET
@Path("{id}/rm_track/{trackId}") @Path("{id}/rm_track/{trackId}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
public Album removeTrack(@PathParam("id") Long id, @PathParam("trackId") Long trackId) throws Exception { public Album removeTrack(@PathParam("id") Long id, @PathParam("trackId") Long trackId) throws Exception {
SqlWrapper.removeLink(Album.class, id, "track", trackId); AddOnManyToMany.removeLink(Album.class, id, "track", trackId);
return SqlWrapper.get(Album.class, id); return SqlWrapper.get(Album.class, id);
} }
@POST @POST
@Path("{id}/add_cover") @Path("{id}/add_cover")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes({MediaType.MULTIPART_FORM_DATA}) @Consumes({ MediaType.MULTIPART_FORM_DATA })
public Response uploadCover(@PathParam("id") Long id, public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
@FormDataParam("fileName") String fileName, @FormDataParam("file") FormDataContentDisposition fileMetaData) {
@FormDataParam("file") InputStream fileInputStream, return DataTools.uploadCover(Album.class, id, fileName, fileInputStream, fileMetaData);
@FormDataParam("file") FormDataContentDisposition fileMetaData }
) {
return DataTools.uploadCover(Album.class, id, fileName, fileInputStream, fileMetaData); @GET
} @Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
@GET public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
@Path("{id}/rm_cover/{coverId}") AddOnManyToMany.removeLink(Album.class, id, "cover", coverId);
@RolesAllowed("ADMIN") return Response.ok(SqlWrapper.get(Album.class, id)).build();
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception { }
SqlWrapper.removeLink(Album.class, id, "cover", coverId);
return Response.ok(SqlWrapper.get(Album.class, id)).build();
}
} }

View File

@ -1,78 +1,82 @@
package org.kar.karusic.api; package org.kar.karusic.api;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.karusic.model.Artist;
import org.kar.archidata.SqlWrapper;
import org.kar.archidata.util.DataTools;
import org.kar.archidata.annotation.security.RolesAllowed;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.annotation.security.RolesAllowed;
import org.kar.archidata.sqlWrapper.SqlWrapper;
import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
import org.kar.archidata.util.DataTools;
import org.kar.karusic.model.Artist;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
@Path("/artist") @Path("/artist")
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public class ArtistResource { public class ArtistResource {
@GET @GET
@Path("{id}") @Path("{id}")
@RolesAllowed("USER") @RolesAllowed("USER")
public static Artist getWithId(@PathParam("id") Long id) throws Exception { public static Artist getWithId(@PathParam("id") Long id) throws Exception {
return SqlWrapper.get(Artist.class, id); return SqlWrapper.get(Artist.class, id);
} }
@GET @GET
@RolesAllowed("USER") @RolesAllowed("USER")
public List<Artist> get() throws Exception { public List<Artist> get() throws Exception {
return SqlWrapper.gets(Artist.class, false); return SqlWrapper.gets(Artist.class);
} }
@POST @POST
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public Artist put(String jsonRequest) throws Exception { public Artist put(String jsonRequest) throws Exception {
return SqlWrapper.insertWithJson(Artist.class, jsonRequest); return SqlWrapper.insertWithJson(Artist.class, jsonRequest);
} }
@PUT @PUT
@Path("{id}") @Path("{id}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public Artist put(@PathParam("id") Long id, String jsonRequest) throws Exception { public Artist put(@PathParam("id") Long id, String jsonRequest) throws Exception {
SqlWrapper.update(Artist.class, id, jsonRequest); SqlWrapper.update(Artist.class, id, jsonRequest);
return SqlWrapper.get(Artist.class, id); return SqlWrapper.get(Artist.class, id);
} }
@DELETE @DELETE
@Path("{id}") @Path("{id}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception { public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.setDelete(Artist.class, id); SqlWrapper.delete(Artist.class, id);
return Response.ok().build(); return Response.ok().build();
} }
@POST
@Path("{id}/add_cover") @POST
@RolesAllowed("ADMIN") @Path("{id}/add_cover")
@Consumes({MediaType.MULTIPART_FORM_DATA}) @RolesAllowed("ADMIN")
public Response uploadCover(@PathParam("id") Long id, @Consumes({ MediaType.MULTIPART_FORM_DATA })
@FormDataParam("fileName") String fileName, public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") InputStream fileInputStream, @FormDataParam("file") FormDataContentDisposition fileMetaData) {
@FormDataParam("file") FormDataContentDisposition fileMetaData return DataTools.uploadCover(Artist.class, id, fileName, fileInputStream, fileMetaData);
) { }
return DataTools.uploadCover(Artist.class, id, fileName, fileInputStream, fileMetaData);
} @GET
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
@GET public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
@Path("{id}/rm_cover/{coverId}") AddOnManyToMany.removeLink(Artist.class, id, "cover", coverId);
@RolesAllowed("ADMIN") return Response.ok(SqlWrapper.get(Artist.class, id)).build();
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception { }
SqlWrapper.removeLink(Artist.class, id, "cover", coverId);
return Response.ok(SqlWrapper.get(Artist.class, id)).build();
}
} }

View File

@ -1,79 +1,82 @@
package org.kar.karusic.api; package org.kar.karusic.api;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.karusic.model.Gender;
import org.kar.archidata.SqlWrapper;
import org.kar.archidata.util.DataTools;
import org.kar.archidata.annotation.security.RolesAllowed;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.annotation.security.RolesAllowed;
import org.kar.archidata.sqlWrapper.SqlWrapper;
import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
import org.kar.archidata.util.DataTools;
import org.kar.karusic.model.Gender;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
@Path("/gender") @Path("/gender")
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public class GenderResource { public class GenderResource {
@GET @GET
@Path("{id}") @Path("{id}")
@RolesAllowed("USER") @RolesAllowed("USER")
public static Gender getWithId(@PathParam("id") Long id) throws Exception { public static Gender getWithId(@PathParam("id") Long id) throws Exception {
return SqlWrapper.get(Gender.class, id); return SqlWrapper.get(Gender.class, id);
} }
@GET @GET
@RolesAllowed("USER") @RolesAllowed("USER")
public List<Gender> get() throws Exception { public List<Gender> get() throws Exception {
return SqlWrapper.gets(Gender.class, false); return SqlWrapper.gets(Gender.class);
} }
@POST @POST
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public Gender put(String jsonRequest) throws Exception { public Gender put(String jsonRequest) throws Exception {
return SqlWrapper.insertWithJson(Gender.class, jsonRequest); return SqlWrapper.insertWithJson(Gender.class, jsonRequest);
} }
@PUT @PUT
@Path("{id}") @Path("{id}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public Gender put(@PathParam("id") Long id, String jsonRequest) throws Exception { public Gender put(@PathParam("id") Long id, String jsonRequest) throws Exception {
SqlWrapper.update(Gender.class, id, jsonRequest); SqlWrapper.update(Gender.class, id, jsonRequest);
return SqlWrapper.get(Gender.class, id); return SqlWrapper.get(Gender.class, id);
} }
@DELETE @DELETE
@Path("{id}") @Path("{id}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception { public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.setDelete(Gender.class, id); SqlWrapper.delete(Gender.class, id);
return Response.ok().build(); return Response.ok().build();
} }
@POST
@Path("{id}/add_cover") @POST
@RolesAllowed("ADMIN") @Path("{id}/add_cover")
@Consumes({MediaType.MULTIPART_FORM_DATA}) @RolesAllowed("ADMIN")
public Response uploadCover(@PathParam("id") Long id, @Consumes({ MediaType.MULTIPART_FORM_DATA })
@FormDataParam("fileName") String fileName, public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") InputStream fileInputStream, @FormDataParam("file") FormDataContentDisposition fileMetaData) {
@FormDataParam("file") FormDataContentDisposition fileMetaData return DataTools.uploadCover(Gender.class, id, fileName, fileInputStream, fileMetaData);
) { }
return DataTools.uploadCover(Gender.class, id, fileName, fileInputStream, fileMetaData);
} @GET
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
@GET public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
@Path("{id}/rm_cover/{coverId}") AddOnManyToMany.removeLink(Gender.class, id, "cover", coverId);
@RolesAllowed("ADMIN") return Response.ok(SqlWrapper.get(Gender.class, id)).build();
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception { }
SqlWrapper.removeLink(Gender.class, id, "cover", coverId);
return Response.ok(SqlWrapper.get(Gender.class, id)).build();
}
} }

View File

@ -1,98 +1,99 @@
package org.kar.karusic.api; package org.kar.karusic.api;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.karusic.model.Playlist;
import org.kar.archidata.SqlWrapper;
import org.kar.archidata.util.DataTools;
import org.kar.archidata.annotation.security.RolesAllowed;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.annotation.security.RolesAllowed;
import org.kar.archidata.sqlWrapper.SqlWrapper;
import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
import org.kar.archidata.util.DataTools;
import org.kar.karusic.model.Playlist;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
@Path("/playlist") @Path("/playlist")
@Produces({MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_JSON })
public class PlaylistResource { public class PlaylistResource {
@GET @GET
@Path("{id}") @Path("{id}")
@RolesAllowed("USER") @RolesAllowed("USER")
public static Playlist getWithId(@PathParam("id") Long id) throws Exception { public static Playlist getWithId(@PathParam("id") Long id) throws Exception {
return SqlWrapper.get(Playlist.class, id); return SqlWrapper.get(Playlist.class, id);
} }
@GET @GET
@RolesAllowed("USER") @RolesAllowed("USER")
public List<Playlist> get() throws Exception { public List<Playlist> get() throws Exception {
return SqlWrapper.gets(Playlist.class, false); return SqlWrapper.gets(Playlist.class);
} }
@POST @POST
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public Playlist put(String jsonRequest) throws Exception { public Playlist put(String jsonRequest) throws Exception {
return SqlWrapper.insertWithJson(Playlist.class, jsonRequest); return SqlWrapper.insertWithJson(Playlist.class, jsonRequest);
} }
@PUT @PUT
@Path("{id}") @Path("{id}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public Playlist put(@PathParam("id") Long id, String jsonRequest) throws Exception { public Playlist put(@PathParam("id") Long id, String jsonRequest) throws Exception {
SqlWrapper.update(Playlist.class, id, jsonRequest); SqlWrapper.update(Playlist.class, id, jsonRequest);
return SqlWrapper.get(Playlist.class, id); return SqlWrapper.get(Playlist.class, id);
} }
@DELETE @DELETE
@Path("{id}") @Path("{id}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception { public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.setDelete(Playlist.class, id); SqlWrapper.delete(Playlist.class, id);
return Response.ok().build(); return Response.ok().build();
} }
@POST @POST
@Path("{id}/add_track/{trackId}") @Path("{id}/add_track/{trackId}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes({MediaType.MULTIPART_FORM_DATA}) @Consumes({ MediaType.MULTIPART_FORM_DATA })
public Playlist addTrack(@PathParam("id") Long id,@PathParam("trackId") Long trackId) throws Exception { public Playlist addTrack(@PathParam("id") Long id, @PathParam("trackId") Long trackId) throws Exception {
SqlWrapper.removeLink(Playlist.class, id, "track", trackId); AddOnManyToMany.removeLink(Playlist.class, id, "track", trackId);
return SqlWrapper.get(Playlist.class, id); return SqlWrapper.get(Playlist.class, id);
} }
@GET
@GET @Path("{id}/rm_track/{trackId}")
@Path("{id}/rm_track/{trackId}") @RolesAllowed("ADMIN")
@RolesAllowed("ADMIN") public Playlist removeTrack(@PathParam("id") Long id, @PathParam("trackId") Long trackId) throws Exception {
public Playlist removeTrack(@PathParam("id") Long id, @PathParam("trackId") Long trackId) throws Exception { AddOnManyToMany.removeLink(Playlist.class, id, "track", trackId);
SqlWrapper.removeLink(Playlist.class, id, "track", trackId); return SqlWrapper.get(Playlist.class, id);
return SqlWrapper.get(Playlist.class, id); }
}
@POST
@Path("{id}/add_cover")
@POST @RolesAllowed("ADMIN")
@Path("{id}/add_cover") @Consumes({ MediaType.MULTIPART_FORM_DATA })
@RolesAllowed("ADMIN") public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
@Consumes({MediaType.MULTIPART_FORM_DATA}) @FormDataParam("file") FormDataContentDisposition fileMetaData) {
public Response uploadCover(@PathParam("id") Long id, return DataTools.uploadCover(Playlist.class, id, fileName, fileInputStream, fileMetaData);
@FormDataParam("fileName") String fileName, }
@FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData @GET
) { @Path("{id}/rm_cover/{coverId}")
return DataTools.uploadCover(Playlist.class, id, fileName, fileInputStream, fileMetaData); @RolesAllowed("ADMIN")
} public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
AddOnManyToMany.removeLink(Playlist.class, id, "cover", coverId);
return Response.ok(SqlWrapper.get(Playlist.class, id)).build();
@GET }
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
SqlWrapper.removeLink(Playlist.class, id, "cover", coverId);
return Response.ok(SqlWrapper.get(Playlist.class, id)).build();
}
} }

View File

@ -1,249 +1,239 @@
package org.kar.karusic.api; package org.kar.karusic.api;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.karusic.model.Album;
import org.kar.karusic.model.Artist;
import org.kar.archidata.model.Data;
import org.kar.karusic.model.Gender;
import org.kar.karusic.model.Track;
import org.kar.archidata.SqlWrapper;
import org.kar.archidata.util.DataTools;
import org.kar.archidata.annotation.security.RolesAllowed;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.annotation.security.RolesAllowed;
import org.kar.archidata.model.Data;
import org.kar.archidata.sqlWrapper.QuerryCondition;
import org.kar.archidata.sqlWrapper.SqlWrapper;
import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
import org.kar.archidata.util.DataTools;
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 jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
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") Long id) throws Exception { public static Track getWithId(@PathParam("id") Long id) throws Exception {
return SqlWrapper.get(Track.class, id); return SqlWrapper.get(Track.class, id);
} }
@GET @GET
@RolesAllowed("USER") @RolesAllowed("USER")
public List<Track> get() throws Exception { public List<Track> get() throws Exception {
return SqlWrapper.gets(Track.class, false); return SqlWrapper.gets(Track.class);
} }
@POST @POST
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public Track create(String jsonRequest) throws Exception { public Track create(String jsonRequest) throws Exception {
return SqlWrapper.insertWithJson(Track.class, jsonRequest); return SqlWrapper.insertWithJson(Track.class, jsonRequest);
} }
@PUT @PUT
@Path("{id}") @Path("{id}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public Track put(@PathParam("id") Long id, String jsonRequest) throws Exception { public Track put(@PathParam("id") Long id, String jsonRequest) throws Exception {
SqlWrapper.update(Track.class, id, jsonRequest); SqlWrapper.update(Track.class, id, jsonRequest);
return SqlWrapper.get(Track.class, id); return SqlWrapper.get(Track.class, id);
} }
@DELETE @DELETE
@Path("{id}") @Path("{id}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception { public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.setDelete(Track.class, id); SqlWrapper.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")
@Consumes({MediaType.MULTIPART_FORM_DATA}) @Consumes({ MediaType.MULTIPART_FORM_DATA })
public Track addTrack(@PathParam("id") Long id,@PathParam("artistId") Long artistId) throws Exception { public Track addTrack(@PathParam("id") Long id, @PathParam("artistId") Long artistId) throws Exception {
SqlWrapper.removeLink(Track.class, id, "artist", artistId); AddOnManyToMany.removeLink(Track.class, id, "artist", artistId);
return SqlWrapper.get(Track.class, id); return SqlWrapper.get(Track.class, id);
} }
@GET
@GET @Path("{id}/rm_artist/{trackId}")
@Path("{id}/rm_artist/{trackId}") @RolesAllowed("ADMIN")
@RolesAllowed("ADMIN") public Track removeTrack(@PathParam("id") Long id, @PathParam("artistId") Long artistId) throws Exception {
public Track removeTrack(@PathParam("id") Long id, @PathParam("artistId") Long artistId) throws Exception { AddOnManyToMany.removeLink(Track.class, id, "artist", artistId);
SqlWrapper.removeLink(Track.class, id, "artist", artistId); return SqlWrapper.get(Track.class, id);
return SqlWrapper.get(Track.class, id); }
}
@POST
@Path("{id}/add_cover")
@POST @RolesAllowed("ADMIN")
@Path("{id}/add_cover") @Consumes({ MediaType.MULTIPART_FORM_DATA })
@RolesAllowed("ADMIN") public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
@Consumes({MediaType.MULTIPART_FORM_DATA}) @FormDataParam("file") FormDataContentDisposition fileMetaData) {
public Response uploadCover(@PathParam("id") Long id, return DataTools.uploadCover(Track.class, id, fileName, fileInputStream, fileMetaData);
@FormDataParam("fileName") String fileName, }
@FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData @GET
) { @Path("{id}/rm_cover/{coverId}")
return DataTools.uploadCover(Track.class, id, fileName, fileInputStream, fileMetaData); @RolesAllowed("ADMIN")
} public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
AddOnManyToMany.removeLink(Track.class, id, "cover", coverId);
return Response.ok(SqlWrapper.get(Track.class, id)).build();
@GET }
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN") @POST
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception { @Path("/upload/")
SqlWrapper.removeLink(Track.class, id, "cover", coverId); @RolesAllowed("ADMIN")
return Response.ok(SqlWrapper.get(Track.class, id)).build(); @Consumes({ MediaType.MULTIPART_FORM_DATA })
} 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") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData) {
@POST try {
@Path("/upload/") // correct input string stream :
@RolesAllowed("ADMIN") fileName = DataTools.multipartCorrection(fileName);
@Consumes({MediaType.MULTIPART_FORM_DATA}) gender = DataTools.multipartCorrection(gender);
public Response uploadFile(@FormDataParam("fileName") String fileName, artist = DataTools.multipartCorrection(artist);
@FormDataParam("gender") String gender, album = DataTools.multipartCorrection(album);
@FormDataParam("artist") String artist, trackId = DataTools.multipartCorrection(trackId);
//@FormDataParam("seriesId") String seriesId, Not used ... title = DataTools.multipartCorrection(title);
@FormDataParam("album") String album,
@FormDataParam("trackId") String trackId, //public NodeSmall uploadFile(final FormDataMultiPart form) {
@FormDataParam("title") String title, System.out.println("Upload media file: " + fileMetaData);
@FormDataParam("file") InputStream fileInputStream, System.out.println(" - fileName: " + fileName);
@FormDataParam("file") FormDataContentDisposition fileMetaData System.out.println(" - gender: " + gender);
) { System.out.println(" - artist: " + artist);
try { System.out.println(" - album: " + album);
// correct input string stream : System.out.println(" - trackId: " + trackId);
fileName = DataTools.multipartCorrection(fileName); System.out.println(" - title: " + title);
gender = DataTools.multipartCorrection(gender); System.out.println(" - fileInputStream: " + fileInputStream);
artist = DataTools.multipartCorrection(artist); System.out.println(" - fileMetaData: " + fileMetaData);
album = DataTools.multipartCorrection(album); System.out.flush();
trackId = DataTools.multipartCorrection(trackId); /*
title = DataTools.multipartCorrection(title); if (typeId == null) {
return Response.status(406).
//public NodeSmall uploadFile(final FormDataMultiPart form) { entity("Missong Input 'type'").
System.out.println("Upload media file: " + fileMetaData); type("text/plain").
System.out.println(" - fileName: " + fileName); build();
System.out.println(" - gender: " + gender); }
System.out.println(" - artist: " + artist); */
System.out.println(" - album: " + album);
System.out.println(" - trackId: " + trackId); long tmpUID = DataTools.getTmpDataId();
System.out.println(" - title: " + title); String sha512 = DataTools.saveTemporaryFile(fileInputStream, tmpUID);
System.out.println(" - fileInputStream: " + fileInputStream); Data data = DataTools.getWithSha512(sha512);
System.out.println(" - fileMetaData: " + fileMetaData); if (data == null) {
System.out.flush(); System.out.println("Need to add the data in the BDD ... ");
/* System.out.flush();
if (typeId == null) { try {
return Response.status(406). data = DataTools.createNewData(tmpUID, fileName, sha512);
entity("Missong Input 'type'"). } catch (IOException ex) {
type("text/plain"). DataTools.removeTemporaryFile(tmpUID);
build(); ex.printStackTrace();
} return Response.notModified("can not create input media").build();
*/ } catch (SQLException ex) {
ex.printStackTrace();
long tmpUID = DataTools.getTmpDataId(); DataTools.removeTemporaryFile(tmpUID);
String sha512 = DataTools.saveTemporaryFile(fileInputStream, tmpUID); return Response.notModified("Error in SQL insertion ...").build();
Data data = DataTools.getWithSha512(sha512); }
if (data == null) { } else if (data.deleted == true) {
System.out.println("Need to add the data in the BDD ... "); System.out.println("Data already exist but deleted");
System.out.flush(); System.out.flush();
try { DataTools.undelete(data.id);
data = DataTools.createNewData(tmpUID, fileName, sha512); data.deleted = false;
} catch (IOException ex) { } else {
DataTools.removeTemporaryFile(tmpUID); System.out.println("Data already exist ... all good");
ex.printStackTrace(); System.out.flush();
return Response.notModified("can not create input media").build(); }
} catch (SQLException ex) { // Fist step: retrieve all the Id of each parents:...
ex.printStackTrace(); System.out.println("Find typeNode");
DataTools.removeTemporaryFile(tmpUID); Gender genderElem = null;
return Response.notModified("Error in SQL insertion ...").build(); if (gender != null) {
} genderElem = SqlWrapper.getWhere(Gender.class, new QuerryCondition("name", "=", gender));
} else if (data.deleted == true) { if (genderElem == null) {
System.out.println("Data already exist but deleted"); genderElem = new Gender();
System.out.flush(); genderElem.name = gender;
DataTools.undelete(data.id); genderElem = SqlWrapper.insert(genderElem);
data.deleted = false; }
} else { }
System.out.println("Data already exist ... all good"); // NodeSmall typeNode = TypeResource.getWithId(Long.parseLong(typeId));
System.out.flush(); // if (typeNode == null) {
} // DataTools.removeTemporaryFile(tmpUID);
// Fist step: retrieve all the Id of each parents:... // return Response.notModified("TypeId does not exist ...").build();
System.out.println("Find typeNode"); // }
Gender genderElem = null; System.out.println(" ==> " + genderElem);
if (gender != null) {
genderElem = SqlWrapper.getWith(Gender.class, "name", gender); Artist artistElem = null;
if (genderElem == null) { if (artist != null) {
genderElem = new Gender(); artistElem = SqlWrapper.getWhere(Artist.class, new QuerryCondition("name", "=", artist));
genderElem.name = gender; if (artistElem == null) {
genderElem = SqlWrapper.insert(genderElem); artistElem = new Artist();
} artistElem.name = artist;
} artistElem = SqlWrapper.insert(artistElem);
// NodeSmall typeNode = TypeResource.getWithId(Long.parseLong(typeId)); }
// if (typeNode == null) { }
// DataTools.removeTemporaryFile(tmpUID); System.out.println(" ==> " + artistElem);
// return Response.notModified("TypeId does not exist ...").build();
// } Album albumElem = null;
System.out.println(" ==> " + genderElem); if (album != null) {
albumElem = SqlWrapper.getWhere(Album.class, new QuerryCondition("name", "=", album));
Artist artistElem = null; if (albumElem == null) {
if (artist != null) { albumElem = new Album();
artistElem = SqlWrapper.getWith(Artist.class, "name", artist); albumElem.name = album;
if (artistElem == null){ albumElem = SqlWrapper.insert(albumElem);
artistElem = new Artist(); }
artistElem.name = artist; }
artistElem = SqlWrapper.insert(artistElem); System.out.println(" ==> " + album);
}
} System.out.println("add media");
System.out.println(" ==> " + artistElem);
Track trackElem = new Track();
Album albumElem = null; trackElem.name = title;
if (album != null) { trackElem.track = trackId != null ? Long.parseLong(trackId) : null;
albumElem = SqlWrapper.getWith(Album.class, "name", album); trackElem.albumId = albumElem != null ? albumElem.id : null;
if (albumElem == null) { trackElem.genderId = genderElem != null ? genderElem.id : null;
albumElem = new Album(); trackElem.dataId = data.id;
albumElem.name = album; // Now list of artis has an internal management:
albumElem = SqlWrapper.insert(albumElem); if (artistElem != null) {
} trackElem.artists = new ArrayList<>();
} trackElem.artists.add(artistElem.id);
System.out.println(" ==> " + album); }
trackElem = SqlWrapper.insert(trackElem);
/*
System.out.println("add media"); Old mode of artist insertion (removed due to the slowlest request of getting value
if (artistElem != null) {
Track trackElem = new Track(); SqlWrapper.addLink(Track.class, trackElem.id, "artist", artistElem.id);
trackElem.name = title; }
trackElem.track = trackId!=null?Long.parseLong(trackId):null; */
trackElem.albumId = albumElem!=null?albumElem.id:null; return Response.ok(trackElem).build();
trackElem.genderId = genderElem!=null?genderElem.id:null; } catch (Exception ex) {
trackElem.dataId = data.id; System.out.println("Catch an unexpected error ... " + ex.getMessage());
// Now list of artis has an internal management: ex.printStackTrace();
if (artistElem != null) { return Response.status(417).entity("Back-end error : " + ex.getMessage()).type("text/plain").build();
trackElem.artists = new ArrayList<>(); }
trackElem.artists.add(artistElem.id); }
}
trackElem = SqlWrapper.insert(trackElem);
/*
Old mode of artist insertion (removed due to the slowlest request of getting value
if (artistElem != null) {
SqlWrapper.addLink(Track.class, trackElem.id, "artist", artistElem.id);
}
*/
return Response.ok(trackElem).build();
} catch (Exception ex) {
System.out.println("Catch an unexpected error ... " + ex.getMessage());
ex.printStackTrace();
return Response.status(417).
entity("Back-end error : " + ex.getMessage()).
type("text/plain").
build();
}
}
} }

View File

@ -1,30 +1,34 @@
package org.kar.karusic.api; package org.kar.karusic.api;
import org.kar.archidata.SqlWrapper; import java.util.List;
import org.kar.archidata.annotation.security.RolesAllowed;
import org.kar.archidata.filter.GenericContext; import org.kar.archidata.filter.GenericContext;
import org.kar.archidata.sqlWrapper.SqlWrapper;
import org.kar.karusic.model.UserKarusic; import org.kar.karusic.model.UserKarusic;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import org.kar.archidata.annotation.security.RolesAllowed; import jakarta.ws.rs.GET;
import jakarta.ws.rs.*; import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context; import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.SecurityContext; import jakarta.ws.rs.core.SecurityContext;
import java.util.List;
@Path("/users") @Path("/users")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public class UserResource { public class UserResource {
final Logger logger = LoggerFactory.getLogger(UserResource.class); final Logger logger = LoggerFactory.getLogger(UserResource.class);
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class UserOut { public class UserOut {
public long id; public long id;
public String login; public String login;
public UserOut(long id, String login) { public UserOut(long id, String login) {
super(); super();
this.id = id; this.id = id;
@ -32,83 +36,49 @@ public class UserResource {
} }
} }
public UserResource() { public UserResource() {}
}
// curl http://localhost:9993/api/users
// curl http://localhost:9993/api/users @GET
@GET @RolesAllowed("ADMIN")
@RolesAllowed("ADMIN") public List<UserKarusic> getUsers() {
public List<UserKarusic> getUsers() { System.out.println("getUsers");
System.out.println("getUsers"); try {
try { return SqlWrapper.gets(UserKarusic.class);
return SqlWrapper.gets(UserKarusic.class, false);
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} }
// curl http://localhost:9993/api/users/3 // curl http://localhost:9993/api/users/3
@GET @GET
@Path("{id}") @Path("{id}")
@RolesAllowed("ADMIN") @RolesAllowed("ADMIN")
public UserKarusic getUsers(@Context SecurityContext sc, @PathParam("id") long userId) { public UserKarusic getUsers(@Context SecurityContext sc, @PathParam("id") long userId) {
System.out.println("getUser " + userId); System.out.println("getUser " + userId);
GenericContext gc = (GenericContext) sc.getUserPrincipal(); GenericContext gc = (GenericContext) sc.getUserPrincipal();
System.out.println("==================================================="); System.out.println("===================================================");
System.out.println("== USER ? " + gc.userByToken.name); System.out.println("== USER ? " + gc.userByToken.name);
System.out.println("==================================================="); System.out.println("===================================================");
try { try {
return SqlWrapper.get(UserKarusic.class, userId); return SqlWrapper.get(UserKarusic.class, userId);
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} }
@GET
@GET @Path("me")
@Path("me") @RolesAllowed("USER")
@RolesAllowed("USER") public UserOut getMe(@Context SecurityContext sc) {
public UserOut getMe(@Context SecurityContext sc) { logger.debug("getMe()");
logger.debug("getMe()"); GenericContext gc = (GenericContext) sc.getUserPrincipal();
GenericContext gc = (GenericContext) sc.getUserPrincipal(); logger.debug("== USER ? {}", gc.userByToken);
logger.debug("== USER ? {}", gc.userByToken); return new UserOut(gc.userByToken.id, gc.userByToken.name);
return new UserOut(gc.userByToken.id, gc.userByToken.name); }
}
} }

View File

@ -1,4 +1,5 @@
package org.kar.karusic.model; package org.kar.karusic.model;
/* /*
CREATE TABLE `node` ( CREATE TABLE `node` (
`id` bigint NOT NULL COMMENT 'table ID' AUTO_INCREMENT PRIMARY KEY, `id` bigint NOT NULL COMMENT 'table ID' AUTO_INCREMENT PRIMARY KEY,
@ -14,11 +15,12 @@ CREATE TABLE `node` (
import java.sql.Date; import java.sql.Date;
import org.kar.archidata.annotation.SQLIfNotExists; import org.kar.archidata.annotation.SQLIfNotExists;
import org.kar.archidata.annotation.SQLTableName;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
@SQLTableName ("album") import jakarta.persistence.Table;
@Table(name = "album")
@SQLIfNotExists @SQLIfNotExists
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class Album extends NodeSmall { public class Album extends NodeSmall {

View File

@ -12,30 +12,29 @@ CREATE TABLE `node` (
) AUTO_INCREMENT=10; ) AUTO_INCREMENT=10;
*/ */
import java.sql.Date;
import org.kar.archidata.annotation.SQLIfNotExists; import org.kar.archidata.annotation.SQLIfNotExists;
import org.kar.archidata.annotation.SQLLimitSize;
import org.kar.archidata.annotation.SQLTableName;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import java.sql.Date; import jakarta.persistence.Column;
import jakarta.persistence.Table;
@SQLTableName ("artist") @Table(name = "artist")
@SQLIfNotExists @SQLIfNotExists
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class Artist extends NodeSmall { public class Artist extends NodeSmall {
@SQLLimitSize(256) @Column(length = 256)
public String firstName = null; public String firstName = null;
@SQLLimitSize(256) @Column(length = 256)
public String surname = null; public String surname = null;
public Date birth = null; public Date birth = null;
public Date death = null; public Date death = null;
@Override @Override
public String toString() { public String toString() {
return "Artist [id=" + id + ", name=" + name + ", description=" + description + ", covers=" + covers + return "Artist [id=" + id + ", name=" + name + ", description=" + description + ", covers=" + covers + ", firstName=" + firstName + ", surname=" + surname + ", birth=" + birth + ", death="
", firstName=" + firstName + ", surname=" + surname + ", birth=" + birth + ", death=" + death + "]"; + death + "]";
} }
} }

View File

@ -13,13 +13,14 @@ CREATE TABLE `node` (
*/ */
import org.kar.archidata.annotation.SQLIfNotExists; import org.kar.archidata.annotation.SQLIfNotExists;
import org.kar.archidata.annotation.SQLTableName;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
@SQLTableName ("gender") import jakarta.persistence.Table;
@Table(name = "gender")
@SQLIfNotExists @SQLIfNotExists
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class Gender extends NodeSmall { public class Gender extends NodeSmall {
} }

View File

@ -14,17 +14,20 @@ CREATE TABLE `node` (
import java.util.List; import java.util.List;
import org.kar.archidata.annotation.SQLLimitSize; import org.kar.archidata.model.Data;
import org.kar.archidata.annotation.SQLTableLinkGeneric;
import org.kar.archidata.model.GenericTable; import org.kar.archidata.model.GenericTable;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToMany;
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class NodeSmall extends GenericTable { public class NodeSmall extends GenericTable {
@SQLLimitSize(256) @Column(length = 256)
public String name = null; public String name = null;
public String description = null; public String description = null;
@SQLTableLinkGeneric @ManyToMany(fetch = FetchType.LAZY, targetEntity = Data.class)
public List<Long> covers = null; public List<Long> covers = null;
} }

View File

@ -15,15 +15,17 @@ CREATE TABLE `node` (
import java.util.List; import java.util.List;
import org.kar.archidata.annotation.SQLIfNotExists; import org.kar.archidata.annotation.SQLIfNotExists;
import org.kar.archidata.annotation.SQLTableLinkGeneric;
import org.kar.archidata.annotation.SQLTableName;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
@SQLTableName ("playlist") import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table;
@Table(name = "playlist")
@SQLIfNotExists @SQLIfNotExists
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class Playlist extends NodeSmall { public class Playlist extends NodeSmall {
@SQLTableLinkGeneric @ManyToMany(fetch = FetchType.LAZY, targetEntity = Track.class)
public List<Long> tracks = null; public List<Long> tracks = null;
} }

View File

@ -15,12 +15,14 @@ CREATE TABLE `node` (
import java.util.List; import java.util.List;
import org.kar.archidata.annotation.SQLIfNotExists; import org.kar.archidata.annotation.SQLIfNotExists;
import org.kar.archidata.annotation.SQLTableLinkGeneric;
import org.kar.archidata.annotation.SQLTableName;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
@SQLTableName ("track") import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table;
@Table(name = "track")
@SQLIfNotExists @SQLIfNotExists
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class Track extends NodeSmall { public class Track extends NodeSmall {
@ -28,12 +30,12 @@ public class Track extends NodeSmall {
public Long albumId = null; public Long albumId = null;
public Long track = null; public Long track = null;
public Long dataId = null; public Long dataId = null;
@SQLTableLinkGeneric(SQLTableLinkGeneric.ModelLink.INTERNAL) @ManyToMany(fetch = FetchType.LAZY, targetEntity = Artist.class)
public List<Long> artists = null; public List<Long> artists = null;
@Override @Override
public String toString() { public String toString() {
return "Track [id=" + id + ", deleted=" + deleted + ", create_date=" + create_date + ", modify_date=" return "Track [id=" + id + ", deleted=" + deleted + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + ", name=" + name + ", description=" + description + ", covers=" + covers
+ modify_date + ", name=" + name + ", description=" + description + ", covers=" + covers + ", genderId=" + ", genderId=" + genderId + ", albumId=" + albumId + ", track=" + track + ", dataId=" + dataId + ", artists=" + artists + "]";
+ genderId + ", albumId=" + albumId + ", track=" + track + ", dataId=" + dataId + ", artists=" + artists + "]";
} }
} }

View File

@ -1,12 +1,13 @@
package org.kar.karusic.model; package org.kar.karusic.model;
import org.kar.archidata.annotation.SQLIfNotExists; import org.kar.archidata.annotation.SQLIfNotExists;
import org.kar.archidata.annotation.SQLTableName;
import org.kar.archidata.model.User; import org.kar.archidata.model.User;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
@SQLTableName ("user") import jakarta.persistence.Table;
@Table(name = "user")
@SQLIfNotExists @SQLIfNotExists
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class UserKarusic extends User { public class UserKarusic extends User {

View File

@ -8,15 +8,12 @@ import { BrowserModule } from '@angular/platform-browser';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core'; import { NgModule, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core';
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { HttpClientModule } from '@angular/common/http'; import { HttpClientModule } from '@angular/common/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; // this is needed for dynamic selection of the select
import { AppRoutingModule } from './app-routing.module'; import { AppRoutingModule } from './app-routing.module';
import { AsyncActionStatusComponent, BurgerPropertyComponent, CheckboxComponent, EntryComponent, EntryNumberComponent, EntryValidatorComponent, ErrorComponent, ErrorMessageStateComponent, PasswordEntryComponent, PopInComponent, RenderFormComponent, RenderSettingsComponent, SpinerComponent, TopMenuComponent, UploadFileComponent } from 'common/component/';
import { ElementDataImageComponent } from './component/data-image/data-image'; import { ElementDataImageComponent } from './component/data-image/data-image';
import { ElementTypeComponent } from './component/element-type/element-type'; import { ElementTypeComponent } from './component/element-type/element-type';
import { PopInCreateType } from './popin/create-type/create-type'; import { PopInCreateType } from './popin/create-type/create-type';
import { PopInDeleteConfirm, PopInUploadProgress } from 'common/popin';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { import {
@ -24,16 +21,13 @@ import {
TrackEditScene, AlbumEditScene, ArtistEditScene, ArtistsScene, ArtistAlbumScene TrackEditScene, AlbumEditScene, ArtistEditScene, ArtistsScene, ArtistAlbumScene
} from './scene'; } from './scene';
import { GenderService, DataService, PlaylistService, ArtistService, AlbumService, TrackService, ArianeService, PlayerService } from './service'; import { GenderService, DataService, PlaylistService, ArtistService, AlbumService, TrackService, ArianeService, PlayerService } from './service';
import { BddService, CookiesService, HttpWrapperService, OnlyAdminGuard, OnlyUnregisteredGuardHome, OnlyUsersGuard, OnlyUsersGuardHome, PopInService, SessionService, SSOService, StorageService, UserService } from 'common/service';
import { ErrorViewerScene, ForbiddenScene, HomeOutScene, NotFound404Scene, SsoScene } from 'common/scene';
import { UploadScene } from './scene/upload/upload'; import { UploadScene } from './scene/upload/upload';
import { ElementSeriesComponent, ElementTrackComponent, ElementSeasonComponent, ElementVideoComponent, ElementPlayerAudioComponent } from './component'; import { ElementSeriesComponent, ElementTrackComponent, ElementSeasonComponent, ElementVideoComponent, ElementPlayerAudioComponent } from './component';
import { common_module_declarations, common_module_imports, common_module_providers, common_module_exports } from 'common/module';
@NgModule({ @NgModule({
declarations: [ declarations: [
AppComponent, AppComponent,
TopMenuComponent,
UploadFileComponent,
ElementDataImageComponent, ElementDataImageComponent,
ElementTypeComponent, ElementTypeComponent,
ElementSeriesComponent, ElementSeriesComponent,
@ -41,28 +35,10 @@ import { ElementSeriesComponent, ElementTrackComponent, ElementSeasonComponent,
ElementSeasonComponent, ElementSeasonComponent,
ElementVideoComponent, ElementVideoComponent,
ElementPlayerAudioComponent, ElementPlayerAudioComponent,
ErrorComponent,
PasswordEntryComponent,
EntryComponent,
EntryValidatorComponent,
SpinerComponent,
AsyncActionStatusComponent,
ErrorMessageStateComponent,
CheckboxComponent,
BurgerPropertyComponent,
RenderSettingsComponent,
RenderFormComponent,
EntryNumberComponent,
PopInComponent,
PopInCreateType, PopInCreateType,
PopInUploadProgress,
PopInDeleteConfirm,
HomeScene, HomeScene,
ErrorViewerScene,
HelpScene, HelpScene,
SsoScene,
GenderScene, GenderScene,
PlaylistScene, PlaylistScene,
ArtistAlbumScene, ArtistAlbumScene,
@ -76,28 +52,16 @@ import { ElementSeriesComponent, ElementTrackComponent, ElementSeasonComponent,
AlbumEditScene, AlbumEditScene,
ArtistEditScene, ArtistEditScene,
UploadScene, UploadScene,
ForbiddenScene, ...common_module_declarations,
HomeOutScene,
NotFound404Scene,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
RouterModule, RouterModule,
AppRoutingModule, AppRoutingModule,
HttpClientModule, HttpClientModule,
FormsModule, ...common_module_imports,
ReactiveFormsModule,
], ],
providers: [ providers: [
PopInService,
HttpWrapperService,
SessionService,
CookiesService,
StorageService,
UserService,
SSOService,
BddService,
PlayerService, PlayerService,
GenderService, GenderService,
DataService, DataService,
@ -106,25 +70,16 @@ import { ElementSeriesComponent, ElementTrackComponent, ElementSeasonComponent,
AlbumService, AlbumService,
TrackService, TrackService,
ArianeService, ArianeService,
OnlyUsersGuard, ...common_module_providers,
OnlyAdminGuard,
OnlyUsersGuardHome,
OnlyUnregisteredGuardHome,
], ],
exports: [ exports: [
AppComponent, AppComponent,
TopMenuComponent,
UploadFileComponent,
ErrorComponent,
ElementTypeComponent, ElementTypeComponent,
ElementSeriesComponent, ElementSeriesComponent,
ElementSeasonComponent, ElementSeasonComponent,
ElementVideoComponent, ElementVideoComponent,
PopInCreateType, PopInCreateType,
...common_module_exports,
PopInComponent,
PopInUploadProgress,
PopInDeleteConfirm,
], ],
bootstrap: [ bootstrap: [
AppComponent AppComponent

View File

@ -9,7 +9,7 @@ import { isMedia, Media } from 'app/model';
import { NodeData } from 'common/model'; import { NodeData } from 'common/model';
import { HttpWrapperService, BddService } from 'common/service'; import { HttpWrapperService, BddService } from 'common/service';
import { DataInterface, isArrayOf, TypeCheck } from 'common/utils'; import { DataInterface, isArrayOf, isNullOrUndefined, TypeCheck } from 'common/utils';
import { GenericInterfaceModelDB } from './GenericInterfaceModelDB'; import { GenericInterfaceModelDB } from './GenericInterfaceModelDB';
@Injectable() @Injectable()
@ -19,7 +19,7 @@ export class TrackService extends GenericInterfaceModelDB {
bdd: BddService) { bdd: BddService) {
super('track', http, bdd); super('track', http, bdd);
} }
get(id:number): Promise<Media> { get(id: number): Promise<Media> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
super.get(id).then((data: NodeData) => { super.get(id).then((data: NodeData) => {
if (isMedia(data)) { if (isMedia(data)) {
@ -28,7 +28,7 @@ export class TrackService extends GenericInterfaceModelDB {
} }
reject("model is wrong !!!") reject("model is wrong !!!")
return return
}).catch((reason:any) => { }).catch((reason: any) => {
reject(reason); reject(reason);
}); });
}); });
@ -39,13 +39,13 @@ export class TrackService extends GenericInterfaceModelDB {
self.bdd.get(self.serviceName) self.bdd.get(self.serviceName)
.then((response: DataInterface) => { .then((response: DataInterface) => {
let data = response.getsWhere([ let data = response.getsWhere([
{ {
check: TypeCheck.EQUAL, check: TypeCheck.EQUAL,
key: 'albumId', key: 'albumId',
value: idAlbum, value: idAlbum,
}, },
], ],
[ 'track', 'name', 'id' ]); ['track', 'name', 'id']);
if (isArrayOf(data, isMedia)) { if (isArrayOf(data, isMedia)) {
resolve(data); resolve(data);
return; return;
@ -57,7 +57,7 @@ export class TrackService extends GenericInterfaceModelDB {
}); });
}); });
} }
getData(): Promise<Media[]> { getData(): Promise<Media[]> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -68,49 +68,49 @@ export class TrackService extends GenericInterfaceModelDB {
} }
reject("model is wrong !!!") reject("model is wrong !!!")
return return
}).catch((reason:any) => { }).catch((reason: any) => {
reject(reason); reject(reason);
}); });
}); });
} }
uploadFile(file:File,
gender?:string,
artist?:string,
album?:string,
trackId?:number,
title?:string,
progress:any = null) {
const formData = new FormData();
formData.append('fileName', file.name);
// set the file at hte begining it will permit to abort the transmission
formData.append('file', file?? null);
formData.append('gender', gender?? null);
formData.append('artist', artist?? null);
formData.append('album', album?? null);
if(trackId !== null) {
formData.append('trackId', trackId.toString());
} else {
formData.append('trackId', null);
}
formData.append('title', title?? null);
return this.http.uploadMultipart(`${this.serviceName }/upload/`, formData, progress); uploadFile(file: File,
gender?: string,
artist?: string,
album?: string,
trackId?: number,
title?: string,
progress: any = null) {
const formData = new FormData();
formData.append('fileName', file.name);
// set the file at hte begining it will permit to abort the transmission
formData.append('file', file ?? null);
formData.append('gender', gender ?? null);
formData.append('artist', artist ?? null);
formData.append('album', album ?? null);
if (!isNullOrUndefined(trackId)) {
formData.append('trackId', trackId.toString());
} else {
formData.append('trackId', null);
}
formData.append('title', title ?? null);
return this.http.uploadMultipart(`${this.serviceName}/upload/`, formData, progress);
} }
uploadCoverBlob(blob:Blob, uploadCoverBlob(blob: Blob,
mediaId:number, mediaId: number,
progress:any = null) { progress: any = null) {
const formData = new FormData(); const formData = new FormData();
formData.append('fileName', 'take_screenshoot'); formData.append('fileName', 'take_screenshoot');
formData.append('typeId', mediaId.toString()); formData.append('typeId', mediaId.toString());
formData.append('file', blob); formData.append('file', blob);
let self = this; let self = this;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
self.http.uploadMultipart(`${this.serviceName }/${ mediaId }/add_cover/`, formData, progress) self.http.uploadMultipart(`${this.serviceName}/${mediaId}/add_cover/`, formData, progress)
.then((response) => { .then((response) => {
let data = response; let data = response;
if(data === null || data === undefined) { if (data === null || data === undefined) {
reject('error retrive data from server'); reject('error retrive data from server');
return; return;
} }

@ -1 +1 @@
Subproject commit 9fc25b4feaeba509ff39f70b24d97be47f4b30e1 Subproject commit ea5a4f6b7537eb707916f4610bf79fbe86c6296f