use of org.folio.rest.jaxrs.model.Locations in project mod-inventory-storage by folio-org.
the class LocationAPI method getLocations.
// Note, this is the way to get rid of unnecessary try-catch blocks. Use the
// same everywhere!
@Override
public void getLocations(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
String tenantId = getTenant(okapiHeaders);
CQLWrapper cql;
try {
cql = getCQL(query, limit, offset, LOCATION_TABLE);
} catch (FieldException e) {
String message = logAndSaveError(e);
asyncResultHandler.handle(Future.succeededFuture(GetLocationsResponse.withPlainBadRequest(message)));
return;
}
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(LOCATION_TABLE, Location.class, new String[] { "*" }, cql, true, true, reply -> {
// netbeans, please indent here!
if (reply.failed()) {
String message = logAndSaveError(reply.cause());
asyncResultHandler.handle(Future.succeededFuture(GetLocationsResponse.withPlainBadRequest(message)));
} else {
Locations shelfLocations = new Locations();
List<Location> shelfLocationsList = (List<Location>) reply.result().getResults();
shelfLocations.setLocations(shelfLocationsList);
shelfLocations.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
asyncResultHandler.handle(Future.succeededFuture(GetLocationsResponse.withJsonOK(shelfLocations)));
}
});
}
Aggregations