diff --git a/ramls/edge-patron.raml b/ramls/edge-patron.raml index a105e82..6973136 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 b2c506d..daab13f 100644 --- a/src/main/java/org/folio/edge/patron/MainVerticle.java +++ b/src/main/java/org/folio/edge/patron/MainVerticle.java @@ -69,7 +69,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 7ac418a..4c4c362 100644 --- a/src/main/java/org/folio/edge/patron/PatronHandler.java +++ b/src/main/java/org/folio/edge/patron/PatronHandler.java @@ -219,17 +219,29 @@ 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[] {}, - (client, params) -> ((PatronOkapiClient) client).getAllowedServicePoints( + (client, params) -> ((PatronOkapiClient) client).getAllowedServicePointsForInstance( params.get(PARAM_PATRON_ID), params.get(PARAM_INSTANCE_ID), resp -> handleProxyResponse(ctx, resp), 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).getAllowedServicePointsForItem( + params.get(PARAM_PATRON_ID), + params.get(PARAM_ITEM_ID), + resp -> handleProxyResponse(ctx, resp), + t -> handleProxyException(ctx, t))); + } + public void handleGetPatronRegistrationStatus(RoutingContext ctx) { logger.debug("handleGetPatronRegistrationStatus:: Fetching patron registration"); String emailId = ctx.request().getParam(PARAM_EMAIL_ID); 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 a6ef365..fccd922 100644 --- a/src/main/java/org/folio/edge/patron/utils/PatronOkapiClient.java +++ b/src/main/java/org/folio/edge/patron/utils/PatronOkapiClient.java @@ -155,13 +155,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) { diff --git a/src/test/java/org/folio/edge/patron/MainVerticleTest.java b/src/test/java/org/folio/edge/patron/MainVerticleTest.java index b73029a..9eaadaa 100644 --- a/src/test/java/org/folio/edge/patron/MainVerticleTest.java +++ b/src/test/java/org/folio/edge/patron/MainVerticleTest.java @@ -53,6 +53,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; @@ -1276,9 +1277,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, itemId_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 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 7fd7780..7f0e4af 100644 --- a/src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java +++ b/src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java @@ -148,7 +148,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); @@ -516,7 +520,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); @@ -538,6 +542,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);