Search in sources :

Example 1 with Loccamp

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

the class LocationUnitAPI method getLocationUnitsCampusesById.

@Override
public void getLocationUnitsCampusesById(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(CAMP_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.GetLocationUnitsCampusesByIdResponse.withPlainInternalServerError(message)));
        return;
    }
    PostgresClient.getInstance(vertxContext.owner(), tenantId).get(CAMPUS_TABLE, Loccamp.class, criterion, true, false, getReply -> {
        if (getReply.failed()) {
            String message = logAndSaveError(getReply.cause());
            asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsCampusesByIdResponse.withPlainInternalServerError(message)));
        } else {
            List<Loccamp> items = (List<Loccamp>) getReply.result().getResults();
            if (items.isEmpty()) {
                asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsCampusesByIdResponse.withPlainNotFound(messages.getMessage(lang, MessageConsts.ObjectDoesNotExist))));
            } else if (items.size() > 1) {
                String message = "Multiple campuses found with the same id";
                logger.error(message);
                asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsCampusesByIdResponse.withPlainInternalServerError(message)));
            } else {
                asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsCampusesByIdResponse.withJsonOK(items.get(0))));
            }
        }
    });
}
Also used : Loccamp(org.folio.rest.jaxrs.model.Loccamp) 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)

Example 2 with Loccamp

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

the class LocationUnitAPI method getLocationUnitsCampuses.

@Override
public void getLocationUnitsCampuses(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, CAMPUS_TABLE);
    } catch (Exception e) {
        String message = logAndSaveError(e);
        asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsCampusesResponse.withPlainInternalServerError(message)));
        return;
    }
    PostgresClient.getInstance(vertxContext.owner(), tenantId).get(CAMPUS_TABLE, Loccamp.class, new String[] { "*" }, cql, true, true, reply -> {
        if (reply.failed()) {
            String message = logAndSaveError(reply.cause());
            asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsCampusesResponse.withPlainBadRequest(message)));
        } else {
            Loccamps camps = new Loccamps();
            List<Loccamp> items = (List<Loccamp>) reply.result().getResults();
            camps.setLoccamps(items);
            camps.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
            asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsCampusesResponse.withJsonOK(camps)));
        }
    });
}
Also used : Loccamp(org.folio.rest.jaxrs.model.Loccamp) List(java.util.List) CQLWrapper(org.folio.rest.persist.cql.CQLWrapper) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Loccamps(org.folio.rest.jaxrs.model.Loccamps)

Aggregations

List (java.util.List)2 Loccamp (org.folio.rest.jaxrs.model.Loccamp)2 FieldException (org.z3950.zing.cql.cql2pgjson.FieldException)2 Loccamps (org.folio.rest.jaxrs.model.Loccamps)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