use of org.folio.rest.jaxrs.model.Loclib in project mod-inventory-storage by folio-org.
the class LocationUnitAPI method getLocationUnitsLibrariesById.
@Override
public void getLocationUnitsLibrariesById(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(LIB_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(LocationUnitsResource.GetLocationUnitsLibrariesByIdResponse.withPlainInternalServerError(message)));
return;
}
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(LIBRARY_TABLE, Loclib.class, criterion, true, false, getReply -> {
if (getReply.failed()) {
String message = logAndSaveError(getReply.cause());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsLibrariesByIdResponse.withPlainInternalServerError(message)));
} else {
List<Loclib> items = (List<Loclib>) getReply.result().getResults();
if (items.isEmpty()) {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsLibrariesByIdResponse.withPlainNotFound(messages.getMessage(lang, MessageConsts.ObjectDoesNotExist))));
} else if (items.size() > 1) {
String message = "Multiple locations found with the same id";
logger.error(message);
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsLibrariesByIdResponse.withPlainInternalServerError(message)));
} else {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsLibrariesByIdResponse.withJsonOK(items.get(0))));
}
}
});
}
use of org.folio.rest.jaxrs.model.Loclib in project mod-inventory-storage by folio-org.
the class LocationUnitAPI method getLocationUnitsLibraries.
@Override
public void getLocationUnitsLibraries(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, LIBRARY_TABLE);
} catch (Exception e) {
String message = logAndSaveError(e);
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsLibrariesResponse.withPlainInternalServerError(message)));
return;
}
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(LIBRARY_TABLE, Loclib.class, new String[] { "*" }, cql, true, true, reply -> {
if (reply.failed()) {
String message = logAndSaveError(reply.cause());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsLibrariesResponse.withPlainBadRequest(message)));
} else {
Loclibs lib = new Loclibs();
List<Loclib> items = (List<Loclib>) reply.result().getResults();
lib.setLoclibs(items);
lib.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsLibrariesResponse.withJsonOK(lib)));
}
});
}
Aggregations