use of org.folio.rest.jaxrs.model.Request in project mod-circulation-storage by folio-org.
the class ExpirationTool method getExpiredRequests.
private static Future<List<Request>> getExpiredRequests(AsyncResult<SQLConnection> conn, Vertx vertx, String tenant) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
df.setTimeZone(TimeZone.getTimeZone(ZoneOffset.UTC));
PostgresClient pgClient = PostgresClient.getInstance(vertx, tenant);
Promise<RowSet<Row>> promise = Promise.promise();
String where = format("WHERE " + "(jsonb->>'status' = '%1$s' AND jsonb->>'requestExpirationDate' < '%5$s') OR " + "(jsonb->>'status' = '%2$s' AND jsonb->>'requestExpirationDate' < '%5$s') OR " + "(jsonb->>'status' = '%3$s' AND jsonb->>'requestExpirationDate' < '%5$s') OR " + "(jsonb->>'status' = '%4$s' AND jsonb->>'holdShelfExpirationDate' < '%5$s') " + "LIMIT 150", OPEN_NOT_YET_FILLED.value(), OPEN_AWAITING_DELIVERY.value(), OPEN_IN_TRANSIT.value(), OPEN_AWAITING_PICKUP.value(), df.format(new Date()));
String fullTableName = format("%s.%s", PostgresClient.convertToPsqlStandard(tenant), REQUEST_TABLE);
String query = format("SELECT jsonb FROM %s %s", fullTableName, where);
pgClient.select(conn, query, promise);
return promise.future().map(rs -> rowSetToStream(rs).map(row -> row.get(JsonObject.class, row.getColumnIndex(JSONB_COLUMN))).map(json -> json.mapTo(Request.class)).collect(toList()));
}
use of org.folio.rest.jaxrs.model.Request in project mod-circulation-storage by folio-org.
the class ExpirationTool method getOpenRequestsByItemIds.
private static Future<List<Request>> getOpenRequestsByItemIds(AsyncResult<SQLConnection> conn, Vertx vertx, String tenant, Set<String> itemIds) {
PostgresClient pgClient = PostgresClient.getInstance(vertx, tenant);
Promise<RowSet<Row>> promise = Promise.promise();
if (itemIds.isEmpty()) {
return succeededFuture(emptyList());
}
Set<String> quotedItemIds = itemIds.stream().map(id -> format("'%s'", id)).collect(toSet());
String where = format("WHERE " + "(jsonb->>'status' = '%1$s' OR " + "jsonb->>'status' = '%2$s' OR " + "jsonb->>'status' = '%3$s' OR " + "jsonb->>'status' = '%4$s') AND " + "jsonb->>'itemId' IN (%5$s) " + "ORDER BY jsonb->>'position' ASC", OPEN_NOT_YET_FILLED.value(), OPEN_AWAITING_PICKUP.value(), OPEN_AWAITING_DELIVERY.value(), OPEN_IN_TRANSIT.value(), String.join(",", quotedItemIds));
String fullTableName = format("%s.%s", PostgresClient.convertToPsqlStandard(tenant), REQUEST_TABLE);
String sql = format("SELECT jsonb FROM %s %s", fullTableName, where);
pgClient.select(conn, sql, promise);
return promise.future().map(rs -> rowSetToStream(rs).map(row -> row.get(JsonObject.class, row.getColumnIndex(JSONB_COLUMN))).map(json -> json.mapTo(Request.class)).collect(toList()));
}
use of org.folio.rest.jaxrs.model.Request 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