From 2cdba7b3ec5a264cec1dc36d075168f563657371 Mon Sep 17 00:00:00 2001 From: vijay-eis Date: Sat, 28 Sep 2024 09:56:29 -0400 Subject: [PATCH 1/4] Add support for getting service points for item --- ramls/edge-patron.raml | 33 +++++++++++++++++++ .../org/folio/edge/patron/MainVerticle.java | 5 ++- .../org/folio/edge/patron/PatronHandler.java | 13 +++++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/ramls/edge-patron.raml b/ramls/edge-patron.raml index 592dd19..eee2ce1 100644 --- a/ramls/edge-patron.raml +++ b/ramls/edge-patron.raml @@ -473,6 +473,39 @@ types: body: text/plain: example: internal server error, contact administrator + /allowed-service-points: + displayName: Allowed service points + description: Service that provides a list of allowed pickup service points + get: + description: | + Returns a list of pickup service points allowed for a particular patron and instance + queryParameters: + apikey: + description: "API Key" + type: string + body: + application/json: + type: allowedServicePoints + example: !include examples/allowed-service-points-response.json + responses: + 200: + description: | + Successfully returns a list of allowed service points + body: + application/json: + type: allowedServicePoints + example: !include examples/allowed-service-points-response.json + 422: + description: Validation error + body: + application/json: + type: errors + 500: + description: | + Internal server error, e.g. due to misconfiguration + body: + text/plain: + example: internal server error, contact administrator /instance: /{instanceId}: uriParameters: diff --git a/src/main/java/org/folio/edge/patron/MainVerticle.java b/src/main/java/org/folio/edge/patron/MainVerticle.java index 8219ef6..6555c67 100644 --- a/src/main/java/org/folio/edge/patron/MainVerticle.java +++ b/src/main/java/org/folio/edge/patron/MainVerticle.java @@ -79,7 +79,10 @@ public Router defineRoutes() { .handler(patronHandler::handlePlaceInstanceHold); router.route(HttpMethod.GET, "/patron/account/:patronId/instance/:instanceId/" + - "allowed-service-points").handler(patronHandler::handleGetAllowedServicePoints); + "allowed-service-points").handler(patronHandler::handleGetAllowedServicePointsForInstance); + + router.route(HttpMethod.GET, "/patron/account/:patronId/item/:itemId/" + + "allowed-service-points").handler(patronHandler::handleGetAllowedServicePointsForItem); router.route(HttpMethod.POST, "/patron/account/:patronId/hold/:holdId/cancel") .handler(patronHandler::handleCancelHold); diff --git a/src/main/java/org/folio/edge/patron/PatronHandler.java b/src/main/java/org/folio/edge/patron/PatronHandler.java index d4c0830..9abcc69 100644 --- a/src/main/java/org/folio/edge/patron/PatronHandler.java +++ b/src/main/java/org/folio/edge/patron/PatronHandler.java @@ -249,7 +249,7 @@ public void handlePlaceInstanceHold(RoutingContext ctx) { t -> handleProxyException(ctx, t))); } - public void handleGetAllowedServicePoints(RoutingContext ctx) { + public void handleGetAllowedServicePointsForInstance(RoutingContext ctx) { handleCommon(ctx, new String[] { PARAM_PATRON_ID, PARAM_INSTANCE_ID }, new String[] {}, @@ -260,6 +260,17 @@ public void handleGetAllowedServicePoints(RoutingContext ctx) { t -> handleProxyException(ctx, t))); } + public void handleGetAllowedServicePointsForItem(RoutingContext ctx) { + handleCommon(ctx, + new String[] { PARAM_PATRON_ID, PARAM_ITEM_ID }, + new String[] {}, + (client, params) -> ((PatronOkapiClient) client).getAllowedServicePoints( + params.get(PARAM_PATRON_ID), + params.get(PARAM_ITEM_ID), + resp -> handleProxyResponse(ctx, resp), + t -> handleProxyException(ctx, t))); + } + @Override protected void invalidApiKey(RoutingContext ctx, String msg) { accessDenied(ctx, msg); From 75aea2f085699cc3c198c642c7c69bc98cc971b1 Mon Sep 17 00:00:00 2001 From: vijay-eis Date: Sat, 28 Sep 2024 12:13:25 -0400 Subject: [PATCH 2/4] Fix endpoint for getting service points for item --- src/main/java/org/folio/edge/patron/PatronHandler.java | 4 ++-- .../org/folio/edge/patron/utils/PatronOkapiClient.java | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/folio/edge/patron/PatronHandler.java b/src/main/java/org/folio/edge/patron/PatronHandler.java index 9abcc69..92e84bc 100644 --- a/src/main/java/org/folio/edge/patron/PatronHandler.java +++ b/src/main/java/org/folio/edge/patron/PatronHandler.java @@ -253,7 +253,7 @@ public void handleGetAllowedServicePointsForInstance(RoutingContext ctx) { handleCommon(ctx, new String[] { PARAM_PATRON_ID, PARAM_INSTANCE_ID }, new String[] {}, - (client, params) -> ((PatronOkapiClient) client).getAllowedServicePoints( + (client, params) -> ((PatronOkapiClient) client).getAllowedServicePointsForInstance( params.get(PARAM_PATRON_ID), params.get(PARAM_INSTANCE_ID), resp -> handleProxyResponse(ctx, resp), @@ -264,7 +264,7 @@ public void handleGetAllowedServicePointsForItem(RoutingContext ctx) { handleCommon(ctx, new String[] { PARAM_PATRON_ID, PARAM_ITEM_ID }, new String[] {}, - (client, params) -> ((PatronOkapiClient) client).getAllowedServicePoints( + (client, params) -> ((PatronOkapiClient) client).getAllowedServicePointsForItem( params.get(PARAM_PATRON_ID), params.get(PARAM_ITEM_ID), resp -> handleProxyResponse(ctx, resp), diff --git a/src/main/java/org/folio/edge/patron/utils/PatronOkapiClient.java b/src/main/java/org/folio/edge/patron/utils/PatronOkapiClient.java index 3472e2a..1ddcaaf 100644 --- a/src/main/java/org/folio/edge/patron/utils/PatronOkapiClient.java +++ b/src/main/java/org/folio/edge/patron/utils/PatronOkapiClient.java @@ -188,13 +188,20 @@ public void cancelHold(String patronId, String holdId, JsonObject holdCancellati ); } - public void getAllowedServicePoints(String patronId, String instanceId, + public void getAllowedServicePointsForInstance(String patronId, String instanceId, Handler> responseHandler, Handler exceptionHandler) { get(String.format("%s/patron/account/%s/instance/%s/allowed-service-points", okapiURL, patronId, instanceId), tenant, null, responseHandler, exceptionHandler); } + public void getAllowedServicePointsForItem(String patronId, String itemId, + Handler> responseHandler, Handler exceptionHandler) { + + get(String.format("%s/patron/account/%s/item/%s/allowed-service-points", okapiURL, + patronId, itemId), tenant, null, responseHandler, exceptionHandler); + } + public void getRequest(String holdId, Handler> responseHandler, Handler exceptionHandler) { From d5142ad27f741153ddaf1d8c76eda0b00c0f2491 Mon Sep 17 00:00:00 2001 From: vijay-eis Date: Mon, 14 Oct 2024 15:51:18 -0400 Subject: [PATCH 3/4] Add test for the new route to get service points for item --- .../folio/edge/patron/MainVerticleTest.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/folio/edge/patron/MainVerticleTest.java b/src/test/java/org/folio/edge/patron/MainVerticleTest.java index aa94411..6a7c388 100644 --- a/src/test/java/org/folio/edge/patron/MainVerticleTest.java +++ b/src/test/java/org/folio/edge/patron/MainVerticleTest.java @@ -1151,9 +1151,28 @@ public void testAllowedServicePointsSuccess(TestContext context) throws Exceptio JsonObject actual = new JsonObject(resp.body().asString()); assertEquals(expected, actual); } + @Test + public void testAllowedServicePointsForItemError(TestContext context) throws Exception { + logger.info("=== Test validation error during allowed service points request ==="); + + final Response resp = RestAssured + .with() + .get(String.format("/patron/account/%s/item/%s/allowed-service-points?apikey=%s", + patronId, instanceId_notFound, apiKey)) + .then() + .statusCode(422) + .header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) + .extract() + .response(); + + JsonObject expected = new JsonObject(readMockFile( + "/allowed_sp_error_edge_patron.json")); + JsonObject actual = new JsonObject(resp.body().asString()); + assertEquals(expected, actual); + } @Test - public void testAllowedServicePointsError(TestContext context) throws Exception { + public void testAllowedServicePointsForInstanceError(TestContext context) throws Exception { logger.info("=== Test validation error during allowed service points request ==="); final Response resp = RestAssured From 0fd12786d55b00cce15b5513e9cd4c83cea59cbb Mon Sep 17 00:00:00 2001 From: vijay-eis Date: Mon, 14 Oct 2024 16:24:12 -0400 Subject: [PATCH 4/4] Fix tests --- .../folio/edge/patron/MainVerticleTest.java | 3 +- .../edge/patron/utils/PatronMockOkapi.java | 30 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/folio/edge/patron/MainVerticleTest.java b/src/test/java/org/folio/edge/patron/MainVerticleTest.java index 6a7c388..8b8ef84 100644 --- a/src/test/java/org/folio/edge/patron/MainVerticleTest.java +++ b/src/test/java/org/folio/edge/patron/MainVerticleTest.java @@ -17,6 +17,7 @@ import static org.folio.edge.patron.utils.PatronMockOkapi.holdReqTs; import static org.folio.edge.patron.utils.PatronMockOkapi.instanceId_notFound; import static org.folio.edge.patron.utils.PatronMockOkapi.invalidHoldCancellationdHoldId; +import static org.folio.edge.patron.utils.PatronMockOkapi.itemId_notFound; import static org.folio.edge.patron.utils.PatronMockOkapi.limit_param; import static org.folio.edge.patron.utils.PatronMockOkapi.malformedHoldCancellationHoldId; import static org.folio.edge.patron.utils.PatronMockOkapi.nonUUIDHoldCanceledByPatronId; @@ -1158,7 +1159,7 @@ public void testAllowedServicePointsForItemError(TestContext context) throws Exc final Response resp = RestAssured .with() .get(String.format("/patron/account/%s/item/%s/allowed-service-points?apikey=%s", - patronId, instanceId_notFound, apiKey)) + patronId, itemId_notFound, apiKey)) .then() .statusCode(422) .header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) diff --git a/src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java b/src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java index f6a660d..fdb19d5 100644 --- a/src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java +++ b/src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java @@ -158,7 +158,11 @@ public Router defineRoutes() { router.route(HttpMethod.GET, "/patron/account/:patronId/instance/:instanceId/allowed-service-points") - .handler(this::getAllowedServicePoints); + .handler(this::getAllowedServicePointsForInstance); + + router.route(HttpMethod.GET, + "/patron/account/:patronId/item/:itemId/allowed-service-points") + .handler(this::getAllowedServicePointsForItem); router.route(HttpMethod.POST, "/patron/account/:patronId/hold/:holdId/cancel") .handler(this::cancelHoldHandler); @@ -497,7 +501,7 @@ public void placeInstanceHoldHandler(RoutingContext ctx) { } } - public void getAllowedServicePoints(RoutingContext ctx) { + public void getAllowedServicePointsForInstance(RoutingContext ctx) { String instanceId = ctx.request().getParam(PARAM_INSTANCE_ID); String token = ctx.request().getHeader(X_OKAPI_TOKEN); @@ -519,6 +523,28 @@ public void getAllowedServicePoints(RoutingContext ctx) { } } + public void getAllowedServicePointsForItem(RoutingContext ctx) { + String itemId = ctx.request().getParam(PARAM_ITEM_ID); + String token = ctx.request().getHeader(X_OKAPI_TOKEN); + + if (token == null || !token.equals(MOCK_TOKEN)) { + ctx.response() + .setStatusCode(403) + .putHeader(HttpHeaders.CONTENT_TYPE, TEXT_PLAIN) + .end("Access requires permission: patron.instance.hold.post"); + } else if (itemId.equals(itemId_notFound)) { + ctx.response() + .setStatusCode(422) + .putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) + .end(readMockFile("/allowed_sp_error_mod_patron.json")); + } else { + ctx.response() + .setStatusCode(200) + .putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) + .end(readMockFile("/allowed_sp_mod_patron_expected_response.json")); + } + } + public static String getPatronJson(String extPatronId) { JsonArray users = new JsonArray(); logger.info(extPatronId_notFound);