From 3ea26e3f78de8337e7db3675c4ce65c119458526 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 17 Jan 2024 20:19:58 +0100 Subject: [PATCH] [DEV] update new archidata (not tested) --- back/pom.xml | 2 +- .../kar/karso/api/ApplicationResource.java | 13 +++++---- .../karso/api/ApplicationTokenResource.java | 23 ++++++++------- back/src/org/kar/karso/api/RightResource.java | 29 ++++++++++--------- .../kar/karso/api/SystemConfigResource.java | 7 +++-- back/src/org/kar/karso/api/UserResource.java | 15 +++++----- 6 files changed, 47 insertions(+), 42 deletions(-) diff --git a/back/pom.xml b/back/pom.xml index b98da71..fdd74d8 100644 --- a/back/pom.xml +++ b/back/pom.xml @@ -20,7 +20,7 @@ kangaroo-and-rabbit archidata - 0.5.0 + 0.6.0 org.slf4j diff --git a/back/src/org/kar/karso/api/ApplicationResource.java b/back/src/org/kar/karso/api/ApplicationResource.java index 4b951bb..19374e4 100755 --- a/back/src/org/kar/karso/api/ApplicationResource.java +++ b/back/src/org/kar/karso/api/ApplicationResource.java @@ -9,6 +9,7 @@ import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.QueryAnd; import org.kar.archidata.dataAccess.QueryCondition; import org.kar.archidata.dataAccess.addOn.AddOnManyToMany; +import org.kar.archidata.dataAccess.options.Condition; import org.kar.archidata.exception.InputException; import org.kar.archidata.filter.GenericContext; import org.kar.archidata.tools.JWTWrapper; @@ -46,7 +47,7 @@ public class ApplicationResource { final List out = new ArrayList<>(); List links = null; try { - links = DataAccess.getsWhere(UserLinkApplication.class, new QueryCondition("userId", "=", userId)); + links = DataAccess.getsWhere(UserLinkApplication.class, new Condition(new QueryCondition("userId", "=", userId))); } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -64,7 +65,7 @@ public class ApplicationResource { final List out = new ArrayList<>(); List links = null; try { - links = DataAccess.getsWhere(UserLinkApplication.class, new QueryCondition("object2id", "=", applicationId)); + links = DataAccess.getsWhere(UserLinkApplication.class, new Condition(new QueryCondition("object2id", "=", applicationId))); } catch (final Exception e) { e.printStackTrace(); final String result = "SERVER Internal error"; @@ -219,7 +220,7 @@ public class ApplicationResource { @RolesAllowed(value = { "ADMIN" }) public List getRightsDescription(@PathParam("id") final Long applicationId) throws Exception { this.logger.debug("getApplications rights"); - return DataAccess.getsWhere(RightDescription.class, new QueryCondition("applicationId", "=", applicationId)); + return DataAccess.getsWhere(RightDescription.class, new Condition(new QueryCondition("applicationId", "=", applicationId))); } @GET @@ -245,7 +246,7 @@ public class ApplicationResource { Application appl = null; try { - appl = DataAccess.getWhere(Application.class, new QueryCondition("name", "=", applicationName)); + appl = DataAccess.getWhere(Application.class, new Condition(new QueryCondition("name", "=", applicationName))); } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -262,7 +263,7 @@ public class ApplicationResource { UserLinkApplication links = null; try { links = DataAccess.getWhere(UserLinkApplication.class, - new QueryAnd(new QueryCondition("userId", "=", gc.userByToken.id), new QueryCondition("deleted", "=", 0), new QueryCondition("object2id", "=", appl.id))); + new Condition(new QueryAnd(new QueryCondition("userId", "=", gc.userByToken.id), new QueryCondition("deleted", "=", 0), new QueryCondition("object2id", "=", appl.id)))); } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -320,7 +321,7 @@ public class ApplicationResource { Application appl = null; try { - appl = DataAccess.getWhere(Application.class, new QueryCondition("name", "=", applicationName)); + appl = DataAccess.getWhere(Application.class, new Condition(new QueryCondition("name", "=", applicationName))); } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/back/src/org/kar/karso/api/ApplicationTokenResource.java b/back/src/org/kar/karso/api/ApplicationTokenResource.java index be09ca2..25a9fb9 100755 --- a/back/src/org/kar/karso/api/ApplicationTokenResource.java +++ b/back/src/org/kar/karso/api/ApplicationTokenResource.java @@ -8,6 +8,7 @@ import java.util.List; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.QueryAnd; import org.kar.archidata.dataAccess.QueryCondition; +import org.kar.archidata.dataAccess.options.Condition; import org.kar.archidata.exception.InputException; import org.kar.karso.model.ApplicationToken; import org.slf4j.Logger; @@ -29,32 +30,32 @@ import jakarta.ws.rs.core.SecurityContext; @Produces(MediaType.APPLICATION_JSON) public class ApplicationTokenResource { final Logger logger = LoggerFactory.getLogger(ApplicationTokenResource.class); - + public ApplicationTokenResource() {} - + //////////////////////////////////////////////////////////////////////////////////////// // // Generic /application_token/{applicationId} // //////////////////////////////////////////////////////////////////////////////////////// - + @GET @Path("{applicationId}") @RolesAllowed(value = { "ADMIN" }) public List gets(@Context final SecurityContext sc, @PathParam("applicationId") final Long applicationId) throws Exception { - final List values = DataAccess.getsWhere(ApplicationToken.class, new QueryCondition("parentId", "=", applicationId)); + final List values = DataAccess.getsWhere(ApplicationToken.class, new Condition(new QueryCondition("parentId", "=", applicationId))); // clean all tokens this is a secret: for (final ApplicationToken elem : values) { elem.token = null; } return values; } - + @DELETE @Path("{applicationId}/{tokenId}") @RolesAllowed(value = { "ADMIN" }) public Response delete(@Context final SecurityContext sc, @PathParam("applicationId") final Long applicationId, @PathParam("tokenId") final Integer tokenId) throws Exception { - final int nbRemoved = DataAccess.deleteWhere(ApplicationToken.class, new QueryAnd(new QueryCondition("parentId", "=", applicationId), new QueryCondition("id", "=", tokenId)), null); + final int nbRemoved = DataAccess.deleteWhere(ApplicationToken.class, new Condition(new QueryAnd(new QueryCondition("parentId", "=", applicationId), new QueryCondition("id", "=", tokenId)))); if (nbRemoved == 0) { return Response.notModified("{}").build(); } @@ -63,7 +64,7 @@ public class ApplicationTokenResource { } return Response.ok("{}").build(); } - + private String multipartCorrection(final String data) { if (data == null) { return null; @@ -76,7 +77,7 @@ public class ApplicationTokenResource { } return data; } - + static String randomToken() { final int len = 48; final String valid_element = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz0123456789#_@-~*!?"; @@ -91,11 +92,11 @@ public class ApplicationTokenResource { } return out.toString(); } - + public record CreateRequest( String name, Integer validity) {}; - + @POST @Path("/{applicationId}/create") @RolesAllowed("ADMIN") @@ -124,7 +125,7 @@ public class ApplicationTokenResource { this.logger.warn("Check Timestamp now = {}", now); token.endValidityTime = Timestamp.from(now.plusDays(validity).toInstant()); this.logger.warn("token.endValidityTime = {}", token.endValidityTime); - + // insert in the BDD token = DataAccess.insert(token); // here we return the token to permit to the user to see it to set it in the application. diff --git a/back/src/org/kar/karso/api/RightResource.java b/back/src/org/kar/karso/api/RightResource.java index fa811c9..b9d39b0 100644 --- a/back/src/org/kar/karso/api/RightResource.java +++ b/back/src/org/kar/karso/api/RightResource.java @@ -7,6 +7,7 @@ import java.util.Map; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.QueryAnd; import org.kar.archidata.dataAccess.QueryCondition; +import org.kar.archidata.dataAccess.options.Condition; import org.kar.karso.model.Right; import org.kar.karso.model.RightDescription; import org.kar.karso.util.Transform; @@ -29,15 +30,15 @@ import jakarta.ws.rs.core.Response; @Produces({ MediaType.APPLICATION_JSON }) public class RightResource { final static Logger logger = LoggerFactory.getLogger(RightResource.class); - + public static List getApplicationRightDecription(final long applicationId) throws Exception { - return DataAccess.getsWhere(RightDescription.class, new QueryCondition("applicationId", "=", applicationId)); - } - - public static List getRawUserRight(final long userId, final long applicationId) throws Exception { - return DataAccess.getsWhere(Right.class, new QueryAnd(new QueryCondition("applicationId", "=", applicationId), new QueryCondition("userId", "=", userId))); + return DataAccess.getsWhere(RightDescription.class, new Condition(new QueryCondition("applicationId", "=", applicationId))); } + public static List getRawUserRight(final long userId, final long applicationId) throws Exception { + return DataAccess.getsWhere(Right.class, new Condition(new QueryAnd(new QueryCondition("applicationId", "=", applicationId), new QueryCondition("userId", "=", userId)))); + } + public static Map getUserRight(final long userId, final long applicationId) throws Exception { final Map out = new HashMap<>(); final List rightsDescriptions = getApplicationRightDecription(applicationId); @@ -54,7 +55,7 @@ public class RightResource { logger.debug(" - id={} key={} type={} default={}", elem.id, elem.key, elem.type, elem.defaultValue); } for (final RightDescription description : rightsDescriptions) { - + if (description == null) { // TODO: this is a really strange case to manage later... continue; @@ -74,7 +75,7 @@ public class RightResource { } return out; } - + public static void updateUserRight(final long userId, final long applicationId, final Map delta) throws Exception { final List rightsDescriptions = getApplicationRightDecription(applicationId); logger.debug("Get some descriptions: {} applicationId={}", rightsDescriptions.size(), applicationId); @@ -115,27 +116,27 @@ public class RightResource { } } } - + @GET @RolesAllowed("ADMIN") public List get() throws Exception { return DataAccess.gets(Right.class); } - + @POST @RolesAllowed("ADMIN") @Consumes(MediaType.APPLICATION_JSON) public Right post(final String jsonRequest) throws Exception { return DataAccess.insertWithJson(Right.class, jsonRequest); } - + @GET @Path("{id}") @RolesAllowed("ADMIN") public static Right getWithId(@PathParam("id") final Long id) throws Exception { return DataAccess.get(Right.class, id); } - + @PUT @Path("{id}") @RolesAllowed("ADMIN") @@ -144,7 +145,7 @@ public class RightResource { DataAccess.updateWithJson(Right.class, id, jsonRequest); return DataAccess.get(Right.class, id); } - + @DELETE @Path("{id}") @RolesAllowed("ADMIN") @@ -152,5 +153,5 @@ public class RightResource { DataAccess.delete(Right.class, id); return Response.ok().build(); } - + } diff --git a/back/src/org/kar/karso/api/SystemConfigResource.java b/back/src/org/kar/karso/api/SystemConfigResource.java index 6fedf68..37bcd6e 100755 --- a/back/src/org/kar/karso/api/SystemConfigResource.java +++ b/back/src/org/kar/karso/api/SystemConfigResource.java @@ -4,6 +4,7 @@ import java.util.List; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.QueryCondition; +import org.kar.archidata.dataAccess.options.Condition; import org.kar.archidata.exception.NotFoundException; import org.kar.karso.model.Settings; import org.slf4j.Logger; @@ -48,7 +49,7 @@ public class SystemConfigResource { @Path("is_sign_up_availlable") @PermitAll public GetSignUpAvaillable isSignUpAvaillable() throws Exception { - final Settings set = DataAccess.getWhere(Settings.class, new QueryCondition("key", "=", "SIGN_UP_ENABLE")); + final Settings set = DataAccess.getWhere(Settings.class, new Condition(new QueryCondition("key", "=", "SIGN_UP_ENABLE"))); if (set == null) { throw new NotFoundException("Value does not exist"); } @@ -62,7 +63,7 @@ public class SystemConfigResource { @Path("key/{key}") @RolesAllowed(value = { "USER", "ADMIN" }) public Response getKey(@Context final SecurityContext sc, @PathParam("key") final String key) throws Exception { - final Settings set = DataAccess.getWhere(Settings.class, new QueryCondition("key", "=", key)); + final Settings set = DataAccess.getWhere(Settings.class, new Condition(new QueryCondition("key", "=", key))); if (set == null) { throw new NotFoundException("Value does not exist"); } @@ -84,7 +85,7 @@ public class SystemConfigResource { public Response setKey(@Context final SecurityContext sc, @PathParam("key") final String key, final String jsonRequest) throws Exception { Settings res = null; try { - res = DataAccess.getWhere(Settings.class, new QueryCondition("key", "=", key)); + res = DataAccess.getWhere(Settings.class, new Condition(new QueryCondition("key", "=", key))); } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/back/src/org/kar/karso/api/UserResource.java b/back/src/org/kar/karso/api/UserResource.java index 79b3891..ea113b5 100755 --- a/back/src/org/kar/karso/api/UserResource.java +++ b/back/src/org/kar/karso/api/UserResource.java @@ -12,6 +12,7 @@ import java.util.Map; import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.QueryCondition; import org.kar.archidata.dataAccess.addOn.AddOnManyToMany; +import org.kar.archidata.dataAccess.options.Condition; import org.kar.archidata.exception.FailException; import org.kar.archidata.exception.InputException; import org.kar.archidata.exception.SystemException; @@ -60,8 +61,8 @@ public class UserResource { this.id = id; this.login = login; } - } - + } + public UserResource() {} @GET @@ -158,12 +159,12 @@ public class UserResource { // TODO: verify if the data are a hash ... // Check login does not exist - List out = DataAccess.getsWhere(UserAuth.class, new QueryCondition("login", "=", user.login)); + List out = DataAccess.getsWhere(UserAuth.class, new Condition(new QueryCondition("login", "=", user.login))); if (out.size() >= 1) { throw new FailException(Response.Status.BAD_REQUEST, "Login already used !!!"); } // Check email does not exist - out = DataAccess.getsWhere(UserAuth.class, new QueryCondition("email", "=", user.email)); + out = DataAccess.getsWhere(UserAuth.class, new Condition(new QueryCondition("email", "=", user.email))); if (out.size() >= 1) { throw new FailException(Response.Status.BAD_REQUEST, "e-mail already used !!!"); } @@ -239,7 +240,7 @@ public class UserResource { @PermitAll public Response checkLogin(@QueryParam("login") final String login) throws Exception { this.logger.debug("checkLogin: '{}'", login); - final List out = DataAccess.getsWhere(UserAuth.class, new QueryCondition("login", "=", login)); + final List out = DataAccess.getsWhere(UserAuth.class, new Condition(new QueryCondition("login", "=", login))); if (out.size() >= 1) { return Response.ok().build(); } @@ -252,7 +253,7 @@ public class UserResource { @PermitAll public Response checkEmail(@QueryParam("email") final String email) throws Exception { this.logger.debug("checkEmail: {}", email); - final List out = DataAccess.getsWhere(UserAuth.class, new QueryCondition("email", "=", email)); + final List out = DataAccess.getsWhere(UserAuth.class, new Condition(new QueryCondition("email", "=", email))); if (out.size() >= 1) { return Response.ok().build(); } @@ -276,7 +277,7 @@ public class UserResource { if (login.contains("@")) { query = "email"; } - final UserAuth user = DataAccess.getWhere(UserAuth.class, new QueryCondition(query, "=", login)); + final UserAuth user = DataAccess.getWhere(UserAuth.class, new Condition(new QueryCondition(query, "=", login))); if (user == null) { throw new FailException(Response.Status.PRECONDITION_FAILED, "FAIL Authentiocate-wrong email/login '" + login + "')");