[DEV] update new JPA

This commit is contained in:
Edouard DUPIN 2023-10-15 23:37:58 +02:00
parent 0ee08ac7e5
commit 9c8def3341
16 changed files with 855 additions and 817 deletions

View File

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

View File

@ -1,16 +1,12 @@
package org.kar.karideo;
import org.glassfish.grizzly.http.server.HttpServer;
import java.net.URI;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.kar.karideo.api.*;
import org.kar.karideo.filter.KarideoAuthenticationFilter;
import org.kar.karideo.migration.Initialization;
import org.kar.karideo.migration.Migration20230810;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.kar.archidata.GlobalConfiguration;
import org.kar.archidata.UpdateJwtPublicKey;
import org.kar.archidata.api.DataResource;
@ -23,15 +19,28 @@ import org.kar.archidata.filter.CORSFilter;
import org.kar.archidata.filter.OptionFilter;
import org.kar.archidata.migration.MigrationEngine;
import org.kar.archidata.util.ConfigBaseVariable;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.kar.karideo.api.Front;
import org.kar.karideo.api.HealthCheck;
import org.kar.karideo.api.SeasonResource;
import org.kar.karideo.api.SeriesResource;
import org.kar.karideo.api.TypeResource;
import org.kar.karideo.api.UserMediaAdvancementResource;
import org.kar.karideo.api.UserResource;
import org.kar.karideo.api.VideoResource;
import org.kar.karideo.filter.KarideoAuthenticationFilter;
import org.kar.karideo.migration.Initialization;
import org.kar.karideo.migration.Migration20230810;
import org.kar.karideo.migration.Migration20231015;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.core.UriBuilder;
import java.net.URI;
public class WebLauncher {
final static Logger LOGGER = LoggerFactory.getLogger(WebLauncher.class);
public static DBConfig dbConfig;
protected UpdateJwtPublicKey keyUpdater = null;
public WebLauncher() {
ConfigBaseVariable.bdDatabase = "karideo";
}
@ -47,6 +56,7 @@ public class WebLauncher {
migrationEngine.setInit(new Initialization());
WebLauncher.LOGGER.info("Add migration since last version");
migrationEngine.add(new Migration20230810());
migrationEngine.add(new Migration20231015());
WebLauncher.LOGGER.info("Migrate the DB [START]");
migrationEngine.migrate(GlobalConfiguration.dbConfig);
WebLauncher.LOGGER.info("Migrate the DB [STOP]");
@ -64,7 +74,6 @@ public class WebLauncher {
WebLauncher.LOGGER.info("STOP the REST server");
}
public void process() throws InterruptedException {
// ===================================================================
@ -111,7 +120,6 @@ public class WebLauncher {
}
}, "shutdownHook"));
// ===================================================================
// start periodic update of the token ...
// ===================================================================

View File

@ -1,22 +1,33 @@
package org.kar.karideo.api;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.karideo.model.Season;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.kar.archidata.SqlWrapper;
import org.kar.archidata.annotation.security.RolesAllowed;
import org.kar.archidata.util.DataTools;
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.QuerryAnd;
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.karideo.model.Season;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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("/season")
@Produces({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON })
public class SeasonResource {
static final Logger LOGGER = LoggerFactory.getLogger(SeasonResource.class);
@ -30,7 +41,7 @@ public class SeasonResource {
@GET
@RolesAllowed("USER")
public List<Season> get() throws Exception {
return SqlWrapper.gets(Season.class, false);
return SqlWrapper.gets(Season.class);
}
@GET
@ -65,19 +76,16 @@ public class SeasonResource {
@Path("{id}")
@RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.setDelete(Season.class, id);
SqlWrapper.delete(Season.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
) {
@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(Season.class, id, fileName, fileInputStream, fileMetaData);
}
@ -85,13 +93,13 @@ public class SeasonResource {
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
SqlWrapper.removeLink(Season.class, id, "cover", coverId);
AddOnManyToMany.removeLink(Season.class, id, "cover", coverId);
return Response.ok(SqlWrapper.get(Season.class, id)).build();
}
public static Season getOrCreate(String name, Long seriesId) {
try {
Season out = SqlWrapper.getWhere(Season.class, "name", "=", name, "parentId", "=", seriesId);
Season out = SqlWrapper.getWhere(Season.class, new QuerryAnd(new QuerryCondition("name", "=", name), new QuerryCondition("parentId", "=", seriesId)));
if (out == null) {
out = new Season();
out.name = name;

View File

@ -1,23 +1,33 @@
package org.kar.karideo.api;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.karideo.model.Season;
import org.kar.karideo.model.Series;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.kar.archidata.SqlWrapper;
import org.kar.archidata.annotation.security.RolesAllowed;
import org.kar.archidata.util.DataTools;
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.QuerryAnd;
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.karideo.model.Series;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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("/series")
@Produces({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON })
public class SeriesResource {
static final Logger LOGGER = LoggerFactory.getLogger(SeriesResource.class);
@ -31,7 +41,7 @@ public class SeriesResource {
@GET
@RolesAllowed("USER")
public List<Series> get() throws Exception {
return SqlWrapper.gets(Series.class, false);
return SqlWrapper.gets(Series.class);
}
@GET
@ -66,19 +76,16 @@ public class SeriesResource {
@Path("{id}")
@RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.setDelete(Series.class, id);
SqlWrapper.delete(Series.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
) {
@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(Series.class, id, fileName, fileInputStream, fileMetaData);
}
@ -86,13 +93,13 @@ public class SeriesResource {
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
SqlWrapper.removeLink(Series.class, id, "cover", coverId);
AddOnManyToMany.removeLink(Series.class, id, "cover", coverId);
return Response.ok(SqlWrapper.get(Series.class, id)).build();
}
public static Series getOrCreate(String name, Long typeId) {
try {
Series out = SqlWrapper.getWhere(Series.class, "name", "=", name, "parentId", "=", typeId);
Series out = SqlWrapper.getWhere(Series.class, new QuerryAnd(new QuerryCondition("name", "=", name), new QuerryCondition("parentId", "=", typeId)));
if (out == null) {
out = new Series();
out.name = name;
@ -108,4 +115,3 @@ public class SeriesResource {
}
}

View File

@ -1,26 +1,35 @@
package org.kar.karideo.api;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.karideo.model.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.kar.archidata.SqlWrapper;
import org.kar.archidata.annotation.security.RolesAllowed;
import org.kar.archidata.util.DataTools;
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.QuerryCondition;
import org.kar.archidata.sqlWrapper.SqlWrapper;
import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
import org.kar.archidata.util.DataTools;
import org.kar.karideo.model.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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("/type")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public class TypeResource {
static final Logger LOGGER = LoggerFactory.getLogger(TypeResource.class);
@GET
@Path("{id}")
@RolesAllowed("USER")
@ -31,7 +40,7 @@ public class TypeResource {
@GET
@RolesAllowed("USER")
public List<Type> get() throws Exception {
return SqlWrapper.gets(Type.class, false);
return SqlWrapper.gets(Type.class);
}
@GET
@ -70,19 +79,16 @@ public class TypeResource {
@Path("{id}")
@RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.setDelete(Type.class, id);
SqlWrapper.delete(Type.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
) {
@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(Type.class, id, fileName, fileInputStream, fileMetaData);
}
@ -90,13 +96,13 @@ public class TypeResource {
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
SqlWrapper.removeLink(Type.class, id, "cover", coverId);
AddOnManyToMany.removeLink(Type.class, id, "cover", coverId);
return Response.ok(SqlWrapper.get(Type.class, id)).build();
}
public static Type getOrCreate(String name) {
try {
Type out = SqlWrapper.getWhere(Type.class, "name", "=", name);
Type out = SqlWrapper.getWhere(Type.class, new QuerryCondition("name", "=", name));
if (out == null) {
out = new Type();
out.name = name;
@ -110,5 +116,4 @@ public class TypeResource {
return null;
}
}

View File

@ -1,57 +1,56 @@
package org.kar.karideo.api;
import java.util.List;
import org.kar.archidata.annotation.security.RolesAllowed;
import org.kar.archidata.filter.GenericContext;
import org.kar.archidata.sqlWrapper.QuerryAnd;
import org.kar.archidata.sqlWrapper.QuerryCondition;
import org.kar.archidata.sqlWrapper.SqlWrapper;
import org.kar.karideo.model.UserMediaAdvancement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.kar.archidata.SqlWrapper;
import org.kar.archidata.WhereCondition;
import org.kar.archidata.annotation.security.RolesAllowed;
import org.kar.archidata.filter.GenericContext;
import jakarta.ws.rs.*;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
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.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.SecurityContext;
import java.util.List;
@Path("/advancement")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public class UserMediaAdvancementResource {
static final Logger LOGGER = LoggerFactory.getLogger(UserMediaAdvancementResource.class);
@GET
@Path("{id}")
@RolesAllowed("USER")
public UserMediaAdvancement getWithId(@Context SecurityContext sc, @PathParam("id") Long id) throws Exception {
GenericContext gc = (GenericContext) sc.getUserPrincipal();
return SqlWrapper.getWhere(UserMediaAdvancement.class,
List.of(
new WhereCondition("mediaId", "=", id),
new WhereCondition("userId", "=", gc.userByToken.id),
new WhereCondition("deleted", "=", 0)
), false);
return SqlWrapper.getWhere(UserMediaAdvancement.class, new QuerryAnd(new QuerryCondition("mediaId", "=", id), new QuerryCondition("userId", "=", gc.userByToken.id)));
}
@GET
@RolesAllowed("USER")
public List<UserMediaAdvancement> gets(@Context SecurityContext sc ) throws Exception {
public List<UserMediaAdvancement> gets(@Context SecurityContext sc) throws Exception {
GenericContext gc = (GenericContext) sc.getUserPrincipal();
return SqlWrapper.getsWhere(UserMediaAdvancement.class,
List.of(
new WhereCondition("userId", "=", gc.userByToken.id),
new WhereCondition("deleted", "=", 0)
), false);
return SqlWrapper.getsWhere(UserMediaAdvancement.class, new QuerryCondition("userId", "=", gc.userByToken.id));
}
/* =============================================================================
* Modification SECTION:
* ============================================================================= */
public record MediaInformations(int time, float percent, int count) {};
public record MediaInformations(
int time,
float percent,
int count) {};
//@POST
//@Path("{id}")
@ -67,7 +66,11 @@ public class UserMediaAdvancementResource {
elem.count = data.count;
return SqlWrapper.insert(elem);
}
public record MediaInformationsDelta(int time, float percent, boolean addCount) {};
public record MediaInformationsDelta(
int time,
float percent,
boolean addCount) {};
@PUT
@Path("{id}")
@ -89,19 +92,19 @@ public class UserMediaAdvancementResource {
elem.count++;
}
LOGGER.info("{},{},{}", elem.time, elem.percent, elem.count);
int nbAfected = SqlWrapper.update(elem, elem.id, List.of("time", "percent","count"));
int nbAfected = SqlWrapper.update(elem, elem.id, List.of("time", "percent", "count"));
// TODO: manage the fact that no element has been updated ...
UserMediaAdvancement ret = SqlWrapper.get(UserMediaAdvancement.class, elem.id);
return ret;
}
@DELETE
@Path("{id}")
@RolesAllowed("USER")
public Response delete(@Context SecurityContext sc, @PathParam("id") Long id) throws Exception {
UserMediaAdvancement elem = this.getWithId(sc, id);
SqlWrapper.setDelete(UserMediaAdvancement.class, elem.id);
SqlWrapper.delete(UserMediaAdvancement.class, elem.id);
return Response.ok().build();
}
}

View File

@ -1,24 +1,26 @@
package org.kar.karideo.api;
import org.kar.archidata.SqlWrapper;
import org.kar.archidata.filter.GenericContext;
import org.kar.archidata.model.User;
import org.kar.karideo.model.UserKarideo;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.List;
import org.kar.archidata.annotation.security.RolesAllowed;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.SecurityContext;
import java.util.List;
import org.kar.archidata.filter.GenericContext;
import org.kar.archidata.sqlWrapper.SqlWrapper;
import org.kar.karideo.model.UserKarideo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.annotation.JsonInclude;
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;
@Path("/users")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public class UserResource {
static final Logger LOGGER = LoggerFactory.getLogger(UserResource.class);
@ -26,6 +28,7 @@ public class UserResource {
public class UserOut {
public long id;
public String login;
public UserOut(long id, String login) {
super();
this.id = id;
@ -33,8 +36,8 @@ public class UserResource {
}
}
public UserResource() {
}
public UserResource() {}
// curl http://localhost:9993/api/users
@GET
@ -42,7 +45,7 @@ public class UserResource {
public List<UserKarideo> getUsers() {
System.out.println("getUsers");
try {
return SqlWrapper.gets(UserKarideo.class, false);
return SqlWrapper.gets(UserKarideo.class);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -80,35 +83,3 @@ public class UserResource {
}
}

View File

@ -1,8 +1,19 @@
package org.kar.karideo.api;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
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.api.DataResource;
import org.kar.archidata.exception.FailException;
import org.kar.archidata.exception.InputException;
import org.kar.archidata.model.Data;
import org.kar.archidata.sqlWrapper.SqlWrapper;
import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
import org.kar.archidata.util.DataTools;
import org.kar.karideo.model.Media;
import org.kar.karideo.model.Season;
@ -10,30 +21,27 @@ import org.kar.karideo.model.Series;
import org.kar.karideo.model.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.kar.archidata.SqlWrapper;
import org.kar.archidata.annotation.security.RolesAllowed;
import org.kar.archidata.api.DataResource;
import org.kar.archidata.exception.FailException;
import org.kar.archidata.exception.InputException;
import jakarta.ws.rs.*;
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;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.List;
@Path("/video")
@Produces({MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON })
public class VideoResource {
static final Logger LOGGER = LoggerFactory.getLogger(VideoResource.class);
@GET
@RolesAllowed("USER")
public List<Media> get() throws Exception {
return SqlWrapper.gets(Media.class, false);
return SqlWrapper.gets(Media.class);
}
@GET
@ -69,18 +77,11 @@ public class VideoResource {
@POST
@Path("/upload/")
@RolesAllowed("ADMIN")
@Consumes({MediaType.MULTIPART_FORM_DATA})
public Response uploadFile(@FormDataParam("fileName") String fileName,
@FormDataParam("universe") String universe,
@FormDataParam("series") String series,
@Consumes({ MediaType.MULTIPART_FORM_DATA })
public Response uploadFile(@FormDataParam("fileName") String fileName, @FormDataParam("universe") String universe, @FormDataParam("series") String series,
//@FormDataParam("seriesId") String seriesId, Not used ...
@FormDataParam("season") String season,
@FormDataParam("episode") String episode,
@FormDataParam("title") String title,
@FormDataParam("typeId") String typeId,
@FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData
) throws FailException {
@FormDataParam("season") String season, @FormDataParam("episode") String episode, @FormDataParam("title") String title, @FormDataParam("typeId") String typeId,
@FormDataParam("file") InputStream fileInputStream, @FormDataParam("file") FormDataContentDisposition fileMetaData) throws FailException {
try {
// correct input string stream :
fileName = multipartCorrection(fileName);
@ -160,7 +161,6 @@ public class VideoResource {
System.out.println(" ==> " + seasonNode);
System.out.println("add media");
long uniqueSQLID = -1;
try {
Media media = new Media();
@ -168,7 +168,7 @@ public class VideoResource {
media.dataId = data.id;
media.typeId = typeNode.id;
media.seriesId = null;
if(seriesNode != null) {
if (seriesNode != null) {
media.seriesId = seriesNode.id;
}
media.seasonId = null;
@ -176,7 +176,7 @@ public class VideoResource {
media.seasonId = seasonNode.id;
}
media.episode = null;
if (episode != null && ! episode.contentEquals("")) {
if (episode != null && !episode.contentEquals("")) {
media.episode = Integer.parseInt(episode);
}
Media out = SqlWrapper.insert(media);
@ -195,22 +195,21 @@ public class VideoResource {
throw new FailException("Catch Exception ==> check server logs");
}
}
@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
) {
@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(Media.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(Media.class, id, "cover", coverId);
AddOnManyToMany.removeLink(Media.class, id, "cover", coverId);
return Response.ok(SqlWrapper.get(Media.class, id)).build();
}
@ -218,7 +217,7 @@ public class VideoResource {
@Path("{id}")
@RolesAllowed("ADMIN")
public Response delete(@PathParam("id") Long id) throws Exception {
SqlWrapper.setDelete(Media.class, id);
SqlWrapper.delete(Media.class, id);
return Response.ok().build();
}
}

View File

@ -0,0 +1,27 @@
package org.kar.karideo.migration;
import java.util.List;
import org.kar.archidata.migration.MigrationSqlStep;
public class Migration20231015 extends MigrationSqlStep {
public static final int KARSO_INITIALISATION_ID = 1;
@Override
public String getName() {
return "refactor creation and update time";
}
public Migration20231015() throws Exception {
for (String elem : List.of("data", "media", "media_link_cover", "season", "season_link_cover", "series", "series_link_cover", "type", "type_link_cover", "user", "userMediaAdvancement")) {
addAction("""
ALTER TABLE `""" + elem + """
`
RENAME COLUMN `create_date` TO `createdAt`,
RENAME COLUMN `modify_date` TO `updatedAt`;
""");
}
display();
}
}

View File

@ -2,48 +2,51 @@ package org.kar.karideo.model;
import java.util.List;
import org.kar.archidata.annotation.SQLComment;
import org.kar.archidata.annotation.SQLForeignKey;
import org.kar.archidata.annotation.SQLIfNotExists;
import org.kar.archidata.annotation.SQLNotNull;
import org.kar.archidata.annotation.SQLTableLinkGeneric;
import org.kar.archidata.annotation.SQLTableName;
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.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
@SQLTableName ("media")
@SQLIfNotExists
@Entity
@Table(name = "media")
@JsonInclude(JsonInclude.Include.NON_NULL)
//@SQLDelete(sql = "UPDATE table_product SET deleted = true WHERE id=?")
//@Where(clause = "deleted=false")
public class Media extends GenericTable {
@SQLNotNull
@SQLComment("Name of the media (this represent the title)")
// Name of the media (this represent the title)
@Column(nullable = false)
public String name;
@SQLComment("Description of the media")
// Description of the media
public String description;
@SQLNotNull
@SQLComment("Foreign Key Id of the data")
@SQLForeignKey("data")
// Foreign Key Id of the data
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Data.class)
@Column(nullable = false)
public Long dataId;
@SQLComment("Type of the media")
@SQLForeignKey("type")
// Type of the media")
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Type.class)
public Long typeId;
@SQLComment("Series reference of the media")
@SQLForeignKey("series")
// Series reference of the media
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Series.class)
public Long seriesId;
@SQLComment("Saison reference of the media")
@SQLForeignKey("season")
// Saison reference of the media
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Season.class)
public Long seasonId;
@SQLComment("Episide Id")
// Episide Id
public Integer episode;
@SQLComment("")
// ")
public Integer date;
@SQLComment("Creation years of the media")
// Creation years of the media
public Integer time;
@SQLComment("Limitation Age of the media")
// Limitation Age of the media
public Integer ageLimit;
@SQLComment("List of Id of the sopecific covers")
@SQLTableLinkGeneric
// List of Id of the specific covers
@ManyToMany(fetch = FetchType.LAZY, targetEntity = Data.class)
public List<Long> covers = null;
}

View File

@ -3,30 +3,32 @@ package org.kar.karideo.model;
import java.util.List;
import org.kar.archidata.annotation.SQLComment;
import org.kar.archidata.annotation.SQLForeignKey;
import org.kar.archidata.annotation.SQLIfNotExists;
import org.kar.archidata.annotation.SQLNotNull;
import org.kar.archidata.annotation.SQLTableLinkGeneric;
import org.kar.archidata.annotation.SQLTableName;
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;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
@SQLTableName ("season")
@Table(name = "season")
@SQLIfNotExists
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Season extends GenericTable {
@SQLNotNull
@Column(nullable = false)
@SQLComment("Name of the media (this represent the title)")
public String name;
@SQLComment("Description of the media")
public String description;
@SQLNotNull
@Column(nullable = false)
@SQLComment("series parent ID")
@SQLForeignKey("series")
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Series.class)
public Long parentId;
@SQLComment("List of Id of the sopecific covers")
@SQLTableLinkGeneric
@ManyToMany(fetch = FetchType.LAZY, targetEntity = Data.class)
public List<Long> covers = null;
}

View File

@ -3,30 +3,32 @@ package org.kar.karideo.model;
import java.util.List;
import org.kar.archidata.annotation.SQLComment;
import org.kar.archidata.annotation.SQLForeignKey;
import org.kar.archidata.annotation.SQLIfNotExists;
import org.kar.archidata.annotation.SQLNotNull;
import org.kar.archidata.annotation.SQLTableLinkGeneric;
import org.kar.archidata.annotation.SQLTableName;
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;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
@SQLTableName ("series")
@Table(name = "series")
@SQLIfNotExists
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Series extends GenericTable {
@SQLNotNull
@Column(nullable = false)
@SQLComment("Name of the media (this represent the title)")
public String name;
@SQLComment("Description of the media")
public String description;
@SQLNotNull
@Column(nullable = false)
@SQLComment("series parent ID")
@SQLForeignKey("type")
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Type.class)
public Long parentId;
@SQLComment("List of Id of the sopecific covers")
@SQLTableLinkGeneric
@ManyToMany(fetch = FetchType.LAZY, targetEntity = Data.class)
public List<Long> covers = null;
}

View File

@ -4,24 +4,26 @@ import java.util.List;
import org.kar.archidata.annotation.SQLComment;
import org.kar.archidata.annotation.SQLIfNotExists;
import org.kar.archidata.annotation.SQLNotNull;
import org.kar.archidata.annotation.SQLTableLinkGeneric;
import org.kar.archidata.annotation.SQLTableName;
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;
import jakarta.persistence.Table;
@SQLTableName ("type")
@Table(name = "type")
@SQLIfNotExists
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Type extends GenericTable {
@SQLNotNull
@Column(nullable = false)
@SQLComment("Name of the media (this represent the title)")
public String name;
@SQLComment("Description of the media")
public String description;
@SQLComment("List of Id of the sopecific covers")
@SQLTableLinkGeneric
@ManyToMany(fetch = FetchType.LAZY, targetEntity = Data.class)
public List<Long> covers = null;
}

View File

@ -1,12 +1,13 @@
package org.kar.karideo.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 UserKarideo extends User {

View File

@ -1,34 +1,35 @@
package org.kar.karideo.model;
import org.kar.archidata.annotation.SQLComment;
import org.kar.archidata.annotation.SQLForeignKey;
import org.kar.archidata.annotation.SQLIfNotExists;
import org.kar.archidata.annotation.SQLNotNull;
import org.kar.archidata.annotation.SQLTableName;
import org.kar.archidata.model.GenericTable;
import com.fasterxml.jackson.annotation.JsonInclude;
import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
@SQLTableName ("userMediaAdvancement")
@Table(name = "userMediaAdvancement")
@SQLIfNotExists
@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserMediaAdvancement extends GenericTable {
@SQLNotNull
@Column(nullable = false)
@SQLComment("Foreign Key Id of the user")
@SQLForeignKey("user")
@ManyToOne(fetch = FetchType.LAZY, targetEntity = UserKarideo.class)
public long userId;
@SQLNotNull
@Column(nullable = false)
@SQLComment("Id of the media")
@SQLForeignKey("media")
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Media.class)
public long mediaId;
@SQLNotNull
@Column(nullable = false)
@SQLComment("Percent of admencement in the media")
public float percent;
@SQLNotNull
@Column(nullable = false)
@SQLComment("Number of second of admencement in the media")
public int time;
@SQLNotNull
@Column(nullable = false)
@SQLComment("Number of time this media has been read")
public int count;
}

View File

@ -5,7 +5,7 @@
"scripts": {
"all": "npm run build && npm run test",
"ng": "ng",
"start": "ng serve --configuration=develop --watch --port 4202",
"dev": "ng serve --configuration=develop --watch --port 4202",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",