use of org.folio.support.LogEventPayloadField.REQUESTS in project mod-circulation-storage by folio-org.
the class ExpirationTool method doRequestExpirationForTenant.
private static Future<Void> doRequestExpirationForTenant(Map<String, String> okapiHeaders, Vertx vertx, String tenant) {
Promise<Void> promise = Promise.promise();
PostgresClient pgClient = PostgresClient.getInstance(vertx, tenant);
List<JsonObject> context = new ArrayList<>();
pgClient.startTx(conn -> getExpiredRequests(conn, vertx, tenant).compose(requests -> closeRequests(conn, vertx, tenant, requests, context)).compose(itemIds -> getOpenRequestsByItemIds(conn, vertx, tenant, itemIds)).compose(requests -> reorderRequests(conn, vertx, tenant, requests)).onComplete(v -> {
if (v.failed()) {
pgClient.rollbackTx(conn, done -> {
log.error("Error in request processing", v.cause());
promise.fail(v.cause());
});
} else {
EventPublisherService eventPublisherService = new EventPublisherService(vertx, okapiHeaders);
context.forEach(p -> eventPublisherService.publishLogRecord(new JsonObject().put(REQUESTS.value(), p), REQUEST_EXPIRED));
pgClient.endTx(conn, done -> promise.complete());
}
}));
return promise.future();
}
use of org.folio.support.LogEventPayloadField.REQUESTS in project mod-circulation-storage by folio-org.
the class ExpirationTool method closeRequests.
private static Future<Set<String>> closeRequests(AsyncResult<SQLConnection> conn, Vertx vertx, String tenant, List<Request> requests, List<JsonObject> context) {
Future<Void> future = succeededFuture();
Set<String> closedRequestsItemIds = new HashSet<>();
for (Request request : requests) {
JsonObject pair = new JsonObject();
pair.put(ORIGINAL.value(), JsonObject.mapFrom(request));
closedRequestsItemIds.add(request.getItemId());
Request updatedRequest = changeRequestStatus(request).withPosition(null);
pair.put(UPDATED.value(), JsonObject.mapFrom(updatedRequest));
context.add(pair);
future = future.compose(v -> updateRequest(conn, vertx, tenant, updatedRequest));
}
return future.map(v -> closedRequestsItemIds);
}
use of org.folio.support.LogEventPayloadField.REQUESTS in project mod-circulation-storage by folio-org.
the class ExpirationTool method updateRequestsPositions.
private static Future<Void> updateRequestsPositions(AsyncResult<SQLConnection> conn, Vertx vertx, String tenant, List<Request> requests) {
requests.sort(Comparator.comparingInt(Request::getPosition));
AtomicInteger pos = new AtomicInteger(1);
Future<Void> future = succeededFuture();
for (Request request : requests) {
future = future.compose(v -> updateRequest(conn, vertx, tenant, request.withPosition(pos.getAndIncrement())));
}
return future;
}
Aggregations