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;
}
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;
}
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));
}
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));
}
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);
}
Aggregations