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

[EDGPATRON-134]-Added Get external patron endpoint #116

Closed
wants to merge 8 commits into from
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"
]
}
2 changes: 1 addition & 1 deletion ramls/raml-util
Submodule raml-util updated 0 files
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 @@ -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";
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 @@ -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);

Expand Down
10 changes: 10 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 @@ -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) {
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
18 changes: 16 additions & 2 deletions src/test/java/org/folio/edge/patron/MainVerticleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 ===");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading