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.spi.FetchDescendantsOption;
33 import org.onap.cps.spi.model.DataNode;
34 import org.onap.cps.spi.model.ModuleReference;
35 import org.onap.cps.utils.DataMapUtils;
36 import org.springframework.http.HttpStatus;
37 import org.springframework.http.ResponseEntity;
38 import org.springframework.web.bind.annotation.RequestMapping;
39 import org.springframework.web.bind.annotation.RestController;
42 @RequestMapping("${rest.api.ncmp-base-path}")
43 public class NetworkCmProxyController implements NetworkCmProxyApi {
45 private static final Gson GSON = new GsonBuilder().create();
47 private final NetworkCmProxyDataService networkCmProxyDataService;
50 * Constructor Injection for Dependencies.
51 * @param networkCmProxyDataService Data Service Interface
53 public NetworkCmProxyController(final NetworkCmProxyDataService networkCmProxyDataService) {
54 this.networkCmProxyDataService = networkCmProxyDataService;
59 * @deprecated This Method is no longer used as part of NCMP.
62 @Deprecated(forRemoval = false)
63 public ResponseEntity<Void> createNode(final String cmHandle, @Valid final String jsonData,
64 @Valid final String parentNodeXpath) {
65 networkCmProxyDataService.createDataNode(cmHandle, parentNodeXpath, jsonData);
66 return new ResponseEntity<>(HttpStatus.CREATED);
70 * Add List-node Child Element.
71 * @deprecated This Method is no longer used as part of NCMP.
74 @Deprecated(forRemoval = false)
75 public ResponseEntity<Void> addListNodeElements(@NotNull @Valid final String parentNodeXpath,
76 final String cmHandle, @Valid final String jsonData) {
77 networkCmProxyDataService.addListNodeElements(cmHandle, parentNodeXpath, jsonData);
78 return new ResponseEntity<>(HttpStatus.CREATED);
82 * Get Node By CM Handle and X-Path.
83 * @deprecated This Method is no longer used as part of NCMP.
86 @Deprecated(forRemoval = false)
87 public ResponseEntity<Object> getNodeByCmHandleAndXpath(final String cmHandle, @Valid final String xpath,
88 @Valid final Boolean includeDescendants) {
89 final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
90 ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
91 final var dataNode = networkCmProxyDataService.getDataNode(cmHandle, xpath, fetchDescendantsOption);
92 return new ResponseEntity<>(DataMapUtils.toDataMap(dataNode), HttpStatus.OK);
97 * @deprecated This Method is no longer used as part of NCMP.
100 @Deprecated(forRemoval = false)
101 public ResponseEntity<Object> queryNodesByCmHandleAndCpsPath(final String cmHandle, @Valid final String cpsPath,
102 @Valid final Boolean includeDescendants) {
103 final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
104 ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
105 final Collection<DataNode> dataNodes =
106 networkCmProxyDataService.queryDataNodes(cmHandle, cpsPath, fetchDescendantsOption);
107 return new ResponseEntity<>(GSON.toJson(dataNodes), HttpStatus.OK);
111 * Replace Node With Descendants.
112 * @deprecated This Method is no longer used as part of NCMP.
115 @Deprecated(forRemoval = false)
116 public ResponseEntity<Object> replaceNode(final String cmHandle, @Valid final String jsonData,
117 @Valid final String parentNodeXpath) {
118 networkCmProxyDataService.replaceNodeTree(cmHandle, parentNodeXpath, jsonData);
119 return new ResponseEntity<>(HttpStatus.OK);
123 * Update Node Leaves.
124 * @deprecated This Method is no longer used as part of NCMP.
127 @Deprecated(forRemoval = false)
128 public ResponseEntity<Object> updateNodeLeaves(final String cmHandle, @Valid final String jsonData,
129 @Valid final String parentNodeXpath) {
130 networkCmProxyDataService.updateNodeLeaves(cmHandle, parentNodeXpath, jsonData);
131 return new ResponseEntity<>(HttpStatus.OK);
135 * Get resource data from operational datastore.
137 * @param cmHandle cm handle identifier
138 * @param resourceIdentifier resource identifier
139 * @param acceptParamInHeader accept header parameter
140 * @param optionsParamInQuery options query parameter
141 * @return {@code ResponseEntity} response from dmi plugin
144 public ResponseEntity<Object> getResourceDataOperationalForCmHandle(final String cmHandle,
145 final @NotNull @Valid String resourceIdentifier,
146 final String acceptParamInHeader,
147 final @Valid String optionsParamInQuery) {
148 final Object responseObject = networkCmProxyDataService.getResourceDataOperationalForCmHandle(cmHandle,
151 optionsParamInQuery);
152 return ResponseEntity.ok(responseObject);
156 * Get resource data from pass-through running datastore.
158 * @param cmHandle cm handle identifier
159 * @param resourceIdentifier resource identifier
160 * @param acceptParamInHeader accept header parameter
161 * @param optionsParamInQuery options query parameter
162 * @return {@code ResponseEntity} response from dmi plugin
165 public ResponseEntity<Object> getResourceDataRunningForCmHandle(final String cmHandle,
166 final @NotNull @Valid String resourceIdentifier,
167 final String acceptParamInHeader,
168 final @Valid String optionsParamInQuery) {
169 final Object responseObject = networkCmProxyDataService.getResourceDataPassThroughRunningForCmHandle(cmHandle,
172 optionsParamInQuery);
173 return ResponseEntity.ok(responseObject);
177 * Create resource data in datastore pass through running
178 * for given cm-handle.
180 * @param resourceIdentifier resource identifier
181 * @param cmHandle cm handle identifier
182 * @param requestBody requestBody
183 * @param contentType content type of body
184 * @return {@code ResponseEntity} response from dmi plugi
187 public ResponseEntity<Void> createResourceDataRunningForCmHandle(final String resourceIdentifier,
188 final String cmHandle,
189 final String requestBody,
190 final String contentType) {
191 networkCmProxyDataService.createResourceDataPassThroughRunningForCmHandle(cmHandle,
192 resourceIdentifier, requestBody, contentType);
193 return new ResponseEntity<>(HttpStatus.CREATED);
197 public ResponseEntity<Object> getModuleReferencesByCmHandle(final String cmHandle) {
198 final Collection<ModuleReference>
199 moduleReferences = networkCmProxyDataService.getYangResourcesModuleReferences(cmHandle);
200 return new ResponseEntity<>(new Gson().toJson(moduleReferences), HttpStatus.OK);