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)));
}
}
Aggregations