2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Pantheon.tech
4 * Modifications (C) 2021 Nordix Foundation
5 * Modification Copyright (C) 2021 highstreet technologies GmbH
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
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.cps.ncmp.rest.controller;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import com.google.gson.Gson;
27 import com.google.gson.GsonBuilder;
28 import java.util.Collection;
29 import javax.validation.Valid;
30 import javax.validation.constraints.Min;
31 import javax.validation.constraints.NotNull;
32 import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
33 import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
34 import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi;
35 import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration;
36 import org.onap.cps.spi.FetchDescendantsOption;
37 import org.onap.cps.spi.model.DataNode;
38 import org.onap.cps.spi.model.ModuleReference;
39 import org.onap.cps.utils.DataMapUtils;
40 import org.springframework.http.HttpStatus;
41 import org.springframework.http.ResponseEntity;
42 import org.springframework.web.bind.annotation.RequestMapping;
43 import org.springframework.web.bind.annotation.RestController;
46 @RequestMapping("${rest.api.ncmp-base-path}")
47 public class NetworkCmProxyController implements NetworkCmProxyApi {
49 private static final Gson GSON = new GsonBuilder().create();
51 private final NetworkCmProxyDataService networkCmProxyDataService;
53 private final ObjectMapper objectMapper;
56 * Constructor Injection for Dependencies.
57 * @param networkCmProxyDataService Data Service Interface
58 * @param objectMapper Object Mapper
60 public NetworkCmProxyController(final NetworkCmProxyDataService networkCmProxyDataService,
61 final ObjectMapper objectMapper) {
62 this.networkCmProxyDataService = networkCmProxyDataService;
63 this.objectMapper = objectMapper;
68 * @deprecated This Method is no longer used as part of NCMP.
71 @Deprecated(forRemoval = false)
72 public ResponseEntity<Void> createNode(final String cmHandle, @Valid final String jsonData,
73 @Valid final String parentNodeXpath) {
74 networkCmProxyDataService.createDataNode(cmHandle, parentNodeXpath, jsonData);
75 return new ResponseEntity<>(HttpStatus.CREATED);
79 * Add List-node Child Element.
80 * @deprecated This Method is no longer used as part of NCMP.
83 @Deprecated(forRemoval = false)
84 public ResponseEntity<Void> addListNodeElements(@NotNull @Valid final String parentNodeXpath,
85 final String cmHandle, @Valid final String jsonData) {
86 networkCmProxyDataService.addListNodeElements(cmHandle, parentNodeXpath, jsonData);
87 return new ResponseEntity<>(HttpStatus.CREATED);
91 * Get Node By CM Handle and X-Path.
92 * @deprecated This Method is no longer used as part of NCMP.
95 @Deprecated(forRemoval = false)
96 public ResponseEntity<Object> getNodeByCmHandleAndXpath(final String cmHandle, @Valid final String xpath,
97 @Valid final Boolean includeDescendants) {
98 final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
99 ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
100 final var dataNode = networkCmProxyDataService.getDataNode(cmHandle, xpath, fetchDescendantsOption);
101 return new ResponseEntity<>(DataMapUtils.toDataMap(dataNode), HttpStatus.OK);
105 * Update DMI Plugin Registration (used for first registration also).
106 * @param restDmiPluginRegistration the registration data
109 public ResponseEntity<Void> updateDmiPluginRegistration(
110 final @Valid RestDmiPluginRegistration restDmiPluginRegistration) {
111 final DmiPluginRegistration dmiPluginRegistration =
112 convertRestObjectToJavaApiObject(restDmiPluginRegistration);
113 networkCmProxyDataService.updateDmiRegistrationAndSyncModule(dmiPluginRegistration);
114 return new ResponseEntity<>(HttpStatus.CREATED);
119 * @deprecated This Method is no longer used as part of NCMP.
122 @Deprecated(forRemoval = false)
123 public ResponseEntity<Object> queryNodesByCmHandleAndCpsPath(final String cmHandle, @Valid final String cpsPath,
124 @Valid final Boolean includeDescendants) {
125 final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
126 ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
127 final Collection<DataNode> dataNodes =
128 networkCmProxyDataService.queryDataNodes(cmHandle, cpsPath, fetchDescendantsOption);
129 return new ResponseEntity<>(GSON.toJson(dataNodes), HttpStatus.OK);
133 * Replace Node With Descendants.
134 * @deprecated This Method is no longer used as part of NCMP.
137 @Deprecated(forRemoval = false)
138 public ResponseEntity<Object> replaceNode(final String cmHandle, @Valid final String jsonData,
139 @Valid final String parentNodeXpath) {
140 networkCmProxyDataService.replaceNodeTree(cmHandle, parentNodeXpath, jsonData);
141 return new ResponseEntity<>(HttpStatus.OK);
145 * Update Node Leaves.
146 * @deprecated This Method is no longer used as part of NCMP.
149 @Deprecated(forRemoval = false)
150 public ResponseEntity<Object> updateNodeLeaves(final String cmHandle, @Valid final String jsonData,
151 @Valid final String parentNodeXpath) {
152 networkCmProxyDataService.updateNodeLeaves(cmHandle, parentNodeXpath, jsonData);
153 return new ResponseEntity<>(HttpStatus.OK);
157 * Get resource data from operational datastore.
159 * @param cmHandle cm handle identifier
160 * @param resourceIdentifier resource identifier
161 * @param accept accept header parameter
162 * @param fields fields query parameter
163 * @param depth depth query parameter
164 * @return {@code ResponseEntity} response from dmi plugin
167 public ResponseEntity<Object> getResourceDataOperationalForCmHandle(final String cmHandle,
168 final String resourceIdentifier,
170 final @Valid String fields,
171 final @Min(1) @Valid Integer depth) {
172 final Object responseObject = networkCmProxyDataService.getResourceDataOperationalForCmHandle(cmHandle,
177 return ResponseEntity.ok(responseObject);
181 * Get resource data from pass-through running datastore.
183 * @param cmHandle cm handle identifier
184 * @param resourceIdentifier resource identifier
185 * @param accept accept header parameter
186 * @param fields fields query parameter
187 * @param depth depth query parameter
188 * @return {@code ResponseEntity} response from dmi plugin
191 public ResponseEntity<Object> getResourceDataRunningForCmHandle(final String cmHandle,
192 final String resourceIdentifier,
194 final @Valid String fields,
195 final @Min(1) @Valid Integer depth) {
196 final Object responseObject = networkCmProxyDataService.getResourceDataPassThroughRunningForCmHandle(cmHandle,
201 return ResponseEntity.ok(responseObject);
205 * Create resource data in datastore pass through running
206 * for given cm-handle.
208 * @param cmHandle cm handle identifier
209 * @param resourceIdentifier resource identifier
210 * @param requestBody requestBody
211 * @param contentType content type of body
212 * @return {@code ResponseEntity} response from dmi plugi
215 public ResponseEntity<Void> createResourceDataRunningForCmHandle(final String cmHandle,
216 final String resourceIdentifier,
217 final Object requestBody,
218 final String contentType) {
219 networkCmProxyDataService.createResourceDataPassThroughRunningForCmHandle(cmHandle,
220 resourceIdentifier, requestBody, contentType);
221 return new ResponseEntity<>(HttpStatus.CREATED);
225 public ResponseEntity<Object> getModuleReferencesByCmHandle(final String cmHandle) {
226 final Collection<ModuleReference>
227 moduleReferences = networkCmProxyDataService.getYangResourcesModuleReferences(cmHandle);
228 return new ResponseEntity<>(new Gson().toJson(moduleReferences), HttpStatus.OK);
231 private DmiPluginRegistration convertRestObjectToJavaApiObject(
232 final RestDmiPluginRegistration restDmiPluginRegistration) {
233 return objectMapper.convertValue(restDmiPluginRegistration, DmiPluginRegistration.class);