Revision 60586
Added by Konstantinos Triantafyllou about 3 years ago
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/utils/RegistryCalls.java | ||
---|---|---|
284 | 284 |
} |
285 | 285 |
|
286 | 286 |
/** |
287 |
* 14. Assign a member role to a User
|
|
287 |
* 14. Get Users' identifiers of a Cou
|
|
288 | 288 |
*/ |
289 |
public JsonArray getUserIdByCouId(Integer couId, boolean admin) { |
|
290 |
Map<String, String> params = new HashMap<>(); |
|
291 |
params.put("couid", couId.toString()); |
|
292 |
if (admin) { |
|
293 |
params.put("admin", "true"); |
|
294 |
} |
|
295 |
JsonElement response = httpUtils.get("identifiers.json", params); |
|
296 |
JsonArray infos = (response != null) ? response.getAsJsonObject().get("Identifiers").getAsJsonArray() : new JsonArray(); |
|
297 |
JsonArray emails = new JsonArray(); |
|
298 |
infos.forEach(info -> { |
|
299 |
JsonObject user = new JsonObject(); |
|
300 |
user.addProperty("id", info.getAsJsonObject().get("Identifier").getAsString()); |
|
301 |
user.addProperty("memberSince", info.getAsJsonObject().get("Created").getAsString()); |
|
302 |
emails.add(user); |
|
303 |
}); |
|
304 |
return emails; |
|
305 |
} |
|
306 |
|
|
307 |
/** |
|
308 |
* 15. Assign a member role to a User |
|
309 |
*/ |
|
289 | 310 |
public void assignMemberRole(Integer coPersonId, Integer couId, Integer id) { |
290 | 311 |
if (id != null) { |
291 | 312 |
httpUtils.put("co_person_roles/" + id.toString() + ".json", jsonUtils.coPersonRoles(coPersonId, couId, "Active")); |
... | ... | |
295 | 316 |
} |
296 | 317 |
|
297 | 318 |
/** |
298 |
* 15. Remove a member role from a User
|
|
319 |
* 16. Remove a member role from a User
|
|
299 | 320 |
*/ |
300 | 321 |
public void removeMemberRole(Integer coPersonId, Integer couId, Integer id) { |
301 | 322 |
httpUtils.put("co_person_roles/" + id.toString() + ".json", jsonUtils.coPersonRoles(coPersonId, couId, "Deleted")); |
302 | 323 |
} |
303 | 324 |
|
304 | 325 |
/** |
305 |
* 16. Create a new role
|
|
326 |
* 17. Create a new role
|
|
306 | 327 |
*/ |
307 | 328 |
public void createRole(Role role) { |
308 | 329 |
httpUtils.post("cous.json", jsonUtils.createNewCou(role)); |
309 | 330 |
} |
310 | 331 |
|
311 | 332 |
/** |
312 |
* 17. Get User's email
|
|
333 |
* 18. Get User's email
|
|
313 | 334 |
*/ |
314 | 335 |
public String getUserEmail(Integer coPersonId) { |
315 | 336 |
Map<String, String> params = new HashMap<>(); |
... | ... | |
320 | 341 |
} |
321 | 342 |
|
322 | 343 |
/** |
323 |
* 18. Get User's names
|
|
344 |
* 19. Get User's names
|
|
324 | 345 |
*/ |
325 | 346 |
public String getUserNames(Integer coPersonId) { |
326 | 347 |
Map<String, String> params = new HashMap<>(); |
... | ... | |
331 | 352 |
} |
332 | 353 |
|
333 | 354 |
/** |
334 |
* 14. Assign an admin role to a User
|
|
355 |
* 20. Get User's identifier
|
|
335 | 356 |
*/ |
357 |
public String getUserId(Integer coPersonId) { |
|
358 |
Map<String, String> params = new HashMap<>(); |
|
359 |
params.put("copersonid", coPersonId.toString()); |
|
360 |
JsonElement response = httpUtils.get("identifiers.json", params); |
|
361 |
JsonObject info = (response != null) ? response.getAsJsonObject().get("Identifiers").getAsJsonArray().get(0).getAsJsonObject() : null; |
|
362 |
return (info != null) ? info.getAsJsonObject().get("Identifier").getAsString() : null; |
|
363 |
} |
|
364 |
|
|
365 |
/** |
|
366 |
* 21. Assign an admin role to a User |
|
367 |
*/ |
|
336 | 368 |
public void assignAdminRole(Integer coPersonId, Integer couId) { |
337 | 369 |
JsonObject group = getCouAdminGroup(couId); |
338 | 370 |
if (group != null) { |
... | ... | |
341 | 373 |
} |
342 | 374 |
|
343 | 375 |
/** |
344 |
* 15. Remove an admin role from a User
|
|
376 |
* 22. Remove an admin role from a User
|
|
345 | 377 |
*/ |
346 | 378 |
public void removeAdminRole(Integer coPersonId, Integer couId) { |
347 | 379 |
JsonObject adminGroup = this.getCouAdminGroup(couId); |
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/api/RegistryService.java | ||
---|---|---|
493 | 493 |
} |
494 | 494 |
|
495 | 495 |
/** |
496 |
* Get the Identifiers of the members of a type(Community, etc.) with id(ee, egi, etc.) |
|
497 |
*/ |
|
498 |
@Path("/{type}/{id}/members/id") |
|
499 |
@GET |
|
500 |
@Produces(MediaType.APPLICATION_JSON) |
|
501 |
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN," + |
|
502 |
"@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))") |
|
503 |
public Response getMembersId(@PathParam("type") String type, @PathParam("id") String id) { |
|
504 |
Integer couId = calls.getCouId(type, id, false); |
|
505 |
if(couId != null) { |
|
506 |
JsonArray members = calls.getUserIdByCouId(couId, false); |
|
507 |
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(members).toString()).type(MediaType.APPLICATION_JSON).build(); |
|
508 |
} else { |
|
509 |
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build(); |
|
510 |
} |
|
511 |
} |
|
512 |
|
|
513 |
/** |
|
496 | 514 |
* Get the number of the members of a type(Community, etc.) with id(ee, egi, etc.) |
497 | 515 |
*/ |
498 | 516 |
@Path("/{type}/{id}/members/count") |
... | ... | |
538 | 556 |
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build(); |
539 | 557 |
} |
540 | 558 |
} |
559 |
|
|
560 |
/** |
|
561 |
* Get the Identifiers of the managers of a type(Community, etc.) with id(ee, egi, etc.) |
|
562 |
*/ |
|
563 |
@Path("/{type}/{id}/managers/id") |
|
564 |
@GET |
|
565 |
@Produces(MediaType.APPLICATION_JSON) |
|
566 |
public Response getManagersId(@PathParam("type") String type, @PathParam("id") String id) { |
|
567 |
Integer couId = calls.getCouId(type, id); |
|
568 |
if(couId != null) { |
|
569 |
JsonArray managers = calls.getUserIdByCouId(couId, true); |
|
570 |
return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(managers).toString()).type(MediaType.APPLICATION_JSON).build(); |
|
571 |
} else { |
|
572 |
return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build(); |
|
573 |
} |
|
574 |
} |
|
541 | 575 |
} |
Also available in: Unified diff
[User | Trunk]: Add methods to get ids of managers and members for an entity.