Search in sources :

Example 1 with NatureOfContentTerms

use of org.folio.rest.jaxrs.model.NatureOfContentTerms in project mod-inventory-storage by folio-org.

the class NatureOfContentTermAPI method getNatureOfContentTerms.

@Validate
@Override
public void getNatureOfContentTerms(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
    /**
     * http://host:port/nature-of-content-terms
     */
    vertxContext.runOnContext(v -> {
        try {
            String tenantId = TenantTool.tenantId(okapiHeaders);
            CQLWrapper cql = getCQL(query, limit, offset);
            PostgresClient.getInstance(vertxContext.owner(), tenantId).get(REFERENCE_TABLE, NatureOfContentTerm.class, new String[] { "*" }, cql, true, true, reply -> {
                if (reply.succeeded()) {
                    NatureOfContentTerms records = new NatureOfContentTerms();
                    List<NatureOfContentTerm> record = reply.result().getResults();
                    records.setNatureOfContentTerms(record);
                    records.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
                    asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetNatureOfContentTermsResponse.respond200WithApplicationJson(records)));
                } else {
                    log.error(reply.cause().getMessage(), reply.cause());
                    asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetNatureOfContentTermsResponse.respond400WithTextPlain(reply.cause().getMessage())));
                }
            });
        } 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(GetNatureOfContentTermsResponse.respond500WithTextPlain(message)));
        }
    });
}
Also used : NatureOfContentTerm(org.folio.rest.jaxrs.model.NatureOfContentTerm) NatureOfContentTerms(org.folio.rest.jaxrs.model.NatureOfContentTerms) CQLParseException(org.z3950.zing.cql.CQLParseException) CQLWrapper(org.folio.rest.persist.cql.CQLWrapper) CQLParseException(org.z3950.zing.cql.CQLParseException) FieldException(org.folio.cql2pgjson.exception.FieldException) Validate(org.folio.rest.annotations.Validate)

Aggregations

FieldException (org.folio.cql2pgjson.exception.FieldException)1 Validate (org.folio.rest.annotations.Validate)1 NatureOfContentTerm (org.folio.rest.jaxrs.model.NatureOfContentTerm)1 NatureOfContentTerms (org.folio.rest.jaxrs.model.NatureOfContentTerms)1 CQLWrapper (org.folio.rest.persist.cql.CQLWrapper)1 CQLParseException (org.z3950.zing.cql.CQLParseException)1