-
Notifications
You must be signed in to change notification settings - Fork 8
[MODORDERS-1311] Prevent unopening of order when related piece has a request #1252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.EnumSet; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
@@ -99,6 +100,48 @@ public Future<Void> process(CompositePurchaseOrder compPO, CompositePurchaseOrde | |
|
|
||
| } | ||
|
|
||
| public Future<Void> rollbackInventory(CompositePurchaseOrder compPO, RequestContext requestContext) { | ||
| return processPoLines(compPO.getPoLines(), poLine -> processInventory(poLine, true, requestContext)); | ||
| } | ||
|
|
||
| public Future<Void> checkRequests(CompositePurchaseOrder compPO, RequestContext requestContext) { | ||
| List<PoLine> poLines = compPO.getPoLines().stream() | ||
| .filter(poLine -> !Boolean.TRUE.equals(poLine.getIsPackage())) | ||
| .toList(); | ||
| HashMap<String, List<String>> tenantIdToPoLineIds = createTenantIdToPoLineIdsMap(poLines); | ||
| List<Future<Void>> futures = tenantIdToPoLineIds.keySet().stream() | ||
| .map(tenantId -> { | ||
| List<String> poLineIds = tenantIdToPoLineIds.get(tenantId); | ||
| RequestContext tenantRequestContext = createContextWithNewTenantId(requestContext, tenantId); | ||
| return inventoryItemManager.getItemsByPoLineIdsAndStatus(poLineIds, ItemStatus.ON_ORDER.value(), tenantRequestContext) | ||
| .compose(onOrderItems -> { | ||
| if (CollectionUtils.isEmpty(onOrderItems)) { | ||
| return Future.succeededFuture(); | ||
| } | ||
| List<String> itemIds = onOrderItems.stream().map(item -> item.getString(ID)).toList(); | ||
| return checkRequestsForItems(itemIds, tenantRequestContext); | ||
| }); | ||
| }) | ||
| .toList(); | ||
| return HelperUtils.executeAllFailFast(futures); | ||
| } | ||
|
|
||
| private HashMap<String, List<String>> createTenantIdToPoLineIdsMap(List<PoLine> poLines) { | ||
| HashMap<String, List<String>> tenantIdToPoLineIds = new HashMap<>(); | ||
| poLines.forEach(poLine -> { | ||
| List<String> tenantIds = PoLineCommonUtil.getTenantsFromLocations(poLine); | ||
SerhiiNosko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| tenantIds.forEach(tenantId -> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this logic check requests from standalone non ecs tenants like diku? Location object will not have standalone tenants, so we should check them from request headers
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, with a null tenantId. |
||
| List<String> poLineIds = tenantIdToPoLineIds.get(tenantId); | ||
| if (poLineIds == null) { | ||
| poLineIds = new ArrayList<>(); | ||
| } | ||
| poLineIds.add(poLine.getId()); | ||
| tenantIdToPoLineIds.put(tenantId, poLineIds); | ||
| }); | ||
| }); | ||
| return tenantIdToPoLineIds; | ||
| } | ||
|
|
||
| private Future<CompositePurchaseOrder> updateAndGetOrderWithLines(CompositePurchaseOrder compPO, RequestContext requestContext) { | ||
| if (CollectionUtils.isNotEmpty(compPO.getPoLines())) { | ||
| return Future.succeededFuture(compPO); | ||
|
|
@@ -121,10 +164,6 @@ private Future<Void> updatePoLinesSummary(List<PoLine> poLines, RequestContext r | |
| return processPoLines(poLines, poLine -> purchaseOrderLineService.saveOrderLine(poLine, requestContext)); | ||
| } | ||
|
|
||
| public Future<Void> rollbackInventory(CompositePurchaseOrder compPO, RequestContext requestContext) { | ||
| return processPoLines(compPO.getPoLines(), poLine -> processInventory(poLine, true, requestContext)); | ||
| } | ||
|
|
||
| private Future<Void> processInventory(List<PoLine> poLines, boolean deleteHoldings, RequestContext requestContext) { | ||
| return processPoLines(poLines, poLine -> processInventory(poLine, deleteHoldings, requestContext)); | ||
| } | ||
|
|
@@ -366,7 +405,6 @@ private Future<Void> deletePieceWithItem(String pieceId, RequestContext requestC | |
| .compose(poLine -> purchaseOrderStorageService.getPurchaseOrderById(poLine.getPurchaseOrderId(), requestContext) | ||
| .map(purchaseOrder -> holder.withOrderInformation(purchaseOrder, poLine))) | ||
| .compose(aHolder -> protectionService.isOperationRestricted(holder.getOriginPurchaseOrder().getAcqUnitIds(), DELETE, requestContext)) | ||
| .compose(vVoid -> canDeletePieceWithItem(holder.getPieceToDelete(), requestContext)) | ||
| .compose(aVoid -> pieceStorageService.deletePiece(pieceId, requestContext)) | ||
| .compose(aVoid -> deletePieceConnectedItem(holder.getPieceToDelete(), itemContext)); | ||
| } | ||
|
|
@@ -390,9 +428,9 @@ private Future<Void> deletePieceConnectedItem(Piece piece, RequestContext reques | |
| }); | ||
| } | ||
|
|
||
| private Future<Void> canDeletePieceWithItem(Piece piece, RequestContext requestContext) { | ||
| return circulationRequestsRetriever.getNumberOfRequestsByItemId(piece.getItemId(), requestContext) | ||
| .compose(numOfRequests -> numOfRequests != null && numOfRequests > 0 | ||
| private Future<Void> checkRequestsForItems(List<String> itemIds, RequestContext requestContext) { | ||
| return circulationRequestsRetriever.getNumbersOfRequestsByItemIds(itemIds, requestContext) | ||
| .compose(idsAndCounts -> idsAndCounts.values().stream().anyMatch(count -> count > 0) | ||
| ? Future.failedFuture(new HttpException(422, ErrorCodes.REQUEST_FOUND.toError())) | ||
| : Future.succeededFuture()); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
karate test can be written for non-ecs setup, for standalone tenants.
But in future we should improve running karate tests locally for the ECS, we have stories for it.