Revert "Omit descendants when not need in ncmp inventory queries"

This reverts commit eba77598601a7e3430f9582dfe433495ded3244c.

Signed-off-by: lukegleeson <luke.gleeson@est.tech>
Change-Id: I76a0d1252177c4115de9190ee7f3bb6d15c4e19a
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java
index ecb6e52..a98c600 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java
@@ -26,7 +26,6 @@
 import static org.onap.cps.ncmp.api.impl.utils.YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle;
 import static org.onap.cps.spi.FetchDescendantsOption.FETCH_DIRECT_CHILDREN_ONLY;
 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
-import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -50,7 +49,6 @@
 import org.onap.cps.ncmp.api.inventory.enums.PropertyType;
 import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
-import org.onap.cps.spi.FetchDescendantsOption;
 import org.onap.cps.spi.exceptions.DataValidationException;
 import org.onap.cps.spi.model.ConditionProperties;
 import org.onap.cps.spi.model.DataNode;
@@ -80,7 +78,7 @@
         }
 
         final Map<String, NcmpServiceCmHandle> combinedQueryResult = executeInventoryQueries(
-                cmHandleQueryServiceParameters, INCLUDE_ALL_DESCENDANTS);
+                cmHandleQueryServiceParameters);
 
         return new HashSet<>(combineWithModuleNameQuery(cmHandleQueryServiceParameters, combinedQueryResult).values());
     }
@@ -100,7 +98,7 @@
         }
 
         final Map<String, NcmpServiceCmHandle> combinedQueryResult = executeInventoryQueries(
-                cmHandleQueryServiceParameters, OMIT_DESCENDANTS);
+                cmHandleQueryServiceParameters);
 
         final Collection<String> moduleNamesForQuery =
                 getModuleNamesForQuery(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
@@ -231,8 +229,7 @@
     }
 
     private Map<String, NcmpServiceCmHandle> executeInventoryQueries(
-            final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
-            final FetchDescendantsOption fetchDescendantsOption) {
+            final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
         final Map<String, String> cpsPath = getCpsPath(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
         if (!validateCpsPathConditionProperties(cpsPath)) {
             return Collections.emptyMap();
@@ -243,7 +240,7 @@
         } else {
             try {
                 cpsPathQueryResult = cmHandleQueries.queryCmHandleDataNodesByCpsPath(
-                                cpsPath.get("cpsPath"), fetchDescendantsOption)
+                                cpsPath.get("cpsPath"), INCLUDE_ALL_DESCENDANTS)
                         .stream().map(this::createNcmpServiceCmHandle)
                         .collect(Collectors.toMap(NcmpServiceCmHandle::getCmHandleId,
                                 Function.identity()));
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImpl.java
index 6ca716c..0f86cb7 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImpl.java
@@ -78,7 +78,7 @@
                     + publicPropertyQueryPair.getKey()
                     + "\" and @value=\"" + publicPropertyQueryPair.getValue() + "\"]";
 
-            final Collection<DataNode> dataNodes = queryCmHandleDataNodesByCpsPath(cpsPath, OMIT_DESCENDANTS);
+            final Collection<DataNode> dataNodes = queryCmHandleDataNodesByCpsPath(cpsPath, INCLUDE_ALL_DESCENDANTS);
             if (cmHandleIdToNcmpServiceCmHandles == null) {
                 cmHandleIdToNcmpServiceCmHandles = collectDataNodesToNcmpServiceCmHandles(dataNodes);
             } else {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy
index a918801..5cd702a 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy
@@ -49,62 +49,34 @@
     def objectUnderTest = new NetworkCmProxyCmHandlerQueryServiceImpl(cmHandleQueries, mockInventoryPersistence)
     def objectUnderTestSpy = new NetworkCmProxyCmHandlerQueryServiceImpl(partiallyMockedCmHandleQueries, mockInventoryPersistence)
 
-    def 'Retrieve cm handle objects with cpsPath when combined with no Module Query.'() {
+    def 'Retrieve cm handles with cpsPath when combined with no Module Query.'() {
         given: 'a cmHandleWithCpsPath condition property'
             def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
             def conditionProperties = createConditionProperties('cmHandleWithCpsPath', [['cpsPath' : '/some/cps/path']])
             cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties])
-        and: 'the query to get the cm handle datanodes including all descendants returns a datanode'
+        and: 'cmHandleQueries returns a non null query result'
             cmHandleQueries.queryCmHandleDataNodesByCpsPath('/some/cps/path', FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> [new DataNode(leaves: ['id':'some-cmhandle-id'])]
         and: 'CmHandleQueries returns cmHandles with the relevant query result'
             cmHandleQueries.combineCmHandleQueries(*_) >> ['PNFDemo1': new NcmpServiceCmHandle(cmHandleId: 'PNFDemo1'), 'PNFDemo3': new NcmpServiceCmHandle(cmHandleId: 'PNFDemo3')]
-        when: 'the query is executed for cm handle details'
+        when: 'the query is executed for both cm handle ids and details'
+            def returnedCmHandlesJustIds = objectUnderTest.queryCmHandleIds(cmHandleQueryParameters)
             def returnedCmHandlesWithData = objectUnderTest.queryCmHandles(cmHandleQueryParameters)
-        then: 'the correct ncmp service cm handles are returned'
+        then: 'the correct expected cm handles ids are returned'
+            returnedCmHandlesJustIds == ['PNFDemo1', 'PNFDemo3'] as Set
+        and: 'the correct ncmp service cm handles are returned'
             returnedCmHandlesWithData.stream().map(CmHandle -> CmHandle.cmHandleId).collect(Collectors.toSet()) == ['PNFDemo1', 'PNFDemo3'] as Set
     }
 
-    def 'Retrieve cm handle ids with cpsPath when combined with no Module Query.'() {
-        given: 'a cmHandleWithCpsPath condition property'
-            def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
-            def conditionProperties = createConditionProperties('cmHandleWithCpsPath', [['cpsPath' : '/some/cps/path']])
-            cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties])
-        and: 'the query get the cm handle datanodes excluding all descendants returns a datanode'
-            cmHandleQueries.queryCmHandleDataNodesByCpsPath('/some/cps/path', FetchDescendantsOption.OMIT_DESCENDANTS) >> [new DataNode(leaves: ['id':'some-cmhandle-id'])]
-        and: 'CmHandleQueries returns cmHandles with the relevant query result'
-            cmHandleQueries.combineCmHandleQueries(*_) >> ['PNFDemo1': new NcmpServiceCmHandle(cmHandleId: 'PNFDemo1'), 'PNFDemo3': new NcmpServiceCmHandle(cmHandleId: 'PNFDemo3')]
-        when: 'the query is executed for cm handle ids'
-            def returnedCmHandlesJustIds = objectUnderTest.queryCmHandleIds(cmHandleQueryParameters)
-        then: 'the correct expected cm handles ids are returned'
-            returnedCmHandlesJustIds == ['PNFDemo1', 'PNFDemo3'] as Set
-    }
-
-    def 'Retrieve cm handle details with cpsPath where #scenario.'() {
+    def 'Retrieve cm handles with cpsPath where #scenario.'() {
         given: 'a cmHandleWithCpsPath condition property'
             def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
             def conditionProperties = createConditionProperties('cmHandleWithCpsPath', [['cpsPath' : '/some/cps/path']])
             cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties])
         and: 'cmHandleQueries throws a path parsing exception'
             cmHandleQueries.queryCmHandleDataNodesByCpsPath('/some/cps/path', FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> { throw thrownException }
-        when: 'the query is executed for cm handle details'
-            objectUnderTest.queryCmHandles(cmHandleQueryParameters)
-        then: 'a data validation exception is thrown'
-            thrown(expectedException)
-        where: 'the following data is used'
-            scenario                           | thrownException                                          || expectedException
-            'a PathParsingException is thrown' | new PathParsingException('some message', 'some details') || DataValidationException
-            'any other Exception is thrown'    | new DataInUseException('some message', 'some details')   || DataInUseException
-    }
-
-    def 'Retrieve cm handle ids with cpsPath where #scenario.'() {
-        given: 'a cmHandleWithCpsPath condition property'
-            def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
-            def conditionProperties = createConditionProperties('cmHandleWithCpsPath', [['cpsPath' : '/some/cps/path']])
-            cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties])
-        and: 'cmHandleQueries throws a path parsing exception'
-            cmHandleQueries.queryCmHandleDataNodesByCpsPath('/some/cps/path', FetchDescendantsOption.OMIT_DESCENDANTS) >> { throw thrownException }
-        when: 'the query is executed for cm handle ids'
+        when: 'the query is executed for both cm handle ids and details'
             objectUnderTest.queryCmHandleIds(cmHandleQueryParameters)
+            objectUnderTest.queryCmHandles(cmHandleQueryParameters)
         then: 'a data validation exception is thrown'
             thrown(expectedException)
         where: 'the following data is used'