Skip to content

Commit

Permalink
CIRC-2109 Pass additional includeRoutingServicePoints parameter when …
Browse files Browse the repository at this point in the history
…needed (#1478)

* CIRC-2109 Initial implementation

* CIRC-2109 Apply suggestions from code review

Co-authored-by: Roman Barannyk <[email protected]>

* CIRC-2109 Support for fake routing service points

* CIRC-2109 Remove unneeded method

* CIRC-2109 Add Override annotation

* CIRC-2109 Apply suggestions from code review

Co-authored-by: Roman Barannyk <[email protected]>

* CIRC-2019 Update src/test/java/api/support/fakes/FakeCQLToJSONInterpreter.java

Co-authored-by: Roman Barannyk <[email protected]>

* CIRC-2109 Fix github suggestion commit

* CIRC-2109 Code review 1

* CIRC-2109 Revert FakeStorageModuleBuilder

---------

Co-authored-by: Roman Barannyk <[email protected]>
  • Loading branch information
alexanderkurash and roman-barannyk authored Jul 3, 2024
1 parent 5cff758 commit ea17564
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ public class ServicePointRepository {
private final CollectionResourceClient servicePointsStorageClient;

public ServicePointRepository(Clients clients) {
servicePointsStorageClient = clients.servicePointsStorage();
this(clients, false);
}

public ServicePointRepository(Clients clients, boolean includeRoutingServicePoints) {
if (includeRoutingServicePoints) {
servicePointsStorageClient = clients.routingServicePointsStorage();
} else {
servicePointsStorageClient = clients.servicePointsStorage();
}
}

public CompletableFuture<Result<ServicePoint>> getServicePointById(UUID id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public AllowedServicePointsService(Clients clients, boolean isEcsRequestRouting)
userRepository = new UserRepository(clients);
requestRepository = new RequestRepository(clients);
requestPolicyRepository = new RequestPolicyRepository(clients);
servicePointRepository = new ServicePointRepository(clients);
servicePointRepository = new ServicePointRepository(clients, isEcsRequestRouting);
settingsRepository = new SettingsRepository(clients);
instanceRepository = new InstanceRepository(clients);
itemFinder = new ItemByInstanceIdFinder(clients.holdingsStorage(), itemRepository);
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/org/folio/circulation/support/Clients.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import org.folio.circulation.rules.CirculationRulesProcessor;
import org.folio.circulation.services.PubSubPublishingService;
import org.folio.circulation.support.http.client.IncludeRoutingServicePoints;
import org.folio.circulation.support.http.client.OkapiHttpClient;
import org.folio.circulation.support.http.client.QueryParameter;
import org.folio.circulation.support.http.server.WebContext;

import io.vertx.core.http.HttpClient;
Expand Down Expand Up @@ -40,6 +42,7 @@ public class Clients {
private final CollectionResourceClient circulationRulesStorageClient;
private final CollectionResourceClient requestPoliciesStorageClient;
private final CollectionResourceClient servicePointsStorageClient;
private final CollectionResourceClient routingServicePointsStorageClient;
private final CollectionResourceClient calendarStorageClient;
private final CollectionResourceClient patronGroupsStorageClient;
private final CollectionResourceClient patronNoticePolicesStorageClient;
Expand Down Expand Up @@ -113,6 +116,8 @@ private Clients(OkapiHttpClient client, WebContext context) {
requestPoliciesStorageClient = createRequestPoliciesStorageClient(client, context);
fixedDueDateSchedulesStorageClient = createFixedDueDateSchedulesStorageClient(client, context);
servicePointsStorageClient = createServicePointsStorageClient(client, context);
routingServicePointsStorageClient = createServicePointsStorageWithCustomParam(client,
context, IncludeRoutingServicePoints.enabled());
patronGroupsStorageClient = createPatronGroupsStorageClient(client, context);
calendarStorageClient = createCalendarStorageClient(client, context);
patronNoticePolicesStorageClient = createPatronNoticePolicesStorageClient(client, context);
Expand Down Expand Up @@ -246,6 +251,10 @@ public CollectionResourceClient servicePointsStorage() {
return servicePointsStorageClient;
}

public CollectionResourceClient routingServicePointsStorage() {
return routingServicePointsStorageClient;
}

public CollectionResourceClient patronGroupsStorage() {
return patronGroupsStorageClient;
}
Expand Down Expand Up @@ -398,6 +407,14 @@ private static CollectionResourceClient getCollectionResourceClient(
return new CollectionResourceClient(client, context.getOkapiBasedUrl(path));
}

private static CollectionResourceClient getCollectionResourceClientWithCustomParam(
OkapiHttpClient client, WebContext context, String path, QueryParameter customParam)
throws MalformedURLException {

return new CustomParamCollectionResourceClient(client, context.getOkapiBasedUrl(path),
customParam);
}

public CollectionResourceClient noticeTemplatesClient() {
return noticeTemplatesClient;
}
Expand Down Expand Up @@ -640,6 +657,14 @@ private CollectionResourceClient createServicePointsStorageClient(
return getCollectionResourceClient(client, context, "/service-points");
}

private CollectionResourceClient createServicePointsStorageWithCustomParam(
OkapiHttpClient client, WebContext context, QueryParameter customParam)
throws MalformedURLException {

return getCollectionResourceClientWithCustomParam(client, context, "/service-points",
customParam);
}

private CollectionResourceClient createPatronGroupsStorageClient(
OkapiHttpClient client, WebContext context)
throws MalformedURLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import io.vertx.core.json.JsonObject;

public class CollectionResourceClient implements GetManyRecordsClient {
private final OkapiHttpClient client;
private final URL collectionRoot;
final OkapiHttpClient client;
final URL collectionRoot;

public CollectionResourceClient(OkapiHttpClient client, URL collectionRoot) {
this.collectionRoot = collectionRoot;
Expand Down Expand Up @@ -109,7 +109,7 @@ public CompletableFuture<Result<Response>> getMany(CqlQuery cqlQuery,
return client.get(collectionRoot, cqlQuery, pageLimit, offset);
}

private String individualRecordUrl(String id) {
String individualRecordUrl(String id) {
return format("%s/%s", collectionRoot, id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.folio.circulation.support;

import java.net.URL;
import java.util.concurrent.CompletableFuture;

import org.folio.circulation.support.http.client.CqlQuery;
import org.folio.circulation.support.http.client.Offset;
import org.folio.circulation.support.http.client.OkapiHttpClient;
import org.folio.circulation.support.http.client.PageLimit;
import org.folio.circulation.support.http.client.QueryParameter;
import org.folio.circulation.support.http.client.Response;
import org.folio.circulation.support.results.Result;

public class CustomParamCollectionResourceClient extends CollectionResourceClient {

private QueryParameter customQueryParameter;

public CustomParamCollectionResourceClient(OkapiHttpClient client, URL collectionRoot,
QueryParameter customQueryParameter) {

super(client, collectionRoot);
this.customQueryParameter = customQueryParameter;
}

@Override
public CompletableFuture<Result<Response>> get() {
return client.get(collectionRoot.toString(), customQueryParameter);
}

@Override
public CompletableFuture<Result<Response>> get(PageLimit pageLimit) {
return client.get(collectionRoot, pageLimit, customQueryParameter);
}

@Override
public CompletableFuture<Result<Response>> get(String id) {
return client.get(individualRecordUrl(id), customQueryParameter);
}

@Override
public CompletableFuture<Result<Response>> getMany(CqlQuery cqlQuery,
PageLimit pageLimit, Offset offset) {

return client.get(collectionRoot, cqlQuery, pageLimit, offset, customQueryParameter);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.folio.circulation.support.http.client;

import static java.lang.String.format;

public class IncludeRoutingServicePoints implements QueryParameter {

private static final String PARAM_NAME = "includeRoutingServicePoints";
private final Boolean value;

public static IncludeRoutingServicePoints enabled() {
return new IncludeRoutingServicePoints(true);
}

private IncludeRoutingServicePoints(Boolean value) {
this.value = value;
}

@Override
public void consume(QueryStringParameterConsumer consumer) {
if (value != null) {
consumer.consume(PARAM_NAME, value.toString());
}
}

@Override
public String toString() {
if (value == null) {
return format("No %s", PARAM_NAME);
}

return format("%s = \"%s\"", PARAM_NAME, value);
}
}
21 changes: 21 additions & 0 deletions src/test/java/api/support/fakes/FakeCQLToJSONInterpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,34 @@
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.folio.circulation.support.http.server.WebContext;

import io.vertx.core.json.JsonObject;

public class FakeCQLToJSONInterpreter {
private static final Logger log = LogManager.getLogger(MethodHandles.lookup().lookupClass());

public List<JsonObject> execute(Collection<JsonObject> records, String query,
WebContext context) {

var initiallyFilteredRecords = execute(records, query);

// Routing SP filtering
String includeRoutingServicePointsParam = context.getStringParameter(
"includeRoutingServicePoints");
if (Boolean.parseBoolean(includeRoutingServicePointsParam)) {
return records.stream()
.filter(json -> json.containsKey("ecsRequestRouting")
? json.getBoolean("ecsRequestRouting")
: false)
.toList();
}

return initiallyFilteredRecords;
}

public List<JsonObject> execute(Collection<JsonObject> records, String query) {

final var queryAndSort = splitQueryAndSort(query);
final var cqlPredicate = new CqlPredicate(queryAndSort.left);

Expand Down
5 changes: 3 additions & 2 deletions src/test/java/api/support/fakes/FakeOkapi.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import java.util.Objects;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.folio.circulation.support.ValidationErrorFailure;
import org.folio.circulation.support.http.client.OkapiHttpClient;
import org.folio.circulation.support.results.Result;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;
Expand Down Expand Up @@ -282,6 +282,7 @@ public void start(Promise<Void> startFuture) throws IOException {
.withRootPath("/service-points")
.withRequiredProperties("name", "code", "discoveryDisplayName")
.withUniqueProperties("name")
.withQueryParameters("includeRoutingServicePoints")
.withChangeMetadata()
.disallowCollectionDelete()
.create()
Expand Down
10 changes: 7 additions & 3 deletions src/test/java/api/support/fakes/FakeStorageModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ private void getMany(RoutingContext routingContext) {

Map<String, JsonObject> resourcesForTenant = getResourcesForTenant(context);

List<JsonObject> filteredItems = new FakeCQLToJSONInterpreter()
.execute(resourcesForTenant.values(), query);
List<JsonObject> filteredItems = getFakeCQLToJSONInterpreter()
.execute(resourcesForTenant.values(), query, context);

List<JsonObject> pagedItems = filteredItems.stream()
.skip(offset)
Expand Down Expand Up @@ -408,6 +408,10 @@ private void getMany(RoutingContext routingContext) {
response.end();
}

FakeCQLToJSONInterpreter getFakeCQLToJSONInterpreter() {
return new FakeCQLToJSONInterpreter();
}

private void empty(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);

Expand All @@ -430,7 +434,7 @@ private void deleteMany(RoutingContext routingContext) {

Map<String, JsonObject> resourcesForTenant = getResourcesForTenant(context);

new FakeCQLToJSONInterpreter()
getFakeCQLToJSONInterpreter()
.execute(resourcesForTenant.values(), query)
.forEach(item -> resourcesForTenant.remove(item.getString("id")));

Expand Down

0 comments on commit ea17564

Please sign in to comment.