Search in sources :

Example 1 with CQLParseException

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

the class PlatformAPI method getPlatforms.

@Validate
@Override
public void getPlatforms(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    /**
     * http://host:port/platforms
     */
    vertxContext.runOnContext(v -> {
        try {
            String tenantId = TenantTool.tenantId(okapiHeaders);
            CQLWrapper cql = getCQL(query, limit, offset);
            PostgresClient.getInstance(vertxContext.owner(), tenantId).get(PLATFORM_TABLE, Platform.class, new String[] { "*" }, cql, true, true, reply -> {
                try {
                    if (reply.succeeded()) {
                        Platforms instanceTypes = new Platforms();
                        @SuppressWarnings("unchecked") List<Platform> instanceType = (List<Platform>) reply.result().getResults();
                        instanceTypes.setPlatforms(instanceType);
                        instanceTypes.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PlatformsResource.GetPlatformsResponse.withJsonOK(instanceTypes)));
                    } else {
                        log.error(reply.cause().getMessage(), reply.cause());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PlatformsResource.GetPlatformsResponse.withPlainBadRequest(reply.cause().getMessage())));
                    }
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                    asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PlatformsResource.GetPlatformsResponse.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(PlatformsResource.GetPlatformsResponse.withPlainInternalServerError(message)));
        }
    });
}
Also used : Platforms(org.folio.rest.jaxrs.model.Platforms) Platform(org.folio.rest.jaxrs.model.Platform) 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 2 with CQLParseException

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

the class IdentifierTypeAPI method getIdentifierTypes.

@Validate
@Override
public void getIdentifierTypes(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    /**
     * http://host:port/identifier-types
     */
    vertxContext.runOnContext(v -> {
        try {
            String tenantId = TenantTool.tenantId(okapiHeaders);
            CQLWrapper cql = getCQL(query, limit, offset);
            PostgresClient.getInstance(vertxContext.owner(), tenantId).get(IDENTIFIER_TYPE_TABLE, IdentifierType.class, new String[] { "*" }, cql, true, true, reply -> {
                try {
                    if (reply.succeeded()) {
                        IdentifierTypes identifierTypes = new IdentifierTypes();
                        @SuppressWarnings("unchecked") List<IdentifierType> identifierType = (List<IdentifierType>) reply.result().getResults();
                        identifierTypes.setIdentifierTypes(identifierType);
                        identifierTypes.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetIdentifierTypesResponse.withJsonOK(identifierTypes)));
                    } else {
                        log.error(reply.cause().getMessage(), reply.cause());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetIdentifierTypesResponse.withPlainBadRequest(reply.cause().getMessage())));
                    }
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                    asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetIdentifierTypesResponse.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(GetIdentifierTypesResponse.withPlainInternalServerError(message)));
        }
    });
}
Also used : IdentifierTypes(org.folio.rest.jaxrs.model.IdentifierTypes) List(java.util.List) IdentifierType(org.folio.rest.jaxrs.model.IdentifierType) 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 3 with CQLParseException

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

the class InstanceFormatAPI method getInstanceFormats.

@Validate
@Override
public void getInstanceFormats(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    /**
     * http://host:port/instance-formats
     */
    vertxContext.runOnContext(v -> {
        try {
            String tenantId = TenantTool.tenantId(okapiHeaders);
            CQLWrapper cql = getCQL(query, limit, offset);
            PostgresClient.getInstance(vertxContext.owner(), tenantId).get(INSTANCE_FORMAT_TABLE, InstanceFormat.class, new String[] { "*" }, cql, true, true, reply -> {
                try {
                    if (reply.succeeded()) {
                        InstanceFormats instanceFormats = new InstanceFormats();
                        @SuppressWarnings("unchecked") List<InstanceFormat> instanceFormat = (List<InstanceFormat>) reply.result().getResults();
                        instanceFormats.setInstanceFormats(instanceFormat);
                        instanceFormats.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetInstanceFormatsResponse.withJsonOK(instanceFormats)));
                    } else {
                        log.error(reply.cause().getMessage(), reply.cause());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetInstanceFormatsResponse.withPlainBadRequest(reply.cause().getMessage())));
                    }
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                    asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetInstanceFormatsResponse.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(GetInstanceFormatsResponse.withPlainInternalServerError(message)));
        }
    });
}
Also used : InstanceFormats(org.folio.rest.jaxrs.model.InstanceFormats) 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) InstanceFormat(org.folio.rest.jaxrs.model.InstanceFormat) Validate(org.folio.rest.annotations.Validate)

Example 4 with CQLParseException

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

the class InstanceTypeAPI method getInstanceTypes.

@Validate
@Override
public void getInstanceTypes(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    /**
     * http://host:port/instance-types
     */
    vertxContext.runOnContext(v -> {
        try {
            String tenantId = TenantTool.tenantId(okapiHeaders);
            CQLWrapper cql = getCQL(query, limit, offset);
            PostgresClient.getInstance(vertxContext.owner(), tenantId).get(INSTANCE_TYPE_TABLE, InstanceType.class, new String[] { "*" }, cql, true, true, reply -> {
                try {
                    if (reply.succeeded()) {
                        InstanceTypes instanceTypes = new InstanceTypes();
                        @SuppressWarnings("unchecked") List<InstanceType> instanceType = (List<InstanceType>) reply.result().getResults();
                        instanceTypes.setInstanceTypes(instanceType);
                        instanceTypes.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetInstanceTypesResponse.withJsonOK(instanceTypes)));
                    } else {
                        log.error(reply.cause().getMessage(), reply.cause());
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetInstanceTypesResponse.withPlainBadRequest(reply.cause().getMessage())));
                    }
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                    asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetInstanceTypesResponse.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(GetInstanceTypesResponse.withPlainInternalServerError(message)));
        }
    });
}
Also used : List(java.util.List) InstanceTypes(org.folio.rest.jaxrs.model.InstanceTypes) InstanceType(org.folio.rest.jaxrs.model.InstanceType) 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 5 with CQLParseException

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

the class ItemStorageAPI method getItemStorageItems.

@Validate
@Override
public void getItemStorageItems(int offset, int limit, String query, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
    String tenantId = okapiHeaders.get(TENANT_HEADER);
    try {
        vertxContext.runOnContext(v -> {
            try {
                PostgresClient postgresClient = PostgresClient.getInstance(vertxContext.owner(), TenantTool.calculateTenantId(tenantId));
                String[] fieldList = { "*" };
                CQLWrapper cql = getCQL(query, limit, offset);
                log.info(String.format("SQL generated by CQL query (%s): %s", query, cql.toString()));
                postgresClient.get(getTableName(query), Item.class, fieldList, cql, true, false, reply -> {
                    try {
                        if (reply.succeeded()) {
                            List<Item> items = (List<Item>) reply.result().getResults();
                            Items itemList = new Items();
                            itemList.setItems(items);
                            itemList.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
                            asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.GetItemStorageItemsResponse.withJsonOK(itemList)));
                        } else {
                            asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.GetItemStorageItemsResponse.withPlainInternalServerError(reply.cause().getMessage())));
                        }
                    } catch (Exception e) {
                        if (e.getCause() != null && e.getCause().getClass().getSimpleName().contains("CQLParseException")) {
                            asyncResultHandler.handle(Future.succeededFuture(GetItemStorageItemsResponse.withPlainBadRequest("CQL Parsing Error for '" + query + "': " + e.getLocalizedMessage())));
                        } else {
                            asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.GetItemStorageItemsResponse.withPlainInternalServerError("Error")));
                        }
                    }
                });
            } catch (IllegalStateException e) {
                asyncResultHandler.handle(Future.succeededFuture(GetItemStorageItemsResponse.withPlainInternalServerError("CQL State Error for '" + query + "': " + e.getLocalizedMessage())));
            } catch (Exception e) {
                if (e.getCause() != null && e.getCause().getClass().getSimpleName().contains("CQLParseException")) {
                    asyncResultHandler.handle(Future.succeededFuture(GetItemStorageItemsResponse.withPlainBadRequest("CQL Parsing Error for '" + query + "': " + e.getLocalizedMessage())));
                } else {
                    asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.GetItemStorageItemsResponse.withPlainInternalServerError("Error")));
                }
            }
        });
    } catch (Exception e) {
        if (e.getCause() != null && e.getCause().getClass().getSimpleName().contains("CQLParseException")) {
            asyncResultHandler.handle(Future.succeededFuture(GetItemStorageItemsResponse.withPlainBadRequest("CQL Parsing Error for '" + query + "': " + e.getLocalizedMessage())));
        } else {
            asyncResultHandler.handle(Future.succeededFuture(ItemStorageResource.GetItemStorageItemsResponse.withPlainInternalServerError("Error")));
        }
    }
}
Also used : PostgresClient(org.folio.rest.persist.PostgresClient) List(java.util.List) CQLWrapper(org.folio.rest.persist.cql.CQLWrapper) 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