Project

General

Profile

« Previous | Next » 

Revision 59763

[Users | Trunk]: Fix get managers and members calls

View differences:

modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/utils/AuthorizationService.java
9 9
    public final String PORTAL_ADMIN = "PORTAL_ADMINISTRATOR";
10 10
    public final String USER_ADMIN = "USER_MANAGER";
11 11

  
12
    private String mapType(String type) {
13
        if(type.equals("organization")) {
14
            type = "institution";
15
        }
16
        if(type.equals("ri")) {
17
            type = "community";
18
        }
19
        return type;
20
    }
21

  
12 22
    /**
13 23
     * Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT
14 24
     *
15 25
     * */
16 26
    public String curator(String type) {
17
        return type.toUpperCase() + "_CURATOR";
27
        return mapType(type).toUpperCase() + "_CURATOR";
18 28
    }
19 29

  
20 30
    /**
......
23 33
     * Id = EE, EGI, etc
24 34
     * */
25 35
    public String manager(String type, String id) {
26
        return type.toUpperCase() + "_" + id.toUpperCase() + "_MANAGER";
36
        return mapType(type).toUpperCase() + "_" + id.toUpperCase() + "_MANAGER";
27 37
    }
28 38

  
29 39
    /**
......
32 42
     * Id = EE, EGI, etc
33 43
     * */
34 44
    public String member(String type, String id) {
35
        return type.toUpperCase() + "_" + id.toUpperCase();
45
        return mapType(type).toUpperCase() + "_" + id.toUpperCase();
36 46
    }
37 47

  
38 48
    public boolean isCommunity(String type) {
39
        return type.equals("community");
49
        return mapType(type).equals("community");
40 50
    }
41 51
}
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/utils/RegistryCalls.java
28 28
    @Autowired
29 29
    public JsonUtils jsonUtils;
30 30

  
31

  
32
    private String mapType(String type) {
33
        if(type.equals("organization")) {
34
            type = "institution";
35
        }
36
        if(type.equals("ri")) {
37
            type = "community";
38
        }
39
        return type;
40
    }
41

  
31 42
    /**
32 43
     * 1. Get CoPersonId by Email
33 44
     */
......
101 112
        JsonArray cous = getCous();
102 113
        Integer couId = null;
103 114
        for (JsonElement cou : cous) {
104
            if (cou.getAsJsonObject().get("Name").getAsString().equals(type + "." + id)) {
115
            if (cou.getAsJsonObject().get("Name").getAsString().equals(mapType(type) + "." + id)) {
105 116
                couId = cou.getAsJsonObject().get("Id").getAsInt();
106 117
            }
107 118
        }
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/api/RegistryService.java
90 90
    @POST
91 91
    @Produces(MediaType.APPLICATION_JSON)
92 92
    @Consumes(MediaType.APPLICATION_JSON)
93
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.USER_ADMIN)")
93
    @PreAuthorize("hasAnyAuthority(@AuthorizationService.SUPER_ADMIN, @AuthorizationService.USER_ADMIN, @AuthorizationService.PORTAL_ADMIN)")
94 94
    public Response createRole(@RequestBody Role role) {
95 95
        calls.createRole(role);
96 96
        return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse("Role has been created").toString()).type(MediaType.APPLICATION_JSON).build();
......
407 407
        Integer coPersonId = calls.getCoPersonIdByEmail(email);
408 408
        if (coPersonId != null) {
409 409
            Integer couId = calls.getCouId(type, id);
410
            Integer role = calls.getRoleId(coPersonId, couId);
410
            Integer role = null;
411
            if(couId != null) {
412
                role = calls.getRoleId(coPersonId, couId);
413
            }
411 414
            if (couId != null && role != null) {
412 415
                calls.removeAdminRole(coPersonId, couId);
413 416
                calls.removeMemberRole(coPersonId, couId, role);
......
430 433
            "@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
431 434
    public Response getMembers(@PathParam("type") String type, @PathParam("id") String id) {
432 435
        Integer couId = calls.getCouId(type, id);
433
        JsonArray subscribers = calls.getUserNamesByCouId(couId, false);
434
        return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(subscribers).toString()).type(MediaType.APPLICATION_JSON).build();
436
        if(couId != null) {
437
            JsonArray members = calls.getUserNamesByCouId(couId, true);
438
            return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(members).toString()).type(MediaType.APPLICATION_JSON).build();
439
        } else {
440
            return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
441
        }
435 442
    }
436 443

  
437 444
    /**
......
444 451
            "@AuthorizationService.curator(#type), @AuthorizationService.manager(#type, #id))")
445 452
    public Response getMembersEmail(@PathParam("type") String type, @PathParam("id") String id) {
446 453
        Integer couId = calls.getCouId(type, id);
447
        JsonArray subscribers = calls.getUserEmailByCouId(couId, false);
448
        return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(subscribers).toString()).type(MediaType.APPLICATION_JSON).build();
454
        if(couId != null) {
455
            JsonArray members = calls.getUserEmailByCouId(couId, true);
456
            return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(members).toString()).type(MediaType.APPLICATION_JSON).build();
457
        } else {
458
            return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
459
        }
449 460
    }
450 461

  
451 462
    /**
......
456 467
    @Produces(MediaType.APPLICATION_JSON)
457 468
    public Response getMembersCount(@PathParam("type") String type, @PathParam("id") String id) {
458 469
        Integer couId = calls.getCouId(type, id);
459
        int count = calls.getUserNamesByCouId(couId, false).size();
470
        int count = 0;
471
        if(couId != null) {
472
            count = calls.getUserNamesByCouId(couId, false).size();
473
        }
460 474
        return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(count).toString()).type(MediaType.APPLICATION_JSON).build();
461 475
    }
462 476

  
......
468 482
    @Produces(MediaType.APPLICATION_JSON)
469 483
    public Response getManagers(@PathParam("type") String type, @PathParam("id") String id) {
470 484
        Integer couId = calls.getCouId(type, id);
471
        JsonArray managers = calls.getUserNamesByCouId(couId, true);
472
        return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(managers).toString()).type(MediaType.APPLICATION_JSON).build();
485
        if(couId != null) {
486
            JsonArray managers = calls.getUserNamesByCouId(couId, true);
487
            return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(managers).toString()).type(MediaType.APPLICATION_JSON).build();
488
        } else {
489
            return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
490
        }
473 491
    }
474 492

  
475 493
    /**
......
480 498
    @Produces(MediaType.APPLICATION_JSON)
481 499
    public Response getManagersEmail(@PathParam("type") String type, @PathParam("id") String id) {
482 500
        Integer couId = calls.getCouId(type, id);
483
        JsonArray managers = calls.getUserEmailByCouId(couId, true);
484
        return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(managers).toString()).type(MediaType.APPLICATION_JSON).build();
501
        if(couId != null) {
502
            JsonArray managers = calls.getUserEmailByCouId(couId, true);
503
            return Response.status(HttpStatus.OK.value()).entity(jsonUtils.createResponse(managers).toString()).type(MediaType.APPLICATION_JSON).build();
504
        } else {
505
            return Response.status(HttpStatus.NOT_FOUND.value()).entity(jsonUtils.createResponse("Role has not been found").toString()).type(MediaType.APPLICATION_JSON).build();
506
        }
485 507
    }
486 508
}

Also available in: Unified diff