Search in sources :

Example 1 with REQUEST_TABLE

use of org.folio.support.ModuleConstants.REQUEST_TABLE in project mod-circulation-storage by folio-org.

the class ExpirationTool method resetPositionsForOpenRequestsByIdemIds.

private static Future<RowSet<Row>> resetPositionsForOpenRequestsByIdemIds(AsyncResult<SQLConnection> conn, Vertx vertx, String tenant, Set<String> itemIds) {
    if (itemIds.isEmpty()) {
        succeededFuture();
    }
    Set<String> quotedItemIds = itemIds.stream().map(id -> format("'%s'", id)).collect(toSet());
    String fullTableName = format("%s.%s", PostgresClient.convertToPsqlStandard(tenant), REQUEST_TABLE);
    String sql = format("UPDATE %1$s SET jsonb = jsonb - 'position' WHERE " + "(jsonb->>'status' = '%2$s' OR " + "jsonb->>'status' = '%3$s' OR " + "jsonb->>'status' = '%4$s' OR " + "jsonb->>'status' = '%5$s') AND " + "jsonb->>'itemId' IN (%6$s)", fullTableName, OPEN_NOT_YET_FILLED.value(), OPEN_AWAITING_PICKUP.value(), OPEN_AWAITING_DELIVERY.value(), OPEN_IN_TRANSIT.value(), String.join(",", quotedItemIds));
    Promise<RowSet<Row>> promise = Promise.promise();
    PostgresClient pgClient = PostgresClient.getInstance(vertx, tenant);
    pgClient.execute(conn, sql, promise);
    return promise.future().map(ur -> null);
}
Also used : Future.succeededFuture(io.vertx.core.Future.succeededFuture) OPEN_AWAITING_DELIVERY(org.folio.rest.jaxrs.model.Request.Status.OPEN_AWAITING_DELIVERY) REQUEST_EXPIRED(org.folio.support.exception.LogEventType.REQUEST_EXPIRED) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) REQUESTS(org.folio.support.LogEventPayloadField.REQUESTS) ArrayList(java.util.ArrayList) OPEN_NOT_YET_FILLED(org.folio.rest.jaxrs.model.Request.Status.OPEN_NOT_YET_FILLED) HashSet(java.util.HashSet) OPEN_AWAITING_PICKUP(org.folio.rest.jaxrs.model.Request.Status.OPEN_AWAITING_PICKUP) DbUtil.rowSetToStream(org.folio.support.DbUtil.rowSetToStream) REQUEST_TABLE(org.folio.support.ModuleConstants.REQUEST_TABLE) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Request(org.folio.rest.jaxrs.model.Request) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) RowSet(io.vertx.sqlclient.RowSet) ZoneOffset(java.time.ZoneOffset) AsyncResult(io.vertx.core.AsyncResult) CLOSED_UNFILLED(org.folio.rest.jaxrs.model.Request.Status.CLOSED_UNFILLED) Collectors.toSet(java.util.stream.Collectors.toSet) OPEN_IN_TRANSIT(org.folio.rest.jaxrs.model.Request.Status.OPEN_IN_TRANSIT) GenericCompositeFuture(org.folio.okapi.common.GenericCompositeFuture) ORIGINAL(org.folio.support.LogEventPayloadField.ORIGINAL) Collections.emptyList(java.util.Collections.emptyList) TimeZone(java.util.TimeZone) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Set(java.util.Set) SQLConnection(org.folio.rest.persist.SQLConnection) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) String.format(java.lang.String.format) PostgresClient(org.folio.rest.persist.PostgresClient) CLOSED_PICKUP_EXPIRED(org.folio.rest.jaxrs.model.Request.Status.CLOSED_PICKUP_EXPIRED) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Row(io.vertx.sqlclient.Row) UPDATED(org.folio.support.LogEventPayloadField.UPDATED) EventPublisherService(org.folio.service.EventPublisherService) Comparator(java.util.Comparator) LogManager(org.apache.logging.log4j.LogManager) RowSet(io.vertx.sqlclient.RowSet) PostgresClient(org.folio.rest.persist.PostgresClient)

Example 2 with REQUEST_TABLE

use of org.folio.support.ModuleConstants.REQUEST_TABLE 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()));
}
Also used : Future.succeededFuture(io.vertx.core.Future.succeededFuture) OPEN_AWAITING_DELIVERY(org.folio.rest.jaxrs.model.Request.Status.OPEN_AWAITING_DELIVERY) REQUEST_EXPIRED(org.folio.support.exception.LogEventType.REQUEST_EXPIRED) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) REQUESTS(org.folio.support.LogEventPayloadField.REQUESTS) ArrayList(java.util.ArrayList) OPEN_NOT_YET_FILLED(org.folio.rest.jaxrs.model.Request.Status.OPEN_NOT_YET_FILLED) HashSet(java.util.HashSet) OPEN_AWAITING_PICKUP(org.folio.rest.jaxrs.model.Request.Status.OPEN_AWAITING_PICKUP) DbUtil.rowSetToStream(org.folio.support.DbUtil.rowSetToStream) REQUEST_TABLE(org.folio.support.ModuleConstants.REQUEST_TABLE) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Request(org.folio.rest.jaxrs.model.Request) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) RowSet(io.vertx.sqlclient.RowSet) ZoneOffset(java.time.ZoneOffset) AsyncResult(io.vertx.core.AsyncResult) CLOSED_UNFILLED(org.folio.rest.jaxrs.model.Request.Status.CLOSED_UNFILLED) Collectors.toSet(java.util.stream.Collectors.toSet) OPEN_IN_TRANSIT(org.folio.rest.jaxrs.model.Request.Status.OPEN_IN_TRANSIT) GenericCompositeFuture(org.folio.okapi.common.GenericCompositeFuture) ORIGINAL(org.folio.support.LogEventPayloadField.ORIGINAL) Collections.emptyList(java.util.Collections.emptyList) TimeZone(java.util.TimeZone) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Set(java.util.Set) SQLConnection(org.folio.rest.persist.SQLConnection) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) String.format(java.lang.String.format) PostgresClient(org.folio.rest.persist.PostgresClient) CLOSED_PICKUP_EXPIRED(org.folio.rest.jaxrs.model.Request.Status.CLOSED_PICKUP_EXPIRED) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Row(io.vertx.sqlclient.Row) UPDATED(org.folio.support.LogEventPayloadField.UPDATED) EventPublisherService(org.folio.service.EventPublisherService) Comparator(java.util.Comparator) LogManager(org.apache.logging.log4j.LogManager) RowSet(io.vertx.sqlclient.RowSet) Request(org.folio.rest.jaxrs.model.Request) PostgresClient(org.folio.rest.persist.PostgresClient) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 3 with REQUEST_TABLE

use of org.folio.support.ModuleConstants.REQUEST_TABLE 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()));
}
Also used : Future.succeededFuture(io.vertx.core.Future.succeededFuture) OPEN_AWAITING_DELIVERY(org.folio.rest.jaxrs.model.Request.Status.OPEN_AWAITING_DELIVERY) REQUEST_EXPIRED(org.folio.support.exception.LogEventType.REQUEST_EXPIRED) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) REQUESTS(org.folio.support.LogEventPayloadField.REQUESTS) ArrayList(java.util.ArrayList) OPEN_NOT_YET_FILLED(org.folio.rest.jaxrs.model.Request.Status.OPEN_NOT_YET_FILLED) HashSet(java.util.HashSet) OPEN_AWAITING_PICKUP(org.folio.rest.jaxrs.model.Request.Status.OPEN_AWAITING_PICKUP) DbUtil.rowSetToStream(org.folio.support.DbUtil.rowSetToStream) REQUEST_TABLE(org.folio.support.ModuleConstants.REQUEST_TABLE) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Request(org.folio.rest.jaxrs.model.Request) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) RowSet(io.vertx.sqlclient.RowSet) ZoneOffset(java.time.ZoneOffset) AsyncResult(io.vertx.core.AsyncResult) CLOSED_UNFILLED(org.folio.rest.jaxrs.model.Request.Status.CLOSED_UNFILLED) Collectors.toSet(java.util.stream.Collectors.toSet) OPEN_IN_TRANSIT(org.folio.rest.jaxrs.model.Request.Status.OPEN_IN_TRANSIT) GenericCompositeFuture(org.folio.okapi.common.GenericCompositeFuture) ORIGINAL(org.folio.support.LogEventPayloadField.ORIGINAL) Collections.emptyList(java.util.Collections.emptyList) TimeZone(java.util.TimeZone) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Set(java.util.Set) SQLConnection(org.folio.rest.persist.SQLConnection) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) String.format(java.lang.String.format) PostgresClient(org.folio.rest.persist.PostgresClient) CLOSED_PICKUP_EXPIRED(org.folio.rest.jaxrs.model.Request.Status.CLOSED_PICKUP_EXPIRED) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Row(io.vertx.sqlclient.Row) UPDATED(org.folio.support.LogEventPayloadField.UPDATED) EventPublisherService(org.folio.service.EventPublisherService) Comparator(java.util.Comparator) LogManager(org.apache.logging.log4j.LogManager) RowSet(io.vertx.sqlclient.RowSet) Request(org.folio.rest.jaxrs.model.Request) PostgresClient(org.folio.rest.persist.PostgresClient)

Aggregations

AsyncResult (io.vertx.core.AsyncResult)3 Future (io.vertx.core.Future)3 Future.succeededFuture (io.vertx.core.Future.succeededFuture)3 Promise (io.vertx.core.Promise)3 Vertx (io.vertx.core.Vertx)3 JsonObject (io.vertx.core.json.JsonObject)3 Row (io.vertx.sqlclient.Row)3 RowSet (io.vertx.sqlclient.RowSet)3 String.format (java.lang.String.format)3 SimpleDateFormat (java.text.SimpleDateFormat)3 ZoneOffset (java.time.ZoneOffset)3 ArrayList (java.util.ArrayList)3 Collections.emptyList (java.util.Collections.emptyList)3 Comparator (java.util.Comparator)3 Date (java.util.Date)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 TimeZone (java.util.TimeZone)3