diff options
author | rajesh.kumar <rk00747546@techmahindra.com> | 2022-12-14 14:27:29 +0000 |
---|---|---|
committer | Luke Gleeson <luke.gleeson@est.tech> | 2023-03-21 09:45:16 +0000 |
commit | a317890387fdbc689f8dcd8648b5bfe3b43abd1e (patch) | |
tree | 652b78e62895aa186eb26788eb475634ce2ddce9 /cps-service/src/main | |
parent | 0b00f81b98e5fa9632b1145e49f62d0b2712f4e4 (diff) |
Query data nodes across all anchors under one dataspace
Issue-ID: CPS-1396
Change-ID: I73f97f986a817d423f93a8d922dcd9647b1412ab
Signed-off-by: rajesh.kumar <rk00747546@techmahindra.com>
Diffstat (limited to 'cps-service/src/main')
5 files changed, 62 insertions, 1 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsQueryService.java b/cps-service/src/main/java/org/onap/cps/api/CpsQueryService.java index 68ae1ebf0a..af54077fea 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsQueryService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsQueryService.java @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020-2022 Nordix Foundation + * Modifications Copyright (C) 2022-2023 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,4 +43,15 @@ public interface CpsQueryService { Collection<DataNode> queryDataNodes(String dataspaceName, String anchorName, String cpsPath, FetchDescendantsOption fetchDescendantsOption); + /** + * Get data nodes for the given dataspace across all anchors by cps path. + * + * @param dataspaceName dataspace name + * @param cpsPath CPS path + * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be + * included in the output + * @return a collection of data nodes + */ + Collection<DataNode> queryDataNodesAcrossAnchors(String dataspaceName, String cpsPath, + FetchDescendantsOption fetchDescendantsOption); } diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsQueryServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsQueryServiceImpl.java index a63faabac4..ac018c9e8f 100644 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsQueryServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsQueryServiceImpl.java @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2021-2022 Nordix Foundation + * Modifications Copyright (C) 2022-2023 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,4 +46,11 @@ public class CpsQueryServiceImpl implements CpsQueryService { cpsValidator.validateNameCharacters(dataspaceName, anchorName); return cpsDataPersistenceService.queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption); } + + @Override + public Collection<DataNode> queryDataNodesAcrossAnchors(final String dataspaceName, + final String cpsPath, final FetchDescendantsOption fetchDescendantsOption) { + cpsValidator.validateNameCharacters(dataspaceName); + return cpsDataPersistenceService.queryDataNodesAcrossAnchors(dataspaceName, cpsPath, fetchDescendantsOption); + } } diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java index f10443fda8..540401913b 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java @@ -224,6 +224,19 @@ public interface CpsDataPersistenceService { String cpsPath, FetchDescendantsOption fetchDescendantsOption); /** + * Get a datanode by dataspace name and cps path across all anchors. + * + * @param dataspaceName dataspace name + * @param cpsPath cps path + * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be + * included in the output + * @return the data nodes found i.e. 0 or more data nodes + */ + List<DataNode> queryDataNodesAcrossAnchors(String dataspaceName, + String cpsPath, FetchDescendantsOption fetchDescendantsOption); + + + /** * Starts a session which allows use of locks and batch interaction with the persistence service. * * @return Session ID string diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java b/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java index b23cdfc8d1..6fc36ebb61 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java +++ b/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java @@ -3,7 +3,7 @@ * Copyright (C) 2021 Bell Canada. All rights reserved. * Modifications Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2022 Nordix Foundation. - * Modifications Copyright (C) 2022 TechMahindra Ltd. + * Modifications Copyright (C) 2022-2023 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,6 +54,7 @@ public class DataNodeBuilder { private String parentNodeXpath = ""; private Map<String, Serializable> leaves = Collections.emptyMap(); private Collection<DataNode> childDataNodes = Collections.emptySet(); + private String anchorName; /** * To use parent node xpath for creating {@link DataNode}. @@ -89,6 +90,17 @@ public class DataNodeBuilder { } /** + * To use anchor name for creating {@link DataNode}. + * + * @param anchorName anchor name for the data node + * @return DataNodeBuilder + */ + public DataNodeBuilder withAnchor(final String anchorName) { + this.anchorName = anchorName; + return this; + } + + /** * To use module name for prefix for creating {@link DataNode}. * * @param moduleNamePrefix module name as prefix @@ -153,6 +165,7 @@ public class DataNodeBuilder { dataNode.setModuleNamePrefix(moduleNamePrefix); dataNode.setLeaves(leaves); dataNode.setChildDataNodes(childDataNodes); + dataNode.setAnchorName(anchorName); return dataNode; } diff --git a/cps-service/src/main/java/org/onap/cps/utils/DataMapUtils.java b/cps-service/src/main/java/org/onap/cps/utils/DataMapUtils.java index 14641e05e6..b0e109bafd 100644 --- a/cps-service/src/main/java/org/onap/cps/utils/DataMapUtils.java +++ b/cps-service/src/main/java/org/onap/cps/utils/DataMapUtils.java @@ -3,6 +3,7 @@ * Copyright (C) 2021 Pantheon.tech * Modifications (C) 2021-2022 Nordix Foundation * Modifications Copyright (C) 2022 Bell Canada + * Modifications Copyright (C) 2022-2023 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,6 +50,20 @@ public class DataMapUtils { } /** + * Converts DataNode structure into a map including the root node identifier for a JSON response. + * + * @param dataNode data node object + * @return a map representing same data with the root node identifier + */ + public static Map<String, Object> toDataMapWithIdentifierAndAnchor(final DataNode dataNode, final String prefix) { + final String nodeIdentifierWithPrefix = getNodeIdentifierWithPrefix(dataNode.getXpath(), prefix); + final Map<String, Object> dataMap = ImmutableMap.<String, Object>builder() + .put(nodeIdentifierWithPrefix, toDataMap(dataNode)).build(); + return ImmutableMap.<String, Object>builder().put("anchorName", dataNode.getAnchorName()) + .put("dataNode", dataMap).build(); + } + + /** * Converts DataNode structure into a map for a JSON response. * * @param dataNode data node object |