Skip to content

Commit

Permalink
[MODORDERS-1166] Add bindItemTenantId to Piece schema (#1003)
Browse files Browse the repository at this point in the history
* [MODORDERS-1166] Add bindItemTenantId to Piece schema

* [MODORDERS-1166] Update acq-models pointer

* [MODORDERS-1166] Update acq-models pointer
  • Loading branch information
Saba-Zedginidze-EPAM authored Aug 22, 2024
1 parent 77571bc commit 92a6845
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ramls/acq-models
7 changes: 4 additions & 3 deletions src/main/java/org/folio/helper/BindHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Future<Void> removeBinding(String pieceId, RequestContext requestContext)
return pieceStorageService.getPieceById(pieceId, requestContext)
.compose(piece -> {
var bindItemId = piece.getBindItemId();
piece.withBindItemId(null).withIsBound(false);
piece.withBindItemId(null).withBindItemTenantId(null).withIsBound(false);
return removeForbiddenEntities(piece, requestContext)
.map(v -> Collections.<String, List<Piece>>singletonMap(null, List.of(piece)))
.compose(piecesGroupedByPoLine -> storeUpdatedPieceRecords(piecesGroupedByPoLine, requestContext))
Expand Down Expand Up @@ -220,18 +220,19 @@ private Future<BindPiecesHolder> updateItemStatus(BindPiecesHolder holder, Reque
private Future<BindPiecesHolder> createItemForPieces(BindPiecesHolder holder, RequestContext requestContext) {
var bindPiecesCollection = holder.getBindPiecesCollection();
var poLineId = holder.getPoLineId();
var bindItem = bindPiecesCollection.getBindItem();
logger.debug("createItemForPiece:: Trying to get poLine by id '{}'", poLineId);
return purchaseOrderLineService.getOrderLineById(poLineId, requestContext)
.map(PoLineCommonUtil::convertToCompositePoLine)
.compose(compPOL -> createInventoryObjects(compPOL, bindPiecesCollection.getInstanceId(), bindPiecesCollection.getBindItem(), requestContext))
.compose(compPOL -> createInventoryObjects(compPOL, bindPiecesCollection.getInstanceId(), bindItem, requestContext))
.map(newItemId -> {
// Move requests if requestsAction is TRANSFER, otherwise do nothing
if (TRANSFER.equals(bindPiecesCollection.getRequestsAction())) {
var itemIds = holder.getPieces().map(Piece::getItemId).toList();
inventoryItemRequestService.transferItemRequests(itemIds, newItemId, requestContext);
}
// Set new item ids for pieces and holder
holder.getPieces().forEach(piece -> piece.setBindItemId(newItemId));
holder.getPieces().forEach(piece -> piece.withBindItemTenantId(bindItem.getTenantId()).setBindItemId(newItemId));
return holder.withBindItemId(newItemId);
});
}
Expand Down
20 changes: 15 additions & 5 deletions src/test/java/org/folio/rest/impl/CheckinReceivingApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,7 @@ void testBindPiecesToTitleWithItem() {
var holdingId = "849241fa-4a14-4df5-b951-846dcd6cfc4d";
var receivingStatus = Piece.ReceivingStatus.UNRECEIVABLE;
var format = Piece.Format.ELECTRONIC;
var tenantId = "tenantId";

var order = getMinimalContentCompositePurchaseOrder()
.withWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
Expand Down Expand Up @@ -1249,7 +1250,8 @@ void testBindPiecesToTitleWithItem() {
.withPoLineId(poLine.getId())
.withBindItem(getMinimalContentBindItem()
.withLocationId(null)
.withHoldingId(holdingId))
.withHoldingId(holdingId)
.withTenantId(tenantId))
.withBindPieceIds(pieceIds);

var response = verifyPostResponse(ORDERS_BIND_ENDPOINT, JsonObject.mapFrom(bindPiecesCollection).encode(),
Expand All @@ -1269,6 +1271,7 @@ void testBindPiecesToTitleWithItem() {
.map(json -> json.mapTo(Piece.class))
.filter(piece -> pieceIds.contains(piece.getId()))
.filter(piece -> piece.getBindItemId().equals(newItemId))
.filter(piece -> piece.getBindItemTenantId().equals(tenantId))
.toList();
assertThat(pieceList.size(), is(2));

Expand Down Expand Up @@ -1306,6 +1309,8 @@ void testBindPiecesWithLocationIdOnly() {

var receivingStatus = Piece.ReceivingStatus.UNRECEIVABLE;
var format = Piece.Format.ELECTRONIC;
var tenantId = "tenantId";

var order = getMinimalContentCompositePurchaseOrder()
.withWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
var poLine = getMinimalContentCompositePoLine(order.getId());
Expand All @@ -1324,7 +1329,8 @@ void testBindPiecesWithLocationIdOnly() {
var bindPiecesCollection = new BindPiecesCollection()
.withPoLineId(poLine.getId())
.withBindItem(getMinimalContentBindItem()
.withLocationId(locationId))
.withLocationId(locationId)
.withTenantId(tenantId))
.withBindPieceIds(pieceIds);

var response = verifyPostResponse(ORDERS_BIND_ENDPOINT, JsonObject.mapFrom(bindPiecesCollection).encode(),
Expand All @@ -1342,7 +1348,8 @@ void testBindPiecesWithLocationIdOnly() {
var pieceList = pieceUpdates.stream().filter(pol -> {
Piece piece = pol.mapTo(Piece.class);
String pieceId = piece.getId();
return Objects.equals(bindingPiece.getId(), pieceId);
return Objects.equals(bindingPiece.getId(), pieceId)
&& Objects.equals(piece.getBindItemTenantId(), tenantId);
}).toList();
assertThat(pieceList.size(), is(1));

Expand Down Expand Up @@ -1504,6 +1511,7 @@ void testRemovePieceBinding() {
logger.info("=== Test DELETE Remove binding");

var holdingId = "849241fa-4a14-4df5-b951-846dcd6cfc4d";
var tenantId = "tenantId";
var order = getMinimalContentCompositePurchaseOrder()
.withWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
var poLine = getMinimalContentCompositePoLine(order.getId());
Expand Down Expand Up @@ -1531,7 +1539,8 @@ void testRemovePieceBinding() {
.withPoLineId(poLine.getId())
.withBindItem(getMinimalContentBindItem()
.withLocationId(null)
.withHoldingId(holdingId))
.withHoldingId(holdingId)
.withTenantId(tenantId))
.withBindPieceIds(bindPieceIds);

var bindResponse = verifyPostResponse(ORDERS_BIND_ENDPOINT, JsonObject.mapFrom(bindPiecesCollection).encode(),
Expand All @@ -1543,7 +1552,6 @@ void testRemovePieceBinding() {
assertThat(bindResponse.getBoundPieceIds(), is(bindPieceIds));
assertThat(bindResponse.getItemId(), notNullValue());

var bindItemId = bindResponse.getItemId();
var url = String.format(ORDERS_BIND_ID_ENDPOINT, bindPiece1.getId());
verifyDeleteResponse(url, "", HttpStatus.HTTP_NO_CONTENT.toInt());

Expand All @@ -1561,10 +1569,12 @@ void testRemovePieceBinding() {
var pieceBefore = pieceList.get(1);
assertThat(pieceBefore.getIsBound(), is(true));
assertThat(pieceBefore.getBindItemId(), notNullValue());
assertThat(pieceBefore.getBindItemTenantId(), notNullValue());

var pieceAfter = pieceList.get(0);
assertThat(pieceAfter.getIsBound(), is(false));
assertThat(pieceAfter.getBindItemId(), nullValue());
assertThat(pieceAfter.getReceivingTenantId(), nullValue());
}

@Test
Expand Down

0 comments on commit 92a6845

Please sign in to comment.