Search in sources :

Example 26 with Validate

use of org.folio.rest.annotations.Validate in project mod-inventory-storage by folio-org.

the class LoanTypeAPI method deleteLoanTypesByLoantypeId.

@Validate
@Override
public void deleteLoanTypesByLoantypeId(String loantypeId, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    vertxContext.runOnContext(v -> {
        try {
            PostgresClient postgres = getPostgresClient(vertxContext, okapiHeaders);
            postgres.delete(LOAN_TYPE_TABLE, loantypeId, reply -> {
                try {
                    if (reply.failed()) {
                        String msg = PgExceptionUtil.badRequestMessage(reply.cause());
                        if (msg == null) {
                            internalServerErrorDuringDelete(reply.cause(), lang, asyncResultHandler);
                            return;
                        }
                        log.info(msg);
                        asyncResultHandler.handle(Future.succeededFuture(DeleteLoanTypesByLoantypeIdResponse.withPlainBadRequest(msg)));
                        return;
                    }
                    int updated = reply.result().getUpdated();
                    if (updated != 1) {
                        String msg = messages.getMessage(lang, MessageConsts.DeletedCountError, 1, updated);
                        log.error(msg);
                        asyncResultHandler.handle(Future.succeededFuture(DeleteLoanTypesByLoantypeIdResponse.withPlainNotFound(msg)));
                        return;
                    }
                    asyncResultHandler.handle(Future.succeededFuture(DeleteLoanTypesByLoantypeIdResponse.withNoContent()));
                } catch (Exception e) {
                    internalServerErrorDuringDelete(e, lang, asyncResultHandler);
                }
            });
        } catch (Exception e) {
            internalServerErrorDuringDelete(e, lang, asyncResultHandler);
        }
    });
}
Also used : PostgresClient(org.folio.rest.persist.PostgresClient) CQLParseException(org.z3950.zing.cql.CQLParseException) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Validate(org.folio.rest.annotations.Validate)

Example 27 with Validate

use of org.folio.rest.annotations.Validate in project mod-inventory-storage by folio-org.

the class ClassificationTypeAPI method getClassificationTypesByClassificationTypeId.

@Validate
@Override
public void getClassificationTypesByClassificationTypeId(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(CLASSIFICATION_TYPE_TABLE, ClassificationType.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(GetClassificationTypesByClassificationTypeIdResponse.withPlainNotFound(msg)));
                        return;
                    }
                    @SuppressWarnings("unchecked") List<ClassificationType> instanceType = (List<ClassificationType>) reply.result().getResults();
                    if (instanceType.isEmpty()) {
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetClassificationTypesByClassificationTypeIdResponse.withPlainNotFound(instanceTypeId)));
                    } else {
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetClassificationTypesByClassificationTypeIdResponse.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) ClassificationType(org.folio.rest.jaxrs.model.ClassificationType) CQLParseException(org.z3950.zing.cql.CQLParseException) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Validate(org.folio.rest.annotations.Validate)

Example 28 with Validate

use of org.folio.rest.annotations.Validate in project mod-inventory-storage by folio-org.

the class ContributorNameTypeAPI method deleteContributorNameTypesByContributorNameTypeId.

@Validate
@Override
public void deleteContributorNameTypesByContributorNameTypeId(String ContributorNameTypeId, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    vertxContext.runOnContext(v -> {
        try {
            String tenantId = TenantTool.tenantId(okapiHeaders);
            PostgresClient postgres = PostgresClient.getInstance(vertxContext.owner(), tenantId);
            postgres.delete(CONTRIBUTOR_NAME_TYPE_TABLE, ContributorNameTypeId, reply -> {
                try {
                    if (reply.failed()) {
                        String msg = PgExceptionUtil.badRequestMessage(reply.cause());
                        if (msg == null) {
                            internalServerErrorDuringDelete(reply.cause(), lang, asyncResultHandler);
                            return;
                        }
                        log.info(msg);
                        asyncResultHandler.handle(Future.succeededFuture(DeleteContributorNameTypesByContributorNameTypeIdResponse.withPlainBadRequest(msg)));
                        return;
                    }
                    int updated = reply.result().getUpdated();
                    if (updated != 1) {
                        String msg = messages.getMessage(lang, MessageConsts.DeletedCountError, 1, updated);
                        log.error(msg);
                        asyncResultHandler.handle(Future.succeededFuture(DeleteContributorNameTypesByContributorNameTypeIdResponse.withPlainNotFound(msg)));
                        return;
                    }
                    asyncResultHandler.handle(Future.succeededFuture(DeleteContributorNameTypesByContributorNameTypeIdResponse.withNoContent()));
                } catch (Exception e) {
                    internalServerErrorDuringDelete(e, lang, asyncResultHandler);
                }
            });
        } catch (Exception e) {
            internalServerErrorDuringDelete(e, lang, asyncResultHandler);
        }
    });
}
Also used : PostgresClient(org.folio.rest.persist.PostgresClient) CQLParseException(org.z3950.zing.cql.CQLParseException) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Validate(org.folio.rest.annotations.Validate)

Example 29 with Validate

use of org.folio.rest.annotations.Validate in project mod-inventory-storage by folio-org.

the class ContributorNameTypeAPI method getContributorNameTypesByContributorNameTypeId.

@Validate
@Override
public void getContributorNameTypesByContributorNameTypeId(String ContributorNameTypeId, 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("'" + ContributorNameTypeId + "'"));
            PostgresClient.getInstance(vertxContext.owner(), tenantId).get(CONTRIBUTOR_NAME_TYPE_TABLE, ContributorNameType.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(GetContributorNameTypesByContributorNameTypeIdResponse.withPlainNotFound(msg)));
                        return;
                    }
                    @SuppressWarnings("unchecked") List<ContributorNameType> ContributorNameType = (List<ContributorNameType>) reply.result().getResults();
                    if (ContributorNameType.isEmpty()) {
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetContributorNameTypesByContributorNameTypeIdResponse.withPlainNotFound(ContributorNameTypeId)));
                    } else {
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetContributorNameTypesByContributorNameTypeIdResponse.withJsonOK(ContributorNameType.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) ContributorNameType(org.folio.rest.jaxrs.model.ContributorNameType) List(java.util.List) Criteria(org.folio.rest.persist.Criteria.Criteria) CQLParseException(org.z3950.zing.cql.CQLParseException) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Validate(org.folio.rest.annotations.Validate)

Example 30 with Validate

use of org.folio.rest.annotations.Validate in project mod-inventory-storage by folio-org.

the class PlatformAPI method deletePlatformsByPlatformId.

@Validate
@Override
public void deletePlatformsByPlatformId(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);
            PostgresClient postgres = PostgresClient.getInstance(vertxContext.owner(), tenantId);
            postgres.delete(PLATFORM_TABLE, instanceTypeId, reply -> {
                try {
                    if (reply.failed()) {
                        String msg = PgExceptionUtil.badRequestMessage(reply.cause());
                        if (msg == null) {
                            internalServerErrorDuringDelete(reply.cause(), lang, asyncResultHandler);
                            return;
                        }
                        log.info(msg);
                        asyncResultHandler.handle(Future.succeededFuture(PlatformsResource.DeletePlatformsByPlatformIdResponse.withPlainBadRequest(msg)));
                        return;
                    }
                    int updated = reply.result().getUpdated();
                    if (updated != 1) {
                        String msg = messages.getMessage(lang, MessageConsts.DeletedCountError, 1, updated);
                        log.error(msg);
                        asyncResultHandler.handle(Future.succeededFuture(PlatformsResource.DeletePlatformsByPlatformIdResponse.withPlainNotFound(msg)));
                        return;
                    }
                    asyncResultHandler.handle(Future.succeededFuture(PlatformsResource.DeletePlatformsByPlatformIdResponse.withNoContent()));
                } catch (Exception e) {
                    internalServerErrorDuringDelete(e, lang, asyncResultHandler);
                }
            });
        } catch (Exception e) {
            internalServerErrorDuringDelete(e, lang, asyncResultHandler);
        }
    });
}
Also used : PostgresClient(org.folio.rest.persist.PostgresClient) CQLParseException(org.z3950.zing.cql.CQLParseException) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Validate(org.folio.rest.annotations.Validate)

Aggregations

Validate (org.folio.rest.annotations.Validate)66 FieldException (org.z3950.zing.cql.cql2pgjson.FieldException)42 CQLParseException (org.z3950.zing.cql.CQLParseException)32 List (java.util.List)27 OutStream (org.folio.rest.tools.utils.OutStream)27 Criteria (org.folio.rest.persist.Criteria.Criteria)16 Criterion (org.folio.rest.persist.Criteria.Criterion)16 PostgresClient (org.folio.rest.persist.PostgresClient)16 CQLWrapper (org.folio.rest.persist.cql.CQLWrapper)13 JsonObject (io.vertx.core.json.JsonObject)4 Map (java.util.Map)4 Response (javax.ws.rs.core.Response)4 TenantTool (org.folio.rest.tools.utils.TenantTool)4 InputStream (java.io.InputStream)3 BodyPart (javax.mail.BodyPart)3 io.vertx.core (io.vertx.core)2 AsyncResult (io.vertx.core.AsyncResult)2 Context (io.vertx.core.Context)2 Handler (io.vertx.core.Handler)2 Logger (io.vertx.core.logging.Logger)2