From a48124790dd0babca488880a3e94a3bac65054dc Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Mon, 4 Oct 2021 16:35:27 +0300 Subject: [PATCH] Fix methods of creating a role in all controllers --- pom.xml | 4 ++-- .../controllers/CuratorController.java | 17 ++++++++++------- .../controllers/MemberController.java | 3 ++- .../controllers/SuperAdminController.java | 3 ++- .../services/RegistryService.java | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 18815c3..b69f646 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ 1.0.0 dnet-role-management - 0.0.1-SNAPSHOT + 1.0.1-SNAPSHOT war dnet-role-management DNET Role Management API. Integrated with AAI Registry Service @@ -97,7 +97,7 @@ maven-war-plugin - 2.4 + 2.6 false diff --git a/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/CuratorController.java b/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/CuratorController.java index 610e3a2..2860d4c 100644 --- a/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/CuratorController.java +++ b/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/CuratorController.java @@ -42,7 +42,8 @@ public class CuratorController { @RequestMapping(value = "/{type}/create", method = RequestMethod.POST) public ResponseEntity createRole(@PathVariable("type") String type, @RequestParam(value = "description", required = false) String description) { try { - if (registryService.getCouId(AuthoritiesUtils.curatorRole(type).toLowerCase()) == null) { + if (registryService.getCouId(AuthoritiesUtils.curatorRole(type)) == null) { + registryService.createRole(AuthoritiesUtils.curatorRole(type), description != null?description:""); return ResponseEntity.ok(new Response("Role has been created successfully")); } else { throw new ConflictException("This role already exists"); @@ -56,12 +57,14 @@ public class CuratorController { * Get the user info of the curators of a type(Community, etc.) */ @RequestMapping(value = "/{type}", method = RequestMethod.GET) - public ResponseEntity getAll(@PathVariable("type") String type) { - Integer couId = registryService.getCouId(AuthoritiesUtils.curatorRole(type).toLowerCase()); + public ResponseEntity getAll(@PathVariable("type") String type, + @RequestParam(value = "email", required = false, defaultValue = "true") boolean email, + @RequestParam(value = "name", required = false, defaultValue = "true") boolean name) { + Integer couId = registryService.getCouId(AuthoritiesUtils.curatorRole(type)); if (couId != null) { JsonArray users = registryService.getUserIdByCouId(couId, false); - JsonArray emails = registryService.getUserEmailByCouId(couId, false); - JsonArray names = registryService.getUserNamesByCouId(couId, false); + JsonArray emails = (email) ? registryService.getUserEmailByCouId(couId, false) : new JsonArray(); + JsonArray names = (name) ? registryService.getUserNamesByCouId(couId, false) : new JsonArray(); return ResponseEntity.ok(JsonUtils.mergeUserInfo(users, emails, names, gson)); } throw new ResourceNotFoundException("Role has not been found"); @@ -75,7 +78,7 @@ public class CuratorController { @RequestParam(value = "force", defaultValue = "false") boolean force) { List coPersonIds = registryService.getCoPersonIdsByEmail(email); if (coPersonIds.size() > 0) { - Integer temp = registryService.getCouId(AuthoritiesUtils.curatorRole(type).toLowerCase()); + Integer temp = registryService.getCouId(AuthoritiesUtils.curatorRole(type)); if (temp != null || force) { Integer couId = (temp != null)?temp:registryService.createRole(AuthoritiesUtils.curatorRole(type), ""); coPersonIds.forEach(coPersonId -> { @@ -98,7 +101,7 @@ public class CuratorController { public ResponseEntity removeRole(@PathVariable("type") String type, @RequestParam(required = false) String email) { List coPersonIds = registryService.getCoPersonIdsByEmail(email); if (coPersonIds.size() > 0) { - Integer couId = registryService.getCouId(AuthoritiesUtils.curatorRole(type).toLowerCase()); + Integer couId = registryService.getCouId(AuthoritiesUtils.curatorRole(type)); if (couId != null) { coPersonIds.forEach(coPersonId -> { String identifier = registryService.getIdentifierByCoPersonId(coPersonId); diff --git a/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/MemberController.java b/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/MemberController.java index 7fb4ea2..390ceb0 100644 --- a/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/MemberController.java +++ b/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/MemberController.java @@ -42,7 +42,8 @@ public class MemberController { public ResponseEntity createGroup(@PathVariable("type") String type, @PathVariable("id") String id, @RequestParam(value = "description", required = false) String description) { try { - if (registryService.createRole(AuthoritiesUtils.memberRole(type, id), description != null ? description : "") != null) { + if (registryService.getCouId(AuthoritiesUtils.memberRole(type, id)) == null) { + registryService.createRole(AuthoritiesUtils.memberRole(type, id), description != null ? description : ""); return ResponseEntity.ok(new Response("Role has been created successfully")); } else { throw new ConflictException("This role already exists"); diff --git a/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/SuperAdminController.java b/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/SuperAdminController.java index 0dec944..08b0fab 100644 --- a/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/SuperAdminController.java +++ b/src/main/java/eu/dnetlib/dnetrolemanagement/controllers/SuperAdminController.java @@ -29,7 +29,8 @@ public class SuperAdminController { @RequestMapping(value = "/create", method = RequestMethod.POST) public ResponseEntity createRole(@RequestParam("name") String name, @RequestParam(value = "description", required = false) String description) { try { - if (registryService.createRole(name, description != null ? description : "") != null) { + if (registryService.getCouId(name) == null) { + registryService.createRole(name, description != null ? description : ""); return ResponseEntity.ok(new Response("Role has been created successfully")); } else { throw new ConflictException("This role already exists"); diff --git a/src/main/java/eu/dnetlib/dnetrolemanagement/services/RegistryService.java b/src/main/java/eu/dnetlib/dnetrolemanagement/services/RegistryService.java index e23a77c..41872cc 100644 --- a/src/main/java/eu/dnetlib/dnetrolemanagement/services/RegistryService.java +++ b/src/main/java/eu/dnetlib/dnetrolemanagement/services/RegistryService.java @@ -121,7 +121,7 @@ public class RegistryService { public Integer getCouId(String name) { JsonArray cous = getCous(name); for (JsonElement cou : cous) { - if (cou.getAsJsonObject().get("Name").getAsString().toLowerCase().equals(name.toLowerCase())) { + if (cou.getAsJsonObject().get("Name").getAsString().equalsIgnoreCase(name)) { return cou.getAsJsonObject().get("Id").getAsInt(); } }