-
Notifications
You must be signed in to change notification settings - Fork 25
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
CIRC-2051 Add ecsRequestRouting parameter to allowed-service-points #1451
Open
roman-barannyk
wants to merge
9
commits into
master
Choose a base branch
from
CIRC-2051
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5b4f4bc
CIRC-2051 add ecsRequestRouting to allowed-service-points
roman-barannyk a65768b
Merge branch 'master' into CIRC-2051
roman-barannyk 6f5c6b1
CIRC-2051 refactoring
roman-barannyk c6ab23f
Merge remote-tracking branch 'origin/CIRC-2051' into CIRC-2051
roman-barannyk 5482316
CIRC-2051 move common validation to separate method
roman-barannyk 818fd01
CIRC-2051 fix code smells
roman-barannyk a0a634f
CIRC-2051 fix code smell
roman-barannyk 4f2f1ec
CIRC-2051 tests refactoring
roman-barannyk b67fbb5
CIRC-2051 rename test
roman-barannyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,20 +145,25 @@ private CompletableFuture<Result<User>> fetchUser(AllowedServicePointsRequest re | |
private CompletableFuture<Result<Map<RequestType, Set<AllowedServicePoint>>>> | ||
getAllowedServicePoints(AllowedServicePointsRequest request, User user, Collection<Item> items) { | ||
|
||
String indexName = request.isEcsRequestRouting() | ||
? "ecsRequestRouting" | ||
: "pickupLocation"; | ||
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. So we are now searching either by |
||
if (items.isEmpty() && request.isForTitleLevelRequest()) { | ||
log.info("getAllowedServicePoints:: requested instance has no items"); | ||
return getAllowedServicePointsForTitleWithNoItems(request); | ||
return getAllowedServicePointsForTitleWithNoItems(request, indexName); | ||
} | ||
|
||
BiFunction<RequestPolicy, Set<Item>, CompletableFuture<Result<Map<RequestType, | ||
Set<AllowedServicePoint>>>>> mappingFunction = request.isImplyingItemStatusIgnore() | ||
? this::extractAllowedServicePointsIgnoringItemStatus | ||
: this::extractAllowedServicePointsConsideringItemStatus; | ||
? (requestPolicy, itemsSet) -> extractAllowedServicePointsIgnoringItemStatus( | ||
requestPolicy, itemsSet, indexName) | ||
: (requestPolicy, itemsSet) -> extractAllowedServicePointsConsideringItemStatus( | ||
requestPolicy, itemsSet, indexName); | ||
|
||
if (request.isUseStubItem()) { | ||
return requestPolicyRepository.lookupRequestPolicy(user) | ||
.thenCompose(r -> r.after(policy -> extractAllowedServicePointsIgnoringItemStatus( | ||
policy, new HashSet<>()))); | ||
policy, new HashSet<>(), indexName))); | ||
} | ||
|
||
return requestPolicyRepository.lookupRequestPolicies(items, user) | ||
|
@@ -168,20 +173,20 @@ private CompletableFuture<Result<User>> fetchUser(AllowedServicePointsRequest re | |
} | ||
|
||
private CompletableFuture<Result<Map<RequestType, Set<AllowedServicePoint>>>> | ||
getAllowedServicePointsForTitleWithNoItems(AllowedServicePointsRequest request) { | ||
getAllowedServicePointsForTitleWithNoItems(AllowedServicePointsRequest request, String indexName) { | ||
|
||
if (request.isForTitleLevelRequest() && request.getOperation() == CREATE) { | ||
log.info("getAllowedServicePointsForTitleWithNoItems:: checking TLR settings"); | ||
return configurationRepository.lookupTlrSettings() | ||
.thenCompose(r -> r.after(this::considerTlrSettings)); | ||
.thenCompose(r -> r.after(tlrSettings -> considerTlrSettings(tlrSettings, indexName))); | ||
} | ||
|
||
log.info("getAllowedServicePointsForTitleWithNoItems:: no need to check TLR-settings"); | ||
return ofAsync(emptyMap()); | ||
} | ||
|
||
private CompletableFuture<Result<Map<RequestType, Set<AllowedServicePoint>>>> considerTlrSettings( | ||
TlrSettingsConfiguration tlrSettings) { | ||
TlrSettingsConfiguration tlrSettings, String indexName) { | ||
|
||
if (!tlrSettings.isTitleLevelRequestsFeatureEnabled() || | ||
tlrSettings.isTlrHoldShouldFollowCirculationRules()) { | ||
|
@@ -192,7 +197,7 @@ private CompletableFuture<Result<Map<RequestType, Set<AllowedServicePoint>>>> co | |
|
||
log.info("considerTlrSettings:: allowing all pickup locations for Hold"); | ||
|
||
return fetchAllowedServicePoints() | ||
return fetchAllowedServicePoints(indexName) | ||
.thenApply(r -> r.map(sp -> sp.isEmpty() ? emptyMap() : Map.of(HOLD, sp))); | ||
} | ||
|
||
|
@@ -231,20 +236,22 @@ private Result<Item> refuseIfItemIsNotFound(Item item, AllowedServicePointsReque | |
} | ||
|
||
private CompletableFuture<Result<Map<RequestType, Set<AllowedServicePoint>>>> | ||
extractAllowedServicePointsIgnoringItemStatus(RequestPolicy requestPolicy, Set<Item> items) { | ||
extractAllowedServicePointsIgnoringItemStatus(RequestPolicy requestPolicy, Set<Item> items, | ||
String indexName) { | ||
|
||
return extractAllowedServicePoints(requestPolicy, items, true); | ||
return extractAllowedServicePoints(requestPolicy, items, true, indexName); | ||
} | ||
|
||
private CompletableFuture<Result<Map<RequestType, Set<AllowedServicePoint>>>> | ||
extractAllowedServicePointsConsideringItemStatus(RequestPolicy requestPolicy, Set<Item> items) { | ||
extractAllowedServicePointsConsideringItemStatus(RequestPolicy requestPolicy, Set<Item> items, | ||
String indexName) { | ||
|
||
return extractAllowedServicePoints(requestPolicy, items, false); | ||
return extractAllowedServicePoints(requestPolicy, items, false, indexName); | ||
} | ||
|
||
private CompletableFuture<Result<Map<RequestType, Set<AllowedServicePoint>>>> | ||
extractAllowedServicePoints(RequestPolicy requestPolicy, Set<Item> items, | ||
boolean ignoreItemStatus) { | ||
boolean ignoreItemStatus, String indexName) { | ||
|
||
log.debug("extractAllowedServicePoints:: parameters requestPolicy: {}, items: {}, " + | ||
"ignoreItemStatus: {}", requestPolicy, items, ignoreItemStatus); | ||
|
@@ -280,22 +287,22 @@ private Result<Item> refuseIfItemIsNotFound(Item item, AllowedServicePointsReque | |
.collect(Collectors.toCollection(ArrayList::new)); // collect into a mutable list | ||
|
||
// TODO: fetch service points on a later stage, we only need IDs here | ||
return fetchServicePoints(requestTypesAllowedByPolicy, servicePointAllowedByPolicy) | ||
return fetchServicePoints(requestTypesAllowedByPolicy, servicePointAllowedByPolicy, indexName) | ||
.thenApply(r -> r.map(servicePoints -> groupAllowedServicePointsByRequestType( | ||
requestTypesAllowedByPolicyAndStatus, servicePoints, servicePointAllowedByPolicy))); | ||
} | ||
|
||
private CompletableFuture<Result<Set<AllowedServicePoint>>> fetchServicePoints( | ||
List<RequestType> requestTypesAllowedByPolicy, | ||
Map<RequestType, Set<String>> servicePointsAllowedByPolicy) { | ||
Map<RequestType, Set<String>> servicePointsAllowedByPolicy, String indexName) { | ||
|
||
Set<String> allowedServicePointsIds = servicePointsAllowedByPolicy.values().stream() | ||
.flatMap(Collection::stream) | ||
.collect(Collectors.toSet()); | ||
|
||
return requestTypesAllowedByPolicy.size() == servicePointsAllowedByPolicy.size() | ||
? fetchPickupLocationServicePointsByIds(allowedServicePointsIds) | ||
: fetchAllowedServicePoints(); | ||
? fetchPickupLocationServicePointsByIds(allowedServicePointsIds, indexName) | ||
: fetchAllowedServicePoints(indexName); | ||
} | ||
|
||
private Map<RequestType, Set<AllowedServicePoint>> groupAllowedServicePointsByRequestType( | ||
|
@@ -359,20 +366,22 @@ private Map<RequestType, Set<AllowedServicePoint>> combineAllowedServicePoints( | |
}, () -> new EnumMap<>(RequestType.class))); | ||
} | ||
|
||
private CompletableFuture<Result<Set<AllowedServicePoint>>> fetchAllowedServicePoints() { | ||
return servicePointRepository.fetchPickupLocationServicePoints() | ||
private CompletableFuture<Result<Set<AllowedServicePoint>>> fetchAllowedServicePoints( | ||
String indexName) { | ||
|
||
return servicePointRepository.fetchServicePointsByIndexName(indexName) | ||
.thenApply(r -> r.map(servicePoints -> servicePoints.stream() | ||
.map(AllowedServicePoint::new) | ||
.collect(Collectors.toSet()))); | ||
} | ||
|
||
private CompletableFuture<Result<Set<AllowedServicePoint>>> fetchPickupLocationServicePointsByIds( | ||
Set<String> ids) { | ||
Set<String> ids, String indexName) { | ||
|
||
log.debug("filterIdsByServicePointsAndPickupLocationExistence:: parameters ids: {}", | ||
() -> collectionAsString(ids)); | ||
|
||
return servicePointRepository.fetchPickupLocationServicePointsByIds(ids) | ||
return servicePointRepository.fetchPickupLocationServicePointsByIdsAndIndexName(ids, indexName) | ||
.thenApply(servicePointsResult -> servicePointsResult | ||
.map(servicePoints -> servicePoints.stream() | ||
.map(AllowedServicePoint::new) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since we are validating boolean string twice now, do you think this check deserves a separate method? Something like
isIvalidBooleanString(String boolean)