Example usage for org.springframework.http ResponseEntity unprocessableEntity

List of usage examples for org.springframework.http ResponseEntity unprocessableEntity

Introduction

In this page you can find the example usage for org.springframework.http ResponseEntity unprocessableEntity.

Prototype

public static BodyBuilder unprocessableEntity() 

Source Link

Document

Create a builder with an HttpStatus#UNPROCESSABLE_ENTITY UNPROCESSABLE_ENTITY status.

Usage

From source file:com.fns.grivet.controller.NamedQueryController.java

@PreAuthorize("hasAuthority('write:query')")
@PostMapping("/api/v1/query")
public ResponseEntity<?> createNamedQuery(@RequestBody NamedQuery query) {
    ResponseEntity<?> result = ResponseEntity.unprocessableEntity().build();
    Assert.isTrue(StringUtils.isNotBlank(query.getName()), "Query name must not be null, empty or blank.");
    Assert.notNull(query.getQuery(), "Query string must not be null!");
    Assert.isTrue(isSupportedQuery(query), "Query must start with either CALL or SELECT");
    // check for named parameters; but only if they exist
    if (!query.getParams().isEmpty()) {
        query.getParams().keySet()//from  ww w .j  a  v  a 2s. c o m
                .forEach(k -> Assert.isTrue(query.getQuery().contains(String.format(":%s", k)),
                        String.format("Query must contain named parameter [%s]", k)));
    }
    namedQueryService.create(query);
    log.info("Named Query \n\n{}\n\n successfully registered!", query);
    UriComponentsBuilder ucb = UriComponentsBuilder.newInstance();
    if (query.getParams().isEmpty()) {
        result = ResponseEntity
                .created(ucb.path("/api/v1/query/{name}").buildAndExpand(query.getName()).toUri()).build();
    } else {
        result = ResponseEntity.noContent().build();
    }
    return result;
}