aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java11
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java21
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java8
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy17
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy24
-rw-r--r--cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentPrefetchRepository.java2
-rw-r--r--cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentPrefetchRepositoryImpl.java32
7 files changed, 78 insertions, 37 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java
index d6b947697e..15aa1213aa 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2025 Nordix Foundation
+ * Copyright (C) 2022-2025 OpenInfra Foundation Europe. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -130,4 +130,13 @@ public interface CmHandleQueryService {
*/
Collection<String> getAllCmHandleReferences(boolean outputAlternateId);
+ /**
+ * Retrieves all Cm handle references by cps path.
+ *
+ * @param cpsPath cps path for which the cmHandle is requested
+ * @param outputAlternateId If {@code true}, returns alternate ids; if {@code false}, returns standard cm handle ids
+ * @return collection of cm handle references. Returns an empty collection if no references are found.
+ */
+ Collection<String> getCmHandleReferencesByCpsPath(String cpsPath, boolean outputAlternateId);
+
}
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 4a753bd8f4..bdf3785a7a 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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2025 Nordix Foundation
+ * Copyright (C) 2022-2025 OpenInfra Foundation Europe. All rights reserved.
* Modifications Copyright (C) 2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -152,6 +152,25 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService {
return cpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cpsPath, String.class);
}
+ @Override
+ public Collection<String> getCmHandleReferencesByCpsPath(final String cpsPath, final boolean outputAlternateId) {
+ final String cpsPathInQuery;
+ final String cpsPathInQueryWithAttribute;
+ if (CpsPathUtil.getCpsPathQuery(cpsPath).getXpathPrefix().endsWith("/cm-handles")) {
+ cpsPathInQuery = cpsPath;
+ } else {
+ cpsPathInQuery = cpsPath + ANCESTOR_CM_HANDLES;
+ }
+
+ if (outputAlternateId) {
+ cpsPathInQueryWithAttribute = cpsPathInQuery + "/@alternate-id";
+ } else {
+ cpsPathInQueryWithAttribute = cpsPathInQuery + "/@id";
+ }
+ return cpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ cpsPathInQueryWithAttribute, String.class);
+ }
+
private Collection<String> getCmHandleReferencesByTrustLevel(final TrustLevel targetTrustLevel,
final boolean outputAlternateId) {
final Collection<String> selectedCmHandleReferences = new HashSet<>();
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java
index 9ce0e04ed2..84a4533d30 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2025 Nordix Foundation
+ * Copyright (C) 2022-2025 OpenInfra Foundation Europe. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
package org.onap.cps.ncmp.impl.inventory;
import static org.onap.cps.api.parameters.FetchDescendantsOption.DIRECT_CHILDREN_ONLY;
-import static org.onap.cps.api.parameters.FetchDescendantsOption.OMIT_DESCENDANTS;
import static org.onap.cps.ncmp.impl.inventory.CmHandleQueryParametersValidator.validateCpsPathConditionProperties;
import static org.onap.cps.ncmp.impl.inventory.CmHandleQueryParametersValidator.validateModuleNameConditionProperties;
import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT;
@@ -189,9 +188,8 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan
return NO_QUERY_TO_EXECUTE;
}
try {
- cpsPathQueryResult = collectCmHandleReferencesFromDataNodes(
- cmHandleQueryService.queryCmHandleAncestorsByCpsPath(cpsPathCondition.get("cpsPath"),
- OMIT_DESCENDANTS), outputAlternateId);
+ cpsPathQueryResult = cmHandleQueryService.getCmHandleReferencesByCpsPath(cpsPathCondition.get("cpsPath"),
+ outputAlternateId);
} catch (final PathParsingException pathParsingException) {
throw new DataValidationException(pathParsingException.getMessage(), pathParsingException.getDetails(),
pathParsingException);
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 57210c5e50..e978121644 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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2025 Nordix Foundation
+ * Copyright (C) 2022-2025 OpenInfra Foundation Europe. All rights reserved.
* Modifications Copyright (C) 2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -234,6 +234,20 @@ class CmHandleQueryServiceImplSpec extends Specification {
'output is cm handle ids' | false || ['PNFDemo', 'PNFDemo2', 'PNFDemo3', 'PNFDemo4', 'PNFDemo5']
}
+ def 'Get all cm handle references by cps path'() {
+ when: 'the all cm handle references is retrieved via cps path'
+ objectUnderTest.getCmHandleReferencesByCpsPath(sampleCpsPath, outputAlternateId)
+ then: 'query service to query data leaf is called once with the correct cps path as parameter'
+ 1 * mockCpsQueryService.queryDataLeaf(_, _, expectedCpsPathForQuery,_)
+ where:
+ scenario | sampleCpsPath | outputAlternateId || expectedCpsPathForQuery
+ 'cps path suffixes with cm-handles and outputs alternateId' | '/some/path/ending/in/cm-handles' | true || '/some/path/ending/in/cm-handles/@alternate-id'
+ 'cps path suffixes without cm-handles and outputs alternateId'| '/some/path/NotEnding/incmhandles'| true || '/some/path/NotEnding/incmhandles/ancestor::cm-handles/@alternate-id'
+ 'cps path suffixes with cm-handles and outputs cmHandleId' | '/some/path/ending/in/cm-handles' | false || '/some/path/ending/in/cm-handles/@id'
+ 'cps path suffixes without cm-handles and outputs cmhandleId' | '/some/path/NotEnding/incmhandles'| false || '/some/path/NotEnding/incmhandles/ancestor::cm-handles/@id'
+
+ }
+
void mockResponses() {
mockCpsQueryService.queryDataLeaf(_, _, '//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')]
@@ -261,6 +275,7 @@ class CmHandleQueryServiceImplSpec extends Specification {
mockCpsQueryService.queryDataLeaf(_, _, '/dmi-registry/cm-handles/@alternate-id', _) >> getAllCmHandleReferences(true)
mockCpsQueryService.queryDataLeaf(_, _, '/dmi-registry/cm-handles/@id', _) >> getAllCmHandleReferences(false)
+
}
def static createDataNode(dataNodeId) {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy
index 8bb4551f79..4541576ee9 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2025 Nordix Foundation
+ * Copyright (C) 2022-2025 OpenInfra Foundation Europe. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,16 +49,16 @@ class ParameterizedCmHandleQueryServiceSpec extends Specification {
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.queryCmHandleAncestorsByCpsPath('/some/cps/path', FetchDescendantsOption.OMIT_DESCENDANTS) >> [new DataNode(leaves: ['id':'some-cmhandle-id', 'alternate-id':'some-alternate-id'])]
+ and: 'the query get the cm handle references'
+ cmHandleQueries.getCmHandleReferencesByCpsPath('/some/cps/path', outputAlternateId) >> cmHandleReferences.asCollection()
when: 'the query is executed for cm handle ids'
def result = objectUnderTest.queryCmHandleReferenceIds(cmHandleQueryParameters, outputAlternateId)
then: 'the correct expected cm handles ids are returned'
assert result == expectedCmhandleReference
where: 'the following data is used'
- senario | outputAlternateId || expectedCmhandleReference
- 'output CmHandle Ids' | false || ['some-cmhandle-id'] as Set
- 'output Alternate Ids' | true || ['some-alternate-id'] as Set
+ senario | outputAlternateId | cmHandleReferences || expectedCmhandleReference
+ 'output CmHandle Ids' | false | ['some-cmhandle-id'] as Set || ['some-cmhandle-id'] as Set
+ 'output Alternate Ids' | true | ['some-alternate-id'] as Set || ['some-alternate-id'] as Set
}
def 'Query cm handle where cps path itself is ancestor axis.'() {
@@ -66,16 +66,16 @@ class ParameterizedCmHandleQueryServiceSpec extends Specification {
def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
def conditionProperties = createConditionProperties('cmHandleWithCpsPath', [['cpsPath' : '/some/cps/path']])
cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties])
- and: 'the query get the cm handle data nodes excluding all descendants returns a datanode'
- cmHandleQueries.queryCmHandleAncestorsByCpsPath('/some/cps/path', FetchDescendantsOption.OMIT_DESCENDANTS) >> [new DataNode(leaves: ['id':'some-cmhandle-id', 'alternate-id':'some-alternate-id'])]
+ and: 'the query get the cm handle references'
+ cmHandleQueries.getCmHandleReferencesByCpsPath('/some/cps/path', outputAlternateId) >> cmHandleReferences.asCollection()
when: 'the query is executed for cm handle ids'
def result = objectUnderTest.queryCmHandleIdsForInventory(cmHandleQueryParameters, outputAlternateId)
then: 'the correct expected cm handles ids are returned'
assert result == expectedCmhandleReference
where: 'the following data is used'
- senario | outputAlternateId || expectedCmhandleReference
- 'outputAlternate is false' | false || ['some-cmhandle-id'] as Set
- 'outputAlternate is true' | true || ['some-alternate-id'] as Set
+ senario | outputAlternateId | cmHandleReferences || expectedCmhandleReference
+ 'outputAlternate is false' | false | ['some-cmhandle-id'] as Set || ['some-cmhandle-id'] as Set
+ 'outputAlternate is true' | true | ['some-alternate-id'] as Set|| ['some-alternate-id'] as Set
}
def 'Cm handle ids query with error: #scenario.'() {
@@ -84,7 +84,7 @@ class ParameterizedCmHandleQueryServiceSpec extends Specification {
def conditionProperties = createConditionProperties('cmHandleWithCpsPath', [['cpsPath' : '/some/cps/path']])
cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties])
and: 'cmHandleQueries throws a path parsing exception'
- cmHandleQueries.queryCmHandleAncestorsByCpsPath('/some/cps/path', FetchDescendantsOption.OMIT_DESCENDANTS) >> { throw thrownException }
+ cmHandleQueries.getCmHandleReferencesByCpsPath('/some/cps/path', _) >> { throw thrownException }
when: 'the query is executed for cm handle ids'
objectUnderTest.queryCmHandleReferenceIds(cmHandleQueryParameters, false)
then: 'a data validation exception is thrown'
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentPrefetchRepository.java b/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentPrefetchRepository.java
index 87d7697df4..75853319da 100644
--- a/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentPrefetchRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentPrefetchRepository.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation.
+ * Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentPrefetchRepositoryImpl.java b/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentPrefetchRepositoryImpl.java
index 6b95213a13..decd864611 100644
--- a/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentPrefetchRepositoryImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentPrefetchRepositoryImpl.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation.
+ * Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,8 +52,7 @@ public class FragmentPrefetchRepositoryImpl implements FragmentPrefetchRepositor
return proxiedFragmentEntities;
}
- final List<Long> fragmentEntityIds = proxiedFragmentEntities.stream()
- .map(FragmentEntity::getId).collect(Collectors.toList());
+ final List<Long> fragmentEntityIds = proxiedFragmentEntities.stream().map(FragmentEntity::getId).toList();
final Map<Long, AnchorEntity> anchorEntityPerId = proxiedFragmentEntities.stream()
.map(FragmentEntity::getAnchor)
@@ -69,19 +68,20 @@ public class FragmentPrefetchRepositoryImpl implements FragmentPrefetchRepositor
final Collection<Long> fragmentEntityIds,
final Map<Long, AnchorEntity> anchorEntityPerId,
final int maxDepth) {
- final String sql
- = "WITH RECURSIVE parent_search AS ("
- + " SELECT id, 0 AS depth "
- + " FROM fragment "
- + " WHERE id = ANY (?) "
- + " UNION "
- + " SELECT child.id, depth + 1 "
- + " FROM fragment child INNER JOIN parent_search parent ON child.parent_id = parent.id"
- + " WHERE depth < ?"
- + ") "
- + "SELECT fragment.id, anchor_id AS anchorId, xpath, parent_id AS parentId, "
- + " CAST(attributes AS TEXT) AS attributes "
- + "FROM fragment INNER JOIN parent_search ON fragment.id = parent_search.id";
+ final String sql = """
+ WITH RECURSIVE fragment_hierarchy AS (
+ SELECT id, anchor_id, xpath, parent_id, attributes, 0 AS depth
+ FROM fragment
+ WHERE id = ANY(?)
+ UNION
+ SELECT child.id, child.anchor_id, child.xpath, child.parent_id, child.attributes, depth + 1
+ FROM fragment child
+ INNER JOIN fragment_hierarchy parent ON child.parent_id = parent.id
+ WHERE depth < ?
+ )
+ SELECT id, anchor_id AS anchorId, xpath, parent_id AS parentId, attributes
+ FROM fragment_hierarchy;
+ """;
final PreparedStatementSetter preparedStatementSetter = preparedStatement -> {
final Connection connection = preparedStatement.getConnection();