Search in sources :

Example 1 with Instances

use of org.folio.rest.jaxrs.model.Instances in project mod-inventory-storage by folio-org.

the class InstanceStorageAPI method getInstanceStorageInstances.

@Override
public void getInstanceStorageInstances(@DefaultValue("0") @Min(0L) @Max(1000L) int offset, @DefaultValue("10") @Min(1L) @Max(100L) int limit, String query, @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 {
        vertxContext.runOnContext(v -> {
            try {
                PostgresClient postgresClient = PostgresClient.getInstance(vertxContext.owner(), TenantTool.calculateTenantId(tenantId));
                String[] fieldList = { "*" };
                CQLWrapper cql = handleCQL(query, limit, offset);
                log.info(String.format("SQL generated from CQL: %s", cql.toString()));
                postgresClient.get(tableName, Instance.class, fieldList, cql, true, false, reply -> {
                    try {
                        if (reply.succeeded()) {
                            List<Instance> instances = (List<Instance>) reply.result().getResults();
                            Instances instanceList = new Instances();
                            instanceList.setInstances(instances);
                            instanceList.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
                            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(InstanceStorageResource.GetInstanceStorageInstancesResponse.withJsonOK(instanceList)));
                        } else {
                            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(InstanceStorageResource.GetInstanceStorageInstancesResponse.withPlainInternalServerError(reply.cause().getMessage())));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(InstanceStorageResource.GetInstanceStorageInstancesResponse.withPlainInternalServerError(e.getMessage())));
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(InstanceStorageResource.GetInstanceStorageInstancesResponse.withPlainInternalServerError(e.getMessage())));
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(InstanceStorageResource.GetInstanceStorageInstancesResponse.withPlainInternalServerError(e.getMessage())));
    }
}
Also used : Instances(org.folio.rest.jaxrs.model.Instances) Instance(org.folio.rest.jaxrs.model.Instance) PostgresClient(org.folio.rest.persist.PostgresClient) List(java.util.List) CQLWrapper(org.folio.rest.persist.cql.CQLWrapper) FieldException(org.z3950.zing.cql.cql2pgjson.FieldException)

Aggregations

List (java.util.List)1 Instance (org.folio.rest.jaxrs.model.Instance)1 Instances (org.folio.rest.jaxrs.model.Instances)1 PostgresClient (org.folio.rest.persist.PostgresClient)1 CQLWrapper (org.folio.rest.persist.cql.CQLWrapper)1 FieldException (org.z3950.zing.cql.cql2pgjson.FieldException)1