Skip to content

Commit

Permalink
CIRC-2029 Returning DCB title in response if the item is a virtual it…
Browse files Browse the repository at this point in the history
…em (#1423) (#1428)

* CIRC-2029 Return dcb instance title for dcb item

* CIRC-2029 Adding test case for checkin,checkout,loan and requests
  • Loading branch information
Vignesh-kalyanasundaram authored Feb 12, 2024
1 parent 436727e commit 87bebb0
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 25 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/folio/circulation/domain/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,8 @@ public boolean isDcbItem() {
public String getLendingLibraryCode() {
return getProperty(itemRepresentation, "lendingLibraryCode");
}

public String getDcbItemTitle() {
return getProperty(itemRepresentation, "instanceTitle");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public JsonObject extendedRepresentation(Request request) {
final JsonObject requestRepresentation = request.asJson();

addItemProperties(requestRepresentation, request.getItem());
addInstanceProperties(requestRepresentation, request.getInstance());
addInstanceProperties(requestRepresentation, request.getInstance(), request.getItem());
addAdditionalLoanProperties(requestRepresentation, request.getLoan());
addAdditionalRequesterProperties(requestRepresentation, request.getRequester());
addAdditionalProxyProperties(requestRepresentation, request.getProxy());
Expand Down Expand Up @@ -94,14 +94,15 @@ private static void addItemProperties(JsonObject request, Item item) {
write(request, "item", itemSummary);
}

private static void addInstanceProperties(JsonObject request, Instance instance) {
private static void addInstanceProperties(JsonObject request, Instance instance, Item item) {
if (instance == null || instance.isNotFound()) {
log.info("Unable to add instance properties to request {}, instance is {}",
request.getString("id"), request.getString("instanceId"));
return;
}
JsonObject instanceSummary = new JsonObject();
write(instanceSummary, "title", instance.getTitle());
write(instanceSummary, "title", item != null && item.isDcbItem() ?
item.getDcbItemTitle() : instance.getTitle());
write(instanceSummary, "identifiers", identifiersToJson(instance.getIdentifiers()));
write(instanceSummary, "contributorNames", mapContributorNamesToJson(instance));
write(instanceSummary, "publication", publicationsToJson(instance.getPublication()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private static JsonObject createItemContext(Item item) {
String yearCaptionsToken = String.join("; ", item.getYearCaption());
String copyNumber = item.getCopyNumber() != null ? item.getCopyNumber() : "";

JsonObject itemContext = createInstanceContext(item.getInstance())
JsonObject itemContext = createInstanceContext(item.getInstance(), item)
.put("barcode", item.getBarcode())
.put("status", item.getStatus().getValue())
.put("enumeration", item.getEnumeration())
Expand Down Expand Up @@ -241,15 +241,16 @@ private static JsonObject createItemContext(Item item) {
private static JsonObject createItemContext(Request request) {
return request.hasItem()
? createItemContext(request.getItem())
: createInstanceContext(request.getInstance());
: createInstanceContext(request.getInstance(), request.getItem());
}

private static JsonObject createInstanceContext(Instance instance) {
private static JsonObject createInstanceContext(Instance instance, Item item) {
JsonObject instanceContext = new JsonObject();

if (instance != null) {
instanceContext
.put("title", instance.getTitle())
.put("title", item != null && item.isDcbItem() ?
item.getDcbItemTitle() : instance.getTitle())
.put("primaryContributor", instance.getPrimaryContributorName())
.put("allContributors", instance.getContributorNames().collect(joining("; ")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public JsonObject createItemSummary(Item item) {
write(itemSummary, "id", item.getItemId());
write(itemSummary, "holdingsRecordId", item.getHoldingsRecordId());
write(itemSummary, "instanceId", item.getInstanceId());
write(itemSummary, "title", item.getTitle());
write(itemSummary, "title", item.isDcbItem() ? item.getDcbItemTitle() : item.getTitle());
write(itemSummary, "barcode", item.getBarcode());
write(itemSummary, "contributors", mapContributorNamesToJson(item));
write(itemSummary, "callNumber", item.getCallNumber());
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/api/loans/CheckInByBarcodeTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ void canCheckInAnDcbItem() {
IndividualResource holdings = holdingsFixture.defaultWithHoldings(instance.getId());
IndividualResource locationsResource = locationsFixture.mainFloor();
var barcode = "100002222";
final IndividualResource circulationItem = circulationItemsFixture.createCirculationItem(barcode, holdings.getId(), locationsResource.getId());
var instanceTitle = "virtual title";
final IndividualResource circulationItem = circulationItemsFixture.createCirculationItem(barcode, holdings.getId(), locationsResource.getId(), instanceTitle);
final CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode(circulationItem, ZonedDateTime.now(), checkInServicePointId);

assertThat("Response should include an item",
Expand All @@ -437,6 +438,9 @@ void canCheckInAnDcbItem() {

assertThat("barcode is included for item",
itemFromResponse.getString("barcode"), is(barcode));

assertThat("item title should match dcb instance title",
itemFromResponse.getString("title"), is(instanceTitle));
}

@Test
Expand All @@ -447,7 +451,7 @@ void slipContainsLendingLibraryCodeForDcb() {
IndividualResource locationsResource = locationsFixture.mainFloor();
var barcode = "100002222";
var lendingLibraryCode = "11223";
final IndividualResource circulationItem = circulationItemsFixture.createCirculationItemWithLandingLibrary(barcode, holdings.getId(), locationsResource.getId(), lendingLibraryCode);
final IndividualResource circulationItem = circulationItemsFixture.createCirculationItemWithLendingLibrary(barcode, holdings.getId(), locationsResource.getId(), lendingLibraryCode);

final CheckInByBarcodeResponse checkInResponse = checkInFixture.checkInByBarcode(circulationItem, ZonedDateTime.now(), checkInServicePointId);
JsonObject staffSlipContext = checkInResponse.getStaffSlipContext();
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/api/loans/CheckOutByBarcodeTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,9 @@ void canCheckOutAnDcbItem() {
IndividualResource holdings = holdingsFixture.defaultWithHoldings(instance.getId());
IndividualResource locationsResource = locationsFixture.mainFloor();
var barcode = "100002222";
IndividualResource circulationItem = circulationItemsFixture.createCirculationItem(barcode, holdings.getId(), locationsResource.getId());
var instanceTitle = "virtual Title";
IndividualResource circulationItem = circulationItemsFixture.createCirculationItem(
barcode, holdings.getId(), locationsResource.getId(), instanceTitle);
final IndividualResource jessica = usersFixture.jessica();
final IndividualResource response = checkOutFixture.checkOutByBarcode(
new CheckOutByBarcodeRequestBuilder()
Expand All @@ -987,6 +989,9 @@ void canCheckOutAnDcbItem() {
assertThat("status should be open",
loan.getJsonObject("status").getString("name"), is("Open"));

assertThat("item title should match dcb instance title",
loan.getJsonObject("item").getString("title"), is(instanceTitle));

circulationItem = circulationItemsClient.get(circulationItem);

assertThat(circulationItem, hasItemStatus(CHECKED_OUT));
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/api/loans/LoanAPITests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1287,15 +1287,20 @@ void loanInCollectionDoesNotProvideItemInformationForUnknownItem() {
void loanInCollectionDoesProvideItemInformationForCirculationItem() {
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());
final IndividualResource circulationItem = circulationItemsFixture.createCirculationItem(
"100002222", holdings.getId(), locationsResource.getId(), instanceTitle);
loansFixture.createLoan(circulationItem, usersFixture.jessica());

JsonObject loan = loansFixture.getLoans().getFirst();

assertThat("should be item information available",
loan.containsKey("item"), is(true));

assertThat("item title should match dcb instance title",
loan.getJsonObject("item").getString("title"), is(instanceTitle));
}

@Test
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/api/requests/RequestsAPICreationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -4822,6 +4822,36 @@ void recallTlrShouldSucceedWhenItNeedsToPickLeastRecalledLoanAndRequestsWithNoLo
assertThat(recallTlr5.getJson().getString("itemId"), is(notRecalledItem.getId().toString()));
}

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

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

final IndividualResource requestPickupServicePoint = servicePointsFixture.cd2();

checkInFixture.checkInByBarcode(circulationItem, requestPickupServicePoint.getId());

final IndividualResource holdRequest = requestsClient.create(new RequestBuilder()
.hold()
.forItem(circulationItem)
.withInstanceId(instance.getId())
.withPickupServicePointId(requestPickupServicePoint.getId())
.by(usersFixture.james()));

JsonObject requestedItem = holdRequest.getJson().getJsonObject("item");

assertThat(holdRequest.getJson().getString("requestType"), is(HOLD.getValue()));
assertThat(requestedItem.getString("status"), is(ItemStatus.IN_TRANSIT.getValue()));
assertThat(holdRequest.getJson().getString("status"), is(RequestStatus.OPEN_NOT_YET_FILLED.getValue()));
assertThat(holdRequest.getJson().getJsonObject("instance").getString("title"), is(instanceTitle));

}

private void setUpNoticesForTitleLevelRequests(boolean isNoticeEnabledInTlrSettings,
boolean isNoticeEnabledInNoticePolicy) {

Expand Down
43 changes: 34 additions & 9 deletions src/test/java/api/support/builders/CirculationItemsBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class CirculationItemsBuilder extends JsonBuilder implements Builder {
private final UUID loanTypeId;
private final boolean isDcb;
private final String lendingLibraryCode;
private final String instanceTitle;

public CirculationItemsBuilder() {
this(UUID.randomUUID(),
Expand All @@ -23,7 +24,8 @@ public CirculationItemsBuilder() {
UUID.randomUUID(),
UUID.randomUUID(),
true,
"11223");
"11223",
null);
}

private CirculationItemsBuilder(
Expand All @@ -34,7 +36,8 @@ private CirculationItemsBuilder(
UUID materialTypeId,
UUID loanTypeId,
boolean isDcb,
String lendingLibraryCode) {
String lendingLibraryCode,
String instanceTitle) {

this.itemId = itemId;
this.barcode = barcode;
Expand All @@ -44,6 +47,7 @@ private CirculationItemsBuilder(
this.loanTypeId = loanTypeId;
this.isDcb = isDcb;
this.lendingLibraryCode = lendingLibraryCode;
this.instanceTitle = instanceTitle;
}

public JsonObject create() {
Expand All @@ -57,6 +61,7 @@ public JsonObject create() {
representation.put("temporaryLoanTypeId", loanTypeId);
representation.put("dcbItem", isDcb);
representation.put("lendingLibraryCode", lendingLibraryCode);
representation.put("instanceTitle", instanceTitle);

return representation;
}
Expand All @@ -70,7 +75,8 @@ public CirculationItemsBuilder withBarcode(String barcode) {
this.materialTypeId,
this.loanTypeId,
this.isDcb,
this.lendingLibraryCode);
this.lendingLibraryCode,
this.instanceTitle);
}

public CirculationItemsBuilder withHoldingId(UUID holdingId) {
Expand All @@ -82,7 +88,8 @@ public CirculationItemsBuilder withHoldingId(UUID holdingId) {
this.materialTypeId,
this.loanTypeId,
this.isDcb,
this.lendingLibraryCode);
this.lendingLibraryCode,
this.instanceTitle);
}

public CirculationItemsBuilder withItemId(UUID itemId) {
Expand All @@ -94,7 +101,8 @@ public CirculationItemsBuilder withItemId(UUID itemId) {
this.materialTypeId,
this.loanTypeId,
this.isDcb,
this.lendingLibraryCode);
this.lendingLibraryCode,
this.instanceTitle);
}

public CirculationItemsBuilder withLocationId(UUID locationId) {
Expand All @@ -106,7 +114,8 @@ public CirculationItemsBuilder withLocationId(UUID locationId) {
this.materialTypeId,
this.loanTypeId,
this.isDcb,
this.lendingLibraryCode);
this.lendingLibraryCode,
this.instanceTitle);
}

public CirculationItemsBuilder withLendingLibraryCode(String lendingLibraryCode) {
Expand All @@ -118,7 +127,8 @@ public CirculationItemsBuilder withLendingLibraryCode(String lendingLibraryCode)
this.materialTypeId,
this.loanTypeId,
this.isDcb,
lendingLibraryCode);
lendingLibraryCode,
this.instanceTitle);
}

public CirculationItemsBuilder withLoanType(UUID loanTypeId) {
Expand All @@ -130,7 +140,8 @@ public CirculationItemsBuilder withLoanType(UUID loanTypeId) {
this.materialTypeId,
loanTypeId,
this.isDcb,
this.lendingLibraryCode);
this.lendingLibraryCode,
this.instanceTitle);
}

public CirculationItemsBuilder withMaterialType(UUID materialTypeId) {
Expand All @@ -142,7 +153,21 @@ public CirculationItemsBuilder withMaterialType(UUID materialTypeId) {
materialTypeId,
this.loanTypeId,
this.isDcb,
this.lendingLibraryCode);
this.lendingLibraryCode,
this.instanceTitle);
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ public CirculationItemsFixture(
this.loanTypesFixture = loanTypesFixture;
}

public IndividualResource createCirculationItem(String barcode, UUID holdingId, UUID locationId) {
public IndividualResource createCirculationItem(String barcode, UUID holdingId, UUID locationId, String instanceTitle) {
CirculationItemsBuilder circulationItemsBuilder = new CirculationItemsBuilder().withBarcode(barcode).withHoldingId(holdingId)
.withLoanType(loanTypesFixture.canCirculate().getId()).withMaterialType(materialTypesFixture.book().getId())
.withLocationId(locationId);
.withLocationId(locationId).withInstanceTitle(instanceTitle);
return circulationItemClient.create(circulationItemsBuilder);
}

public IndividualResource createCirculationItemWithLandingLibrary(String barcode, UUID holdingId, UUID locationId, String landingLibrary) {
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())
.withLocationId(locationId).withLendingLibraryCode(landingLibrary);
.withLocationId(locationId).withLendingLibraryCode(lendingLibrary);
return circulationItemClient.create(circulationItemsBuilder);
}
}

0 comments on commit 87bebb0

Please sign in to comment.