[DEV] update new archidata (not tested)
This commit is contained in:
parent
4a8dfe3fb0
commit
3ea26e3f78
@ -20,7 +20,7 @@
|
||||
<dependency>
|
||||
<groupId>kangaroo-and-rabbit</groupId>
|
||||
<artifactId>archidata</artifactId>
|
||||
<version>0.5.0</version>
|
||||
<version>0.6.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
|
@ -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<Long> out = new ArrayList<>();
|
||||
List<UserLinkApplication> 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<Long> out = new ArrayList<>();
|
||||
List<UserLinkApplication> 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<RightDescription> 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();
|
||||
|
@ -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<ApplicationToken> gets(@Context final SecurityContext sc, @PathParam("applicationId") final Long applicationId) throws Exception {
|
||||
final List<ApplicationToken> values = DataAccess.getsWhere(ApplicationToken.class, new QueryCondition("parentId", "=", applicationId));
|
||||
final List<ApplicationToken> 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.
|
||||
|
@ -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<RightDescription> getApplicationRightDecription(final long applicationId) throws Exception {
|
||||
return DataAccess.getsWhere(RightDescription.class, new QueryCondition("applicationId", "=", applicationId));
|
||||
}
|
||||
|
||||
public static List<Right> 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<Right> 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<String, Object> getUserRight(final long userId, final long applicationId) throws Exception {
|
||||
final Map<String, Object> out = new HashMap<>();
|
||||
final List<RightDescription> 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<String, Object> delta) throws Exception {
|
||||
final List<RightDescription> rightsDescriptions = getApplicationRightDecription(applicationId);
|
||||
logger.debug("Get some descriptions: {} applicationId={}", rightsDescriptions.size(), applicationId);
|
||||
@ -115,27 +116,27 @@ public class RightResource {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@RolesAllowed("ADMIN")
|
||||
public List<Right> 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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<UserAuth> out = DataAccess.getsWhere(UserAuth.class, new QueryCondition("login", "=", user.login));
|
||||
List<UserAuth> 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<UserAuth> out = DataAccess.getsWhere(UserAuth.class, new QueryCondition("login", "=", login));
|
||||
final List<UserAuth> 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<UserAuth> out = DataAccess.getsWhere(UserAuth.class, new QueryCondition("email", "=", email));
|
||||
final List<UserAuth> 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 + "')");
|
||||
|
Loading…
Reference in New Issue
Block a user