From 1f77f638a8da07d766c8c6d276e7170b24828f85 Mon Sep 17 00:00:00 2001 From: Ruslan Kashapov Date: Mon, 1 Feb 2021 10:47:25 +0200 Subject: Fetching data node by xpath - persistence layer IssueID: CPS-71 Change-Id: I88f76cf36ef8a1e4ccbd4f1eac8867e93ed5be82 Signed-off-by: Ruslan Kashapov --- .../onap/cps/spi/CpsDataPersistenceService.java | 14 ++++++++++++ .../org/onap/cps/spi/FetchDescendantsOption.java | 25 ++++++++++++++++++++++ .../org/onap/cps/spi/model/DataNodeBuilder.java | 14 ++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 cps-service/src/main/java/org/onap/cps/spi/FetchDescendantsOption.java (limited to 'cps-service') 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 d59fa4746..97aecaafd 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 @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * Modifications Copyright (C) 2021 Pantheon.tech * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,4 +51,17 @@ public interface CpsDataPersistenceService { */ void addChildDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentXpath, @NonNull DataNode dataNode); + + /** + * Retrieves datanode by XPath for given dataspace and anchor. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @param xpath xpath + * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes + * (recursively) as well + * @return data node object + */ + DataNode getDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String xpath, + @NonNull FetchDescendantsOption fetchDescendantsOption); } diff --git a/cps-service/src/main/java/org/onap/cps/spi/FetchDescendantsOption.java b/cps-service/src/main/java/org/onap/cps/spi/FetchDescendantsOption.java new file mode 100644 index 000000000..0c994d8d7 --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/FetchDescendantsOption.java @@ -0,0 +1,25 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Pantheon.tech + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi; + +public enum FetchDescendantsOption { + OMIT_DESCENDANTS, + INCLUDE_ALL_DESCENDANTS +} 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 d187f62e0..67e93dd82 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 @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2021 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021 Pantheon.tech * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,6 +43,7 @@ public class DataNodeBuilder { private NormalizedNode normalizedNodeTree; private String xpath; + private Map leaves = Collections.emptyMap(); private Collection childDataNodes = Collections.emptySet(); @@ -67,6 +69,17 @@ public class DataNodeBuilder { return this; } + /** + * To use attributes for creating {@link DataNode}. + * + * @param leaves for the data node + * @return DataNodeBuilder + */ + public DataNodeBuilder withLeaves(final Map leaves) { + this.leaves = leaves; + return this; + } + /** * To specify child nodes needs to be used while creating {@link DataNode}. * @@ -96,6 +109,7 @@ public class DataNodeBuilder { private DataNode buildFromAttributes() { final DataNode dataNode = new DataNode(); dataNode.setXpath(xpath); + dataNode.setLeaves(leaves); dataNode.setChildDataNodes(childDataNodes); return dataNode; } -- cgit 1.2.3-korg