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.NotNull;
31 import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
32 import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
33 import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi;
34 import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration;
35 import org.onap.cps.spi.FetchDescendantsOption;
36 import org.onap.cps.spi.model.DataNode;
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;
51 private final ObjectMapper objectMapper;
54 * Constructor Injection for Dependencies.
55 * @param networkCmProxyDataService Data Service Interface
56 * @param objectMapper Object Mapper
58 public NetworkCmProxyController(final NetworkCmProxyDataService networkCmProxyDataService,
59 final ObjectMapper objectMapper) {
60 this.networkCmProxyDataService = networkCmProxyDataService;
61 this.objectMapper = objectMapper;
66 * @deprecated This Method is no longer used as part of NCMP.
69 @Deprecated(forRemoval = false)
70 public ResponseEntity<Void> createNode(final String cmHandle, @Valid final String jsonData,
71 @Valid final String parentNodeXpath) {
72 networkCmProxyDataService.createDataNode(cmHandle, parentNodeXpath, jsonData);
73 return new ResponseEntity<>(HttpStatus.CREATED);
77 * Add List-node Child Element.
78 * @deprecated This Method is no longer used as part of NCMP.
81 @Deprecated(forRemoval = false)
82 public ResponseEntity<Void> addListNodeElements(@NotNull @Valid final String parentNodeXpath,
83 final String cmHandle, @Valid final String jsonData) {
84 networkCmProxyDataService.addListNodeElements(cmHandle, parentNodeXpath, jsonData);
85 return new ResponseEntity<>(HttpStatus.CREATED);
89 * Get Node By CM Handle and X-Path.
90 * @deprecated This Method is no longer used as part of NCMP.
93 @Deprecated(forRemoval = false)
94 public ResponseEntity<Object> getNodeByCmHandleAndXpath(final String cmHandle, @Valid final String xpath,
95 @Valid final Boolean includeDescendants) {
96 final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
97 ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
98 final var dataNode = networkCmProxyDataService.getDataNode(cmHandle, xpath, fetchDescendantsOption);
99 return new ResponseEntity<>(DataMapUtils.toDataMap(dataNode), HttpStatus.OK);
103 * Update DMI Plugin Registration (used for first registration also).
104 * @param restDmiPluginRegistration the registration data
107 public ResponseEntity<Void> updateDmiPluginRegistration(
108 final @Valid RestDmiPluginRegistration restDmiPluginRegistration) {
109 final DmiPluginRegistration dmiPluginRegistration =
110 convertRestObjectToJavaApiObject(restDmiPluginRegistration);
111 networkCmProxyDataService.updateDmiPluginRegistration(dmiPluginRegistration);
112 return new ResponseEntity<>(HttpStatus.CREATED);
117 * @deprecated This Method is no longer used as part of NCMP.
120 @Deprecated(forRemoval = false)
121 public ResponseEntity<Object> queryNodesByCmHandleAndCpsPath(final String cmHandle, @Valid final String cpsPath,
122 @Valid final Boolean includeDescendants) {
123 final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
124 ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
125 final Collection<DataNode> dataNodes =
126 networkCmProxyDataService.queryDataNodes(cmHandle, cpsPath, fetchDescendantsOption);
127 return new ResponseEntity<>(GSON.toJson(dataNodes), HttpStatus.OK);
131 * Replace Node With Descendants.
132 * @deprecated This Method is no longer used as part of NCMP.
135 @Deprecated(forRemoval = false)
136 public ResponseEntity<Object> replaceNode(final String cmHandle, @Valid final String jsonData,
137 @Valid final String parentNodeXpath) {
138 networkCmProxyDataService.replaceNodeTree(cmHandle, parentNodeXpath, jsonData);
139 return new ResponseEntity<>(HttpStatus.OK);
143 * Update Node Leaves.
144 * @deprecated This Method is no longer used as part of NCMP.
147 @Deprecated(forRemoval = false)
148 public ResponseEntity<Object> updateNodeLeaves(final String cmHandle, @Valid final String jsonData,
149 @Valid final String parentNodeXpath) {
150 networkCmProxyDataService.updateNodeLeaves(cmHandle, parentNodeXpath, jsonData);
151 return new ResponseEntity<>(HttpStatus.OK);
155 private DmiPluginRegistration convertRestObjectToJavaApiObject(
156 final RestDmiPluginRegistration restDmiPluginRegistration) {
157 return objectMapper.convertValue(restDmiPluginRegistration, DmiPluginRegistration.class);