[User | Trunk]: Add methods to get ids of managers and members for an entity.
This commit is contained in:
parent
5ba31496de
commit
f748b6e2a9
|
@ -492,6 +492,24 @@ public class RegistryService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Identifiers of the members of a type(Community, etc.) with id(ee, egi, etc.)
|
||||||
|
*/
|
||||||
|
@Path("/{type}/{id}/members/id")
|
||||||
|
@GET
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN," +
|
||||||
|
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
|
||||||
|
public Response getMembersId(@PathParam("type") String type, @PathParam("id") String id) {
|
||||||
|
Integer couId = calls.getCouId(type, id, false);
|
||||||
|
if(couId != null) {
|
||||||
|
JsonArray members = calls.getUserIdByCouId(couId, false);
|
||||||
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(members).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||||
|
} else {
|
||||||
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of the members of a type(Community, etc.) with id(ee, egi, etc.)
|
* Get the number of the members of a type(Community, etc.) with id(ee, egi, etc.)
|
||||||
*/
|
*/
|
||||||
|
@ -538,4 +556,20 @@ public class RegistryService {
|
||||||
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Identifiers of the managers of a type(Community, etc.) with id(ee, egi, etc.)
|
||||||
|
*/
|
||||||
|
@Path("/{type}/{id}/managers/id")
|
||||||
|
@GET
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Response getManagersId(@PathParam("type") String type, @PathParam("id") String id) {
|
||||||
|
Integer couId = calls.getCouId(type, id);
|
||||||
|
if(couId != null) {
|
||||||
|
JsonArray managers = calls.getUserIdByCouId(couId, true);
|
||||||
|
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(managers).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||||
|
} else {
|
||||||
|
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -284,7 +284,28 @@ public class RegistryCalls {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 14. Assign a member role to a User
|
* 14. Get Users' identifiers of a Cou
|
||||||
|
*/
|
||||||
|
public JsonArray getUserIdByCouId(Integer couId, boolean admin) {
|
||||||
|
Map<String, String> params = new HashMap<>();
|
||||||
|
params.put("couid", couId.toString());
|
||||||
|
if (admin) {
|
||||||
|
params.put("admin", "true");
|
||||||
|
}
|
||||||
|
JsonElement response = httpUtils.get("identifiers.json", params);
|
||||||
|
JsonArray infos = (response != null) ? response.getAsJsonObject().get("Identifiers").getAsJsonArray() : new JsonArray();
|
||||||
|
JsonArray emails = new JsonArray();
|
||||||
|
infos.forEach(info -> {
|
||||||
|
JsonObject user = new JsonObject();
|
||||||
|
user.addProperty("id", info.getAsJsonObject().get("Identifier").getAsString());
|
||||||
|
user.addProperty("memberSince", info.getAsJsonObject().get("Created").getAsString());
|
||||||
|
emails.add(user);
|
||||||
|
});
|
||||||
|
return emails;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 15. Assign a member role to a User
|
||||||
*/
|
*/
|
||||||
public void assignMemberRole(Integer coPersonId, Integer couId, Integer id) {
|
public void assignMemberRole(Integer coPersonId, Integer couId, Integer id) {
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
|
@ -295,21 +316,21 @@ public class RegistryCalls {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 15. Remove a member role from a User
|
* 16. Remove a member role from a User
|
||||||
*/
|
*/
|
||||||
public void removeMemberRole(Integer coPersonId, Integer couId, Integer id) {
|
public void removeMemberRole(Integer coPersonId, Integer couId, Integer id) {
|
||||||
httpUtils.put("co_person_roles/" + id.toString() + ".json", jsonUtils.coPersonRoles(coPersonId, couId, "Deleted"));
|
httpUtils.put("co_person_roles/" + id.toString() + ".json", jsonUtils.coPersonRoles(coPersonId, couId, "Deleted"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 16. Create a new role
|
* 17. Create a new role
|
||||||
*/
|
*/
|
||||||
public void createRole(Role role) {
|
public void createRole(Role role) {
|
||||||
httpUtils.post("cous.json", jsonUtils.createNewCou(role));
|
httpUtils.post("cous.json", jsonUtils.createNewCou(role));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 17. Get User's email
|
* 18. Get User's email
|
||||||
*/
|
*/
|
||||||
public String getUserEmail(Integer coPersonId) {
|
public String getUserEmail(Integer coPersonId) {
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
|
@ -320,7 +341,7 @@ public class RegistryCalls {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 18. Get User's names
|
* 19. Get User's names
|
||||||
*/
|
*/
|
||||||
public String getUserNames(Integer coPersonId) {
|
public String getUserNames(Integer coPersonId) {
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
|
@ -331,7 +352,18 @@ public class RegistryCalls {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 14. Assign an admin role to a User
|
* 20. Get User's identifier
|
||||||
|
*/
|
||||||
|
public String getUserId(Integer coPersonId) {
|
||||||
|
Map<String, String> params = new HashMap<>();
|
||||||
|
params.put("copersonid", coPersonId.toString());
|
||||||
|
JsonElement response = httpUtils.get("identifiers.json", params);
|
||||||
|
JsonObject info = (response != null) ? response.getAsJsonObject().get("Identifiers").getAsJsonArray().get(0).getAsJsonObject() : null;
|
||||||
|
return (info != null) ? info.getAsJsonObject().get("Identifier").getAsString() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 21. Assign an admin role to a User
|
||||||
*/
|
*/
|
||||||
public void assignAdminRole(Integer coPersonId, Integer couId) {
|
public void assignAdminRole(Integer coPersonId, Integer couId) {
|
||||||
JsonObject group = getCouAdminGroup(couId);
|
JsonObject group = getCouAdminGroup(couId);
|
||||||
|
@ -341,7 +373,7 @@ public class RegistryCalls {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 15. Remove an admin role from a User
|
* 22. Remove an admin role from a User
|
||||||
*/
|
*/
|
||||||
public void removeAdminRole(Integer coPersonId, Integer couId) {
|
public void removeAdminRole(Integer coPersonId, Integer couId) {
|
||||||
JsonObject adminGroup = this.getCouAdminGroup(couId);
|
JsonObject adminGroup = this.getCouAdminGroup(couId);
|
||||||
|
|
Loading…
Reference in New Issue