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
Conversation
35b352a
to
39d8e77
Compare
1f7db2a
to
59457a3
Compare
Map<String, Piece> processedPiecesForPoLine = StreamEx | ||
.of(piecesGroupedByPoLine.getOrDefault(poLineId, Collections.emptyList())) | ||
.toMap(Piece::getId, piece -> piece); | ||
Map<String, Piece> processedPiecesForPoLine = getProcessedPiecesForPoLine(poLineId, piecesGroupedByPoLine); |
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
.toMap(Piece::getId, piece -> piece); | ||
} | ||
|
||
protected Map<String, Integer> getEmptyResultCounts() { |
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.
Maybe (if map is not modified later)
return Map.of(
ProcessingStatus.Type.SUCCESS.toString(), 0,
ProcessingStatus.Type.FAILURE.toString(), 0
);
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.
The values are updated, that's why didn't use .of()
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.
Actually map is modified later. Why we have Map<String, int>
instead of Map<ProcessingStatus.Type, int>
?
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.
That's a good point. I just refactored some irrelevant code and didn't go much into details. Will modify
@@ -783,6 +784,30 @@ protected void addErrorForUpdatingItem(Piece piece, Throwable e) { | |||
} | |||
} | |||
|
|||
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 comment
The 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 comment
The 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.
logger.warn("checkRequestsForPieceItems:: Found outstanding requests on items with ids: {}", items); | ||
throw new HttpException(RestConstants.VALIDATION_ERROR, ErrorCodes.REQUESTS_ACTION_REQUIRED); | ||
} | ||
else if (bindPiecesCollection.getRequestsAction().equals(TRANSFER)) { |
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.
Why do you need else if
if you throw an error otherwise?
It's better to handle edge case first:
if (items.isEmpty()) {
return Future.succeededFuture();
}
and then continue with general case.
I'd write:
if (!items.isEmpty() && Objects.isNull(bindPiecesCollection.getRequestsAction())) {
logger.warn("checkRequestsForPieceItems:: Found outstanding requests on items with ids: {}", items);
throw new HttpException(RestConstants.VALIDATION_ERROR, ErrorCodes.REQUESTS_ACTION_REQUIRED);
}
if (!items.isEmpty() && bindPiecesCollection.getRequestsAction().equals(TRANSFER) && !tenantToItem.keySet().isEmpty()) {
logger.warn("checkRequestsForPieceItems:: All pieces do not have the same receivingTenantId: {}", tenantToItem.keySet());
throw new HttpException(RestConstants.VALIDATION_ERROR, ErrorCodes.PIECES_HAVE_DIFFERENT_RECEIVING_TENANT_IDS);
}
return Future.succeededFuture();
});
This way I see a 2 cases where you throw an error but it's up to you. Main thing is to not keep many lines of code indented as this increases a complexity.
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.
Correct, better to get rid of nested conditions.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This is much like to what I did in getItemRecrods
: lines 544-551. Maybe that place can reuse this?
Quality Gate passedIssues Measures |
Purpose
[MODORDERS-1114] Enhance bind-pieces endpoint with flag to transfer circulation requests
Approach