use of org.folio.rest.jaxrs.model.Loantypes in project mod-inventory-storage by folio-org.
the class LoanTypeAPI method getLoanTypes.
@Validate
@Override
public void getLoanTypes(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
/**
* http://host:port/loan-types
*/
vertxContext.runOnContext(v -> {
try {
CQLWrapper cql = getCQL(query, limit, offset);
getPostgresClient(vertxContext, okapiHeaders).get(LOAN_TYPE_TABLE, Loantype.class, new String[] { "*" }, cql, true, true, reply -> {
try {
if (reply.succeeded()) {
Loantypes loantypes = new Loantypes();
@SuppressWarnings("unchecked") List<Loantype> loantype = (List<Loantype>) reply.result().getResults();
loantypes.setLoantypes(loantype);
loantypes.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetLoanTypesResponse.withJsonOK(loantypes)));
} else {
log.error(reply.cause().getMessage(), reply.cause());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetLoanTypesResponse.withPlainBadRequest(reply.cause().getMessage())));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetLoanTypesResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
});
} catch (Exception e) {
log.error(e.getMessage(), e);
String message = messages.getMessage(lang, MessageConsts.InternalServerError);
if (e.getCause() instanceof CQLParseException) {
message = " CQL parse error " + e.getLocalizedMessage();
}
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetLoanTypesResponse.withPlainInternalServerError(message)));
}
});
}
Aggregations