Added additional logging 00/139200/5
authorsourabh_sourabh <sourabh.sourabh@est.tech>
Tue, 15 Oct 2024 11:11:16 +0000 (12:11 +0100)
committersourabh_sourabh <sourabh.sourabh@est.tech>
Tue, 15 Oct 2024 13:38:51 +0000 (14:38 +0100)
- Added logging for non existing xpath while updating data notes and its
  decendants.

Issue-ID: CPS-2403
Change-Id: I1ecaf2aed77aec8d266f6a758fe80ee96717d9c7
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
cps-ri/src/main/java/org/onap/cps/ri/CpsDataPersistenceServiceImpl.java

index ee555f7..ecbe447 100644 (file)
@@ -228,6 +228,9 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
 
         final Collection<String> xpaths = xpathToUpdatedDataNode.keySet();
         Collection<FragmentEntity> existingFragmentEntities = getFragmentEntities(anchorEntity, xpaths);
+
+        logMissingXPaths(xpaths, existingFragmentEntities);
+
         existingFragmentEntities = fragmentRepository.prefetchDescendantsOfFragmentEntities(
             FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS, existingFragmentEntities);
 
@@ -243,6 +246,19 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
         }
     }
 
+    private void logMissingXPaths(final Collection<String> xpaths, final Collection<FragmentEntity>
+            existingFragmentEntities) {
+        final Set<String> existingXPaths = existingFragmentEntities.stream().map(FragmentEntity::getXpath)
+                .collect(Collectors.toSet());
+
+        final Set<String> missingXPaths = xpaths.stream().filter(xpath -> !existingXPaths.contains(xpath))
+                .collect(Collectors.toSet());
+
+        if (!missingXPaths.isEmpty()) {
+            log.warn("Cannot update data nodes: Target XPaths {} not found in DB.", missingXPaths);
+        }
+    }
+
     private void retryUpdateDataNodesIndividually(final AnchorEntity anchorEntity,
                                                   final Collection<FragmentEntity> fragmentEntities) {
         final Collection<String> failedXpaths = new HashSet<>();