/*
* ============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");
* Get data node with the given cm handle id.
*
* @param cmHandleId cmHandle ID
- * @param fetchDescendantsOption fetchDescendantsOption
+ * @param fetchDescendantsOption fetch descendants option
* @return data node
*/
Collection<DataNode> getCmHandleDataNodeByCmHandleId(String cmHandleId,
* Get collection of data nodes of given cm handles.
*
* @param cmHandleIds collection of cmHandle IDs
+ * @param fetchDescendantsOption fetch descendants option
* @return collection of data nodes
*/
- Collection<DataNode> getCmHandleDataNodes(Collection<String> cmHandleIds);
+ Collection<DataNode> getCmHandleDataNodes(Collection<String> cmHandleIds,
+ FetchDescendantsOption fetchDescendantsOption);
/**
* get CM handles that has given module names.
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2025 Nordix Foundation
+ * Copyright (C) 2022-2025 OpenInfra Foundation Europe. All rights reserved.
* Modifications Copyright (C) 2022 Bell Canada
* Modifications Copyright (C) 2024 TechMahindra Ltd.
* ================================================================================
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.onap.cps.api.CpsAnchorService;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.api.CpsModuleService;
dataValidationException.getMessage());
}
});
- return YangDataConverter.toYangModelCmHandles(getCmHandleDataNodes(validCmHandleIds));
+ return YangDataConverter.toYangModelCmHandles(getCmHandleDataNodes(validCmHandleIds, INCLUDE_ALL_DESCENDANTS));
}
@Override
}
@Override
- public Collection<DataNode> getCmHandleDataNodes(final Collection<String> cmHandleIds) {
+ public Collection<DataNode> getCmHandleDataNodes(final Collection<String> cmHandleIds,
+ final FetchDescendantsOption fetchDescendantsOption) {
final Collection<String> xpaths = new ArrayList<>(cmHandleIds.size());
cmHandleIds.forEach(cmHandleId -> xpaths.add(getXPathForCmHandleById(cmHandleId)));
- return this.getDataNodes(xpaths);
+ return this.getDataNodes(xpaths, fetchDescendantsOption);
}
@Override
public Collection<String> getCmHandleReferencesWithGivenModules(final Collection<String> moduleNamesForQuery,
final boolean outputAlternateId) {
- if (outputAlternateId) {
- final Collection<String> cmHandleIds =
+ final Collection<String> cmHandleIds =
cpsAnchorService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNamesForQuery);
- return getAlternateIdsFromDataNodes(getCmHandleDataNodes(cmHandleIds));
- } else {
- return cpsAnchorService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNamesForQuery);
+ if (outputAlternateId) {
+ return getAlternateIdsForCmHandleIds(cmHandleIds);
}
+ return cmHandleIds;
}
@Override
NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@alternate-id='", "']"));
}
- private String getCpsPathForCmHandlesByReferences(final Collection<String> cmHandleReferences) {
- return cmHandleReferences.stream()
- .flatMap(id -> Stream.of("@id='" + id + "'", "@alternate-id='" + id + "'"))
- .collect(Collectors.joining(" or ", NCMP_DMI_REGISTRY_PARENT + "/cm-handles[", "]"));
- }
-
private static String createStateJsonData(final String state) {
return "{\"state\":" + state + "}";
}
return "{\"cm-handles\":" + jsonObjectMapper.asJsonString(yangModelCmHandles) + "}";
}
- private Collection<String> getAlternateIdsFromDataNodes(final Collection<DataNode> dataNodes) {
- return dataNodes.stream().map(dataNode ->
- (String) dataNode.getLeaves().get("alternate-id")).collect(Collectors.toSet());
+
+ private Collection<String> getAlternateIdsForCmHandleIds(final Collection<String> cmHandleIds) {
+ final Collection<DataNode> dataNodes = getCmHandleDataNodes(cmHandleIds, OMIT_DESCENDANTS);
+ return dataNodes.stream()
+ .map(DataNode::getLeaves)
+ .map(leaves -> (String) leaves.get("alternate-id"))
+ .filter(StringUtils::isNotBlank)
+ .collect(Collectors.toSet());
}
}
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2025 Nordix Foundation
+ * Copyright (C) 2022-2025 OpenInfra Foundation Europe. All rights reserved.
* Modifications Copyright (C) 2022 Bell Canada
* Modifications Copyright (C) 2024 TechMahindra Ltd.
* ================================================================================
}
def 'Get Alternate Ids for CM Handles that has given module names'() {
- given: 'A Collection of data nodes'
- def dataNodes = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='ch-1']", leaves: ['id': 'ch-1', 'alternate-id': 'alt-1'])]
- when: 'the methods to get dataNodes is called and returns correct values'
+ given: 'cps anchor service returns a CM-handle ID for the given module name'
mockCpsAnchorService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, ['sample-module-name']) >> ['ch-1']
- mockCpsDataService.getDataNodesForMultipleXpaths(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, ["/dmi-registry/cm-handles[@id='ch-1']"], INCLUDE_ALL_DESCENDANTS) >> dataNodes
- and: 'the method returns a result'
+ and: 'cps data service returns some data nodes for the given CM-handle ID'
+ def dataNodes = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='ch-1']", leaves: ['id': 'ch-1', 'alternate-id': 'alt-1'])]
+ mockCpsDataService.getDataNodesForMultipleXpaths(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, ["/dmi-registry/cm-handles[@id='ch-1']"], OMIT_DESCENDANTS) >> dataNodes
+ when: 'the method to get cm-handle references by modules is called (outputting alternate IDs)'
def result = objectUnderTest.getCmHandleReferencesWithGivenModules(['sample-module-name'], true)
then: 'the result contains the correct alternate Id'
- assert result == ['alt-1'] as HashSet
+ assert result == ['alt-1'] as Set
}
def 'Replace list content'() {