2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Pantheon.tech
4 * ================================================================================
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.nfproxy.rest.controller;
24 import javax.validation.Valid;
25 import org.onap.cps.nfproxy.api.NfProxyDataService;
26 import org.onap.cps.nfproxy.rest.api.NfProxyApi;
27 import org.onap.cps.spi.FetchDescendantsOption;
28 import org.onap.cps.spi.model.DataNode;
29 import org.onap.cps.utils.DataMapUtils;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.http.HttpStatus;
32 import org.springframework.http.ResponseEntity;
33 import org.springframework.web.bind.annotation.RequestMapping;
34 import org.springframework.web.bind.annotation.RestController;
38 @RequestMapping("${rest.api.xnf-base-path}")
39 public class NfProxyController implements NfProxyApi {
41 private static final String XPATH_ROOT = "/";
44 private NfProxyDataService nfProxyDataService;
47 public ResponseEntity<Object> getNodeByCmHandleAndXpath(final String cmHandle, @Valid final String xpath,
48 @Valid final Boolean includeDescendants) {
49 if (XPATH_ROOT.equals(xpath)) {
50 return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
52 final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants)
53 ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS;
54 final DataNode dataNode = nfProxyDataService.getDataNode(cmHandle, xpath, fetchDescendantsOption);
55 return new ResponseEntity<>(DataMapUtils.toDataMap(dataNode), HttpStatus.OK);