Search in sources :

Example 1 with Shelflocations

use of org.folio.rest.jaxrs.model.Shelflocations in project mod-inventory-storage by folio-org.

the class ShelfLocationAPI method getShelfLocations.

/**
 * Get a list of the new locations, and fake old kind of shelf-locations out
 * of them.
 */
@Override
public void getShelfLocations(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    try {
        String tenantId = getTenant(okapiHeaders);
        CQLWrapper cql = getCQL(query, limit, offset, LocationAPI.LOCATION_TABLE);
        PostgresClient.getInstance(vertxContext.owner(), tenantId).get(LocationAPI.LOCATION_TABLE, Location.class, new String[] { "*" }, cql, true, true, reply -> {
            try {
                if (reply.failed()) {
                    String message = logAndSaveError(reply.cause());
                    asyncResultHandler.handle(Future.succeededFuture(GetShelfLocationsResponse.withPlainBadRequest(message)));
                } else {
                    Shelflocations shelfLocations = new Shelflocations();
                    List<Location> locationsList = (List<Location>) reply.result().getResults();
                    List<Shelflocation> shelfLocationsList = new ArrayList<>(locationsList.size());
                    for (Location loc : locationsList) {
                        Shelflocation sl = new Shelflocation();
                        sl.setId(loc.getId());
                        sl.setName(loc.getName());
                        shelfLocationsList.add(sl);
                    }
                    shelfLocations.setShelflocations(shelfLocationsList);
                    shelfLocations.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
                    asyncResultHandler.handle(Future.succeededFuture(GetShelfLocationsResponse.withJsonOK(shelfLocations)));
                }
            } catch (Exception e) {
                String message = logAndSaveError(e);
                asyncResultHandler.handle(Future.succeededFuture(GetShelfLocationsResponse.withPlainInternalServerError(message)));
            }
        });
    } catch (Exception e) {
        String message = logAndSaveError(e);
        asyncResultHandler.handle(Future.succeededFuture(GetShelfLocationsResponse.withPlainInternalServerError(message)));
    }
}
Also used : Shelflocations(org.folio.rest.jaxrs.model.Shelflocations) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CQLWrapper(org.folio.rest.persist.cql.CQLWrapper) NotImplementedException(org.apache.commons.lang.NotImplementedException) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Location(org.folio.rest.jaxrs.model.Location) Shelflocation(org.folio.rest.jaxrs.model.Shelflocation)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 NotImplementedException (org.apache.commons.lang.NotImplementedException)1 Location (org.folio.rest.jaxrs.model.Location)1 Shelflocation (org.folio.rest.jaxrs.model.Shelflocation)1 Shelflocations (org.folio.rest.jaxrs.model.Shelflocations)1 CQLWrapper (org.folio.rest.persist.cql.CQLWrapper)1 FieldException (org.z3950.zing.cql.cql2pgjson.FieldException)1