use of org.folio.rest.jaxrs.model.Request in project mod-circulation-storage by folio-org.
the class RequestExpirationApiTest method assertPublishedEvents.
private void assertPublishedEvents(List<JsonObject> events) {
events.forEach(e -> {
Event event = e.mapTo(Event.class);
assertThat(event.getEventType(), is(LOG_RECORD.name()));
JsonObject payload = new JsonObject(event.getEventPayload()).getJsonObject(PAYLOAD.value());
Request original = payload.getJsonObject(REQUESTS.value()).getJsonObject(ORIGINAL.value()).mapTo(Request.class);
Request updated = payload.getJsonObject(REQUESTS.value()).getJsonObject(UPDATED.value()).mapTo(Request.class);
assertThat(original.getStatus(), not(equalTo(updated.getStatus())));
});
}
use of org.folio.rest.jaxrs.model.Request 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.rest.jaxrs.model.Request 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.rest.jaxrs.model.Request in project mod-circulation-storage by folio-org.
the class RequestUpdateTriggerTest method awaitingPickupRequestClosedDateShouldBePresentAfterStatusTransition.
@ParameterizedTest
@CsvSource(value = { "Open - Awaiting pickup | Closed - Pickup expired", "Open - Awaiting pickup | Closed - Cancelled " }, delimiter = '|')
void awaitingPickupRequestClosedDateShouldBePresentAfterStatusTransition(String oldStatus, String newStatus) throws InterruptedException, ExecutionException, TimeoutException {
CompletableFuture<JsonObject> future = new CompletableFuture<>();
String id = "3a57dc83-e70d-404b-b1f1-442b88760331";
Request request = new Request().withStatus(fromValue(oldStatus));
DateTime requestUpdatedDate = DateTime.now();
saveRequest(id, request).compose(v -> updateRequest(id, request.withStatus(fromValue(newStatus)))).compose(v -> getRequest(id)).onComplete(updatedRequest -> future.complete(updatedRequest.result()));
JsonObject updatedRequest = future.get(5, TimeUnit.SECONDS);
assertThat(updatedRequest.getString("awaitingPickupRequestClosedDate"), is(notNullValue()));
assertThat(updatedRequest.getString("awaitingPickupRequestClosedDate"), is(withinSecondsAfter(Seconds.seconds(2), requestUpdatedDate)));
}
use of org.folio.rest.jaxrs.model.Request in project mod-circulation-storage by folio-org.
the class RequestUpdateTriggerTest method awaitingPickupRequestClosedDateShouldNotBePresentAfterStatusTransition.
@ParameterizedTest
@CsvSource(value = { "Open - Not yet filled | Closed - Filled ", "Open - Not yet filled | Closed - Cancelled ", "Open - Not yet filled | Closed - Unfilled ", "Open - Not yet filled | Open - In transit ", "Open - Not yet filled | Open - Awaiting pickup", "Open - Awaiting pickup | Open - In transit ", "Open - In transit | Closed - Cancelled ", "Open - In transit | Open - Awaiting pickup", "Open - In transit | Open - Not yet filled " }, delimiter = '|')
void awaitingPickupRequestClosedDateShouldNotBePresentAfterStatusTransition(String oldStatus, String newStatus) throws InterruptedException, ExecutionException, TimeoutException {
CompletableFuture<JsonObject> future = new CompletableFuture<>();
String id = "3a57dc83-e70d-404b-b1f1-442b88760331";
Request request = new Request().withStatus(fromValue(oldStatus));
saveRequest(id, request).compose(v -> updateRequest(id, request.withStatus(fromValue(newStatus)))).compose(v -> getRequest(id)).onComplete(updatedRequest -> future.complete(updatedRequest.result()));
JsonObject updatedRequest = future.get(5, TimeUnit.SECONDS);
assertThat(updatedRequest.getString("awaitingPickupRequestClosedDate"), is(nullValue()));
}
Aggregations