aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Hanrahan <daniel.hanrahan@est.tech>2025-03-05 16:08:13 +0000
committerGerrit Code Review <gerrit@onap.org>2025-03-05 16:08:13 +0000
commit68f2f55e2a6b693b126901e1aa09b2c25d8c5860 (patch)
tree7fee456b0661d28e1d28d19cfe2368071cab0a38
parenta2c05f69b9dacee2ce8c12bbb80174aa60116a2a (diff)
parentbc2c4ef4cc51c4c6f4fe860cb4cd4c3dfa1ca447 (diff)
Merge "Use attribute-axis in NCMP [#2]"
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java36
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy15
2 files changed, 23 insertions, 28 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java
index 770ada0a5f..890522ca60 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java
@@ -52,8 +52,6 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor
@Component
public class CmHandleQueryServiceImpl implements CmHandleQueryService {
-
- private static final String DESCENDANT_PATH = "//";
private static final String ANCESTOR_CM_HANDLES = "/ancestor::cm-handles";
private static final String ALTERNATE_ID = "alternate-id";
private final CpsDataService cpsDataService;
@@ -161,17 +159,6 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
return selectedCmHandleReferences;
}
- private Collection<String> collectCmHandleReferencesFromDataNodes(final Collection<DataNode> dataNodes,
- final boolean outputAlternateId) {
- if (outputAlternateId) {
- return dataNodes.stream().map(dataNode ->
- (String) dataNode.getLeaves().get(ALTERNATE_ID)).collect(Collectors.toSet());
- } else {
- return dataNodes.stream().map(dataNode ->
- (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet());
- }
- }
-
private Collection<String> queryCmHandleAnyProperties(
final Map<String, String> propertyQueryPairs,
final PropertyType propertyType, final boolean outputAlternateId) {
@@ -180,17 +167,11 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
}
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() + "\"]";
-
- final Collection<DataNode> dataNodes = queryCmHandleAncestorsByCpsPath(cpsPath,
- OMIT_DESCENDANTS);
+ final Collection<String> cmHandleReferencesToRetain = getCmHandleReferencesByProperties(propertyType,
+ publicPropertyQueryPair.getKey(), publicPropertyQueryPair.getValue(), outputAlternateId);
if (cmHandleReferences == null) {
- cmHandleReferences = collectCmHandleReferencesFromDataNodes(dataNodes, outputAlternateId);
+ cmHandleReferences = cmHandleReferencesToRetain;
} else {
- final Collection<String> cmHandleReferencesToRetain;
- cmHandleReferencesToRetain = collectCmHandleReferencesFromDataNodes(dataNodes, outputAlternateId);
cmHandleReferences.retainAll(cmHandleReferencesToRetain);
}
if (cmHandleReferences.isEmpty()) {
@@ -217,6 +198,16 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
return cpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cpsPath, String.class);
}
+ private Collection<String> getCmHandleReferencesByProperties(final PropertyType propertyType,
+ final String propertyName,
+ final String propertyValue,
+ final boolean outputAlternateId) {
+ final String attributeName = outputAlternateId ? ALTERNATE_ID : "id";
+ final String cpsPath = String.format("//%s[@name='%s' and @value='%s']%s/@%s",
+ propertyType.getYangContainerName(), propertyName, propertyValue, ANCESTOR_CM_HANDLES, attributeName);
+ 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 + "'")
@@ -230,5 +221,4 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
return cpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
xpath, OMIT_DESCENDANTS).iterator().next();
}
-
} \ No newline at end of file
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy
index 6e6116e409..884d968c4f 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy
@@ -51,7 +51,7 @@ class CmHandleQueryServiceImplSpec extends Specification {
def static sampleDataNodes = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='ch-1']"),
new DataNode(xpath: "/dmi-registry/cm-handles[@id='ch-2']")]
- def dataNodeWithPrivateField = '//additional-properties[@name=\"Contact3\" and @value=\"newemailforstore3@bookstore.com\"]/ancestor::cm-handles'
+ def cpsPathWithPrivateField = '//additional-properties[@name=\'Contact3\' and @value=\'newemailforstore3@bookstore.com\']/ancestor::cm-handles/@id'
def static pnfDemo = createDataNode('PNFDemo')
def static pnfDemo2 = createDataNode('PNFDemo2')
@@ -119,7 +119,7 @@ class CmHandleQueryServiceImplSpec extends Specification {
def 'Query CmHandles by a private field\'s value.'() {
given: 'a data node exists with a certain additional-property'
- mockCpsQueryService.queryDataNodes(_, _, dataNodeWithPrivateField, _) >> [pnfDemo5]
+ mockCpsQueryService.queryDataLeaf(_, _, cpsPathWithPrivateField, _) >> [pnfDemo5.getLeaves().get('id')]
when: 'a query on CmHandle private properties is executed using a map'
def result = objectUnderTest.queryCmHandleAdditionalProperties(['Contact3': 'newemailforstore3@bookstore.com'], false)
then: 'one cm handle is returned'
@@ -169,9 +169,7 @@ class CmHandleQueryServiceImplSpec extends Specification {
}
def 'Retrieve Cm Handles By Operational Sync State : UNSYNCHRONIZED'() {
- given: 'a cm handle state to query'
- def cmHandleState = CmHandleState.READY
- and: 'cps data service returns a list of data nodes'
+ 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
when: 'cm handles are fetched by the UNSYNCHRONIZED operational sync state'
@@ -244,6 +242,13 @@ class CmHandleQueryServiceImplSpec extends Specification {
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')]
+
+ mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '//public-properties[@name=\'Contact\' and @value=\'newemailforstore@bookstore.com\']/ancestor::cm-handles/@id',_) >> [pnfDemo.getLeaves().get('id'), pnfDemo2.getLeaves().get('id'), pnfDemo4.getLeaves().get('id')]
+ mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '//public-properties[@name=\'Contact\' and @value=\'newemailforstore@bookstore.com\']/ancestor::cm-handles/@alternate-id',_) >> [pnfDemo.getLeaves().get('alternate-id'), pnfDemo2.getLeaves().get('alternate-id'), pnfDemo4.getLeaves().get('alternate-id')]
+ mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,'//public-properties[@name=\'Contact2\' and @value=\'newemailforstore2@bookstore.com\']/ancestor::cm-handles/@alternate-id', _) >> [pnfDemo4.getLeaves().get('alternate-id')]
+ mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,'//public-properties[@name=\'Contact2\' and @value=\'newemailforstore2@bookstore.com\']/ancestor::cm-handles/@id', _) >> [pnfDemo4.getLeaves().get('id')]
+ mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,'//public-properties[@name=\'Contact2\' and @value=\'\']/ancestor::cm-handles/@id', _) >> []
+ mockCpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, '//public-properties[@name=\'wont_match\' and @value=\'wont_match\']/ancestor::cm-handles/@id', _) >> []
}
def static createDataNode(dataNodeId) {