aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service
diff options
context:
space:
mode:
authorRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-02-01 10:47:25 +0200
committerRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-02-04 07:50:59 +0200
commit1f77f638a8da07d766c8c6d276e7170b24828f85 (patch)
treea04c1dbbab701c719d0092357aa852bf4b49926a /cps-service
parente7f94478a241f8ee7618da08f6bc8495e9f5a504 (diff)
Fetching data node by xpath - persistence layer
IssueID: CPS-71 Change-Id: I88f76cf36ef8a1e4ccbd4f1eac8867e93ed5be82 Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
Diffstat (limited to 'cps-service')
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java14
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/FetchDescendantsOption.java25
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java14
3 files changed, 53 insertions, 0 deletions
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 d59fa47467..97aecaafd1 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 0000000000..0c994d8d7b
--- /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 d187f62e0f..67e93dd82b 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<String, Object> leaves = Collections.emptyMap();
private Collection<DataNode> childDataNodes = Collections.emptySet();
@@ -68,6 +70,17 @@ public class DataNodeBuilder {
}
/**
+ * To use attributes for creating {@link DataNode}.
+ *
+ * @param leaves for the data node
+ * @return DataNodeBuilder
+ */
+ public DataNodeBuilder withLeaves(final Map<String, Object> leaves) {
+ this.leaves = leaves;
+ return this;
+ }
+
+ /**
* To specify child nodes needs to be used while creating {@link DataNode}.
*
* @param childDataNodes to be added to the 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;
}