use of org.springframework.web.bind.annotation.ResponseStatus in project geode by apache.
the class BaseControllerAdvice method handleException.
/**
* Handles any Exception thrown by a REST API web service endpoint, HTTP request handler method.
* <p/>
*
* @param cause the Exception causing the error.
* @return a ResponseEntity with an appropriate HTTP status code (500 - Internal Server Error) and
* HTTP response body containing the stack trace of the Exception.
*/
@ExceptionHandler(Throwable.class)
@ResponseBody
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public String handleException(final Throwable cause) {
final StringWriter stackTraceWriter = new StringWriter();
cause.printStackTrace(new PrintWriter(stackTraceWriter));
final String stackTrace = stackTraceWriter.toString();
if (logger.isDebugEnabled()) {
logger.debug(stackTrace);
}
return convertErrorAsJson(cause.getMessage());
}
use of org.springframework.web.bind.annotation.ResponseStatus in project geode by apache.
the class QueryAccessController method runNamedQuery.
/**
* Run named parametrized Query with ID
*
* @param queryId id of the OQL string
* @param arguments query bind params required while executing query
* @return query result as a JSON document
*/
@RequestMapping(method = RequestMethod.POST, value = "/{query}", produces = { MediaType.APPLICATION_JSON_VALUE })
@ApiOperation(value = "run parametrized query", notes = "run the specified named query passing in scalar values for query parameters in the GemFire cluster", response = void.class)
@ApiResponses({ @ApiResponse(code = 200, message = "Query successfully executed."), @ApiResponse(code = 401, message = "Invalid Username or Password."), @ApiResponse(code = 403, message = "Insufficient privileges for operation."), @ApiResponse(code = 400, message = "Query bind params specified as JSON document in the request body is invalid"), @ApiResponse(code = 500, message = "GemFire throws an error or exception") })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@PreAuthorize("@securityService.authorize('DATA', 'READ')")
public ResponseEntity<String> runNamedQuery(@PathVariable("query") String queryId, @RequestBody String arguments) {
logger.debug("Running named Query with ID ({})...", queryId);
queryId = decode(queryId);
if (arguments != null) {
// Its a compiled query.
// Convert arguments into Object[]
Object[] args = jsonToObjectArray(arguments);
Query compiledQuery = compiledQueries.get(queryId);
if (compiledQuery == null) {
// This is first time the query is seen by this server.
final String oql = getValue(PARAMETERIZED_QUERIES_REGION, queryId, false);
ValidationUtils.returnValueThrowOnNull(oql, new ResourceNotFoundException(String.format("No Query with ID (%1$s) was found!", queryId)));
try {
compiledQuery = getQueryService().newQuery(oql);
} catch (QueryInvalidException qie) {
throw new GemfireRestException("Syntax of the OQL queryString is invalid!", qie);
}
compiledQueries.putIfAbsent(queryId, (DefaultQuery) compiledQuery);
}
// and handle the Exceptions appropriately (500 Server Error)!
try {
Object queryResult = compiledQuery.execute(args);
return processQueryResponse(compiledQuery, args, queryResult);
} catch (FunctionDomainException fde) {
throw new GemfireRestException("A function was applied to a parameter that is improper for that function!", fde);
} catch (TypeMismatchException tme) {
throw new GemfireRestException("Bind parameter is not of the expected type!", tme);
} catch (NameResolutionException nre) {
throw new GemfireRestException("Name in the query cannot be resolved!", nre);
} catch (IllegalArgumentException iae) {
throw new GemfireRestException(" The number of bound parameters does not match the number of placeholders!", iae);
} catch (IllegalStateException ise) {
throw new GemfireRestException("Query is not permitted on this type of region!", ise);
} catch (QueryExecutionTimeoutException qete) {
throw new GemfireRestException("Query execution time is exceeded max query execution time (gemfire.Cache.MAX_QUERY_EXECUTION_TIME) configured!", qete);
} catch (QueryInvocationTargetException qite) {
throw new GemfireRestException("Data referenced in from clause is not available for querying!", qite);
} catch (QueryExecutionLowMemoryException qelme) {
throw new GemfireRestException("Query gets canceled due to low memory conditions and the resource manager critical heap percentage has been set!", qelme);
} catch (Exception e) {
throw new GemfireRestException("Error encountered while executing named query!", e);
}
} else {
throw new GemfireRestException(" Bind params either not specified or not processed properly by the server!");
}
}
use of org.springframework.web.bind.annotation.ResponseStatus in project sic by belluccifranco.
the class PagoController method getPagosPorCajaYFormaDePago.
@GetMapping("/pagos/busqueda")
@ResponseStatus(HttpStatus.OK)
public List<Pago> getPagosPorCajaYFormaDePago(@RequestParam long idEmpresa, @RequestParam long idFormaDePago, @RequestParam long desde, @RequestParam long hasta) {
Date fechaDesde = new Date(desde);
Date fechaHasta = new Date(hasta);
return pagoService.getPagosEntreFechasYFormaDePago(idEmpresa, idFormaDePago, fechaDesde, fechaHasta);
}
use of org.springframework.web.bind.annotation.ResponseStatus in project sic by belluccifranco.
the class PedidoController method buscarConCriteria.
@GetMapping("/pedidos/busqueda/criteria")
@ResponseStatus(HttpStatus.OK)
public List<Pedido> buscarConCriteria(@RequestParam(value = "idEmpresa") Long idEmpresa, @RequestParam(value = "desde", required = false) Long desde, @RequestParam(value = "hasta", required = false) Long hasta, @RequestParam(value = "idCliente", required = false) Long idCliente, @RequestParam(value = "idUsuario", required = false) Long idUsuario, @RequestParam(value = "nroPedido", required = false) Long nroPedido) {
Empresa empresa = empresaService.getEmpresaPorId(idEmpresa);
Calendar fechaDesde = Calendar.getInstance();
Calendar fechaHasta = Calendar.getInstance();
if ((desde != null) && (hasta != null)) {
fechaDesde.setTimeInMillis(desde);
fechaHasta.setTimeInMillis(hasta);
}
Usuario usuario = null;
if (idUsuario != null) {
usuario = usuarioService.getUsuarioPorId(idUsuario);
}
Cliente cliente = null;
if (idCliente != null) {
cliente = clienteService.getClientePorId(idCliente);
}
BusquedaPedidoCriteria criteria = BusquedaPedidoCriteria.builder().buscaPorFecha((desde != null) && (hasta != null)).fechaDesde(fechaDesde.getTime()).fechaHasta(fechaHasta.getTime()).buscaCliente(cliente != null).cliente(cliente).buscaUsuario(idUsuario != null).usuario(usuario).buscaPorNroPedido(nroPedido != null).nroPedido((nroPedido != null) ? nroPedido : 0).empresa(empresa).build();
return pedidoService.buscarConCriteria(criteria);
}
use of org.springframework.web.bind.annotation.ResponseStatus in project sic by belluccifranco.
the class ProductoController method calcularValorStock.
@GetMapping("/productos/valor-stock/criteria")
@ResponseStatus(HttpStatus.OK)
public double calcularValorStock(@RequestParam long idEmpresa, @RequestParam(required = false) String codigo, @RequestParam(required = false) String descripcion, @RequestParam(required = false) Long idRubro, @RequestParam(required = false) Long idProveedor, @RequestParam(required = false) Integer cantidadRegistros, @RequestParam(required = false) boolean soloFantantes) {
Rubro rubro = null;
if (idRubro != null) {
rubro = rubroService.getRubroPorId(idRubro);
}
Proveedor proveedor = null;
if (idProveedor != null) {
proveedor = proveedorService.getProveedorPorId(idProveedor);
}
if (cantidadRegistros == null) {
cantidadRegistros = 0;
}
BusquedaProductoCriteria criteria = BusquedaProductoCriteria.builder().buscarPorCodigo((codigo != null)).codigo(codigo).buscarPorDescripcion(descripcion != null).descripcion(descripcion).buscarPorRubro(rubro != null).rubro(rubro).buscarPorProveedor(proveedor != null).proveedor(proveedor).empresa(empresaService.getEmpresaPorId(idEmpresa)).cantRegistros(cantidadRegistros).listarSoloFaltantes(soloFantantes).build();
return productoService.calcularValorStock(criteria);
}
Aggregations