Use attribute-axis in NCMP [#1] 72/140272/3
authoremaclee <lee.anjella.macabuhay@est.tech>
Tue, 18 Feb 2025 17:39:02 +0000 (17:39 +0000)
committeremaclee <lee.anjella.macabuhay@est.tech>
Thu, 27 Feb 2025 03:43:46 +0000 (03:43 +0000)
- uses queryleaf API on the methods getCmHandleReferencesByTrustLevel,
getCmHandleReferencesByDmiPluginIdentifier

Issue-ID: CPS-2663
Change-Id: Ib9ff3ceb58b14664660f2a92b02e0bacf00bebda
Signed-off-by: emaclee <lee.anjella.macabuhay@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/ParameterizedCmHandleQueryServiceImpl.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/ParameterizedCmHandleQueryServiceSpec.groovy

index 9447f13..f1f71dc 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2022-2024 Nordix Foundation
+ *  Copyright (C) 2022-2025 Nordix Foundation
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -110,12 +110,4 @@ public interface CmHandleQueryService {
     Collection<String> getCmHandleReferencesByDmiPluginIdentifier(String dmiPluginIdentifier,
                                                                   boolean outputAlternateId);
 
-    /**
-     * Get map of cmHandle references by DMI plugin identifier.
-     *
-     * @param dmiPluginIdentifier DMI plugin identifier
-     * @return map of cmHandle references key:CmHandleId Value:AlternateId
-     */
-    Map<String, String> getCmHandleReferencesMapByDmiPluginIdentifier(String dmiPluginIdentifier);
-
 }
index ae913dd..770ada0 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2022-2024 Nordix Foundation
+ *  Copyright (C) 2022-2025 Nordix Foundation
  *  Modifications Copyright (C) 2023 TechMahindra Ltd.
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,9 +28,9 @@ import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DMI_REGISTRY
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 import java.util.stream.Collectors;
 import lombok.RequiredArgsConstructor;
 import org.onap.cps.api.CpsDataService;
@@ -90,7 +90,8 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
     @Override
     public Collection<String> queryCmHandleIdsByState(final CmHandleState cmHandleState) {
         final Collection<DataNode> cmHandlesAsDataNodes =
-                queryNcmpRegistryByCpsPath("//state[@cm-handle-state='" + cmHandleState + "']", OMIT_DESCENDANTS);
+                queryNcmpRegistryByCpsPath("//state[@cm-handle-state='" + cmHandleState + "']",
+                        OMIT_DESCENDANTS);
         return cmHandlesAsDataNodes.stream()
                 .map(DataNode::getXpath)
                 .map(YangDataConverter::extractCmHandleIdFromXpath)
@@ -106,7 +107,7 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
 
     @Override
     public Collection<DataNode> queryCmHandleAncestorsByCpsPath(final String cpsPath,
-                                                          final FetchDescendantsOption fetchDescendantsOption) {
+                                                                final FetchDescendantsOption fetchDescendantsOption) {
         if (CpsPathUtil.getCpsPathQuery(cpsPath).getXpathPrefix().endsWith("/cm-handles")) {
             return queryNcmpRegistryByCpsPath(cpsPath, fetchDescendantsOption);
         }
@@ -128,84 +129,60 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
 
     @Override
     public Collection<String> getCmHandleReferencesByDmiPluginIdentifier(final String dmiPluginIdentifier,
-                                                                  final boolean outputAlternateId) {
+                                                                         final boolean outputAlternateId) {
         final Collection<String> cmHandleReferences = new HashSet<>();
         for (final ModelledDmiServiceLeaves modelledDmiServiceLeaf : ModelledDmiServiceLeaves.values()) {
-            for (final DataNode cmHandleAsDataNode: getCmHandlesByDmiPluginIdentifierAndDmiProperty(
-                    dmiPluginIdentifier,
-                    modelledDmiServiceLeaf.getLeafName())) {
-                if (outputAlternateId) {
-                    cmHandleReferences.add(cmHandleAsDataNode.getLeaves().get(ALTERNATE_ID).toString());
-                } else {
-                    cmHandleReferences.add(cmHandleAsDataNode.getLeaves().get("id").toString());
-                }
-            }
+            cmHandleReferences.addAll(getIdsByDmiPluginIdentifierAndDmiProperty(
+                        dmiPluginIdentifier, modelledDmiServiceLeaf.getLeafName(), outputAlternateId));
         }
         return cmHandleReferences;
     }
 
-    @Override
-    public Map<String, String> getCmHandleReferencesMapByDmiPluginIdentifier(final String dmiPluginIdentifier) {
-        final Map<String, String> cmHandleReferencesMap = new HashMap<>();
-        for (final ModelledDmiServiceLeaves modelledDmiServiceLeaf : ModelledDmiServiceLeaves.values()) {
-            for (final DataNode cmHandleAsDataNode: getCmHandlesByDmiPluginIdentifierAndDmiProperty(
-                dmiPluginIdentifier,
-                modelledDmiServiceLeaf.getLeafName())) {
-                cmHandleReferencesMap.put(cmHandleAsDataNode.getLeaves().get("id").toString(),
-                                            cmHandleAsDataNode.getLeaves().get(ALTERNATE_ID).toString());
-            }
-        }
-        return cmHandleReferencesMap;
-    }
-
     private Collection<String> getCmHandleReferencesByTrustLevel(final TrustLevel targetTrustLevel,
                                                                  final boolean outputAlternateId) {
         final Collection<String> selectedCmHandleReferences = new HashSet<>();
-
         for (final Map.Entry<String, TrustLevel> mapEntry : trustLevelPerDmiPlugin.entrySet()) {
             final String dmiPluginIdentifier = mapEntry.getKey();
             final TrustLevel dmiTrustLevel = mapEntry.getValue();
-            final Map<String, String> candidateCmHandleReferences =
-                getCmHandleReferencesMapByDmiPluginIdentifier(dmiPluginIdentifier);
-            for (final Map.Entry<String, String> candidateCmHandleReference : candidateCmHandleReferences.entrySet()) {
-                final TrustLevel candidateCmHandleTrustLevel =
-                    trustLevelPerCmHandleId.get(candidateCmHandleReference.getKey());
+            final Collection<String> candidateCmHandleIds = getCmHandleReferencesByDmiPluginIdentifier(
+                    dmiPluginIdentifier, false);
+            for (final String candidateCmHandleId : candidateCmHandleIds) {
+                final TrustLevel candidateCmHandleTrustLevel = trustLevelPerCmHandleId.get(candidateCmHandleId);
                 final TrustLevel effectiveTrustlevel =
-                    candidateCmHandleTrustLevel.getEffectiveTrustLevel(dmiTrustLevel);
+                        candidateCmHandleTrustLevel.getEffectiveTrustLevel(dmiTrustLevel);
                 if (targetTrustLevel.equals(effectiveTrustlevel)) {
-                    if (outputAlternateId) {
-                        selectedCmHandleReferences.add(candidateCmHandleReference.getValue());
-                    } else {
-                        selectedCmHandleReferences.add(candidateCmHandleReference.getKey());
-                    }
+                    selectedCmHandleReferences.add(candidateCmHandleId);
                 }
             }
         }
+        if (outputAlternateId) {
+            return getAlternateIdsByCmHandleIds(selectedCmHandleReferences);
+        }
         return selectedCmHandleReferences;
     }
 
     private Collection<String> collectCmHandleReferencesFromDataNodes(final Collection<DataNode> dataNodes,
-                                                               final boolean outputAlternateId) {
+                                                                      final boolean outputAlternateId) {
         if (outputAlternateId) {
             return dataNodes.stream().map(dataNode ->
-                (String) dataNode.getLeaves().get(ALTERNATE_ID)).collect(Collectors.toSet());
+                    (String) dataNode.getLeaves().get(ALTERNATE_ID)).collect(Collectors.toSet());
         } else {
             return dataNodes.stream().map(dataNode ->
-                (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet());
+                    (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet());
         }
     }
 
     private Collection<String> queryCmHandleAnyProperties(
-        final Map<String, String> propertyQueryPairs,
-        final PropertyType propertyType, final boolean outputAlternateId) {
+            final Map<String, String> propertyQueryPairs,
+            final PropertyType propertyType, final boolean outputAlternateId) {
         if (propertyQueryPairs.isEmpty()) {
             return Collections.emptySet();
         }
         Collection<String> cmHandleReferences = null;
         for (final Map.Entry<String, String> publicPropertyQueryPair : propertyQueryPairs.entrySet()) {
             final String cpsPath = DESCENDANT_PATH + propertyType.getYangContainerName() + "[@name=\""
-                + publicPropertyQueryPair.getKey()
-                + "\" and @value=\"" + publicPropertyQueryPair.getValue() + "\"]";
+                    + publicPropertyQueryPair.getKey()
+                    + "\" and @value=\"" + publicPropertyQueryPair.getValue() + "\"]";
 
             final Collection<DataNode> dataNodes = queryCmHandleAncestorsByCpsPath(cpsPath,
                     OMIT_DESCENDANTS);
@@ -223,17 +200,35 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
         return cmHandleReferences;
     }
 
-    private Collection<DataNode> getCmHandlesByDmiPluginIdentifierAndDmiProperty(final String dmiPluginIdentifier,
-                                                                                 final String dmiProperty) {
-        return cpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
-                NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@" + dmiProperty + "='" + dmiPluginIdentifier + "']",
-                OMIT_DESCENDANTS);
+    private Set<String> getIdsByDmiPluginIdentifierAndDmiProperty(final String dmiPluginIdentifier,
+                                                                  final String dmiProperty,
+                                                                  final boolean outputAlternateId) {
+        final String attributeName = outputAlternateId ? ALTERNATE_ID : "id";
+        final String cpsPath = String.format("%s/cm-handles[@%s='%s']/@%s",
+                NCMP_DMI_REGISTRY_PARENT, dmiProperty, dmiPluginIdentifier, attributeName);
+        return cpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cpsPath, String.class);
+    }
+
+    private Collection<String> getAlternateIdsByCmHandleIds(final Collection<String> cmHandleIds) {
+
+        final String cpsPath = NCMP_DMI_REGISTRY_PARENT + "/cm-handles["
+                + createFormattedQueryString(cmHandleIds) + "]/@alternate-id";
+
+        return cpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cpsPath, String.class);
+    }
+
+    private String createFormattedQueryString(final Collection<String> cmHandleIds) {
+        return cmHandleIds.stream()
+                .map(cmHandleId -> "@id='" + cmHandleId + "'")
+                .collect(Collectors.joining(" or "));
     }
 
+
     private DataNode getCmHandleState(final String cmHandleId) {
         cpsValidator.validateNameCharacters(cmHandleId);
         final String xpath = NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']/state";
         return cpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
                 xpath, OMIT_DESCENDANTS).iterator().next();
     }
-}
+
+}
\ No newline at end of file
index 428c6f6..4c1032e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2022-2024 Nordix Foundation
+ *  Copyright (C) 2022-2025 Nordix Foundation
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -62,13 +62,13 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
 
     @Override
     public Collection<String> queryCmHandleReferenceIds(
-        final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
-        final boolean outputAlternateId) {
+            final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
+            final boolean outputAlternateId) {
         return executeQueries(cmHandleQueryServiceParameters, outputAlternateId,
-            this::executeCpsPathQuery,
-            this::queryCmHandlesByPublicProperties,
-            this::executeModuleNameQuery,
-            this::queryCmHandlesByTrustLevel);
+                this::executeCpsPathQuery,
+                this::queryCmHandlesByPublicProperties,
+                this::executeModuleNameQuery,
+                this::queryCmHandlesByTrustLevel);
     }
 
     @Override
@@ -84,7 +84,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
 
     @Override
     public Collection<NcmpServiceCmHandle> queryCmHandles(
-        final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+            final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
 
         if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) {
             return getAllCmHandles();
@@ -111,15 +111,11 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
         }
 
         final String dmiPluginIdentifierValue = dmiPropertyQueryPairs
-            .get(PropertyType.DMI_PLUGIN.getYangContainerName());
+                .get(PropertyType.DMI_PLUGIN.getYangContainerName());
+
+        return cmHandleQueryService.getCmHandleReferencesByDmiPluginIdentifier(
+                dmiPluginIdentifierValue, outputAlternateId);
 
-        if (outputAlternateId) {
-            return
-                cmHandleQueryService.getCmHandleReferencesMapByDmiPluginIdentifier(dmiPluginIdentifierValue).values();
-        } else {
-            return cmHandleQueryService.getCmHandleReferencesByDmiPluginIdentifier(dmiPluginIdentifierValue,
-                outputAlternateId);
-        }
     }
 
     private Collection<String> queryCmHandlesByPrivateProperties(
@@ -175,7 +171,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
     private Collection<String> executeCpsPathQuery(
             final CmHandleQueryServiceParameters cmHandleQueryServiceParameters, final boolean outputAlternateId) {
         final Map<String, String> cpsPathCondition
-            = getCpsPathCondition(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
+                = getCpsPathCondition(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
         if (!validateCpsPathConditionProperties(cpsPathCondition)) {
             return Collections.emptySet();
         }
@@ -185,8 +181,8 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
         }
         try {
             cpsPathQueryResult = collectCmHandleReferencesFromDataNodes(
-                cmHandleQueryService.queryCmHandleAncestorsByCpsPath(cpsPathCondition.get("cpsPath"), OMIT_DESCENDANTS),
-                outputAlternateId);
+                    cmHandleQueryService.queryCmHandleAncestorsByCpsPath(cpsPathCondition.get("cpsPath"),
+                            OMIT_DESCENDANTS), outputAlternateId);
         } catch (final PathParsingException pathParsingException) {
             throw new DataValidationException(pathParsingException.getMessage(), pathParsingException.getDetails(),
                     pathParsingException);
@@ -211,7 +207,7 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
     }
 
     private Map<String, String> getPropertyPairs(final List<ConditionProperties> conditionProperties,
-                                                       final String queryProperty) {
+                                                 final String queryProperty) {
         final Map<String, String> result = new HashMap<>();
         getConditions(conditionProperties, queryProperty).forEach(result::putAll);
         return result;
@@ -229,18 +225,18 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
 
     private Collection<String> getAllCmHandleReferences(final boolean outputAlternateId) {
         final DataNode dataNode = inventoryPersistence.getDataNode(NCMP_DMI_REGISTRY_PARENT, DIRECT_CHILDREN_ONLY)
-            .iterator().next();
+                .iterator().next();
         return collectCmHandleReferencesFromDataNodes(dataNode.getChildDataNodes(), outputAlternateId);
     }
 
     private Collection<NcmpServiceCmHandle> getNcmpServiceCmHandles(final Collection<String> cmHandleIds) {
         final Collection<YangModelCmHandle> yangModelcmHandles
-            = inventoryPersistence.getYangModelCmHandles(cmHandleIds);
+                = inventoryPersistence.getYangModelCmHandles(cmHandleIds);
 
         final Collection<NcmpServiceCmHandle> ncmpServiceCmHandles = new ArrayList<>(yangModelcmHandles.size());
 
         yangModelcmHandles.forEach(yangModelcmHandle ->
-            ncmpServiceCmHandles.add(YangDataConverter.toNcmpServiceCmHandle(yangModelcmHandle))
+                ncmpServiceCmHandles.add(YangDataConverter.toNcmpServiceCmHandle(yangModelcmHandle))
         );
         return ncmpServiceCmHandles;
     }
@@ -252,15 +248,15 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
     private Collection<String> executeQueries(final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
                                               final boolean outputAlternateId,
                                               final BiFunction<CmHandleQueryServiceParameters, Boolean,
-                                                  Collection<String>>... queryFunctions) {
+                                                      Collection<String>>... queryFunctions) {
         if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) {
             return getAllCmHandleReferences(outputAlternateId);
         }
         Collection<String> combinedQueryResult = NO_QUERY_TO_EXECUTE;
         for (final BiFunction<CmHandleQueryServiceParameters, Boolean,
-            Collection<String>> queryFunction : queryFunctions) {
+                Collection<String>> queryFunction : queryFunctions) {
             final Collection<String> queryResult = queryFunction.apply(cmHandleQueryServiceParameters,
-                outputAlternateId);
+                    outputAlternateId);
             if (noEntriesFoundCanStopQuerying(queryResult)) {
                 return Collections.emptySet();
             }
@@ -288,13 +284,13 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
     }
 
     private Collection<String> collectCmHandleReferencesFromDataNodes(final Collection<DataNode> dataNodes,
-                                                               final boolean outputAlternateId) {
+                                                                      final boolean outputAlternateId) {
         if (outputAlternateId) {
             return dataNodes.stream().map(dataNode ->
-                (String) dataNode.getLeaves().get("alternate-id")).collect(Collectors.toSet());
+                    (String) dataNode.getLeaves().get("alternate-id")).collect(Collectors.toSet());
         } else {
             return dataNodes.stream().map(dataNode ->
-                (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet());
+                    (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet());
         }
     }
 }
index 1cbdc7b..6e6116e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2022-2024 Nordix Foundation
+ *  Copyright (C) 2022-2025 Nordix Foundation
  *  Modifications Copyright (C) 2023 TechMahindra Ltd.
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
@@ -86,21 +86,21 @@ class CmHandleQueryServiceImplSpec extends Specification {
     }
 
     def 'Query cm handles on trust level'() {
-        given: 'query properties for trust level COMPLETE'
-            def trustLevelPropertyQueryPairs = ['trustLevel' : TrustLevel.COMPLETE.toString()]
+        given: 'query properties for #trustLevel'
+            def trustLevelPropertyQueryPairs = ['trustLevel' : trustLevel.toString()]
         and: 'the dmi cache has been initialised and "knows" about my-dmi-plugin-identifier'
-            trustLevelPerDmiPlugin.put('my-dmi-plugin-identifier', TrustLevel.COMPLETE)
+            trustLevelPerDmiPlugin.put('my-dmi-plugin-identifier', trustLevel)
         and: 'the DataNodes queried for a given cpsPath are returned from the persistence service'
             mockResponses()
         when: 'the query is run'
             def result = objectUnderTest.queryCmHandlesByTrustLevel(trustLevelPropertyQueryPairs, outputAlternateId)
         then: 'the result contain trusted cmHandle reference'
-            assert result.size() == 1
-            assert result[0] == expectedCmHandleReference
+            assert result as Set == expectedCmHandleReference as Set
         where: 'the following data is used'
-            senario               | outputAlternateId | expectedCmHandleReference
-            'output cmHandleId'   |  false            | 'PNFDemo'
-            'output AlternateId'  |  true             | 'alt-PNFDemo'
+            senario                                     | outputAlternateId | expectedCmHandleReference                      | trustLevel           || resultSize
+            'output cmHandleId for trustLevel Complete' |  false            | ['PNFDemo']                                    | TrustLevel.COMPLETE  || 1
+            'output alternateId for trustLevel Complete'|  true             | ['alt-PNFDemo']                                | TrustLevel.COMPLETE  || 1
+            'output alternateIds for trustLevel None'   |  true             | ['alt-PNFDemo2', 'alt-PNFDemo', 'alt-PNFDemo4']| TrustLevel.NONE      || 3
     }
 
     def 'Query CmHandles using empty public properties query pair.'() {
@@ -143,8 +143,8 @@ class CmHandleQueryServiceImplSpec extends Specification {
             def cmHandleState = state
         and: 'the persistence service returns a list of data nodes'
             mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
-                    NCMP_DMI_REGISTRY_PARENT + '/cm-handles[@id=\'some-cm-handle\']/state',
-                    OMIT_DESCENDANTS) >> [new DataNode(leaves: ['cm-handle-state': 'READY'])]
+                NCMP_DMI_REGISTRY_PARENT + '/cm-handles[@id=\'some-cm-handle\']/state',
+                OMIT_DESCENDANTS) >> [new DataNode(leaves: ['cm-handle-state': 'READY'])]
         when: 'cm handles are compared by state'
             def result = objectUnderTest.cmHandleHasState('some-cm-handle', cmHandleState)
         then: 'the returned result matches the expected result from the persistence service'
@@ -160,8 +160,8 @@ class CmHandleQueryServiceImplSpec extends Specification {
             def cmHandleState = CmHandleState.READY
         and: 'cps data service returns a list of data nodes'
             mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
-                    NCMP_DMI_REGISTRY_PARENT + '/cm-handles[@id=\'some-cm-handle\']/state',
-                    OMIT_DESCENDANTS) >> [new DataNode(leaves: ['cm-handle-state': 'READY'])]
+                NCMP_DMI_REGISTRY_PARENT + '/cm-handles[@id=\'some-cm-handle\']/state',
+                OMIT_DESCENDANTS) >> [new DataNode(leaves: ['cm-handle-state': 'READY'])]
         when: 'cm handles are fetched by state and id'
             def result = objectUnderTest.getCmHandleState('some-cm-handle')
         then: 'the returned result is a list of data nodes returned by cps data service'
@@ -200,8 +200,8 @@ 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)
-                    >> Arrays.asList(cmHandleDataNode)
+                cpsPath, INCLUDE_ALL_DESCENDANTS)
+                >> Arrays.asList(cmHandleDataNode)
         when: 'get cm handles by cps path is invoked'
             def result = objectUnderTest.queryCmHandleAncestorsByCpsPath(cpsPath, INCLUDE_ALL_DESCENDANTS)
         then: 'the returned result is a list of data nodes returned by cps data service'
@@ -223,18 +223,8 @@ class CmHandleQueryServiceImplSpec extends Specification {
             'output is for cm handle ids'   | false             || ['PNFDemo', 'PNFDemo2', 'PNFDemo4']
     }
 
-    def 'Get all alternateIds by dmi plugin identifier'() {
-        given: 'the DataNodes queried for a given cpsPath are returned from the persistence service.'
-            mockResponses()
-        when: 'cm Handles are fetched for a given dmi plugin identifier'
-            def result = objectUnderTest.getCmHandleReferencesMapByDmiPluginIdentifier('my-dmi-plugin-identifier').values()
-        then: 'result is the correct size'
-            assert result.size() == 3
-        and: 'result contains the correct alternate Ids'
-            assert result.containsAll('alt-PNFDemo', 'alt-PNFDemo2', 'alt-PNFDemo4')
-    }
-
     void mockResponses() {
+
         mockCpsQueryService.queryDataNodes(_, _, '//public-properties[@name=\"Contact\" and @value=\"newemailforstore@bookstore.com\"]/ancestor::cm-handles', _) >> [pnfDemo, pnfDemo2, pnfDemo4]
         mockCpsQueryService.queryDataNodes(_, _, '//public-properties[@name=\"wont_match\" and @value=\"wont_match\"]/ancestor::cm-handles', _) >> []
         mockCpsQueryService.queryDataNodes(_, _, '//public-properties[@name=\"Contact2\" and @value=\"newemailforstore2@bookstore.com\"]/ancestor::cm-handles', _) >> [pnfDemo4]
@@ -244,6 +234,16 @@ class CmHandleQueryServiceImplSpec extends Specification {
         mockCpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-service-name=\'my-dmi-plugin-identifier\']', OMIT_DESCENDANTS) >> [pnfDemo, pnfDemo2]
         mockCpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-data-service-name=\'my-dmi-plugin-identifier\']', OMIT_DESCENDANTS) >> [pnfDemo, pnfDemo4]
         mockCpsQueryService.queryDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-model-service-name=\'my-dmi-plugin-identifier\']', OMIT_DESCENDANTS) >> [pnfDemo2, pnfDemo4]
+
+        mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-service-name=\'my-dmi-plugin-identifier\']/@id', _) >> [pnfDemo.getLeaves().get('id'), pnfDemo2.getLeaves().get('id')]
+        mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-data-service-name=\'my-dmi-plugin-identifier\']/@id', _) >> [pnfDemo.getLeaves().get('id'), pnfDemo4.getLeaves().get('id')]
+        mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-model-service-name=\'my-dmi-plugin-identifier\']/@id', _) >> [pnfDemo2.getLeaves().get('id'), pnfDemo4.getLeaves().get('id')]
+
+        mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-service-name=\'my-dmi-plugin-identifier\']/@alternate-id', _) >> [pnfDemo.getLeaves().get('alternate-id'), pnfDemo2.getLeaves().get('alternate-id')]
+        mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-data-service-name=\'my-dmi-plugin-identifier\']/@alternate-id', _) >> [pnfDemo.getLeaves().get('alternate-id'), pnfDemo4.getLeaves().get('alternate-id')]
+        mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@dmi-model-service-name=\'my-dmi-plugin-identifier\']/@alternate-id', _) >> [pnfDemo2.getLeaves().get('alternate-id'), pnfDemo4.getLeaves().get('alternate-id')]
+        mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@id=\'PNFDemo\']/@alternate-id', _) >> [pnfDemo.getLeaves().get('alternate-id')]
+        mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '/dmi-registry/cm-handles[@id=\'PNFDemo2\' or @id=\'PNFDemo\' or @id=\'PNFDemo4\']/@alternate-id', _) >> [pnfDemo2.getLeaves().get('alternate-id'), pnfDemo.getLeaves().get('alternate-id'), pnfDemo4.getLeaves().get('alternate-id')]
     }
 
     def static createDataNode(dataNodeId) {
index bf6ea36..7ba2bdf 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2022-2024 Nordix Foundation
+ *  Copyright (C) 2022-2025 Nordix Foundation
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -206,7 +206,7 @@ class ParameterizedCmHandleQueryServiceSpec extends Specification {
             def conditionProperties = createConditionProperties('cmHandleWithDmiPlugin', [['some-key': 'some-value']])
             cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties])
         and: 'the inventoryPersistence returns different CmHandleIds'
-            partiallyMockedCmHandleQueries.getCmHandleReferencesMapByDmiPluginIdentifier(*_) >> [:]
+            partiallyMockedCmHandleQueries.getCmHandleReferencesByDmiPluginIdentifier(_,_) >> []
         when: 'the query executed'
             def result = objectUnderTestWithPartiallyMockedQueries.queryCmHandleIdsForInventory(cmHandleQueryParameters, true)
         then: 'the expected number of results are returned.'