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