use of org.folio.rest.jaxrs.model.Locinst in project mod-inventory-storage by folio-org.
the class LocationUnitAPI method getLocationUnitsInstitutions.
@Override
public void getLocationUnitsInstitutions(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, INSTITUTION_TABLE);
} catch (Exception e) {
String message = logAndSaveError(e);
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsInstitutionsResponse.withPlainInternalServerError(message)));
return;
}
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(INSTITUTION_TABLE, Locinst.class, new String[] { "*" }, cql, true, true, reply -> {
if (reply.failed()) {
String message = logAndSaveError(reply.cause());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsInstitutionsResponse.withPlainBadRequest(message)));
} else {
Locinsts insts = new Locinsts();
List<Locinst> items = (List<Locinst>) reply.result().getResults();
insts.setLocinsts(items);
insts.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsInstitutionsResponse.withJsonOK(insts)));
}
});
}
use of org.folio.rest.jaxrs.model.Locinst in project mod-inventory-storage by folio-org.
the class LocationUnitAPI method getLocationUnitsInstitutionsById.
@Override
public void getLocationUnitsInstitutionsById(String id, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
Criterion criterion;
String tenantId = getTenant(okapiHeaders);
try {
Criteria criteria = new Criteria(INST_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.GetLocationUnitsInstitutionsByIdResponse.withPlainInternalServerError(message)));
return;
}
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(INSTITUTION_TABLE, Locinst.class, criterion, true, false, getReply -> {
if (getReply.failed()) {
String message = logAndSaveError(getReply.cause());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsInstitutionsByIdResponse.withPlainInternalServerError(message)));
} else {
List<Locinst> instlist = (List<Locinst>) getReply.result().getResults();
if (instlist.isEmpty()) {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsInstitutionsByIdResponse.withPlainNotFound(messages.getMessage(lang, MessageConsts.ObjectDoesNotExist))));
// We can safely ignore the case that we have more than one with
// the same id, RMB has a primary key on ID, will not allow it
} else {
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsInstitutionsByIdResponse.withJsonOK(instlist.get(0))));
}
}
});
}
Aggregations