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

[EDGEPATRON-134]-Added Get Endpoint for expired External Patron #118

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
43 changes: 43 additions & 0 deletions ramls/edge-patron.raml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions ramls/examples/external_patron_collection.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]"
},
"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": "[email protected]"
},
"preferredEmailCommunication": ["Programs", "Service"]
}
],
"totalRecords": 2
}
23 changes: 23 additions & 0 deletions ramls/external_patron_collection.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
1 change: 1 addition & 0 deletions src/main/java/org/folio/edge/patron/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/folio/edge/patron/MainVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/folio/edge/patron/PatronHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/folio/edge/patron/utils/PatronOkapiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ public void getExtPatronAccountByEmail(String email, Handler<HttpResponse<Buffer
exceptionHandler);
}

public void getExtPatronAccounts(boolean expired, Handler<HttpResponse<Buffer>> responseHandler,
Handler<Throwable> 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<HttpResponse<Buffer>> responseHandler, Handler<Throwable> exceptionHandler) {
post(
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/folio/edge/patron/MainVerticleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading