diff --git a/ramls/edge-patron.raml b/ramls/edge-patron.raml index 735ea4e..6f38acd 100644 --- a/ramls/edge-patron.raml +++ b/ramls/edge-patron.raml @@ -18,6 +18,7 @@ types: money: !include money.json item: !include item.json external_patron: !include external_patron.json + external_patron_collection: !include external_patron_collection.json allowedServicePoints: !include allowed-service-points-response.json hold-cancellation: !include hold-cancellation.json errors: !include raml-util/schemas/errors.schema @@ -77,6 +78,48 @@ types: body: text/plain: example: internal server error, contact administrator + /external-patrons: + displayName: Get Accounts of External Patrons + description: Get accounts of external patrons based on flag + get: + description: Return external_patrons detail + queryParameters: + expired: + description: | + Indicates to return only expired patron + required: false + type: boolean + default: false + apikey: + description: "API Key" + type: string + responses: + 200: + description: Returns the external patron accounts collection + body: + application/json: + type: external_patron_collection + example: !include examples/external_patron_collection.json + 400: + description: Bad request + body: + text/plain: + example: unable to process request -- constraint violation + 401: + description: Not authorized to perform requested action + body: + text/plain: + example: unable to get account -- unauthorized + 403: + description: Access Denied + body: + text/plain: + example: Access Denied + 500: + description: Internal server error, e.g. due to misconfiguration + body: + text/plain: + example: internal server error, contact administrator /by-email/{emailId}: displayName: Get Accounts By email description: Service endpoints that manage accounts by an existing email diff --git a/ramls/examples/external_patron_collection.json b/ramls/examples/external_patron_collection.json new file mode 100644 index 0000000..a2d182d --- /dev/null +++ b/ramls/examples/external_patron_collection.json @@ -0,0 +1,50 @@ +{ + "externalPatrons": [ + { + "generalInfo": { + "externalSystemId": "ext123", + "firstName": "John", + "preferredFirstName": "Johnny", + "middleName": "Michael", + "lastName": "Doe" + }, + "address0": { + "addressLine0": "123 Main St", + "addressLine1": "", + "city": "Anytown", + "province": "California", + "zip": "12345", + "country": "USA" + }, + "contactInfo": { + "phone": "123-456-7890", + "mobilePhone": "987-654-3210", + "email": "john.doe@example.com" + }, + "preferredEmailCommunication": ["Support", "Programs"] + }, + { + "generalInfo": { + "externalSystemId": "ext456", + "firstName": "Jane", + "preferredFirstName": "Janey", + "lastName": "Smith" + }, + "address0": { + "addressLine0": "456 Oak Ave", + "addressLine1": "Apt 2B", + "city": "Smallville", + "province": "Kansas", + "zip": "54321", + "country": "USA" + }, + "contactInfo": { + "phone": "987-654-3210", + "mobilePhone": "123-456-7890", + "email": "jane.smith@example.com" + }, + "preferredEmailCommunication": ["Programs", "Service"] + } + ], + "totalRecords": 2 +} diff --git a/ramls/external_patron_collection.json b/ramls/external_patron_collection.json new file mode 100644 index 0000000..4066f36 --- /dev/null +++ b/ramls/external_patron_collection.json @@ -0,0 +1,23 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "description": "Collection of external patrons", + "properties": { + "externalPatrons": { + "description": "List of external patron items", + "type": "array", + "id": "externalPatron", + "items": { + "type": "object", + "$ref": "external_patron.json" + } + }, + "totalRecords": { + "type": "integer" + } + }, + "required": [ + "externalPatrons", + "totalRecords" + ] +} diff --git a/ramls/raml-util b/ramls/raml-util index 4aaeffa..d93a160 160000 --- a/ramls/raml-util +++ b/ramls/raml-util @@ -1 +1 @@ -Subproject commit 4aaeffa22d5461b41ac761870dcfce58bf8db387 +Subproject commit d93a160488e29d0fce564fe5e47fd74b804818e8 diff --git a/src/main/java/org/folio/edge/patron/Constants.java b/src/main/java/org/folio/edge/patron/Constants.java index 5e76604..e019d48 100644 --- a/src/main/java/org/folio/edge/patron/Constants.java +++ b/src/main/java/org/folio/edge/patron/Constants.java @@ -24,6 +24,7 @@ public class Constants { public static final String PARAM_INSTANCE_ID = "instanceId"; public static final String PARAM_HOLD_ID = "holdId"; public static final String PARAM_EMAIL_ID = "emailId"; + public static final String PARAM_EXPIRED = "expired"; public static final String PARAM_REQUEST_ID = "requestId"; public static final String MSG_ACCESS_DENIED = "Access Denied"; diff --git a/src/main/java/org/folio/edge/patron/MainVerticle.java b/src/main/java/org/folio/edge/patron/MainVerticle.java index 079a416..41c378f 100644 --- a/src/main/java/org/folio/edge/patron/MainVerticle.java +++ b/src/main/java/org/folio/edge/patron/MainVerticle.java @@ -60,6 +60,9 @@ public Router defineRoutes() { router.route(HttpMethod.GET, "/patron/account/:patronId/by-email/:emailId") .handler(patronHandler::handleGetExtPatronAccountByEmail); + router.route(HttpMethod.GET, "/patron/account/:patronId/external-patrons") + .handler(patronHandler::handleGetExtPatronsAccounts); + router.route(HttpMethod.PUT, "/patron/account/:patronId/by-email/:emailId") .handler(patronHandler::handlePutExtPatronAccountByEmail); diff --git a/src/main/java/org/folio/edge/patron/PatronHandler.java b/src/main/java/org/folio/edge/patron/PatronHandler.java index 7b90d73..2d88136 100644 --- a/src/main/java/org/folio/edge/patron/PatronHandler.java +++ b/src/main/java/org/folio/edge/patron/PatronHandler.java @@ -9,6 +9,7 @@ import static org.folio.edge.patron.Constants.MSG_INTERNAL_SERVER_ERROR; import static org.folio.edge.patron.Constants.MSG_REQUEST_TIMEOUT; import static org.folio.edge.patron.Constants.PARAM_EMAIL_ID; +import static org.folio.edge.patron.Constants.PARAM_EXPIRED; 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; @@ -163,6 +164,15 @@ public void handlePutExtPatronAccountByEmail(RoutingContext ctx) { resp -> handleProxyResponse(ctx, resp), t -> handleProxyException(ctx, t))); } + public void handleGetExtPatronsAccounts(RoutingContext ctx) { + handleCommon(ctx, + new String[] { PARAM_PATRON_ID, PARAM_EXPIRED }, + new String[] {}, + (client, params) -> ((PatronOkapiClient) client).getExtPatronAccounts( + Boolean.parseBoolean(params.get(PARAM_EXPIRED)), + resp -> handleProxyResponse(ctx, resp), + t -> handleProxyException(ctx, t))); + } public void handlePlaceItemHold(RoutingContext ctx) { if (ctx.body().asJsonObject() == null) { 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 2ab6bda..2b92077 100644 --- a/src/main/java/org/folio/edge/patron/utils/PatronOkapiClient.java +++ b/src/main/java/org/folio/edge/patron/utils/PatronOkapiClient.java @@ -106,6 +106,17 @@ public void getExtPatronAccountByEmail(String email, Handler> responseHandler, + Handler exceptionHandler) { + String url = String.format("%s/patron/account?expired=%s", okapiURL, expired); + get( + url, + tenant, + null, + responseHandler, + exceptionHandler); + } + public void renewItem(String patronId, String itemId, Handler> responseHandler, Handler exceptionHandler) { post( diff --git a/src/test/java/org/folio/edge/patron/MainVerticleTest.java b/src/test/java/org/folio/edge/patron/MainVerticleTest.java index b397992..45a3312 100644 --- a/src/test/java/org/folio/edge/patron/MainVerticleTest.java +++ b/src/test/java/org/folio/edge/patron/MainVerticleTest.java @@ -635,9 +635,7 @@ public void testRenewRequesMaxRenewalWithEmptyErrors(TestContext context) throws .statusCode(expectedStatusCode) .extract() .response(); - ErrorMessage msg = ErrorMessage.fromJson(resp.body().asString()); - assertEquals("No error message found", msg.message); assertEquals(expectedStatusCode, msg.httpStatusCode); } @@ -731,6 +729,22 @@ public void testPostExternalLCPatron(TestContext context) throws Exception { .response(); } + @Test + public void testGetExternalLCPatrons(TestContext context) { + logger.info("=== Test get external patron ==="); + int expectedStatusCode = 200; + RestAssured + .with() + .contentType(APPLICATION_JSON) + .get( + String.format("/patron/account/%s/external-patrons?apikey=%s&expired=false",UUID.randomUUID(), apiKey)) + .then() + .statusCode(expectedStatusCode) + .header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) + .extract() + .response(); + } + @Test public void testPutExternalLCPatron(TestContext context) throws Exception { logger.info("=== Test put external patron ==="); 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 7fc76b9..46be071 100644 --- a/src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java +++ b/src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java @@ -135,6 +135,9 @@ public Router defineRoutes() { router.route(HttpMethod.GET, "/patron/account/:patronId") .handler(this::getAccountHandler); + router.route(HttpMethod.GET, "/patron/account") + .handler(this::getExtPatronAccountHandler); + router.route(HttpMethod.GET, "/patron/account/by-email/:emailId") .handler(this::getExtPatronAccountHandler);