Add Start and Stop sessions on JAVA API
[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  *  ================================================================================
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
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  *  SPDX-License-Identifier: Apache-2.0
20  *  ============LICENSE_END=========================================================
21  */
22
23 package org.onap.cps.api;
24
25 import java.time.OffsetDateTime;
26 import java.util.Collection;
27 import org.onap.cps.spi.FetchDescendantsOption;
28 import org.onap.cps.spi.model.DataNode;
29
30 /*
31  * Datastore interface for handling CPS data.
32  */
33 public interface CpsDataService {
34
35     /**
36      * Persists data for the given anchor and dataspace.
37      *
38      * @param dataspaceName dataspace name
39      * @param anchorName    anchor name
40      * @param jsonData      json data
41      * @param observedTimestamp observedTimestamp
42      */
43     void saveData(String dataspaceName, String anchorName, String jsonData, OffsetDateTime observedTimestamp);
44
45     /**
46      * Persists child data fragment under existing data node for the given anchor and dataspace.
47      *
48      * @param dataspaceName   dataspace name
49      * @param anchorName      anchor name
50      * @param parentNodeXpath parent node xpath
51      * @param jsonData        json data
52      * @param observedTimestamp observedTimestamp
53      */
54     void saveData(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
55         OffsetDateTime observedTimestamp);
56
57     /**
58      * Persists child data fragment representing one or more list elements under existing data node for the
59      * given anchor and dataspace.
60      *
61      * @param dataspaceName     dataspace name
62      * @param anchorName        anchor name
63      * @param parentNodeXpath   parent node xpath
64      * @param jsonData          json data representing list element(s)
65      * @param observedTimestamp observedTimestamp
66      */
67     void saveListElements(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
68         OffsetDateTime observedTimestamp);
69
70     /**
71      * Retrieves datanode by XPath for given dataspace and anchor.
72      *
73      * @param dataspaceName          dataspace name
74      * @param anchorName             anchor name
75      * @param xpath                  xpath
76      * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
77      *                               (recursively) as well
78      * @return data node object
79      */
80     DataNode getDataNode(String dataspaceName, String anchorName, String xpath,
81         FetchDescendantsOption fetchDescendantsOption);
82
83     /**
84      * Updates data node for given dataspace and anchor using xpath to parent node.
85      *
86      * @param dataspaceName   dataspace name
87      * @param anchorName      anchor name
88      * @param parentNodeXpath xpath to parent node
89      * @param jsonData        json data
90      * @param observedTimestamp observedTimestamp
91      */
92     void updateNodeLeaves(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
93         OffsetDateTime observedTimestamp);
94
95     /**
96      * Replaces existing data node content including descendants.
97      *
98      * @param dataspaceName   dataspace name
99      * @param anchorName      anchor name
100      * @param parentNodeXpath xpath to parent node
101      * @param jsonData        json data
102      * @param observedTimestamp observedTimestamp
103      */
104     void replaceNodeTree(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
105         OffsetDateTime observedTimestamp);
106
107     /**
108      * Replaces list content by removing all existing elements and inserting the given new elements as json
109      * under given parent, anchor and dataspace.
110      *
111      * @param dataspaceName     dataspace name
112      * @param anchorName        anchor name
113      * @param parentNodeXpath   parent node xpath
114      * @param jsonData          json data representing the new list elements
115      * @param observedTimestamp observedTimestamp
116      */
117     void replaceListContent(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
118         OffsetDateTime observedTimestamp);
119
120     /**
121      * Replaces list content by removing all existing elements and inserting the given new elements as data nodes
122      * under given parent, anchor and dataspace.
123      *
124      * @param dataspaceName     dataspace-name
125      * @param anchorName        anchor name
126      * @param parentNodeXpath   parent node xpath
127      * @param dataNodes         datanodes representing the updated data
128      * @param observedTimestamp observedTimestamp
129      */
130     void replaceListContent(String dataspaceName, String anchorName, String parentNodeXpath,
131             Collection<DataNode> dataNodes, OffsetDateTime observedTimestamp);
132
133     /**
134      * Deletes data node for given anchor and dataspace.
135      *
136      * @param dataspaceName dataspace name
137      * @param anchorName anchor name
138      * @param dataNodeXpath data node xpath
139      * @param observedTimestamp observed timestamp
140      */
141     void deleteDataNode(String dataspaceName, String anchorName, String dataNodeXpath,
142         OffsetDateTime observedTimestamp);
143
144     /**
145      * Deletes all data nodes for a given anchor in a dataspace.
146      *
147      * @param dataspaceName     dataspace name
148      * @param anchorName       anchor name
149      * @param observedTimestamp observed timestamp
150      */
151     void deleteDataNodes(String dataspaceName, String anchorName, OffsetDateTime observedTimestamp);
152
153     /**
154      * Deletes a list or a list-element under given anchor and dataspace.
155      *
156      * @param dataspaceName dataspace name
157      * @param anchorName    anchor name
158      * @param listElementXpath list element xpath
159      * @param observedTimestamp observedTimestamp
160      */
161     void deleteListOrListElement(String dataspaceName, String anchorName, String listElementXpath,
162         OffsetDateTime observedTimestamp);
163
164     /**
165      * Updates leaves of DataNode for given dataspace and anchor using xpath, along with the leaves of each Child Data
166      * Node which already exists. This method will throw an exception if data node update or any descendant update does
167      * not exist.
168      *
169      * @param dataspaceName         dataspace name
170      * @param anchorName            anchor name
171      * @param parentNodeXpath       xpath
172      * @param dataNodeUpdatesAsJson json data representing data node updates
173      * @param observedTimestamp observedTimestamp
174      */
175     void updateNodeLeavesAndExistingDescendantLeaves(String dataspaceName, String anchorName, String parentNodeXpath,
176         String dataNodeUpdatesAsJson, OffsetDateTime observedTimestamp);
177
178     /**
179      * Starts a session which allows use of locks and batch interaction with the persistence service.
180      *
181      * @return Session ID string
182      */
183     String startSession();
184
185     /**
186      * Close session.
187      *
188      * @param sessionId session ID
189      *
190      */
191     void closeSession(String sessionId);
192 }