2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation
4 * Modifications Copyright (C) 2021 Pantheon.tech
5 * Modifications Copyright (C) 2021-2022 Bell Canada
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.cps.api;
25 import java.time.OffsetDateTime;
26 import org.onap.cps.spi.FetchDescendantsOption;
27 import org.onap.cps.spi.model.DataNode;
30 * Datastore interface for handling CPS data.
32 public interface CpsDataService {
35 * Persists data for the given anchor and dataspace.
37 * @param dataspaceName dataspace name
38 * @param anchorName anchor name
39 * @param jsonData json data
40 * @param observedTimestamp observedTimestamp
42 void saveData(String dataspaceName, String anchorName, String jsonData, OffsetDateTime observedTimestamp);
45 * Persists child data fragment under existing data node for the given anchor and dataspace.
47 * @param dataspaceName dataspace name
48 * @param anchorName anchor name
49 * @param parentNodeXpath parent node xpath
50 * @param jsonData json data
51 * @param observedTimestamp observedTimestamp
53 void saveData(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
54 OffsetDateTime observedTimestamp);
57 * Persists child data fragment representing one or more list elements under existing data node for the
58 * given anchor and dataspace.
60 * @param dataspaceName dataspace name
61 * @param anchorName anchor name
62 * @param parentNodeXpath parent node xpath
63 * @param jsonData json data representing list element(s)
64 * @param observedTimestamp observedTimestamp
66 void saveListElements(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
67 OffsetDateTime observedTimestamp);
70 * Retrieves datanode by XPath for given dataspace and anchor.
72 * @param dataspaceName dataspace name
73 * @param anchorName anchor name
75 * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
76 * (recursively) as well
77 * @return data node object
79 DataNode getDataNode(String dataspaceName, String anchorName, String xpath,
80 FetchDescendantsOption fetchDescendantsOption);
83 * Updates data node for given dataspace and anchor using xpath to parent node.
85 * @param dataspaceName dataspace name
86 * @param anchorName anchor name
87 * @param parentNodeXpath xpath to parent node
88 * @param jsonData json data
89 * @param observedTimestamp observedTimestamp
91 void updateNodeLeaves(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
92 OffsetDateTime observedTimestamp);
95 * Replaces existing data node content including descendants.
97 * @param dataspaceName dataspace name
98 * @param anchorName anchor name
99 * @param parentNodeXpath xpath to parent node
100 * @param jsonData json data
101 * @param observedTimestamp observedTimestamp
103 void replaceNodeTree(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
104 OffsetDateTime observedTimestamp);
107 * Replaces list content by removing all existing elements and inserting the given new elements as json
108 * under given parent, anchor and dataspace.
110 * @param dataspaceName dataspace name
111 * @param anchorName anchor name
112 * @param parentNodeXpath parent node xpath
113 * @param jsonData json data representing the new list elements
114 * @param observedTimestamp observedTimestamp
116 void replaceListContent(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
117 OffsetDateTime observedTimestamp);
120 * Deletes data node for given anchor and dataspace.
122 * @param dataspaceName dataspace name
123 * @param anchorName anchor name
124 * @param dataNodeXpath data node xpath
125 * @param observedTimestamp observed timestamp
127 void deleteDataNode(String dataspaceName, String anchorName, String dataNodeXpath,
128 OffsetDateTime observedTimestamp);
131 * Deletes all data nodes for a given anchor in a dataspace.
133 * @param dataspaceName dataspace name
134 * @param anchorName anchor name
135 * @param observedTimestamp observed timestamp
137 void deleteDataNodes(String dataspaceName, String anchorName, OffsetDateTime observedTimestamp);
140 * Deletes a list or a list-element under given anchor and dataspace.
142 * @param dataspaceName dataspace name
143 * @param anchorName anchor name
144 * @param listElementXpath list element xpath
145 * @param observedTimestamp observedTimestamp
147 void deleteListOrListElement(String dataspaceName, String anchorName, String listElementXpath,
148 OffsetDateTime observedTimestamp);
151 * Updates leaves of DataNode for given dataspace and anchor using xpath, along with the leaves of each Child Data
152 * Node which already exists. This method will throw an exception if data node update or any descendant update does
155 * @param dataspaceName dataspace name
156 * @param anchorName anchor name
157 * @param parentNodeXpath xpath
158 * @param dataNodeUpdatesAsJson json data representing data node updates
159 * @param observedTimestamp observedTimestamp
161 void updateNodeLeavesAndExistingDescendantLeaves(String dataspaceName, String anchorName, String parentNodeXpath,
162 String dataNodeUpdatesAsJson, OffsetDateTime observedTimestamp);