Search in sources :

Example 6 with CQLParseException

use of org.z3950.zing.cql.CQLParseException in project mod-inventory-storage by folio-org.

the class MaterialTypeAPI method getMaterialTypes.

@Validate
@Override
public void getMaterialTypes(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    /**
     * http://host:port/material-types
     */
    vertxContext.runOnContext(v -> {
        try {
            String tenantId = TenantTool.calculateTenantId(okapiHeaders.get(RestVerticle.OKAPI_HEADER_TENANT));
            CQLWrapper cql = getCQL(query, limit, offset);
            PostgresClient.getInstance(vertxContext.owner(), tenantId).get(MATERIAL_TYPE_TABLE, Mtype.class, new String[] { "*" }, cql, true, true, reply -> {
                try {
                    if (reply.succeeded()) {
                        Mtypes mtypes = new Mtypes();
                        @SuppressWarnings("unchecked") List<Mtype> mtype = (List<Mtype>) reply.result().getResults();
                        mtypes.setMtypes(mtype);
                        mtypes.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetMaterialTypesResponse.withJsonOK(mtypes)));
                    } else {
                        log.error(reply.cause().getMessage(), reply.cause());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetMaterialTypesResponse.withPlainBadRequest(reply.cause().getMessage())));
                    }
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                    asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetMaterialTypesResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
                }
            });
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            String message = messages.getMessage(lang, MessageConsts.InternalServerError);
            if (e.getCause() != null && e.getCause().getClass().getSimpleName().endsWith("CQLParseException")) {
                message = " CQL parse error " + e.getLocalizedMessage();
            }
            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetMaterialTypesResponse.withPlainInternalServerError(message)));
        }
    });
}
Also used : Mtype(org.folio.rest.jaxrs.model.Mtype) List(java.util.List) Mtypes(org.folio.rest.jaxrs.model.Mtypes) CQLWrapper(org.folio.rest.persist.cql.CQLWrapper) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Validate(org.folio.rest.annotations.Validate)

Example 7 with CQLParseException

use of org.z3950.zing.cql.CQLParseException in project mod-inventory-storage by folio-org.

the class LoanTypeAPI method getLoanTypes.

@Validate
@Override
public void getLoanTypes(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    /**
     * http://host:port/loan-types
     */
    vertxContext.runOnContext(v -> {
        try {
            CQLWrapper cql = getCQL(query, limit, offset);
            getPostgresClient(vertxContext, okapiHeaders).get(LOAN_TYPE_TABLE, Loantype.class, new String[] { "*" }, cql, true, true, reply -> {
                try {
                    if (reply.succeeded()) {
                        Loantypes loantypes = new Loantypes();
                        @SuppressWarnings("unchecked") List<Loantype> loantype = (List<Loantype>) reply.result().getResults();
                        loantypes.setLoantypes(loantype);
                        loantypes.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetLoanTypesResponse.withJsonOK(loantypes)));
                    } else {
                        log.error(reply.cause().getMessage(), reply.cause());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetLoanTypesResponse.withPlainBadRequest(reply.cause().getMessage())));
                    }
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                    asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetLoanTypesResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
                }
            });
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            String message = messages.getMessage(lang, MessageConsts.InternalServerError);
            if (e.getCause() instanceof CQLParseException) {
                message = " CQL parse error " + e.getLocalizedMessage();
            }
            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetLoanTypesResponse.withPlainInternalServerError(message)));
        }
    });
}
Also used : Loantypes(org.folio.rest.jaxrs.model.Loantypes) List(java.util.List) Loantype(org.folio.rest.jaxrs.model.Loantype) CQLParseException(org.z3950.zing.cql.CQLParseException) CQLWrapper(org.folio.rest.persist.cql.CQLWrapper) CQLParseException(org.z3950.zing.cql.CQLParseException) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Validate(org.folio.rest.annotations.Validate)

Example 8 with CQLParseException

use of org.z3950.zing.cql.CQLParseException in project mod-inventory-storage by folio-org.

the class ClassificationTypeAPI method getClassificationTypes.

@Validate
@Override
public void getClassificationTypes(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    /**
     * http://host:port/classification-types
     */
    vertxContext.runOnContext(v -> {
        try {
            String tenantId = TenantTool.tenantId(okapiHeaders);
            CQLWrapper cql = getCQL(query, limit, offset);
            PostgresClient.getInstance(vertxContext.owner(), tenantId).get(CLASSIFICATION_TYPE_TABLE, ClassificationType.class, new String[] { "*" }, cql, true, true, reply -> {
                try {
                    if (reply.succeeded()) {
                        ClassificationTypes instanceTypes = new ClassificationTypes();
                        @SuppressWarnings("unchecked") List<ClassificationType> instanceType = (List<ClassificationType>) reply.result().getResults();
                        instanceTypes.setClassificationTypes(instanceType);
                        instanceTypes.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetClassificationTypesResponse.withJsonOK(instanceTypes)));
                    } else {
                        log.error(reply.cause().getMessage(), reply.cause());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetClassificationTypesResponse.withPlainBadRequest(reply.cause().getMessage())));
                    }
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                    asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetClassificationTypesResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
                }
            });
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            String message = messages.getMessage(lang, MessageConsts.InternalServerError);
            if (e.getCause() instanceof CQLParseException) {
                message = " CQL parse error " + e.getLocalizedMessage();
            }
            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetClassificationTypesResponse.withPlainInternalServerError(message)));
        }
    });
}
Also used : ClassificationTypes(org.folio.rest.jaxrs.model.ClassificationTypes) List(java.util.List) ClassificationType(org.folio.rest.jaxrs.model.ClassificationType) CQLParseException(org.z3950.zing.cql.CQLParseException) CQLWrapper(org.folio.rest.persist.cql.CQLWrapper) CQLParseException(org.z3950.zing.cql.CQLParseException) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Validate(org.folio.rest.annotations.Validate)

Example 9 with CQLParseException

use of org.z3950.zing.cql.CQLParseException in project mod-inventory-storage by folio-org.

the class ContributorNameTypeAPI method getContributorNameTypes.

@Validate
@Override
public void getContributorNameTypes(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    /**
     * http://host:port/contributor-name-types
     */
    vertxContext.runOnContext(v -> {
        try {
            String tenantId = TenantTool.tenantId(okapiHeaders);
            CQLWrapper cql = getCQL(query, limit, offset);
            PostgresClient.getInstance(vertxContext.owner(), tenantId).get(CONTRIBUTOR_NAME_TYPE_TABLE, ContributorNameType.class, new String[] { "*" }, cql, true, true, reply -> {
                try {
                    if (reply.succeeded()) {
                        ContributorNameTypes ContributorNameTypes = new ContributorNameTypes();
                        @SuppressWarnings("unchecked") List<ContributorNameType> ContributorNameType = (List<ContributorNameType>) reply.result().getResults();
                        ContributorNameTypes.setContributorNameTypes(ContributorNameType);
                        ContributorNameTypes.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetContributorNameTypesResponse.withJsonOK(ContributorNameTypes)));
                    } else {
                        log.error(reply.cause().getMessage(), reply.cause());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetContributorNameTypesResponse.withPlainBadRequest(reply.cause().getMessage())));
                    }
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                    asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetContributorNameTypesResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
                }
            });
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            String message = messages.getMessage(lang, MessageConsts.InternalServerError);
            if (e.getCause() instanceof CQLParseException) {
                message = " CQL parse error " + e.getLocalizedMessage();
            }
            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetContributorNameTypesResponse.withPlainInternalServerError(message)));
        }
    });
}
Also used : ContributorNameTypes(org.folio.rest.jaxrs.model.ContributorNameTypes) ContributorNameType(org.folio.rest.jaxrs.model.ContributorNameType) List(java.util.List) CQLParseException(org.z3950.zing.cql.CQLParseException) CQLWrapper(org.folio.rest.persist.cql.CQLWrapper) CQLParseException(org.z3950.zing.cql.CQLParseException) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Validate(org.folio.rest.annotations.Validate)

Example 10 with CQLParseException

use of org.z3950.zing.cql.CQLParseException in project mod-inventory-storage by folio-org.

the class ContributorTypeAPI method getContributorTypes.

@Validate
@Override
public void getContributorTypes(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    /**
     * http://host:port/contributor-types
     */
    vertxContext.runOnContext(v -> {
        try {
            String tenantId = TenantTool.tenantId(okapiHeaders);
            CQLWrapper cql = getCQL(query, limit, offset);
            PostgresClient.getInstance(vertxContext.owner(), tenantId).get(CONTRIBUTOR_TYPE_TABLE, ContributorType.class, new String[] { "*" }, cql, true, true, reply -> {
                try {
                    if (reply.succeeded()) {
                        ContributorTypes contributorTypes = new ContributorTypes();
                        @SuppressWarnings("unchecked") List<ContributorType> contributorType = (List<ContributorType>) reply.result().getResults();
                        contributorTypes.setContributorTypes(contributorType);
                        contributorTypes.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetContributorTypesResponse.withJsonOK(contributorTypes)));
                    } else {
                        log.error(reply.cause().getMessage(), reply.cause());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetContributorTypesResponse.withPlainBadRequest(reply.cause().getMessage())));
                    }
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                    asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetContributorTypesResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
                }
            });
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            String message = messages.getMessage(lang, MessageConsts.InternalServerError);
            if (e.getCause() instanceof CQLParseException) {
                message = " CQL parse error " + e.getLocalizedMessage();
            }
            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetContributorTypesResponse.withPlainInternalServerError(message)));
        }
    });
}
Also used : ContributorType(org.folio.rest.jaxrs.model.ContributorType) List(java.util.List) ContributorTypes(org.folio.rest.jaxrs.model.ContributorTypes) CQLParseException(org.z3950.zing.cql.CQLParseException) CQLWrapper(org.folio.rest.persist.cql.CQLWrapper) CQLParseException(org.z3950.zing.cql.CQLParseException) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException) Validate(org.folio.rest.annotations.Validate)

Aggregations

List (java.util.List)10 Validate (org.folio.rest.annotations.Validate)10 CQLWrapper (org.folio.rest.persist.cql.CQLWrapper)10 FieldException (org.z3950.zing.cql.cql2pgjson.FieldException)10 CQLParseException (org.z3950.zing.cql.CQLParseException)8 ClassificationType (org.folio.rest.jaxrs.model.ClassificationType)1 ClassificationTypes (org.folio.rest.jaxrs.model.ClassificationTypes)1 ContributorNameType (org.folio.rest.jaxrs.model.ContributorNameType)1 ContributorNameTypes (org.folio.rest.jaxrs.model.ContributorNameTypes)1 ContributorType (org.folio.rest.jaxrs.model.ContributorType)1 ContributorTypes (org.folio.rest.jaxrs.model.ContributorTypes)1 IdentifierType (org.folio.rest.jaxrs.model.IdentifierType)1 IdentifierTypes (org.folio.rest.jaxrs.model.IdentifierTypes)1 InstanceFormat (org.folio.rest.jaxrs.model.InstanceFormat)1 InstanceFormats (org.folio.rest.jaxrs.model.InstanceFormats)1 InstanceType (org.folio.rest.jaxrs.model.InstanceType)1 InstanceTypes (org.folio.rest.jaxrs.model.InstanceTypes)1 Loantype (org.folio.rest.jaxrs.model.Loantype)1 Loantypes (org.folio.rest.jaxrs.model.Loantypes)1 Mtype (org.folio.rest.jaxrs.model.Mtype)1