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

Circ 2084 #1475

Merged
merged 6 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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