Skip to content
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

Merged
merged 14 commits into from May 16, 2024

Conversation

Saba-Zedginidze-EPAM
Copy link
Contributor

@Saba-Zedginidze-EPAM Saba-Zedginidze-EPAM commented May 10, 2024

Purpose

[MODORDERS-1114] Enhance bind-pieces endpoint with flag to transfer circulation requests

Approach

  • Add enum TransferRequests field to determine in case of outstanding requests for item to transfer these or do nothing
  • Support binding of pieces with items in different tenants

@Saba-Zedginidze-EPAM Saba-Zedginidze-EPAM force-pushed the MODORDERS-1114 branch 2 times, most recently from 35b352a to 39d8e77 Compare May 14, 2024 08:55
@Saba-Zedginidze-EPAM Saba-Zedginidze-EPAM requested a review from a team May 14, 2024 13:35
Map<String, Piece> processedPiecesForPoLine = StreamEx
.of(piecesGroupedByPoLine.getOrDefault(poLineId, Collections.emptyList()))
.toMap(Piece::getId, piece -> piece);
Map<String, Piece> processedPiecesForPoLine = getProcessedPiecesForPoLine(poLineId, piecesGroupedByPoLine);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.toMap(Piece::getId, piece -> piece);
}

protected Map<String, Integer> getEmptyResultCounts() {
Copy link
Contributor

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
    );

Copy link
Contributor Author

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()

Copy link
Contributor

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>?

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This group of 4 methods are misplaced in "Errors" section. Please check comments after dashes in this class:
image
Actually this class is already big and hard to manage. We can easily move new methods to corresponding classes but maybe this type of refactoring increases the scope a bit.

Copy link
Contributor Author

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)) {
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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?

Copy link

sonarcloud bot commented May 16, 2024

@Saba-Zedginidze-EPAM Saba-Zedginidze-EPAM merged commit f285901 into master May 16, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants