From 5b4f4bcbf8855309185e6942b1bec94cdc721b1a Mon Sep 17 00:00:00 2001 From: Roman_Barannyk Date: Thu, 11 Apr 2024 16:37:21 +0300 Subject: [PATCH] CIRC-2051 add ecsRequestRouting to allowed-service-points --- descriptors/ModuleDescriptor-template.json | 2 +- ramls/circulation.raml | 4 + .../domain/AllowedServicePointsRequest.java | 1 + .../storage/ServicePointRepository.java | 16 +-- .../AllowedServicePointsResource.java | 10 +- .../services/AllowedServicePointsService.java | 51 ++++++---- .../AllowedServicePointsAPITests.java | 99 ++++++++++++++----- .../LoanDueDatesAfterRecallTests.java | 2 +- .../support/builders/ServicePointBuilder.java | 53 +++++++--- .../fixtures/ServicePointExamples.java | 8 ++ .../fixtures/ServicePointsFixture.java | 6 ++ 11 files changed, 184 insertions(+), 68 deletions(-) diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index edf565551e..d82a62abae 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -649,7 +649,7 @@ }, { "id": "allowed-service-points", - "version": "1.1", + "version": "1.2", "handlers": [ { "methods": [ diff --git a/ramls/circulation.raml b/ramls/circulation.raml index dca970e8e4..1b527ed222 100644 --- a/ramls/circulation.raml +++ b/ramls/circulation.raml @@ -347,6 +347,10 @@ resourceTypes: description: "When true, allows to apply circulation rules based on patron group only" type: boolean required: false + ecsRequestRouting: + description: "When true, returns only service points with ecsRequestRouting" + type: boolean + required: false responses: 200: description: "List of allowed service points was retrieved successfully" diff --git a/src/main/java/org/folio/circulation/domain/AllowedServicePointsRequest.java b/src/main/java/org/folio/circulation/domain/AllowedServicePointsRequest.java index 1f2a13854c..16ea46f1ea 100644 --- a/src/main/java/org/folio/circulation/domain/AllowedServicePointsRequest.java +++ b/src/main/java/org/folio/circulation/domain/AllowedServicePointsRequest.java @@ -21,6 +21,7 @@ public class AllowedServicePointsRequest { private String itemId; private String requestId; private boolean useStubItem; + private boolean ecsRequestRouting; public boolean isForTitleLevelRequest() { return instanceId != null; diff --git a/src/main/java/org/folio/circulation/infrastructure/storage/ServicePointRepository.java b/src/main/java/org/folio/circulation/infrastructure/storage/ServicePointRepository.java index fe9ec5c7e1..c7533cd1fc 100644 --- a/src/main/java/org/folio/circulation/infrastructure/storage/ServicePointRepository.java +++ b/src/main/java/org/folio/circulation/infrastructure/storage/ServicePointRepository.java @@ -206,22 +206,24 @@ public CompletableFuture>> findServicePointsById .thenApply(r -> r.map(MultipleRecords::getRecords)); } - public CompletableFuture>> fetchPickupLocationServicePoints() { + public CompletableFuture>> fetchServicePointsByIndexName( + String indexName) { + return createServicePointsFetcher().find(MultipleCqlIndexValuesCriteria.builder() - .indexName("pickupLocation") + .indexName(indexName) .indexOperator(CqlQuery::matchAny) .value("true") .build()) .thenApply(r -> r.map(MultipleRecords::getRecords)); } - public CompletableFuture>> fetchPickupLocationServicePointsByIds( - Set ids) { + public CompletableFuture>> + fetchPickupLocationServicePointsByIdsAndIndexName(Set ids, String indexName) { - log.debug("filterIdsByServicePointsAndPickupLocationExistence:: parameters ids: {}", - () -> collectionAsString(ids)); + log.debug("filterIdsByServicePointsAndPickupLocationExistence:: parameters ids: {}, " + + "indexName: {}", () -> collectionAsString(ids), () -> indexName); - Result pickupLocationQuery = exactMatch("pickupLocation", "true"); + Result pickupLocationQuery = exactMatch(indexName, "true"); return createServicePointsFetcher().findByIdIndexAndQuery(ids, "id", pickupLocationQuery) .thenApply(r -> r.map(MultipleRecords::getRecords)); diff --git a/src/main/java/org/folio/circulation/resources/AllowedServicePointsResource.java b/src/main/java/org/folio/circulation/resources/AllowedServicePointsResource.java index 4b7c9e9f2d..7510dfa111 100644 --- a/src/main/java/org/folio/circulation/resources/AllowedServicePointsResource.java +++ b/src/main/java/org/folio/circulation/resources/AllowedServicePointsResource.java @@ -72,6 +72,7 @@ private static Result buildRequest(RoutingContext r String itemId = queryParams.get("itemId"); String requestId = queryParams.get("requestId"); String useStubItem = queryParams.get("useStubItem"); + String ecsRequestRouting = queryParams.get("ecsRequestRouting"); List errors = new ArrayList<>(); @@ -99,6 +100,13 @@ private static Result buildRequest(RoutingContext r useStubItem); errors.add(String.format("useStubItem is not a valid boolean: %s.", useStubItem)); } + if (ecsRequestRouting != null && !"true".equals(ecsRequestRouting) + && !"false".equals(ecsRequestRouting)) { + + log.warn("validateAllowedServicePointsRequest:: ecsRequestRouting is not a valid boolean: {}", + ecsRequestRouting); + errors.add(String.format("ecsRequestRouting is not a valid boolean: %s.", ecsRequestRouting)); + } // Checking parameter combinations boolean allowedCombinationOfParametersDetected = false; @@ -137,7 +145,7 @@ private static Result buildRequest(RoutingContext r } return succeeded(new AllowedServicePointsRequest(operation, requesterId, instanceId, itemId, - requestId, Boolean.parseBoolean(useStubItem))); + requestId, Boolean.parseBoolean(useStubItem), Boolean.parseBoolean(ecsRequestRouting))); } private static JsonObject toJson(Map> allowedServicePoints) { diff --git a/src/main/java/org/folio/circulation/services/AllowedServicePointsService.java b/src/main/java/org/folio/circulation/services/AllowedServicePointsService.java index 74140f217a..aee2912029 100644 --- a/src/main/java/org/folio/circulation/services/AllowedServicePointsService.java +++ b/src/main/java/org/folio/circulation/services/AllowedServicePointsService.java @@ -145,20 +145,25 @@ private CompletableFuture> fetchUser(AllowedServicePointsRequest re private CompletableFuture>>> getAllowedServicePoints(AllowedServicePointsRequest request, User user, Collection items) { + String indexName = request.isEcsRequestRouting() + ? "ecsRequestRouting" + : "pickupLocation"; if (items.isEmpty() && request.isForTitleLevelRequest()) { log.info("getAllowedServicePoints:: requested instance has no items"); - return getAllowedServicePointsForTitleWithNoItems(request); + return getAllowedServicePointsForTitleWithNoItems(request, indexName); } BiFunction, CompletableFuture>>>> 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,12 +173,12 @@ private CompletableFuture> fetchUser(AllowedServicePointsRequest re } private CompletableFuture>>> - 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"); @@ -181,7 +186,7 @@ private CompletableFuture> fetchUser(AllowedServicePointsRequest re } private CompletableFuture>>> considerTlrSettings( - TlrSettingsConfiguration tlrSettings) { + TlrSettingsConfiguration tlrSettings, String indexName) { if (!tlrSettings.isTitleLevelRequestsFeatureEnabled() || tlrSettings.isTlrHoldShouldFollowCirculationRules()) { @@ -192,7 +197,7 @@ private CompletableFuture>>> 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 refuseIfItemIsNotFound(Item item, AllowedServicePointsReque } private CompletableFuture>>> - extractAllowedServicePointsIgnoringItemStatus(RequestPolicy requestPolicy, Set items) { + extractAllowedServicePointsIgnoringItemStatus(RequestPolicy requestPolicy, Set items, + String indexName) { - return extractAllowedServicePoints(requestPolicy, items, true); + return extractAllowedServicePoints(requestPolicy, items, true, indexName); } private CompletableFuture>>> - extractAllowedServicePointsConsideringItemStatus(RequestPolicy requestPolicy, Set items) { + extractAllowedServicePointsConsideringItemStatus(RequestPolicy requestPolicy, Set items, + String indexName) { - return extractAllowedServicePoints(requestPolicy, items, false); + return extractAllowedServicePoints(requestPolicy, items, false, indexName); } private CompletableFuture>>> extractAllowedServicePoints(RequestPolicy requestPolicy, Set items, - boolean ignoreItemStatus) { + boolean ignoreItemStatus, String indexName) { log.debug("extractAllowedServicePoints:: parameters requestPolicy: {}, items: {}, " + "ignoreItemStatus: {}", requestPolicy, items, ignoreItemStatus); @@ -280,22 +287,22 @@ private Result 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>> fetchServicePoints( List requestTypesAllowedByPolicy, - Map> servicePointsAllowedByPolicy) { + Map> servicePointsAllowedByPolicy, String indexName) { Set 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> groupAllowedServicePointsByRequestType( @@ -359,20 +366,22 @@ private Map> combineAllowedServicePoints( }, () -> new EnumMap<>(RequestType.class))); } - private CompletableFuture>> fetchAllowedServicePoints() { - return servicePointRepository.fetchPickupLocationServicePoints() + private CompletableFuture>> fetchAllowedServicePoints( + String indexName) { + + return servicePointRepository.fetchServicePointsByIndexName(indexName) .thenApply(r -> r.map(servicePoints -> servicePoints.stream() .map(AllowedServicePoint::new) .collect(Collectors.toSet()))); } private CompletableFuture>> fetchPickupLocationServicePointsByIds( - Set ids) { + Set 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) diff --git a/src/test/java/api/requests/AllowedServicePointsAPITests.java b/src/test/java/api/requests/AllowedServicePointsAPITests.java index a8da598cd2..9368e5e10c 100644 --- a/src/test/java/api/requests/AllowedServicePointsAPITests.java +++ b/src/test/java/api/requests/AllowedServicePointsAPITests.java @@ -154,8 +154,8 @@ void shouldReturnListOfAllowedServicePointsForRequest(RequestType requestType, .collect(Collectors.toSet())); var response = requestLevel == TITLE - ? get("create", requesterId, instanceId, null, null, null, HttpStatus.SC_OK).getJson() - : get("create", requesterId, null, itemId, null, null, HttpStatus.SC_OK).getJson(); + ? get("create", requesterId, instanceId, null, null, null, null, HttpStatus.SC_OK).getJson() + : get("create", requesterId, null, itemId, null, null, null, HttpStatus.SC_OK).getJson(); assertThat(response, allowedServicePointMatcher(Map.of(requestType, allowedSpInResponse))); } @@ -223,7 +223,7 @@ void shouldReturnListOfAllowedServicePointsForRequestReplacement( var requestId = request == null ? null : request.getId().toString(); var response = - get("replace", null, null, null, requestId, null, HttpStatus.SC_OK).getJson(); + get("replace", null, null, null, requestId, null, null, HttpStatus.SC_OK).getJson(); assertThat(response, allowedServicePointMatcher(Map.of(requestType, allowedSpInResponse))); } @@ -625,7 +625,7 @@ void shouldReturnAllowedServicePointsForAllEnabledRequestTypes() { void getReplaceFailsWhenRequestDoesNotExist() { String requestId = randomId(); Response response = get("replace", null, null, null, requestId, null, - HttpStatus.SC_UNPROCESSABLE_ENTITY); + null, HttpStatus.SC_UNPROCESSABLE_ENTITY); assertThat(response.getJson(), hasErrorWith(hasMessage( String.format("Request with ID %s was not found", requestId)))); } @@ -635,7 +635,7 @@ void getMoveFailsWhenRequestDoesNotExist() { String requestId = randomId(); String itemId = itemsFixture.basedUponNod().getId().toString(); Response response = get("move", null, null, itemId, requestId, null, - HttpStatus.SC_UNPROCESSABLE_ENTITY); + null, HttpStatus.SC_UNPROCESSABLE_ENTITY); assertThat(response.getJson(), hasErrorWith(hasMessage( String.format("Request with ID %s was not found", requestId)))); } @@ -696,58 +696,58 @@ void shouldReturnListOfAllowedServicePointsForRequestMove(RequestLevel requestLe // Valid "move" request var moveResponse = - get("move", null, null, itemToMoveToId, requestId, null, HttpStatus.SC_OK).getJson(); + get("move", null, null, itemToMoveToId, requestId, null, null, HttpStatus.SC_OK).getJson(); assertThat(moveResponse, allowedServicePointMatcher(Map.of(HOLD, List.of(sp2)))); // Invalid "move" requests var invalidMoveResponse1 = get("move", null, null, null, requestId, - null, HttpStatus.SC_BAD_REQUEST); + null, null, HttpStatus.SC_BAD_REQUEST); assertThat(invalidMoveResponse1.getBody(), equalTo("Invalid combination of query parameters")); var invalidMoveResponse2 = get("move", null, null, itemToMoveToId, null, - null, HttpStatus.SC_BAD_REQUEST); + null, null, HttpStatus.SC_BAD_REQUEST); assertThat(invalidMoveResponse2.getBody(), equalTo("Invalid combination of query parameters")); var invalidMoveResponse3 = get("move", null, null, null, null, - null, HttpStatus.SC_BAD_REQUEST); + null, null, HttpStatus.SC_BAD_REQUEST); assertThat(invalidMoveResponse3.getBody(), equalTo("Invalid combination of query parameters")); var invalidMoveResponse4 = get("move", requesterId, null, itemToMoveToId, requestId, - null, HttpStatus.SC_BAD_REQUEST); + null, null, HttpStatus.SC_BAD_REQUEST); assertThat(invalidMoveResponse4.getBody(), equalTo("Invalid combination of query parameters")); var invalidMoveResponse5 = get("move", null, instanceId, itemToMoveToId, requestId, - null, HttpStatus.SC_BAD_REQUEST); + null, null, HttpStatus.SC_BAD_REQUEST); assertThat(invalidMoveResponse5.getBody(), equalTo("Invalid combination of query parameters")); // Valid "replace" request var replaceResponse = - get("replace", null, null, null, requestId, null, HttpStatus.SC_OK).getJson(); + get("replace", null, null, null, requestId, null, null, HttpStatus.SC_OK).getJson(); assertThat(replaceResponse, allowedServicePointMatcher(Map.of(HOLD, List.of(sp2)))); // Invalid "replace" requests var invalidReplaceResponse1 = get("replace", null, null, null, null, - null, HttpStatus.SC_BAD_REQUEST); + null, null, HttpStatus.SC_BAD_REQUEST); assertThat(invalidReplaceResponse1.getBody(), equalTo("Invalid combination of query parameters")); var invalidReplaceResponse2 = get("replace", requesterId, null, null, requestId, - null, HttpStatus.SC_BAD_REQUEST); + null, null, HttpStatus.SC_BAD_REQUEST); assertThat(invalidReplaceResponse2.getBody(), equalTo("Invalid combination of query parameters")); var invalidReplaceResponse3 = get("replace", null, instanceId, null, requestId, - null, HttpStatus.SC_BAD_REQUEST); + null, null, HttpStatus.SC_BAD_REQUEST); assertThat(invalidReplaceResponse3.getBody(), equalTo("Invalid combination of query parameters")); var invalidReplaceResponse4 = get("replace", null, null, requestedItemId, requestId, - null, HttpStatus.SC_BAD_REQUEST); + null, null, HttpStatus.SC_BAD_REQUEST); assertThat(invalidReplaceResponse4.getBody(), equalTo("Invalid combination of query parameters")); var invalidReplaceResponse5 = get("replace", requesterId, instanceId, - requestedItemId, requestId, null, HttpStatus.SC_BAD_REQUEST); + requestedItemId, requestId, null, null, HttpStatus.SC_BAD_REQUEST); assertThat(invalidReplaceResponse5.getBody(), equalTo("Invalid combination of query parameters")); } @@ -766,14 +766,16 @@ void shouldUseStubItemParameterInCirculationRuleMatchingWhenPresent() { circulationRulesFixture.updateCirculationRules(createRules("m " + book + "+ g " + patronGroup, "g " + patronGroup)); - var response = getCreateOp(requesterId, instanceId, null, "true", HttpStatus.SC_OK).getJson(); + var response = getCreateOp(requesterId, instanceId, null, "true", null, HttpStatus.SC_OK) + .getJson(); assertThat(response, hasNoJsonPath(PAGE.getValue())); JsonArray allowedServicePoints = response.getJsonArray(HOLD.getValue()); assertServicePointsMatch(allowedServicePoints, List.of(cd1, cd2, cd4, cd5)); allowedServicePoints = response.getJsonArray(RECALL.getValue()); assertServicePointsMatch(allowedServicePoints, List.of(cd1, cd2, cd4, cd5)); - response = getCreateOp(requesterId, instanceId, null, "false", HttpStatus.SC_OK).getJson(); + response = getCreateOp(requesterId, instanceId, null, "false", null, HttpStatus.SC_OK) + .getJson(); assertThat(response, hasNoJsonPath(HOLD.getValue())); assertThat(response, hasNoJsonPath(RECALL.getValue())); allowedServicePoints = response.getJsonArray(PAGE.getValue()); @@ -785,11 +787,54 @@ void shouldUseStubItemParameterInCirculationRuleMatchingWhenPresent() { allowedServicePoints = response.getJsonArray(PAGE.getValue()); assertServicePointsMatch(allowedServicePoints, List.of(cd1, cd2, cd4, cd5)); - Response errorResponse = getCreateOp(requesterId, instanceId, null, "invalid", + Response errorResponse = getCreateOp(requesterId, instanceId, null, "invalid", null, HttpStatus.SC_BAD_REQUEST); assertThat(errorResponse.getBody(), is("useStubItem is not a valid boolean: invalid.")); } + @Test + void shouldReturnEcsRequestRoutingServicePointsIfEcsRequestRoutingPresent() { + var requesterId = usersFixture.steve().getId().toString(); + var instanceId = itemsFixture.createMultipleItemsForTheSameInstance(2).get(0) + .getInstanceId().toString(); + var cd1 = servicePointsFixture.cd1(); + var cd2 = servicePointsFixture.cd2(); + var cd4 = servicePointsFixture.cd4(); + var cd11 = servicePointsFixture.cd11(); + + final Map> allowedServicePointsInPolicy = new HashMap<>(); + allowedServicePointsInPolicy.put(PAGE, Set.of(cd1.getId(), cd2.getId(), cd11.getId())); + allowedServicePointsInPolicy.put(HOLD, Set.of(cd4.getId(), cd2.getId(), cd11.getId())); + var requestPolicy = requestPoliciesFixture.createRequestPolicyWithAllowedServicePoints( + allowedServicePointsInPolicy, PAGE, HOLD); + policiesActivation.use(PoliciesToActivate.builder().requestPolicy(requestPolicy)); + + var response = getCreateOp(requesterId, instanceId, null, "false", "true", + HttpStatus.SC_OK).getJson(); + JsonArray allowedServicePoints = response.getJsonArray(PAGE.getValue()); + assertServicePointsMatch(allowedServicePoints, List.of(cd11)); + assertThat(response, hasNoJsonPath(HOLD.getValue())); + assertThat(response, hasNoJsonPath(RECALL.getValue())); + + response = getCreateOp(requesterId, instanceId, null, "false", "false", + HttpStatus.SC_OK).getJson(); + allowedServicePoints = response.getJsonArray(PAGE.getValue()); + assertServicePointsMatch(allowedServicePoints, List.of(cd1, cd2)); + assertThat(response, hasNoJsonPath(HOLD.getValue())); + assertThat(response, hasNoJsonPath(RECALL.getValue())); + + response = getCreateOp(requesterId, instanceId, null, "false", null, + HttpStatus.SC_OK).getJson(); + allowedServicePoints = response.getJsonArray(PAGE.getValue()); + assertServicePointsMatch(allowedServicePoints, List.of(cd1, cd2)); + assertThat(response, hasNoJsonPath(HOLD.getValue())); + assertThat(response, hasNoJsonPath(RECALL.getValue())); + + Response errorResponse = getCreateOp(requesterId, instanceId, null, null, "invalid", + HttpStatus.SC_BAD_REQUEST); + assertThat(errorResponse.getBody(), is("ecsRequestRouting is not a valid boolean: invalid.")); + } + private void assertServicePointsMatch(JsonArray response, List expectedServicePoints) { @@ -814,23 +859,24 @@ private void assertServicePointsMatch(JsonArray response, } private Response getCreateOp(String requesterId, String instanceId, String itemId, - String useStubItem, int expectedStatusCode) { + String useStubItem, String ecsRequestRouting, int expectedStatusCode) { - return get("create", requesterId, instanceId, itemId, null, useStubItem, expectedStatusCode); + return get("create", requesterId, instanceId, itemId, null, useStubItem, + ecsRequestRouting, expectedStatusCode); } private Response getCreateOp(String requesterId, String instanceId, String itemId, int expectedStatusCode) { - return get("create", requesterId, instanceId, itemId, null, null, expectedStatusCode); + return get("create", requesterId, instanceId, itemId, null, null, null, expectedStatusCode); } private Response getReplaceOp(String requestId, int expectedStatusCode) { - return get("replace", null, null, null, requestId, null, expectedStatusCode); + return get("replace", null, null, null, requestId, null, null, expectedStatusCode); } private Response get(String operation, String requesterId, String instanceId, String itemId, - String requestId, String useStubItem, int expectedStatusCode) { + String requestId, String useStubItem, String ecsRequestRouting, int expectedStatusCode) { List queryParams = new ArrayList<>(); queryParams.add(namedParameter("operation", operation)); @@ -849,6 +895,9 @@ private Response get(String operation, String requesterId, String instanceId, St if (useStubItem != null) { queryParams.add(namedParameter("useStubItem", useStubItem)); } + if (ecsRequestRouting != null) { + queryParams.add(namedParameter("ecsRequestRouting", ecsRequestRouting)); + } return restAssuredClient.get(allowedServicePointsUrl(), queryParams, expectedStatusCode, "allowed-service-points"); diff --git a/src/test/java/api/requests/scenarios/LoanDueDatesAfterRecallTests.java b/src/test/java/api/requests/scenarios/LoanDueDatesAfterRecallTests.java index e038b56595..eeaf801853 100644 --- a/src/test/java/api/requests/scenarios/LoanDueDatesAfterRecallTests.java +++ b/src/test/java/api/requests/scenarios/LoanDueDatesAfterRecallTests.java @@ -285,7 +285,7 @@ void recallRequestWithMGDAndRDValuesChangesDueDateToMGDWithCLDDM() { setFallbackPolicies(canCirculateRollingPolicy); - servicePointsFixture.create(new ServicePointBuilder(checkOutServicePointId, "CLDDM Desk", "clddm", "CLDDM Desk Test", null, null, TRUE, null, null)); + servicePointsFixture.create(new ServicePointBuilder(checkOutServicePointId, "CLDDM Desk", "clddm", "CLDDM Desk Test", null, null, TRUE, null, null, null)); // We use the loan date to calculate the minimum guaranteed due date (MGD) final ZonedDateTime loanDate = diff --git a/src/test/java/api/support/builders/ServicePointBuilder.java b/src/test/java/api/support/builders/ServicePointBuilder.java index e2fb90ec3f..480f354a67 100644 --- a/src/test/java/api/support/builders/ServicePointBuilder.java +++ b/src/test/java/api/support/builders/ServicePointBuilder.java @@ -18,6 +18,7 @@ public class ServicePointBuilder extends JsonBuilder implements Builder { private final JsonObject holdShelfExpiryPeriod; private final String holdShelfClosedLibraryDateManagement; + private final Boolean ecsRequestRouting; public ServicePointBuilder( UUID id, @@ -28,7 +29,8 @@ public ServicePointBuilder( Integer shelvingLagTime, Boolean pickupLocation, JsonObject holdShelfExpiryPeriod, - String holdShelfClosedLibraryDateManagement) { + String holdShelfClosedLibraryDateManagement, + Boolean ecsRequestRouting) { this.id = id; this.name = name; this.code = code; @@ -38,6 +40,7 @@ public ServicePointBuilder( this.pickupLocation = pickupLocation; this.holdShelfExpiryPeriod = holdShelfExpiryPeriod; this.holdShelfClosedLibraryDateManagement = holdShelfClosedLibraryDateManagement; + this.ecsRequestRouting = ecsRequestRouting; } public ServicePointBuilder(String name, String code, String discoveryDisplayName) { @@ -50,6 +53,7 @@ public ServicePointBuilder(String name, String code, String discoveryDisplayName null, false, null, + null, null); } @@ -64,8 +68,9 @@ public static ServicePointBuilder from(IndividualResource response) { getIntegerProperty(representation, "shelvingLagTime", null), getBooleanProperty(representation, "pickupLocation"), getObjectProperty(representation, "holdShelfExpiryPeriod"), - getProperty(representation, "holdShelfClosedLibraryDateManagement") - ); + getProperty(representation, "holdShelfClosedLibraryDateManagement"), + getBooleanProperty(representation, "ecsRequestRouting") + ); } @Override @@ -80,6 +85,7 @@ public JsonObject create() { put(servicePoint, "pickupLocation", this.pickupLocation); put(servicePoint, "holdShelfExpiryPeriod", this.holdShelfExpiryPeriod); put(servicePoint, "holdShelfClosedLibraryDateManagement", this.holdShelfClosedLibraryDateManagement); + put(servicePoint, "ecsRequestRouting", this.ecsRequestRouting); return servicePoint; } @@ -94,7 +100,8 @@ public ServicePointBuilder withId(UUID newId) { this.shelvingLagTime, this.pickupLocation, this.holdShelfExpiryPeriod, - this.holdShelfClosedLibraryDateManagement); + this.holdShelfClosedLibraryDateManagement, + this.ecsRequestRouting); } public ServicePointBuilder withName(String newName) { @@ -107,7 +114,8 @@ public ServicePointBuilder withName(String newName) { this.shelvingLagTime, this.pickupLocation, this.holdShelfExpiryPeriod, - this.holdShelfClosedLibraryDateManagement); + this.holdShelfClosedLibraryDateManagement, + this.ecsRequestRouting); } public ServicePointBuilder withCode(String newCode) { @@ -120,7 +128,8 @@ public ServicePointBuilder withCode(String newCode) { this.shelvingLagTime, this.pickupLocation, this.holdShelfExpiryPeriod, - this.holdShelfClosedLibraryDateManagement); + this.holdShelfClosedLibraryDateManagement, + this.ecsRequestRouting); } public ServicePointBuilder withDiscoveryDisplayName(String newDiscoveryDisplayName) { @@ -133,7 +142,8 @@ public ServicePointBuilder withDiscoveryDisplayName(String newDiscoveryDisplayNa this.shelvingLagTime, this.pickupLocation, this.holdShelfExpiryPeriod, - this.holdShelfClosedLibraryDateManagement); + this.holdShelfClosedLibraryDateManagement, + this.ecsRequestRouting); } public ServicePointBuilder withDescription(String newDescription) { @@ -146,7 +156,8 @@ public ServicePointBuilder withDescription(String newDescription) { this.shelvingLagTime, this.pickupLocation, this.holdShelfExpiryPeriod, - this.holdShelfClosedLibraryDateManagement); + this.holdShelfClosedLibraryDateManagement, + this.ecsRequestRouting); } public ServicePointBuilder withShelvingLagTime(Integer newShelvingLagTime) { @@ -159,7 +170,8 @@ public ServicePointBuilder withShelvingLagTime(Integer newShelvingLagTime) { newShelvingLagTime, this.pickupLocation, this.holdShelfExpiryPeriod, - this.holdShelfClosedLibraryDateManagement); + this.holdShelfClosedLibraryDateManagement, + this.ecsRequestRouting); } public ServicePointBuilder withPickupLocation(Boolean newPickupLocation) { @@ -172,7 +184,8 @@ public ServicePointBuilder withPickupLocation(Boolean newPickupLocation) { this.shelvingLagTime, newPickupLocation, this.holdShelfExpiryPeriod, - this.holdShelfClosedLibraryDateManagement); + this.holdShelfClosedLibraryDateManagement, + this.ecsRequestRouting); } public ServicePointBuilder withHoldShelfExpriyPeriod(int duration, String intervalId) { @@ -190,7 +203,8 @@ public ServicePointBuilder withHoldShelfExpriyPeriod(int duration, String interv this.shelvingLagTime, this.pickupLocation, holdShelfExpiryPeriod, - this.holdShelfClosedLibraryDateManagement); + this.holdShelfClosedLibraryDateManagement, + this.ecsRequestRouting); } public ServicePointBuilder withholdShelfClosedLibraryDateManagement(String expirationDateManagement) { @@ -203,6 +217,21 @@ public ServicePointBuilder withholdShelfClosedLibraryDateManagement(String expir this.shelvingLagTime, this.pickupLocation, this.holdShelfExpiryPeriod, - expirationDateManagement); + expirationDateManagement, + this.ecsRequestRouting); + } + + public ServicePointBuilder withEcsRequestRouting(Boolean ecsRequestRouting) { + return new ServicePointBuilder( + this.id, + this.name, + this.code, + this.discoveryDisplayName, + this.description, + this.shelvingLagTime, + this.pickupLocation, + this.holdShelfExpiryPeriod, + this.holdShelfClosedLibraryDateManagement, + ecsRequestRouting); } } diff --git a/src/test/java/api/support/fixtures/ServicePointExamples.java b/src/test/java/api/support/fixtures/ServicePointExamples.java index 05dc048a41..3267a39341 100644 --- a/src/test/java/api/support/fixtures/ServicePointExamples.java +++ b/src/test/java/api/support/fixtures/ServicePointExamples.java @@ -79,4 +79,12 @@ static ServicePointBuilder basedUponCircDesk10() { .withholdShelfClosedLibraryDateManagement(ExpirationDateManagement.MOVE_TO_THE_END_OF_THE_NEXT_OPEN_DAY.name()) .withHoldShelfExpriyPeriod(6, "Months"); } + + static ServicePointBuilder basedUponCircDesk11() { + return new ServicePointBuilder("Circ Desk 11", "cd11", + "Circulation Desk -- Back Entrance") + .withPickupLocation(FALSE) + .withEcsRequestRouting(TRUE) + .withHoldShelfExpriyPeriod(6, "Months"); + } } diff --git a/src/test/java/api/support/fixtures/ServicePointsFixture.java b/src/test/java/api/support/fixtures/ServicePointsFixture.java index aaf734c60f..cc4fb0fce1 100644 --- a/src/test/java/api/support/fixtures/ServicePointsFixture.java +++ b/src/test/java/api/support/fixtures/ServicePointsFixture.java @@ -2,6 +2,7 @@ import static api.support.fixtures.ServicePointExamples.basedUponCircDesk1; import static api.support.fixtures.ServicePointExamples.basedUponCircDesk10; +import static api.support.fixtures.ServicePointExamples.basedUponCircDesk11; import static api.support.fixtures.ServicePointExamples.basedUponCircDesk2; import static api.support.fixtures.ServicePointExamples.basedUponCircDesk3; import static api.support.fixtures.ServicePointExamples.basedUponCircDesk4; @@ -81,6 +82,11 @@ public IndividualResource cd10() { return create(basedUponCircDesk10()); } + public IndividualResource cd11() { + + return create(basedUponCircDesk11()); + } + public IndividualResource create(ServicePointBuilder builder) { return servicePointRecordCreator.createIfAbsent(builder);