Added query limits to NCMP service methods 91/140391/1
authorleventecsanyi <levente.csanyi@est.tech>
Thu, 6 Mar 2025 12:33:12 +0000 (13:33 +0100)
committerleventecsanyi <levente.csanyi@est.tech>
Thu, 6 Mar 2025 13:24:06 +0000 (14:24 +0100)
  - modified CmHandleQueryService if
  - added limits to certain Impl methods

Issue-ID: CPS-2678
Change-Id: Ia5fd58afcd6f48404aeafba08ee2977c3efc6dcc
Signed-off-by: leventecsanyi <levente.csanyi@est.tech>
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy

index f1f71dc..9cbc6b0 100644 (file)
@@ -83,6 +83,16 @@ public interface CmHandleQueryService {
      */
     Collection<DataNode> queryNcmpRegistryByCpsPath(String cpsPath, FetchDescendantsOption fetchDescendantsOption);
 
+    /**
+     * Method to return data nodes representing the cm handles.
+     *
+     * @param cpsPath cps path for which the cmHandle is requested
+     * @param queryResultLimit the maximum number of data nodes to return; if less than 1, returns all matching nodes
+     * @return a list of data nodes representing the cm handles.
+     */
+    Collection<DataNode> queryNcmpRegistryByCpsPath(String cpsPath, FetchDescendantsOption fetchDescendantsOption,
+                                                    int queryResultLimit);
+
     /**
      * Method to check the state of a cm handle with given id.
      *
index 890522c..8b6934b 100644 (file)
@@ -54,6 +54,7 @@ import org.springframework.stereotype.Component;
 public class CmHandleQueryServiceImpl implements CmHandleQueryService {
     private static final String ANCESTOR_CM_HANDLES = "/ancestor::cm-handles";
     private static final String ALTERNATE_ID = "alternate-id";
+    private static final Integer NO_LIMIT = 0;
     private final CpsDataService cpsDataService;
     private final CpsQueryService cpsQueryService;
 
@@ -99,8 +100,15 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
     @Override
     public Collection<DataNode> queryNcmpRegistryByCpsPath(final String cpsPath,
                                                            final FetchDescendantsOption fetchDescendantsOption) {
+        return queryNcmpRegistryByCpsPath(cpsPath, fetchDescendantsOption, NO_LIMIT);
+    }
+
+    @Override
+    public Collection<DataNode> queryNcmpRegistryByCpsPath(final String cpsPath,
+                                                           final FetchDescendantsOption fetchDescendantsOption,
+                                                           final int queryResultLimit) {
         return cpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cpsPath,
-                fetchDescendantsOption);
+                fetchDescendantsOption, queryResultLimit);
     }
 
     @Override
index e145c62..f331d60 100644 (file)
@@ -144,7 +144,7 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv
 
         final Collection<DataNode> cmHandlesAsDataNodes =
             cmHandleQueryService.queryNcmpRegistryByCpsPath(
-                cpsPathForCmHandlesByReferences, INCLUDE_ALL_DESCENDANTS);
+                cpsPathForCmHandlesByReferences, INCLUDE_ALL_DESCENDANTS, cmHandleReferences.size());
 
         return YangDataConverter.toYangModelCmHandles(cmHandlesAsDataNodes);
     }
@@ -193,7 +193,7 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv
     public YangModelCmHandle getYangModelCmHandleByAlternateId(final String alternateId) {
         final String cpsPathForCmHandleByAlternateId = getCpsPathForCmHandleByAlternateId(alternateId);
         final Collection<DataNode> dataNodes = cmHandleQueryService
-            .queryNcmpRegistryByCpsPath(cpsPathForCmHandleByAlternateId, OMIT_DESCENDANTS);
+            .queryNcmpRegistryByCpsPath(cpsPathForCmHandleByAlternateId, OMIT_DESCENDANTS, 1);
         if (dataNodes.isEmpty()) {
             throw new CmHandleNotFoundException(alternateId);
         }
@@ -207,7 +207,7 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv
         }
         final String cpsPathForCmHandlesByAlternateIds = getCpsPathForCmHandlesByAlternateIds(alternateIds);
         final Collection<DataNode> dataNodes = cmHandleQueryService.queryNcmpRegistryByCpsPath(
-            cpsPathForCmHandlesByAlternateIds, INCLUDE_ALL_DESCENDANTS);
+            cpsPathForCmHandlesByAlternateIds, INCLUDE_ALL_DESCENDANTS, alternateIds.size());
         return YangDataConverter.toYangModelCmHandles(dataNodes);
     }
 
index 884d968..6ac42db 100644 (file)
@@ -131,7 +131,7 @@ class CmHandleQueryServiceImplSpec extends Specification {
             def cmHandleState = CmHandleState.ADVISED
         and: 'the persistence service returns a list of data nodes'
             mockCpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
-                "//state[@cm-handle-state='ADVISED']", OMIT_DESCENDANTS) >> sampleDataNodes
+                "//state[@cm-handle-state='ADVISED']", OMIT_DESCENDANTS, 0) >> sampleDataNodes
         when: 'cm handles are fetched by state'
             def result = objectUnderTest.queryCmHandleIdsByState(cmHandleState)
         then: 'the returned result matches the result from the persistence service'
@@ -171,7 +171,7 @@ class CmHandleQueryServiceImplSpec extends Specification {
     def 'Retrieve Cm Handles By Operational Sync State : UNSYNCHRONIZED'() {
         given: 'cps data service returns a list of data nodes'
             mockCpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
-                '//state/datastores/operational[@sync-state="'+'UNSYNCHRONIZED'+'"]/ancestor::cm-handles', OMIT_DESCENDANTS) >> sampleDataNodes
+                '//state/datastores/operational[@sync-state="'+'UNSYNCHRONIZED'+'"]/ancestor::cm-handles', OMIT_DESCENDANTS, 0) >> sampleDataNodes
         when: 'cm handles are fetched by the UNSYNCHRONIZED operational sync state'
             def result = objectUnderTest.queryCmHandlesByOperationalSyncState(DataStoreSyncState.UNSYNCHRONIZED)
         then: 'the returned result is a list of data nodes returned by cps data service'
@@ -184,7 +184,7 @@ class CmHandleQueryServiceImplSpec extends Specification {
             def cpsPath = "//state[@cm-handle-state='LOCKED']"
         and: 'cps data service returns a valid data node for cm handle ancestor'
             mockCpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
-                cpsPath + '/ancestor::cm-handles', INCLUDE_ALL_DESCENDANTS)
+                cpsPath + '/ancestor::cm-handles', INCLUDE_ALL_DESCENDANTS, 0)
                 >> Arrays.asList(cmHandleDataNode)
         when: 'get cm handles by cps path is invoked'
             def result = objectUnderTest.queryCmHandleAncestorsByCpsPath(cpsPath, INCLUDE_ALL_DESCENDANTS)
@@ -198,7 +198,7 @@ class CmHandleQueryServiceImplSpec extends Specification {
             def cpsPath = "//cm-handles[@alternate-id='1']"
         and: 'cps data service returns a valid data node'
             mockCpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
-                cpsPath, INCLUDE_ALL_DESCENDANTS)
+                cpsPath, INCLUDE_ALL_DESCENDANTS, 0)
                 >> Arrays.asList(cmHandleDataNode)
         when: 'get cm handles by cps path is invoked'
             def result = objectUnderTest.queryCmHandleAncestorsByCpsPath(cpsPath, INCLUDE_ALL_DESCENDANTS)
index 0ed9dd8..0d7722f 100644 (file)
@@ -165,7 +165,7 @@ class InventoryPersistenceImplSpec extends Specification {
     def "Retrieve multiple YangModelCmHandles using cm handle references"() {
         given: 'the cps data service returns 2 data nodes from the DMI registry'
             def dataNodes = [new DataNode(xpath: xpath, leaves: ['id': cmHandleId, 'alternate-id':alternateId]), new DataNode(xpath: xpath2, leaves: ['id': cmHandleId2,'alternate-id':alternateId2])]
-            mockCmHandleQueries.queryNcmpRegistryByCpsPath(_, INCLUDE_ALL_DESCENDANTS) >> dataNodes
+            mockCmHandleQueries.queryNcmpRegistryByCpsPath(_, INCLUDE_ALL_DESCENDANTS, _) >> dataNodes
         when: 'retrieving the yang modelled cm handle'
             def results = objectUnderTest.getYangModelCmHandlesFromCmHandleReferences([cmHandleId, cmHandleId2])
         then: 'verify both have returned and cmhandleIds are correct'
@@ -312,7 +312,7 @@ class InventoryPersistenceImplSpec extends Specification {
             def expectedXPath = '/dmi-registry/cm-handles[@alternate-id=\'alternate id\']'
             def expectedDataNode = new DataNode(xpath: expectedXPath, leaves: [id: 'id', alternateId: 'alternate id'])
         and: 'query service is invoked with expected xpath'
-            mockCmHandleQueries.queryNcmpRegistryByCpsPath(expectedXPath, OMIT_DESCENDANTS) >> [expectedDataNode]
+            mockCmHandleQueries.queryNcmpRegistryByCpsPath(expectedXPath, OMIT_DESCENDANTS, _) >> [expectedDataNode]
             mockYangDataConverter.toYangModelCmHandle(expectedDataNode) >> new YangModelCmHandle(id: 'id')
         expect: 'getting the yang model cm handle'
             assert objectUnderTest.getYangModelCmHandleByAlternateId('alternate id') == new YangModelCmHandle(id: 'id')