From 7b49c914986d7ce10ccf72cec7d625052f3848b4 Mon Sep 17 00:00:00 2001 From: SreejaMangarapu <164345887+SreejaMangarapu@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:25:30 +0530 Subject: [PATCH] Circ 2144 Extending the loan representation with additional fields required for Due date receipt (#1493) * CIRC-2144 Extending the loan representation with additional fields required for Due date receipt --- ramls/examples/loan.json | 7 +++++-- ramls/loan.json | 15 +++++++++++++++ .../circulation/domain/LoanRepresentation.java | 4 ++-- .../ItemSummaryRepresentation.java | 1 + src/test/java/api/loans/LoanAPITests.java | 15 +++++++++++++++ .../java/api/support/fixtures/UserExamples.java | 7 +++++++ .../java/api/support/fixtures/UsersFixture.java | 6 ++++++ 7 files changed, 51 insertions(+), 4 deletions(-) diff --git a/ramls/examples/loan.json b/ramls/examples/loan.json index 7417c10beb..6be2c47ed1 100644 --- a/ramls/examples/loan.json +++ b/ramls/examples/loan.json @@ -19,7 +19,8 @@ { "name": "Steve Jones" } - ] + ], + "primaryContributor" : "Steve Jones" }, "loanPolicyId" : "e9af4ba4-6801-4722-be45-d7a49d13564d", "loanPolicy": { @@ -37,7 +38,9 @@ "firstName" : "FirstName", "lastName" : "LastName", "middleName" : "MiddleName", - "barcode" : "102322966933815" + "barcode" : "102322966933815", + "preferredFirstName" : "preferredFirstName", + "patronGroup" : "3684a786-6671-4268-8ed0-9db82ebca60b" }, "loanDate": "2017-03-01T23:11:00.000Z", "dueDate": "2017-04-01T23:11:00.000Z", diff --git a/ramls/loan.json b/ramls/loan.json index 80125978c9..05e92a46c8 100644 --- a/ramls/loan.json +++ b/ramls/loan.json @@ -38,6 +38,16 @@ "description": "barcode used to identify the borrower (read only, defined by the server)", "type": "string", "readonly": true + }, + "preferredFirstName": { + "description": "preferred first name of the borrower (read only, defined by the server)", + "type": "string", + "readonly": true + }, + "patronGroup": { + "description": "current patron group of the borrower (read only, defined by the server)", + "type": "string", + "readonly": true } }, "additionalProperties": false @@ -158,6 +168,11 @@ "additionalProperties": false } }, + "primaryContributor": { + "description": "primary contributor of the item", + "type": "string", + "readonly": true + }, "holdingsRecordId": { "description": "The ID of the holdings for the item", "type": "string", diff --git a/src/main/java/org/folio/circulation/domain/LoanRepresentation.java b/src/main/java/org/folio/circulation/domain/LoanRepresentation.java index 467dd334c4..7198f393de 100644 --- a/src/main/java/org/folio/circulation/domain/LoanRepresentation.java +++ b/src/main/java/org/folio/circulation/domain/LoanRepresentation.java @@ -177,9 +177,9 @@ private void additionalBorrowerProperties(JsonObject loanRepresentation, User bo borrowerSummary.put("lastName", borrower.getLastName()); borrowerSummary.put("middleName", borrower.getMiddleName()); borrowerSummary.put("barcode", borrower.getBarcode()); - + borrowerSummary.put("preferredFirstName",borrower.getPreferredFirstName()); + borrowerSummary.put("patronGroup",borrower.getPatronGroupId()); loanRepresentation.put(BORROWER, borrowerSummary); - additionalPatronGroupProperties(loanRepresentation, borrower.getPatronGroup()); } diff --git a/src/main/java/org/folio/circulation/domain/representations/ItemSummaryRepresentation.java b/src/main/java/org/folio/circulation/domain/representations/ItemSummaryRepresentation.java index efb1db2699..f9143cc197 100644 --- a/src/main/java/org/folio/circulation/domain/representations/ItemSummaryRepresentation.java +++ b/src/main/java/org/folio/circulation/domain/representations/ItemSummaryRepresentation.java @@ -36,6 +36,7 @@ public JsonObject createItemSummary(Item item) { write(itemSummary, "title", item.isDcbItem() ? item.getDcbItemTitle() : item.getTitle()); write(itemSummary, "barcode", item.getBarcode()); write(itemSummary, "contributors", mapContributorNamesToJson(item)); + write(itemSummary, "primaryContributor",item.getPrimaryContributorName()); write(itemSummary, "callNumber", item.getCallNumber()); write(itemSummary, "enumeration", item.getEnumeration()); write(itemSummary, "chronology", item.getChronology()); diff --git a/src/test/java/api/loans/LoanAPITests.java b/src/test/java/api/loans/LoanAPITests.java index 4d4f43131c..6b5f8c57b0 100644 --- a/src/test/java/api/loans/LoanAPITests.java +++ b/src/test/java/api/loans/LoanAPITests.java @@ -255,6 +255,21 @@ void createLoanForDcbUserAndDcbItem() { loan.getString("isDcb"), is("true")); } + @Test + void canGetLoansWithAdditionalFieldsRequiredForDueDateSlip() { + loansFixture.createLoan(itemsFixture.basedUponSmallAngryPlanet(), usersFixture.KimJames()); + JsonObject loan = loansFixture.getLoans().getFirst(); + + assertThat("Borrower has preferredFirstName", + loan.getJsonObject("borrower").containsKey("preferredFirstName"), is(true)); + + assertThat("Borrower has patronGroup", + loan.getJsonObject("borrower").containsKey("patronGroup"), is(true)); + + assertThat("Item has primaryContributor", + loan.getJsonObject("item").containsKey("primaryContributor"), is(true)); + } + @Test void canGetLoanWithoutOpenFeesFines() { UUID id = UUID.randomUUID(); diff --git a/src/test/java/api/support/fixtures/UserExamples.java b/src/test/java/api/support/fixtures/UserExamples.java index b44bd89f96..4b8fa35c2f 100644 --- a/src/test/java/api/support/fixtures/UserExamples.java +++ b/src/test/java/api/support/fixtures/UserExamples.java @@ -39,6 +39,13 @@ static UserBuilder basedUponGroot() { .withActive(true); } + static UserBuilder basedUponJames() { + return new UserBuilder() + .withBarcode("6430530304") + .withPreferredFirstName("kim", "james", "kimJ") + .withActive(true); + } + static UserBuilder basedUponCharlotteBroadwell() { return new UserBuilder() .withName("Broadwell", "Charlotte") diff --git a/src/test/java/api/support/fixtures/UsersFixture.java b/src/test/java/api/support/fixtures/UsersFixture.java index d442941d6d..af6d9e979e 100644 --- a/src/test/java/api/support/fixtures/UsersFixture.java +++ b/src/test/java/api/support/fixtures/UsersFixture.java @@ -4,6 +4,7 @@ import static api.support.fixtures.UserExamples.basedUponCharlotteBroadwell; import static api.support.fixtures.UserExamples.basedUponGroot; import static api.support.fixtures.UserExamples.basedUponHenryHanks; +import static api.support.fixtures.UserExamples.basedUponJames; import static api.support.fixtures.UserExamples.basedUponJamesRodwell; import static api.support.fixtures.UserExamples.basedUponJessicaPontefract; import static api.support.fixtures.UserExamples.basedUponRebeccaStuart; @@ -40,6 +41,11 @@ public UserResource groot() { .inGroupFor(patronGroupsFixture.regular())); } + public UserResource KimJames() { + return createIfAbsent(basedUponJames() + .inGroupFor(patronGroupsFixture.staff())); + } + public UserResource james() { return createIfAbsent(basedUponJamesRodwell() .inGroupFor(patronGroupsFixture.regular()));