2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.controller;
23 import org.onap.portalsdk.core.controller.RestrictedBaseController;
24 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
25 import org.onap.portalsdk.core.util.SystemProperties;
26 import org.onap.vid.category.CategoryParametersResponse;
27 import org.onap.vid.model.CategoryParameter.Family;
28 import org.onap.vid.services.CategoryParameterService;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.http.HttpStatus;
31 import org.springframework.http.ResponseEntity;
32 import org.springframework.web.bind.annotation.*;
33 import org.springframework.web.servlet.ModelAndView;
35 import javax.servlet.http.HttpServletRequest;
37 import static org.onap.vid.utils.Logging.getMethodName;
40 * The Class PropertyController.
43 public class PropertyController extends RestrictedBaseController{
47 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(PropertyController.class);
50 protected CategoryParameterService categoryParameterService;
56 * @param request the request
57 * @return the model and view
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());
68 * @param name the name
69 * @param defaultvalue the defaultvalue
70 * @param request the request
71 * @return the property
72 * @throws Exception the exception
74 @RequestMapping(value = "/get_property/{name}/{defaultvalue}", method = RequestMethod.GET)
75 public ResponseEntity<String> getProperty (@PathVariable("name") String name, @PathVariable("defaultvalue") String defaultvalue,
76 HttpServletRequest request) {
78 String methodName = "getProperty";
79 ResponseEntity<String> resp = null;
81 LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + " start");
84 // convert "_" to "." in the property name
85 if (name == null || name.length() == 0 ) {
86 return ( new ResponseEntity<String> (defaultvalue, HttpStatus.OK));
88 // convert "_" to "." in the property name
89 String propertyName = name.replace('_', '.');
90 pvalue = SystemProperties.getProperty(propertyName);
91 if ( ( pvalue == null ) || ( pvalue.length() == 0 ) ) {
92 pvalue = defaultvalue;
94 resp = new ResponseEntity<>(pvalue, HttpStatus.OK);
97 LOGGER.info(EELFLoggerDelegate.errorLogger, "<== " + "." + methodName + e.toString());
98 LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + "." + methodName + e.toString());
101 LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + " returning " + pvalue);
106 * Gets the owning entity properties.
107 * @param request the request
108 * @return the property
109 * @throws Exception the exception
111 @RequestMapping(value = "/category_parameter", method = RequestMethod.GET)
112 public ResponseEntity getCategoryParameter(HttpServletRequest request, @RequestParam(value="familyName", required = true) Family familyName) {
113 LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodName());
115 CategoryParametersResponse response = categoryParameterService.getCategoryParameters(familyName);
116 LOGGER.debug(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodName(), response);
117 return new ResponseEntity<>(response, HttpStatus.OK);
119 catch (Exception exception) {
120 LOGGER.error("failed to retrieve category parameter list from DB.", exception);
121 return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);