-
Notifications
You must be signed in to change notification settings - Fork 7
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-1114] Add transferRequests flag to validate binding #936
Changes from all commits
07ab60e
0bf38fe
54eb806
69da16e
066e1ac
beb449b
88f5906
50c6bac
0a0096c
606606c
59457a3
7fbdd8b
29e88b9
2c5f15b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
+5 −0 | mod-orders/schemas/bindPiecesCollection.json | |
+10 −0 | mod-orders/schemas/requestsAction.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,8 @@ | |
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
import static java.util.stream.Collectors.mapping; | ||
import static java.util.stream.Collectors.toList; | ||
import static org.apache.commons.lang3.StringUtils.EMPTY; | ||
import static org.folio.orders.utils.HelperUtils.collectResultsOnSuccess; | ||
import static org.folio.orders.utils.ResourcePathResolver.PIECES_STORAGE; | ||
|
@@ -465,8 +467,7 @@ private Future<Void> processHoldingsUpdate(Map<String, List<Piece>> piecesGroupe | |
PoLineAndTitleById poLinesAndTitlesById, | ||
RequestContext requestContext) { | ||
List<Future<Boolean>> futuresForHoldingsUpdates = new ArrayList<>(); | ||
StreamEx.ofValues(piecesGroupedByPoLine) | ||
.flatMap(List::stream) | ||
extractAllPieces(piecesGroupedByPoLine) | ||
.forEach(piece -> { | ||
CompositePoLine poLine = poLinesAndTitlesById.poLineById.get(piece.getPoLineId()); | ||
if (poLine == null) { | ||
|
@@ -539,30 +540,18 @@ private boolean ifHoldingNotProcessed(String key) { | |
private Future<List<JsonObject>> getItemRecords(Map<String, List<Piece>> piecesGroupedByPoLine, | ||
Map<String, Piece> piecesByItemId, | ||
RequestContext requestContext) { | ||
|
||
Map<String, List<String>> itemIdsByTenantId = new HashMap<>(); | ||
for (List<Piece> pieceList : piecesGroupedByPoLine.values()) { | ||
for (Piece piece : pieceList) { | ||
if (StringUtils.isNotEmpty(piece.getItemId())) { | ||
itemIdsByTenantId.computeIfAbsent(piece.getReceivingTenantId(), k -> new ArrayList<>()).add(piece.getItemId()); | ||
} | ||
} | ||
} | ||
|
||
// split all id lists by maximum number of id's for get query | ||
List<Future<List<JsonObject>>> futures = itemIdsByTenantId.entrySet() | ||
.stream() | ||
.flatMap( | ||
entry -> StreamEx.ofSubLists(entry.getValue(), MAX_IDS_FOR_GET_RQ_15) | ||
.map(ids -> { | ||
var locationContext = RequestContextUtil.createContextWithNewTenantId(requestContext, entry.getKey()); | ||
return getItemRecordsByIds(ids, piecesByItemId, locationContext); | ||
}) | ||
) | ||
.toList(); | ||
|
||
return collectResultsOnSuccess(futures) | ||
.map(lists -> StreamEx.of(lists).toFlatList(jsonObjects -> jsonObjects)); | ||
// Split all id lists by maximum number of id's for get query | ||
return collectResultsOnSuccess( | ||
mapTenantIdsToItemIds(piecesGroupedByPoLine, requestContext).entrySet().stream() | ||
.flatMap(entry -> | ||
StreamEx.ofSubLists(entry.getValue(), MAX_IDS_FOR_GET_RQ_15) | ||
.map(ids -> { | ||
var locationContext = RequestContextUtil.createContextWithNewTenantId(requestContext, entry.getKey()); | ||
return getItemRecordsByIds(ids, piecesByItemId, locationContext); | ||
}) | ||
) | ||
.toList()) | ||
.map(lists -> StreamEx.of(lists).toFlatList(items -> items)); | ||
} | ||
|
||
/** | ||
|
@@ -767,6 +756,31 @@ private List<String> getPieceIds() { | |
.toFlatList(ids -> ids); | ||
} | ||
|
||
protected Map<String, Piece> getProcessedPiecesForPoLine(String poLineId, Map<String, List<Piece>> piecesGroupedByPoLine) { | ||
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. 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 move above the errors, thanks. I guess yes, the class is pretty big and can be refactored, unsure if in scope of this. |
||
return StreamEx | ||
.of(piecesGroupedByPoLine.getOrDefault(poLineId, Collections.emptyList())) | ||
.toMap(Piece::getId, piece -> piece); | ||
} | ||
|
||
protected Map<ProcessingStatus.Type, Integer> getEmptyResultCounts() { | ||
Map<ProcessingStatus.Type, Integer> resultCounts = new HashMap<>(); | ||
resultCounts.put(ProcessingStatus.Type.SUCCESS, 0); | ||
resultCounts.put(ProcessingStatus.Type.FAILURE, 0); | ||
return resultCounts; | ||
} | ||
|
||
protected StreamEx<Piece> extractAllPieces(Map<String, List<Piece>> piecesGroupedByPoLine) { | ||
return StreamEx.ofValues(piecesGroupedByPoLine).flatMap(List::stream); | ||
} | ||
|
||
protected Map<String, List<String>> mapTenantIdsToItemIds(Map<String, List<Piece>> piecesGroupedByPoLine, RequestContext 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. This is much like to what I did in |
||
return extractAllPieces(piecesGroupedByPoLine) | ||
.filter(piece -> StringUtils.isNotEmpty(piece.getItemId())) | ||
.groupingBy(piece -> Optional.ofNullable(piece.getReceivingTenantId()) | ||
.orElse(RequestContextUtil.getContextTenantId(requestContext)), | ||
mapping(Piece::getItemId, toList())); | ||
} | ||
|
||
//------------------------------------------------------------------------------------- | ||
/* | ||
Errors | ||
|
@@ -813,17 +827,17 @@ private void addError(String polId, String pieceId, Error error) { | |
|
||
public void calculateProcessingErrors(String poLineId, ReceivingResult result, | ||
Map<String, Piece> processedPiecesForPoLine, | ||
Map<String, Integer> resultCounts, String pieceId) { | ||
Map<ProcessingStatus.Type, Integer> resultCounts, String pieceId) { | ||
// Calculate processing status | ||
ProcessingStatus status = new ProcessingStatus(); | ||
Error error = getError(poLineId, pieceId); | ||
if (processedPiecesForPoLine.get(pieceId) != null && error == null) { | ||
status.setType(ProcessingStatus.Type.SUCCESS); | ||
resultCounts.merge(ProcessingStatus.Type.SUCCESS.toString(), 1, Integer::sum); | ||
resultCounts.merge(ProcessingStatus.Type.SUCCESS, 1, Integer::sum); | ||
} else { | ||
status.setType(ProcessingStatus.Type.FAILURE); | ||
status.setError(error); | ||
resultCounts.merge(ProcessingStatus.Type.FAILURE.toString(), 1, Integer::sum); | ||
resultCounts.merge(ProcessingStatus.Type.FAILURE, 1, Integer::sum); | ||
} | ||
|
||
ReceivingItemResult itemResult = new ReceivingItemResult(); | ||
|
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.
some unused imports are introduced, you can find them in sonar report:
https://sonarcloud.io/project/issues?id=org.folio%3Amod-orders&pullRequest=936&resolved=false&sinceLeakPeriod=true