From 9a68f1b22d4ba7adc5236d44a79ff1bb9785cbd0 Mon Sep 17 00:00:00 2001 From: Arghya22 Date: Wed, 1 Feb 2023 11:58:43 +0530 Subject: [PATCH 1/7] [MODAUD-154] 1. logs added --- .../main/java/org/folio/rest/impl/AuditHandlersService.java | 5 +++++ .../java/org/folio/rest/impl/CirculationLogsService.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/mod-audit-server/src/main/java/org/folio/rest/impl/AuditHandlersService.java b/mod-audit-server/src/main/java/org/folio/rest/impl/AuditHandlersService.java index 8ea8867e..4c17ee1f 100644 --- a/mod-audit-server/src/main/java/org/folio/rest/impl/AuditHandlersService.java +++ b/mod-audit-server/src/main/java/org/folio/rest/impl/AuditHandlersService.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.CompletableFuture; import javax.ws.rs.core.Response; @@ -88,6 +89,10 @@ private CompletableFuture> anonymizeLoanRelatedRecords(List saveLogRecords(List logRecords, Map okapiHeaders, Context vertxContext) { + if(!logRecords.isEmpty()){ + logRecords.forEach(recordData-> LOGGER.info("saveLogRecords :: saved record userBarcode :{} & description is :{}", + recordData.getUserBarcode(),recordData.getDescription())); + } CompletableFuture future = new CompletableFuture<>(); getClient(okapiHeaders, vertxContext).upsertBatch(LOGS_TABLE_NAME, logRecords, reply -> { if (reply.failed()) { diff --git a/mod-audit-server/src/main/java/org/folio/rest/impl/CirculationLogsService.java b/mod-audit-server/src/main/java/org/folio/rest/impl/CirculationLogsService.java index 2703c7d2..a8f4dd8e 100644 --- a/mod-audit-server/src/main/java/org/folio/rest/impl/CirculationLogsService.java +++ b/mod-audit-server/src/main/java/org/folio/rest/impl/CirculationLogsService.java @@ -10,6 +10,8 @@ import javax.ws.rs.core.Response; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.folio.rest.annotations.Validate; import org.folio.rest.jaxrs.model.LogRecord; import org.folio.rest.jaxrs.model.LogRecordCollection; @@ -21,6 +23,7 @@ public class CirculationLogsService extends BaseService implements AuditDataCirculation { public static final String LOGS_TABLE_NAME = "circulation_logs"; + private static final Logger LOGGER = LogManager.getLogger(); @Override @Validate @@ -31,6 +34,8 @@ public void getAuditDataCirculationLogs(String query, int offset, int limit, Str .get(LOGS_TABLE_NAME, LogRecord.class, new String[] { "*" }, cqlWrapper, true, false, reply -> { if (reply.succeeded()) { var results = reply.result().getResults(); + results.forEach(logData-> LOGGER.info("get record while fetching userBarcode :{} & description is:{}", + logData.getUserBarcode(),logData.getDescription())); results.stream().filter(logRecord -> isNull(logRecord.getUserBarcode())) .forEach(logRecord -> logRecord.setUserBarcode(NO_BARCODE)); asyncResultHandler.handle(succeededFuture(GetAuditDataCirculationLogsResponse From f753b604e2d8336022c14fdd08b77648d75e760e Mon Sep 17 00:00:00 2001 From: Arghya22 Date: Fri, 3 Feb 2023 11:41:13 +0530 Subject: [PATCH 2/7] [MODAUD-154] 1. logs added --- .../src/main/java/org/folio/rest/impl/AuditHandlersService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/mod-audit-server/src/main/java/org/folio/rest/impl/AuditHandlersService.java b/mod-audit-server/src/main/java/org/folio/rest/impl/AuditHandlersService.java index 4c17ee1f..34f1c7f5 100644 --- a/mod-audit-server/src/main/java/org/folio/rest/impl/AuditHandlersService.java +++ b/mod-audit-server/src/main/java/org/folio/rest/impl/AuditHandlersService.java @@ -36,6 +36,7 @@ public void postAuditHandlersLogRecord(String entity, Map okapiH Handler> asyncResultHandler, Context vertxContext) { try { JsonObject payload = new JsonObject(entity); + LOGGER.info("input payload :{}",payload); LogRecordBuilder builder = LogRecordBuilderResolver.getBuilder(payload.getString(LOG_EVENT_TYPE.value()), okapiHeaders, vertxContext); builder.buildLogRecord(payload) .thenCompose(logRecords -> processAnonymize(logRecords, okapiHeaders, vertxContext)) From ad08c98142d3b67ff6d9cda92a8d24c2e93ac061 Mon Sep 17 00:00:00 2001 From: Arghya22 Date: Thu, 9 Feb 2023 11:52:17 +0530 Subject: [PATCH 3/7] [MODAUD-154] 1. For billed comments will be added 2. Test case updated --- .../main/java/org/folio/builder/description/Descriptions.java | 2 +- .../folio/builder/description/FeeFineDescriptionBuilder.java | 3 ++- .../java/org/folio/builder/service/FeeFineDescriptions.java | 2 +- .../org/folio/builder/service/FeeFineRecordBuilderTest.java | 2 +- .../src/test/resources/payloads/fee_fine_billed.json | 1 + 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mod-audit-server/src/main/java/org/folio/builder/description/Descriptions.java b/mod-audit-server/src/main/java/org/folio/builder/description/Descriptions.java index 26b59e95..03ba6b9c 100644 --- a/mod-audit-server/src/main/java/org/folio/builder/description/Descriptions.java +++ b/mod-audit-server/src/main/java/org/folio/builder/description/Descriptions.java @@ -9,7 +9,7 @@ public class Descriptions { public static final String CLAIMED_RETURNED_ITEM_MSG = " . Claimed returned item: "; public static final String BACKDATED_TO_MSG = ". Backdated to: "; public static final String OVERDUE_DUE_DATE_MSG = ". Overdue due date: "; - public static final String BILLED_MSG = "Fee/Fine type: %s. Fee/Fine owner: %s. Amount: %.2f. %s"; + public static final String BILLED_MSG = "Fee/Fine type: %s. Fee/Fine owner: %s. Amount: %.2f. %s. Additional information to staff: %s"; public static final String CANCELLED_MSG = "Amount: %.2f. Cancellation reason: %s. Additional information to patron: %s."; public static final String FEE_FINE_PAID_MSG = "Fee/Fine type: %s. Amount: %.2f. Balance: %.2f. Payment method: %s. Additional information to staff: %s. Additional information to patron: %s."; public static final String FEE_FINE_WAIVED_MSG = "Fee/Fine type: %s. Amount: %.2f. Balance: %.2f. Waive reason: %s. Additional information to staff: %s. Additional information to patron: %s."; diff --git a/mod-audit-server/src/main/java/org/folio/builder/description/FeeFineDescriptionBuilder.java b/mod-audit-server/src/main/java/org/folio/builder/description/FeeFineDescriptionBuilder.java index d2a5feb7..58d5e174 100644 --- a/mod-audit-server/src/main/java/org/folio/builder/description/FeeFineDescriptionBuilder.java +++ b/mod-audit-server/src/main/java/org/folio/builder/description/FeeFineDescriptionBuilder.java @@ -47,7 +47,8 @@ public String buildDescription(JsonObject logEventPayload) { getProperty(logEventPayload, TYPE), getProperty(logEventPayload, FEE_FINE_OWNER), getDoubleProperty(logEventPayload, AMOUNT), - getBooleanProperty(logEventPayload, AUTOMATED) ? "automated" : "manual"); + getBooleanProperty(logEventPayload, AUTOMATED) ? "automated" : "manual", + getProperty(logEventPayload, COMMENTS)); case PAID_FULLY: case PAID_PARTIALLY: return createDescriptionFor(FEE_FINE_PAID_MSG, logEventPayload); diff --git a/mod-audit-server/src/test/java/org/folio/builder/service/FeeFineDescriptions.java b/mod-audit-server/src/test/java/org/folio/builder/service/FeeFineDescriptions.java index 4f6499a9..aabb9c5f 100644 --- a/mod-audit-server/src/test/java/org/folio/builder/service/FeeFineDescriptions.java +++ b/mod-audit-server/src/test/java/org/folio/builder/service/FeeFineDescriptions.java @@ -2,7 +2,7 @@ public enum FeeFineDescriptions { BILLED("{\"userId\":\"6f36265e-722a-490a-b436-806e63af2ea7\",\"userBarcode\":\"693787594998493\",\"itemBarcode\":\"90000\",\"action\":\"Billed\",\"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\":false,\"type\":\"manual charge\",\"paymentMethod\":\"cash\",\"amount\":10.0,\"balance\":0.0,\"comments\":\"STAFF : staff info \\n PATRON : patron info\"}", - "Fee/Fine type: manual charge. Fee/Fine owner: sample owner. Amount: 10.00. manual"), + "Fee/Fine type: manual charge. Fee/Fine owner: sample owner. Amount: 10.00. manual. Additional information to staff: STAFF : staff info \n PATRON : patron info"), CANCELLED("{\"userId\":\"6f36265e-722a-490a-b436-806e63af2ea7\",\"userBarcode\":\"693787594998493\",\"itemBarcode\":\"90000\",\"action\":\"Cancelled as error\",\"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\":false,\"type\":\"Paid fully\",\"paymentMethod\":\"cash\",\"amount\":10.0,\"balance\":0.0,\"comments\":\"STAFF : sample reason \\n PATRON : patron info\"}", "Amount: 10.00. Cancellation reason: sample reason. Additional information to patron: patron info."), PAID("{\"userId\":\"6f36265e-722a-490a-b436-806e63af2ea7\",\"userBarcode\":\"693787594998493\",\"itemBarcode\":\"90000\",\"action\":\"Paid fully\",\"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\":false,\"type\":\"cash\",\"paymentMethod\":\"cash\",\"amount\":10.0,\"balance\":0.0,\"comments\":\"STAFF : staff info \\n PATRON : patron info\"}", diff --git a/mod-audit-server/src/test/java/org/folio/builder/service/FeeFineRecordBuilderTest.java b/mod-audit-server/src/test/java/org/folio/builder/service/FeeFineRecordBuilderTest.java index 6278a6a7..73a5d75b 100644 --- a/mod-audit-server/src/test/java/org/folio/builder/service/FeeFineRecordBuilderTest.java +++ b/mod-audit-server/src/test/java/org/folio/builder/service/FeeFineRecordBuilderTest.java @@ -46,7 +46,7 @@ void testFeeFine() throws Exception { assertThat(feeFineLogRecord.getServicePointId(), equalTo("7c5abc9f-f3d7-4856-b8d7-6712462ca007")); assertThat(feeFineLogRecord.getSource(), equalTo("ADMINISTRATOR, DIKU")); assertThat(feeFineLogRecord.getDescription(), - equalTo("Fee/Fine type: manual charge. Fee/Fine owner: sample owner. Amount: 10.00. manual")); + equalTo("Fee/Fine type: manual charge. Fee/Fine owner: sample owner. Amount: 10.00. manual. Additional information to staff: Comments from Staff")); } @ParameterizedTest diff --git a/mod-audit-server/src/test/resources/payloads/fee_fine_billed.json b/mod-audit-server/src/test/resources/payloads/fee_fine_billed.json index 7710770a..6e22b8e7 100644 --- a/mod-audit-server/src/test/resources/payloads/fee_fine_billed.json +++ b/mod-audit-server/src/test/resources/payloads/fee_fine_billed.json @@ -6,6 +6,7 @@ "itemBarcode":"90000", "itemId":"100d10bf-2f06-4aa0-be15-0b95b2d9f9e3", "action":"Billed", + "comments": "Comments from Staff", "date":"2020-10-15T12:17:38.627Z", "servicePointId":"7c5abc9f-f3d7-4856-b8d7-6712462ca007", "source":"ADMINISTRATOR, DIKU", From 7a21175609b4ac69baccdc4a54e7909d95359d95 Mon Sep 17 00:00:00 2001 From: Arghya22 Date: Thu, 9 Feb 2023 16:42:05 +0530 Subject: [PATCH 4/7] [MODAUD-154] 1. removed unused code --- .../main/java/org/folio/rest/impl/AuditHandlersService.java | 6 ------ .../java/org/folio/rest/impl/CirculationLogsService.java | 2 -- 2 files changed, 8 deletions(-) diff --git a/mod-audit-server/src/main/java/org/folio/rest/impl/AuditHandlersService.java b/mod-audit-server/src/main/java/org/folio/rest/impl/AuditHandlersService.java index 34f1c7f5..8ea8867e 100644 --- a/mod-audit-server/src/main/java/org/folio/rest/impl/AuditHandlersService.java +++ b/mod-audit-server/src/main/java/org/folio/rest/impl/AuditHandlersService.java @@ -7,7 +7,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.concurrent.CompletableFuture; import javax.ws.rs.core.Response; @@ -36,7 +35,6 @@ public void postAuditHandlersLogRecord(String entity, Map okapiH Handler> asyncResultHandler, Context vertxContext) { try { JsonObject payload = new JsonObject(entity); - LOGGER.info("input payload :{}",payload); LogRecordBuilder builder = LogRecordBuilderResolver.getBuilder(payload.getString(LOG_EVENT_TYPE.value()), okapiHeaders, vertxContext); builder.buildLogRecord(payload) .thenCompose(logRecords -> processAnonymize(logRecords, okapiHeaders, vertxContext)) @@ -90,10 +88,6 @@ private CompletableFuture> anonymizeLoanRelatedRecords(List saveLogRecords(List logRecords, Map okapiHeaders, Context vertxContext) { - if(!logRecords.isEmpty()){ - logRecords.forEach(recordData-> LOGGER.info("saveLogRecords :: saved record userBarcode :{} & description is :{}", - recordData.getUserBarcode(),recordData.getDescription())); - } CompletableFuture future = new CompletableFuture<>(); getClient(okapiHeaders, vertxContext).upsertBatch(LOGS_TABLE_NAME, logRecords, reply -> { if (reply.failed()) { diff --git a/mod-audit-server/src/main/java/org/folio/rest/impl/CirculationLogsService.java b/mod-audit-server/src/main/java/org/folio/rest/impl/CirculationLogsService.java index a8f4dd8e..3c130628 100644 --- a/mod-audit-server/src/main/java/org/folio/rest/impl/CirculationLogsService.java +++ b/mod-audit-server/src/main/java/org/folio/rest/impl/CirculationLogsService.java @@ -34,8 +34,6 @@ public void getAuditDataCirculationLogs(String query, int offset, int limit, Str .get(LOGS_TABLE_NAME, LogRecord.class, new String[] { "*" }, cqlWrapper, true, false, reply -> { if (reply.succeeded()) { var results = reply.result().getResults(); - results.forEach(logData-> LOGGER.info("get record while fetching userBarcode :{} & description is:{}", - logData.getUserBarcode(),logData.getDescription())); results.stream().filter(logRecord -> isNull(logRecord.getUserBarcode())) .forEach(logRecord -> logRecord.setUserBarcode(NO_BARCODE)); asyncResultHandler.handle(succeededFuture(GetAuditDataCirculationLogsResponse From cb4400fc74adc94c0bf0db88507472ee47f45054 Mon Sep 17 00:00:00 2001 From: Arghya22 Date: Thu, 9 Feb 2023 17:08:25 +0530 Subject: [PATCH 5/7] [MODAUD-154] 1. removed unused code --- .../main/java/org/folio/rest/impl/CirculationLogsService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/mod-audit-server/src/main/java/org/folio/rest/impl/CirculationLogsService.java b/mod-audit-server/src/main/java/org/folio/rest/impl/CirculationLogsService.java index 3c130628..5a3ff81b 100644 --- a/mod-audit-server/src/main/java/org/folio/rest/impl/CirculationLogsService.java +++ b/mod-audit-server/src/main/java/org/folio/rest/impl/CirculationLogsService.java @@ -23,7 +23,6 @@ public class CirculationLogsService extends BaseService implements AuditDataCirculation { public static final String LOGS_TABLE_NAME = "circulation_logs"; - private static final Logger LOGGER = LogManager.getLogger(); @Override @Validate From 083301df3388cfb3422955c22d06c9805474e42e Mon Sep 17 00:00:00 2001 From: Arghya22 Date: Thu, 9 Feb 2023 17:11:55 +0530 Subject: [PATCH 6/7] [MODAUD-154] 1. removed unused code --- .../main/java/org/folio/rest/impl/CirculationLogsService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/mod-audit-server/src/main/java/org/folio/rest/impl/CirculationLogsService.java b/mod-audit-server/src/main/java/org/folio/rest/impl/CirculationLogsService.java index 5a3ff81b..2703c7d2 100644 --- a/mod-audit-server/src/main/java/org/folio/rest/impl/CirculationLogsService.java +++ b/mod-audit-server/src/main/java/org/folio/rest/impl/CirculationLogsService.java @@ -10,8 +10,6 @@ import javax.ws.rs.core.Response; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.folio.rest.annotations.Validate; import org.folio.rest.jaxrs.model.LogRecord; import org.folio.rest.jaxrs.model.LogRecordCollection; From 65f6817117daaf105dee5589657eb53be6555fd6 Mon Sep 17 00:00:00 2001 From: Arghya22 Date: Fri, 10 Feb 2023 16:41:13 +0530 Subject: [PATCH 7/7] [MODAUD-154] 1. test case updated --- .../service/FeeFineRecordBuilderTest.java | 11 ++++--- .../folio/builder/service/FeeFineUtil.java | 30 +++++++++++++++++++ .../payloads/fee_fine_billed_automated.json | 20 +++++++++++++ 3 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 mod-audit-server/src/test/java/org/folio/builder/service/FeeFineUtil.java create mode 100644 mod-audit-server/src/test/resources/payloads/fee_fine_billed_automated.json diff --git a/mod-audit-server/src/test/java/org/folio/builder/service/FeeFineRecordBuilderTest.java b/mod-audit-server/src/test/java/org/folio/builder/service/FeeFineRecordBuilderTest.java index 73a5d75b..cceef294 100644 --- a/mod-audit-server/src/test/java/org/folio/builder/service/FeeFineRecordBuilderTest.java +++ b/mod-audit-server/src/test/java/org/folio/builder/service/FeeFineRecordBuilderTest.java @@ -1,7 +1,6 @@ package org.folio.builder.service; import static org.folio.rest.jaxrs.model.LogRecord.Action.BILLED; -import static org.folio.utils.TenantApiTestUtil.FEE_FINE_PAYLOAD_JSON; import static org.folio.utils.TenantApiTestUtil.getFile; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; @@ -15,7 +14,6 @@ import org.apache.logging.log4j.Logger; import org.folio.builder.description.FeeFineDescriptionBuilder; import org.folio.rest.jaxrs.model.LogRecord; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; @@ -24,11 +22,12 @@ public class FeeFineRecordBuilderTest extends BuilderTestBase { private static final Logger logger = LogManager.getLogger(); - @Test - void testFeeFine() throws Exception { + @ParameterizedTest + @EnumSource(FeeFineUtil.class) + void testFeeFine(FeeFineUtil feeFineUtil) throws Exception { logger.info("===== Test fees/fines log records builder ====="); - JsonObject payload = new JsonObject(getFile(FEE_FINE_PAYLOAD_JSON)); + JsonObject payload = new JsonObject(getFile(feeFineUtil.getFileName())); List records = feeFineRecordBuilder.buildLogRecord(payload).get(); assertThat(records.size(), equalTo(1)); @@ -46,7 +45,7 @@ void testFeeFine() throws Exception { assertThat(feeFineLogRecord.getServicePointId(), equalTo("7c5abc9f-f3d7-4856-b8d7-6712462ca007")); assertThat(feeFineLogRecord.getSource(), equalTo("ADMINISTRATOR, DIKU")); assertThat(feeFineLogRecord.getDescription(), - equalTo("Fee/Fine type: manual charge. Fee/Fine owner: sample owner. Amount: 10.00. manual. Additional information to staff: Comments from Staff")); + equalTo("Fee/Fine type: manual charge. Fee/Fine owner: sample owner. Amount: 10.00. "+ feeFineUtil.getType() +". Additional information to staff: Comments from Staff")); } @ParameterizedTest diff --git a/mod-audit-server/src/test/java/org/folio/builder/service/FeeFineUtil.java b/mod-audit-server/src/test/java/org/folio/builder/service/FeeFineUtil.java new file mode 100644 index 00000000..0ea0ceb0 --- /dev/null +++ b/mod-audit-server/src/test/java/org/folio/builder/service/FeeFineUtil.java @@ -0,0 +1,30 @@ +package org.folio.builder.service; + +public enum FeeFineUtil { + + MANUAL("payloads/fee_fine_billed.json","manual"), + AUTOMATED("payloads/fee_fine_billed_automated.json","automated"); + private String fileName; + private String type; + + FeeFineUtil(String fileName, String type) { + this.fileName = fileName; + this.type = type; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/mod-audit-server/src/test/resources/payloads/fee_fine_billed_automated.json b/mod-audit-server/src/test/resources/payloads/fee_fine_billed_automated.json new file mode 100644 index 00000000..fac7892c --- /dev/null +++ b/mod-audit-server/src/test/resources/payloads/fee_fine_billed_automated.json @@ -0,0 +1,20 @@ +{ + "logEventType":"FEE_FINE", + "payload": { + "userId":"6f36265e-722a-490a-b436-806e63af2ea7", + "userBarcode":"693787594998493", + "itemBarcode":"90000", + "itemId":"100d10bf-2f06-4aa0-be15-0b95b2d9f9e3", + "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 + } +}