From 87bebb05abcde25967a84439651880819a175c4d Mon Sep 17 00:00:00 2001 From: Vignesh <125984866+Vignesh-kalyanasundaram@users.noreply.github.com> Date: Mon, 12 Feb 2024 16:30:16 +0530 Subject: [PATCH] CIRC-2029 Returning DCB title in response if the item is a virtual item (#1423) (#1428) * CIRC-2029 Return dcb instance title for dcb item * CIRC-2029 Adding test case for checkin,checkout,loan and requests --- .../org/folio/circulation/domain/Item.java | 4 ++ .../domain/RequestRepresentation.java | 7 +-- .../domain/notice/TemplateContextUtil.java | 9 ++-- .../ItemSummaryRepresentation.java | 2 +- .../java/api/loans/CheckInByBarcodeTests.java | 8 +++- .../api/loans/CheckOutByBarcodeTests.java | 7 ++- src/test/java/api/loans/LoanAPITests.java | 7 ++- .../requests/RequestsAPICreationTests.java | 30 +++++++++++++ .../builders/CirculationItemsBuilder.java | 43 +++++++++++++++---- .../fixtures/CirculationItemsFixture.java | 8 ++-- 10 files changed, 100 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/folio/circulation/domain/Item.java b/src/main/java/org/folio/circulation/domain/Item.java index d4fba931d6..fef9d339d8 100644 --- a/src/main/java/org/folio/circulation/domain/Item.java +++ b/src/main/java/org/folio/circulation/domain/Item.java @@ -407,4 +407,8 @@ public boolean isDcbItem() { public String getLendingLibraryCode() { return getProperty(itemRepresentation, "lendingLibraryCode"); } + + public String getDcbItemTitle() { + return getProperty(itemRepresentation, "instanceTitle"); + } } diff --git a/src/main/java/org/folio/circulation/domain/RequestRepresentation.java b/src/main/java/org/folio/circulation/domain/RequestRepresentation.java index f1da0a4e41..005c2654f8 100644 --- a/src/main/java/org/folio/circulation/domain/RequestRepresentation.java +++ b/src/main/java/org/folio/circulation/domain/RequestRepresentation.java @@ -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()); @@ -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())); diff --git a/src/main/java/org/folio/circulation/domain/notice/TemplateContextUtil.java b/src/main/java/org/folio/circulation/domain/notice/TemplateContextUtil.java index 35db89db2c..b0e9b59d64 100644 --- a/src/main/java/org/folio/circulation/domain/notice/TemplateContextUtil.java +++ b/src/main/java/org/folio/circulation/domain/notice/TemplateContextUtil.java @@ -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()) @@ -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("; "))); } 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 91bc937c44..c689058e42 100644 --- a/src/main/java/org/folio/circulation/domain/representations/ItemSummaryRepresentation.java +++ b/src/main/java/org/folio/circulation/domain/representations/ItemSummaryRepresentation.java @@ -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()); diff --git a/src/test/java/api/loans/CheckInByBarcodeTests.java b/src/test/java/api/loans/CheckInByBarcodeTests.java index bac1af0d9d..7fabae974e 100644 --- a/src/test/java/api/loans/CheckInByBarcodeTests.java +++ b/src/test/java/api/loans/CheckInByBarcodeTests.java @@ -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", @@ -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 @@ -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(); diff --git a/src/test/java/api/loans/CheckOutByBarcodeTests.java b/src/test/java/api/loans/CheckOutByBarcodeTests.java index 74549cec35..d1171130c5 100644 --- a/src/test/java/api/loans/CheckOutByBarcodeTests.java +++ b/src/test/java/api/loans/CheckOutByBarcodeTests.java @@ -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() @@ -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)); diff --git a/src/test/java/api/loans/LoanAPITests.java b/src/test/java/api/loans/LoanAPITests.java index bc022d7b50..e42fb4eb9c 100644 --- a/src/test/java/api/loans/LoanAPITests.java +++ b/src/test/java/api/loans/LoanAPITests.java @@ -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 diff --git a/src/test/java/api/requests/RequestsAPICreationTests.java b/src/test/java/api/requests/RequestsAPICreationTests.java index 42c35155ec..716ce6a2ab 100644 --- a/src/test/java/api/requests/RequestsAPICreationTests.java +++ b/src/test/java/api/requests/RequestsAPICreationTests.java @@ -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) { diff --git a/src/test/java/api/support/builders/CirculationItemsBuilder.java b/src/test/java/api/support/builders/CirculationItemsBuilder.java index d3b5d6b84e..1ec177ec60 100644 --- a/src/test/java/api/support/builders/CirculationItemsBuilder.java +++ b/src/test/java/api/support/builders/CirculationItemsBuilder.java @@ -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(), @@ -23,7 +24,8 @@ public CirculationItemsBuilder() { UUID.randomUUID(), UUID.randomUUID(), true, - "11223"); + "11223", + null); } private CirculationItemsBuilder( @@ -34,7 +36,8 @@ private CirculationItemsBuilder( UUID materialTypeId, UUID loanTypeId, boolean isDcb, - String lendingLibraryCode) { + String lendingLibraryCode, + String instanceTitle) { this.itemId = itemId; this.barcode = barcode; @@ -44,6 +47,7 @@ private CirculationItemsBuilder( this.loanTypeId = loanTypeId; this.isDcb = isDcb; this.lendingLibraryCode = lendingLibraryCode; + this.instanceTitle = instanceTitle; } public JsonObject create() { @@ -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; } @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -118,7 +127,8 @@ public CirculationItemsBuilder withLendingLibraryCode(String lendingLibraryCode) this.materialTypeId, this.loanTypeId, this.isDcb, - lendingLibraryCode); + lendingLibraryCode, + this.instanceTitle); } public CirculationItemsBuilder withLoanType(UUID loanTypeId) { @@ -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) { @@ -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); } } diff --git a/src/test/java/api/support/fixtures/CirculationItemsFixture.java b/src/test/java/api/support/fixtures/CirculationItemsFixture.java index 3ff94568ca..10e69d57f4 100644 --- a/src/test/java/api/support/fixtures/CirculationItemsFixture.java +++ b/src/test/java/api/support/fixtures/CirculationItemsFixture.java @@ -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); } }