@Test public void shouldReturnErrorIfSaveUserFails() throws Exception { User user = new User(); doThrow(new DataException("Save user failed")).when(userService).create(eq(user), anyString()); ResponseEntity<OpenLmisResponse> response = userController.create(user, request); assertThat(response.getStatusCode(), is(BAD_REQUEST)); assertThat(response.getBody().getErrorMsg(), is("Save user failed")); }
@RequestMapping(value = "/users", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") public ResponseEntity<OpenLmisResponse> create(@RequestBody User user, HttpServletRequest request) { user.setCreatedBy(loggedInUserId(request)); user.setModifiedBy(loggedInUserId(request)); if (user.isMobileUser()) { user.setVerified(true); } else { user.setIsMobileUser(false); } try { String resetPasswordBaseLink = baseUrl + RESET_PASSWORD_PATH; userService.create(user, resetPasswordBaseLink); } catch (DataException e) { return error(e, BAD_REQUEST); } ResponseEntity<OpenLmisResponse> success = success(USER_CREATED_SUCCESS_MSG); success.getBody().addData("user", user); return success; }
UserController extends BaseController { @RequestMapping(value = "/users", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") public ResponseEntity<OpenLmisResponse> create(@RequestBody User user, HttpServletRequest request) { user.setCreatedBy(loggedInUserId(request)); user.setModifiedBy(loggedInUserId(request)); if (user.isMobileUser()) { user.setVerified(true); } else { user.setIsMobileUser(false); } try { String resetPasswordBaseLink = baseUrl + RESET_PASSWORD_PATH; userService.create(user, resetPasswordBaseLink); } catch (DataException e) { return error(e, BAD_REQUEST); } ResponseEntity<OpenLmisResponse> success = success(USER_CREATED_SUCCESS_MSG); success.getBody().addData("user", user); return success; } }
UserController extends BaseController { @RequestMapping(value = "/users", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") public ResponseEntity<OpenLmisResponse> create(@RequestBody User user, HttpServletRequest request) { user.setCreatedBy(loggedInUserId(request)); user.setModifiedBy(loggedInUserId(request)); if (user.isMobileUser()) { user.setVerified(true); } else { user.setIsMobileUser(false); } try { String resetPasswordBaseLink = baseUrl + RESET_PASSWORD_PATH; userService.create(user, resetPasswordBaseLink); } catch (DataException e) { return error(e, BAD_REQUEST); } ResponseEntity<OpenLmisResponse> success = success(USER_CREATED_SUCCESS_MSG); success.getBody().addData("user", user); return success; }  }
UserController extends BaseController { @RequestMapping(value = "/users", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") public ResponseEntity<OpenLmisResponse> create(@RequestBody User user, HttpServletRequest request) { user.setCreatedBy(loggedInUserId(request)); user.setModifiedBy(loggedInUserId(request)); if (user.isMobileUser()) { user.setVerified(true); } else { user.setIsMobileUser(false); } try { String resetPasswordBaseLink = baseUrl + RESET_PASSWORD_PATH; userService.create(user, resetPasswordBaseLink); } catch (DataException e) { return error(e, BAD_REQUEST); } ResponseEntity<OpenLmisResponse> success = success(USER_CREATED_SUCCESS_MSG); success.getBody().addData("user", user); return success; }  @RequestMapping(value = "/user-context", method = GET, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> user(HttpServletRequest httpServletRequest); @RequestMapping(value = "/authentication-error", method = POST, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> authenticationError(); @RequestMapping(value = "/forgot-password", method = POST, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> sendPasswordTokenEmail(@RequestBody User user); @RequestMapping(value = "/users", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") ResponseEntity<OpenLmisResponse> create(@RequestBody User user, HttpServletRequest request); @RequestMapping(value = "/users/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") ResponseEntity<OpenLmisResponse> update(@RequestBody User user,
                                                 @PathVariable("id") Long id,
                                                 HttpServletRequest request); @RequestMapping(value = "/users", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") ResponseEntity<OpenLmisResponse> searchUser(@RequestParam(value = "searchParam", required = false) String searchParam,
                                                     @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                     @Value("${search.page.size}") String limit); @RequestMapping(value = "/users/{id}", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") User get(@PathVariable(value = "id") Long id); @RequestMapping(value = "/users/{id}", method = DELETE, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> disable(@PathVariable("id") Long id,
                                                  HttpServletRequest request); @RequestMapping(value = "/user/validatePasswordResetToken/{token}", method = GET) ResponseEntity<OpenLmisResponse> validatePasswordResetToken(@PathVariable(value = "token") String token); @RequestMapping(value = "/user/resetPassword/{token}", method = PUT) ResponseEntity<OpenLmisResponse> resetPassword(@PathVariable(value = "token") String token, @RequestBody String password); @RequestMapping(value = "/admin/resetPassword/{userId}", method = PUT) ResponseEntity<OpenLmisResponse> updateUserPassword(@PathVariable(value = "userId") Long userId, @RequestBody String password); @RequestMapping(value = "/user/preferences", method = GET) ResponseEntity<OpenLmisResponse> getUserPreferences(HttpServletRequest request); @RequestMapping(value = "/users/{userId}/preferences", method = GET) ResponseEntity<OpenLmisResponse> getUserPreferences(@PathVariable("userId") Long userId); @RequestMapping(value = "/users/{userId}/preferences", method = PUT, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> updateUserPreferences(@PathVariable(value = "userId") Long userId, @RequestParam("programId") Long programId,
                                                                  @RequestParam("facilityId") Long facilityId, @RequestParam("products") List<Long> productListId,
                                                                  @RequestBody User user,
                                                                  HttpServletRequest request); @RequestMapping(value = "/preference/users/{id}", method = GET) User getUser(@PathVariable(value = "id") Long id, HttpServletRequest request); @RequestMapping(value = "/users/supervisory/rights.json", method= GET) ResponseEntity<OpenLmisResponse> getRights(HttpServletRequest request); }
UserController extends BaseController { @RequestMapping(value = "/users", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") public ResponseEntity<OpenLmisResponse> create(@RequestBody User user, HttpServletRequest request) { user.setCreatedBy(loggedInUserId(request)); user.setModifiedBy(loggedInUserId(request)); if (user.isMobileUser()) { user.setVerified(true); } else { user.setIsMobileUser(false); } try { String resetPasswordBaseLink = baseUrl + RESET_PASSWORD_PATH; userService.create(user, resetPasswordBaseLink); } catch (DataException e) { return error(e, BAD_REQUEST); } ResponseEntity<OpenLmisResponse> success = success(USER_CREATED_SUCCESS_MSG); success.getBody().addData("user", user); return success; }  @RequestMapping(value = "/user-context", method = GET, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> user(HttpServletRequest httpServletRequest); @RequestMapping(value = "/authentication-error", method = POST, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> authenticationError(); @RequestMapping(value = "/forgot-password", method = POST, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> sendPasswordTokenEmail(@RequestBody User user); @RequestMapping(value = "/users", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") ResponseEntity<OpenLmisResponse> create(@RequestBody User user, HttpServletRequest request); @RequestMapping(value = "/users/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") ResponseEntity<OpenLmisResponse> update(@RequestBody User user,
                                                 @PathVariable("id") Long id,
                                                 HttpServletRequest request); @RequestMapping(value = "/users", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") ResponseEntity<OpenLmisResponse> searchUser(@RequestParam(value = "searchParam", required = false) String searchParam,
                                                     @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                     @Value("${search.page.size}") String limit); @RequestMapping(value = "/users/{id}", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_USER')") User get(@PathVariable(value = "id") Long id); @RequestMapping(value = "/users/{id}", method = DELETE, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> disable(@PathVariable("id") Long id,
                                                  HttpServletRequest request); @RequestMapping(value = "/user/validatePasswordResetToken/{token}", method = GET) ResponseEntity<OpenLmisResponse> validatePasswordResetToken(@PathVariable(value = "token") String token); @RequestMapping(value = "/user/resetPassword/{token}", method = PUT) ResponseEntity<OpenLmisResponse> resetPassword(@PathVariable(value = "token") String token, @RequestBody String password); @RequestMapping(value = "/admin/resetPassword/{userId}", method = PUT) ResponseEntity<OpenLmisResponse> updateUserPassword(@PathVariable(value = "userId") Long userId, @RequestBody String password); @RequestMapping(value = "/user/preferences", method = GET) ResponseEntity<OpenLmisResponse> getUserPreferences(HttpServletRequest request); @RequestMapping(value = "/users/{userId}/preferences", method = GET) ResponseEntity<OpenLmisResponse> getUserPreferences(@PathVariable("userId") Long userId); @RequestMapping(value = "/users/{userId}/preferences", method = PUT, headers = ACCEPT_JSON) ResponseEntity<OpenLmisResponse> updateUserPreferences(@PathVariable(value = "userId") Long userId, @RequestParam("programId") Long programId,
                                                                  @RequestParam("facilityId") Long facilityId, @RequestParam("products") List<Long> productListId,
                                                                  @RequestBody User user,
                                                                  HttpServletRequest request); @RequestMapping(value = "/preference/users/{id}", method = GET) User getUser(@PathVariable(value = "id") Long id, HttpServletRequest request); @RequestMapping(value = "/users/supervisory/rights.json", method= GET) ResponseEntity<OpenLmisResponse> getRights(HttpServletRequest request); static final String TOKEN_VALID; static final String USERS; @Value("${mail.base.url}")
  public String baseUrl; }