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.utils.DataMapUtils;
39 import org.springframework.http.HttpStatus;
40 import org.springframework.http.ResponseEntity;
41 import org.springframework.web.bind.annotation.RequestMapping;
42 import org.springframework.web.bind.annotation.RestController;
45 @RequestMapping("${rest.api.ncmp-base-path}")
46 public class NetworkCmProxyController implements NetworkCmProxyApi {
48 private static final Gson GSON = new GsonBuilder().create();
50 private final NetworkCmProxyDataService networkCmProxyDataService;
52 private final ObjectMapper objectMapper;
55 * Constructor Injection for Dependencies.
56 * @param networkCmProxyDataService Data Service Interface
57 * @param objectMapper Object Mapper
59 public NetworkCmProxyController(final NetworkCmProxyDataService networkCmProxyDataService,
60 final ObjectMapper objectMapper) {
61 this.networkCmProxyDataService = networkCmProxyDataService;
62 this.objectMapper = objectMapper;
67 * @deprecated This Method is no longer used as part of NCMP.
70 @Deprecated(forRemoval = false)
71 public ResponseEntity<Void> createNode(final String cmHandle, @Valid final String jsonData,
72 @Valid final String parentNodeXpath) {
73 networkCmProxyDataService.createDataNode(cmHandle, parentNodeXpath, jsonData);
74 return new ResponseEntity<>(HttpStatus.CREATED);
78 * Add List-node Child Element.
79 * @deprecated This Method is no longer used as part of NCMP.
82 @Deprecated(forRemoval = false)
83 public ResponseEntity<Void> addListNodeElements(@NotNull @Valid final String parentNodeXpath,
84 final String cmHandle, @Valid final String jsonData) {
85 networkCmProxyDataService.addListNodeElements(cmHandle, parentNodeXpath, jsonData);
86 return new ResponseEntity<>(HttpStatus.CREATED);
90 * Get Node By CM Handle and X-Path.
91 * @deprecated This Method is no longer used as part of NCMP.
94 @Deprecated(forRemoval = false)
95 public ResponseEntity<Object> getNodeByCmHandleAndXpath(final String cmHandle, @Valid final String xpath,
96 @Valid final Boolean includeDescendants) {
97 final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
98 ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
99 final var dataNode = networkCmProxyDataService.getDataNode(cmHandle, xpath, fetchDescendantsOption);
100 return new ResponseEntity<>(DataMapUtils.toDataMap(dataNode), HttpStatus.OK);
104 * Update DMI Plugin Registration (used for first registration also).
105 * @param restDmiPluginRegistration the registration data
108 public ResponseEntity<Void> updateDmiPluginRegistration(
109 final @Valid RestDmiPluginRegistration restDmiPluginRegistration) {
110 final DmiPluginRegistration dmiPluginRegistration =
111 convertRestObjectToJavaApiObject(restDmiPluginRegistration);
112 networkCmProxyDataService.updateDmiPluginRegistration(dmiPluginRegistration);
113 return new ResponseEntity<>(HttpStatus.CREATED);
118 * @deprecated This Method is no longer used as part of NCMP.
121 @Deprecated(forRemoval = false)
122 public ResponseEntity<Object> queryNodesByCmHandleAndCpsPath(final String cmHandle, @Valid final String cpsPath,
123 @Valid final Boolean includeDescendants) {
124 final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
125 ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
126 final Collection<DataNode> dataNodes =
127 networkCmProxyDataService.queryDataNodes(cmHandle, cpsPath, fetchDescendantsOption);
128 return new ResponseEntity<>(GSON.toJson(dataNodes), HttpStatus.OK);
132 * Replace Node With Descendants.
133 * @deprecated This Method is no longer used as part of NCMP.
136 @Deprecated(forRemoval = false)
137 public ResponseEntity<Object> replaceNode(final String cmHandle, @Valid final String jsonData,
138 @Valid final String parentNodeXpath) {
139 networkCmProxyDataService.replaceNodeTree(cmHandle, parentNodeXpath, jsonData);
140 return new ResponseEntity<>(HttpStatus.OK);
144 * Update Node Leaves.
145 * @deprecated This Method is no longer used as part of NCMP.
148 @Deprecated(forRemoval = false)
149 public ResponseEntity<Object> updateNodeLeaves(final String cmHandle, @Valid final String jsonData,
150 @Valid final String parentNodeXpath) {
151 networkCmProxyDataService.updateNodeLeaves(cmHandle, parentNodeXpath, jsonData);
152 return new ResponseEntity<>(HttpStatus.OK);
156 * Get resource data for for operational datastore.
158 * @param cmHandle cm handle identifier
159 * @param resourceIdentifier resource identifier
160 * @param accept accept header parameter
161 * @param fields fields query parameter
162 * @param depth depth query parameter
163 * @return {@code ResponseEntity} response from dmi plugin
166 public ResponseEntity<Object> getResourceDataOperationalForCmHandle(final String cmHandle,
167 final String resourceIdentifier,
169 final @Valid String fields,
170 final @Min(1) @Valid Integer depth) {
171 final var responseObject = networkCmProxyDataService.getResourceDataOperationalFoCmHandle(cmHandle,
176 return ResponseEntity.ok(responseObject);
179 private DmiPluginRegistration convertRestObjectToJavaApiObject(
180 final RestDmiPluginRegistration restDmiPluginRegistration) {
181 return objectMapper.convertValue(restDmiPluginRegistration, DmiPluginRegistration.class);