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 list-node (with one or more 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
66 * @param observedTimestamp observedTimestamp
68 void saveListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
69 @NonNull String jsonData, OffsetDateTime observedTimestamp);
72 * Retrieves datanode by XPath for given dataspace and anchor.
74 * @param dataspaceName dataspace name
75 * @param anchorName anchor name
77 * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
78 * (recursively) as well
79 * @return data node object
81 DataNode getDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String xpath,
82 @NonNull FetchDescendantsOption fetchDescendantsOption);
85 * Updates data node for given dataspace and anchor using xpath to parent node.
87 * @param dataspaceName dataspace name
88 * @param anchorName anchor name
89 * @param parentNodeXpath xpath to parent node
90 * @param jsonData json data
91 * @param observedTimestamp observedTimestamp
93 void updateNodeLeaves(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
94 @NonNull String jsonData, OffsetDateTime observedTimestamp);
97 * Replaces existing data node content including descendants.
99 * @param dataspaceName dataspace name
100 * @param anchorName anchor name
101 * @param parentNodeXpath xpath to parent node
102 * @param jsonData json data
103 * @param observedTimestamp observedTimestamp
105 void replaceNodeTree(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
106 @NonNull String jsonData, OffsetDateTime observedTimestamp);
109 * Replaces (if exists) child data fragment representing list-node (with one or more elements) under existing data
110 * node for the given anchor and dataspace.
112 * @param dataspaceName dataspace name
113 * @param anchorName anchor name
114 * @param parentNodeXpath parent node xpath
115 * @param jsonData json data representing list element
116 * @param observedTimestamp observedTimestamp
118 void replaceListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
119 @NonNull String jsonData, OffsetDateTime observedTimestamp);
122 * Deletes (if exists) child data fragment representing list-node (with one or more elements) under existing data
123 * node for the given anchor and dataspace.
125 * @param dataspaceName dataspace name
126 * @param anchorName anchor name
127 * @param listNodeXpath list node xpath
128 * @param observedTimestamp observedTimestamp
130 void deleteListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String listNodeXpath,
131 OffsetDateTime observedTimestamp);
134 * Updates leaves of DataNode for given dataspace and anchor using xpath, along with the leaves of each Child Data
135 * Node which already exists. This method will throw an exception if data node update or any descendant update does
138 * @param dataspaceName dataspace name
139 * @param anchorName anchor name
140 * @param parentNodeXpath xpath
141 * @param dataNodeUpdatesAsJson json data representing data node updates
142 * @param observedTimestamp observedTimestamp
144 void updateNodeLeavesAndExistingDescendantLeaves(String dataspaceName, String anchorName, String parentNodeXpath,
145 String dataNodeUpdatesAsJson, OffsetDateTime observedTimestamp);