Skip deleting list xpaths that are list elements
[cps.git] / cps-ri / src / main / java / org / onap / cps / spi / impl / CpsDataPersistenceServiceImpl.java
index dd2d365..2159cea 100644 (file)
@@ -621,17 +621,23 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
         final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
         final AnchorEntity anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
 
-        final Collection<String> normalizedXpaths = new ArrayList<>(xpathsToDelete.size());
+        final Collection<String> normalizedXPathsToDelete = new ArrayList<>(xpathsToDelete.size());
+        final Collection<String> normalizedXpathsToPotentialLists = new ArrayList<>();
         for (final String xpath : xpathsToDelete) {
             try {
-                normalizedXpaths.add(CpsPathUtil.getNormalizedXpath(xpath));
+                final CpsPathQuery cpsPathQuery = CpsPathUtil.getCpsPathQuery(xpath);
+                final String normalizedXpath = cpsPathQuery.getNormalizedXpath();
+                normalizedXPathsToDelete.add(normalizedXpath);
+                if (!cpsPathQuery.isPathToListElement()) {
+                    normalizedXpathsToPotentialLists.add(normalizedXpath);
+                }
             } catch (final PathParsingException e) {
                 log.debug("Error parsing xpath \"{}\": {}", xpath, e.getMessage());
             }
         }
 
-        fragmentRepository.deleteByAnchorIdAndXpaths(anchorEntity.getId(), normalizedXpaths);
-        fragmentRepository.deleteListsByAnchorIdAndXpaths(anchorEntity.getId(), normalizedXpaths);
+        fragmentRepository.deleteByAnchorIdAndXpaths(anchorEntity.getId(), normalizedXPathsToDelete);
+        fragmentRepository.deleteListsByAnchorIdAndXpaths(anchorEntity.getId(), normalizedXpathsToPotentialLists);
     }
 
     @Override