Fetch CM handles by collection of xpaths
[cps.git] / cps-service / src / main / java / org / onap / cps / api / CpsDataService.java
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2020-2022 Nordix Foundation
4  *  Modifications Copyright (C) 2021 Pantheon.tech
5  *  Modifications Copyright (C) 2021-2022 Bell Canada
6  *  Modifications Copyright (C) 2022 Deutsche Telekom AG
7  *  ================================================================================
8  *  Licensed under the Apache License, Version 2.0 (the "License");
9  *  you may not use this file except in compliance with the License.
10  *  You may obtain a copy of the License at
11  *
12  *        http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *  Unless required by applicable law or agreed to in writing, software
15  *  distributed under the License is distributed on an "AS IS" BASIS,
16  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  See the License for the specific language governing permissions and
18  *  limitations under the License.
19  *
20  *  SPDX-License-Identifier: Apache-2.0
21  *  ============LICENSE_END=========================================================
22  */
23
24 package org.onap.cps.api;
25
26 import java.time.OffsetDateTime;
27 import java.util.Collection;
28 import java.util.Map;
29 import org.onap.cps.spi.FetchDescendantsOption;
30 import org.onap.cps.spi.model.DataNode;
31 import org.onap.cps.utils.ContentType;
32
33 /*
34  * Datastore interface for handling CPS data.
35  */
36 public interface CpsDataService {
37
38     /**
39      * Persists data for the given anchor and dataspace.
40      *
41      * @param dataspaceName dataspace name
42      * @param anchorName    anchor name
43      * @param nodeData      node data
44      * @param observedTimestamp observedTimestamp
45      */
46     void saveData(String dataspaceName, String anchorName, String nodeData, OffsetDateTime observedTimestamp);
47
48     /**
49      * Persists data for the given anchor and dataspace.
50      *
51      * @param dataspaceName dataspace name
52      * @param anchorName    anchor name
53      * @param nodeData      node data
54      * @param observedTimestamp observedTimestamp
55      * @param contentType       node data content type
56      */
57     void saveData(String dataspaceName, String anchorName, String nodeData, OffsetDateTime observedTimestamp,
58                   ContentType contentType);
59
60     /**
61      * Persists child data fragment under existing data node for the given anchor and dataspace.
62      *
63      * @param dataspaceName   dataspace name
64      * @param anchorName      anchor name
65      * @param parentNodeXpath parent node xpath
66      * @param nodeData        node data
67      * @param observedTimestamp observedTimestamp
68      */
69     void saveData(String dataspaceName, String anchorName, String parentNodeXpath, String nodeData,
70                   OffsetDateTime observedTimestamp);
71
72     /**
73      * Persists child data fragment under existing data node for the given anchor, dataspace and content type.
74      *
75      * @param dataspaceName     dataspace name
76      * @param anchorName        anchor name
77      * @param parentNodeXpath   parent node xpath
78      * @param nodeData          node data
79      * @param observedTimestamp observedTimestamp
80      * @param contentType       node data content type
81      *
82      */
83     void saveData(String dataspaceName, String anchorName, String parentNodeXpath, String nodeData,
84                   OffsetDateTime observedTimestamp, ContentType contentType);
85
86     /**
87      * Persists child data fragment representing one or more list elements under existing data node for the
88      * given anchor and dataspace.
89      *
90      * @param dataspaceName     dataspace name
91      * @param anchorName        anchor name
92      * @param parentNodeXpath   parent node xpath
93      * @param jsonData          json data representing list element(s)
94      * @param observedTimestamp observedTimestamp
95      */
96     void saveListElements(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
97         OffsetDateTime observedTimestamp);
98
99     /**
100      * Persists child data fragment representing one or more list elements under existing data node for the
101      * given anchor and dataspace.
102      *
103      * @param dataspaceName     dataspace name
104      * @param anchorName        anchor name
105      * @param parentNodeXpath   parent node xpath
106      * @param jsonDataList      collection of json data representing list element(s)
107      * @param observedTimestamp observedTimestamp
108      */
109     void saveListElementsBatch(String dataspaceName, String anchorName, String parentNodeXpath,
110             Collection<String> jsonDataList, OffsetDateTime observedTimestamp);
111
112     /**
113      * Retrieves datanode by XPath for given dataspace and anchor.
114      *
115      * @param dataspaceName          dataspace name
116      * @param anchorName             anchor name
117      * @param xpath                  xpath
118      * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
119      *                               (recursively) as well
120      * @return data node object
121      */
122     DataNode getDataNode(String dataspaceName, String anchorName, String xpath,
123         FetchDescendantsOption fetchDescendantsOption);
124
125     /**
126      * Retrieves datanodes by XPath for given dataspace and anchor.
127      *
128      * @param dataspaceName          dataspace name
129      * @param anchorName             anchor name
130      * @param xpaths                 collection of xpath
131      * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
132      *                               (recursively) as well
133      * @return data node object
134      */
135     Collection<DataNode> getDataNodes(String dataspaceName, String anchorName, Collection<String> xpaths,
136                          FetchDescendantsOption fetchDescendantsOption);
137
138     /**
139      * Updates data node for given dataspace and anchor using xpath to parent node.
140      *
141      * @param dataspaceName   dataspace name
142      * @param anchorName      anchor name
143      * @param parentNodeXpath xpath to parent node
144      * @param jsonData        json data
145      * @param observedTimestamp observedTimestamp
146      */
147     void updateNodeLeaves(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
148         OffsetDateTime observedTimestamp);
149
150     /**
151      * Replaces an existing data node's content including descendants.
152      *
153      * @param dataspaceName   dataspace name
154      * @param anchorName      anchor name
155      * @param parentNodeXpath xpath to parent node
156      * @param jsonData        json data
157      * @param observedTimestamp observedTimestamp
158      */
159     void updateDataNodeAndDescendants(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
160                                        OffsetDateTime observedTimestamp);
161
162     /**
163      * Replaces multiple existing data nodes' content including descendants in a batch operation.
164      *
165      * @param dataspaceName   dataspace name
166      * @param anchorName      anchor name
167      * @param nodesJsonData   map of xpath and node JSON data
168      * @param observedTimestamp observedTimestamp
169      */
170     void updateDataNodesAndDescendants(String dataspaceName, String anchorName, Map<String, String> nodesJsonData,
171                                        OffsetDateTime observedTimestamp);
172
173     /**
174      * Replaces list content by removing all existing elements and inserting the given new elements as json
175      * under given parent, anchor and dataspace.
176      *
177      * @param dataspaceName     dataspace name
178      * @param anchorName        anchor name
179      * @param parentNodeXpath   parent node xpath
180      * @param jsonData          json data representing the new list elements
181      * @param observedTimestamp observedTimestamp
182      */
183     void replaceListContent(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
184         OffsetDateTime observedTimestamp);
185
186     /**
187      * Replaces list content by removing all existing elements and inserting the given new elements as data nodes
188      * under given parent, anchor and dataspace.
189      *
190      * @param dataspaceName     dataspace-name
191      * @param anchorName        anchor name
192      * @param parentNodeXpath   parent node xpath
193      * @param dataNodes         datanodes representing the updated data
194      * @param observedTimestamp observedTimestamp
195      */
196     void replaceListContent(String dataspaceName, String anchorName, String parentNodeXpath,
197             Collection<DataNode> dataNodes, OffsetDateTime observedTimestamp);
198
199     /**
200      * Deletes data node for given anchor and dataspace.
201      *
202      * @param dataspaceName dataspace name
203      * @param anchorName anchor name
204      * @param dataNodeXpath data node xpath
205      * @param observedTimestamp observed timestamp
206      */
207     void deleteDataNode(String dataspaceName, String anchorName, String dataNodeXpath,
208         OffsetDateTime observedTimestamp);
209
210     /**
211      * Deletes all data nodes for a given anchor in a dataspace.
212      *
213      * @param dataspaceName     dataspace name
214      * @param anchorName       anchor name
215      * @param observedTimestamp observed timestamp
216      */
217     void deleteDataNodes(String dataspaceName, String anchorName, OffsetDateTime observedTimestamp);
218
219     /**
220      * Deletes a list or a list-element under given anchor and dataspace.
221      *
222      * @param dataspaceName dataspace name
223      * @param anchorName    anchor name
224      * @param listElementXpath list element xpath
225      * @param observedTimestamp observedTimestamp
226      */
227     void deleteListOrListElement(String dataspaceName, String anchorName, String listElementXpath,
228         OffsetDateTime observedTimestamp);
229
230     /**
231      * Updates leaves of DataNode for given dataspace and anchor using xpath, along with the leaves of each Child Data
232      * Node which already exists. This method will throw an exception if data node update or any descendant update does
233      * not exist.
234      *
235      * @param dataspaceName         dataspace name
236      * @param anchorName            anchor name
237      * @param parentNodeXpath       xpath
238      * @param dataNodeUpdatesAsJson json data representing data node updates
239      * @param observedTimestamp observedTimestamp
240      */
241     void updateNodeLeavesAndExistingDescendantLeaves(String dataspaceName, String anchorName, String parentNodeXpath,
242         String dataNodeUpdatesAsJson, OffsetDateTime observedTimestamp);
243
244     /**
245      * Starts a session which allows use of locks and batch interaction with the persistence service.
246      *
247      * @return Session ID string
248      */
249     String startSession();
250
251     /**
252      * Close session.
253      *
254      * @param sessionId session ID
255      *
256      */
257     void closeSession(String sessionId);
258
259     /**
260      * Lock anchor with default timeout.
261      * To release locks(s), the session holding the lock(s) must be closed.
262      *
263      * @param sessionID session ID
264      * @param dataspaceName dataspace name
265      * @param anchorName anchor name
266      */
267     void lockAnchor(String sessionID, String dataspaceName, String anchorName);
268
269     /**
270      * Lock anchor with custom timeout.
271      * To release locks(s), the session holding the lock(s) must be closed.
272      *
273      * @param sessionID session ID
274      * @param dataspaceName dataspace name
275      * @param anchorName anchor name
276      * @param timeoutInMilliseconds lock attempt timeout in milliseconds
277      */
278     void lockAnchor(String sessionID, String dataspaceName, String anchorName, Long timeoutInMilliseconds);
279 }