Skip to content

Commit

Permalink
[EDGPATRON-161] - Extend get API for /patron/registration-status with…
Browse files Browse the repository at this point in the history
… externalSystemId (#140)

* [EDGPATRON-161] - Extend get API for /patron/registration-status with {externalSystemId}

* [EDGPATRON-161] - Extend get API for /patron/registration-status with {externalSystemId}
  • Loading branch information
gurleenkaurbp committed Jan 13, 2025
1 parent 6f090f2 commit d01c9cc
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 31 deletions.
7 changes: 5 additions & 2 deletions ramls/edge-patron.raml
Original file line number Diff line number Diff line change
Expand Up @@ -1036,15 +1036,18 @@ types:
example: internal server error, contact administrator
/registration-status:
get:
description: Get the patron details by email ID
description: Get the patron details by email ID or externalSystemId
queryParameters:
apikey:
description: "API Key"
type: string
emailId:
description: The email ID of the patron.
type: string
required: true
externalSystemId:
description: The UUID of a staging user
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}$
responses:
200:
description: patron information retrieved successfully
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/org/folio/edge/patron/PatronHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,24 +308,32 @@ public void handleSecureGetAllowedServicePointsForItem(RoutingContext ctx) {

public void handleGetPatronRegistrationStatus(RoutingContext ctx) {
logger.debug("handleGetPatronRegistrationStatus:: Fetching patron registration");

String emailId = ctx.request().getParam(PARAM_EMAIL_ID);
if(StringUtils.isNullOrEmpty(emailId)) {
logger.warn("handleGetPatronRegistrationStatus:: Missing or empty emailId");
String externalSystemId = ctx.request().getParam(PARAM_EXTERNAL_SYSTEM_ID);

if (StringUtils.isNullOrEmpty(emailId) && StringUtils.isNullOrEmpty(externalSystemId)) {
logger.warn("handleGetPatronRegistrationStatus:: Missing or empty emailId and externalSystemId");
ctx.response()
.setStatusCode(400)
.putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON)
.end(getErrorMsg("EMAIL_NOT_PROVIDED", "emailId is missing in the request"));
.end(getErrorMsg("IDENTIFIERS_NOT_PROVIDED", "Either emailId or externalSystemId must be provided in the request"));
return;
}

super.handleCommon(ctx, new String[]{}, new String[]{}, (client, params) -> {
String alternateTenantId = ctx.request().getParam("alternateTenantId", client.tenant);
final PatronOkapiClient patronClient = new PatronOkapiClient(client, alternateTenantId);
patronClient.getPatronRegistrationStatus(emailId,

patronClient.getPatronRegistrationStatus(
emailId != null ? emailId : externalSystemId,
resp -> handleRegistrationStatusResponse(ctx, resp),
t -> handleProxyException(ctx, t));
t -> handleProxyException(ctx, t)
);
});
}


@Override
protected void invalidApiKey(RoutingContext ctx, String msg) {
accessDenied(ctx, msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,11 @@ public void placeInstanceHold(String patronId, String instanceId, String request
exceptionHandler);
}

public void getPatronRegistrationStatus(String emailId,
Handler<HttpResponse<Buffer>> responseHandler, Handler<Throwable> exceptionHandler) {
public void getPatronRegistrationStatus(String identifier,
Handler<HttpResponse<Buffer>> responseHandler, Handler<Throwable> exceptionHandler) {

get(format("%s/patron/registration-status/%s", okapiURL,
emailId), tenant, null, responseHandler, exceptionHandler);
identifier), tenant, null, responseHandler, exceptionHandler);
}

private Hold createCancellationHoldRequest(JsonObject cancellationRequest, JsonObject baseRequest, String patronId) {
Expand Down
42 changes: 38 additions & 4 deletions src/test/java/org/folio/edge/patron/MainVerticleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ public void testGetPatronRegistrationStatusWithoutEmail(TestContext context) {
.response();

var jsonResponse = new JsonObject(response.body().asString());
assertEquals("EMAIL_NOT_PROVIDED", jsonResponse.getString("code"));
assertEquals("emailId is missing in the request", jsonResponse.getString("errorMessage"));
assertEquals("IDENTIFIERS_NOT_PROVIDED", jsonResponse.getString("code"));
assertEquals("Either emailId or externalSystemId must be provided in the request", jsonResponse.getString("errorMessage"));

response = RestAssured
.get(String.format("/patron/registration-status?emailId=%s&apikey=%s", "", apiKey))
Expand All @@ -405,8 +405,8 @@ public void testGetPatronRegistrationStatusWithoutEmail(TestContext context) {
.response();

jsonResponse = new JsonObject(response.body().asString());
assertEquals("EMAIL_NOT_PROVIDED", jsonResponse.getString("code"));
assertEquals("emailId is missing in the request", jsonResponse.getString("errorMessage"));
assertEquals("IDENTIFIERS_NOT_PROVIDED", jsonResponse.getString("code"));
assertEquals("Either emailId or externalSystemId must be provided in the request", jsonResponse.getString("errorMessage"));
}

@Test
Expand All @@ -426,6 +426,23 @@ public void testGetPatronRegistrationStatusWithActiveEmail(TestContext context)
assertEquals(expected, actual);
}

@Test
public void testGetPatronRegistrationStatusWithExternalSystemId(TestContext context) {

final var response = RestAssured
.get(String.format("/patron/registration-status?externalSystemId=%s&apikey=%s", "9eb67301-6f6e-468f-9b1a-6134dc39a699", apiKey))
.then()
.statusCode(200)
.header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON)
.extract()
.response();

var expected = new JsonObject(readMockFile(
"/user_active.json"));
var actual = new JsonObject(response.body().asString());
assertEquals(expected, actual);
}

@Test
public void testGetPatronRegistrationStatusWithInvalidEmail() {

Expand All @@ -442,6 +459,23 @@ public void testGetPatronRegistrationStatusWithInvalidEmail() {
assertEquals("User does not exist", jsonResponse.getString("errorMessage"));
}

@Test
public void testGetPatronRegistrationStatusWithInvalidExternalSystemId() {

final var response = RestAssured
.get(String.format("/patron/registration-status?externalSystemId=%s&apikey=%s", "9eb67301-6f6e-468f-9b1a-6134dc39a700", apiKey))
.then()
.statusCode(404)
.header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON)
.extract()
.response();

var jsonResponse = new JsonObject(response.body().asString());
assertEquals("USER_NOT_FOUND", jsonResponse.getString("code"));
assertEquals("User does not exist", jsonResponse.getString("errorMessage"));
}


@Test
public void testGetPatronRegistrationStatusWithMultipleUserEmail() {

Expand Down
33 changes: 17 additions & 16 deletions src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,7 @@
import static org.folio.edge.core.Constants.DAY_IN_MILLIS;
import static org.folio.edge.core.Constants.TEXT_PLAIN;
import static org.folio.edge.core.Constants.X_OKAPI_TOKEN;
import static org.folio.edge.patron.Constants.PARAM_EMAIL_ID;
import static org.folio.edge.patron.Constants.PARAM_HOLD_ID;
import static org.folio.edge.patron.Constants.PARAM_INCLUDE_CHARGES;
import static org.folio.edge.patron.Constants.PARAM_INCLUDE_HOLDS;
import static org.folio.edge.patron.Constants.PARAM_INCLUDE_LOANS;
import static org.folio.edge.patron.Constants.PARAM_INSTANCE_ID;
import static org.folio.edge.patron.Constants.PARAM_ITEM_ID;
import static org.folio.edge.patron.Constants.PARAM_LIMIT;
import static org.folio.edge.patron.Constants.PARAM_OFFSET;
import static org.folio.edge.patron.Constants.PARAM_PATRON_ID;
import static org.folio.edge.patron.Constants.PARAM_REQUEST_ID;
import static org.folio.edge.patron.Constants.PARAM_SORT_BY;
import static org.folio.edge.patron.Constants.*;

import com.fasterxml.jackson.core.JsonProcessingException;
import io.vertx.core.http.HttpHeaders;
Expand Down Expand Up @@ -277,22 +266,34 @@ public void getRegistrationStatusHandler(RoutingContext ctx) {
.setStatusCode(403)
.putHeader(HttpHeaders.CONTENT_TYPE, TEXT_PLAIN)
.end("Access requires permission: patron.account.get");
} else if(emailId.equals("[email protected]")) {
} else if(emailId!=null && emailId.equals("[email protected]")) {
ctx.response()
.setStatusCode(200)
.putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON)
.end(readMockFile("/user_active.json"));
} else if(emailId.equals("[email protected]")) {
} else if(emailId!=null && emailId.equals("9eb67301-6f6e-468f-9b1a-6134dc39a699")) {
ctx.response()
.setStatusCode(200)
.putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON)
.end(readMockFile("/user_active.json"));
} else if(emailId!=null && emailId.equals("[email protected]")) {
ctx.response()
.setStatusCode(400)
.putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON)
.end(readMockFile("/multiple_user_error.json"));
} else if(emailId.equals("[email protected]")) {
} else if(emailId!=null && emailId.equals("[email protected]")) {
ctx.response()
.setStatusCode(404)
.putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON)
.end(readMockFile("/user_not_found_error.json"));
}
else if(emailId!=null && emailId.equals("9eb67301-6f6e-468f-9b1a-6134dc39a700")) {
ctx.response()
.setStatusCode(404)
.putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON)
.end(readMockFile("/user_not_found_error.json"));
} else if(emailId.equals("[email protected]")) {
}
else if(emailId!=null && emailId.equals("[email protected]")) {
ctx.response()
.setStatusCode(404)
.putHeader(HttpHeaders.CONTENT_TYPE, TEXT_PLAIN)
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/user_active.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "cacc29d8-cade-4312-a5f2-4eeac55d8697",
"externalSystemId": "[email protected]",
"externalSystemId": "9eb67301-6f6e-468f-9b1a-6134dc39a699",
"active": true,
"type": "patron",
"patronGroup": "63f8065f-df84-4e76-a36b-3ba32dbdc9e5",
Expand Down

0 comments on commit d01c9cc

Please sign in to comment.