use of org.folio.rest.jaxrs.model.CheckinCollection in project mod-orders by folio-org.
the class ReceivingCheckinProtectionTest method testCheckInCompositeFlow.
@Test
void testCheckInCompositeFlow() {
addMockEntry(PURCHASE_ORDER_STORAGE, JsonObject.mapFrom(getMinimalContentCompositePurchaseOrder().withAcqUnitIds(NOT_PROTECTED_UNITS).withId(ORDER_WITH_NOT_PROTECTED_UNITS_ID)));
addMockEntry(PURCHASE_ORDER_STORAGE, JsonObject.mapFrom(getMinimalContentCompositePurchaseOrder().withAcqUnitIds(PROTECTED_UNITS).withId(ORDER_WITH_PROTECTED_UNITS_ID)));
List<CompositePoLine> poLines = new ArrayList<>();
poLines.add(getMinimalContentCompositePoLine(ORDER_WITH_NOT_PROTECTED_UNITS_ID).withId(EXPECTED_FLOW_PO_LINE_ID));
poLines.add(getMinimalContentCompositePoLine(ORDER_WITH_NOT_PROTECTED_UNITS_ID).withId(RANDOM_PO_LINE_ID_1));
poLines.add(getMinimalContentCompositePoLine(ORDER_WITH_PROTECTED_UNITS_ID).withId(RANDOM_PO_LINE_ID_2));
poLines.forEach(line -> addMockEntry(PO_LINES_STORAGE, JsonObject.mapFrom(line)));
MockServer.addMockTitles(poLines);
CheckinCollection toBeCheckedInRq = new CheckinCollection();
List<ToBeCheckedIn> toBeCheckedInList = new ArrayList<>();
toBeCheckedInList.add(getToBeCheckedIn(EXPECTED_FLOW_PO_LINE_ID, EXPECTED_FLOW_PIECE_ID_1));
toBeCheckedInList.add(getToBeCheckedIn(RANDOM_PO_LINE_ID_1, getRandomId()));
toBeCheckedInList.add(getToBeCheckedIn(RANDOM_PO_LINE_ID_2, getRandomId()));
toBeCheckedInList.add(getToBeCheckedIn(EXPECTED_FLOW_PO_LINE_ID, getRandomId()));
toBeCheckedInRq.setToBeCheckedIn(toBeCheckedInList);
toBeCheckedInRq.setTotalRecords(toBeCheckedInList.size());
ReceivingResults results = verifyPostResponse(Entities.CHECK_IN.getEndpoint(), JsonObject.mapFrom(toBeCheckedInRq).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_WITH_UNITS_NOT_ASSIGNED_TO_ORDER), APPLICATION_JSON, HttpStatus.HTTP_OK.toInt()).as(ReceivingResults.class);
List<ProcessingStatus> result = results.getReceivingResults().stream().flatMap(r -> r.getReceivingItemResults().stream().map(ReceivingItemResult::getProcessingStatus)).filter(s -> Objects.isNull(s.getError())).collect(Collectors.toList());
assertThat(result, hasSize(1));
List<Error> errors = results.getReceivingResults().stream().flatMap(r -> r.getReceivingItemResults().stream().map(e -> e.getProcessingStatus().getError())).filter(Objects::nonNull).collect(Collectors.toList());
assertThat(errors, hasSize(toBeCheckedInList.size() - 1));
assertThat(errors.stream().filter(e -> e.getCode().equals(PIECE_NOT_FOUND.getCode())).count(), is(2L));
assertThat(errors.stream().filter(e -> e.getCode().equals(USER_HAS_NO_PERMISSIONS.getCode())).count(), is(1L));
}
use of org.folio.rest.jaxrs.model.CheckinCollection in project mod-orders by folio-org.
the class CheckinReceivingApiTest method testPostCheckinElectronicPhysicalChangeLocationIdNewHoldingIsCreatedForPhysicalPiece.
@Test
void testPostCheckinElectronicPhysicalChangeLocationIdNewHoldingIsCreatedForPhysicalPiece() {
logger.info("=== Test POST check-in - Check-in physical and electronic resource with new locationId ===");
CompositePurchaseOrder order = getMinimalContentCompositePurchaseOrder();
CompositePoLine poLine = getMinimalContentCompositePoLine(order.getId());
poLine.setOrderFormat(CompositePoLine.OrderFormat.P_E_MIX);
// holding mustn't be created
poLine.setEresource(new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE));
// holding must be created
poLine.setPhysical(new Physical().withCreateInventory(Physical.CreateInventory.INSTANCE_HOLDING));
String locationForPhysical = UUID.randomUUID().toString();
String locationForElectronic = UUID.randomUUID().toString();
String titleId = UUID.randomUUID().toString();
MockServer.addMockTitleWithId(poLine, titleId);
Piece physicalPiece = getMinimalContentPiece(poLine.getId()).withReceivingStatus(Piece.ReceivingStatus.EXPECTED).withFormat(org.folio.rest.jaxrs.model.Piece.Format.PHYSICAL).withLocationId(locationForPhysical).withId(UUID.randomUUID().toString()).withTitleId(titleId).withItemId(UUID.randomUUID().toString());
Piece electronicPiece = getMinimalContentPiece(poLine.getId()).withReceivingStatus(Piece.ReceivingStatus.EXPECTED).withFormat(org.folio.rest.jaxrs.model.Piece.Format.ELECTRONIC).withId(UUID.randomUUID().toString()).withTitleId(titleId).withItemId(UUID.randomUUID().toString());
addMockEntry(PURCHASE_ORDER_STORAGE, order.withWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN));
addMockEntry(PO_LINES_STORAGE, poLine);
addMockEntry(PIECES_STORAGE, physicalPiece);
addMockEntry(PIECES_STORAGE, electronicPiece);
List<ToBeCheckedIn> toBeCheckedInList = new ArrayList<>();
toBeCheckedInList.add(new ToBeCheckedIn().withCheckedIn(1).withPoLineId(poLine.getId()).withCheckInPieces(Arrays.asList(new CheckInPiece().withItemStatus(CheckInPiece.ItemStatus.ON_ORDER), new CheckInPiece().withItemStatus(CheckInPiece.ItemStatus.ON_ORDER))));
CheckinCollection request = new CheckinCollection().withToBeCheckedIn(toBeCheckedInList).withTotalRecords(2);
request.getToBeCheckedIn().get(0).getCheckInPieces().get(0).setId(physicalPiece.getId());
request.getToBeCheckedIn().get(0).getCheckInPieces().get(0).setLocationId(locationForPhysical);
request.getToBeCheckedIn().get(0).getCheckInPieces().get(1).setId(electronicPiece.getId());
request.getToBeCheckedIn().get(0).getCheckInPieces().get(1).setLocationId(locationForElectronic);
checkResultWithErrors(request, 0);
assertThat(getCreatedHoldings(), hasSize(1));
assertThat(getCreatedHoldings().get(0).getString(HOLDING_PERMANENT_LOCATION_ID), is(locationForPhysical));
}
use of org.folio.rest.jaxrs.model.CheckinCollection in project mod-orders by folio-org.
the class CheckinReceivingApiTest method testPostCheckinTitleNotFoundError.
@Test
void testPostCheckinTitleNotFoundError() {
logger.info("=== Test POST check-in title not found error ===");
CompositePurchaseOrder order = getMinimalContentCompositePurchaseOrder();
CompositePoLine poLine = getMinimalContentCompositePoLine(order.getId());
poLine.setIsPackage(true);
poLine.setOrderFormat(CompositePoLine.OrderFormat.ELECTRONIC_RESOURCE);
poLine.setEresource(new Eresource().withCreateInventory(Eresource.CreateInventory.INSTANCE_HOLDING_ITEM));
String locationForElectronic = UUID.randomUUID().toString();
Piece electronicPiece = getMinimalContentPiece(poLine.getId()).withReceivingStatus(Piece.ReceivingStatus.EXPECTED).withFormat(org.folio.rest.jaxrs.model.Piece.Format.ELECTRONIC).withId(UUID.randomUUID().toString()).withTitleId(UUID.randomUUID().toString()).withItemId(UUID.randomUUID().toString());
addMockEntry(PURCHASE_ORDER_STORAGE, order.withWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN));
addMockEntry(PO_LINES_STORAGE, poLine);
addMockEntry(PIECES_STORAGE, electronicPiece);
List<ToBeCheckedIn> toBeCheckedInList = new ArrayList<>();
toBeCheckedInList.add(new ToBeCheckedIn().withCheckedIn(1).withPoLineId(poLine.getId()).withCheckInPieces(Collections.singletonList(new CheckInPiece().withItemStatus(CheckInPiece.ItemStatus.ON_ORDER))));
CheckinCollection request = new CheckinCollection().withToBeCheckedIn(toBeCheckedInList).withTotalRecords(1);
request.getToBeCheckedIn().get(0).getCheckInPieces().get(0).setId(electronicPiece.getId());
request.getToBeCheckedIn().get(0).getCheckInPieces().get(0).setLocationId(locationForElectronic);
Response response = verifyPostResponse(ORDERS_CHECKIN_ENDPOINT, JsonObject.mapFrom(request).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10), APPLICATION_JSON, HttpStatus.HTTP_BAD_REQUEST.toInt());
assertThat(response.as(Errors.class).getErrors().get(0).getMessage(), is(TITLE_NOT_FOUND.getDescription()));
}
use of org.folio.rest.jaxrs.model.CheckinCollection in project mod-orders by folio-org.
the class CheckinReceivingApiTest method testPostCheckInElectronicWithNoItems.
@Test
void testPostCheckInElectronicWithNoItems() {
logger.info("=== Test POST Checkin - CheckIn Electronic resource");
CompositePoLine poLines = getMockAsJson(POLINES_COLLECTION).getJsonArray("poLines").getJsonObject(7).mapTo(CompositePoLine.class);
MockServer.addMockTitles(Collections.singletonList(poLines));
CheckinCollection checkInRq = getMockAsJson(CHECKIN_RQ_MOCK_DATA_PATH + "checkin-pe-mix-2-electronic-resources.json").mapTo(CheckinCollection.class);
ReceivingResults results = verifyPostResponse(ORDERS_CHECKIN_ENDPOINT, JsonObject.mapFrom(checkInRq).encode(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10), APPLICATION_JSON, 200).as(ReceivingResults.class);
assertThat(results.getTotalRecords(), equalTo(checkInRq.getTotalRecords()));
Map<String, Set<String>> pieceIdsByPol = verifyReceivingSuccessRs(results);
List<JsonObject> pieceSearches = getPieceSearches();
List<JsonObject> pieceUpdates = getPieceUpdates();
List<JsonObject> polSearches = getPoLineSearches();
List<JsonObject> polUpdates = getPoLineUpdates();
assertThat(pieceSearches, not(nullValue()));
assertThat(pieceUpdates, not(nullValue()));
assertThat(getItemsSearches(), is(nullValue()));
assertThat(getItemUpdates(), is(nullValue()));
assertThat(polSearches, not(nullValue()));
assertThat(polUpdates, not(nullValue()));
int expectedSearchRqQty = Math.floorDiv(checkInRq.getTotalRecords(), MAX_IDS_FOR_GET_RQ) + 1;
// The piece searches should be made 2 times: 1st time to get all required piece records, 2nd time to calculate expected PO Line status
assertThat(pieceSearches, hasSize(expectedSearchRqQty + pieceIdsByPol.size()));
assertThat(pieceUpdates, hasSize(checkInRq.getTotalRecords()));
assertThat(polSearches, hasSize(pieceIdsByPol.size()));
assertThat(polUpdates, hasSize(pieceIdsByPol.size()));
polUpdates.forEach(pol -> {
PoLine poLine = pol.mapTo(PoLine.class);
assertThat(poLine.getCheckinItems(), is(true));
assertThat(poLine.getReceiptStatus(), is(PoLine.ReceiptStatus.PARTIALLY_RECEIVED));
assertThat(poLine.getReceiptDate(), is(notNullValue()));
});
// Verify message is sent via event bus
verifyCheckinOrderStatusUpdateEvent(1);
}
use of org.folio.rest.jaxrs.model.CheckinCollection in project mod-orders by folio-org.
the class CheckinReceivingApiTest method testPostCheckInLocationId.
@Test
void testPostCheckInLocationId() {
logger.info("=== Test POST Checkin - locationId checking ===");
String poLineId = "fe47e95d-24e9-4a9a-9dc0-bcba64b51f56";
String pieceId = UUID.randomUUID().toString();
CompositePoLine poLine = getMockAsJson(POLINES_COLLECTION).getJsonArray("poLines").getJsonObject(5).mapTo(CompositePoLine.class);
MockServer.addMockTitles(Collections.singletonList(poLine));
List<ToBeCheckedIn> toBeCheckedInList = new ArrayList<>();
toBeCheckedInList.add(new ToBeCheckedIn().withCheckedIn(1).withPoLineId(poLineId).withCheckInPieces(Arrays.asList(new CheckInPiece().withId(pieceId).withItemStatus(CheckInPiece.ItemStatus.ON_ORDER), new CheckInPiece().withItemStatus(CheckInPiece.ItemStatus.IN_PROCESS))));
CheckinCollection request = new CheckinCollection().withToBeCheckedIn(toBeCheckedInList).withTotalRecords(2);
String physicalPieceWithoutLocationId = "90894300-5285-4d83-80f4-76cf621e555e";
String electronicPieceWithoutLocationId = "1a247602-c51a-4221-9a07-27d075d03625";
// Positive cases:
// 1. Both CheckInPiece with locationId
request.getToBeCheckedIn().get(0).getCheckInPieces().get(0).setId(physicalPieceWithoutLocationId);
request.getToBeCheckedIn().get(0).getCheckInPieces().get(0).setLocationId(UUID.randomUUID().toString());
request.getToBeCheckedIn().get(0).getCheckInPieces().get(1).setId(electronicPieceWithoutLocationId);
request.getToBeCheckedIn().get(0).getCheckInPieces().get(1).setLocationId(UUID.randomUUID().toString());
checkResultWithErrors(request, 0);
assertThat(getPieceSearches(), hasSize(2));
assertThat(getPieceUpdates(), hasSize(2));
assertThat(getPoLineSearches(), hasSize(1));
assertThat(getPoLineUpdates(), hasSize(1));
verifyCheckinOrderStatusUpdateEvent(1);
// Negative cases:
// 1. One CheckInPiece and corresponding Piece without locationId
request.getToBeCheckedIn().get(0).getCheckInPieces().get(0).setLocationId(null);
clearServiceInteractions();
MockServer.addMockTitles(Collections.singletonList(poLine));
checkResultWithErrors(request, 1);
assertThat(getPieceSearches(), hasSize(2));
assertThat(getPieceUpdates(), hasSize(1));
assertThat(getPoLineSearches(), hasSize(1));
assertThat(getPoLineUpdates(), hasSize(1));
verifyCheckinOrderStatusUpdateEvent(1);
// 2. All CheckInPieces and corresponding Pieces without locationId
request.getToBeCheckedIn().get(0).getCheckInPieces().get(0).setLocationId(null);
request.getToBeCheckedIn().get(0).getCheckInPieces().get(1).setLocationId(null);
clearServiceInteractions();
MockServer.addMockTitles(Collections.singletonList(poLine));
checkResultWithErrors(request, 2);
assertThat(getPieceSearches(), hasSize(1));
assertThat(getPieceUpdates(), nullValue());
assertThat(getPoLineSearches(), hasSize(1));
assertThat(getPoLineUpdates(), nullValue());
verifyOrderStatusUpdateEvent(0);
}
Aggregations