@Test public void shouldGiveErrorIfRoleNotSaved() throws Exception { doThrow(new DataException("Error message")).when(roleRightsService).saveRole(role); ResponseEntity<OpenLmisResponse> responseEntity = controller.createRole(role, httpServletRequest); verify(roleRightsService).saveRole(role); assertThat(responseEntity.getBody().getErrorMsg(), is("Error message")); assertThat(responseEntity.getStatusCode(), is(HttpStatus.CONFLICT)); }
@RequestMapping(value = "/roles", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") public ResponseEntity<OpenLmisResponse> createRole(@RequestBody Role role, HttpServletRequest request) { role.setCreatedBy(loggedInUserId(request)); role.setModifiedBy(loggedInUserId(request)); try { roleRightsService.saveRole(role); return success(messageService.message("message.role.created.success", role.getName())); } catch (DataException e) { return error(e, HttpStatus.CONFLICT); } }
RoleRightsController extends BaseController { @RequestMapping(value = "/roles", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") public ResponseEntity<OpenLmisResponse> createRole(@RequestBody Role role, HttpServletRequest request) { role.setCreatedBy(loggedInUserId(request)); role.setModifiedBy(loggedInUserId(request)); try { roleRightsService.saveRole(role); return success(messageService.message("message.role.created.success", role.getName())); } catch (DataException e) { return error(e, HttpStatus.CONFLICT); } } }
RoleRightsController extends BaseController { @RequestMapping(value = "/roles", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") public ResponseEntity<OpenLmisResponse> createRole(@RequestBody Role role, HttpServletRequest request) { role.setCreatedBy(loggedInUserId(request)); role.setModifiedBy(loggedInUserId(request)); try { roleRightsService.saveRole(role); return success(messageService.message("message.role.created.success", role.getName())); } catch (DataException e) { return error(e, HttpStatus.CONFLICT); } }  }
RoleRightsController extends BaseController { @RequestMapping(value = "/roles", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") public ResponseEntity<OpenLmisResponse> createRole(@RequestBody Role role, HttpServletRequest request) { role.setCreatedBy(loggedInUserId(request)); role.setModifiedBy(loggedInUserId(request)); try { roleRightsService.saveRole(role); return success(messageService.message("message.role.created.success", role.getName())); } catch (DataException e) { return error(e, HttpStatus.CONFLICT); } }  @RequestMapping(value = "/rights", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> getAllRights(); @RequestMapping(value = "/roles", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> createRole(@RequestBody Role role, HttpServletRequest request); @RequestMapping(value = "/roles", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE, MANAGE_USER')") ResponseEntity<OpenLmisResponse> getAll(); @RequestMapping(value = "/roles/list", method = GET) ResponseEntity<OpenLmisResponse> getAllReadonly(); @RequestMapping(value = "/roles-flat", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE, MANAGE_USER')") ResponseEntity<OpenLmisResponse> getAllRolesFlat(); @RequestMapping(value = "/roles/{id}", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> get(@PathVariable("id") Long id); @RequestMapping(value = "/roles/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> updateRole(@PathVariable("id") Long id, @RequestBody Role role, HttpServletRequest request); @RequestMapping(value = "facility/{facilityId}/program/{programId}/rights", method = GET) ResponseEntity<OpenLmisResponse> getRightsForUserAndFacilityProgram(@PathVariable("facilityId") Long facilityId, @PathVariable("programId") Long programId, HttpServletRequest httpServletRequest); @RequestMapping(value="/roles/getList",method= RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> getRoleList(HttpServletRequest request); }
RoleRightsController extends BaseController { @RequestMapping(value = "/roles", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") public ResponseEntity<OpenLmisResponse> createRole(@RequestBody Role role, HttpServletRequest request) { role.setCreatedBy(loggedInUserId(request)); role.setModifiedBy(loggedInUserId(request)); try { roleRightsService.saveRole(role); return success(messageService.message("message.role.created.success", role.getName())); } catch (DataException e) { return error(e, HttpStatus.CONFLICT); } }  @RequestMapping(value = "/rights", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> getAllRights(); @RequestMapping(value = "/roles", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> createRole(@RequestBody Role role, HttpServletRequest request); @RequestMapping(value = "/roles", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE, MANAGE_USER')") ResponseEntity<OpenLmisResponse> getAll(); @RequestMapping(value = "/roles/list", method = GET) ResponseEntity<OpenLmisResponse> getAllReadonly(); @RequestMapping(value = "/roles-flat", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE, MANAGE_USER')") ResponseEntity<OpenLmisResponse> getAllRolesFlat(); @RequestMapping(value = "/roles/{id}", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> get(@PathVariable("id") Long id); @RequestMapping(value = "/roles/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> updateRole(@PathVariable("id") Long id, @RequestBody Role role, HttpServletRequest request); @RequestMapping(value = "facility/{facilityId}/program/{programId}/rights", method = GET) ResponseEntity<OpenLmisResponse> getRightsForUserAndFacilityProgram(@PathVariable("facilityId") Long facilityId, @PathVariable("programId") Long programId, HttpServletRequest httpServletRequest); @RequestMapping(value="/roles/getList",method= RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> getRoleList(HttpServletRequest request); static final String ROLE; static final String ROLES_MAP; static final String RIGHTS; static final String RIGHT_TYPE; }