use of org.folio.rest.jaxrs.model.Location in project mod-inventory-storage by folio-org.
the class LocationAPI method getLocationsById.
@Override
public void getLocationsById(String id, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
String tenantId = getTenant(okapiHeaders);
Criterion criterion;
try {
Criteria criteria = new Criteria(LOCATION_SCHEMA_PATH);
criteria.addField(ID_FIELD_NAME);
criteria.setOperation("=");
criteria.setValue(id);
criterion = new Criterion(criteria);
} catch (Exception e) {
String message = logAndSaveError(e);
asyncResultHandler.handle(Future.succeededFuture(GetLocationsByIdResponse.withPlainInternalServerError(message)));
return;
}
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(LOCATION_TABLE, Location.class, criterion, true, false, getReply -> {
if (getReply.failed()) {
String message = logAndSaveError(getReply.cause());
asyncResultHandler.handle(Future.succeededFuture(GetLocationsByIdResponse.withPlainInternalServerError(message)));
} else {
List<Location> locationList = (List<Location>) getReply.result().getResults();
if (locationList.isEmpty()) {
asyncResultHandler.handle(Future.succeededFuture(GetLocationsByIdResponse.withPlainNotFound(messages.getMessage(lang, MessageConsts.ObjectDoesNotExist))));
} else if (locationList.size() > 1) {
String message = "Multiple locations found with the same id";
logger.error(message);
asyncResultHandler.handle(Future.succeededFuture(GetLocationsByIdResponse.withPlainInternalServerError(message)));
} else {
asyncResultHandler.handle(Future.succeededFuture(GetLocationsByIdResponse.withJsonOK(locationList.get(0))));
}
}
});
}
use of org.folio.rest.jaxrs.model.Location 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)));
}
});
}
use of org.folio.rest.jaxrs.model.Location in project mod-inventory-storage by folio-org.
the class ShelfLocationAPI method getShelfLocationsById.
/**
* Get a new-kind of Location object, and convert it to old-style
* shelf-location.
*/
@Override
public void getShelfLocationsById(String id, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
try {
String tenantId = getTenant(okapiHeaders);
Criteria criteria = new Criteria(LOCATION_SCHEMA_PATH);
criteria.addField(ID_FIELD_NAME);
criteria.setOperation("=");
criteria.setValue(id);
Criterion criterion = new Criterion(criteria);
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(LOCATION_TABLE, Location.class, criterion, true, false, getReply -> {
if (getReply.failed()) {
String message = logAndSaveError(getReply.cause());
asyncResultHandler.handle(Future.succeededFuture(GetShelfLocationsByIdResponse.withPlainInternalServerError(message)));
} else {
List<Location> locationList = (List<Location>) getReply.result().getResults();
if (locationList.size() < 1) {
asyncResultHandler.handle(Future.succeededFuture(GetShelfLocationsByIdResponse.withPlainNotFound(messages.getMessage(lang, MessageConsts.ObjectDoesNotExist))));
} else if (locationList.size() > 1) {
String message = "Multiple locations found with the same id";
logger.error(message);
asyncResultHandler.handle(Future.succeededFuture(GetShelfLocationsByIdResponse.withPlainInternalServerError(message)));
} else {
Location loc = locationList.get(0);
Shelflocation sl = new Shelflocation();
sl.setId(loc.getId());
sl.setName(loc.getName());
asyncResultHandler.handle(Future.succeededFuture(GetShelfLocationsByIdResponse.withJsonOK(sl)));
}
}
});
} catch (Exception e) {
String message = logAndSaveError(e);
asyncResultHandler.handle(Future.succeededFuture(GetShelfLocationsByIdResponse.withPlainInternalServerError(message)));
}
}
use of org.folio.rest.jaxrs.model.Location 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