f455e47efda8d1b3c376d087b43dcb4a16d908ed
[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 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.checkerframework.checker.nullness.qual.NonNull;
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(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String jsonData,
44         OffsetDateTime observedTimestamp);
45
46     /**
47      * Persists child data fragment under existing data node for the given anchor and dataspace.
48      *
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
54      */
55     void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
56         @NonNull String jsonData, OffsetDateTime observedTimestamp);
57
58     /**
59      * Persists child data fragment representing one or more list elements under existing data node for the
60      * given anchor and dataspace.
61      *
62      * @param dataspaceName     dataspace name
63      * @param anchorName        anchor name
64      * @param parentNodeXpath   parent node xpath
65      * @param jsonData          json data representing list element(s)
66      * @param observedTimestamp observedTimestamp
67      */
68     void saveListElements(@NonNull String dataspaceName, @NonNull String anchorName,
69                               @NonNull String parentNodeXpath,
70                               @NonNull String jsonData, OffsetDateTime observedTimestamp);
71
72     /**
73      * Retrieves datanode by XPath for given dataspace and anchor.
74      *
75      * @param dataspaceName          dataspace name
76      * @param anchorName             anchor name
77      * @param xpath                  xpath
78      * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
79      *                               (recursively) as well
80      * @return data node object
81      */
82     DataNode getDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String xpath,
83         @NonNull FetchDescendantsOption fetchDescendantsOption);
84
85     /**
86      * Updates data node for given dataspace and anchor using xpath to parent node.
87      *
88      * @param dataspaceName   dataspace name
89      * @param anchorName      anchor name
90      * @param parentNodeXpath xpath to parent node
91      * @param jsonData        json data
92      * @param observedTimestamp observedTimestamp
93      */
94     void updateNodeLeaves(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
95         @NonNull String jsonData, OffsetDateTime observedTimestamp);
96
97     /**
98      * Replaces existing data node content including descendants.
99      *
100      * @param dataspaceName   dataspace name
101      * @param anchorName      anchor name
102      * @param parentNodeXpath xpath to parent node
103      * @param jsonData        json data
104      * @param observedTimestamp observedTimestamp
105      */
106     void replaceNodeTree(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
107         @NonNull String jsonData, OffsetDateTime observedTimestamp);
108
109     /**
110      * Replaces list content by removing all existing elements and inserting the given new elements as json
111      * under given parent, anchor and dataspace.
112      *
113      * @param dataspaceName     dataspace name
114      * @param anchorName        anchor name
115      * @param parentNodeXpath   parent node xpath
116      * @param jsonData          json data representing the new list elements
117      * @param observedTimestamp observedTimestamp
118      */
119     void replaceListContent(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
120                             @NonNull String jsonData, OffsetDateTime observedTimestamp);
121
122     /**
123      * Deletes data node for given anchor and dataspace.
124      *
125      * @param dataspaceName dataspace name
126      * @param anchorName anchor name
127      * @param dataNodeXpath data node xpath
128      * @param observedTimestamp observed timestamp
129      */
130     void deleteDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String dataNodeXpath,
131                         OffsetDateTime observedTimestamp);
132
133     /**
134      * Deletes a list or a list-element under given anchor and dataspace.
135      *
136      * @param dataspaceName dataspace name
137      * @param anchorName    anchor name
138      * @param listElementXpath list element xpath
139      * @param observedTimestamp observedTimestamp
140      */
141     void deleteListOrListElement(@NonNull String dataspaceName, @NonNull String anchorName,
142                              @NonNull String listElementXpath, OffsetDateTime observedTimestamp);
143
144     /**
145      * Updates leaves of DataNode for given dataspace and anchor using xpath, along with the leaves of each Child Data
146      * Node which already exists. This method will throw an exception if data node update or any descendant update does
147      * not exist.
148      *
149      * @param dataspaceName         dataspace name
150      * @param anchorName            anchor name
151      * @param parentNodeXpath       xpath
152      * @param dataNodeUpdatesAsJson json data representing data node updates
153      * @param observedTimestamp observedTimestamp
154      */
155     void updateNodeLeavesAndExistingDescendantLeaves(String dataspaceName, String anchorName, String parentNodeXpath,
156         String dataNodeUpdatesAsJson, OffsetDateTime observedTimestamp);
157 }