diff --git a/back/.checkstyle b/back/.checkstyle
new file mode 100644
index 0000000..5783bc0
--- /dev/null
+++ b/back/.checkstyle
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/back/Dockerfile b/back/Dockerfile
index 8fc1c69..6571dab 100644
--- a/back/Dockerfile
+++ b/back/Dockerfile
@@ -1,15 +1,15 @@
-FROM maven:3.6.3-openjdk-16 AS build
+FROM maven:3-openjdk-18 AS build
COPY pom.xml /tmp/
COPY src /tmp/src/
WORKDIR /tmp/
RUN mvn clean compile assembly:single
-
-
FROM bellsoft/liberica-openjdk-alpine:latest
ENV LANG=C.UTF-8
+# add wget to manage the health check...
+RUN apk add --no-cache wget
RUN mkdir /application/
COPY --from=build /tmp/out/maven/*.jar /application/application.jar
diff --git a/back/README.md b/back/README.md
index b91b705..b3e5090 100644
--- a/back/README.md
+++ b/back/README.md
@@ -2,16 +2,24 @@ Generic backend for karusic in java
===================================
-
-
mvn install
+mvn compile
+
+mvn package
+
+// download all dependency in out/maven/dependency
+mvn dependency:copy-dependencies
+
+java -cp out/maven/kar-karusic-0.1.0.jar org.kar.karusic.WebLauncher
+
+
// create a single package jar
mvn clean compile assembly:single
-java -cp out/maven/karusic-0.1.0-jar-with-dependencies.jar org.kar.karideo.WebLauncher
+java -cp out/maven/karusic-0.1.0-jar-with-dependencies.jar org.kar.karusic.WebLauncher
diff --git a/back/karusic-back.iml b/back/karusic-back.iml
deleted file mode 100644
index c56ba78..0000000
--- a/back/karusic-back.iml
+++ /dev/null
@@ -1,61 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/back/pom.xml b/back/pom.xml
index 5cf9696..45a79ab 100644
--- a/back/pom.xml
+++ b/back/pom.xml
@@ -8,7 +8,6 @@
3.1
17
17
-
3.1.1
@@ -17,7 +16,6 @@
https://gitea.atria-soft.org/api/packages/kangaroo-and-rabbit/maven
-
kangaroo-and-rabbit
@@ -28,19 +26,39 @@
org.slf4j
slf4j-simple
2.0.7
-
-
-
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.10.0
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.10.0
+ test
+
+
src
test/src
- ${project.basedir}/out/maven/
+ ${project.basedir}/out/maven/
src/resources
+
+
+ ${basedir}/test/resources
+
+
org.apache.maven.plugins
@@ -49,16 +67,15 @@
${maven.compiler.source}
${maven.compiler.target}
-
- org.codehaus.mojo
- exec-maven-plugin
- 1.4.0
-
- org.kar.karusic.WebLauncher
-
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.4.0
+
+ org.kar.karusic.WebLauncher
+
@@ -80,27 +97,28 @@
maven-surefire-plugin
3.0.0-M5
-
- maven-assembly-plugin
-
-
-
- fully.qualified.MainClass
-
-
-
- jar-with-dependencies
-
-
-
+
+ maven-assembly-plugin
+
+
+
+ fully.qualified.MainClass
+
+
+
+ jar-with-dependencies
+
+
+
@@ -125,6 +163,23 @@
true
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 3.1.0
+
+
+ exec-application
+ package
+
+ java
+
+
+
+
+ org.kar.karusic.WebLauncher
+
+
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- 1.4.0
-
- io.scenarium.oauth.WebLauncher
-
-
-
-
- org.apache.maven.plugins
- maven-source-plugin
-
-
- attach-sources
-
- jar
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- 3.0.0-M5
-
-
- maven-assembly-plugin
-
-
-
- fully.qualified.MainClass
-
-
-
- jar-with-dependencies
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 3.2.0
-
- private
- true
-
-
-
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 3.2.0
-
- public
-
-
-
-
-
-
\ No newline at end of file
diff --git a/back/src/org/kar/karusic/WebLauncher.java b/back/src/org/kar/karusic/WebLauncher.java
index 0a2190b..97a792d 100755
--- a/back/src/org/kar/karusic/WebLauncher.java
+++ b/back/src/org/kar/karusic/WebLauncher.java
@@ -2,23 +2,11 @@ package org.kar.karusic;
import java.net.URI;
-import jakarta.ws.rs.core.UriBuilder;
-
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.karusic.api.AlbumResource;
-import org.kar.karusic.api.ArtistResource;
-import org.kar.karusic.api.Front;
-import org.kar.karusic.api.GenderResource;
-import org.kar.karusic.api.HealthCheck;
-import org.kar.karusic.api.PlaylistResource;
-import org.kar.karusic.api.TrackResource;
-import org.kar.karusic.api.UserResource;
-import org.kar.karusic.filter.KarusicAuthenticationFilter;
-import org.kar.karusic.migration.Initialization;
import org.kar.archidata.GlobalConfiguration;
import org.kar.archidata.UpdateJwtPublicKey;
import org.kar.archidata.api.DataResource;
@@ -30,23 +18,37 @@ 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.slf4j.LoggerFactory;
+import org.kar.karusic.api.AlbumResource;
+import org.kar.karusic.api.ArtistResource;
+import org.kar.karusic.api.Front;
+import org.kar.karusic.api.GenderResource;
+import org.kar.karusic.api.HealthCheck;
+import org.kar.karusic.api.PlaylistResource;
+import org.kar.karusic.api.TrackResource;
+import org.kar.karusic.api.UserResource;
+import org.kar.karusic.filter.KarusicAuthenticationFilter;
+import org.kar.karusic.migration.Initialization;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import jakarta.ws.rs.core.UriBuilder;
public class WebLauncher {
final static Logger LOGGER = LoggerFactory.getLogger(WebLauncher.class);
- protected UpdateJwtPublicKey keyUpdater = null;
+ protected UpdateJwtPublicKey keyUpdater = null;
+ protected HttpServer server = null;
+
public WebLauncher() {
ConfigBaseVariable.bdDatabase = "karusic";
}
- private static URI getBaseURI() {
- return UriBuilder.fromUri(ConfigBaseVariable.getlocalAddress()).build();
- }
+ private static URI getBaseURI() {
+ return UriBuilder.fromUri(ConfigBaseVariable.getlocalAddress()).build();
+ }
public void migrateDB() throws Exception {
WebLauncher.LOGGER.info("Create migration engine");
- MigrationEngine migrationEngine = new MigrationEngine();
+ final MigrationEngine migrationEngine = new MigrationEngine();
WebLauncher.LOGGER.info("Add initialization");
migrationEngine.setInit(new Initialization());
WebLauncher.LOGGER.info("Add migration since last version");
@@ -56,9 +58,9 @@ public class WebLauncher {
WebLauncher.LOGGER.info("Migrate the DB [STOP]");
}
- public static void main(String[] args) throws Exception {
+ public static void main(final String[] args) throws Exception {
WebLauncher.LOGGER.info("[START] application wake UP");
- WebLauncher launcher = new WebLauncher();
+ final WebLauncher launcher = new WebLauncher();
launcher.migrateDB();
launcher.process();
@@ -68,43 +70,42 @@ public class WebLauncher {
launcher.stopOther();
WebLauncher.LOGGER.info("STOP the REST server:");
}
-
- public void process() throws InterruptedException {
+ public void process() throws InterruptedException {
// ===================================================================
// Configure resources
// ===================================================================
- ResourceConfig rc = new ResourceConfig();
-
- // add multipart 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(KarusicAuthenticationFilter.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(AlbumResource.class);
- rc.register(ArtistResource.class);
- rc.register(GenderResource.class);
- rc.register(PlaylistResource.class);
- rc.register(TrackResource.class);
- rc.register(DataResource.class);
-
- rc.register(HealthCheck.class);
- rc.register(Front.class);
-
- // add jackson to be discover when we are ins standalone server
- rc.register(JacksonFeature.class);
- // enable this to show low level request
- //rc.property(LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_SERVER, Level.WARNING.getName());
+ final ResourceConfig rc = new ResourceConfig();
+
+ // add multipart 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(KarusicAuthenticationFilter.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(AlbumResource.class);
+ rc.register(ArtistResource.class);
+ rc.register(GenderResource.class);
+ rc.register(PlaylistResource.class);
+ rc.register(TrackResource.class);
+ rc.register(DataResource.class);
+
+ rc.register(HealthCheck.class);
+ rc.register(Front.class);
+
+ // add jackson to be discover when we are ins standalone server
+ rc.register(JacksonFeature.class);
+ // enable this to show low level request
+ //rc.property(LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_SERVER, Level.WARNING.getName());
//System.out.println("Connect on the BDD:");
//System.out.println(" getDBHost: '" + ConfigVariable.getDBHost() + "'");
@@ -114,12 +115,13 @@ public class WebLauncher {
//System.out.println(" getDBName: '" + ConfigVariable.getDBName() + "'");
System.out.println(" ==> " + GlobalConfiguration.dbConfig);
System.out.println("OAuth service " + getBaseURI());
- HttpServer server = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc);
+ this.server = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc);
+ final HttpServer serverLink = this.server;
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Stopping server..");
- server.shutdownNow();
+ serverLink.shutdownNow();
}
}, "shutdownHook"));
@@ -129,25 +131,32 @@ public class WebLauncher {
this.keyUpdater = new UpdateJwtPublicKey();
this.keyUpdater.start();
- // ===================================================================
+ // ===================================================================
// run JERSEY
- // ===================================================================
+ // ===================================================================
try {
- server.start();
+ this.server.start();
LOGGER.info("Jersey app started at {}", getBaseURI());
- } catch (Exception e) {
+ } catch (final Exception e) {
LOGGER.error("There was an error while starting Grizzly HTTP server.");
e.printStackTrace();
}
- }
-
- public void stopOther() {
- keyUpdater.kill();
+ }
+
+ public void stop() {
+ if (this.server != null) {
+ this.server.shutdownNow();
+ this.server = null;
+ }
+ }
+
+ public void stopOther() {
+ this.keyUpdater.kill();
try {
- keyUpdater.join(4000, 0);
- } catch (InterruptedException e) {
+ this.keyUpdater.join(4000, 0);
+ } catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
- }
+ }
}
diff --git a/back/src/org/kar/karusic/api/AlbumResource.java b/back/src/org/kar/karusic/api/AlbumResource.java
index 3aa5b06..6f8a5e8 100644
--- a/back/src/org/kar/karusic/api/AlbumResource.java
+++ b/back/src/org/kar/karusic/api/AlbumResource.java
@@ -5,12 +5,12 @@ import java.util.List;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
-import org.kar.archidata.annotation.security.RolesAllowed;
-import org.kar.archidata.sqlWrapper.SqlWrapper;
-import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
+import org.kar.archidata.dataAccess.DataAccess;
+import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
import org.kar.archidata.util.DataTools;
import org.kar.karusic.model.Album;
+import jakarta.annotation.security.RolesAllowed;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
@@ -25,75 +25,75 @@ import jakarta.ws.rs.core.Response;
@Path("/album")
@Produces({ MediaType.APPLICATION_JSON })
public class AlbumResource {
-
+
@GET
@Path("{id}")
@RolesAllowed("USER")
- public static Album getWithId(@PathParam("id") Long id) throws Exception {
- return SqlWrapper.get(Album.class, id);
+ public static Album getWithId(@PathParam("id") final Long id) throws Exception {
+ return DataAccess.get(Album.class, id);
}
-
+
@GET
@RolesAllowed("USER")
public List get() throws Exception {
- return SqlWrapper.gets(Album.class);
+ return DataAccess.gets(Album.class);
}
@POST
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
- public Album post(String jsonRequest) throws Exception {
- return SqlWrapper.insertWithJson(Album.class, jsonRequest);
+ public Album post(final String jsonRequest) throws Exception {
+ return DataAccess.insertWithJson(Album.class, jsonRequest);
}
-
+
@PUT
@Path("{id}")
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
- public Album put(@PathParam("id") Long id, String jsonRequest) throws Exception {
- SqlWrapper.update(Album.class, id, jsonRequest);
- return SqlWrapper.get(Album.class, id);
+ public Album put(@PathParam("id") final Long id, final String jsonRequest) throws Exception {
+ DataAccess.updateWithJson(Album.class, id, jsonRequest);
+ return DataAccess.get(Album.class, id);
}
-
+
@DELETE
@Path("{id}")
@RolesAllowed("ADMIN")
- public Response delete(@PathParam("id") Long id) throws Exception {
- SqlWrapper.delete(Album.class, id);
+ public Response delete(@PathParam("id") final Long id) throws Exception {
+ DataAccess.delete(Album.class, id);
return Response.ok().build();
}
-
+
@POST
@Path("{id}/add_track/{trackId}")
@RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
- public Album addTrack(@PathParam("id") Long id, @PathParam("trackId") Long trackId) throws Exception {
+ public Album addTrack(@PathParam("id") final Long id, @PathParam("trackId") final Long trackId) throws Exception {
AddOnManyToMany.removeLink(Album.class, id, "track", trackId);
- return SqlWrapper.get(Album.class, id);
+ return DataAccess.get(Album.class, id);
}
-
+
@GET
@Path("{id}/rm_track/{trackId}")
@RolesAllowed("ADMIN")
- public Album removeTrack(@PathParam("id") Long id, @PathParam("trackId") Long trackId) throws Exception {
+ public Album removeTrack(@PathParam("id") final Long id, @PathParam("trackId") final Long trackId) throws Exception {
AddOnManyToMany.removeLink(Album.class, id, "track", trackId);
- return SqlWrapper.get(Album.class, id);
+ return DataAccess.get(Album.class, id);
}
-
+
@POST
@Path("{id}/add_cover")
@RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
- public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
- @FormDataParam("file") FormDataContentDisposition fileMetaData) {
+ public Response uploadCover(@PathParam("id") final Long id, @FormDataParam("fileName") final String fileName, @FormDataParam("file") final InputStream fileInputStream,
+ @FormDataParam("file") final FormDataContentDisposition fileMetaData) {
return DataTools.uploadCover(Album.class, id, fileName, fileInputStream, fileMetaData);
}
-
+
@GET
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
- public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
+ public Response removeCover(@PathParam("id") final Long id, @PathParam("coverId") final Long coverId) throws Exception {
AddOnManyToMany.removeLink(Album.class, id, "cover", coverId);
- return Response.ok(SqlWrapper.get(Album.class, id)).build();
+ return Response.ok(DataAccess.get(Album.class, id)).build();
}
}
diff --git a/back/src/org/kar/karusic/api/ArtistResource.java b/back/src/org/kar/karusic/api/ArtistResource.java
index 2e9dc4f..650d647 100644
--- a/back/src/org/kar/karusic/api/ArtistResource.java
+++ b/back/src/org/kar/karusic/api/ArtistResource.java
@@ -5,12 +5,12 @@ import java.util.List;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
-import org.kar.archidata.annotation.security.RolesAllowed;
-import org.kar.archidata.sqlWrapper.SqlWrapper;
-import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
+import org.kar.archidata.dataAccess.DataAccess;
+import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
import org.kar.archidata.util.DataTools;
import org.kar.karusic.model.Artist;
+import jakarta.annotation.security.RolesAllowed;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
@@ -25,58 +25,58 @@ import jakarta.ws.rs.core.Response;
@Path("/artist")
@Produces({ MediaType.APPLICATION_JSON })
public class ArtistResource {
-
+
@GET
@Path("{id}")
@RolesAllowed("USER")
- public static Artist getWithId(@PathParam("id") Long id) throws Exception {
- return SqlWrapper.get(Artist.class, id);
+ public static Artist getWithId(@PathParam("id") final Long id) throws Exception {
+ return DataAccess.get(Artist.class, id);
}
-
+
@GET
@RolesAllowed("USER")
public List get() throws Exception {
- return SqlWrapper.gets(Artist.class);
+ return DataAccess.gets(Artist.class);
}
@POST
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
- public Artist put(String jsonRequest) throws Exception {
- return SqlWrapper.insertWithJson(Artist.class, jsonRequest);
+ public Artist put(final String jsonRequest) throws Exception {
+ return DataAccess.insertWithJson(Artist.class, jsonRequest);
}
-
+
@PUT
@Path("{id}")
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
- public Artist put(@PathParam("id") Long id, String jsonRequest) throws Exception {
- SqlWrapper.update(Artist.class, id, jsonRequest);
- return SqlWrapper.get(Artist.class, id);
+ public Artist put(@PathParam("id") final Long id, final String jsonRequest) throws Exception {
+ DataAccess.updateWithJson(Artist.class, id, jsonRequest);
+ return DataAccess.get(Artist.class, id);
}
-
+
@DELETE
@Path("{id}")
@RolesAllowed("ADMIN")
- public Response delete(@PathParam("id") Long id) throws Exception {
- SqlWrapper.delete(Artist.class, id);
+ public Response delete(@PathParam("id") final Long id) throws Exception {
+ DataAccess.delete(Artist.class, id);
return Response.ok().build();
}
-
+
@POST
@Path("{id}/add_cover")
@RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
- public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
- @FormDataParam("file") FormDataContentDisposition fileMetaData) {
+ public Response uploadCover(@PathParam("id") final Long id, @FormDataParam("fileName") final String fileName, @FormDataParam("file") final InputStream fileInputStream,
+ @FormDataParam("file") final FormDataContentDisposition fileMetaData) {
return DataTools.uploadCover(Artist.class, id, fileName, fileInputStream, fileMetaData);
}
-
+
@GET
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
- public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
+ public Response removeCover(@PathParam("id") final Long id, @PathParam("coverId") final Long coverId) throws Exception {
AddOnManyToMany.removeLink(Artist.class, id, "cover", coverId);
- return Response.ok(SqlWrapper.get(Artist.class, id)).build();
+ return Response.ok(DataAccess.get(Artist.class, id)).build();
}
}
diff --git a/back/src/org/kar/karusic/api/Front.java b/back/src/org/kar/karusic/api/Front.java
index 0d972e1..ed978c7 100644
--- a/back/src/org/kar/karusic/api/Front.java
+++ b/back/src/org/kar/karusic/api/Front.java
@@ -1,22 +1,14 @@
package org.kar.karusic.api;
-import java.io.File;
-import java.util.List;
-
-import org.kar.archidata.annotation.security.PermitAll;
-import jakarta.ws.rs.*;
-import jakarta.ws.rs.core.CacheControl;
-import jakarta.ws.rs.core.PathSegment;
-import jakarta.ws.rs.core.Response;
-import jakarta.ws.rs.core.Response.ResponseBuilder;
-
import org.kar.archidata.api.FrontGeneric;
import org.kar.karusic.util.ConfigVariable;
+import jakarta.ws.rs.Path;
+
@Path("/front")
public class Front extends FrontGeneric {
public Front() {
this.baseFrontFolder = ConfigVariable.getFrontFolder();
-
+
}
}
diff --git a/back/src/org/kar/karusic/api/GenderResource.java b/back/src/org/kar/karusic/api/GenderResource.java
index 6255804..2957b65 100644
--- a/back/src/org/kar/karusic/api/GenderResource.java
+++ b/back/src/org/kar/karusic/api/GenderResource.java
@@ -5,12 +5,12 @@ import java.util.List;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
-import org.kar.archidata.annotation.security.RolesAllowed;
-import org.kar.archidata.sqlWrapper.SqlWrapper;
-import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
+import org.kar.archidata.dataAccess.DataAccess;
+import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
import org.kar.archidata.util.DataTools;
import org.kar.karusic.model.Gender;
+import jakarta.annotation.security.RolesAllowed;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
@@ -25,58 +25,58 @@ import jakarta.ws.rs.core.Response;
@Path("/gender")
@Produces({ MediaType.APPLICATION_JSON })
public class GenderResource {
-
+
@GET
@Path("{id}")
@RolesAllowed("USER")
- public static Gender getWithId(@PathParam("id") Long id) throws Exception {
- return SqlWrapper.get(Gender.class, id);
+ public static Gender getWithId(@PathParam("id") final Long id) throws Exception {
+ return DataAccess.get(Gender.class, id);
}
-
+
@GET
@RolesAllowed("USER")
public List get() throws Exception {
- return SqlWrapper.gets(Gender.class);
+ return DataAccess.gets(Gender.class);
}
@POST
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
- public Gender put(String jsonRequest) throws Exception {
- return SqlWrapper.insertWithJson(Gender.class, jsonRequest);
+ public Gender put(final String jsonRequest) throws Exception {
+ return DataAccess.insertWithJson(Gender.class, jsonRequest);
}
-
+
@PUT
@Path("{id}")
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
- public Gender put(@PathParam("id") Long id, String jsonRequest) throws Exception {
- SqlWrapper.update(Gender.class, id, jsonRequest);
- return SqlWrapper.get(Gender.class, id);
+ public Gender put(@PathParam("id") final Long id, final String jsonRequest) throws Exception {
+ DataAccess.updateWithJson(Gender.class, id, jsonRequest);
+ return DataAccess.get(Gender.class, id);
}
-
+
@DELETE
@Path("{id}")
@RolesAllowed("ADMIN")
- public Response delete(@PathParam("id") Long id) throws Exception {
- SqlWrapper.delete(Gender.class, id);
+ public Response delete(@PathParam("id") final Long id) throws Exception {
+ DataAccess.delete(Gender.class, id);
return Response.ok().build();
}
-
+
@POST
@Path("{id}/add_cover")
@RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
- public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
- @FormDataParam("file") FormDataContentDisposition fileMetaData) {
+ public Response uploadCover(@PathParam("id") final Long id, @FormDataParam("fileName") final String fileName, @FormDataParam("file") final InputStream fileInputStream,
+ @FormDataParam("file") final FormDataContentDisposition fileMetaData) {
return DataTools.uploadCover(Gender.class, id, fileName, fileInputStream, fileMetaData);
}
-
+
@GET
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
- public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
+ public Response removeCover(@PathParam("id") final Long id, @PathParam("coverId") final Long coverId) throws Exception {
AddOnManyToMany.removeLink(Gender.class, id, "cover", coverId);
- return Response.ok(SqlWrapper.get(Gender.class, id)).build();
+ return Response.ok(DataAccess.get(Gender.class, id)).build();
}
}
diff --git a/back/src/org/kar/karusic/api/HealthCheck.java b/back/src/org/kar/karusic/api/HealthCheck.java
index a088855..5a1ec09 100644
--- a/back/src/org/kar/karusic/api/HealthCheck.java
+++ b/back/src/org/kar/karusic/api/HealthCheck.java
@@ -1,28 +1,29 @@
package org.kar.karusic.api;
-import org.kar.archidata.annotation.security.PermitAll;
-import jakarta.ws.rs.core.Response;
-import jakarta.ws.rs.*;
-import jakarta.ws.rs.core.MediaType;
-
+import org.kar.archidata.exception.FailException;
+import org.kar.archidata.util.ConfigBaseVariable;
import org.kar.archidata.util.JWTWrapper;
+import jakarta.annotation.security.PermitAll;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+
@Path("/health_check")
@Produces(MediaType.APPLICATION_JSON)
public class HealthCheck {
- public class HealthResult {
- public String value;
- public HealthResult(String value) {
- this.value = value;
+
+ public record HealthResult(
+ String value) {};
+
+ @GET
+ @PermitAll
+ public HealthResult getHealth() throws FailException {
+ if (JWTWrapper.getPublicKeyJson() == null && !ConfigBaseVariable.getTestMode()) {
+ throw new FailException(Response.Status.INTERNAL_SERVER_ERROR, "Missing Jwt public token");
}
+ return new HealthResult("alive and kicking");
}
- // todo : do it better...
- @GET
- @PermitAll
- public Response getHealth() {
- if (JWTWrapper.getPublicKeyJson() == null) {
- return Response.status(500).entity(new HealthResult("Missing Jwt public token")).build();
- }
- return Response.status(200).entity(new HealthResult("alive and kicking")).build();
- }
}
diff --git a/back/src/org/kar/karusic/api/PlaylistResource.java b/back/src/org/kar/karusic/api/PlaylistResource.java
index afdf32f..995e05f 100644
--- a/back/src/org/kar/karusic/api/PlaylistResource.java
+++ b/back/src/org/kar/karusic/api/PlaylistResource.java
@@ -5,12 +5,12 @@ import java.util.List;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
-import org.kar.archidata.annotation.security.RolesAllowed;
-import org.kar.archidata.sqlWrapper.SqlWrapper;
-import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
+import org.kar.archidata.dataAccess.DataAccess;
+import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
import org.kar.archidata.util.DataTools;
import org.kar.karusic.model.Playlist;
+import jakarta.annotation.security.RolesAllowed;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
@@ -25,75 +25,75 @@ import jakarta.ws.rs.core.Response;
@Path("/playlist")
@Produces({ MediaType.APPLICATION_JSON })
public class PlaylistResource {
-
+
@GET
@Path("{id}")
@RolesAllowed("USER")
- public static Playlist getWithId(@PathParam("id") Long id) throws Exception {
- return SqlWrapper.get(Playlist.class, id);
+ public static Playlist getWithId(@PathParam("id") final Long id) throws Exception {
+ return DataAccess.get(Playlist.class, id);
}
-
+
@GET
@RolesAllowed("USER")
public List get() throws Exception {
- return SqlWrapper.gets(Playlist.class);
+ return DataAccess.gets(Playlist.class);
}
@POST
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
- public Playlist put(String jsonRequest) throws Exception {
- return SqlWrapper.insertWithJson(Playlist.class, jsonRequest);
+ public Playlist put(final String jsonRequest) throws Exception {
+ return DataAccess.insertWithJson(Playlist.class, jsonRequest);
}
-
+
@PUT
@Path("{id}")
@RolesAllowed("ADMIN")
@Consumes(MediaType.APPLICATION_JSON)
- public Playlist put(@PathParam("id") Long id, String jsonRequest) throws Exception {
- SqlWrapper.update(Playlist.class, id, jsonRequest);
- return SqlWrapper.get(Playlist.class, id);
+ public Playlist put(@PathParam("id") final Long id, final String jsonRequest) throws Exception {
+ DataAccess.updateWithJson(Playlist.class, id, jsonRequest);
+ return DataAccess.get(Playlist.class, id);
}
-
+
@DELETE
@Path("{id}")
@RolesAllowed("ADMIN")
- public Response delete(@PathParam("id") Long id) throws Exception {
- SqlWrapper.delete(Playlist.class, id);
+ public Response delete(@PathParam("id") final Long id) throws Exception {
+ DataAccess.delete(Playlist.class, id);
return Response.ok().build();
}
-
+
@POST
@Path("{id}/add_track/{trackId}")
@RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
- public Playlist addTrack(@PathParam("id") Long id, @PathParam("trackId") Long trackId) throws Exception {
+ public Playlist addTrack(@PathParam("id") final Long id, @PathParam("trackId") final Long trackId) throws Exception {
AddOnManyToMany.removeLink(Playlist.class, id, "track", trackId);
- return SqlWrapper.get(Playlist.class, id);
+ return DataAccess.get(Playlist.class, id);
}
-
+
@GET
@Path("{id}/rm_track/{trackId}")
@RolesAllowed("ADMIN")
- public Playlist removeTrack(@PathParam("id") Long id, @PathParam("trackId") Long trackId) throws Exception {
+ public Playlist removeTrack(@PathParam("id") final Long id, @PathParam("trackId") final Long trackId) throws Exception {
AddOnManyToMany.removeLink(Playlist.class, id, "track", trackId);
- return SqlWrapper.get(Playlist.class, id);
+ return DataAccess.get(Playlist.class, id);
}
-
+
@POST
@Path("{id}/add_cover")
@RolesAllowed("ADMIN")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
- public Response uploadCover(@PathParam("id") Long id, @FormDataParam("fileName") String fileName, @FormDataParam("file") InputStream fileInputStream,
- @FormDataParam("file") FormDataContentDisposition fileMetaData) {
+ public Response uploadCover(@PathParam("id") final Long id, @FormDataParam("fileName") final String fileName, @FormDataParam("file") final InputStream fileInputStream,
+ @FormDataParam("file") final FormDataContentDisposition fileMetaData) {
return DataTools.uploadCover(Playlist.class, id, fileName, fileInputStream, fileMetaData);
}
-
+
@GET
@Path("{id}/rm_cover/{coverId}")
@RolesAllowed("ADMIN")
- public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
+ public Response removeCover(@PathParam("id") final Long id, @PathParam("coverId") final Long coverId) throws Exception {
AddOnManyToMany.removeLink(Playlist.class, id, "cover", coverId);
- return Response.ok(SqlWrapper.get(Playlist.class, id)).build();
+ return Response.ok(DataAccess.get(Playlist.class, id)).build();
}
}
diff --git a/back/src/org/kar/karusic/api/TrackResource.java b/back/src/org/kar/karusic/api/TrackResource.java
index 5444ace..3432a6f 100644
--- a/back/src/org/kar/karusic/api/TrackResource.java
+++ b/back/src/org/kar/karusic/api/TrackResource.java
@@ -8,17 +8,17 @@ 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.dataAccess.DataAccess;
+import org.kar.archidata.dataAccess.QueryCondition;
+import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
import org.kar.archidata.model.Data;
-import org.kar.archidata.sqlWrapper.QuerryCondition;
-import org.kar.archidata.sqlWrapper.SqlWrapper;
-import org.kar.archidata.sqlWrapper.addOn.AddOnManyToMany;
import org.kar.archidata.util.DataTools;
import org.kar.karusic.model.Album;
import org.kar.karusic.model.Artist;
import org.kar.karusic.model.Gender;
import org.kar.karusic.model.Track;
+import jakarta.annotation.security.RolesAllowed;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
@@ -37,37 +37,37 @@ public class TrackResource {
@GET
@Path("{id}")
@RolesAllowed("USER")
- public static Track getWithId(@PathParam("id") Long id) throws Exception {
- return SqlWrapper.get(Track.class, id);
+ public static Track getWithId(@PathParam("id") final Long id) throws Exception {
+ return DataAccess.get(Track.class, id);
}
@GET
@RolesAllowed("USER")
public List