Skip to content

Commit

Permalink
Circ 2084 (#1475)
Browse files Browse the repository at this point in the history
* CIRC-2084 changes required for dcb loan event

* CIRC-2084 changes required for dcb loan event

* CIRC-2084 added test cases for dcb loan

* CIRC-2084 changes made in LoanRepository.java

* CIRC-2084 Added isDcb property in loan.json and changed loan-storage version to 7.3 in ModuleDescriptor

* CIRC-2084 renamed storage-loan-7-2.json to storage-loan-7-3.json and changes made in LoanRepository
  • Loading branch information
SreejaMangarapu authored Jun 6, 2024
1 parent 83d13a3 commit fb01b92
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 3 deletions.
2 changes: 1 addition & 1 deletion descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@
"requires": [
{
"id": "loan-storage",
"version": "7.1"
"version": "7.3"
},
{
"id": "circulation-rules-storage",
Expand Down
4 changes: 4 additions & 0 deletions ramls/loan.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@
"type": "string",
"format": "date-time"
},
"isDcb": {
"description": "Indicates whether or not this loan is associated for DCB use case",
"type": "boolean"
},
"metadata": {
"description": "Metadata about creation and changes to loan, provided by the server (client should not provide)",
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public class LoanRepository implements GetManyRecordsRepository<Loan> {
private static final String ID = "id";
private static final String USER_ID = "userId";

private static final String IS_DCB = "isDcb";
private static final String DCB_USER_LASTNAME = "DcbSystem";

public LoanRepository(Clients clients, ItemRepository itemRepository,
UserRepository userRepository) {

Expand Down Expand Up @@ -294,6 +297,15 @@ private Result<MultipleRecords<Loan>> mapResponseToLoans(Response response) {
return MultipleRecords.from(response, Loan::from, RECORDS_PROPERTY_NAME);
}

private static void addIsDcbProperty(Loan loan, Item item, JsonObject storageLoan) {
write(storageLoan, IS_DCB, isDcbLoan(loan, item));
}

private static boolean isDcbLoan(Loan loan, Item item) {
return item.isDcbItem() || (nonNull(loan.getUser()) && nonNull(loan.getUser().getLastName())
&& loan.getUser().getLastName().equalsIgnoreCase(DCB_USER_LASTNAME));
}

private static JsonObject mapToStorageRepresentation(Loan loan, Item item) {
log.debug("mapToStorageRepresentation:: parameters loan: {}, item: {}", loan, item);
JsonObject storageLoan = loan.asJson();
Expand All @@ -307,7 +319,7 @@ private static JsonObject mapToStorageRepresentation(Loan loan, Item item) {
removeProperty(storageLoan, FEESANDFINES);
removeProperty(storageLoan, OVERDUE_FINE_POLICY);
removeProperty(storageLoan, LOST_ITEM_POLICY);

addIsDcbProperty(loan, item, storageLoan);
updatePolicy(storageLoan, loan.getLoanPolicy(), "loanPolicyId");
updatePolicy(storageLoan, loan.getOverdueFinePolicy(), "overdueFinePolicyId");
updatePolicy(storageLoan, loan.getLostItemPolicy(), "lostItemPolicyId");
Expand Down
53 changes: 53 additions & 0 deletions src/test/java/api/loans/LoanAPITests.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,61 @@ void canCreateALoan() {
assertThat("has item volume",
item.getString("volume"), is("testVolume"));

assertThat("isDcb should be false",
loan.getString("isDcb"), is("false"));

loanHasExpectedProperties(loan, user);
}
@Test
void createLoanForDcbItem() {
IndividualResource instance = instancesFixture.basedUponDunkirk();
IndividualResource holdings = holdingsFixture.defaultWithHoldings(instance.getId());
var instanceTitle = "virtual Title";

IndividualResource locationsResource = locationsFixture.mainFloor();
final IndividualResource circulationItem = circulationItemsFixture.createCirculationItem(
"100002222", holdings.getId(), locationsResource.getId(), instanceTitle);

loansFixture.createLoan(circulationItem, usersFixture.jessica());
JsonObject loan = loansFixture.getLoans().getFirst();

assertThat("isDcb should be true",
loan.getString("isDcb"), is("true"));
}

@Test
void createLoanForDcbUser() {
IndividualResource instance = instancesFixture.basedUponDunkirk();
IndividualResource holdings = holdingsFixture.defaultWithHoldings(instance.getId());
var instanceTitle = "title";

IndividualResource locationsResource = locationsFixture.mainFloor();
final IndividualResource circulationItem = circulationItemsFixture.createCirculationItemForDcb(
"100002222", holdings.getId(), locationsResource.getId(), instanceTitle, false);

loansFixture.createLoan(circulationItem, usersFixture.groot());
JsonObject loan = loansFixture.getLoans().getFirst();

assertThat("isDcb should be true",
loan.getString("isDcb"), is("true"));
}

@Test
void createLoanForDcbUserAndDcbItem() {
IndividualResource instance = instancesFixture.basedUponDunkirk();
IndividualResource holdings = holdingsFixture.defaultWithHoldings(instance.getId());
var instanceTitle = "virtual Title";

IndividualResource locationsResource = locationsFixture.mainFloor();
final IndividualResource circulationItem = circulationItemsFixture.createCirculationItem(
"100002222", holdings.getId(), locationsResource.getId(), instanceTitle);

loansFixture.createLoan(circulationItem, usersFixture.groot());
JsonObject loan = loansFixture.getLoans().getFirst();

assertThat("isDcb should be true",
loan.getString("isDcb"), is("true"));
}

@Test
void canGetLoanWithoutOpenFeesFines() {
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/api/support/builders/CirculationItemsBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,17 @@ public CirculationItemsBuilder withInstanceTitle(String instanceTitle) {
instanceTitle);
}

public CirculationItemsBuilder withDcb(boolean isDcb) {
return new CirculationItemsBuilder(
this.itemId,
this.barcode,
this.holdingId,
this.locationId,
this.materialTypeId,
this.loanTypeId,
isDcb,
this.lendingLibraryCode,
this.instanceTitle);
}

}
2 changes: 1 addition & 1 deletion src/test/java/api/support/fakes/StorageSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static JsonSchemaValidator validatorForStorageItemSchema() throws IOExcep
}

public static JsonSchemaValidator validatorForStorageLoanSchema() throws IOException {
return JsonSchemaValidator.fromResource("/storage-loan-7-2.json");
return JsonSchemaValidator.fromResource("/storage-loan-7-3.json");
}

public static JsonSchemaValidator validatorForLocationInstSchema() throws IOException {
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/api/support/fixtures/CirculationItemsFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ public IndividualResource createCirculationItem(String barcode, UUID holdingId,
return circulationItemClient.create(circulationItemsBuilder);
}

public IndividualResource createCirculationItemForDcb(String barcode, UUID holdingId, UUID locationId,
String instanceTitle, boolean isDcb) {
CirculationItemsBuilder circulationItemsBuilder = new CirculationItemsBuilder()
.withBarcode(barcode)
.withHoldingId(holdingId)
.withLoanType(loanTypesFixture.canCirculate().getId())
.withMaterialType(materialTypesFixture.book().getId())
.withLocationId(locationId)
.withInstanceTitle(instanceTitle)
.withDcb(isDcb);

return circulationItemClient.create(circulationItemsBuilder);
}

public IndividualResource createCirculationItemWithLendingLibrary(String barcode, UUID holdingId, UUID locationId, String lendingLibrary) {
CirculationItemsBuilder circulationItemsBuilder = new CirculationItemsBuilder().withBarcode(barcode).withHoldingId(holdingId)
.withLoanType(loanTypesFixture.canCirculate().getId()).withMaterialType(materialTypesFixture.book().getId())
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/api/support/fixtures/UserExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ static UserBuilder basedUponJamesRodwell() {

}

static UserBuilder basedUponGroot() {
return new UserBuilder()
.withName("DcbSystem", "dcb")
.withBarcode("6430530304")
.withActive(true);
}

static UserBuilder basedUponCharlotteBroadwell() {
return new UserBuilder()
.withName("Broadwell", "Charlotte")
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/api/support/fixtures/UsersFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static api.support.fixtures.UserExamples.basedUponBobbyBibbin;
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.basedUponJamesRodwell;
import static api.support.fixtures.UserExamples.basedUponJessicaPontefract;
Expand Down Expand Up @@ -34,6 +35,11 @@ public UserResource jessica() {
.inGroupFor(patronGroupsFixture.regular()));
}

public UserResource groot() {
return createIfAbsent(basedUponGroot()
.inGroupFor(patronGroupsFixture.regular()));
}

public UserResource james() {
return createIfAbsent(basedUponJamesRodwell()
.inGroupFor(patronGroupsFixture.regular()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@
"description": "Indicates whether or not this loan had its due date modified by a recall on the loaned item",
"type": "boolean"
},
"isDcb": {
"description": "Indicates whether or not this loan is associated for DCB use case",
"type": "boolean"
},
"declaredLostDate" : {
"description": "Date and time the item was declared lost during this loan",
"type": "string",
Expand Down

0 comments on commit fb01b92

Please sign in to comment.