Merge "Update CmHandle in DMI-Registry for a DMI-Plugin Instance in NCMP as part...
[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  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.onap.cps.api;
23
24 import org.checkerframework.checker.nullness.qual.NonNull;
25 import org.onap.cps.spi.FetchDescendantsOption;
26 import org.onap.cps.spi.model.DataNode;
27
28 /*
29  * Datastore interface for handling CPS data.
30  */
31 public interface CpsDataService {
32
33     /**
34      * Persists data for the given anchor and dataspace.
35      *
36      * @param dataspaceName dataspace name
37      * @param anchorName    anchor name
38      * @param jsonData      json data
39      */
40     void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String jsonData);
41
42     /**
43      * Persists child data fragment under existing data node for the given anchor and dataspace.
44      *
45      * @param dataspaceName   dataspace name
46      * @param anchorName      anchor name
47      * @param parentNodeXpath parent node xpath
48      * @param jsonData        json data
49      */
50     void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
51         @NonNull String jsonData);
52
53     /**
54      * Persists child data fragment representing list-node (with one or more elements) under existing data node
55      * for the given anchor and dataspace.
56      *
57      * @param dataspaceName   dataspace name
58      * @param anchorName      anchor name
59      * @param parentNodeXpath parent node xpath
60      * @param jsonData        json data representing list element
61      */
62     void saveListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
63         @NonNull String jsonData);
64
65     /**
66      * Retrieves datanode by XPath for given dataspace and anchor.
67      *
68      * @param dataspaceName          dataspace name
69      * @param anchorName             anchor name
70      * @param xpath                  xpath
71      * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
72      *                               (recursively) as well
73      * @return data node object
74      */
75     DataNode getDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String xpath,
76         @NonNull FetchDescendantsOption fetchDescendantsOption);
77
78     /**
79      * Updates data node for given dataspace and anchor using xpath to parent node.
80      *
81      * @param dataspaceName   dataspace name
82      * @param anchorName      anchor name
83      * @param parentNodeXpath xpath to parent node
84      * @param jsonData        json data
85      */
86     void updateNodeLeaves(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
87         @NonNull String jsonData);
88
89     /**
90      * Replaces existing data node content including descendants.
91      *
92      * @param dataspaceName   dataspace name
93      * @param anchorName      anchor name
94      * @param parentNodeXpath xpath to parent node
95      * @param jsonData        json data
96      */
97     void replaceNodeTree(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
98         @NonNull String jsonData);
99
100     /**
101      * Replaces (if exists) child data fragment representing list-node (with one or more elements)
102      * under existing data node for the given anchor and dataspace.
103      *
104      * @param dataspaceName   dataspace name
105      * @param anchorName      anchor name
106      * @param parentNodeXpath parent node xpath
107      * @param jsonData        json data representing list element
108      */
109     void replaceListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
110         @NonNull String jsonData);
111
112     /**
113      * Deletes (if exists) child data fragment representing list-node (with one or more elements)
114      * under existing data node for the given anchor and dataspace.
115      *
116      * @param dataspaceName   dataspace name
117      * @param anchorName      anchor name
118      * @param listNodeXpath   list node xpath
119      */
120     void deleteListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String listNodeXpath);
121
122     /**
123      * Updates leaves of DataNode for given dataspace and anchor using xpath,
124      * along with the leaves of each Child Data Node which already exists.
125      * This method will throw an exception if data node update or any descendant update does not exist.
126      *
127      * @param dataspaceName dataspace name
128      * @param anchorName anchor name
129      * @param parentNodeXpath xpath
130      * @param dataNodeUpdatesAsJson json data representing data node updates
131      */
132     void updateNodeLeavesAndExistingDescendantLeaves(String dataspaceName, String anchorName, String parentNodeXpath,
133                                                      String dataNodeUpdatesAsJson);
134 }