2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation
4 * Modifications Copyright (C) 2021 Pantheon.tech
5 * Modifications Copyright (C) 2021 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.checkerframework.checker.nullness.qual.NonNull;
27 import org.onap.cps.spi.FetchDescendantsOption;
28 import org.onap.cps.spi.model.DataNode;
31 * Datastore interface for handling CPS data.
33 public interface CpsDataService {
36 * Persists data for the given anchor and dataspace.
38 * @param dataspaceName dataspace name
39 * @param anchorName anchor name
40 * @param jsonData json data
41 * @param observedTimestamp observedTimestamp
43 void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String jsonData,
44 OffsetDateTime observedTimestamp);
47 * Persists child data fragment under existing data node for the given anchor and dataspace.
49 * @param dataspaceName dataspace name
50 * @param anchorName anchor name
51 * @param parentNodeXpath parent node xpath
52 * @param jsonData json data
53 * @param observedTimestamp observedTimestamp
55 void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
56 @NonNull String jsonData, OffsetDateTime observedTimestamp);
59 * Persists child data fragment representing one or more list elements under existing data node for the
60 * given anchor and dataspace.
62 * @param dataspaceName dataspace name
63 * @param anchorName anchor name
64 * @param parentNodeXpath parent node xpath
65 * @param jsonData json data representing list element(s)
66 * @param observedTimestamp observedTimestamp
68 void saveListElements(@NonNull String dataspaceName, @NonNull String anchorName,
69 @NonNull String parentNodeXpath,
70 @NonNull String jsonData, OffsetDateTime observedTimestamp);
73 * Retrieves datanode by XPath for given dataspace and anchor.
75 * @param dataspaceName dataspace name
76 * @param anchorName anchor name
78 * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
79 * (recursively) as well
80 * @return data node object
82 DataNode getDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String xpath,
83 @NonNull FetchDescendantsOption fetchDescendantsOption);
86 * Updates data node for given dataspace and anchor using xpath to parent node.
88 * @param dataspaceName dataspace name
89 * @param anchorName anchor name
90 * @param parentNodeXpath xpath to parent node
91 * @param jsonData json data
92 * @param observedTimestamp observedTimestamp
94 void updateNodeLeaves(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
95 @NonNull String jsonData, OffsetDateTime observedTimestamp);
98 * Replaces existing data node content including descendants.
100 * @param dataspaceName dataspace name
101 * @param anchorName anchor name
102 * @param parentNodeXpath xpath to parent node
103 * @param jsonData json data
104 * @param observedTimestamp observedTimestamp
106 void replaceNodeTree(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
107 @NonNull String jsonData, OffsetDateTime observedTimestamp);
110 * Replaces list content by removing all existing elements and inserting the given new elements as json
111 * under given parent, anchor and dataspace.
113 * @param dataspaceName dataspace name
114 * @param anchorName anchor name
115 * @param parentNodeXpath parent node xpath
116 * @param jsonData json data representing the new list elements
117 * @param observedTimestamp observedTimestamp
119 void replaceListContent(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
120 @NonNull String jsonData, OffsetDateTime observedTimestamp);
123 * Deletes data node for given anchor and dataspace.
125 * @param dataspaceName dataspace name
126 * @param anchorName anchor name
127 * @param dataNodeXpath data node xpath
128 * @param observedTimestamp observed timestamp
130 void deleteDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String dataNodeXpath,
131 OffsetDateTime observedTimestamp);
134 * Deletes a list or a list-element under given anchor and dataspace.
136 * @param dataspaceName dataspace name
137 * @param anchorName anchor name
138 * @param listElementXpath list element xpath
139 * @param observedTimestamp observedTimestamp
141 void deleteListOrListElement(@NonNull String dataspaceName, @NonNull String anchorName,
142 @NonNull String listElementXpath, OffsetDateTime observedTimestamp);
145 * Updates leaves of DataNode for given dataspace and anchor using xpath, along with the leaves of each Child Data
146 * Node which already exists. This method will throw an exception if data node update or any descendant update does
149 * @param dataspaceName dataspace name
150 * @param anchorName anchor name
151 * @param parentNodeXpath xpath
152 * @param dataNodeUpdatesAsJson json data representing data node updates
153 * @param observedTimestamp observedTimestamp
155 void updateNodeLeavesAndExistingDescendantLeaves(String dataspaceName, String anchorName, String parentNodeXpath,
156 String dataNodeUpdatesAsJson, OffsetDateTime observedTimestamp);