Search in sources :

Example 1 with Locations

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)));
        }
    });
}
Also used : FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Locations(org.folio.rest.jaxrs.model.Locations) List(java.util.List) CQLWrapper(org.folio.rest.persist.cql.CQLWrapper) Location(org.folio.rest.jaxrs.model.Location)

Aggregations

List (java.util.List)1 Location (org.folio.rest.jaxrs.model.Location)1 Locations (org.folio.rest.jaxrs.model.Locations)1 CQLWrapper (org.folio.rest.persist.cql.CQLWrapper)1 FieldException (org.z3950.zing.cql.cql2pgjson.FieldException)1