-
Notifications
You must be signed in to change notification settings - Fork 8
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
MODORDERS -1087 Delete received pieces in bulk #905
base: master
Are you sure you want to change the base?
Changes from 11 commits
eda88e0
e64274c
28f1b6c
72ac005
68d0484
f01b393
525c527
6f668d5
a901c73
d0af7ee
e8f7699
21afa09
2757e77
be962f1
2b281ef
f5c448a
87c595a
bceb008
bf581aa
1cf716a
3bb8489
7a2add6
b20df9d
d32be26
cf510ae
472c0ee
8629560
fca8ab8
a632499
eb142cc
01286f9
3205ba6
ac5d118
6d1fd0d
b8d16d0
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 |
---|---|---|
|
@@ -7,7 +7,9 @@ | |
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import io.vertx.core.CompositeFuture; | ||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
@@ -54,6 +56,7 @@ public PieceDeleteFlowManager(PieceStorageService pieceStorageService, Protectio | |
|
||
public Future<Void> deletePiece(String pieceId, boolean deleteHolding, RequestContext requestContext) { | ||
PieceDeletionHolder holder = new PieceDeletionHolder().withDeleteHolding(deleteHolding); | ||
|
||
return pieceStorageService.getPieceById(pieceId, requestContext) | ||
.map(pieceToDelete -> { | ||
holder.withPieceToDelete(pieceToDelete); return null; | ||
|
@@ -140,4 +143,26 @@ private Future<JsonObject> getOnOrderItemForPiece(Piece piece, RequestContext re | |
return Future.succeededFuture(); | ||
} | ||
} | ||
|
||
public Future<Void> batchDeletePiece(List<String> ids, RequestContext requestContext) { | ||
PieceDeletionHolder holder = new PieceDeletionHolder().withDeleteHolding(false); | ||
|
||
List<Future> deleteFutures = ids.stream() | ||
.map(id -> pieceStorageService.getPieceById(id, requestContext) | ||
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. instead of fetching piece one by one, can we get as collections? like getPieces(List pieceIds).. 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. I will try it. I see there is a max number of get pieces in batch is 15. I am not sure why. but, I will try it first, and see how it goes. 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. it is some constant to prevent long url query size, the max size of url length - 4 kb, historically we use chunks by 15 elems to avoid this issue. 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. Thank you for the info, Serhii |
||
.map(pieceToDelete -> { | ||
holder.withPieceToDelete(pieceToDelete); | ||
return null; | ||
}) | ||
.compose(aHolder -> basePieceFlowHolderBuilder.updateHolderWithOrderInformation(holder, requestContext)) | ||
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. The same logic also is in deletePiece method. We should avoid code duplication, logic should be in 1 places 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. thank you Serhii, I will rewrite this part |
||
.compose(aHolder -> basePieceFlowHolderBuilder.updateHolderWithTitleInformation(holder, requestContext)) | ||
.compose(aVoid -> protectionService.isOperationRestricted(holder.getTitle().getAcqUnitIds(), DELETE, requestContext)) | ||
.compose(aVoid -> isDeletePieceRequestValid(holder, requestContext)) | ||
.compose(aVoid -> processInventory(holder, requestContext)) | ||
.compose(pair -> updatePoLine(holder, requestContext)) | ||
.compose(aVoid -> pieceStorageService.deletePiece(holder.getPieceToDelete().getId(), true, requestContext)) | ||
) | ||
.collect(Collectors.toList()); | ||
|
||
return CompositeFuture.all(deleteFutures).mapEmpty(); | ||
} | ||
} |
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.
please reformat this file one more time