Add optional observed timestamp in the cps data api
[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 list-node (with one or more 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
66      * @param observedTimestamp observedTimestamp
67      */
68     void saveListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
69         @NonNull String jsonData, OffsetDateTime observedTimestamp);
70
71     /**
72      * Retrieves datanode by XPath for given dataspace and anchor.
73      *
74      * @param dataspaceName          dataspace name
75      * @param anchorName             anchor name
76      * @param xpath                  xpath
77      * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
78      *                               (recursively) as well
79      * @return data node object
80      */
81     DataNode getDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String xpath,
82         @NonNull FetchDescendantsOption fetchDescendantsOption);
83
84     /**
85      * Updates data node for given dataspace and anchor using xpath to parent node.
86      *
87      * @param dataspaceName   dataspace name
88      * @param anchorName      anchor name
89      * @param parentNodeXpath xpath to parent node
90      * @param jsonData        json data
91      * @param observedTimestamp observedTimestamp
92      */
93     void updateNodeLeaves(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
94         @NonNull String jsonData, OffsetDateTime observedTimestamp);
95
96     /**
97      * Replaces existing data node content including descendants.
98      *
99      * @param dataspaceName   dataspace name
100      * @param anchorName      anchor name
101      * @param parentNodeXpath xpath to parent node
102      * @param jsonData        json data
103      * @param observedTimestamp observedTimestamp
104      */
105     void replaceNodeTree(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
106         @NonNull String jsonData, OffsetDateTime observedTimestamp);
107
108     /**
109      * Replaces (if exists) child data fragment representing list-node (with one or more elements) under existing data
110      * node for the given anchor and dataspace.
111      *
112      * @param dataspaceName     dataspace name
113      * @param anchorName        anchor name
114      * @param parentNodeXpath   parent node xpath
115      * @param jsonData          json data representing list element
116      * @param observedTimestamp observedTimestamp
117      */
118     void replaceListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
119         @NonNull String jsonData, OffsetDateTime observedTimestamp);
120
121     /**
122      * Deletes (if exists) child data fragment representing list-node (with one or more elements) under existing data
123      * node for the given anchor and dataspace.
124      *
125      * @param dataspaceName dataspace name
126      * @param anchorName    anchor name
127      * @param listNodeXpath list node xpath
128      * @param observedTimestamp observedTimestamp
129      */
130     void deleteListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String listNodeXpath,
131         OffsetDateTime observedTimestamp);
132
133     /**
134      * Updates leaves of DataNode for given dataspace and anchor using xpath, along with the leaves of each Child Data
135      * Node which already exists. This method will throw an exception if data node update or any descendant update does
136      * not exist.
137      *
138      * @param dataspaceName         dataspace name
139      * @param anchorName            anchor name
140      * @param parentNodeXpath       xpath
141      * @param dataNodeUpdatesAsJson json data representing data node updates
142      * @param observedTimestamp observedTimestamp
143      */
144     void updateNodeLeavesAndExistingDescendantLeaves(String dataspaceName, String anchorName, String parentNodeXpath,
145         String dataNodeUpdatesAsJson, OffsetDateTime observedTimestamp);
146 }