Search in sources :

Example 1 with PieceCollection

use of org.folio.rest.jaxrs.model.PieceCollection in project mod-orders by folio-org.

the class PieceStorageServiceTest method testPiecesShouldBeReturnedByQuery.

@Test
void testPiecesShouldBeReturnedByQuery() {
    String pieceId = UUID.randomUUID().toString();
    List<Piece> pieces = Collections.singletonList(new Piece().withId(pieceId));
    PieceCollection pieceCollection = new PieceCollection().withPieces(pieces).withTotalRecords(1);
    when(restClientMock.get(any(), any(), any())).thenReturn(CompletableFuture.completedFuture(pieceCollection));
    String expectedQuery = String.format("id==%s", pieceId);
    PieceCollection retrievedPieces = pieceStorageService.getPieces(Integer.MAX_VALUE, 0, expectedQuery, requestContext).join();
    verify(restClientMock).get(any(), eq(requestContext), eq(PieceCollection.class));
    assertEquals(pieceCollection, retrievedPieces);
}
Also used : PieceCollection(org.folio.rest.jaxrs.model.PieceCollection) Piece(org.folio.rest.jaxrs.model.Piece) Test(org.junit.jupiter.api.Test)

Example 2 with PieceCollection

use of org.folio.rest.jaxrs.model.PieceCollection in project mod-orders by folio-org.

the class PieceStorageService method getPieceChunkByLineIds.

private CompletableFuture<List<Piece>> getPieceChunkByLineIds(Collection<String> poLineIds, RequestContext requestContext) {
    String query = convertIdsToCqlQuery(poLineIds, "poLineId");
    RequestEntry requestEntry = new RequestEntry(resourcesPath(PIECES_STORAGE)).withQuery(query).withOffset(0).withLimit(Integer.MAX_VALUE);
    return restClient.get(requestEntry, requestContext, PieceCollection.class).thenApply(PieceCollection::getPieces);
}
Also used : PieceCollection(org.folio.rest.jaxrs.model.PieceCollection) RequestEntry(org.folio.rest.core.models.RequestEntry)

Example 3 with PieceCollection

use of org.folio.rest.jaxrs.model.PieceCollection in project mod-orders by folio-org.

the class PieceStorageService method getPiecesByPoLineId.

/**
 * Search for pieces which might be already created for the PO line
 * @param compPOL PO line to retrieve Piece Records for
 * @return future with list of Pieces
 */
public CompletableFuture<List<Piece>> getPiecesByPoLineId(CompositePoLine compPOL, RequestContext requestContext) {
    String query = String.format("poLineId==%s", compPOL.getId());
    RequestEntry requestEntry = new RequestEntry(resourcesPath(PIECES_STORAGE)).withQuery(query).withLimit(Integer.MAX_VALUE).withOffset(0);
    return restClient.get(requestEntry, requestContext, PieceCollection.class).thenApply(PieceCollection::getPieces);
}
Also used : PieceCollection(org.folio.rest.jaxrs.model.PieceCollection) RequestEntry(org.folio.rest.core.models.RequestEntry)

Example 4 with PieceCollection

use of org.folio.rest.jaxrs.model.PieceCollection in project mod-orders by folio-org.

the class LocationsAndPiecesConsistencyValidatorTest method testVerifyLocationsAndPiecesConsistencyWhenTwoLocationWithHoldingAndPiecesWithHoldingIdAndLocationId.

@Test
public void testVerifyLocationsAndPiecesConsistencyWhenTwoLocationWithHoldingAndPiecesWithHoldingIdAndLocationId() {
    String holdingId1 = UUID.randomUUID().toString();
    String holdingId2 = UUID.randomUUID().toString();
    Location location1 = new Location().withHoldingId(holdingId1).withQuantity(1).withQuantityPhysical(1);
    Location location2 = new Location().withHoldingId(holdingId2).withQuantity(1).withQuantityPhysical(1);
    String poLineId = UUID.randomUUID().toString();
    CompositePoLine poLine = new CompositePoLine().withId(poLineId).withLocations(List.of(location1, location2));
    List<CompositePoLine> poLines = List.of(poLine);
    Piece piece1 = new Piece().withPoLineId(poLineId).withLocationId(UUID.randomUUID().toString()).withReceivingStatus(Piece.ReceivingStatus.EXPECTED);
    Piece piece2 = new Piece().withPoLineId(poLineId).withHoldingId(holdingId2).withReceivingStatus(Piece.ReceivingStatus.EXPECTED);
    PieceCollection pieces = new PieceCollection().withPieces(List.of(piece1, piece2)).withTotalRecords(2);
    // Expect
    HttpException actHttpException = assertThrows(HttpException.class, () -> LocationsAndPiecesConsistencyValidator.verifyLocationsAndPiecesConsistency(poLines, pieces), "Expected exception");
    Error actError = actHttpException.getError();
    assertEquals(PIECES_TO_BE_DELETED.getCode(), actError.getCode());
    assertEquals(VALIDATION_ERROR, actHttpException.getCode());
}
Also used : PieceCollection(org.folio.rest.jaxrs.model.PieceCollection) Piece(org.folio.rest.jaxrs.model.Piece) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Error(org.folio.rest.jaxrs.model.Error) HttpException(org.folio.rest.core.exceptions.HttpException) Location(org.folio.rest.jaxrs.model.Location) Test(org.junit.jupiter.api.Test)

Example 5 with PieceCollection

use of org.folio.rest.jaxrs.model.PieceCollection in project mod-orders by folio-org.

the class LocationsAndPiecesConsistencyValidator method verifyLocationsAndPiecesConsistency.

public static void verifyLocationsAndPiecesConsistency(List<CompositePoLine> poLines, PieceCollection pieces) {
    if (CollectionUtils.isNotEmpty(poLines)) {
        Map<String, Map<String, Integer>> numOfLocationsByPoLineIdAndLocationIdV = numOfLocationsByPoLineIdAndLocationId(poLines);
        Map<String, Map<String, Integer>> numOfPiecesByPoLineIdAndLocationIdV = numOfPiecesByPoLineAndLocationId(pieces);
        numOfPiecesByPoLineIdAndLocationIdV.forEach((poLineId, numOfPiecesByLocationId) -> numOfPiecesByLocationId.forEach((locationId, quantity) -> {
            Integer numOfPieces = 0;
            if (numOfLocationsByPoLineIdAndLocationIdV.get(poLineId) != null && numOfLocationsByPoLineIdAndLocationIdV.get(poLineId).get(locationId) != null) {
                numOfPieces = numOfLocationsByPoLineIdAndLocationIdV.get(poLineId).get(locationId);
            }
            if (quantity > numOfPieces) {
                throw new HttpException(422, PIECES_TO_BE_DELETED.toError());
            }
        }));
    }
}
Also used : Location(org.folio.rest.jaxrs.model.Location) Piece(org.folio.rest.jaxrs.model.Piece) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) HttpException(org.folio.rest.core.exceptions.HttpException) PIECES_TO_BE_DELETED(org.folio.rest.core.exceptions.ErrorCodes.PIECES_TO_BE_DELETED) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) Collectors.toMap(java.util.stream.Collectors.toMap) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) PieceCollection(org.folio.rest.jaxrs.model.PieceCollection) Map(java.util.Map) Optional(java.util.Optional) Collectors.summingInt(java.util.stream.Collectors.summingInt) HttpException(org.folio.rest.core.exceptions.HttpException) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map)

Aggregations

PieceCollection (org.folio.rest.jaxrs.model.PieceCollection)8 Piece (org.folio.rest.jaxrs.model.Piece)6 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)5 Location (org.folio.rest.jaxrs.model.Location)5 Test (org.junit.jupiter.api.Test)5 HttpException (org.folio.rest.core.exceptions.HttpException)4 Error (org.folio.rest.jaxrs.model.Error)3 List (java.util.List)2 Map (java.util.Map)2 RequestEntry (org.folio.rest.core.models.RequestEntry)2 Context (io.vertx.core.Context)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1