Example usage for org.springframework.http HttpStatus UNPROCESSABLE_ENTITY

List of usage examples for org.springframework.http HttpStatus UNPROCESSABLE_ENTITY

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus UNPROCESSABLE_ENTITY.

Prototype

HttpStatus UNPROCESSABLE_ENTITY

To view the source code for org.springframework.http HttpStatus UNPROCESSABLE_ENTITY.

Click Source Link

Document

422 Unprocessable Entity .

Usage

From source file:org.smigo.user.password.PasswordController.java

@RequestMapping(value = "/change-password", method = RequestMethod.POST)
@ResponseBody//from ww w .j  a va 2 s .c  o m
public List<ObjectError> changePassword(@RequestBody @Valid Password password, BindingResult result,
        @AuthenticationPrincipal AuthenticatedUser user, HttpServletResponse response) {
    if (result.hasErrors()) {
        response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
        return result.getAllErrors();
    }
    userHandler.updatePassword(user.getId(), password.getNewPassword());
    return Collections.emptyList();
}

From source file:org.trustedanalytics.examples.hbase.api.ExceptionHandlerAdvice.java

@ExceptionHandler
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
@ResponseBody//from  w  w  w.  ja  v a  2  s  . c om
public String handleIOException(IOException ex) {
    LOG.error("Error while talking to HBase", ex);
    return "Error while talking to HBase";
}

From source file:org.smigo.comment.CommentController.java

@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/rest/comment", produces = "application/json", method = RequestMethod.PUT)
@ResponseBody/*www. ja va 2  s. c  o m*/
public Object updateComment(@Valid @RequestBody Comment comment, BindingResult result,
        @AuthenticationPrincipal AuthenticatedUser user, HttpServletResponse response) {
    if (result.hasErrors()) {
        response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
        return result.getAllErrors();
    }
    commentHandler.updateComment(comment, user);
    return Collections.emptyList();
}

From source file:py.com.sodep.web.UserWatchListController.java

@ExceptionHandler
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
public RestResponse handleUserNotAllowedToWatch(UserNotAllowedToWatchException ex) {
    return new RestResponse(false, ex.getMessage());
}

From source file:org.smigo.species.vernacular.VernacularController.java

@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/rest/vernacular", method = RequestMethod.POST)
@ResponseBody//from www.ja v a2s . c o m
public Object addVernacular(@Valid @RequestBody Vernacular vernacular, BindingResult result,
        @AuthenticationPrincipal AuthenticatedUser user, Locale locale, HttpServletResponse response) {
    log.info("Adding vernacular:" + vernacular);
    if (result.hasErrors()) {
        response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
        return result.getAllErrors();
    }
    CrudResult review = vernacularHandler.addVernacular(vernacular, user, locale);
    if (review.getReview() == Review.MODERATOR) {
        response.setStatus(HttpStatus.ACCEPTED.value());
    }
    return review.getId();
}

From source file:org.openbaton.autoscaling.api.exceptions.GlobalExceptionHandler.java

@ExceptionHandler({ BadFormatException.class, NetworkServiceIntegrityException.class,
        WrongStatusException.class })
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
protected ResponseEntity<Object> handleInvalidRequest(Exception e, WebRequest request) {
    log.error("Exception with message " + e.getMessage() + " was thrown");
    ExceptionResource exc = new ExceptionResource("Bad Request", e.getMessage());
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);

    return handleExceptionInternal(e, exc, headers, HttpStatus.UNPROCESSABLE_ENTITY, request);
}

From source file:org.smigo.species.SpeciesController.java

@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/rest/species", method = RequestMethod.POST)
@ResponseBody/*from  w w w  .  ja v  a  2s .c  o m*/
public Object addSpecies(@Valid @RequestBody Species species, BindingResult result,
        @AuthenticationPrincipal AuthenticatedUser user, Locale locale, HttpServletResponse response) {
    log.info("Adding species. Name:" + species);
    if (result.hasErrors()) {
        response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
        return result.getAllErrors();
    }
    return speciesHandler.addSpecies(species, user, locale);
}

From source file:com.ge.predix.acs.zone.management.ZoneController.java

@RequestMapping(method = PUT, value = V1
        + AcsApiUriTemplates.ZONE_URL, consumes = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Creates/Updates the zone.", hidden = true)
public ResponseEntity<Zone> putZone(@RequestBody final Zone zone,
        @PathVariable("zoneName") final String zoneName) {

    validateAndSanitizeInputOrFail(zone, zoneName);
    try {//from   w ww .  j  a v  a2 s  .c  o m

        boolean zoneCreated = this.service.upsertZone(zone);

        if (zoneCreated) {
            return created(false, V1 + AcsApiUriTemplates.ZONE_URL, "zoneName:" + zoneName);
        }

        return created();

    } catch (ZoneManagementException e) {
        throw new RestApiException(HttpStatus.UNPROCESSABLE_ENTITY, e);
    } catch (Exception e) {
        String message = String.format(
                "Unexpected Exception " + "while upserting Zone with name %s and subdomain %s", zone.getName(),
                zone.getSubdomain());
        throw new RestApiException(HttpStatus.INTERNAL_SERVER_ERROR, message, e);
    }
}

From source file:com.sentinel.web.controllers.OrientDbController.java

/**
 * /*from   w w  w . j a v  a  2  s . c o  m*/
 * @param user
 * @param role
 * @return
 */
@RequestMapping(value = "/users/{userId}/grant/role/{roleId}", method = RequestMethod.POST)
@ResponseBody
@PreAuthorize(value = "hasRole('ORIENT_ADMIN_PRIVILEGE')")
public ResponseEntity<String> grantRole(@PathVariable Long userId, @PathVariable Long roleId) {
    User user = userRepository.findOne(userId);
    Role role = roleRepository.findOne(roleId);
    if (user == null) {
        return new ResponseEntity<String>("invalid user id", HttpStatus.UNPROCESSABLE_ENTITY);
    }
    userService.grantRole(user, role);

    //TODO break down to create user  separately with none role +  same password 
    boolean found = orientdbService.checkForUserInOrient(user.getEmail())
            && orientdbService.checkForRoleInOrient(role.getName());
    if (found) {
        orientdbService.grantUserRole(user.getEmail(), role.getName());
        userRepository.saveAndFlush(user);
    } else
        return new ResponseEntity<String>("user or role already exist", HttpStatus.UNPROCESSABLE_ENTITY);
    return new ResponseEntity<String>("role granted", HttpStatus.OK);

}