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.controllers;
23 import org.onap.vid.category.CategoryParametersResponse;
24 import org.onap.vid.model.CategoryParameter.Family;
25 import org.onap.vid.services.CategoryParameterService;
26 import org.onap.portalsdk.core.controller.RestrictedBaseController;
27 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
28 import org.onap.portalsdk.core.util.SystemProperties;
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;
36 import java.text.DateFormat;
37 import java.text.SimpleDateFormat;
38 import java.util.Date;
40 import static org.onap.vid.utils.Logging.getMethodName;
43 * The Class PropertyController.
46 public class PropertyController extends RestrictedBaseController{
50 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(PropertyController.class);
52 /** The Constant dateFormat. */
53 final protected static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
56 protected CategoryParameterService categoryParameterService;
62 * @param request the request
63 * @return the model and view
65 @RequestMapping(value = {"/propertyhome" }, method = RequestMethod.GET)
66 public ModelAndView welcome(HttpServletRequest request) {
67 LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== PropertyController welcome start");
68 return new ModelAndView(getViewName());
74 * @param name the name
75 * @param defaultvalue the defaultvalue
76 * @param request the request
77 * @return the property
78 * @throws Exception the exception
80 @RequestMapping(value = "/get_property/{name}/{defaultvalue}", method = RequestMethod.GET)
81 public ResponseEntity<String> getProperty (@PathVariable("name") String name, @PathVariable("defaultvalue") String defaultvalue,
82 HttpServletRequest request) {
84 String methodName = "getProperty";
85 ResponseEntity<String> resp = null;
87 LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
90 // convert "_" to "." in the property name
91 if (name == null || name.length() == 0 ) {
92 return ( new ResponseEntity<String> (defaultvalue, HttpStatus.OK));
94 // convert "_" to "." in the property name
95 String propertyName = name.replace('_', '.');
96 pvalue = SystemProperties.getProperty(propertyName);
97 if ( ( pvalue == null ) || ( pvalue.length() == 0 ) ) {
98 pvalue = defaultvalue;
100 resp = new ResponseEntity<String>(pvalue, HttpStatus.OK);
102 catch (Exception e) {
103 LOGGER.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
104 LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
107 LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " returning " + pvalue);
112 * Gets the owning entity properties.
113 * @param request the request
114 * @return the property
115 * @throws Exception the exception
117 @RequestMapping(value = "/category_parameter", method = RequestMethod.GET)
118 public ResponseEntity getCategoryParameter(HttpServletRequest request, @RequestParam(value="familyName", required = true) Family familyName) {
119 LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodName());
121 CategoryParametersResponse response = categoryParameterService.getCategoryParameters(familyName);
122 LOGGER.debug(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodName(), response);
123 return new ResponseEntity<>(response, HttpStatus.OK);
125 catch (Exception exception) {
126 LOGGER.error("failed to retrieve category parameter list from DB.", exception);
127 return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);