[DEV] update new JPA
This commit is contained in:
parent
0ee08ac7e5
commit
9c8def3341
@ -20,7 +20,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>kangaroo-and-rabbit</groupId>
|
<groupId>kangaroo-and-rabbit</groupId>
|
||||||
<artifactId>archidata</artifactId>
|
<artifactId>archidata</artifactId>
|
||||||
<version>0.3.8</version>
|
<version>0.4.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
package org.kar.karideo;
|
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.grizzly2.httpserver.GrizzlyHttpServerFactory;
|
||||||
|
import org.glassfish.jersey.jackson.JacksonFeature;
|
||||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||||
import org.glassfish.jersey.server.ResourceConfig;
|
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.GlobalConfiguration;
|
||||||
import org.kar.archidata.UpdateJwtPublicKey;
|
import org.kar.archidata.UpdateJwtPublicKey;
|
||||||
import org.kar.archidata.api.DataResource;
|
import org.kar.archidata.api.DataResource;
|
||||||
@ -23,23 +19,36 @@ import org.kar.archidata.filter.CORSFilter;
|
|||||||
import org.kar.archidata.filter.OptionFilter;
|
import org.kar.archidata.filter.OptionFilter;
|
||||||
import org.kar.archidata.migration.MigrationEngine;
|
import org.kar.archidata.migration.MigrationEngine;
|
||||||
import org.kar.archidata.util.ConfigBaseVariable;
|
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 jakarta.ws.rs.core.UriBuilder;
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
public class WebLauncher {
|
public class WebLauncher {
|
||||||
final static Logger LOGGER = LoggerFactory.getLogger(WebLauncher.class);
|
final static Logger LOGGER = LoggerFactory.getLogger(WebLauncher.class);
|
||||||
public static DBConfig dbConfig;
|
public static DBConfig dbConfig;
|
||||||
protected UpdateJwtPublicKey keyUpdater = null;
|
protected UpdateJwtPublicKey keyUpdater = null;
|
||||||
|
|
||||||
public WebLauncher() {
|
public WebLauncher() {
|
||||||
ConfigBaseVariable.bdDatabase = "karideo";
|
ConfigBaseVariable.bdDatabase = "karideo";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static URI getBaseURI() {
|
private static URI getBaseURI() {
|
||||||
return UriBuilder.fromUri(ConfigBaseVariable.getlocalAddress()).build();
|
return UriBuilder.fromUri(ConfigBaseVariable.getlocalAddress()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void migrateDB() throws Exception {
|
public void migrateDB() throws Exception {
|
||||||
WebLauncher.LOGGER.info("Create migration engine");
|
WebLauncher.LOGGER.info("Create migration engine");
|
||||||
MigrationEngine migrationEngine = new MigrationEngine();
|
MigrationEngine migrationEngine = new MigrationEngine();
|
||||||
@ -47,15 +56,16 @@ public class WebLauncher {
|
|||||||
migrationEngine.setInit(new Initialization());
|
migrationEngine.setInit(new Initialization());
|
||||||
WebLauncher.LOGGER.info("Add migration since last version");
|
WebLauncher.LOGGER.info("Add migration since last version");
|
||||||
migrationEngine.add(new Migration20230810());
|
migrationEngine.add(new Migration20230810());
|
||||||
|
migrationEngine.add(new Migration20231015());
|
||||||
WebLauncher.LOGGER.info("Migrate the DB [START]");
|
WebLauncher.LOGGER.info("Migrate the DB [START]");
|
||||||
migrationEngine.migrate(GlobalConfiguration.dbConfig);
|
migrationEngine.migrate(GlobalConfiguration.dbConfig);
|
||||||
WebLauncher.LOGGER.info("Migrate the DB [STOP]");
|
WebLauncher.LOGGER.info("Migrate the DB [STOP]");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
WebLauncher.LOGGER.info("[START] application wake UP");
|
WebLauncher.LOGGER.info("[START] application wake UP");
|
||||||
WebLauncher launcher = new WebLauncher();
|
WebLauncher launcher = new WebLauncher();
|
||||||
launcher.migrateDB();
|
launcher.migrateDB();
|
||||||
launcher.process();
|
launcher.process();
|
||||||
WebLauncher.LOGGER.info("end-configure the server & wait finish process:");
|
WebLauncher.LOGGER.info("end-configure the server & wait finish process:");
|
||||||
Thread.currentThread().join();
|
Thread.currentThread().join();
|
||||||
@ -63,45 +73,44 @@ public class WebLauncher {
|
|||||||
launcher.stopOther();
|
launcher.stopOther();
|
||||||
WebLauncher.LOGGER.info("STOP the REST server");
|
WebLauncher.LOGGER.info("STOP the REST server");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void process() throws InterruptedException {
|
||||||
public void process() throws InterruptedException {
|
|
||||||
|
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
// Configure resources
|
// Configure resources
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
ResourceConfig rc = new ResourceConfig();
|
ResourceConfig rc = new ResourceConfig();
|
||||||
|
|
||||||
|
// add multi-part models ..
|
||||||
|
rc.register(MultiPartFeature.class);
|
||||||
|
// global authentication system
|
||||||
|
rc.register(OptionFilter.class);
|
||||||
|
// remove cors ==> all time called by an other system...
|
||||||
|
rc.register(CORSFilter.class);
|
||||||
|
// global authentication system
|
||||||
|
rc.register(KarideoAuthenticationFilter.class);
|
||||||
|
// register exception catcher
|
||||||
|
rc.register(InputExceptionCatcher.class);
|
||||||
|
rc.register(SystemExceptionCatcher.class);
|
||||||
|
rc.register(FailExceptionCatcher.class);
|
||||||
|
rc.register(ExceptionCatcher.class);
|
||||||
|
// add default resource:
|
||||||
|
rc.register(UserResource.class);
|
||||||
|
rc.register(SeriesResource.class);
|
||||||
|
rc.register(DataResource.class);
|
||||||
|
rc.register(SeasonResource.class);
|
||||||
|
rc.register(TypeResource.class);
|
||||||
|
rc.register(VideoResource.class);
|
||||||
|
rc.register(UserMediaAdvancementResource.class);
|
||||||
|
|
||||||
|
rc.register(HealthCheck.class);
|
||||||
|
rc.register(Front.class);
|
||||||
|
|
||||||
|
// add jackson to be discover when we are ins stand-alone server
|
||||||
|
rc.register(JacksonFeature.class);
|
||||||
|
// enable this to show low level request
|
||||||
|
//rc.property(LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_SERVER, Level.WARNING.getName());
|
||||||
|
|
||||||
// add multi-part models ..
|
|
||||||
rc.register(MultiPartFeature.class);
|
|
||||||
// global authentication system
|
|
||||||
rc.register(OptionFilter.class);
|
|
||||||
// remove cors ==> all time called by an other system...
|
|
||||||
rc.register(CORSFilter.class);
|
|
||||||
// global authentication system
|
|
||||||
rc.register(KarideoAuthenticationFilter.class);
|
|
||||||
// register exception catcher
|
|
||||||
rc.register(InputExceptionCatcher.class);
|
|
||||||
rc.register(SystemExceptionCatcher.class);
|
|
||||||
rc.register(FailExceptionCatcher.class);
|
|
||||||
rc.register(ExceptionCatcher.class);
|
|
||||||
// add default resource:
|
|
||||||
rc.register(UserResource.class);
|
|
||||||
rc.register(SeriesResource.class);
|
|
||||||
rc.register(DataResource.class);
|
|
||||||
rc.register(SeasonResource.class);
|
|
||||||
rc.register(TypeResource.class);
|
|
||||||
rc.register(VideoResource.class);
|
|
||||||
rc.register(UserMediaAdvancementResource.class);
|
|
||||||
|
|
||||||
rc.register(HealthCheck.class);
|
|
||||||
rc.register(Front.class);
|
|
||||||
|
|
||||||
// add jackson to be discover when we are ins stand-alone server
|
|
||||||
rc.register(JacksonFeature.class);
|
|
||||||
// enable this to show low level request
|
|
||||||
//rc.property(LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_SERVER, Level.WARNING.getName());
|
|
||||||
|
|
||||||
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc);
|
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc);
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -110,17 +119,16 @@ public class WebLauncher {
|
|||||||
server.shutdownNow();
|
server.shutdownNow();
|
||||||
}
|
}
|
||||||
}, "shutdownHook"));
|
}, "shutdownHook"));
|
||||||
|
|
||||||
|
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
// start periodic update of the token ...
|
// start periodic update of the token ...
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
this.keyUpdater = new UpdateJwtPublicKey();
|
this.keyUpdater = new UpdateJwtPublicKey();
|
||||||
keyUpdater.start();
|
keyUpdater.start();
|
||||||
|
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
// run JERSEY
|
// run JERSEY
|
||||||
// ===================================================================
|
// ===================================================================
|
||||||
try {
|
try {
|
||||||
server.start();
|
server.start();
|
||||||
LOGGER.info("Jersey app started at {}", getBaseURI());
|
LOGGER.info("Jersey app started at {}", getBaseURI());
|
||||||
@ -128,9 +136,9 @@ public class WebLauncher {
|
|||||||
LOGGER.error("There was an error while starting Grizzly HTTP server.");
|
LOGGER.error("There was an error while starting Grizzly HTTP server.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopOther() {
|
public void stopOther() {
|
||||||
keyUpdater.kill();
|
keyUpdater.kill();
|
||||||
try {
|
try {
|
||||||
keyUpdater.join(4000, 0);
|
keyUpdater.join(4000, 0);
|
||||||
@ -138,5 +146,5 @@ public class WebLauncher {
|
|||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,97 +1,105 @@
|
|||||||
package org.kar.karideo.api;
|
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.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.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")
|
@Path("/season")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public class SeasonResource {
|
public class SeasonResource {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(SeasonResource.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(SeasonResource.class);
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public static Season getWithId(@PathParam("id") Long id) throws Exception {
|
public static Season getWithId(@PathParam("id") Long id) throws Exception {
|
||||||
return SqlWrapper.get(Season.class, id);
|
return SqlWrapper.get(Season.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public List<Season> get() throws Exception {
|
public List<Season> get() throws Exception {
|
||||||
return SqlWrapper.gets(Season.class, false);
|
return SqlWrapper.gets(Season.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Season get(@PathParam("id") Long id) throws Exception {
|
public Season get(@PathParam("id") Long id) throws Exception {
|
||||||
return SqlWrapper.get(Season.class, id);
|
return SqlWrapper.get(Season.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =============================================================================
|
/* =============================================================================
|
||||||
* ADMIN SECTION:
|
* ADMIN SECTION:
|
||||||
* ============================================================================= */
|
* ============================================================================= */
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Season put(String jsonRequest) throws Exception {
|
public Season put(String jsonRequest) throws Exception {
|
||||||
return SqlWrapper.insertWithJson(Season.class, jsonRequest);
|
return SqlWrapper.insertWithJson(Season.class, jsonRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Season put(@PathParam("id") Long id, String jsonRequest) throws Exception {
|
public Season put(@PathParam("id") Long id, String jsonRequest) throws Exception {
|
||||||
SqlWrapper.update(Season.class, id, jsonRequest);
|
SqlWrapper.update(Season.class, id, jsonRequest);
|
||||||
return SqlWrapper.get(Season.class, id);
|
return SqlWrapper.get(Season.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(Season.class, id);
|
SqlWrapper.delete(Season.class, id);
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@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(Season.class, id, fileName, fileInputStream, fileMetaData);
|
||||||
@FormDataParam("file") FormDataContentDisposition fileMetaData
|
}
|
||||||
) {
|
|
||||||
return DataTools.uploadCover(Season.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(Season.class, id, "cover", coverId);
|
||||||
@RolesAllowed("ADMIN")
|
return Response.ok(SqlWrapper.get(Season.class, id)).build();
|
||||||
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
|
}
|
||||||
SqlWrapper.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, new QuerryAnd(new QuerryCondition("name", "=", name), new QuerryCondition("parentId", "=", seriesId)));
|
||||||
public static Season getOrCreate(String name, Long seriesId) {
|
|
||||||
try {
|
|
||||||
Season out = SqlWrapper.getWhere(Season.class, "name", "=", name, "parentId", "=", seriesId);
|
|
||||||
if (out == null) {
|
if (out == null) {
|
||||||
out = new Season();
|
out = new Season();
|
||||||
out.name = name;
|
out.name = name;
|
||||||
@ -103,7 +111,7 @@ public class SeasonResource {
|
|||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,98 +1,105 @@
|
|||||||
package org.kar.karideo.api;
|
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.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.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")
|
@Path("/series")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public class SeriesResource {
|
public class SeriesResource {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(SeriesResource.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(SeriesResource.class);
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public static Series getWithId(@PathParam("id") Long id) throws Exception {
|
public static Series getWithId(@PathParam("id") Long id) throws Exception {
|
||||||
return SqlWrapper.get(Series.class, id);
|
return SqlWrapper.get(Series.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public List<Series> get() throws Exception {
|
public List<Series> get() throws Exception {
|
||||||
return SqlWrapper.gets(Series.class, false);
|
return SqlWrapper.gets(Series.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Series get(@PathParam("id") Long id) throws Exception {
|
public Series get(@PathParam("id") Long id) throws Exception {
|
||||||
return SqlWrapper.get(Series.class, id);
|
return SqlWrapper.get(Series.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =============================================================================
|
/* =============================================================================
|
||||||
* ADMIN SECTION:
|
* ADMIN SECTION:
|
||||||
* ============================================================================= */
|
* ============================================================================= */
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Series put(String jsonRequest) throws Exception {
|
public Series put(String jsonRequest) throws Exception {
|
||||||
return SqlWrapper.insertWithJson(Series.class, jsonRequest);
|
return SqlWrapper.insertWithJson(Series.class, jsonRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Series put(@PathParam("id") Long id, String jsonRequest) throws Exception {
|
public Series put(@PathParam("id") Long id, String jsonRequest) throws Exception {
|
||||||
SqlWrapper.update(Series.class, id, jsonRequest);
|
SqlWrapper.update(Series.class, id, jsonRequest);
|
||||||
return SqlWrapper.get(Series.class, id);
|
return SqlWrapper.get(Series.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(Series.class, id);
|
SqlWrapper.delete(Series.class, id);
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@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(Series.class, id, fileName, fileInputStream, fileMetaData);
|
||||||
@FormDataParam("file") FormDataContentDisposition fileMetaData
|
}
|
||||||
) {
|
|
||||||
return DataTools.uploadCover(Series.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(Series.class, id, "cover", coverId);
|
||||||
@RolesAllowed("ADMIN")
|
return Response.ok(SqlWrapper.get(Series.class, id)).build();
|
||||||
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
|
}
|
||||||
SqlWrapper.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, new QuerryAnd(new QuerryCondition("name", "=", name), new QuerryCondition("parentId", "=", typeId)));
|
||||||
public static Series getOrCreate(String name, Long typeId) {
|
|
||||||
try {
|
|
||||||
Series out = SqlWrapper.getWhere(Series.class, "name", "=", name, "parentId", "=", typeId);
|
|
||||||
if (out == null) {
|
if (out == null) {
|
||||||
out = new Series();
|
out = new Series();
|
||||||
out.name = name;
|
out.name = name;
|
||||||
@ -104,8 +111,7 @@ public class SeriesResource {
|
|||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,102 +1,108 @@
|
|||||||
package org.kar.karideo.api;
|
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.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.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")
|
@Path("/type")
|
||||||
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
|
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||||
public class TypeResource {
|
public class TypeResource {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(TypeResource.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(TypeResource.class);
|
||||||
|
|
||||||
|
@GET
|
||||||
@GET
|
@Path("{id}")
|
||||||
@Path("{id}")
|
@RolesAllowed("USER")
|
||||||
@RolesAllowed("USER")
|
public static Type getWithId(@PathParam("id") Long id) throws Exception {
|
||||||
public static Type getWithId(@PathParam("id") Long id) throws Exception {
|
return SqlWrapper.get(Type.class, id);
|
||||||
return SqlWrapper.get(Type.class, id);
|
}
|
||||||
}
|
|
||||||
|
@GET
|
||||||
@GET
|
@RolesAllowed("USER")
|
||||||
@RolesAllowed("USER")
|
public List<Type> get() throws Exception {
|
||||||
public List<Type> get() throws Exception {
|
return SqlWrapper.gets(Type.class);
|
||||||
return SqlWrapper.gets(Type.class, false);
|
}
|
||||||
}
|
|
||||||
|
@GET
|
||||||
@GET
|
@Path("{id}")
|
||||||
@Path("{id}")
|
@RolesAllowed("USER")
|
||||||
@RolesAllowed("USER")
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
public Type get(@PathParam("id") Long id) throws Exception {
|
||||||
public Type get(@PathParam("id") Long id) throws Exception {
|
return SqlWrapper.get(Type.class, id);
|
||||||
return SqlWrapper.get(Type.class, id);
|
}
|
||||||
}
|
|
||||||
|
public static Type getId(Long id) throws Exception {
|
||||||
public static Type getId(Long id) throws Exception {
|
return SqlWrapper.get(Type.class, id);
|
||||||
return SqlWrapper.get(Type.class, id);
|
}
|
||||||
}
|
|
||||||
|
/* =============================================================================
|
||||||
/* =============================================================================
|
* ADMIN SECTION:
|
||||||
* ADMIN SECTION:
|
* ============================================================================= */
|
||||||
* ============================================================================= */
|
|
||||||
|
@POST
|
||||||
@POST
|
@RolesAllowed("ADMIN")
|
||||||
@RolesAllowed("ADMIN")
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
public Type put(String jsonRequest) throws Exception {
|
||||||
public Type put(String jsonRequest) throws Exception {
|
return SqlWrapper.insertWithJson(Type.class, jsonRequest);
|
||||||
return SqlWrapper.insertWithJson(Type.class, jsonRequest);
|
}
|
||||||
}
|
|
||||||
|
@PUT
|
||||||
@PUT
|
@Path("{id}")
|
||||||
@Path("{id}")
|
@RolesAllowed("ADMIN")
|
||||||
@RolesAllowed("ADMIN")
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
public Type put(@PathParam("id") Long id, String jsonRequest) throws Exception {
|
||||||
public Type put(@PathParam("id") Long id, String jsonRequest) throws Exception {
|
SqlWrapper.update(Type.class, id, jsonRequest);
|
||||||
SqlWrapper.update(Type.class, id, jsonRequest);
|
return SqlWrapper.get(Type.class, id);
|
||||||
return SqlWrapper.get(Type.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.delete(Type.class, id);
|
||||||
SqlWrapper.setDelete(Type.class, id);
|
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@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(Type.class, id, fileName, fileInputStream, fileMetaData);
|
||||||
@FormDataParam("file") FormDataContentDisposition fileMetaData
|
}
|
||||||
) {
|
|
||||||
return DataTools.uploadCover(Type.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(Type.class, id, "cover", coverId);
|
||||||
@RolesAllowed("ADMIN")
|
return Response.ok(SqlWrapper.get(Type.class, id)).build();
|
||||||
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
|
}
|
||||||
SqlWrapper.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, new QuerryCondition("name", "=", name));
|
||||||
public static Type getOrCreate(String name) {
|
|
||||||
try {
|
|
||||||
Type out = SqlWrapper.getWhere(Type.class, "name", "=", name);
|
|
||||||
if (out == null) {
|
if (out == null) {
|
||||||
out = new Type();
|
out = new Type();
|
||||||
out.name = name;
|
out.name = name;
|
||||||
@ -107,8 +113,7 @@ public class TypeResource {
|
|||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,107 +1,110 @@
|
|||||||
package org.kar.karideo.api;
|
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.kar.karideo.model.UserMediaAdvancement;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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.Context;
|
||||||
import jakarta.ws.rs.core.MediaType;
|
import jakarta.ws.rs.core.MediaType;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
import jakarta.ws.rs.core.SecurityContext;
|
import jakarta.ws.rs.core.SecurityContext;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Path("/advancement")
|
@Path("/advancement")
|
||||||
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
|
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||||
public class UserMediaAdvancementResource {
|
public class UserMediaAdvancementResource {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(UserMediaAdvancementResource.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(UserMediaAdvancementResource.class);
|
||||||
|
|
||||||
|
@GET
|
||||||
@GET
|
@Path("{id}")
|
||||||
@Path("{id}")
|
@RolesAllowed("USER")
|
||||||
@RolesAllowed("USER")
|
public UserMediaAdvancement getWithId(@Context SecurityContext sc, @PathParam("id") Long id) throws Exception {
|
||||||
public UserMediaAdvancement getWithId(@Context SecurityContext sc, @PathParam("id") Long id) throws Exception {
|
GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
||||||
GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
return SqlWrapper.getWhere(UserMediaAdvancement.class, new QuerryAnd(new QuerryCondition("mediaId", "=", id), new QuerryCondition("userId", "=", gc.userByToken.id)));
|
||||||
return SqlWrapper.getWhere(UserMediaAdvancement.class,
|
}
|
||||||
List.of(
|
|
||||||
new WhereCondition("mediaId", "=", id),
|
@GET
|
||||||
new WhereCondition("userId", "=", gc.userByToken.id),
|
@RolesAllowed("USER")
|
||||||
new WhereCondition("deleted", "=", 0)
|
public List<UserMediaAdvancement> gets(@Context SecurityContext sc) throws Exception {
|
||||||
), false);
|
GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
||||||
}
|
return SqlWrapper.getsWhere(UserMediaAdvancement.class, new QuerryCondition("userId", "=", gc.userByToken.id));
|
||||||
|
}
|
||||||
@GET
|
|
||||||
@RolesAllowed("USER")
|
/* =============================================================================
|
||||||
public List<UserMediaAdvancement> gets(@Context SecurityContext sc ) throws Exception {
|
* Modification SECTION:
|
||||||
GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
* ============================================================================= */
|
||||||
return SqlWrapper.getsWhere(UserMediaAdvancement.class,
|
|
||||||
List.of(
|
public record MediaInformations(
|
||||||
new WhereCondition("userId", "=", gc.userByToken.id),
|
int time,
|
||||||
new WhereCondition("deleted", "=", 0)
|
float percent,
|
||||||
), false);
|
int count) {};
|
||||||
}
|
|
||||||
|
//@POST
|
||||||
|
//@Path("{id}")
|
||||||
/* =============================================================================
|
//@RolesAllowed("USER")
|
||||||
* Modification SECTION:
|
//@Consumes(MediaType.APPLICATION_JSON)
|
||||||
* ============================================================================= */
|
public UserMediaAdvancement post(@Context SecurityContext sc, @PathParam("id") Long id, MediaInformations data) throws Exception {
|
||||||
|
GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
||||||
public record MediaInformations(int time, float percent, int count) {};
|
UserMediaAdvancement elem = new UserMediaAdvancement();
|
||||||
|
elem.userId = gc.userByToken.id;
|
||||||
//@POST
|
elem.mediaId = id;
|
||||||
//@Path("{id}")
|
elem.time = data.time;
|
||||||
//@RolesAllowed("USER")
|
elem.percent = data.percent;
|
||||||
//@Consumes(MediaType.APPLICATION_JSON)
|
elem.count = data.count;
|
||||||
public UserMediaAdvancement post(@Context SecurityContext sc, @PathParam("id") Long id, MediaInformations data) throws Exception {
|
return SqlWrapper.insert(elem);
|
||||||
GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
}
|
||||||
UserMediaAdvancement elem = new UserMediaAdvancement();
|
|
||||||
elem.userId = gc.userByToken.id;
|
public record MediaInformationsDelta(
|
||||||
elem.mediaId = id;
|
int time,
|
||||||
elem.time = data.time;
|
float percent,
|
||||||
elem.percent = data.percent;
|
boolean addCount) {};
|
||||||
elem.count = data.count;
|
|
||||||
return SqlWrapper.insert(elem);
|
@PUT
|
||||||
}
|
@Path("{id}")
|
||||||
public record MediaInformationsDelta(int time, float percent, boolean addCount) {};
|
@RolesAllowed("USER")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@PUT
|
public UserMediaAdvancement put(@Context SecurityContext sc, @PathParam("id") Long id, MediaInformationsDelta data) throws Exception {
|
||||||
@Path("{id}")
|
UserMediaAdvancement elem = this.getWithId(sc, id);
|
||||||
@RolesAllowed("USER")
|
if (elem == null) {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
// insert element
|
||||||
public UserMediaAdvancement put(@Context SecurityContext sc, @PathParam("id") Long id, MediaInformationsDelta data) throws Exception {
|
if (data.addCount) {
|
||||||
UserMediaAdvancement elem = this.getWithId(sc, id);
|
return this.post(sc, id, new MediaInformations(data.time(), data.percent(), 1));
|
||||||
if (elem == null) {
|
} else {
|
||||||
// insert element
|
return this.post(sc, id, new MediaInformations(data.time(), data.percent(), 0));
|
||||||
if (data.addCount) {
|
}
|
||||||
return this.post(sc, id, new MediaInformations(data.time(), data.percent(), 1));
|
}
|
||||||
} else {
|
elem.time = data.time;
|
||||||
return this.post(sc, id, new MediaInformations(data.time(), data.percent(), 0));
|
elem.percent = data.percent;
|
||||||
}
|
if (data.addCount) {
|
||||||
}
|
elem.count++;
|
||||||
elem.time = data.time;
|
}
|
||||||
elem.percent = data.percent;
|
LOGGER.info("{},{},{}", elem.time, elem.percent, elem.count);
|
||||||
if (data.addCount) {
|
int nbAfected = SqlWrapper.update(elem, elem.id, List.of("time", "percent", "count"));
|
||||||
elem.count++;
|
// TODO: manage the fact that no element has been updated ...
|
||||||
}
|
UserMediaAdvancement ret = SqlWrapper.get(UserMediaAdvancement.class, elem.id);
|
||||||
LOGGER.info("{},{},{}", elem.time, elem.percent, elem.count);
|
return ret;
|
||||||
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);
|
@DELETE
|
||||||
return ret;
|
@Path("{id}")
|
||||||
}
|
@RolesAllowed("USER")
|
||||||
@DELETE
|
public Response delete(@Context SecurityContext sc, @PathParam("id") Long id) throws Exception {
|
||||||
@Path("{id}")
|
UserMediaAdvancement elem = this.getWithId(sc, id);
|
||||||
@RolesAllowed("USER")
|
SqlWrapper.delete(UserMediaAdvancement.class, elem.id);
|
||||||
public Response delete(@Context SecurityContext sc, @PathParam("id") Long id) throws Exception {
|
|
||||||
UserMediaAdvancement elem = this.getWithId(sc, id);
|
|
||||||
SqlWrapper.setDelete(UserMediaAdvancement.class, elem.id);
|
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,34 @@
|
|||||||
package org.kar.karideo.api;
|
package org.kar.karideo.api;
|
||||||
|
|
||||||
import org.kar.archidata.SqlWrapper;
|
import java.util.List;
|
||||||
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 org.kar.archidata.annotation.security.RolesAllowed;
|
import org.kar.archidata.annotation.security.RolesAllowed;
|
||||||
import jakarta.ws.rs.*;
|
import org.kar.archidata.filter.GenericContext;
|
||||||
import jakarta.ws.rs.core.Context;
|
import org.kar.archidata.sqlWrapper.SqlWrapper;
|
||||||
import jakarta.ws.rs.core.MediaType;
|
import org.kar.karideo.model.UserKarideo;
|
||||||
import jakarta.ws.rs.core.SecurityContext;
|
|
||||||
import java.util.List;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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")
|
@Path("/users")
|
||||||
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
|
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||||
public class UserResource {
|
public class UserResource {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(UserResource.class);
|
static 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;
|
||||||
@ -33,82 +36,50 @@ 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<UserKarideo> getUsers() {
|
public List<UserKarideo> getUsers() {
|
||||||
System.out.println("getUsers");
|
System.out.println("getUsers");
|
||||||
try {
|
try {
|
||||||
return SqlWrapper.gets(UserKarideo.class, false);
|
return SqlWrapper.gets(UserKarideo.class);
|
||||||
} 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 UserKarideo getUsers(@Context SecurityContext sc, @PathParam("id") long userId) {
|
public UserKarideo 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(UserKarideo.class, userId);
|
return SqlWrapper.get(UserKarideo.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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,8 +1,19 @@
|
|||||||
package org.kar.karideo.api;
|
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.FormDataContentDisposition;
|
||||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
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.model.Data;
|
||||||
|
import org.kar.archidata.sqlWrapper.SqlWrapper;
|
||||||
|
import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
|
||||||
import org.kar.archidata.util.DataTools;
|
import org.kar.archidata.util.DataTools;
|
||||||
import org.kar.karideo.model.Media;
|
import org.kar.karideo.model.Media;
|
||||||
import org.kar.karideo.model.Season;
|
import org.kar.karideo.model.Season;
|
||||||
@ -10,215 +21,203 @@ import org.kar.karideo.model.Series;
|
|||||||
import org.kar.karideo.model.Type;
|
import org.kar.karideo.model.Type;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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.MediaType;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.sql.*;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Path("/video")
|
@Path("/video")
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public class VideoResource {
|
public class VideoResource {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(VideoResource.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(VideoResource.class);
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public List<Media> get() throws Exception {
|
public List<Media> get() throws Exception {
|
||||||
return SqlWrapper.gets(Media.class, false);
|
return SqlWrapper.gets(Media.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("USER")
|
@RolesAllowed("USER")
|
||||||
public Media get(@PathParam("id") Long id) throws Exception {
|
public Media get(@PathParam("id") Long id) throws Exception {
|
||||||
return SqlWrapper.get(Media.class, id);
|
return SqlWrapper.get(Media.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Media put(@PathParam("id") Long id, String jsonRequest) throws Exception {
|
public Media put(@PathParam("id") Long id, String jsonRequest) throws Exception {
|
||||||
System.out.println("update video " + id + " ==> '" + jsonRequest + "'");
|
System.out.println("update video " + id + " ==> '" + jsonRequest + "'");
|
||||||
SqlWrapper.update(Media.class, id, jsonRequest);
|
SqlWrapper.update(Media.class, id, jsonRequest);
|
||||||
return SqlWrapper.get(Media.class, id);
|
return SqlWrapper.get(Media.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String multipartCorrection(String data) {
|
private String multipartCorrection(String data) {
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (data.isEmpty()) {
|
if (data.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (data.contentEquals("null")) {
|
if (data.contentEquals("null")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/upload/")
|
@Path("/upload/")
|
||||||
@RolesAllowed("ADMIN")
|
@RolesAllowed("ADMIN")
|
||||||
@Consumes({MediaType.MULTIPART_FORM_DATA})
|
@Consumes({ MediaType.MULTIPART_FORM_DATA })
|
||||||
public Response uploadFile(@FormDataParam("fileName") String fileName,
|
public Response uploadFile(@FormDataParam("fileName") String fileName, @FormDataParam("universe") String universe, @FormDataParam("series") String series,
|
||||||
@FormDataParam("universe") String universe,
|
//@FormDataParam("seriesId") String seriesId, Not used ...
|
||||||
@FormDataParam("series") String series,
|
@FormDataParam("season") String season, @FormDataParam("episode") String episode, @FormDataParam("title") String title, @FormDataParam("typeId") String typeId,
|
||||||
//@FormDataParam("seriesId") String seriesId, Not used ...
|
@FormDataParam("file") InputStream fileInputStream, @FormDataParam("file") FormDataContentDisposition fileMetaData) throws FailException {
|
||||||
@FormDataParam("season") String season,
|
try {
|
||||||
@FormDataParam("episode") String episode,
|
// correct input string stream :
|
||||||
@FormDataParam("title") String title,
|
fileName = multipartCorrection(fileName);
|
||||||
@FormDataParam("typeId") String typeId,
|
universe = multipartCorrection(universe);
|
||||||
@FormDataParam("file") InputStream fileInputStream,
|
series = multipartCorrection(series);
|
||||||
@FormDataParam("file") FormDataContentDisposition fileMetaData
|
season = multipartCorrection(season);
|
||||||
) throws FailException {
|
episode = multipartCorrection(episode);
|
||||||
try {
|
title = multipartCorrection(title);
|
||||||
// correct input string stream :
|
typeId = multipartCorrection(typeId);
|
||||||
fileName = multipartCorrection(fileName);
|
|
||||||
universe = multipartCorrection(universe);
|
//public NodeSmall uploadFile(final FormDataMultiPart form) {
|
||||||
series = multipartCorrection(series);
|
System.out.println("Upload media file: " + fileMetaData);
|
||||||
season = multipartCorrection(season);
|
System.out.println(" - fileName: " + fileName);
|
||||||
episode = multipartCorrection(episode);
|
System.out.println(" - universe: " + universe);
|
||||||
title = multipartCorrection(title);
|
System.out.println(" - series: " + series);
|
||||||
typeId = multipartCorrection(typeId);
|
System.out.println(" - season: " + season);
|
||||||
|
System.out.println(" - episode: " + episode);
|
||||||
//public NodeSmall uploadFile(final FormDataMultiPart form) {
|
System.out.println(" - title: " + title);
|
||||||
System.out.println("Upload media file: " + fileMetaData);
|
System.out.println(" - type: " + typeId);
|
||||||
System.out.println(" - fileName: " + fileName);
|
System.out.println(" - fileInputStream: " + fileInputStream);
|
||||||
System.out.println(" - universe: " + universe);
|
System.out.println(" - fileMetaData: " + fileMetaData);
|
||||||
System.out.println(" - series: " + series);
|
System.out.flush();
|
||||||
System.out.println(" - season: " + season);
|
if (typeId == null) {
|
||||||
System.out.println(" - episode: " + episode);
|
throw new InputException("typeId", "TypiId is not specified");
|
||||||
System.out.println(" - title: " + title);
|
}
|
||||||
System.out.println(" - type: " + typeId);
|
|
||||||
System.out.println(" - fileInputStream: " + fileInputStream);
|
long tmpUID = DataResource.getTmpDataId();
|
||||||
System.out.println(" - fileMetaData: " + fileMetaData);
|
String sha512 = DataResource.saveTemporaryFile(fileInputStream, tmpUID);
|
||||||
System.out.flush();
|
Data data = DataResource.getWithSha512(sha512);
|
||||||
if (typeId == null) {
|
if (data == null) {
|
||||||
throw new InputException("typeId", "TypiId is not specified");
|
System.out.println("Need to add the data in the BDD ... ");
|
||||||
}
|
System.out.flush();
|
||||||
|
try {
|
||||||
long tmpUID = DataResource.getTmpDataId();
|
data = DataResource.createNewData(tmpUID, fileName, sha512);
|
||||||
String sha512 = DataResource.saveTemporaryFile(fileInputStream, tmpUID);
|
} catch (IOException ex) {
|
||||||
Data data = DataResource.getWithSha512(sha512);
|
DataResource.removeTemporaryFile(tmpUID);
|
||||||
if (data == null) {
|
ex.printStackTrace();
|
||||||
System.out.println("Need to add the data in the BDD ... ");
|
throw new FailException("can not create input media (the data model has an internal error");
|
||||||
System.out.flush();
|
}
|
||||||
try {
|
} else if (data.deleted == true) {
|
||||||
data = DataResource.createNewData(tmpUID, fileName, sha512);
|
System.out.println("Data already exist but deleted");
|
||||||
} catch (IOException ex) {
|
System.out.flush();
|
||||||
DataResource.removeTemporaryFile(tmpUID);
|
DataResource.undelete(data.id);
|
||||||
ex.printStackTrace();
|
data.deleted = false;
|
||||||
throw new FailException("can not create input media (the data model has an internal error");
|
} else {
|
||||||
}
|
System.out.println("Data already exist ... all good");
|
||||||
} else if (data.deleted == true) {
|
System.out.flush();
|
||||||
System.out.println("Data already exist but deleted");
|
}
|
||||||
System.out.flush();
|
// Fist step: retive all the Id of each parents:...
|
||||||
DataResource.undelete(data.id);
|
System.out.println("Find typeNode");
|
||||||
data.deleted = false;
|
// check if id of type exist:
|
||||||
} else {
|
Type typeNode = TypeResource.getId(Long.parseLong(typeId));
|
||||||
System.out.println("Data already exist ... all good");
|
if (typeNode == null) {
|
||||||
System.out.flush();
|
DataResource.removeTemporaryFile(tmpUID);
|
||||||
}
|
throw new InputException("typeId", "TypeId does not exist ...");
|
||||||
// Fist step: retive all the Id of each parents:...
|
}
|
||||||
System.out.println("Find typeNode");
|
System.out.println(" ==> " + typeNode);
|
||||||
// check if id of type exist:
|
System.out.println("Find seriesNode");
|
||||||
Type typeNode = TypeResource.getId(Long.parseLong(typeId));
|
// get uid of group:
|
||||||
if (typeNode == null) {
|
Series seriesNode = null;
|
||||||
DataResource.removeTemporaryFile(tmpUID);
|
if (series != null) {
|
||||||
throw new InputException("typeId", "TypeId does not exist ...");
|
seriesNode = SeriesResource.getOrCreate(series, typeNode.id);
|
||||||
}
|
}
|
||||||
System.out.println(" ==> " + typeNode);
|
|
||||||
System.out.println("Find seriesNode");
|
System.out.println(" ==> " + seriesNode);
|
||||||
// get uid of group:
|
System.out.println("Find seasonNode");
|
||||||
Series seriesNode = null;
|
// get uid of season:
|
||||||
if (series != null) {
|
Season seasonNode = null;
|
||||||
seriesNode = SeriesResource.getOrCreate(series, typeNode.id);
|
if (seriesNode == null && season != null) {
|
||||||
}
|
DataResource.removeTemporaryFile(tmpUID);
|
||||||
|
throw new InputException("season", "Season is set but no seraies is set !!");
|
||||||
System.out.println(" ==> " + seriesNode);
|
}
|
||||||
System.out.println("Find seasonNode");
|
if (season != null) {
|
||||||
// get uid of season:
|
seasonNode = SeasonResource.getOrCreate(season, seriesNode.id);
|
||||||
Season seasonNode = null;
|
}
|
||||||
if (seriesNode == null && season != null) {
|
|
||||||
DataResource.removeTemporaryFile(tmpUID);
|
System.out.println(" ==> " + seasonNode);
|
||||||
throw new InputException("season", "Season is set but no seraies is set !!");
|
System.out.println("add media");
|
||||||
}
|
|
||||||
if (season != null) {
|
long uniqueSQLID = -1;
|
||||||
seasonNode = SeasonResource.getOrCreate(season, seriesNode.id);
|
try {
|
||||||
}
|
Media media = new Media();
|
||||||
|
media.name = title;
|
||||||
System.out.println(" ==> " + seasonNode);
|
media.dataId = data.id;
|
||||||
System.out.println("add media");
|
media.typeId = typeNode.id;
|
||||||
|
media.seriesId = null;
|
||||||
|
if (seriesNode != null) {
|
||||||
long uniqueSQLID = -1;
|
media.seriesId = seriesNode.id;
|
||||||
try {
|
}
|
||||||
Media media = new Media();
|
media.seasonId = null;
|
||||||
media.name = title;
|
if (seasonNode != null) {
|
||||||
media.dataId = data.id;
|
media.seasonId = seasonNode.id;
|
||||||
media.typeId = typeNode.id;
|
}
|
||||||
media.seriesId = null;
|
media.episode = null;
|
||||||
if(seriesNode != null) {
|
if (episode != null && !episode.contentEquals("")) {
|
||||||
media.seriesId = seriesNode.id;
|
media.episode = Integer.parseInt(episode);
|
||||||
}
|
}
|
||||||
media.seasonId = null;
|
Media out = SqlWrapper.insert(media);
|
||||||
if (seasonNode != null) {
|
DataResource.removeTemporaryFile(tmpUID);
|
||||||
media.seasonId = seasonNode.id;
|
System.out.println("uploaded .... compleate: " + uniqueSQLID);
|
||||||
}
|
Media creation = get(uniqueSQLID);
|
||||||
media.episode = null;
|
return Response.ok(creation).build();
|
||||||
if (episode != null && ! episode.contentEquals("")) {
|
} catch (SQLException ex) {
|
||||||
media.episode = Integer.parseInt(episode);
|
ex.printStackTrace();
|
||||||
}
|
System.out.println("Catch error:" + ex.getMessage());
|
||||||
Media out = SqlWrapper.insert(media);
|
throw new FailException("Catch SQLerror ==> check server logs");
|
||||||
DataResource.removeTemporaryFile(tmpUID);
|
}
|
||||||
System.out.println("uploaded .... compleate: " + uniqueSQLID);
|
} catch (Exception ex) {
|
||||||
Media creation = get(uniqueSQLID);
|
System.out.println("Catch an unexpected error ... " + ex.getMessage());
|
||||||
return Response.ok(creation).build();
|
ex.printStackTrace();
|
||||||
} catch (SQLException ex) {
|
throw new FailException("Catch Exception ==> check server logs");
|
||||||
ex.printStackTrace();
|
}
|
||||||
System.out.println("Catch error:" + ex.getMessage());
|
}
|
||||||
throw new FailException("Catch SQLerror ==> check server logs");
|
|
||||||
}
|
@POST
|
||||||
} catch (Exception ex) {
|
@Path("{id}/add_cover")
|
||||||
System.out.println("Catch an unexpected error ... " + ex.getMessage());
|
@RolesAllowed("ADMIN")
|
||||||
ex.printStackTrace();
|
@Consumes({ MediaType.MULTIPART_FORM_DATA })
|
||||||
throw new FailException("Catch Exception ==> check server logs");
|
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);
|
||||||
@POST
|
}
|
||||||
@Path("{id}/add_cover")
|
|
||||||
@RolesAllowed("ADMIN")
|
@GET
|
||||||
@Consumes({MediaType.MULTIPART_FORM_DATA})
|
@Path("{id}/rm_cover/{coverId}")
|
||||||
public Response uploadCover(@PathParam("id") Long id,
|
@RolesAllowed("ADMIN")
|
||||||
@FormDataParam("fileName") String fileName,
|
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
|
||||||
@FormDataParam("file") InputStream fileInputStream,
|
AddOnManyToMany.removeLink(Media.class, id, "cover", coverId);
|
||||||
@FormDataParam("file") FormDataContentDisposition fileMetaData
|
return Response.ok(SqlWrapper.get(Media.class, id)).build();
|
||||||
) {
|
}
|
||||||
return DataTools.uploadCover(Media.class, id, fileName, fileInputStream, fileMetaData);
|
|
||||||
}
|
@DELETE
|
||||||
@GET
|
@Path("{id}")
|
||||||
@Path("{id}/rm_cover/{coverId}")
|
@RolesAllowed("ADMIN")
|
||||||
@RolesAllowed("ADMIN")
|
public Response delete(@PathParam("id") Long id) throws Exception {
|
||||||
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
|
SqlWrapper.delete(Media.class, id);
|
||||||
SqlWrapper.removeLink(Media.class, id, "cover", coverId);
|
|
||||||
return Response.ok(SqlWrapper.get(Media.class, id)).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@DELETE
|
|
||||||
@Path("{id}")
|
|
||||||
@RolesAllowed("ADMIN")
|
|
||||||
public Response delete(@PathParam("id") Long id) throws Exception {
|
|
||||||
SqlWrapper.setDelete(Media.class, id);
|
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
back/src/org/kar/karideo/migration/Migration20231015.java
Normal file
27
back/src/org/kar/karideo/migration/Migration20231015.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -2,48 +2,51 @@ package org.kar.karideo.model;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.kar.archidata.annotation.SQLComment;
|
import org.kar.archidata.model.Data;
|
||||||
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.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.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.ManyToMany;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@SQLTableName ("media")
|
@Entity
|
||||||
@SQLIfNotExists
|
@Table(name = "media")
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
//@SQLDelete(sql = "UPDATE table_product SET deleted = true WHERE id=?")
|
||||||
|
//@Where(clause = "deleted=false")
|
||||||
public class Media extends GenericTable {
|
public class Media extends GenericTable {
|
||||||
@SQLNotNull
|
// Name of the media (this represent the title)
|
||||||
@SQLComment("Name of the media (this represent the title)")
|
@Column(nullable = false)
|
||||||
public String name;
|
public String name;
|
||||||
@SQLComment("Description of the media")
|
// Description of the media
|
||||||
public String description;
|
public String description;
|
||||||
@SQLNotNull
|
// Foreign Key Id of the data
|
||||||
@SQLComment("Foreign Key Id of the data")
|
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Data.class)
|
||||||
@SQLForeignKey("data")
|
@Column(nullable = false)
|
||||||
public Long dataId;
|
public Long dataId;
|
||||||
@SQLComment("Type of the media")
|
// Type of the media")
|
||||||
@SQLForeignKey("type")
|
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Type.class)
|
||||||
public Long typeId;
|
public Long typeId;
|
||||||
@SQLComment("Series reference of the media")
|
// Series reference of the media
|
||||||
@SQLForeignKey("series")
|
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Series.class)
|
||||||
public Long seriesId;
|
public Long seriesId;
|
||||||
@SQLComment("Saison reference of the media")
|
// Saison reference of the media
|
||||||
@SQLForeignKey("season")
|
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Season.class)
|
||||||
public Long seasonId;
|
public Long seasonId;
|
||||||
@SQLComment("Episide Id")
|
// Episide Id
|
||||||
public Integer episode;
|
public Integer episode;
|
||||||
@SQLComment("")
|
// ")
|
||||||
public Integer date;
|
public Integer date;
|
||||||
@SQLComment("Creation years of the media")
|
// Creation years of the media
|
||||||
public Integer time;
|
public Integer time;
|
||||||
@SQLComment("Limitation Age of the media")
|
// Limitation Age of the media
|
||||||
public Integer ageLimit;
|
public Integer ageLimit;
|
||||||
@SQLComment("List of Id of the sopecific covers")
|
// List of Id of the specific covers
|
||||||
@SQLTableLinkGeneric
|
@ManyToMany(fetch = FetchType.LAZY, targetEntity = Data.class)
|
||||||
public List<Long> covers = null;
|
public List<Long> covers = null;
|
||||||
}
|
}
|
||||||
|
@ -3,30 +3,32 @@ package org.kar.karideo.model;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.kar.archidata.annotation.SQLComment;
|
import org.kar.archidata.annotation.SQLComment;
|
||||||
import org.kar.archidata.annotation.SQLForeignKey;
|
|
||||||
import org.kar.archidata.annotation.SQLIfNotExists;
|
import org.kar.archidata.annotation.SQLIfNotExists;
|
||||||
import org.kar.archidata.annotation.SQLNotNull;
|
import org.kar.archidata.model.Data;
|
||||||
import org.kar.archidata.annotation.SQLTableLinkGeneric;
|
|
||||||
import org.kar.archidata.annotation.SQLTableName;
|
|
||||||
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;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@SQLTableName ("season")
|
@Table(name = "season")
|
||||||
@SQLIfNotExists
|
@SQLIfNotExists
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class Season extends GenericTable {
|
public class Season extends GenericTable {
|
||||||
@SQLNotNull
|
@Column(nullable = false)
|
||||||
@SQLComment("Name of the media (this represent the title)")
|
@SQLComment("Name of the media (this represent the title)")
|
||||||
public String name;
|
public String name;
|
||||||
@SQLComment("Description of the media")
|
@SQLComment("Description of the media")
|
||||||
public String description;
|
public String description;
|
||||||
@SQLNotNull
|
@Column(nullable = false)
|
||||||
@SQLComment("series parent ID")
|
@SQLComment("series parent ID")
|
||||||
@SQLForeignKey("series")
|
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Series.class)
|
||||||
public Long parentId;
|
public Long parentId;
|
||||||
@SQLComment("List of Id of the sopecific covers")
|
@SQLComment("List of Id of the sopecific covers")
|
||||||
@SQLTableLinkGeneric
|
@ManyToMany(fetch = FetchType.LAZY, targetEntity = Data.class)
|
||||||
public List<Long> covers = null;
|
public List<Long> covers = null;
|
||||||
}
|
}
|
@ -3,30 +3,32 @@ package org.kar.karideo.model;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.kar.archidata.annotation.SQLComment;
|
import org.kar.archidata.annotation.SQLComment;
|
||||||
import org.kar.archidata.annotation.SQLForeignKey;
|
|
||||||
import org.kar.archidata.annotation.SQLIfNotExists;
|
import org.kar.archidata.annotation.SQLIfNotExists;
|
||||||
import org.kar.archidata.annotation.SQLNotNull;
|
import org.kar.archidata.model.Data;
|
||||||
import org.kar.archidata.annotation.SQLTableLinkGeneric;
|
|
||||||
import org.kar.archidata.annotation.SQLTableName;
|
|
||||||
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;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@SQLTableName ("series")
|
@Table(name = "series")
|
||||||
@SQLIfNotExists
|
@SQLIfNotExists
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class Series extends GenericTable {
|
public class Series extends GenericTable {
|
||||||
@SQLNotNull
|
@Column(nullable = false)
|
||||||
@SQLComment("Name of the media (this represent the title)")
|
@SQLComment("Name of the media (this represent the title)")
|
||||||
public String name;
|
public String name;
|
||||||
@SQLComment("Description of the media")
|
@SQLComment("Description of the media")
|
||||||
public String description;
|
public String description;
|
||||||
@SQLNotNull
|
@Column(nullable = false)
|
||||||
@SQLComment("series parent ID")
|
@SQLComment("series parent ID")
|
||||||
@SQLForeignKey("type")
|
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Type.class)
|
||||||
public Long parentId;
|
public Long parentId;
|
||||||
@SQLComment("List of Id of the sopecific covers")
|
@SQLComment("List of Id of the sopecific covers")
|
||||||
@SQLTableLinkGeneric
|
@ManyToMany(fetch = FetchType.LAZY, targetEntity = Data.class)
|
||||||
public List<Long> covers = null;
|
public List<Long> covers = null;
|
||||||
}
|
}
|
||||||
|
@ -4,24 +4,26 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.kar.archidata.annotation.SQLComment;
|
import org.kar.archidata.annotation.SQLComment;
|
||||||
import org.kar.archidata.annotation.SQLIfNotExists;
|
import org.kar.archidata.annotation.SQLIfNotExists;
|
||||||
import org.kar.archidata.annotation.SQLNotNull;
|
import org.kar.archidata.model.Data;
|
||||||
import org.kar.archidata.annotation.SQLTableLinkGeneric;
|
|
||||||
import org.kar.archidata.annotation.SQLTableName;
|
|
||||||
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;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@SQLTableName ("type")
|
@Table(name = "type")
|
||||||
@SQLIfNotExists
|
@SQLIfNotExists
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class Type extends GenericTable {
|
public class Type extends GenericTable {
|
||||||
@SQLNotNull
|
@Column(nullable = false)
|
||||||
@SQLComment("Name of the media (this represent the title)")
|
@SQLComment("Name of the media (this represent the title)")
|
||||||
public String name;
|
public String name;
|
||||||
@SQLComment("Description of the media")
|
@SQLComment("Description of the media")
|
||||||
public String description;
|
public String description;
|
||||||
@SQLComment("List of Id of the sopecific covers")
|
@SQLComment("List of Id of the sopecific covers")
|
||||||
@SQLTableLinkGeneric
|
@ManyToMany(fetch = FetchType.LAZY, targetEntity = Data.class)
|
||||||
public List<Long> covers = null;
|
public List<Long> covers = null;
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package org.kar.karideo.model;
|
package org.kar.karideo.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 UserKarideo extends User {
|
public class UserKarideo extends User {
|
||||||
|
@ -1,34 +1,35 @@
|
|||||||
package org.kar.karideo.model;
|
package org.kar.karideo.model;
|
||||||
|
|
||||||
import org.kar.archidata.annotation.SQLComment;
|
import org.kar.archidata.annotation.SQLComment;
|
||||||
import org.kar.archidata.annotation.SQLForeignKey;
|
|
||||||
import org.kar.archidata.annotation.SQLIfNotExists;
|
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 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.ManyToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@SQLTableName ("userMediaAdvancement")
|
@Table(name = "userMediaAdvancement")
|
||||||
@SQLIfNotExists
|
@SQLIfNotExists
|
||||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class UserMediaAdvancement extends GenericTable {
|
public class UserMediaAdvancement extends GenericTable {
|
||||||
@SQLNotNull
|
@Column(nullable = false)
|
||||||
@SQLComment("Foreign Key Id of the user")
|
@SQLComment("Foreign Key Id of the user")
|
||||||
@SQLForeignKey("user")
|
@ManyToOne(fetch = FetchType.LAZY, targetEntity = UserKarideo.class)
|
||||||
public long userId;
|
public long userId;
|
||||||
@SQLNotNull
|
@Column(nullable = false)
|
||||||
@SQLComment("Id of the media")
|
@SQLComment("Id of the media")
|
||||||
@SQLForeignKey("media")
|
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Media.class)
|
||||||
public long mediaId;
|
public long mediaId;
|
||||||
@SQLNotNull
|
@Column(nullable = false)
|
||||||
@SQLComment("Percent of admencement in the media")
|
@SQLComment("Percent of admencement in the media")
|
||||||
public float percent;
|
public float percent;
|
||||||
@SQLNotNull
|
@Column(nullable = false)
|
||||||
@SQLComment("Number of second of admencement in the media")
|
@SQLComment("Number of second of admencement in the media")
|
||||||
public int time;
|
public int time;
|
||||||
@SQLNotNull
|
@Column(nullable = false)
|
||||||
@SQLComment("Number of time this media has been read")
|
@SQLComment("Number of time this media has been read")
|
||||||
public int count;
|
public int count;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"all": "npm run build && npm run test",
|
"all": "npm run build && npm run test",
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"start": "ng serve --configuration=develop --watch --port 4202",
|
"dev": "ng serve --configuration=develop --watch --port 4202",
|
||||||
"build": "ng build --prod",
|
"build": "ng build --prod",
|
||||||
"test": "ng test",
|
"test": "ng test",
|
||||||
"lint": "ng lint",
|
"lint": "ng lint",
|
||||||
@ -38,4 +38,4 @@
|
|||||||
"@angular/compiler-cli": "^14.2.10",
|
"@angular/compiler-cli": "^14.2.10",
|
||||||
"@angular/language-service": "^14.2.10"
|
"@angular/language-service": "^14.2.10"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user