Search in sources :

Example 1 with HoldingsRecords

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

the class HoldingsStorageAPI method getHoldingsStorageHoldings.

@Override
public void getHoldingsStorageHoldings(@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 = { "*" };
                CQL2PgJSON cql2pgJson = new CQL2PgJSON(HOLDINGS_RECORD_TABLE + ".jsonb");
                CQLWrapper cql = new CQLWrapper(cql2pgJson, query).setLimit(new Limit(limit)).setOffset(new Offset(offset));
                postgresClient.get(HOLDINGS_RECORD_TABLE, HoldingsRecord.class, fieldList, cql, true, false, reply -> {
                    try {
                        if (reply.succeeded()) {
                            List<HoldingsRecord> holdingsRecords = (List<HoldingsRecord>) reply.result().getResults();
                            HoldingsRecords holdingsList = new HoldingsRecords();
                            holdingsList.setHoldingsRecords(holdingsRecords);
                            holdingsList.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
                            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(HoldingsStorageResource.GetHoldingsStorageHoldingsResponse.withJsonOK(holdingsList)));
                        } else {
                            asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(HoldingsStorageResource.GetHoldingsStorageHoldingsResponse.withPlainInternalServerError(reply.cause().getMessage())));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(HoldingsStorageResource.GetHoldingsStorageHoldingsResponse.withPlainInternalServerError(e.getMessage())));
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(HoldingsStorageResource.GetHoldingsStorageHoldingsResponse.withPlainInternalServerError(e.getMessage())));
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(HoldingsStorageResource.GetHoldingsStorageHoldingsResponse.withPlainInternalServerError(e.getMessage())));
    }
}
Also used : CQL2PgJSON(org.z3950.zing.cql.cql2pgjson.CQL2PgJSON) HoldingsRecord(org.folio.rest.jaxrs.model.HoldingsRecord) HoldingsRecords(org.folio.rest.jaxrs.model.HoldingsRecords) PostgresClient(org.folio.rest.persist.PostgresClient) List(java.util.List) Limit(org.folio.rest.persist.Criteria.Limit) CQLWrapper(org.folio.rest.persist.cql.CQLWrapper) Offset(org.folio.rest.persist.Criteria.Offset)

Aggregations

List (java.util.List)1 HoldingsRecord (org.folio.rest.jaxrs.model.HoldingsRecord)1 HoldingsRecords (org.folio.rest.jaxrs.model.HoldingsRecords)1 Limit (org.folio.rest.persist.Criteria.Limit)1 Offset (org.folio.rest.persist.Criteria.Offset)1 PostgresClient (org.folio.rest.persist.PostgresClient)1 CQLWrapper (org.folio.rest.persist.cql.CQLWrapper)1 CQL2PgJSON (org.z3950.zing.cql.cql2pgjson.CQL2PgJSON)1