Node API - Find root by anchor method performance
[cps.git] / cps-ri / src / main / java / org / onap / cps / spi / impl / CpsDataPersistenceServiceImpl.java
index dc848e6..ac1be1c 100644 (file)
@@ -230,7 +230,11 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
         final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
         final AnchorEntity anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
         if (isRootXpath(xpath)) {
-            return fragmentRepository.findFirstRootByDataspaceAndAnchor(dataspaceEntity, anchorEntity);
+            final List<FragmentExtract> fragmentExtracts = fragmentRepository.getTopLevelFragments(dataspaceEntity,
+                    anchorEntity);
+            final FragmentEntity fragmentEntity = FragmentEntityArranger.toFragmentEntityTree(anchorEntity,
+                    fragmentExtracts);
+            return fragmentEntity;
         } else {
             final String normalizedXpath = getNormalizedXpath(xpath);
             final FragmentEntity fragmentEntity;
@@ -500,7 +504,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
                                 final boolean onlySupportListNodeDeletion) {
         final String parentNodeXpath;
         FragmentEntity parentFragmentEntity = null;
-        boolean targetDeleted = false;
+        boolean targetDeleted;
         if (isRootXpath(targetXpath)) {
             deleteDataNodes(dataspaceName, anchorName);
             targetDeleted = true;