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())));
}
}
Aggregations