Esempio n. 1
0
 /** PUT /users -> Updates an existing User. */
 @RequestMapping(
     value = "/users",
     method = RequestMethod.PUT,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 @Transactional
 @Secured(AuthoritiesConstants.ADMIN)
 public ResponseEntity<ManagedUserDTO> updateUser(@RequestBody ManagedUserDTO managedUserDTO)
     throws URISyntaxException {
   log.debug("REST request to update User : {}", managedUserDTO);
   return Optional.of(userRepository.findOne(managedUserDTO.getId()))
       .map(
           user -> {
             user.setLogin(managedUserDTO.getLogin());
             user.setFirstName(managedUserDTO.getFirstName());
             user.setLastName(managedUserDTO.getLastName());
             user.setEmail(managedUserDTO.getEmail());
             user.setActivated(managedUserDTO.isActivated());
             user.setLangKey(managedUserDTO.getLangKey());
             Set<Authority> authorities = user.getAuthorities();
             authorities.clear();
             managedUserDTO
                 .getAuthorities()
                 .stream()
                 .forEach(authority -> authorities.add(authorityRepository.findOne(authority)));
             return ResponseEntity.ok()
                 .headers(HeaderUtil.createEntityUpdateAlert("user", managedUserDTO.getLogin()))
                 .body(new ManagedUserDTO(userRepository.findOne(managedUserDTO.getId())));
           })
       .orElseGet(() -> new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR));
 }
Esempio n. 2
0
 /** GET /users -> get all users. */
 @RequestMapping(
     value = "/users",
     method = RequestMethod.GET,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 @Transactional(readOnly = true)
 public ResponseEntity<List<ManagedUserDTO>> getAllUsers(Pageable pageable)
     throws URISyntaxException {
   Page<User> page = userRepository.findAll(pageable);
   List<ManagedUserDTO> managedUserDTOs =
       page.getContent()
           .stream()
           .map(user -> new ManagedUserDTO(user))
           .collect(Collectors.toList());
   HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/users");
   return new ResponseEntity<>(managedUserDTOs, headers, HttpStatus.OK);
 }
Esempio n. 3
0
 /** POST /users -> Create a new user. */
 @RequestMapping(
     value = "/users",
     method = RequestMethod.POST,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 @Secured(AuthoritiesConstants.ADMIN)
 public ResponseEntity<User> createUser(@RequestBody User user) throws URISyntaxException {
   log.debug("REST request to save User : {}", user);
   if (user.getId() != null) {
     return ResponseEntity.badRequest()
         .header("Failure", "A new user cannot already have an ID")
         .body(null);
   }
   User result = userRepository.save(user);
   return ResponseEntity.created(new URI("/api/users/" + result.getId()))
       .headers(HeaderUtil.createEntityCreationAlert("user", result.getId().toString()))
       .body(result);
 }