Search in sources :

Example 1 with Loclib

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))));
            }
        }
    });
}
Also used : Criterion(org.folio.rest.persist.Criteria.Criterion) List(java.util.List) Criteria(org.folio.rest.persist.Criteria.Criteria) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Loclib(org.folio.rest.jaxrs.model.Loclib)

Example 2 with Loclib

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)));
        }
    });
}
Also used : Loclibs(org.folio.rest.jaxrs.model.Loclibs) List(java.util.List) CQLWrapper(org.folio.rest.persist.cql.CQLWrapper) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Loclib(org.folio.rest.jaxrs.model.Loclib)

Aggregations

List (java.util.List)2 Loclib (org.folio.rest.jaxrs.model.Loclib)2 FieldException (org.z3950.zing.cql.cql2pgjson.FieldException)2 Loclibs (org.folio.rest.jaxrs.model.Loclibs)1 Criteria (org.folio.rest.persist.Criteria.Criteria)1 Criterion (org.folio.rest.persist.Criteria.Criterion)1 CQLWrapper (org.folio.rest.persist.cql.CQLWrapper)1