Repository: folio-org/mod-linked-data
Pull request #162: MODLD-707: Optimize log messages
Author: login: askhat-abishev
Created: 2025-04-14T08:58:23Z | Merged: 2025-04-15T10:41:55Z



Diff:
diff --git a/NEWS.md b/NEWS.md
index 6baa45ab5..21504f627 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,6 @@
+## 1.0.3 (IN PROGRESS)
+- Optimize log messages [MODLD-707](https://folio-org.atlassian.net/browse/MODLD-707)
+
 ## 1.0.2 (04-13-2025)
 - "targetAudience", "geographicCoverage" links contain https instead of http [MODLD-695](https://folio-org.atlassian.net/browse/MODLD-695)
 - Bump up lib-linked-data-marc4ld version to [1.0.3](https://github.com/folio-org/lib-linked-data-marc4ld/tree/v1.0.3)
diff --git a/src/main/java/org/folio/linked/data/integration/ResourceModificationEventListener.java b/src/main/java/org/folio/linked/data/integration/ResourceModificationEventListener.java
index bf1315336..e49240339 100644
--- a/src/main/java/org/folio/linked/data/integration/ResourceModificationEventListener.java
+++ b/src/main/java/org/folio/linked/data/integration/ResourceModificationEventListener.java
@@ -1,6 +1,7 @@
 package org.folio.linked.data.integration;
 
 import static org.folio.linked.data.util.Constants.STANDALONE_PROFILE;
+import static org.folio.linked.data.util.ResourceUtils.getTypes;
 
 import java.util.Collection;
 import lombok.RequiredArgsConstructor;
@@ -36,35 +37,46 @@ public class ResourceModificationEventListener {
 
   @TransactionalEventListener
   public void afterCreate(ResourceCreatedEvent resourceCreatedEvent) {
-    log.info("ResourceCreatedEvent received [{}]", resourceCreatedEvent);
-    createMessageSenders.forEach(sender -> sender.produce(resourceCreatedEvent.resource()));
+    var resource = resourceCreatedEvent.resource();
+    log.debug("ResourceCreatedEvent received [{}]", resourceCreatedEvent);
+    log.info("Resource with id {} and types {} was created", resource.getId(), getTypes(resource));
+    createMessageSenders.forEach(sender -> sender.produce(resource));
   }
 
   @TransactionalEventListener
   public void afterUpdate(ResourceUpdatedEvent resourceUpdatedEvent) {
-    log.info("ResourceUpdatedEvent received [{}]", resourceUpdatedEvent);
-    updateMessageSenders.forEach(sender -> sender.produce(resourceUpdatedEvent.resource()));
+    var resource = resourceUpdatedEvent.resource();
+    log.debug("ResourceUpdatedEvent received [{}]", resourceUpdatedEvent);
+    log.info("Resource with id {} and types {} was updated", resource.getId(), getTypes(resource));
+    updateMessageSenders.forEach(sender -> sender.produce(resource));
   }
 
   @TransactionalEventListener
   public void afterReplace(ResourceReplacedEvent resourceReplacedEvent) {
-    log.info("ResourceReplacedEvent received [{}]", resourceReplacedEvent);
-    resourceRepository.findById(resourceReplacedEvent.currentResourceId())
+    var previous = resourceReplacedEvent.previous();
+    var currentResourceId = resourceReplacedEvent.currentResourceId();
+    log.debug("ResourceReplacedEvent received [{}]", resourceReplacedEvent);
+    log.info("Resource with id {} and types {} was replaced by resource with id {}",
+      previous.getId(), getTypes(previous), currentResourceId);
+    resourceRepository.findById(currentResourceId)
       .ifPresent(
-        resource -> replaceMessageSenders.forEach(sender -> sender.produce(resourceReplacedEvent.previous(), resource))
+        resource -> replaceMessageSenders.forEach(sender -> sender.produce(previous, resource))
       );
   }
 
   @TransactionalEventListener
   public void afterDelete(ResourceDeletedEvent resourceDeletedEvent) {
-    log.info("ResourceDeletedEvent received [{}]", resourceDeletedEvent);
-    deleteMessageSenders.forEach(sender -> sender.produce(resourceDeletedEvent.resource()));
+    var resource = resourceDeletedEvent.resource();
+    log.debug("ResourceDeletedEvent received [{}]", resourceDeletedEvent);
+    log.info("Resource with id {} and types {} was deleted", resource.getId(), getTypes(resource));
+    deleteMessageSenders.forEach(sender -> sender.produce(resource));
   }
 
   @EventListener
   @Transactional(propagation = Propagation.REQUIRES_NEW)
   public void afterIndex(ResourceIndexedEvent resourceIndexedEvent) {
-    log.info("ResourceIndexedEvent received [{}]", resourceIndexedEvent);
+    log.debug("ResourceIndexedEvent received [{}]", resourceIndexedEvent);
+    log.info("Resource with id {} was indexed", resourceIndexedEvent.resourceId());
     resourceRepository.updateIndexDate(resourceIndexedEvent.resourceId());
   }
 }
diff --git a/src/main/java/org/folio/linked/data/util/ResourceUtils.java b/src/main/java/org/folio/linked/data/util/ResourceUtils.java
index 98984a362..297a28e33 100644
--- a/src/main/java/org/folio/linked/data/util/ResourceUtils.java
+++ b/src/main/java/org/folio/linked/data/util/ResourceUtils.java
@@ -31,6 +31,7 @@
 import org.folio.linked.data.domain.dto.TitleFieldRequestTitleInner;
 import org.folio.linked.data.model.entity.Resource;
 import org.folio.linked.data.model.entity.ResourceEdge;
+import org.folio.linked.data.model.entity.ResourceTypeEntity;
 
 @Log4j2
 @UtilityClass
@@ -152,4 +153,11 @@ public static boolean isPreferred(Resource resource) {
       .filter(value -> value.equals("true"))
       .isPresent();
   }
+
+  public static List<String> getTypes(Resource resource) {
+    return resource.getTypes()
+      .stream()
+      .map(ResourceTypeEntity::getUri)
+      .toList();
+  }
 }
diff --git a/src/test/java/org/folio/linked/data/util/ResourceUtilsTest.java b/src/test/java/org/folio/linked/data/util/ResourceUtilsTest.java
index c13becfe2..d96e307d5 100644
--- a/src/test/java/org/folio/linked/data/util/ResourceUtilsTest.java
+++ b/src/test/java/org/folio/linked/data/util/ResourceUtilsTest.java
@@ -2,18 +2,24 @@
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.folio.ld.dictionary.PredicateDictionary.INSTANTIATES;
+import static org.folio.ld.dictionary.ResourceTypeDictionary.CONCEPT;
 import static org.folio.ld.dictionary.ResourceTypeDictionary.INSTANCE;
 import static org.folio.ld.dictionary.ResourceTypeDictionary.JURISDICTION;
+import static org.folio.ld.dictionary.ResourceTypeDictionary.PERSON;
 import static org.folio.ld.dictionary.ResourceTypeDictionary.WORK;
 
 import com.google.common.collect.Lists;
 import java.util.List;
 import java.util.UUID;
 import java.util.function.Supplier;
+import java.util.stream.Stream;
 import org.folio.linked.data.model.entity.Resource;
 import org.folio.linked.data.model.entity.ResourceEdge;
 import org.folio.spring.testing.type.UnitTest;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 
 @UnitTest
 class ResourceUtilsTest {
@@ -191,4 +197,21 @@ void test_isPreferred_when_preferred_flag_is_set_as_false() {
     // then
     assertThat(ResourceUtils.isPreferred(resource)).isFalse();
   }
+
+  @ParameterizedTest
+  @MethodSource("dataProvider")
+  void getTypes_shouldReturn_resourceTypes(Resource resource, List<String> expectedTypes) {
+    // expect
+    assertThat(ResourceUtils.getTypes(resource))
+      .containsExactlyInAnyOrderElementsOf(expectedTypes);
+  }
+
+  private static Stream<Arguments> dataProvider() {
+    return Stream.of(
+      Arguments.of(new Resource().addTypes(INSTANCE), List.of("http://bibfra.me/vocab/lite/Instance")),
+      Arguments.of(new Resource().addTypes(WORK), List.of("http://bibfra.me/vocab/lite/Work")),
+      Arguments.of(new Resource().addTypes(CONCEPT, PERSON),
+        List.of("http://bibfra.me/vocab/lite/Concept", "http://bibfra.me/vocab/lite/Person"))
+    );
+  }
 }


Reviews:
user: login: pkjacob
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-14T12:25:28Z
user: login: askhat-abishev
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-15T09:01:05Z
user: login: AndreiBordak
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-15T09:38:04Z
user: login: PBobylev
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-15T10:09:11Z
user: login: pkjacob
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-15T10:33:17Z

Review comments:
diff_hunk: @@ -152,4 +153,12 @@ public static boolean isPreferred(Resource resource) {
       .filter(value -> value.equals("true"))
       .isPresent();
   }
+
+  public static String getType(Resource resource) {
+    return resource.getTypes()
+      .stream()
+      .map(ResourceTypeEntity::getUri)
+      .findFirst()
path: src/main/java/org/folio/linked/data/util/ResourceUtils.java
user: login: pkjacob
body: Let us return all the types from here. Method name can be changed to `public static List<String> getTypes(...)`
created_at: 2025-04-14T12:25:28Z
author_association: CONTRIBUTOR
diff_hunk: @@ -152,4 +153,12 @@ public static boolean isPreferred(Resource resource) {
       .filter(value -> value.equals("true"))
       .isPresent();
   }
+
+  public static String getType(Resource resource) {
+    return resource.getTypes()
+      .stream()
+      .map(ResourceTypeEntity::getUri)
+      .findFirst()
path: src/main/java/org/folio/linked/data/util/ResourceUtils.java
user: login: askhat-abishev
body: done
created_at: 2025-04-15T09:01:04Z
author_association: CONTRIBUTOR

PR comments:
user: login: sonarqubecloud[bot]
created_at: 2025-04-15T09:25:40Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=org.folio%3Amod-linked-data&pullRequest=162) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=org.folio%3Amod-linked-data&pullRequest=162&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=org.folio%3Amod-linked-data&pullRequest=162&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=org.folio%3Amod-linked-data&pullRequest=162&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=org.folio%3Amod-linked-data&pullRequest=162&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=org.folio%3Amod-linked-data&pullRequest=162&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=org.folio%3Amod-linked-data&pullRequest=162)


author_association: NONE