From 79a2328a5d81136da49b9ed4534c7388fdb3af4e Mon Sep 17 00:00:00 2001 From: SreejaMangarapu Date: Thu, 6 Jun 2024 15:51:44 +0530 Subject: [PATCH] CIRC-2084 renamed storage-loan-7-2.json to storage-loan-7-3.json and changes made in LoanRepository --- .../storage/loans/LoanRepository.java | 9 ++++++--- .../java/api/support/fakes/StorageSchema.java | 2 +- .../support/fixtures/CirculationItemsFixture.java | 15 +++++++++++---- ...torage-loan-7-2.json => storage-loan-7-3.json} | 0 4 files changed, 18 insertions(+), 8 deletions(-) rename src/test/resources/{storage-loan-7-2.json => storage-loan-7-3.json} (100%) diff --git a/src/main/java/org/folio/circulation/infrastructure/storage/loans/LoanRepository.java b/src/main/java/org/folio/circulation/infrastructure/storage/loans/LoanRepository.java index 145cc6e852..d804634fd9 100644 --- a/src/main/java/org/folio/circulation/infrastructure/storage/loans/LoanRepository.java +++ b/src/main/java/org/folio/circulation/infrastructure/storage/loans/LoanRepository.java @@ -298,9 +298,12 @@ private Result> mapResponseToLoans(Response response) { } private static void addIsDcbProperty(Loan loan, Item item, JsonObject storageLoan) { - write(storageLoan, IS_DCB, (nonNull(loan.getUser()) && nonNull(loan.getUser().getLastName()) - && loan.getUser().getLastName().equalsIgnoreCase(DCB_USER_LASTNAME)) - || item.isDcbItem()); + 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) { diff --git a/src/test/java/api/support/fakes/StorageSchema.java b/src/test/java/api/support/fakes/StorageSchema.java index 9f00695474..87aa34eac9 100644 --- a/src/test/java/api/support/fakes/StorageSchema.java +++ b/src/test/java/api/support/fakes/StorageSchema.java @@ -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 { diff --git a/src/test/java/api/support/fixtures/CirculationItemsFixture.java b/src/test/java/api/support/fixtures/CirculationItemsFixture.java index 61f236829b..2444d9d89e 100644 --- a/src/test/java/api/support/fixtures/CirculationItemsFixture.java +++ b/src/test/java/api/support/fixtures/CirculationItemsFixture.java @@ -27,10 +27,17 @@ 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); + 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); } diff --git a/src/test/resources/storage-loan-7-2.json b/src/test/resources/storage-loan-7-3.json similarity index 100% rename from src/test/resources/storage-loan-7-2.json rename to src/test/resources/storage-loan-7-3.json