Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODPATRON-181 Added new endpoint to get service points based on the item #159

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@
"modulePermissions": [
"circulation.requests.allowed-service-points.get"
]
},
{
"methods": ["GET"],
"pathPattern": "/patron/account/{accountId}/item/{itemId}/allowed-service-points",
"permissionsRequired": ["patron.hold.allowed-service-points.get"],
"modulePermissions": [
"circulation.requests.allowed-service-points.get"
]
}
]
}
Expand Down
26 changes: 26 additions & 0 deletions ramls/patron.raml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,32 @@ traits:
description: The UUID of a FOLIO hold request
type: string
pattern: ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$
/allowed-service-points:
displayName: Allowed service points
description: Services that provides a list of allowed pickup service points
get:
description: |
Returns a list of pickup service points allowed for a particular patron and item
is: [ validate ]
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
15 changes: 15 additions & 0 deletions src/main/java/org/folio/rest/impl/PatronServicesResourceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,16 @@ public void postPatronAccountInstanceHoldByIdAndInstanceId(String id,
}
}

@Override
public void getPatronAccountItemAllowedServicePointsByIdAndItemId(String requesterId, String itemId,
Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
var httpClient = HttpClientFactory.getHttpClient(vertxContext.owner());
var queryParameters = Map.of("operation", "create",
"requesterId", requesterId, "itemId", itemId);

getAllowedServicePoints(okapiHeaders, asyncResultHandler, httpClient, queryParameters);
}

@Override
public void getPatronAccountInstanceAllowedServicePointsByIdAndInstanceId(String requesterId,
String instanceId, Map<String, String> okapiHeaders,
Expand All @@ -502,6 +512,11 @@ public void getPatronAccountInstanceAllowedServicePointsByIdAndInstanceId(String
var queryParameters = Map.of("operation", "create",
"requesterId", requesterId, "instanceId", instanceId);

getAllowedServicePoints(okapiHeaders, asyncResultHandler, httpClient, queryParameters);
}

private void getAllowedServicePoints(Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler,
VertxOkapiHttpClient httpClient, Map<String, String> queryParameters) {
new EcsTlrSettingsService()
.isEcsTlrFeatureEnabled(httpClient, okapiHeaders)
.thenApply(this::getAllowedServicePointsUrl)
Expand Down
96 changes: 92 additions & 4 deletions src/test/java/org/folio/rest/impl/PatronResourceImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1143,9 +1143,88 @@ public final void testDeletePatronAccountByIdItemByItemIdHoldByHoldIdWithErrors(
// Test done
logger.info("Test done");
}
@Test
final void allowedServicePointsForItemShouldSucceed() {
logger.info("Testing allowed service points for Item");

var response = given()
.header(tenantHeader)
.header(urlHeader)
.header(contentTypeHeader)
.pathParam("accountId", goodUserId)
.pathParam("itemId", goodItemId)
.log().all()
.when()
.contentType(ContentType.JSON)
.get(accountPath + itemPath + allowedServicePointsPath)
.then()
.log().all()
.and().assertThat().contentType(ContentType.JSON)
.and().assertThat().statusCode(200)
.extract()
.asString();

final JsonObject expectedJson = new JsonObject(readMockFile(MOCK_DATA_FOLDER +
"/allowed_sp_mod_patron_expected_response.json"));
verifyAllowedServicePoints(expectedJson, new JsonObject(response));
logger.info("Test done");
}

@Test
final void allowedServicePointsShouldSucceed() {
final void allowedServicePointsForItemShouldFailWhenModCirculationFails() {
logger.info("Testing allowed service points for item");

given()
.header(tenantHeader)
.header(urlHeader)
.header(contentTypeHeader)
.header(new Header(okapiBadDataHeader, "500"))
.pathParam("accountId", goodUserId)
.pathParam("itemId", goodItemId)
.log().all()
.when()
.contentType(ContentType.JSON)
.get(accountPath + itemPath + allowedServicePointsPath)
.then()
.log().all()
.and().assertThat().contentType(TEXT)
.and().assertThat().statusCode(500)
.extract()
.asString();

logger.info("Test done");
}

@Test
final void allowedServicePointsForItemShouldProxyModCirculationErrors() {
logger.info("Testing allowed service points for item");

var response = given()
.header(tenantHeader)
.header(urlHeader)
.header(contentTypeHeader)
.header(new Header(okapiBadDataHeader, "422"))
.pathParam("accountId", goodUserId)
.pathParam("itemId", goodItemId)
.log().all()
.when()
.contentType(ContentType.JSON)
.get(accountPath + itemPath + allowedServicePointsPath)
.then()
.log().all()
.and().assertThat().contentType(JSON)
.and().assertThat().statusCode(422)
.extract()
.asString();

final var expected = readMockFile(MOCK_DATA_FOLDER +
"/allowed_service_points_instance_not_found.json");
assertEquals(new JsonObject(expected), new JsonObject(response));

logger.info("Test done");
}
@Test
final void allowedServicePointsForInstanceShouldSucceed() {
logger.info("Testing allowed service points");

var response = given()
Expand All @@ -1172,7 +1251,7 @@ final void allowedServicePointsShouldSucceed() {
}

@Test
final void allowedServicePointsShouldFailWhenModCirculationFails() {
final void allowedServicePointsForInstanceShouldFailWhenModCirculationFails() {
logger.info("Testing allowed service points");

given()
Expand All @@ -1197,7 +1276,7 @@ final void allowedServicePointsShouldFailWhenModCirculationFails() {
}

@Test
final void allowedServicePointsShouldProxyModCirculationErrors() {
final void allowedServicePointsForInstanceShouldProxyModCirculationErrors() {
logger.info("Testing allowed service points");

var response = given()
Expand Down Expand Up @@ -2193,7 +2272,16 @@ else if (req.path().equals("/circulation/requests/allowed-service-points")) {
.setStatusCode(200)
.putHeader("content-type", "application/json")
.end(readMockFile(MOCK_DATA_FOLDER + "/allowed_sp_mod_circulation_response.json"));
} else {
}
else if ("create".equals(req.getParam("operation"))
&& goodUserId.equals(req.getParam("requesterId"))
&& goodItemId.equals(req.getParam("itemId"))) {
req.response()
.setStatusCode(200)
.putHeader("content-type", "application/json")
.end(readMockFile(MOCK_DATA_FOLDER + "/allowed_sp_mod_circulation_response.json"));
}
else {
req.response()
.setStatusCode(400)
.putHeader("content-type", "text/plain")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"errors": [
{
"message": "Item with ID d5a2f197-23d9-4153-9d79-da7a9f2d4a0d was not found",
"parameters": []
}
]
}
Loading