2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright 2019 Nokia
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.vid.controller;
24 import static org.onap.vid.utils.Logging.getMethodName;
25 import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
26 import static org.springframework.http.HttpStatus.OK;
28 import javax.servlet.http.HttpServletRequest;
29 import org.onap.portalsdk.core.controller.RestrictedBaseController;
30 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
31 import org.onap.vid.category.CategoryParametersResponse;
32 import org.onap.vid.model.CategoryParameter.Family;
33 import org.onap.vid.services.CategoryParameterService;
34 import org.onap.vid.services.CategoryParameterServiceWithRoles;
35 import org.onap.vid.utils.SystemPropertiesWrapper;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.http.ResponseEntity;
38 import org.springframework.web.bind.annotation.PathVariable;
39 import org.springframework.web.bind.annotation.RequestMapping;
40 import org.springframework.web.bind.annotation.RequestMethod;
41 import org.springframework.web.bind.annotation.RequestParam;
42 import org.springframework.web.bind.annotation.RestController;
43 import org.springframework.web.servlet.ModelAndView;
46 public class PropertyController extends RestrictedBaseController {
48 private static final String ERROR_MESSAGE = "Internal error occurred: ";
49 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(PropertyController.class);
50 private final CategoryParameterService categoryParameterService;
51 private final SystemPropertiesWrapper systemPropertiesWrapper;
54 public PropertyController(CategoryParameterServiceWithRoles service, SystemPropertiesWrapper systemPropertiesWrapper) {
55 categoryParameterService = service;
56 this.systemPropertiesWrapper = systemPropertiesWrapper;
59 @RequestMapping(value = {"/propertyhome"}, method = RequestMethod.GET)
60 public ModelAndView welcome(HttpServletRequest request) {
61 LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== PropertyController welcome start");
62 return new ModelAndView(getViewName());
65 @RequestMapping(value = "/get_property/{name}/{defaultvalue}", method = RequestMethod.GET)
66 public ResponseEntity<String> getProperty(@PathVariable("name") String name,
67 @PathVariable("defaultvalue") String defaultvalue,
68 HttpServletRequest request) {
70 String methodName = "getProperty";
71 LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== {} {}", methodName, " start");
73 String propertyName = name.replace('_', '.');
74 String pvalue = systemPropertiesWrapper.getOrDefault(propertyName, defaultvalue);
75 LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== {} {} {}", methodName, "returning", pvalue);
76 return ResponseEntity.status(OK).body(pvalue);
77 } catch (Exception e) {
78 LOGGER.info(EELFLoggerDelegate.errorLogger, "<== {} {}", methodName, e.toString());
79 LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== {} {}", methodName, e.toString());
80 return ResponseEntity.status(INTERNAL_SERVER_ERROR).body(ERROR_MESSAGE + e.getMessage());
84 @RequestMapping(value = "/category_parameter", method = RequestMethod.GET)
85 public ResponseEntity getCategoryParameter(HttpServletRequest request,
86 @RequestParam(value = "familyName", required = true) Family familyName) {
87 LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodName());
89 CategoryParametersResponse response = categoryParameterService.getCategoryParameters(familyName);
90 LOGGER.debug(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodName(), response);
91 return ResponseEntity.status(OK).body(response);
92 } catch (Exception e) {
93 LOGGER.error("failed to retrieve category parameter list from DB.", e);
94 return ResponseEntity.status(INTERNAL_SERVER_ERROR).body(ERROR_MESSAGE + e.getMessage());