494e7f6596e3b77d042490a0c1d7638237ad897c
[cps.git] / cps-nf-proxy-rest / src / main / java / org / onap / cps / nfproxy / rest / controller / NfProxyController.java
1 /*
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
10  *
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.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.onap.cps.nfproxy.rest.controller;
23
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;
35
36
37 @RestController
38 @RequestMapping("${rest.api.xnf-base-path}")
39 public class NfProxyController implements NfProxyApi {
40
41     private static final String XPATH_ROOT = "/";
42
43     @Autowired
44     private NfProxyDataService nfProxyDataService;
45
46     @Override
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);
51         }
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);
56     }
57 }