Skip to content

Commit

Permalink
[MODORDERS-1210] Add acq unit check
Browse files Browse the repository at this point in the history
  • Loading branch information
Saba-Zedginidze-EPAM committed Nov 27, 2024
1 parent 06ff190 commit 3e09215
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
13 changes: 6 additions & 7 deletions src/main/java/org/folio/config/ApplicationConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -641,13 +641,12 @@ PieceUpdateFlowPoLineService pieceUpdateFlowPoLineService(PurchaseOrderStorageSe
}

@Bean
PieceUpdateFlowManager pieceUpdateFlowManager(PieceStorageService pieceStorageService, PieceService pieceService, ProtectionService protectionService,
PieceUpdateFlowPoLineService pieceUpdateFlowPoLineService, PieceUpdateFlowInventoryManager pieceUpdateFlowInventoryManager,
BasePieceFlowHolderBuilder basePieceFlowHolderBuilder, DefaultPieceFlowsValidator defaultPieceFlowsValidator,
PurchaseOrderLineService purchaseOrderLineService) {
return new PieceUpdateFlowManager(pieceStorageService, pieceService, protectionService, pieceUpdateFlowPoLineService,
pieceUpdateFlowInventoryManager, basePieceFlowHolderBuilder, defaultPieceFlowsValidator,
purchaseOrderLineService);
PieceUpdateFlowManager pieceUpdateFlowManager(PieceStorageService pieceStorageService, PieceService pieceService, TitlesService titlesService,
ProtectionService protectionService, PieceUpdateFlowPoLineService pieceUpdateFlowPoLineService,
PieceUpdateFlowInventoryManager pieceUpdateFlowInventoryManager, BasePieceFlowHolderBuilder basePieceFlowHolderBuilder,
DefaultPieceFlowsValidator defaultPieceFlowsValidator, PurchaseOrderLineService purchaseOrderLineService) {
return new PieceUpdateFlowManager(pieceStorageService, pieceService, titlesService, protectionService, pieceUpdateFlowPoLineService,
pieceUpdateFlowInventoryManager, basePieceFlowHolderBuilder, defaultPieceFlowsValidator, purchaseOrderLineService);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import org.folio.models.pieces.BasePieceFlowHolder;
import org.folio.models.pieces.PieceBatchStatusUpdateHolder;
import org.folio.models.pieces.PieceUpdateHolder;
import org.folio.okapi.common.GenericCompositeFuture;
import org.folio.orders.utils.HelperUtils;
import org.folio.orders.utils.PoLineCommonUtil;
import org.folio.orders.utils.ProtectedOperationType;
import org.folio.rest.core.models.RequestContext;
import org.folio.rest.jaxrs.model.CompositePoLine;
import org.folio.rest.jaxrs.model.CompositePurchaseOrder.OrderType;
Expand All @@ -29,25 +31,28 @@
import org.folio.service.pieces.flows.DefaultPieceFlowsValidator;

import io.vertx.core.Future;
import org.folio.service.titles.TitlesService;

@Log4j2
public class PieceUpdateFlowManager {

private final PieceStorageService pieceStorageService;
private final PieceService pieceService;
private final TitlesService titlesService;
private final ProtectionService protectionService;
private final PieceUpdateFlowPoLineService updatePoLineService;
private final PieceUpdateFlowInventoryManager pieceUpdateFlowInventoryManager;
private final BasePieceFlowHolderBuilder basePieceFlowHolderBuilder;
private final DefaultPieceFlowsValidator defaultPieceFlowsValidator;
private final PurchaseOrderLineService purchaseOrderLineService;

public PieceUpdateFlowManager(PieceStorageService pieceStorageService, PieceService pieceService, ProtectionService protectionService,
public PieceUpdateFlowManager(PieceStorageService pieceStorageService, PieceService pieceService, TitlesService titlesService, ProtectionService protectionService,
PieceUpdateFlowPoLineService updatePoLineService, PieceUpdateFlowInventoryManager pieceUpdateFlowInventoryManager,
BasePieceFlowHolderBuilder basePieceFlowHolderBuilder, DefaultPieceFlowsValidator defaultPieceFlowsValidator,
PurchaseOrderLineService purchaseOrderLineService) {
this.pieceStorageService = pieceStorageService;
this.pieceService = pieceService;
this.titlesService = titlesService;
this.protectionService = protectionService;
this.updatePoLineService = updatePoLineService;
this.pieceUpdateFlowInventoryManager = pieceUpdateFlowInventoryManager;
Expand Down Expand Up @@ -92,6 +97,7 @@ public Future<Void> updatePiece(Piece pieceToUpdate, boolean createItem, boolean
public Future<Void> updatePiecesStatuses(List<String> pieceIds, PieceBatchStatusCollection.ReceivingStatus receivingStatus, RequestContext requestContext) {
var newStatus = Piece.ReceivingStatus.fromValue(receivingStatus.value());
return pieceStorageService.getPiecesByIds(pieceIds, requestContext)
.compose(pieces -> isOperationRestricted(pieces, requestContext))
.map(pieces -> pieces.stream().collect(Collectors.groupingBy(Piece::getPoLineId)))
.map(piecesByPoLineId -> piecesByPoLineId.entrySet().stream()
.map(entry -> new PieceBatchStatusUpdateHolder(newStatus, entry.getValue(), entry.getKey()))
Expand Down Expand Up @@ -152,4 +158,14 @@ private List<Location> getPieceLocations(List<Piece> pieces, CompositePoLine poL
.toList();
}

protected Future<List<Piece>> isOperationRestricted(List<Piece> pieces, RequestContext requestContext) {
var pieceIds = pieces.stream().map(Piece::getId).toList();
return titlesService.getTitlesByPieceIds(pieceIds, requestContext)
.map(titles -> titles.stream()
.map(title -> protectionService.isOperationRestricted(title.getAcqUnitIds(), ProtectedOperationType.UPDATE, requestContext))
.collect(Collectors.toList()))
.map(GenericCompositeFuture::all)
.map(pieces);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.folio.service.pieces.PieceUtil;
import org.folio.service.pieces.flows.BasePieceFlowHolderBuilder;
import org.folio.service.pieces.flows.DefaultPieceFlowsValidator;
import org.folio.service.titles.TitlesService;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -397,6 +398,9 @@ private static class ContextConfiguration {
@Bean PieceService pieceService() {
return mock(PieceService.class);
}
@Bean TitlesService titlesService() {
return mock(TitlesService.class);
}
@Bean PieceUpdateFlowInventoryManager pieceUpdateFlowInventoryManager() {
return mock(PieceUpdateFlowInventoryManager.class);
}
Expand All @@ -423,11 +427,11 @@ private static class ContextConfiguration {
}

@Bean
PieceUpdateFlowManager pieceUpdateFlowManager(PieceStorageService pieceStorageService, PieceService pieceService,
PieceUpdateFlowManager pieceUpdateFlowManager(PieceStorageService pieceStorageService, PieceService pieceService, TitlesService titlesService,
ProtectionService protectionService, PieceUpdateFlowPoLineService pieceUpdateFlowPoLineService,
PieceUpdateFlowInventoryManager pieceUpdateFlowInventoryManager, BasePieceFlowHolderBuilder basePieceFlowHolderBuilder,
DefaultPieceFlowsValidator defaultPieceFlowsValidator, PurchaseOrderLineService purchaseOrderLineService) {
return new PieceUpdateFlowManager(pieceStorageService, pieceService, protectionService,
return new PieceUpdateFlowManager(pieceStorageService, pieceService, titlesService, protectionService,
pieceUpdateFlowPoLineService, pieceUpdateFlowInventoryManager, basePieceFlowHolderBuilder,
defaultPieceFlowsValidator, purchaseOrderLineService);
}
Expand Down

0 comments on commit 3e09215

Please sign in to comment.