diff --git a/ramls/edge-patron.raml b/ramls/edge-patron.raml index 735ea4e..2941523 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,47 @@ 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/src/main/java/org/folio/edge/patron/Constants.java b/src/main/java/org/folio/edge/patron/Constants.java index 5e76604..48c960c 100644 --- a/src/main/java/org/folio/edge/patron/Constants.java +++ b/src/main/java/org/folio/edge/patron/Constants.java @@ -7,6 +7,7 @@ public class Constants { public static final String SYS_PATRON_ID_CACHE_TTL_MS = "patron_id_cache_ttl_ms"; public static final String SYS_NULL_PATRON_ID_CACHE_TTL_MS = "null_patron_id_cache_ttl_ms"; public static final String SYS_PATRON_ID_CACHE_CAPACITY = "patron_id_cache_capacity"; + public static final String PARAM_EXPIRED = "expired"; public static final String DEFAULT_CURRENCY_CODE = Currency.getInstance("USD").getCurrencyCode(); public static final long DEFAULT_PATRON_ID_CACHE_TTL_MS = 60 * 60 * 1000L; diff --git a/src/main/java/org/folio/edge/patron/MainVerticle.java b/src/main/java/org/folio/edge/patron/MainVerticle.java index 079a416..8219ef6 100644 --- a/src/main/java/org/folio/edge/patron/MainVerticle.java +++ b/src/main/java/org/folio/edge/patron/MainVerticle.java @@ -57,6 +57,9 @@ public Router defineRoutes() { router.route(HttpMethod.GET, "/patron/account/:patronId") .handler(patronHandler::handleGetAccount); + router.route(HttpMethod.GET, "/patron/account/:patronId/external-patrons") + .handler(patronHandler::handleGetExtPatronsAccounts); + router.route(HttpMethod.GET, "/patron/account/:patronId/by-email/:emailId") .handler(patronHandler::handleGetExtPatronAccountByEmail); diff --git a/src/main/java/org/folio/edge/patron/PatronHandler.java b/src/main/java/org/folio/edge/patron/PatronHandler.java index 7b90d73..d4c0830 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; @@ -221,6 +222,16 @@ public void handleCancelHold(RoutingContext ctx) { ); } + 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 handlePlaceInstanceHold(RoutingContext ctx) { if (ctx.body().asJsonObject() == null) { badRequest(ctx, MSG_HOLD_NOBODY); 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..3472e2a 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..aa94411 100644 --- a/src/test/java/org/folio/edge/patron/MainVerticleTest.java +++ b/src/test/java/org/folio/edge/patron/MainVerticleTest.java @@ -202,6 +202,22 @@ public void testGetAccountPatronFound(TestContext context) throws Exception { .body(is(expected)); } + @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 testGetAccountPatronFoundGzip(TestContext context) throws Exception { logger.info("=== Patron in GZip compression ==="); 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..7ceb37d 100644 --- a/src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java +++ b/src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java @@ -138,6 +138,9 @@ public Router defineRoutes() { router.route(HttpMethod.GET, "/patron/account/by-email/:emailId") .handler(this::getExtPatronAccountHandler); + router.route(HttpMethod.GET, "/patron/account") + .handler(this::getExtPatronAccountHandler); + router.route(HttpMethod.PUT, "/patron/account/by-email/:emailId") .handler(this::putExtPatronAccountHandler);