Search in sources :

Example 1 with Locinst

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

Example 2 with Locinst

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))));
            }
        }
    });
}
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) Locinst(org.folio.rest.jaxrs.model.Locinst)

Aggregations

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