Fix methods of creating a role in all controllers

This commit is contained in:
Konstantinos Triantafyllou 2021-10-04 16:35:27 +03:00
parent 6d79bf210f
commit a48124790d
5 changed files with 17 additions and 12 deletions

View File

@ -8,7 +8,7 @@
<version>1.0.0</version>
</parent>
<artifactId>dnet-role-management</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>dnet-role-management</name>
<description>DNET Role Management API. Integrated with AAI Registry Service</description>
@ -97,7 +97,7 @@
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>

View File

@ -42,7 +42,8 @@ public class CuratorController {
@RequestMapping(value = "/{type}/create", method = RequestMethod.POST)
public ResponseEntity<Response> 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<User[]> getAll(@PathVariable("type") String type) {
Integer couId = registryService.getCouId(AuthoritiesUtils.curatorRole(type).toLowerCase());
public ResponseEntity<User[]> 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<Integer> 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<Response> removeRole(@PathVariable("type") String type, @RequestParam(required = false) String email) {
List<Integer> 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);

View File

@ -42,7 +42,8 @@ public class MemberController {
public ResponseEntity<Response> 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");

View File

@ -29,7 +29,8 @@ public class SuperAdminController {
@RequestMapping(value = "/create", method = RequestMethod.POST)
public ResponseEntity<Response> 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");

View File

@ -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();
}
}