Search in sources :

Example 1 with Platforms

use of org.folio.rest.jaxrs.model.Platforms 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)

Aggregations

List (java.util.List)1 Validate (org.folio.rest.annotations.Validate)1 Platform (org.folio.rest.jaxrs.model.Platform)1 Platforms (org.folio.rest.jaxrs.model.Platforms)1 CQLWrapper (org.folio.rest.persist.cql.CQLWrapper)1 CQLParseException (org.z3950.zing.cql.CQLParseException)1 FieldException (org.z3950.zing.cql.cql2pgjson.FieldException)1