Skip to content

Commit

Permalink
EDGEPATRON-148 Add allowed service-point endpoint for item level (#130)
Browse files Browse the repository at this point in the history
* Add support for getting service points for item

* Fix endpoint for getting service points for item

* Add test for the new route to get service points for item

* Fix tests
  • Loading branch information
vijay-eis authored Oct 24, 2024
1 parent 11da78b commit 1495975
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 7 deletions.
33 changes: 33 additions & 0 deletions ramls/edge-patron.raml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/folio/edge/patron/MainVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/org/folio/edge/patron/PatronHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpResponse<Buffer>> responseHandler, Handler<Throwable> 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<HttpResponse<Buffer>> responseHandler, Handler<Throwable> 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<HttpResponse<Buffer>> responseHandler,
Handler<Throwable> exceptionHandler) {

Expand Down
22 changes: 21 additions & 1 deletion src/test/java/org/folio/edge/patron/MainVerticleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
30 changes: 28 additions & 2 deletions src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down

0 comments on commit 1495975

Please sign in to comment.