56f4cf8dcefd8c84ec1618e5a7a0af85d951328d
[cps.git] / cps-ncmp-service / src / main / java / org / onap / cps / ncmp / api / impl / NetworkCmProxyDataServiceImpl.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 highstreet technologies GmbH
4  *  Copyright (C) 2021 Nordix Foundation
5  *  Modifications Copyright (C) 2021 Pantheon.tech
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  *  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.ncmp.api.impl;
23
24 import java.util.Collection;
25 import org.onap.cps.api.CpsDataService;
26 import org.onap.cps.api.CpsQueryService;
27 import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
28 import org.onap.cps.spi.FetchDescendantsOption;
29 import org.onap.cps.spi.model.DataNode;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Service;
32 import org.springframework.util.StringUtils;
33
34 @Service
35 public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService {
36
37     private static final String NF_PROXY_DATASPACE_NAME = "NFP-Operational";
38
39     @Autowired
40     private CpsDataService cpsDataService;
41
42     @Autowired
43     private CpsQueryService cpsQueryService;
44
45     private String getDataspaceName() {
46         return NF_PROXY_DATASPACE_NAME;
47     }
48
49     @Override
50     public DataNode getDataNode(final String cmHandle, final String xpath,
51         final FetchDescendantsOption fetchDescendantsOption) {
52         return cpsDataService.getDataNode(getDataspaceName(), cmHandle, xpath, fetchDescendantsOption);
53     }
54
55     @Override
56     public Collection<DataNode> queryDataNodes(final String cmHandle, final String cpsPath,
57         final FetchDescendantsOption fetchDescendantsOption) {
58         return cpsQueryService.queryDataNodes(getDataspaceName(), cmHandle, cpsPath, fetchDescendantsOption);
59     }
60
61     @Override
62     public void createDataNode(final String cmHandle, final String parentNodeXpath, final String jsonData) {
63         if (StringUtils.isEmpty(parentNodeXpath) || "/".equals(parentNodeXpath)) {
64             cpsDataService.saveData(getDataspaceName(), cmHandle, jsonData);
65         } else {
66             cpsDataService.saveData(getDataspaceName(), cmHandle, parentNodeXpath, jsonData);
67         }
68     }
69
70     @Override
71     public void updateNodeLeaves(final String cmHandle, final String parentNodeXpath, final String jsonData) {
72         cpsDataService.updateNodeLeaves(getDataspaceName(), cmHandle, parentNodeXpath, jsonData);
73     }
74
75     @Override
76     public void replaceNodeTree(final String cmHandle, final String parentNodeXpath, final String jsonData) {
77         cpsDataService.replaceNodeTree(getDataspaceName(), cmHandle, parentNodeXpath, jsonData);
78     }
79 }