Search in sources :

Example 21 with Criterion

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

the class HoldingsStorageAPI method deleteHoldingsStorageHoldingsByHoldingsRecordId.

@Override
public void deleteHoldingsStorageHoldingsByHoldingsRecordId(@NotNull String holdingsRecordId, @DefaultValue("en") @Pattern(regexp = "[a-zA-Z]{2}") String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    String tenantId = okapiHeaders.get(TENANT_HEADER);
    try {
        PostgresClient postgresClient = PostgresClient.getInstance(vertxContext.owner(), TenantTool.calculateTenantId(tenantId));
        Criteria a = new Criteria();
        a.addField("'id'");
        a.setOperation("=");
        a.setValue(holdingsRecordId);
        Criterion criterion = new Criterion(a);
        vertxContext.runOnContext(v -> {
            try {
                postgresClient.delete(HOLDINGS_RECORD_TABLE, criterion, reply -> {
                    if (reply.succeeded()) {
                        asyncResultHandler.handle(Future.succeededFuture(DeleteHoldingsStorageHoldingsByHoldingsRecordIdResponse.withNoContent()));
                    } else {
                        asyncResultHandler.handle(Future.succeededFuture(DeleteHoldingsStorageHoldingsByHoldingsRecordIdResponse.withPlainInternalServerError(reply.cause().getMessage())));
                    }
                });
            } catch (Exception e) {
                asyncResultHandler.handle(Future.succeededFuture(DeleteHoldingsStorageHoldingsByHoldingsRecordIdResponse.withPlainInternalServerError(e.getMessage())));
            }
        });
    } catch (Exception e) {
        asyncResultHandler.handle(Future.succeededFuture(DeleteHoldingsStorageHoldingsByHoldingsRecordIdResponse.withPlainInternalServerError(e.getMessage())));
    }
}
Also used : Criterion(org.folio.rest.persist.Criteria.Criterion) PostgresClient(org.folio.rest.persist.PostgresClient) Criteria(org.folio.rest.persist.Criteria.Criteria)

Example 22 with Criterion

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

the class IdentifierTypeAPI method getIdentifierTypesByIdentifierTypeId.

@Validate
@Override
public void getIdentifierTypesByIdentifierTypeId(String identifierTypeId, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    vertxContext.runOnContext(v -> {
        try {
            String tenantId = TenantTool.tenantId(okapiHeaders);
            Criterion c = new Criterion(new Criteria().addField(idFieldName).setJSONB(false).setOperation("=").setValue("'" + identifierTypeId + "'"));
            PostgresClient.getInstance(vertxContext.owner(), tenantId).get(IDENTIFIER_TYPE_TABLE, IdentifierType.class, c, true, reply -> {
                try {
                    if (reply.failed()) {
                        String msg = PgExceptionUtil.badRequestMessage(reply.cause());
                        if (msg == null) {
                            internalServerErrorDuringGetById(reply.cause(), lang, asyncResultHandler);
                            return;
                        }
                        log.info(msg);
                        asyncResultHandler.handle(Future.succeededFuture(GetIdentifierTypesByIdentifierTypeIdResponse.withPlainNotFound(msg)));
                        return;
                    }
                    @SuppressWarnings("unchecked") List<IdentifierType> identifierType = (List<IdentifierType>) reply.result().getResults();
                    if (identifierType.isEmpty()) {
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetIdentifierTypesByIdentifierTypeIdResponse.withPlainNotFound(identifierTypeId)));
                    } else {
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetIdentifierTypesByIdentifierTypeIdResponse.withJsonOK(identifierType.get(0))));
                    }
                } catch (Exception e) {
                    internalServerErrorDuringGetById(e, lang, asyncResultHandler);
                }
            });
        } catch (Exception e) {
            internalServerErrorDuringGetById(e, lang, asyncResultHandler);
        }
    });
}
Also used : Criterion(org.folio.rest.persist.Criteria.Criterion) List(java.util.List) Criteria(org.folio.rest.persist.Criteria.Criteria) IdentifierType(org.folio.rest.jaxrs.model.IdentifierType) CQLParseException(org.z3950.zing.cql.CQLParseException) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Validate(org.folio.rest.annotations.Validate)

Example 23 with Criterion

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

the class InstanceFormatAPI method getInstanceFormatsByInstanceFormatId.

@Validate
@Override
public void getInstanceFormatsByInstanceFormatId(String instanceFormatId, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    vertxContext.runOnContext(v -> {
        try {
            String tenantId = TenantTool.tenantId(okapiHeaders);
            Criterion c = new Criterion(new Criteria().addField(idFieldName).setJSONB(false).setOperation("=").setValue("'" + instanceFormatId + "'"));
            PostgresClient.getInstance(vertxContext.owner(), tenantId).get(INSTANCE_FORMAT_TABLE, InstanceFormat.class, c, true, reply -> {
                try {
                    if (reply.failed()) {
                        String msg = PgExceptionUtil.badRequestMessage(reply.cause());
                        if (msg == null) {
                            internalServerErrorDuringGetById(reply.cause(), lang, asyncResultHandler);
                            return;
                        }
                        log.info(msg);
                        asyncResultHandler.handle(Future.succeededFuture(GetInstanceFormatsByInstanceFormatIdResponse.withPlainNotFound(msg)));
                        return;
                    }
                    @SuppressWarnings("unchecked") List<InstanceFormat> instanceFormat = (List<InstanceFormat>) reply.result().getResults();
                    if (instanceFormat.isEmpty()) {
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetInstanceFormatsByInstanceFormatIdResponse.withPlainNotFound(instanceFormatId)));
                    } else {
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetInstanceFormatsByInstanceFormatIdResponse.withJsonOK(instanceFormat.get(0))));
                    }
                } catch (Exception e) {
                    internalServerErrorDuringGetById(e, lang, asyncResultHandler);
                }
            });
        } catch (Exception e) {
            internalServerErrorDuringGetById(e, lang, asyncResultHandler);
        }
    });
}
Also used : Criterion(org.folio.rest.persist.Criteria.Criterion) List(java.util.List) Criteria(org.folio.rest.persist.Criteria.Criteria) CQLParseException(org.z3950.zing.cql.CQLParseException) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) InstanceFormat(org.folio.rest.jaxrs.model.InstanceFormat) Validate(org.folio.rest.annotations.Validate)

Example 24 with Criterion

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

the class InstanceStorageAPI method deleteInstanceStorageInstancesByInstanceId.

@Override
public void deleteInstanceStorageInstancesByInstanceId(@NotNull String instanceId, @DefaultValue("en") @Pattern(regexp = "[a-zA-Z]{2}") String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    String tenantId = okapiHeaders.get(TENANT_HEADER);
    try {
        PostgresClient postgresClient = PostgresClient.getInstance(vertxContext.owner(), TenantTool.calculateTenantId(tenantId));
        Criteria a = new Criteria();
        a.addField("'id'");
        a.setOperation("=");
        a.setValue(instanceId);
        Criterion criterion = new Criterion(a);
        vertxContext.runOnContext(v -> {
            try {
                postgresClient.delete("instance", criterion, reply -> {
                    if (reply.succeeded()) {
                        asyncResultHandler.handle(Future.succeededFuture(DeleteInstanceStorageInstancesByInstanceIdResponse.withNoContent()));
                    } else {
                        asyncResultHandler.handle(Future.succeededFuture(DeleteInstanceStorageInstancesByInstanceIdResponse.withPlainInternalServerError(reply.cause().getMessage())));
                    }
                });
            } catch (Exception e) {
                asyncResultHandler.handle(Future.succeededFuture(DeleteInstanceStorageInstancesByInstanceIdResponse.withPlainInternalServerError(e.getMessage())));
            }
        });
    } catch (Exception e) {
        asyncResultHandler.handle(Future.succeededFuture(DeleteInstanceStorageInstancesByInstanceIdResponse.withPlainInternalServerError(e.getMessage())));
    }
}
Also used : Criterion(org.folio.rest.persist.Criteria.Criterion) PostgresClient(org.folio.rest.persist.PostgresClient) Criteria(org.folio.rest.persist.Criteria.Criteria) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException)

Example 25 with Criterion

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

the class InstanceTypeAPI method getInstanceTypesByInstanceTypeId.

@Validate
@Override
public void getInstanceTypesByInstanceTypeId(String instanceTypeId, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    vertxContext.runOnContext(v -> {
        try {
            String tenantId = TenantTool.tenantId(okapiHeaders);
            Criterion c = new Criterion(new Criteria().addField(idFieldName).setJSONB(false).setOperation("=").setValue("'" + instanceTypeId + "'"));
            PostgresClient.getInstance(vertxContext.owner(), tenantId).get(INSTANCE_TYPE_TABLE, InstanceType.class, c, true, reply -> {
                try {
                    if (reply.failed()) {
                        String msg = PgExceptionUtil.badRequestMessage(reply.cause());
                        if (msg == null) {
                            internalServerErrorDuringGetById(reply.cause(), lang, asyncResultHandler);
                            return;
                        }
                        log.info(msg);
                        asyncResultHandler.handle(Future.succeededFuture(GetInstanceTypesByInstanceTypeIdResponse.withPlainNotFound(msg)));
                        return;
                    }
                    @SuppressWarnings("unchecked") List<InstanceType> instanceType = (List<InstanceType>) reply.result().getResults();
                    if (instanceType.isEmpty()) {
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetInstanceTypesByInstanceTypeIdResponse.withPlainNotFound(instanceTypeId)));
                    } else {
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetInstanceTypesByInstanceTypeIdResponse.withJsonOK(instanceType.get(0))));
                    }
                } catch (Exception e) {
                    internalServerErrorDuringGetById(e, lang, asyncResultHandler);
                }
            });
        } catch (Exception e) {
            internalServerErrorDuringGetById(e, lang, asyncResultHandler);
        }
    });
}
Also used : Criterion(org.folio.rest.persist.Criteria.Criterion) List(java.util.List) Criteria(org.folio.rest.persist.Criteria.Criteria) InstanceType(org.folio.rest.jaxrs.model.InstanceType) CQLParseException(org.z3950.zing.cql.CQLParseException) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Validate(org.folio.rest.annotations.Validate)

Aggregations

Criterion (org.folio.rest.persist.Criteria.Criterion)32 Criteria (org.folio.rest.persist.Criteria.Criteria)31 FieldException (org.z3950.zing.cql.cql2pgjson.FieldException)26 List (java.util.List)18 Validate (org.folio.rest.annotations.Validate)14 CQLParseException (org.z3950.zing.cql.CQLParseException)8 PostgresClient (org.folio.rest.persist.PostgresClient)3 IOException (java.io.IOException)2 JobConf (org.folio.rest.jaxrs.model.JobConf)2 Location (org.folio.rest.jaxrs.model.Location)2 Limit (org.folio.rest.persist.Criteria.Limit)2 Offset (org.folio.rest.persist.Criteria.Offset)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 UnrecognizedPropertyException (com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException)1 SQLConnection (io.vertx.ext.sql.SQLConnection)1 Async (io.vertx.ext.unit.Async)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NotImplementedException (org.apache.commons.lang.NotImplementedException)1