2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Pantheon.tech
4 * Modifications (C) 2021 Nordix Foundation
5 * Modification Copyright (C) 2021 highstreet technologies GmbH
6 * Modifications (C) 2021 Bell Canada
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.cps.ncmp.rest.controller;
25 import com.google.gson.Gson;
26 import com.google.gson.GsonBuilder;
27 import java.util.Collection;
28 import javax.validation.Valid;
29 import javax.validation.constraints.NotNull;
30 import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
31 import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi;
32 import org.onap.cps.ncmp.rest.model.CmHandles;
33 import org.onap.cps.ncmp.rest.model.Conditions;
34 import org.onap.cps.spi.FetchDescendantsOption;
35 import org.onap.cps.spi.model.DataNode;
36 import org.onap.cps.spi.model.ModuleReference;
37 import org.onap.cps.utils.DataMapUtils;
38 import org.springframework.http.HttpStatus;
39 import org.springframework.http.ResponseEntity;
40 import org.springframework.web.bind.annotation.RequestMapping;
41 import org.springframework.web.bind.annotation.RestController;
44 @RequestMapping("${rest.api.ncmp-base-path}")
45 public class NetworkCmProxyController implements NetworkCmProxyApi {
47 private static final Gson GSON = new GsonBuilder().create();
49 private final NetworkCmProxyDataService networkCmProxyDataService;
52 * Constructor Injection for Dependencies.
53 * @param networkCmProxyDataService Data Service Interface
55 public NetworkCmProxyController(final NetworkCmProxyDataService networkCmProxyDataService) {
56 this.networkCmProxyDataService = networkCmProxyDataService;
61 * @deprecated This Method is no longer used as part of NCMP.
64 @Deprecated(forRemoval = false)
65 public ResponseEntity<Void> createNode(final String cmHandle, @Valid final String jsonData,
66 @Valid final String parentNodeXpath) {
67 networkCmProxyDataService.createDataNode(cmHandle, parentNodeXpath, jsonData);
68 return new ResponseEntity<>(HttpStatus.CREATED);
72 * Add List-node Child Element.
73 * @deprecated This Method is no longer used as part of NCMP.
76 @Deprecated(forRemoval = false)
77 public ResponseEntity<Void> addListNodeElements(@NotNull @Valid final String parentNodeXpath,
78 final String cmHandle, @Valid final String jsonData) {
79 networkCmProxyDataService.addListNodeElements(cmHandle, parentNodeXpath, jsonData);
80 return new ResponseEntity<>(HttpStatus.CREATED);
84 * Get Node By CM Handle and X-Path.
85 * @deprecated This Method is no longer used as part of NCMP.
88 @Deprecated(forRemoval = false)
89 public ResponseEntity<Object> getNodeByCmHandleAndXpath(final String cmHandle, @Valid final String xpath,
90 @Valid final Boolean includeDescendants) {
91 final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
92 ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
93 final var dataNode = networkCmProxyDataService.getDataNode(cmHandle, xpath, fetchDescendantsOption);
94 return new ResponseEntity<>(DataMapUtils.toDataMap(dataNode), HttpStatus.OK);
99 * @deprecated This Method is no longer used as part of NCMP.
102 @Deprecated(forRemoval = false)
103 public ResponseEntity<Object> queryNodesByCmHandleAndCpsPath(final String cmHandle, @Valid final String cpsPath,
104 @Valid final Boolean includeDescendants) {
105 final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
106 ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
107 final Collection<DataNode> dataNodes =
108 networkCmProxyDataService.queryDataNodes(cmHandle, cpsPath, fetchDescendantsOption);
109 return new ResponseEntity<>(GSON.toJson(dataNodes), HttpStatus.OK);
113 * Replace Node With Descendants.
114 * @deprecated This Method is no longer used as part of NCMP.
117 @Deprecated(forRemoval = false)
118 public ResponseEntity<Object> replaceNode(final String cmHandle, @Valid final String jsonData,
119 @Valid final String parentNodeXpath) {
120 networkCmProxyDataService.replaceNodeTree(cmHandle, parentNodeXpath, jsonData);
121 return new ResponseEntity<>(HttpStatus.OK);
125 * Update Node Leaves.
126 * @deprecated This Method is no longer used as part of NCMP.
129 @Deprecated(forRemoval = false)
130 public ResponseEntity<Object> updateNodeLeaves(final String cmHandle, @Valid final String jsonData,
131 @Valid final String parentNodeXpath) {
132 networkCmProxyDataService.updateNodeLeaves(cmHandle, parentNodeXpath, jsonData);
133 return new ResponseEntity<>(HttpStatus.OK);
137 * Get resource data from operational datastore.
139 * @param cmHandle cm handle identifier
140 * @param resourceIdentifier resource identifier
141 * @param acceptParamInHeader accept header parameter
142 * @param optionsParamInQuery options query parameter
143 * @return {@code ResponseEntity} response from dmi plugin
146 public ResponseEntity<Object> getResourceDataOperationalForCmHandle(final String cmHandle,
147 final @NotNull @Valid String resourceIdentifier,
148 final String acceptParamInHeader,
149 final @Valid String optionsParamInQuery) {
150 final Object responseObject = networkCmProxyDataService.getResourceDataOperationalForCmHandle(cmHandle,
153 optionsParamInQuery);
154 return ResponseEntity.ok(responseObject);
158 * Get resource data from pass-through running datastore.
160 * @param cmHandle cm handle identifier
161 * @param resourceIdentifier resource identifier
162 * @param acceptParamInHeader accept header parameter
163 * @param optionsParamInQuery options query parameter
164 * @return {@code ResponseEntity} response from dmi plugin
167 public ResponseEntity<Object> getResourceDataRunningForCmHandle(final String cmHandle,
168 final @NotNull @Valid String resourceIdentifier,
169 final String acceptParamInHeader,
170 final @Valid String optionsParamInQuery) {
171 final Object responseObject = networkCmProxyDataService.getResourceDataPassThroughRunningForCmHandle(cmHandle,
174 optionsParamInQuery);
175 return ResponseEntity.ok(responseObject);
179 * Create resource data in datastore pass through running
180 * for given cm-handle.
182 * @param resourceIdentifier resource identifier
183 * @param cmHandle cm handle identifier
184 * @param requestBody requestBody
185 * @param contentType content type of body
186 * @return {@code ResponseEntity} response from dmi plugi
189 public ResponseEntity<Void> createResourceDataRunningForCmHandle(final String resourceIdentifier,
190 final String cmHandle,
191 final String requestBody,
192 final String contentType) {
193 networkCmProxyDataService.createResourceDataPassThroughRunningForCmHandle(cmHandle,
194 resourceIdentifier, requestBody, contentType);
195 return new ResponseEntity<>(HttpStatus.CREATED);
199 public ResponseEntity<CmHandles> executeCmHandleSearch(final Conditions conditions) {
200 return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
204 public ResponseEntity<Object> getModuleReferencesByCmHandle(final String cmHandle) {
205 final Collection<ModuleReference>
206 moduleReferences = networkCmProxyDataService.getYangResourcesModuleReferences(cmHandle);
207 return new ResponseEntity<>(new Gson().toJson(moduleReferences), HttpStatus.OK);