d2482d50a64651fdaea265a682738c6f76fe01ae
[cps.git] / cps-service / src / main / java / org / onap / cps / api / CpsDataService.java
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 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 org.onap.cps.spi.FetchDescendantsOption;
27 import org.onap.cps.spi.model.DataNode;
28
29 /*
30  * Datastore interface for handling CPS data.
31  */
32 public interface CpsDataService {
33
34     /**
35      * Persists data for the given anchor and dataspace.
36      *
37      * @param dataspaceName dataspace name
38      * @param anchorName    anchor name
39      * @param jsonData      json data
40      * @param observedTimestamp observedTimestamp
41      */
42     void saveData(String dataspaceName, String anchorName, String jsonData, OffsetDateTime observedTimestamp);
43
44     /**
45      * Persists child data fragment under existing data node for the given anchor and dataspace.
46      *
47      * @param dataspaceName   dataspace name
48      * @param anchorName      anchor name
49      * @param parentNodeXpath parent node xpath
50      * @param jsonData        json data
51      * @param observedTimestamp observedTimestamp
52      */
53     void saveData(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
54         OffsetDateTime observedTimestamp);
55
56     /**
57      * Persists child data fragment representing one or more list elements under existing data node for the
58      * given anchor and dataspace.
59      *
60      * @param dataspaceName     dataspace name
61      * @param anchorName        anchor name
62      * @param parentNodeXpath   parent node xpath
63      * @param jsonData          json data representing list element(s)
64      * @param observedTimestamp observedTimestamp
65      */
66     void saveListElements(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
67         OffsetDateTime observedTimestamp);
68
69     /**
70      * Retrieves datanode by XPath for given dataspace and anchor.
71      *
72      * @param dataspaceName          dataspace name
73      * @param anchorName             anchor name
74      * @param xpath                  xpath
75      * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
76      *                               (recursively) as well
77      * @return data node object
78      */
79     DataNode getDataNode(String dataspaceName, String anchorName, String xpath,
80         FetchDescendantsOption fetchDescendantsOption);
81
82     /**
83      * Updates data node for given dataspace and anchor using xpath to parent node.
84      *
85      * @param dataspaceName   dataspace name
86      * @param anchorName      anchor name
87      * @param parentNodeXpath xpath to parent node
88      * @param jsonData        json data
89      * @param observedTimestamp observedTimestamp
90      */
91     void updateNodeLeaves(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
92         OffsetDateTime observedTimestamp);
93
94     /**
95      * Replaces existing data node content including descendants.
96      *
97      * @param dataspaceName   dataspace name
98      * @param anchorName      anchor name
99      * @param parentNodeXpath xpath to parent node
100      * @param jsonData        json data
101      * @param observedTimestamp observedTimestamp
102      */
103     void replaceNodeTree(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
104         OffsetDateTime observedTimestamp);
105
106     /**
107      * Replaces list content by removing all existing elements and inserting the given new elements as json
108      * under given parent, anchor and dataspace.
109      *
110      * @param dataspaceName     dataspace name
111      * @param anchorName        anchor name
112      * @param parentNodeXpath   parent node xpath
113      * @param jsonData          json data representing the new list elements
114      * @param observedTimestamp observedTimestamp
115      */
116     void replaceListContent(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
117         OffsetDateTime observedTimestamp);
118
119     /**
120      * Deletes data node for given anchor and dataspace.
121      *
122      * @param dataspaceName dataspace name
123      * @param anchorName anchor name
124      * @param dataNodeXpath data node xpath
125      * @param observedTimestamp observed timestamp
126      */
127     void deleteDataNode(String dataspaceName, String anchorName, String dataNodeXpath,
128         OffsetDateTime observedTimestamp);
129
130     /**
131      * Deletes all data nodes for a given anchor in a dataspace.
132      *
133      * @param dataspaceName     dataspace name
134      * @param anchorName       anchor name
135      * @param observedTimestamp observed timestamp
136      */
137     void deleteDataNodes(String dataspaceName, String anchorName, OffsetDateTime observedTimestamp);
138
139     /**
140      * Deletes a list or a list-element under given anchor and dataspace.
141      *
142      * @param dataspaceName dataspace name
143      * @param anchorName    anchor name
144      * @param listElementXpath list element xpath
145      * @param observedTimestamp observedTimestamp
146      */
147     void deleteListOrListElement(String dataspaceName, String anchorName, String listElementXpath,
148         OffsetDateTime observedTimestamp);
149
150     /**
151      * Updates leaves of DataNode for given dataspace and anchor using xpath, along with the leaves of each Child Data
152      * Node which already exists. This method will throw an exception if data node update or any descendant update does
153      * not exist.
154      *
155      * @param dataspaceName         dataspace name
156      * @param anchorName            anchor name
157      * @param parentNodeXpath       xpath
158      * @param dataNodeUpdatesAsJson json data representing data node updates
159      * @param observedTimestamp observedTimestamp
160      */
161     void updateNodeLeavesAndExistingDescendantLeaves(String dataspaceName, String anchorName, String parentNodeXpath,
162         String dataNodeUpdatesAsJson, OffsetDateTime observedTimestamp);
163 }