Merge "Eliminate cmhandle-properties tag"
authorJoseph Keenan <joseph.keenan@est.tech>
Wed, 22 Jun 2022 09:16:56 +0000 (09:16 +0000)
committerGerrit Code Review <gerrit@onap.org>
Wed, 22 Jun 2022 09:16:56 +0000 (09:16 +0000)
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy

index 00cbe69..3deaa7d 100644 (file)
@@ -31,6 +31,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService;
@@ -126,17 +127,19 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
                                     final Map<DataNodeIdentifier, DataNode> amalgamatedQueryResults) {
         boolean firstQuery = true;
         if (!getModuleNames(cmHandleQueryServiceParameters.getCmHandleQueryParameters()).isEmpty()) {
-            final Collection<Anchor> anchors = cpsAdminPersistenceService.queryAnchors("NFP-Operational",
-                    getModuleNames(cmHandleQueryServiceParameters.getCmHandleQueryParameters()));
-            anchors.forEach(anchor -> {
-                final List<DataNode> dataNodes = getDataNodes("//cm-handles[@id='" + anchor.getName() + "']");
-                dataNodes.parallelStream().forEach(dataNode -> {
+            final Collection<String> anchorNames = cpsAdminPersistenceService.queryAnchors("NFP-Operational",
+                    getModuleNames(cmHandleQueryServiceParameters.getCmHandleQueryParameters()))
+                    .parallelStream().map(Anchor::getName).collect(Collectors.toList());
+
+            getAllCmHandles().forEach(dataNode -> {
+                if (anchorNames.contains(dataNode.getLeaves().get("id").toString())) {
                     final DataNodeIdentifier dataNodeIdentifier =
                             jsonObjectMapper.convertToValueType(dataNode, DataNodeIdentifier.class);
                     amalgamatedQueryResultIdentifiers.add(dataNodeIdentifier);
                     amalgamatedQueryResults.put(dataNodeIdentifier, dataNode);
-                });
+                }
             });
+
             firstQuery = false;
         }
         return firstQuery;
index b689097..46c8662 100644 (file)
@@ -54,7 +54,7 @@ class NetworkCmProxyCmHandlerQueryServiceSpec extends Specification {
         when: 'the service is invoked'
             def returnedCmHandles = objectUnderTest.queryCmHandles(cmHandleQueryParameters)
         then: 'the correct expected cm handles are returned'
-            returnedCmHandles.stream().map(d -> d.leaves.get('id').toString()).collect(Collectors.toList()) == expectedCmHandleIds
+            returnedCmHandles.stream().map(d -> d.leaves.get('id').toString()).collect(Collectors.toSet()) == expectedCmHandleIds as Set
         where: 'the following data is used'
             scenario                                       | publicProperties                                                                                  || expectedCmHandleIds
             'single matching property'                     | [['Contact' : 'newemailforstore@bookstore.com']]                                                  || ['PNFDemo', 'PNFDemo2', 'PNFDemo4']
@@ -75,10 +75,10 @@ class NetworkCmProxyCmHandlerQueryServiceSpec extends Specification {
         when: 'the service is invoked'
             def returnedCmHandles = objectUnderTest.queryCmHandles(cmHandleQueryParameters)
         then: 'the correct expected cm handles are returned'
-            returnedCmHandles.stream().map(d -> d.leaves.get('id').toString()).collect(Collectors.toList()) == expectedCmHandleIds
+            returnedCmHandles.stream().map(d -> d.leaves.get('id').toString()).collect(Collectors.toSet()) == expectedCmHandleIds as Set
         where: 'the following data is used'
             scenario                               | moduleNames                                                             || expectedCmHandleIds
-            'single matching module name'          | [['moduleName' : 'MODULE-NAME-001']]                                    || ['PNFDemo2', 'PNFDemo3', 'PNFDemo']
+            'single matching module name'          | [['moduleName' : 'MODULE-NAME-001']]                                    || ['PNFDemo3', 'PNFDemo', 'PNFDemo2']
             'module name dont match'               | [['moduleName' : 'MODULE-NAME-004']]                                    || []
             '2 module names, only one match (and)' | [['moduleName' : 'MODULE-NAME-002'], ['moduleName': 'MODULE-NAME-003']] || ['PNFDemo4']
             '2 module names, no match (and)'       | [['moduleName' : 'MODULE-NAME-002'], ['moduleName': 'MODULE-NAME-004']] || []
@@ -99,7 +99,7 @@ class NetworkCmProxyCmHandlerQueryServiceSpec extends Specification {
         when: 'the service is invoked'
             def returnedCmHandles = objectUnderTest.queryCmHandles(cmHandleQueryParameters)
         then: 'the correct expected cm handles are returned'
-            returnedCmHandles.stream().map(d -> d.leaves.get('id').toString()).collect(Collectors.toList()) == expectedCmHandleIds
+            returnedCmHandles.stream().map(d -> d.leaves.get('id').toString()).collect(Collectors.toSet()) == expectedCmHandleIds as Set
         where: 'the following data is used'
             scenario                 | moduleNames                          | publicProperties                                   || expectedCmHandleIds
             'particularly intersect' | [['moduleName' : 'MODULE-NAME-001']] | [['Contact' : 'newemailforstore@bookstore.com']]   || ['PNFDemo2', 'PNFDemo']
@@ -114,7 +114,7 @@ class NetworkCmProxyCmHandlerQueryServiceSpec extends Specification {
             def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
             def returnedCmHandles = objectUnderTest.queryCmHandles(cmHandleQueryParameters)
         then: 'the correct expected cm handles are returned'
-            returnedCmHandles.stream().map(d -> d.leaves.get('id').toString()).collect(Collectors.toList()) == ['PNFDemo', 'PNFDemo2', 'PNFDemo3', 'PNFDemo4']
+            returnedCmHandles.stream().map(d -> d.leaves.get('id').toString()).collect(Collectors.toSet()) == ['PNFDemo', 'PNFDemo2', 'PNFDemo3', 'PNFDemo4'] as Set
     }
 
     void mockResponses() {