[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>
<groupId>kangaroo-and-rabbit</groupId>
<artifactId>archidata</artifactId>
<version>0.3.7</version>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>

View File

@ -1,96 +1,99 @@
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.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")
@Produces({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON })
public class AlbumResource {
@GET
@Path("{id}")
@RolesAllowed("USER")
public static Album getWithId(@PathParam("id") Long id) throws Exception {
return SqlWrapper.get(Album.class, id);
}
@GET
@RolesAllowed("USER")
public List<Album> get() throws Exception {
return SqlWrapper.gets(Album.class, false);
}
@POST
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Album post(String jsonRequest) throws Exception {
return SqlWrapper.insertWithJson(Album.class, jsonRequest);
}
@PUT
@Path("{id}")
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Album put(@PathParam("id") Long id, String jsonRequest) throws Exception {
SqlWrapper.update(Album.class, id, jsonRequest);
return SqlWrapper.get(Album.class, id);
}
@DELETE
@Path("{id}")
@RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.setDelete(Album.class, id);
return Response.ok().build();
}
@POST
@Path("{id}/add_track/{trackId}")
@RolesAllowed("ADMIN")
@Consumes({MediaType.MULTIPART_FORM_DATA})
public Album addTrack(@PathParam("id") Long id,@PathParam("trackId") Long trackId) throws Exception {
SqlWrapper.removeLink(Album.class, id, "track", trackId);
return SqlWrapper.get(Album.class, id);
}
@GET
@Path("{id}/rm_track/{trackId}")
@RolesAllowed("ADMIN")
public Album removeTrack(@PathParam("id") Long id, @PathParam("trackId") Long trackId) throws Exception {
SqlWrapper.removeLink(Album.class, id, "track", trackId);
return SqlWrapper.get(Album.class, id);
}
@POST
@Path("{id}/add_cover")
@RolesAllowed("ADMIN")
@Consumes({MediaType.MULTIPART_FORM_DATA})
public Response uploadCover(@PathParam("id") Long id,
@FormDataParam("fileName") String fileName,
@FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData
) {
return DataTools.uploadCover(Album.class, id, fileName, fileInputStream, fileMetaData);
}
@GET
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
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();
}
@GET
@Path("{id}")
@RolesAllowed("USER")
public static Album getWithId(@PathParam("id") Long id) throws Exception {
return SqlWrapper.get(Album.class, id);
}
@GET
@RolesAllowed("USER")
public List<Album> get() throws Exception {
return SqlWrapper.gets(Album.class);
}
@POST
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Album post(String jsonRequest) throws Exception {
return SqlWrapper.insertWithJson(Album.class, jsonRequest);
}
@PUT
@Path("{id}")
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Album put(@PathParam("id") Long id, String jsonRequest) throws Exception {
SqlWrapper.update(Album.class, id, jsonRequest);
return SqlWrapper.get(Album.class, id);
}
@DELETE
@Path("{id}")
@RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.delete(Album.class, id);
return Response.ok().build();
}
@POST
@Path("{id}/add_track/{trackId}")
@RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
public Album addTrack(@PathParam("id") Long id, @PathParam("trackId") Long trackId) throws Exception {
AddOnManyToMany.removeLink(Album.class, id, "track", trackId);
return SqlWrapper.get(Album.class, id);
}
@GET
@Path("{id}/rm_track/{trackId}")
@RolesAllowed("ADMIN")
public Album removeTrack(@PathParam("id") Long id, @PathParam("trackId") Long trackId) throws Exception {
AddOnManyToMany.removeLink(Album.class, id, "track", trackId);
return SqlWrapper.get(Album.class, id);
}
@POST
@Path("{id}/add_cover")
@RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData) {
return DataTools.uploadCover(Album.class, id, fileName, fileInputStream, fileMetaData);
}
@GET
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
AddOnManyToMany.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;
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.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")
@Produces({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON })
public class ArtistResource {
@GET
@Path("{id}")
@RolesAllowed("USER")
public static Artist getWithId(@PathParam("id") Long id) throws Exception {
return SqlWrapper.get(Artist.class, id);
}
@GET
@RolesAllowed("USER")
public List<Artist> get() throws Exception {
return SqlWrapper.gets(Artist.class, false);
}
@POST
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Artist put(String jsonRequest) throws Exception {
return SqlWrapper.insertWithJson(Artist.class, jsonRequest);
}
@PUT
@Path("{id}")
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Artist put(@PathParam("id") Long id, String jsonRequest) throws Exception {
SqlWrapper.update(Artist.class, id, jsonRequest);
return SqlWrapper.get(Artist.class, id);
}
@DELETE
@Path("{id}")
@RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.setDelete(Artist.class, id);
return Response.ok().build();
}
@POST
@Path("{id}/add_cover")
@RolesAllowed("ADMIN")
@Consumes({MediaType.MULTIPART_FORM_DATA})
public Response uploadCover(@PathParam("id") Long id,
@FormDataParam("fileName") String fileName,
@FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData
) {
return DataTools.uploadCover(Artist.class, id, fileName, fileInputStream, fileMetaData);
}
@GET
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
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();
}
@GET
@Path("{id}")
@RolesAllowed("USER")
public static Artist getWithId(@PathParam("id") Long id) throws Exception {
return SqlWrapper.get(Artist.class, id);
}
@GET
@RolesAllowed("USER")
public List<Artist> get() throws Exception {
return SqlWrapper.gets(Artist.class);
}
@POST
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Artist put(String jsonRequest) throws Exception {
return SqlWrapper.insertWithJson(Artist.class, jsonRequest);
}
@PUT
@Path("{id}")
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Artist put(@PathParam("id") Long id, String jsonRequest) throws Exception {
SqlWrapper.update(Artist.class, id, jsonRequest);
return SqlWrapper.get(Artist.class, id);
}
@DELETE
@Path("{id}")
@RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.delete(Artist.class, id);
return Response.ok().build();
}
@POST
@Path("{id}/add_cover")
@RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData) {
return DataTools.uploadCover(Artist.class, id, fileName, fileInputStream, fileMetaData);
}
@GET
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
AddOnManyToMany.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;
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.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")
@Produces({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON })
public class GenderResource {
@GET
@Path("{id}")
@RolesAllowed("USER")
public static Gender getWithId(@PathParam("id") Long id) throws Exception {
return SqlWrapper.get(Gender.class, id);
}
@GET
@RolesAllowed("USER")
public List<Gender> get() throws Exception {
return SqlWrapper.gets(Gender.class, false);
}
@POST
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Gender put(String jsonRequest) throws Exception {
return SqlWrapper.insertWithJson(Gender.class, jsonRequest);
}
@PUT
@Path("{id}")
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Gender put(@PathParam("id") Long id, String jsonRequest) throws Exception {
SqlWrapper.update(Gender.class, id, jsonRequest);
return SqlWrapper.get(Gender.class, id);
}
@DELETE
@Path("{id}")
@RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.setDelete(Gender.class, id);
return Response.ok().build();
}
@POST
@Path("{id}/add_cover")
@RolesAllowed("ADMIN")
@Consumes({MediaType.MULTIPART_FORM_DATA})
public Response uploadCover(@PathParam("id") Long id,
@FormDataParam("fileName") String fileName,
@FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData
) {
return DataTools.uploadCover(Gender.class, id, fileName, fileInputStream, fileMetaData);
}
@GET
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
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();
}
@GET
@Path("{id}")
@RolesAllowed("USER")
public static Gender getWithId(@PathParam("id") Long id) throws Exception {
return SqlWrapper.get(Gender.class, id);
}
@GET
@RolesAllowed("USER")
public List<Gender> get() throws Exception {
return SqlWrapper.gets(Gender.class);
}
@POST
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Gender put(String jsonRequest) throws Exception {
return SqlWrapper.insertWithJson(Gender.class, jsonRequest);
}
@PUT
@Path("{id}")
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Gender put(@PathParam("id") Long id, String jsonRequest) throws Exception {
SqlWrapper.update(Gender.class, id, jsonRequest);
return SqlWrapper.get(Gender.class, id);
}
@DELETE
@Path("{id}")
@RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.delete(Gender.class, id);
return Response.ok().build();
}
@POST
@Path("{id}/add_cover")
@RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData) {
return DataTools.uploadCover(Gender.class, id, fileName, fileInputStream, fileMetaData);
}
@GET
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
AddOnManyToMany.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;
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.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")
@Produces({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON })
public class PlaylistResource {
@GET
@Path("{id}")
@RolesAllowed("USER")
public static Playlist getWithId(@PathParam("id") Long id) throws Exception {
return SqlWrapper.get(Playlist.class, id);
}
@GET
@RolesAllowed("USER")
public List<Playlist> get() throws Exception {
return SqlWrapper.gets(Playlist.class, false);
}
@POST
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Playlist put(String jsonRequest) throws Exception {
return SqlWrapper.insertWithJson(Playlist.class, jsonRequest);
}
@PUT
@Path("{id}")
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Playlist put(@PathParam("id") Long id, String jsonRequest) throws Exception {
SqlWrapper.update(Playlist.class, id, jsonRequest);
return SqlWrapper.get(Playlist.class, id);
}
@DELETE
@Path("{id}")
@RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.setDelete(Playlist.class, id);
return Response.ok().build();
}
@POST
@Path("{id}/add_track/{trackId}")
@RolesAllowed("ADMIN")
@Consumes({MediaType.MULTIPART_FORM_DATA})
public Playlist addTrack(@PathParam("id") Long id,@PathParam("trackId") Long trackId) throws Exception {
SqlWrapper.removeLink(Playlist.class, id, "track", trackId);
return SqlWrapper.get(Playlist.class, id);
}
@GET
@Path("{id}/rm_track/{trackId}")
@RolesAllowed("ADMIN")
public Playlist removeTrack(@PathParam("id") Long id, @PathParam("trackId") Long trackId) throws Exception {
SqlWrapper.removeLink(Playlist.class, id, "track", trackId);
return SqlWrapper.get(Playlist.class, id);
}
@POST
@Path("{id}/add_cover")
@RolesAllowed("ADMIN")
@Consumes({MediaType.MULTIPART_FORM_DATA})
public Response uploadCover(@PathParam("id") Long id,
@FormDataParam("fileName") String fileName,
@FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData
) {
return DataTools.uploadCover(Playlist.class, id, fileName, fileInputStream, fileMetaData);
}
@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();
}
@GET
@Path("{id}")
@RolesAllowed("USER")
public static Playlist getWithId(@PathParam("id") Long id) throws Exception {
return SqlWrapper.get(Playlist.class, id);
}
@GET
@RolesAllowed("USER")
public List<Playlist> get() throws Exception {
return SqlWrapper.gets(Playlist.class);
}
@POST
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Playlist put(String jsonRequest) throws Exception {
return SqlWrapper.insertWithJson(Playlist.class, jsonRequest);
}
@PUT
@Path("{id}")
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Playlist put(@PathParam("id") Long id, String jsonRequest) throws Exception {
SqlWrapper.update(Playlist.class, id, jsonRequest);
return SqlWrapper.get(Playlist.class, id);
}
@DELETE
@Path("{id}")
@RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.delete(Playlist.class, id);
return Response.ok().build();
}
@POST
@Path("{id}/add_track/{trackId}")
@RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
public Playlist addTrack(@PathParam("id") Long id, @PathParam("trackId") Long trackId) throws Exception {
AddOnManyToMany.removeLink(Playlist.class, id, "track", trackId);
return SqlWrapper.get(Playlist.class, id);
}
@GET
@Path("{id}/rm_track/{trackId}")
@RolesAllowed("ADMIN")
public Playlist removeTrack(@PathParam("id") Long id, @PathParam("trackId") Long trackId) throws Exception {
AddOnManyToMany.removeLink(Playlist.class, id, "track", trackId);
return SqlWrapper.get(Playlist.class, id);
}
@POST
@Path("{id}/add_cover")
@RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData) {
return DataTools.uploadCover(Playlist.class, id, fileName, fileInputStream, fileMetaData);
}
@GET
@Path("{id}/rm_cover/{coverId}")
@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();
}
}

View File

@ -1,249 +1,239 @@
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.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
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")
@Produces({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON })
public class TrackResource {
@GET
@Path("{id}")
@RolesAllowed("USER")
public static Track getWithId(@PathParam("id") Long id) throws Exception {
return SqlWrapper.get(Track.class, id);
}
@GET
@RolesAllowed("USER")
public List<Track> get() throws Exception {
return SqlWrapper.gets(Track.class, false);
}
@POST
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Track create(String jsonRequest) throws Exception {
return SqlWrapper.insertWithJson(Track.class, jsonRequest);
}
@PUT
@Path("{id}")
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Track put(@PathParam("id") Long id, String jsonRequest) throws Exception {
SqlWrapper.update(Track.class, id, jsonRequest);
return SqlWrapper.get(Track.class, id);
}
@DELETE
@Path("{id}")
@RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.setDelete(Track.class, id);
return Response.ok().build();
}
@POST
@Path("{id}/add_artist/{artistId}")
@RolesAllowed("ADMIN")
@Consumes({MediaType.MULTIPART_FORM_DATA})
public Track addTrack(@PathParam("id") Long id,@PathParam("artistId") Long artistId) throws Exception {
SqlWrapper.removeLink(Track.class, id, "artist", artistId);
return SqlWrapper.get(Track.class, id);
}
@GET
@Path("{id}/rm_artist/{trackId}")
@RolesAllowed("ADMIN")
public Track removeTrack(@PathParam("id") Long id, @PathParam("artistId") Long artistId) throws Exception {
SqlWrapper.removeLink(Track.class, id, "artist", artistId);
return SqlWrapper.get(Track.class, id);
}
@POST
@Path("{id}/add_cover")
@RolesAllowed("ADMIN")
@Consumes({MediaType.MULTIPART_FORM_DATA})
public Response uploadCover(@PathParam("id") Long id,
@FormDataParam("fileName") String fileName,
@FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData
) {
return DataTools.uploadCover(Track.class, id, fileName, fileInputStream, fileMetaData);
}
@GET
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
SqlWrapper.removeLink(Track.class, id, "cover", coverId);
return Response.ok(SqlWrapper.get(Track.class, id)).build();
}
@POST
@Path("/upload/")
@RolesAllowed("ADMIN")
@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
) {
try {
// correct input string stream :
fileName = DataTools.multipartCorrection(fileName);
gender = DataTools.multipartCorrection(gender);
artist = DataTools.multipartCorrection(artist);
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);
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();
/*
if (typeId == null) {
return Response.status(406).
entity("Missong Input 'type'").
type("text/plain").
build();
}
*/
long tmpUID = DataTools.getTmpDataId();
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();
try {
data = DataTools.createNewData(tmpUID, fileName, sha512);
} catch (IOException ex) {
DataTools.removeTemporaryFile(tmpUID);
ex.printStackTrace();
return Response.notModified("can not create input media").build();
} catch (SQLException ex) {
ex.printStackTrace();
DataTools.removeTemporaryFile(tmpUID);
return Response.notModified("Error in SQL insertion ...").build();
}
} else if (data.deleted == true) {
System.out.println("Data already exist but deleted");
System.out.flush();
DataTools.undelete(data.id);
data.deleted = false;
} else {
System.out.println("Data already exist ... all good");
System.out.flush();
}
// Fist step: retrieve all the Id of each parents:...
System.out.println("Find typeNode");
Gender genderElem = null;
if (gender != null) {
genderElem = SqlWrapper.getWith(Gender.class, "name", gender);
if (genderElem == null) {
genderElem = new Gender();
genderElem.name = gender;
genderElem = SqlWrapper.insert(genderElem);
}
}
// NodeSmall typeNode = TypeResource.getWithId(Long.parseLong(typeId));
// if (typeNode == null) {
// DataTools.removeTemporaryFile(tmpUID);
// return Response.notModified("TypeId does not exist ...").build();
// }
System.out.println(" ==> " + genderElem);
Artist artistElem = null;
if (artist != null) {
artistElem = SqlWrapper.getWith(Artist.class, "name", artist);
if (artistElem == null){
artistElem = new Artist();
artistElem.name = artist;
artistElem = SqlWrapper.insert(artistElem);
}
}
System.out.println(" ==> " + artistElem);
Album albumElem = null;
if (album != null) {
albumElem = SqlWrapper.getWith(Album.class, "name", album);
if (albumElem == null) {
albumElem = new Album();
albumElem.name = album;
albumElem = SqlWrapper.insert(albumElem);
}
}
System.out.println(" ==> " + album);
System.out.println("add media");
Track trackElem = new Track();
trackElem.name = title;
trackElem.track = trackId!=null?Long.parseLong(trackId):null;
trackElem.albumId = albumElem!=null?albumElem.id:null;
trackElem.genderId = genderElem!=null?genderElem.id:null;
trackElem.dataId = data.id;
// Now list of artis has an internal management:
if (artistElem != null) {
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();
}
}
@GET
@Path("{id}")
@RolesAllowed("USER")
public static Track getWithId(@PathParam("id") Long id) throws Exception {
return SqlWrapper.get(Track.class, id);
}
@GET
@RolesAllowed("USER")
public List<Track> get() throws Exception {
return SqlWrapper.gets(Track.class);
}
@POST
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Track create(String jsonRequest) throws Exception {
return SqlWrapper.insertWithJson(Track.class, jsonRequest);
}
@PUT
@Path("{id}")
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
public Track put(@PathParam("id") Long id, String jsonRequest) throws Exception {
SqlWrapper.update(Track.class, id, jsonRequest);
return SqlWrapper.get(Track.class, id);
}
@DELETE
@Path("{id}")
@RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.delete(Track.class, id);
return Response.ok().build();
}
@POST
@Path("{id}/add_artist/{artistId}")
@RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
public Track addTrack(@PathParam("id") Long id, @PathParam("artistId") Long artistId) throws Exception {
AddOnManyToMany.removeLink(Track.class, id, "artist", artistId);
return SqlWrapper.get(Track.class, id);
}
@GET
@Path("{id}/rm_artist/{trackId}")
@RolesAllowed("ADMIN")
public Track removeTrack(@PathParam("id") Long id, @PathParam("artistId") Long artistId) throws Exception {
AddOnManyToMany.removeLink(Track.class, id, "artist", artistId);
return SqlWrapper.get(Track.class, id);
}
@POST
@Path("{id}/add_cover")
@RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData) {
return DataTools.uploadCover(Track.class, id, fileName, fileInputStream, fileMetaData);
}
@GET
@Path("{id}/rm_cover/{coverId}")
@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();
}
@POST
@Path("/upload/")
@RolesAllowed("ADMIN")
@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) {
try {
// correct input string stream :
fileName = DataTools.multipartCorrection(fileName);
gender = DataTools.multipartCorrection(gender);
artist = DataTools.multipartCorrection(artist);
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);
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();
/*
if (typeId == null) {
return Response.status(406).
entity("Missong Input 'type'").
type("text/plain").
build();
}
*/
long tmpUID = DataTools.getTmpDataId();
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();
try {
data = DataTools.createNewData(tmpUID, fileName, sha512);
} catch (IOException ex) {
DataTools.removeTemporaryFile(tmpUID);
ex.printStackTrace();
return Response.notModified("can not create input media").build();
} catch (SQLException ex) {
ex.printStackTrace();
DataTools.removeTemporaryFile(tmpUID);
return Response.notModified("Error in SQL insertion ...").build();
}
} else if (data.deleted == true) {
System.out.println("Data already exist but deleted");
System.out.flush();
DataTools.undelete(data.id);
data.deleted = false;
} else {
System.out.println("Data already exist ... all good");
System.out.flush();
}
// Fist step: retrieve all the Id of each parents:...
System.out.println("Find typeNode");
Gender genderElem = null;
if (gender != null) {
genderElem = SqlWrapper.getWhere(Gender.class, new QuerryCondition("name", "=", gender));
if (genderElem == null) {
genderElem = new Gender();
genderElem.name = gender;
genderElem = SqlWrapper.insert(genderElem);
}
}
// NodeSmall typeNode = TypeResource.getWithId(Long.parseLong(typeId));
// if (typeNode == null) {
// DataTools.removeTemporaryFile(tmpUID);
// return Response.notModified("TypeId does not exist ...").build();
// }
System.out.println(" ==> " + genderElem);
Artist artistElem = null;
if (artist != null) {
artistElem = SqlWrapper.getWhere(Artist.class, new QuerryCondition("name", "=", artist));
if (artistElem == null) {
artistElem = new Artist();
artistElem.name = artist;
artistElem = SqlWrapper.insert(artistElem);
}
}
System.out.println(" ==> " + artistElem);
Album albumElem = null;
if (album != null) {
albumElem = SqlWrapper.getWhere(Album.class, new QuerryCondition("name", "=", album));
if (albumElem == null) {
albumElem = new Album();
albumElem.name = album;
albumElem = SqlWrapper.insert(albumElem);
}
}
System.out.println(" ==> " + album);
System.out.println("add media");
Track trackElem = new Track();
trackElem.name = title;
trackElem.track = trackId != null ? Long.parseLong(trackId) : null;
trackElem.albumId = albumElem != null ? albumElem.id : null;
trackElem.genderId = genderElem != null ? genderElem.id : null;
trackElem.dataId = data.id;
// Now list of artis has an internal management:
if (artistElem != null) {
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;
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.sqlWrapper.SqlWrapper;
import org.kar.karusic.model.UserKarusic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.annotation.JsonInclude;
import org.kar.archidata.annotation.security.RolesAllowed;
import jakarta.ws.rs.*;
import jakarta.ws.rs.GET;
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.MediaType;
import jakarta.ws.rs.core.SecurityContext;
import java.util.List;
@Path("/users")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public class UserResource {
final Logger logger = LoggerFactory.getLogger(UserResource.class);
@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserOut {
public long id;
public String login;
public UserOut(long id, String login) {
super();
this.id = id;
@ -32,83 +36,49 @@ public class UserResource {
}
}
public UserResource() {
}
// curl http://localhost:9993/api/users
@GET
@RolesAllowed("ADMIN")
public List<UserKarusic> getUsers() {
System.out.println("getUsers");
try {
return SqlWrapper.gets(UserKarusic.class, false);
public UserResource() {}
// curl http://localhost:9993/api/users
@GET
@RolesAllowed("ADMIN")
public List<UserKarusic> getUsers() {
System.out.println("getUsers");
try {
return SqlWrapper.gets(UserKarusic.class);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
// curl http://localhost:9993/api/users/3
@GET
@Path("{id}")
@RolesAllowed("ADMIN")
public UserKarusic getUsers(@Context SecurityContext sc, @PathParam("id") long userId) {
System.out.println("getUser " + userId);
GenericContext gc = (GenericContext) sc.getUserPrincipal();
System.out.println("===================================================");
System.out.println("== USER ? " + gc.userByToken.name);
System.out.println("===================================================");
try {
}
// curl http://localhost:9993/api/users/3
@GET
@Path("{id}")
@RolesAllowed("ADMIN")
public UserKarusic getUsers(@Context SecurityContext sc, @PathParam("id") long userId) {
System.out.println("getUser " + userId);
GenericContext gc = (GenericContext) sc.getUserPrincipal();
System.out.println("===================================================");
System.out.println("== USER ? " + gc.userByToken.name);
System.out.println("===================================================");
try {
return SqlWrapper.get(UserKarusic.class, userId);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@GET
@Path("me")
@RolesAllowed("USER")
public UserOut getMe(@Context SecurityContext sc) {
logger.debug("getMe()");
GenericContext gc = (GenericContext) sc.getUserPrincipal();
logger.debug("== USER ? {}", gc.userByToken);
return new UserOut(gc.userByToken.id, gc.userByToken.name);
}
return null;
}
@GET
@Path("me")
@RolesAllowed("USER")
public UserOut getMe(@Context SecurityContext sc) {
logger.debug("getMe()");
GenericContext gc = (GenericContext) sc.getUserPrincipal();
logger.debug("== USER ? {}", gc.userByToken);
return new UserOut(gc.userByToken.id, gc.userByToken.name);
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,12 +1,13 @@
package org.kar.karusic.model;
import org.kar.archidata.annotation.SQLIfNotExists;
import org.kar.archidata.annotation.SQLTableName;
import org.kar.archidata.model.User;
import com.fasterxml.jackson.annotation.JsonInclude;
@SQLTableName ("user")
import jakarta.persistence.Table;
@Table(name = "user")
@SQLIfNotExists
@JsonInclude(JsonInclude.Include.NON_NULL)
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 { RouterModule } from '@angular/router';
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 { 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 { ElementTypeComponent } from './component/element-type/element-type';
import { PopInCreateType } from './popin/create-type/create-type';
import { PopInDeleteConfirm, PopInUploadProgress } from 'common/popin';
import { AppComponent } from './app.component';
import {
@ -24,16 +21,13 @@ import {
TrackEditScene, AlbumEditScene, ArtistEditScene, ArtistsScene, ArtistAlbumScene
} from './scene';
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 { ElementSeriesComponent, ElementTrackComponent, ElementSeasonComponent, ElementVideoComponent, ElementPlayerAudioComponent } from './component';
import { common_module_declarations, common_module_imports, common_module_providers, common_module_exports } from 'common/module';
@NgModule({
declarations: [
AppComponent,
TopMenuComponent,
UploadFileComponent,
ElementDataImageComponent,
ElementTypeComponent,
ElementSeriesComponent,
@ -41,28 +35,10 @@ import { ElementSeriesComponent, ElementTrackComponent, ElementSeasonComponent,
ElementSeasonComponent,
ElementVideoComponent,
ElementPlayerAudioComponent,
ErrorComponent,
PasswordEntryComponent,
EntryComponent,
EntryValidatorComponent,
SpinerComponent,
AsyncActionStatusComponent,
ErrorMessageStateComponent,
CheckboxComponent,
BurgerPropertyComponent,
RenderSettingsComponent,
RenderFormComponent,
EntryNumberComponent,
PopInComponent,
PopInCreateType,
PopInUploadProgress,
PopInDeleteConfirm,
HomeScene,
ErrorViewerScene,
HelpScene,
SsoScene,
GenderScene,
PlaylistScene,
ArtistAlbumScene,
@ -76,28 +52,16 @@ import { ElementSeriesComponent, ElementTrackComponent, ElementSeasonComponent,
AlbumEditScene,
ArtistEditScene,
UploadScene,
ForbiddenScene,
HomeOutScene,
NotFound404Scene,
...common_module_declarations,
],
imports: [
BrowserModule,
RouterModule,
AppRoutingModule,
HttpClientModule,
FormsModule,
ReactiveFormsModule,
...common_module_imports,
],
providers: [
PopInService,
HttpWrapperService,
SessionService,
CookiesService,
StorageService,
UserService,
SSOService,
BddService,
PlayerService,
GenderService,
DataService,
@ -106,25 +70,16 @@ import { ElementSeriesComponent, ElementTrackComponent, ElementSeasonComponent,
AlbumService,
TrackService,
ArianeService,
OnlyUsersGuard,
OnlyAdminGuard,
OnlyUsersGuardHome,
OnlyUnregisteredGuardHome,
...common_module_providers,
],
exports: [
AppComponent,
TopMenuComponent,
UploadFileComponent,
ErrorComponent,
ElementTypeComponent,
ElementSeriesComponent,
ElementSeasonComponent,
ElementVideoComponent,
PopInCreateType,
PopInComponent,
PopInUploadProgress,
PopInDeleteConfirm,
...common_module_exports,
],
bootstrap: [
AppComponent

View File

@ -9,7 +9,7 @@ import { isMedia, Media } from 'app/model';
import { NodeData } from 'common/model';
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';
@Injectable()
@ -19,7 +19,7 @@ export class TrackService extends GenericInterfaceModelDB {
bdd: BddService) {
super('track', http, bdd);
}
get(id:number): Promise<Media> {
get(id: number): Promise<Media> {
return new Promise((resolve, reject) => {
super.get(id).then((data: NodeData) => {
if (isMedia(data)) {
@ -28,7 +28,7 @@ export class TrackService extends GenericInterfaceModelDB {
}
reject("model is wrong !!!")
return
}).catch((reason:any) => {
}).catch((reason: any) => {
reject(reason);
});
});
@ -39,13 +39,13 @@ export class TrackService extends GenericInterfaceModelDB {
self.bdd.get(self.serviceName)
.then((response: DataInterface) => {
let data = response.getsWhere([
{
check: TypeCheck.EQUAL,
key: 'albumId',
value: idAlbum,
},
],
[ 'track', 'name', 'id' ]);
{
check: TypeCheck.EQUAL,
key: 'albumId',
value: idAlbum,
},
],
['track', 'name', 'id']);
if (isArrayOf(data, isMedia)) {
resolve(data);
return;
@ -57,7 +57,7 @@ export class TrackService extends GenericInterfaceModelDB {
});
});
}
getData(): Promise<Media[]> {
return new Promise((resolve, reject) => {
@ -68,49 +68,49 @@ export class TrackService extends GenericInterfaceModelDB {
}
reject("model is wrong !!!")
return
}).catch((reason:any) => {
}).catch((reason: any) => {
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,
mediaId:number,
progress:any = null) {
uploadCoverBlob(blob: Blob,
mediaId: number,
progress: any = null) {
const formData = new FormData();
formData.append('fileName', 'take_screenshoot');
formData.append('typeId', mediaId.toString());
formData.append('file', blob);
let self = this;
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) => {
let data = response;
if(data === null || data === undefined) {
if (data === null || data === undefined) {
reject('error retrive data from server');
return;
}

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