Search in sources :

Example 1 with ReorderRequest

use of org.folio.circulation.domain.reorder.ReorderRequest in project mod-circulation by folio-org.

the class ReorderRequestContext method getReorderRequestToRequestMap.

/**
 * Returns Map of pairs where key is ReorderedRequest and value is Request from the queue.
 *
 * @return Map of pairs ReorderRequest - Request.
 */
public Map<ReorderRequest, Request> getReorderRequestToRequestMap() {
    final Map<ReorderRequest, Request> reorderRequestToRequestMap = new HashMap<>();
    reorderQueueRequest.getReorderedQueue().forEach(reorderRequest -> {
        Request relatedRequest = requestQueue.getRequests().stream().filter(request -> request.getId().equals(reorderRequest.getId())).findAny().orElse(null);
        reorderRequestToRequestMap.put(reorderRequest, relatedRequest);
    });
    return reorderRequestToRequestMap;
}
Also used : ReorderRequest(org.folio.circulation.domain.reorder.ReorderRequest) HashMap(java.util.HashMap) ReorderQueueRequest(org.folio.circulation.domain.reorder.ReorderQueueRequest) Request(org.folio.circulation.domain.Request) ReorderRequest(org.folio.circulation.domain.reorder.ReorderRequest)

Example 2 with ReorderRequest

use of org.folio.circulation.domain.reorder.ReorderRequest in project mod-circulation by folio-org.

the class ReorderQueueBuilder method addReorderRequest.

public ReorderQueueBuilder addReorderRequest(String requestId, int newPosition) {
    ReorderRequest reorderRequest = new ReorderRequest();
    reorderRequest.setId(requestId);
    reorderRequest.setNewPosition(newPosition);
    reorderQueueRequest.getReorderedQueue().add(reorderRequest);
    return this;
}
Also used : ReorderRequest(org.folio.circulation.domain.reorder.ReorderRequest)

Example 3 with ReorderRequest

use of org.folio.circulation.domain.reorder.ReorderRequest in project mod-circulation by folio-org.

the class RequestQueueValidation method positionsAreSequential.

/**
 * Verifies that newPositions has sequential order, i.e. 1, 2, 3, 4 but not 1, 2, 3, 40.
 * Used for both item and instance queues.
 *
 * @param result - Context object.
 * @return New Result, failed if validation have not been passed.
 */
public static Result<ReorderRequestContext> positionsAreSequential(Result<ReorderRequestContext> result) {
    return result.failWhen(r -> {
        List<ReorderRequest> sortedReorderedQueue = r.getReorderQueueRequest().getReorderedQueue().stream().sorted(Comparator.comparingInt(ReorderRequest::getNewPosition)).collect(Collectors.toList());
        int expectedCurrentPosition = 1;
        for (ReorderRequest reorderRequest : sortedReorderedQueue) {
            if (reorderRequest.getNewPosition() != expectedCurrentPosition) {
                return succeeded(true);
            }
            expectedCurrentPosition++;
        }
        return succeeded(false);
    }, r -> singleValidationError("Positions must have sequential order.", "newPosition", null));
}
Also used : ReorderRequest(org.folio.circulation.domain.reorder.ReorderRequest)

Example 4 with ReorderRequest

use of org.folio.circulation.domain.reorder.ReorderRequest in project mod-circulation by folio-org.

the class RequestQueueValidation method validateRequestAtFirstPosition.

private static Result<ReorderRequestContext> validateRequestAtFirstPosition(Result<ReorderRequestContext> result, Predicate<Request> requestTypePredicate, String onFailureMessage) {
    return result.failWhen(context -> {
        boolean notAtFirstPosition = context.getReorderRequestToRequestMap().entrySet().stream().anyMatch(entry -> {
            ReorderRequest reorderRequest = entry.getKey();
            Request request = entry.getValue();
            return requestTypePredicate.test(request) && reorderRequest.getNewPosition() != 1;
        });
        return succeeded(notAtFirstPosition);
    }, r -> singleValidationError(onFailureMessage, "newPosition", null));
}
Also used : ReorderRequest(org.folio.circulation.domain.reorder.ReorderRequest) Request(org.folio.circulation.domain.Request) ReorderRequest(org.folio.circulation.domain.reorder.ReorderRequest)

Example 5 with ReorderRequest

use of org.folio.circulation.domain.reorder.ReorderRequest in project mod-circulation by folio-org.

the class UpdateRequestQueueTest method createReorderContext.

private ReorderRequestContext createReorderContext() {
    UUID itemId = UUID.randomUUID();
    RequestQueue requestQueue = createRequestQueue(itemId, 4);
    ReorderQueueRequest reorderQueueRequest = new ReorderQueueRequest();
    reorderQueueRequest.setReorderedQueue(new ArrayList<>());
    final int requestCount = requestQueue.getRequests().size();
    for (Request request : requestQueue.getRequests()) {
        ReorderRequest reorderRequest = new ReorderRequest();
        reorderQueueRequest.getReorderedQueue().add(reorderRequest);
        reorderRequest.setId(request.getId());
        // i.e. reverse positions
        reorderRequest.setNewPosition(requestCount - request.getPosition());
    }
    return new ReorderRequestContext(null, itemId.toString(), reorderQueueRequest).withRequestQueue(requestQueue);
}
Also used : ReorderRequest(org.folio.circulation.domain.reorder.ReorderRequest) ReorderRequest(org.folio.circulation.domain.reorder.ReorderRequest) ReorderQueueRequest(org.folio.circulation.domain.reorder.ReorderQueueRequest) UUID(java.util.UUID) ReorderRequestContext(org.folio.circulation.resources.context.ReorderRequestContext) ReorderQueueRequest(org.folio.circulation.domain.reorder.ReorderQueueRequest)

Aggregations

ReorderRequest (org.folio.circulation.domain.reorder.ReorderRequest)5 Request (org.folio.circulation.domain.Request)2 ReorderQueueRequest (org.folio.circulation.domain.reorder.ReorderQueueRequest)2 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 ReorderRequestContext (org.folio.circulation.resources.context.ReorderRequestContext)1