Merge "[CPS] RI: Code Refactoring # Replace '[\s\S]' to '.' as it is same as '.'...
[cps.git] / cps-service / src / main / java / org / onap / cps / spi / CpsDataPersistenceService.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020-2023 Nordix Foundation.
4  *  Modifications Copyright (C) 2021 Pantheon.tech
5  *  Modifications Copyright (C) 2022 Bell Canada
6  *  Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
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.spi;
25
26 import java.io.Serializable;
27 import java.util.Collection;
28 import java.util.List;
29 import java.util.Map;
30 import org.onap.cps.spi.model.DataNode;
31
32 /*
33     Data Store interface that is responsible for handling yang data.
34     Please follow guidelines in https://gerrit.nordix.org/#/c/onap/ccsdk/features/+/6698/19/cps/interface-proposal/src/main/java/cps/javadoc/spi/DataStoreService.java
35     when adding methods.
36  */
37 public interface CpsDataPersistenceService {
38
39     /**
40      * Store multiple datanodes at once.
41      * @param dataspaceName dataspace name
42      * @param anchorName    anchor name
43      * @param dataNodes     data nodes
44      */
45     void storeDataNodes(String dataspaceName, String anchorName, Collection<DataNode> dataNodes);
46
47     /**
48      * Add a child to a Fragment.
49      *
50      * @param dataspaceName dataspace name
51      * @param anchorName    anchor name
52      * @param parentXpath   parent xpath
53      * @param dataNode      dataNode
54      */
55     void addChildDataNode(String dataspaceName, String anchorName, String parentXpath, DataNode dataNode);
56
57     /**
58      * Add multiple children to a Fragment.
59      *
60      * @param dataspaceName dataspace name
61      * @param anchorName    anchor name
62      * @param parentXpath   parent xpath
63      * @param dataNodes     collection of dataNodes
64      */
65     void addChildDataNodes(String dataspaceName, String anchorName, String parentXpath, Collection<DataNode> dataNodes);
66
67     /**
68      * Adds list child elements to a Fragment.
69      *
70      * @param dataspaceName          dataspace name
71      * @param anchorName             anchor name
72      * @param parentNodeXpath        parent node xpath
73      * @param listElementsCollection collection of data nodes representing list elements
74      */
75     void addListElements(String dataspaceName, String anchorName, String parentNodeXpath,
76         Collection<DataNode> listElementsCollection);
77
78     /**
79      * Add multiple lists of data nodes to a parent node at the same time.
80      *
81      * @param dataspaceName           dataspace name
82      * @param anchorName              anchor name
83      * @param parentNodeXpath         parent node xpath
84      * @param newLists collections of lists of data nodes representing list elements
85      */
86     void addMultipleLists(String dataspaceName, String anchorName, String parentNodeXpath,
87             Collection<Collection<DataNode>> newLists);
88
89     /**
90      * Retrieves multiple datanodes for a single XPath for given dataspace and anchor.
91      * Multiple data nodes are returned when xPath is set to root '/', otherwise single data node
92      * is returned when a specific xpath is used (Example: /bookstore).
93      *
94      * @param dataspaceName          dataspace name
95      * @param anchorName             anchor name
96      * @param xpath                  one xpath
97      * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
98      *                               (recursively) as well
99      * @return collection of data node object
100      */
101     Collection<DataNode> getDataNodes(String dataspaceName, String anchorName, String xpath,
102                                       FetchDescendantsOption fetchDescendantsOption);
103
104     /**
105      * Retrieves multiple datanodes for multiple XPaths, given a dataspace and anchor.
106      *
107      * @param dataspaceName           dataspace name
108      * @param anchorName              anchor name
109      * @param xpaths                  collection of xpaths
110      * @param fetchDescendantsOption  defines the scope of data to fetch: either single node or all the descendant nodes
111      *                                (recursively) as well
112      * @return collection of data node object
113      */
114     Collection<DataNode> getDataNodesForMultipleXpaths(String dataspaceName, String anchorName,
115                                                        Collection<String> xpaths,
116                                                        FetchDescendantsOption fetchDescendantsOption);
117
118     /**
119      * Updates leaves for existing data node.
120      *
121      * @param dataspaceName dataspace name
122      * @param anchorName    anchor name
123      * @param xpath         xpath
124      * @param leaves        the leaves as a map where key is a leaf name and a value is a leaf value
125      */
126     void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Serializable> leaves);
127
128     /**
129      * Replaces multiple existing data nodes' content including descendants in a batch operation.
130      *
131      * @param dataspaceName dataspace name
132      * @param anchorName    anchor name
133      * @param dataNodes     data nodes
134      */
135     void updateDataNodesAndDescendants(String dataspaceName, String anchorName, final Collection<DataNode> dataNodes);
136
137     /**
138      * Replaces list content by removing all existing elements and inserting the given new elements
139      * under given parent, anchor and dataspace.
140      *
141      * @param dataspaceName   dataspace name
142      * @param anchorName      anchor name
143      * @param parentNodeXpath parent node xpath
144      * @param newListElements collection of data nodes representing the new list content
145      */
146     void replaceListContent(String dataspaceName, String anchorName,
147                             String parentNodeXpath, Collection<DataNode> newListElements);
148
149     /**
150      * Deletes any dataNode, yang container or yang list or yang list element.
151      *
152      * @param dataspaceName   dataspace name
153      * @param anchorName      anchor name
154      * @param targetXpath     xpath to list or list element (include [@key=value] to delete a single list element)
155      */
156     void deleteDataNode(String dataspaceName, String anchorName, String targetXpath);
157
158     /**
159      * Deletes multiple dataNode, yang container or yang list or yang list element.
160      *
161      * @param dataspaceName   dataspace name
162      * @param anchorName      anchor name
163      * @param targetXpaths    xpaths of nodes to delete
164      */
165     void deleteDataNodes(String dataspaceName, String anchorName, Collection<String> targetXpaths);
166
167     /**
168      * Deletes all dataNodes in a given anchor.
169      *
170      * @param dataspaceName   dataspace name
171      * @param anchorName      anchor name
172      */
173     void deleteDataNodes(String dataspaceName, String anchorName);
174
175     /**
176      * Deletes all dataNodes in multiple anchors.
177      *
178      * @param dataspaceName   dataspace name
179      * @param anchorNames     anchor names
180      */
181     void deleteDataNodes(String dataspaceName, Collection<String> anchorNames);
182
183     /**
184      * Deletes a single existing list element or the whole list.
185      *
186      * @param dataspaceName   dataspace name
187      * @param anchorName      anchor name
188      * @param targetXpath     xpath to list or list element (include [@key=value] to delete a single list element)
189      */
190     void deleteListDataNode(String dataspaceName, String anchorName, String targetXpath);
191
192     /**
193      * Get a datanode by cps path.
194      *
195      * @param dataspaceName          dataspace name
196      * @param anchorName             anchor name
197      * @param cpsPath                cps path
198      * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be
199      *                               included in the output
200      * @return the data nodes found i.e. 0 or more data nodes
201      */
202     List<DataNode> queryDataNodes(String dataspaceName, String anchorName,
203                                   String cpsPath, FetchDescendantsOption fetchDescendantsOption);
204
205     /**
206      * Get a datanode by dataspace name and cps path across all anchors.
207      *
208      * @param dataspaceName          dataspace name
209      * @param cpsPath                cps path
210      * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be
211      *                               included in the output
212      * @return the data nodes found i.e. 0 or more data nodes
213      */
214     List<DataNode> queryDataNodesAcrossAnchors(String dataspaceName,
215                                   String cpsPath, FetchDescendantsOption fetchDescendantsOption);
216
217
218     /**
219      * Starts a session which allows use of locks and batch interaction with the persistence service.
220      *
221      * @return Session ID string
222      */
223     String startSession();
224
225     /**
226      * Close session.
227      *
228      * @param sessionId session ID
229      */
230     void closeSession(String sessionId);
231
232     /**
233      * Lock anchor.
234      * To release locks(s), the session holding the lock(s) must be closed.
235      *
236      * @param sessionID session ID
237      * @param dataspaceName dataspace name
238      * @param anchorName anchor name
239      * @param timeoutInMilliseconds lock attempt timeout in milliseconds
240      */
241     void lockAnchor(String sessionID, String dataspaceName, String anchorName, Long timeoutInMilliseconds);
242 }