2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation
4 * Modifications Copyright (C) 2021 Pantheon.tech
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.cps.api;
24 import org.checkerframework.checker.nullness.qual.NonNull;
25 import org.onap.cps.spi.FetchDescendantsOption;
26 import org.onap.cps.spi.model.DataNode;
29 * Datastore interface for handling CPS data.
31 public interface CpsDataService {
34 * Persists data for the given anchor and dataspace.
36 * @param dataspaceName dataspace name
37 * @param anchorName anchor name
38 * @param jsonData json data
40 void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String jsonData);
43 * Persists child data fragment under existing data node for the given anchor and dataspace.
45 * @param dataspaceName dataspace name
46 * @param anchorName anchor name
47 * @param parentNodeXpath parent node xpath
48 * @param jsonData json data
50 void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
51 @NonNull String jsonData);
54 * Persists child data fragment representing list-node (with one or more elements) under existing data node
55 * for the given anchor and dataspace.
57 * @param dataspaceName dataspace name
58 * @param anchorName anchor name
59 * @param parentNodeXpath parent node xpath
60 * @param jsonData json data representing list element
62 void saveListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
63 @NonNull String jsonData);
66 * Retrieves datanode by XPath for given dataspace and anchor.
68 * @param dataspaceName dataspace name
69 * @param anchorName anchor name
71 * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
72 * (recursively) as well
73 * @return data node object
75 DataNode getDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String xpath,
76 @NonNull FetchDescendantsOption fetchDescendantsOption);
79 * Updates data node for given dataspace and anchor using xpath to parent node.
81 * @param dataspaceName dataspace name
82 * @param anchorName anchor name
83 * @param parentNodeXpath xpath to parent node
84 * @param jsonData json data
86 void updateNodeLeaves(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
87 @NonNull String jsonData);
90 * Replaces existing data node content including descendants.
92 * @param dataspaceName dataspace name
93 * @param anchorName anchor name
94 * @param parentNodeXpath xpath to parent node
95 * @param jsonData json data
97 void replaceNodeTree(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
98 @NonNull String jsonData);
101 * Replaces (if exists) child data fragment representing list-node (with one or more elements)
102 * under existing data node for the given anchor and dataspace.
104 * @param dataspaceName dataspace name
105 * @param anchorName anchor name
106 * @param parentNodeXpath parent node xpath
107 * @param jsonData json data representing list element
109 void replaceListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
110 @NonNull String jsonData);
113 * Deletes (if exists) child data fragment representing list-node (with one or more elements)
114 * under existing data node for the given anchor and dataspace.
116 * @param dataspaceName dataspace name
117 * @param anchorName anchor name
118 * @param listNodeXpath list node xpath
120 void deleteListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String listNodeXpath);
123 * Updates leaves of DataNode for given dataspace and anchor using xpath,
124 * along with the leaves of each Child Data Node which already exists.
125 * This method will throw an exception if data node update or any descendant update does not exist.
127 * @param dataspaceName dataspace name
128 * @param anchorName anchor name
129 * @param parentNodeXpath xpath
130 * @param dataNodeUpdatesAsJson json data representing data node updates
132 void updateNodeLeavesAndExistingDescendantLeaves(String dataspaceName, String anchorName, String parentNodeXpath,
133 String dataNodeUpdatesAsJson);