use of org.folio.rest.persist.PostgresClient in project mod-inventory-storage by folio-org.
the class PlatformAPI method deletePlatformsByPlatformId.
@Validate
@Override
public void deletePlatformsByPlatformId(String instanceTypeId, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
vertxContext.runOnContext(v -> {
try {
String tenantId = TenantTool.tenantId(okapiHeaders);
PostgresClient postgres = PostgresClient.getInstance(vertxContext.owner(), tenantId);
postgres.delete(PLATFORM_TABLE, instanceTypeId, reply -> {
try {
if (reply.failed()) {
String msg = PgExceptionUtil.badRequestMessage(reply.cause());
if (msg == null) {
internalServerErrorDuringDelete(reply.cause(), lang, asyncResultHandler);
return;
}
log.info(msg);
asyncResultHandler.handle(Future.succeededFuture(PlatformsResource.DeletePlatformsByPlatformIdResponse.withPlainBadRequest(msg)));
return;
}
int updated = reply.result().getUpdated();
if (updated != 1) {
String msg = messages.getMessage(lang, MessageConsts.DeletedCountError, 1, updated);
log.error(msg);
asyncResultHandler.handle(Future.succeededFuture(PlatformsResource.DeletePlatformsByPlatformIdResponse.withPlainNotFound(msg)));
return;
}
asyncResultHandler.handle(Future.succeededFuture(PlatformsResource.DeletePlatformsByPlatformIdResponse.withNoContent()));
} catch (Exception e) {
internalServerErrorDuringDelete(e, lang, asyncResultHandler);
}
});
} catch (Exception e) {
internalServerErrorDuringDelete(e, lang, asyncResultHandler);
}
});
}
use of org.folio.rest.persist.PostgresClient in project mod-inventory-storage by folio-org.
the class HoldingsStorageAPI method deleteHoldingsStorageHoldings.
@Override
public void deleteHoldingsStorageHoldings(@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);
vertxContext.runOnContext(v -> {
try {
PostgresClient postgresClient = PostgresClient.getInstance(vertxContext.owner(), TenantTool.calculateTenantId(tenantId));
postgresClient.mutate(String.format("TRUNCATE TABLE %s_%s." + HOLDINGS_RECORD_TABLE, tenantId, "mod_inventory_storage"), reply -> {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(HoldingsStorageResource.DeleteHoldingsStorageHoldingsResponse.noContent().build()));
});
} catch (Exception e) {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(HoldingsStorageResource.DeleteHoldingsStorageHoldingsResponse.withPlainInternalServerError(e.getMessage())));
}
});
}
use of org.folio.rest.persist.PostgresClient 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())));
}
}
use of org.folio.rest.persist.PostgresClient in project mod-inventory-storage by folio-org.
the class HoldingsStorageAPI method getHoldingsStorageHoldingsByHoldingsRecordId.
@Override
public void getHoldingsStorageHoldingsByHoldingsRecordId(@NotNull String holdingsRecordId, @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 {
PostgresClient postgresClient = PostgresClient.getInstance(vertxContext.owner(), TenantTool.calculateTenantId(tenantId));
vertxContext.runOnContext(v -> {
try {
String[] fieldList = { "*" };
CQL2PgJSON cql2pgJson = new CQL2PgJSON(HOLDINGS_RECORD_TABLE + ".jsonb");
CQLWrapper cql = new CQLWrapper(cql2pgJson, String.format("id==%s", holdingsRecordId)).setLimit(new Limit(1)).setOffset(new Offset(0));
log.info(String.format("SQL generated from CQL: %s", cql.toString()));
postgresClient.get(HOLDINGS_RECORD_TABLE, HoldingsRecord.class, fieldList, cql, true, false, reply -> {
try {
if (reply.succeeded()) {
List<HoldingsRecord> holdingsList = (List<HoldingsRecord>) reply.result().getResults();
if (holdingsList.size() == 1) {
HoldingsRecord holdingsRecord = holdingsList.get(0);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(HoldingsStorageResource.GetHoldingsStorageHoldingsByHoldingsRecordIdResponse.withJsonOK(holdingsRecord)));
} else {
asyncResultHandler.handle(Future.succeededFuture(HoldingsStorageResource.GetHoldingsStorageHoldingsByHoldingsRecordIdResponse.withPlainNotFound("Not Found")));
}
} else {
asyncResultHandler.handle(Future.succeededFuture(HoldingsStorageResource.GetHoldingsStorageHoldingsByHoldingsRecordIdResponse.withPlainInternalServerError(reply.cause().getMessage())));
}
} catch (Exception e) {
e.printStackTrace();
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(HoldingsStorageResource.GetHoldingsStorageHoldingsByHoldingsRecordIdResponse.withPlainInternalServerError(e.getMessage())));
}
});
} catch (Exception e) {
e.printStackTrace();
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(HoldingsStorageResource.GetHoldingsStorageHoldingsByHoldingsRecordIdResponse.withPlainInternalServerError(e.getMessage())));
}
});
} catch (Exception e) {
e.printStackTrace();
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(HoldingsStorageResource.GetHoldingsStorageHoldingsByHoldingsRecordIdResponse.withPlainInternalServerError(e.getMessage())));
}
}
use of org.folio.rest.persist.PostgresClient in project mod-inventory-storage by folio-org.
the class HoldingsStorageAPI method deleteHoldingsStorageHoldingsByHoldingsRecordId.
@Override
public void deleteHoldingsStorageHoldingsByHoldingsRecordId(@NotNull String holdingsRecordId, @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 {
PostgresClient postgresClient = PostgresClient.getInstance(vertxContext.owner(), TenantTool.calculateTenantId(tenantId));
Criteria a = new Criteria();
a.addField("'id'");
a.setOperation("=");
a.setValue(holdingsRecordId);
Criterion criterion = new Criterion(a);
vertxContext.runOnContext(v -> {
try {
postgresClient.delete(HOLDINGS_RECORD_TABLE, criterion, reply -> {
if (reply.succeeded()) {
asyncResultHandler.handle(Future.succeededFuture(DeleteHoldingsStorageHoldingsByHoldingsRecordIdResponse.withNoContent()));
} else {
asyncResultHandler.handle(Future.succeededFuture(DeleteHoldingsStorageHoldingsByHoldingsRecordIdResponse.withPlainInternalServerError(reply.cause().getMessage())));
}
});
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(DeleteHoldingsStorageHoldingsByHoldingsRecordIdResponse.withPlainInternalServerError(e.getMessage())));
}
});
} catch (Exception e) {
asyncResultHandler.handle(Future.succeededFuture(DeleteHoldingsStorageHoldingsByHoldingsRecordIdResponse.withPlainInternalServerError(e.getMessage())));
}
}
Aggregations