Search in sources :

Example 1 with Request

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())));
    });
}
Also used : Request(org.folio.rest.jaxrs.model.Request) Event(org.folio.rest.jaxrs.model.Event) JsonObject(io.vertx.core.json.JsonObject)

Example 2 with Request

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();
}
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) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) PostgresClient(org.folio.rest.persist.PostgresClient) EventPublisherService(org.folio.service.EventPublisherService)

Example 3 with Request

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);
}
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) Request(org.folio.rest.jaxrs.model.Request) JsonObject(io.vertx.core.json.JsonObject) HashSet(java.util.HashSet)

Example 4 with Request

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)));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CsvSource(org.junit.jupiter.params.provider.CsvSource) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) AfterAll(org.junit.jupiter.api.AfterAll) IsNull.nullValue(org.hamcrest.core.IsNull.nullValue) TextDateTimeMatcher.withinSecondsAfter(org.folio.rest.support.matchers.TextDateTimeMatcher.withinSecondsAfter) Seconds(org.joda.time.Seconds) BeforeAll(org.junit.jupiter.api.BeforeAll) Request(org.folio.rest.jaxrs.model.Request) Is.is(org.hamcrest.core.Is.is) JsonObject(io.vertx.core.json.JsonObject) RowSet(io.vertx.sqlclient.RowSet) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) RequestsApiTest.requestStorageUrl(org.folio.rest.api.RequestsApiTest.requestStorageUrl) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) MalformedURLException(java.net.MalformedURLException) Promise(io.vertx.core.Promise) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) Future(io.vertx.core.Future) PostgresClient(org.folio.rest.persist.PostgresClient) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Status.fromValue(org.folio.rest.jaxrs.model.Request.Status.fromValue) Row(io.vertx.sqlclient.Row) CompletableFuture(java.util.concurrent.CompletableFuture) Request(org.folio.rest.jaxrs.model.Request) JsonObject(io.vertx.core.json.JsonObject) DateTime(org.joda.time.DateTime) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with Request

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()));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CsvSource(org.junit.jupiter.params.provider.CsvSource) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) AfterAll(org.junit.jupiter.api.AfterAll) IsNull.nullValue(org.hamcrest.core.IsNull.nullValue) TextDateTimeMatcher.withinSecondsAfter(org.folio.rest.support.matchers.TextDateTimeMatcher.withinSecondsAfter) Seconds(org.joda.time.Seconds) BeforeAll(org.junit.jupiter.api.BeforeAll) Request(org.folio.rest.jaxrs.model.Request) Is.is(org.hamcrest.core.Is.is) JsonObject(io.vertx.core.json.JsonObject) RowSet(io.vertx.sqlclient.RowSet) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) RequestsApiTest.requestStorageUrl(org.folio.rest.api.RequestsApiTest.requestStorageUrl) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) MalformedURLException(java.net.MalformedURLException) Promise(io.vertx.core.Promise) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) Future(io.vertx.core.Future) PostgresClient(org.folio.rest.persist.PostgresClient) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Status.fromValue(org.folio.rest.jaxrs.model.Request.Status.fromValue) Row(io.vertx.sqlclient.Row) CompletableFuture(java.util.concurrent.CompletableFuture) Request(org.folio.rest.jaxrs.model.Request) JsonObject(io.vertx.core.json.JsonObject) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)8 Request (org.folio.rest.jaxrs.model.Request)8 Future (io.vertx.core.Future)7 Promise (io.vertx.core.Promise)7 Row (io.vertx.sqlclient.Row)7 RowSet (io.vertx.sqlclient.RowSet)7 PostgresClient (org.folio.rest.persist.PostgresClient)7 AsyncResult (io.vertx.core.AsyncResult)5 Future.succeededFuture (io.vertx.core.Future.succeededFuture)5 Vertx (io.vertx.core.Vertx)5 String.format (java.lang.String.format)5 SimpleDateFormat (java.text.SimpleDateFormat)5 ZoneOffset (java.time.ZoneOffset)5 ArrayList (java.util.ArrayList)5 Collections.emptyList (java.util.Collections.emptyList)5 Comparator (java.util.Comparator)5 Date (java.util.Date)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Map (java.util.Map)5