Search in sources :

Example 1 with Criteria

use of org.folio.rest.persist.Criteria.Criteria in project mod-inventory-storage by folio-org.

the class LocationUnitAPI method deleteLocationUnitsInstitutionsById.

@Override
public void deleteLocationUnitsInstitutionsById(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.DeleteLocationUnitsInstitutionsByIdResponse.withPlainInternalServerError(message)));
        return;
    }
    instInUse(id, tenantId, vertxContext).setHandler(res -> {
        if (res.failed()) {
            String message = logAndSaveError(res.cause());
            LocationUnitsResource.DeleteLocationUnitsInstitutionsByIdResponse.withPlainInternalServerError(message);
        } else {
            if (res.result()) {
                asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsInstitutionsByIdResponse.withPlainBadRequest("Cannot delete institution, as it is in use")));
            } else {
                try {
                    PostgresClient.getInstance(vertxContext.owner(), tenantId).delete(INSTITUTION_TABLE, criterion, deleteReply -> {
                        if (deleteReply.failed()) {
                            logAndSaveError(deleteReply.cause());
                            asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsInstitutionsByIdResponse.withPlainNotFound("Institution not found")));
                        } else {
                            asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsInstitutionsByIdResponse.withNoContent()));
                        }
                    });
                } catch (Exception e) {
                    String message = logAndSaveError(e);
                    asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsInstitutionsByIdResponse.withPlainInternalServerError(message)));
                }
            }
        }
    });
}
Also used : Criterion(org.folio.rest.persist.Criteria.Criterion) Criteria(org.folio.rest.persist.Criteria.Criteria) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException)

Example 2 with Criteria

use of org.folio.rest.persist.Criteria.Criteria in project mod-inventory-storage by folio-org.

the class LocationUnitAPI method deleteLocationUnitsCampusesById.

@Override
public void deleteLocationUnitsCampusesById(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.DeleteLocationUnitsCampusesByIdResponse.withPlainInternalServerError(message)));
        return;
    }
    campInUse(id, tenantId, vertxContext).setHandler(res -> {
        if (res.failed()) {
            String message = logAndSaveError(res.cause());
            LocationUnitsResource.DeleteLocationUnitsCampusesByIdResponse.withPlainInternalServerError(message);
        } else {
            if (res.result()) {
                asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsCampusesByIdResponse.withPlainBadRequest("Cannot delete campus, as it is in use")));
            } else {
                PostgresClient.getInstance(vertxContext.owner(), tenantId).delete(CAMPUS_TABLE, criterion, deleteReply -> {
                    if (deleteReply.failed()) {
                        logAndSaveError(deleteReply.cause());
                        asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsCampusesByIdResponse.withPlainNotFound("Campus not found")));
                    } else {
                        asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.DeleteLocationUnitsCampusesByIdResponse.withNoContent()));
                    }
                });
            }
        }
    });
}
Also used : Criterion(org.folio.rest.persist.Criteria.Criterion) Criteria(org.folio.rest.persist.Criteria.Criteria) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException)

Example 3 with Criteria

use of org.folio.rest.persist.Criteria.Criteria 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 4 with Criteria

use of org.folio.rest.persist.Criteria.Criteria in project mod-inventory-storage by folio-org.

the class LocationUnitAPI method putLocationUnitsCampusesById.

@Override
public void putLocationUnitsCampusesById(String id, String lang, Loccamp entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    if (!id.equals(entity.getId())) {
        String message = "Illegal operation: id cannot be changed";
        asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.PutLocationUnitsCampusesByIdResponse.withPlainBadRequest(message)));
        return;
    }
    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.PutLocationUnitsCampusesByIdResponse.withPlainInternalServerError(message)));
        return;
    }
    PostgresClient.getInstance(vertxContext.owner(), tenantId).update(CAMPUS_TABLE, entity, criterion, false, updateReply -> {
        if (updateReply.failed()) {
            String message = logAndSaveError(updateReply.cause());
            asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.PutLocationUnitsCampusesByIdResponse.withPlainInternalServerError(message)));
        } else {
            if (updateReply.result().getUpdated() == 0) {
                asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.PutLocationUnitsCampusesByIdResponse.withPlainNotFound("Campus not found")));
            } else {
                asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.PutLocationUnitsCampusesByIdResponse.withNoContent()));
            }
        }
    });
}
Also used : Criterion(org.folio.rest.persist.Criteria.Criterion) Criteria(org.folio.rest.persist.Criteria.Criteria) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException)

Example 5 with Criteria

use of org.folio.rest.persist.Criteria.Criteria 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)

Aggregations

Criteria (org.folio.rest.persist.Criteria.Criteria)30 Criterion (org.folio.rest.persist.Criteria.Criterion)29 FieldException (org.z3950.zing.cql.cql2pgjson.FieldException)26 List (java.util.List)16 Validate (org.folio.rest.annotations.Validate)12 CQLParseException (org.z3950.zing.cql.CQLParseException)8 PostgresClient (org.folio.rest.persist.PostgresClient)3 Location (org.folio.rest.jaxrs.model.Location)2 Async (io.vertx.ext.unit.Async)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 NotImplementedException (org.apache.commons.lang.NotImplementedException)1 ClassificationType (org.folio.rest.jaxrs.model.ClassificationType)1 ContributorNameType (org.folio.rest.jaxrs.model.ContributorNameType)1 ContributorType (org.folio.rest.jaxrs.model.ContributorType)1 IdentifierType (org.folio.rest.jaxrs.model.IdentifierType)1 InstanceFormat (org.folio.rest.jaxrs.model.InstanceFormat)1 InstanceType (org.folio.rest.jaxrs.model.InstanceType)1 JobConf (org.folio.rest.jaxrs.model.JobConf)1 Loantype (org.folio.rest.jaxrs.model.Loantype)1