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 org.onap.cps.ncmp.api.NetworkCmProxyDataService;
31 import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
32 import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi;
33 import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration;
34 import org.onap.cps.spi.FetchDescendantsOption;
35 import org.onap.cps.spi.model.DataNode;
36 import org.onap.cps.utils.DataMapUtils;
37 import org.springframework.http.HttpStatus;
38 import org.springframework.http.ResponseEntity;
39 import org.springframework.web.bind.annotation.RequestMapping;
40 import org.springframework.web.bind.annotation.RestController;
43 @RequestMapping("${rest.api.ncmp-base-path}")
44 public class NetworkCmProxyController implements NetworkCmProxyApi {
46 private static final Gson GSON = new GsonBuilder().create();
48 private final NetworkCmProxyDataService networkCmProxyDataService;
50 private final ObjectMapper objectMapper;
53 * Constructor Injection for Dependencies.
54 * @param networkCmProxyDataService Data Service Interface
55 * @param objectMapper Object Mapper
57 public NetworkCmProxyController(final NetworkCmProxyDataService networkCmProxyDataService,
58 final ObjectMapper objectMapper) {
59 this.networkCmProxyDataService = networkCmProxyDataService;
60 this.objectMapper = objectMapper;
65 * @deprecated This Method is no longer used as part of NCMP.
68 @Deprecated(forRemoval = false)
69 public ResponseEntity<Void> createNode(final String jsonData, final String cmHandle,
70 final String parentNodeXpath) {
71 networkCmProxyDataService.createDataNode(cmHandle, parentNodeXpath, jsonData);
72 return new ResponseEntity<>(HttpStatus.CREATED);
76 * Add List-node Child Element.
77 * @deprecated This Method is no longer used as part of NCMP.
80 @Deprecated(forRemoval = false)
81 public ResponseEntity<Void> addListNodeElements(final String jsonData, final String parentNodeXpath,
82 final String cmHandle) {
83 networkCmProxyDataService.addListNodeElements(cmHandle, parentNodeXpath, jsonData);
84 return new ResponseEntity<>(HttpStatus.CREATED);
88 * Get Node By CM Handle and X-Path.
89 * @deprecated This Method is no longer used as part of NCMP.
92 @Deprecated(forRemoval = false)
93 public ResponseEntity<Object> getNodeByCmHandleAndXpath(final String cmHandle, @Valid final String xpath,
94 @Valid final Boolean includeDescendants) {
95 final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
96 ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
97 final var dataNode = networkCmProxyDataService.getDataNode(cmHandle, xpath, fetchDescendantsOption);
98 return new ResponseEntity<>(DataMapUtils.toDataMap(dataNode), HttpStatus.OK);
102 * Update DMI Plugin Registration (used for first registration also).
103 * @param restDmiPluginRegistration the registration data
106 public ResponseEntity<Void> updateDmiPluginRegistration(
107 final @Valid RestDmiPluginRegistration restDmiPluginRegistration) {
108 final DmiPluginRegistration dmiPluginRegistration =
109 convertRestObjectToJavaApiObject(restDmiPluginRegistration);
110 networkCmProxyDataService.updateDmiPluginRegistration(dmiPluginRegistration);
111 return new ResponseEntity<>(HttpStatus.CREATED);
116 * @deprecated This Method is no longer used as part of NCMP.
119 @Deprecated(forRemoval = false)
120 public ResponseEntity<Object> queryNodesByCmHandleAndCpsPath(final String cmHandle, @Valid final String cpsPath,
121 @Valid final Boolean includeDescendants) {
122 final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
123 ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
124 final Collection<DataNode> dataNodes =
125 networkCmProxyDataService.queryDataNodes(cmHandle, cpsPath, fetchDescendantsOption);
126 return new ResponseEntity<>(GSON.toJson(dataNodes), HttpStatus.OK);
130 * Replace Node With Descendants.
131 * @deprecated This Method is no longer used as part of NCMP.
134 @Deprecated(forRemoval = false)
135 public ResponseEntity<Object> replaceNode(@Valid final String jsonData, final String cmHandle,
136 @Valid final String parentNodeXpath) {
137 networkCmProxyDataService.replaceNodeTree(cmHandle, parentNodeXpath, jsonData);
138 return new ResponseEntity<>(HttpStatus.OK);
142 * Update Node Leaves.
143 * @deprecated This Method is no longer used as part of NCMP.
146 @Deprecated(forRemoval = false)
147 public ResponseEntity<Object> updateNodeLeaves(@Valid final String jsonData, final String cmHandle,
148 @Valid final String parentNodeXpath) {
149 networkCmProxyDataService.updateNodeLeaves(cmHandle, parentNodeXpath, jsonData);
150 return new ResponseEntity<>(HttpStatus.OK);
154 private DmiPluginRegistration convertRestObjectToJavaApiObject(
155 final RestDmiPluginRegistration restDmiPluginRegistration) {
156 return objectMapper.convertValue(restDmiPluginRegistration, DmiPluginRegistration.class);