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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.cps.api;
24 import org.checkerframework.checker.nullness.qual.NonNull;
25 import org.onap.cps.spi.FetchDescendantsOption;
26 import org.onap.cps.spi.exceptions.AlreadyDefinedException;
27 import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
28 import org.onap.cps.spi.exceptions.DataValidationException;
29 import org.onap.cps.spi.model.DataNode;
32 * Datastore interface for handling CPS data.
34 public interface CpsDataService {
37 * Persists data for the given anchor and dataspace.
39 * @param dataspaceName dataspace name
40 * @param anchorName anchor name
41 * @param jsonData json data
42 * @throws DataValidationException when json data is invalid
44 void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String jsonData);
47 * Persists child data fragment under existing data node for the given anchor and dataspace.
49 * @param dataspaceName dataspace name
50 * @param anchorName anchor name
51 * @param parentNodeXpath parent node xpath
52 * @param jsonData json data
53 * @throws DataValidationException when json data is invalid
54 * @throws DataNodeNotFoundException when parent node cannot be found by parent node xpath
55 * @throws AlreadyDefinedException when child data node with same xpath already exists
57 void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
58 @NonNull String jsonData);
61 * Persists child data fragment representing list-node (with one or more elements) under existing data node
62 * for the given anchor and dataspace.
64 * @param dataspaceName dataspace name
65 * @param anchorName anchor name
66 * @param parentNodeXpath parent node xpath
67 * @param jsonData json data representing list element
68 * @throws DataValidationException when json data is invalid (incl. list-node being empty)
69 * @throws DataNodeNotFoundException when parent node cannot be found by parent node xpath
70 * @throws AlreadyDefinedException when any of child data nodes is having xpath of already existing node
72 void saveListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
73 @NonNull String jsonData);
76 * Retrieves datanode by XPath for given dataspace and anchor.
78 * @param dataspaceName dataspace name
79 * @param anchorName anchor name
81 * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
82 * (recursively) as well
83 * @return data node object
85 DataNode getDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String xpath,
86 @NonNull FetchDescendantsOption fetchDescendantsOption);
89 * Updates data node for given dataspace and anchor using xpath to parent node.
91 * @param dataspaceName dataspace name
92 * @param anchorName anchor name
93 * @param parentNodeXpath xpath to parent node
94 * @param jsonData json data
96 void updateNodeLeaves(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
97 @NonNull String jsonData);
100 * Replaces existing data node content including descendants.
102 * @param dataspaceName dataspace name
103 * @param anchorName anchor name
104 * @param parentNodeXpath xpath to parent node
105 * @param jsonData json data
107 void replaceNodeTree(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
108 @NonNull String jsonData);
111 * Replaces (if exists) child data fragment representing list-node (with one or more elements)
112 * under existing data node for the given anchor and dataspace.
114 * @param dataspaceName dataspace name
115 * @param anchorName anchor name
116 * @param parentNodeXpath parent node xpath
117 * @param jsonData json data representing list element
118 * @throws DataValidationException when json data is invalid (incl. list-node being empty)
119 * @throws DataNodeNotFoundException when parent node cannot be found by parent node xpath
121 void replaceListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
122 @NonNull String jsonData);