diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index e7bfceb7..b028594d 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -39,6 +39,12 @@ "version": "1.2" } ], + "optional": [ + { + "id": "circulation-item", + "version": "1.0" + } + ], "provides": [ { "id": "audit", @@ -152,7 +158,8 @@ "templates.item.get", "inventory.items.item.get", "inventory-storage.holdings.item.get", - "circulation-storage.cancellation-reasons.collection.get" + "circulation-storage.cancellation-reasons.collection.get", + "circulation-item.item.get" ] } ] diff --git a/mod-audit-server/src/main/java/org/folio/builder/service/LogRecordBuilder.java b/mod-audit-server/src/main/java/org/folio/builder/service/LogRecordBuilder.java index 517a1ab4..53e4355d 100644 --- a/mod-audit-server/src/main/java/org/folio/builder/service/LogRecordBuilder.java +++ b/mod-audit-server/src/main/java/org/folio/builder/service/LogRecordBuilder.java @@ -10,6 +10,7 @@ import static org.apache.commons.lang3.StringUtils.isEmpty; import static org.apache.commons.lang3.StringUtils.isNotEmpty; import static org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT; +import static org.folio.util.Constants.CIRCULATION_ITEM_URL; import static org.folio.util.Constants.HOLDINGS_URL; import static org.folio.util.Constants.ITEMS_URL; import static org.folio.util.Constants.TEMPLATES_URL; @@ -224,6 +225,8 @@ private void fetchUserPersonal(JsonObject payload, User user) { public CompletableFuture fetchItemDetails(JsonObject payload) { LOGGER.debug("fetchItemDetails:: Fetching Item Details"); return handleGetRequest(String.format(URL_WITH_ID_PATTERN, ITEMS_URL, getProperty(payload, ITEM_ID))) + .thenCompose(itemJson -> nonNull(itemJson) ? CompletableFuture.completedFuture(itemJson) : + handleGetRequest(String.format(URL_WITH_ID_PATTERN, CIRCULATION_ITEM_URL, getProperty(payload, ITEM_ID)))) .thenCompose(itemJson -> addItemData(payload, itemJson)) .thenCompose(json -> handleGetRequest(String.format(URL_WITH_ID_PATTERN, HOLDINGS_URL, getProperty(json, HOLDINGS_RECORD_ID)))) diff --git a/mod-audit-server/src/main/java/org/folio/util/Constants.java b/mod-audit-server/src/main/java/org/folio/util/Constants.java index f3cb9d89..c3071b16 100644 --- a/mod-audit-server/src/main/java/org/folio/util/Constants.java +++ b/mod-audit-server/src/main/java/org/folio/util/Constants.java @@ -4,6 +4,7 @@ public class Constants { private Constants(){} public static final String ITEMS_URL = "/inventory/items"; + public static final String CIRCULATION_ITEM_URL = "/circulation-item"; public static final String HOLDINGS_URL = "/holdings-storage/holdings"; public static final String TEMPLATES_URL = "/templates"; public static final String USERS_URL = "/users"; diff --git a/mod-audit-server/src/test/java/org/folio/rest/impl/CirculationLogsImplApiTest.java b/mod-audit-server/src/test/java/org/folio/rest/impl/CirculationLogsImplApiTest.java index 7865d7d5..ce39fe8a 100644 --- a/mod-audit-server/src/test/java/org/folio/rest/impl/CirculationLogsImplApiTest.java +++ b/mod-audit-server/src/test/java/org/folio/rest/impl/CirculationLogsImplApiTest.java @@ -48,7 +48,7 @@ void getCirculationAuditLogRecordsNoFilter() { logger.info("Get circulation audit log records: no filter"); given().headers(HEADERS).get(CIRCULATION_LOGS_ENDPOINT) .then().log().all().statusCode(200) - .assertThat().body("totalRecords", equalTo(25)); + .assertThat().body("totalRecords", equalTo(26)); } @Test @@ -115,6 +115,20 @@ void anonymizeLoanShouldRemoveUserDataFromRelatedRecords() { .and().body("logRecords[5].linkToIds.userId", is(emptyOrNullString())); } + @Test + void getFeeFineRelatedRecordOfVirtualItem() { + // For virtual item, holdingsId and instanceId needs to be present, then only FE validation will work. + // This record is already posted in beforeAll method so directly assert it using get endpoint with virtual item ID. + given().headers(HEADERS).get(CIRCULATION_LOGS_ENDPOINT + "?query=(items=100d10bf-2f06-4aa0-be15-0b95b2d9f9e4)") + .then().log().all().statusCode(200) + .assertThat() + .body("totalRecords", equalTo(1)) + .body("logRecords[0].items[0].itemBarcode", is("virtualItem")) + .and().body("logRecords[0].items[0].itemId", is("100d10bf-2f06-4aa0-be15-0b95b2d9f9e4")) + .and().body("logRecords[0].items[0].instanceId", is("5bf370e0-8cca-4d9c-82e4-5170ab2a0a39")) + .and().body("logRecords[0].items[0].holdingId", is("e3ff6133-b9a2-4d4c-a1c9-dc1867d4df19")); + } + @Test void getCirculationAuditLogRecordsMalformedQuery() { logger.info("get circulation audit log records: malformed query"); diff --git a/mod-audit-server/src/test/java/org/folio/utils/TenantApiTestUtil.java b/mod-audit-server/src/test/java/org/folio/utils/TenantApiTestUtil.java index 9428cc43..828a8e51 100644 --- a/mod-audit-server/src/test/java/org/folio/utils/TenantApiTestUtil.java +++ b/mod-audit-server/src/test/java/org/folio/utils/TenantApiTestUtil.java @@ -41,6 +41,7 @@ public class TenantApiTestUtil { public static final String MANUAL_BLOCK_UPDATED_PAYLOAD_JSON = "payloads/manual_block_updated.json"; public static final String MANUAL_BLOCK_DELETED_PAYLOAD_JSON = "payloads/manual_block_deleted.json"; public static final String FEE_FINE_PAYLOAD_JSON = "payloads/fee_fine_billed.json"; + public static final String FEE_FINE_VIRTUAL_ITEM_PAYLOAD_JSON = "payloads/fee_fine_billed_automated_virtual_item.json"; public static final String LOAN_PAYLOAD_JSON = "payloads/loan.json"; public static final String LOAN_ANONYMIZE_PAYLOAD_JSON = "payloads/anonymize_loan.json"; public static final String LOAN_AGE_TO_LOST_PAYLOAD_JSON = "payloads/loan_age_to_lost.json"; @@ -69,7 +70,7 @@ public class TenantApiTestUtil { public static final String ANONYMIZE_LOAN_CLOSED = "payloads/anonymize_loan_closed.json"; public static final List SAMPLES = Arrays.asList(CHECK_IN_PAYLOAD_JSON, CHECK_OUT_PAYLOAD_JSON, MANUAL_BLOCK_CREATED_PAYLOAD_JSON, MANUAL_BLOCK_UPDATED_PAYLOAD_JSON, MANUAL_BLOCK_DELETED_PAYLOAD_JSON, - FEE_FINE_PAYLOAD_JSON, LOAN_PAYLOAD_JSON, LOAN_AGE_TO_LOST_PAYLOAD_JSON, LOAN_WRONG_ACTION_JSON, LOAN_EMPTY_ACTION_JSON, NOTICE_PAYLOAD_JSON, + FEE_FINE_PAYLOAD_JSON, FEE_FINE_VIRTUAL_ITEM_PAYLOAD_JSON, LOAN_PAYLOAD_JSON, LOAN_AGE_TO_LOST_PAYLOAD_JSON, LOAN_WRONG_ACTION_JSON, LOAN_EMPTY_ACTION_JSON, NOTICE_PAYLOAD_JSON, REQUEST_CREATED_THROUGH_OVERRIDE_PAYLOAD_JSON, REQUEST_CREATED_PAYLOAD_JSON, REQUEST_EDITED_PAYLOAD_JSON, REQUEST_MOVED_PAYLOAD_JSON, REQUEST_REORDERED_PAYLOAD_JSON, REQUEST_CANCELLED_PAYLOAD_JSON, REQUEST_EXPIRED_PAYLOAD_JSON, ANONYMIZE_CHECK_OUT, ANONYMIZE_CHECK_IN, ANONYMIZE_LOAN_CLOSED); diff --git a/mod-audit-server/src/test/resources/mock_content.json b/mod-audit-server/src/test/resources/mock_content.json index 77a55be4..dc3eb051 100644 --- a/mod-audit-server/src/test/resources/mock_content.json +++ b/mod-audit-server/src/test/resources/mock_content.json @@ -88,6 +88,17 @@ "receivedPath": "mocks/item.json", "status": 200 }, + { + "url": "/inventory/items/100d10bf-2f06-4aa0-be15-0b95b2d9f9e4", + "method": "GET", + "status": 404 + }, + { + "url": "/circulation-item/100d10bf-2f06-4aa0-be15-0b95b2d9f9e4", + "method": "GET", + "receivedPath": "mocks/circulation-item.json", + "status": 200 + }, { "url": "/inventory/items/e038e283-4104-455d-80b7-e6d05ca4e5a7", "method": "GET", diff --git a/mod-audit-server/src/test/resources/mocks/circulation-item.json b/mod-audit-server/src/test/resources/mocks/circulation-item.json new file mode 100644 index 00000000..dccc3249 --- /dev/null +++ b/mod-audit-server/src/test/resources/mocks/circulation-item.json @@ -0,0 +1,4 @@ +{ + "barcode": "virtualItem", + "holdingsRecordId" : "e3ff6133-b9a2-4d4c-a1c9-dc1867d4df19" +} diff --git a/mod-audit-server/src/test/resources/payloads/fee_fine_billed_automated_virtual_item.json b/mod-audit-server/src/test/resources/payloads/fee_fine_billed_automated_virtual_item.json new file mode 100644 index 00000000..e26b8979 --- /dev/null +++ b/mod-audit-server/src/test/resources/payloads/fee_fine_billed_automated_virtual_item.json @@ -0,0 +1,20 @@ +{ + "logEventType":"FEE_FINE", + "payload": { + "userId":"6f36265e-722a-490a-b436-806e63af2ea7", + "userBarcode":"693787594998493", + "itemBarcode":"virtualItem", + "itemId":"100d10bf-2f06-4aa0-be15-0b95b2d9f9e4", + "action":"Billed", + "comments": "Comments from Staff", + "date":"2020-10-15T12:17:38.627Z", + "servicePointId":"7c5abc9f-f3d7-4856-b8d7-6712462ca007", + "source":"ADMINISTRATOR, DIKU", + "feeFineId":"7ad9dfa0-6ee9-43ba-8db5-7a034ce05838", + "feeFineOwner":"sample owner", + "loanId":"0", + "automated":true, + "type":"manual charge", + "amount":10.0 + } +}