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.openecomp.vid.controller;
23 import java.text.DateFormat;
24 import java.text.SimpleDateFormat;
25 import java.util.Date;
27 import javax.servlet.http.HttpServletRequest;
29 import org.springframework.http.HttpStatus;
30 import org.springframework.http.ResponseEntity;
31 import org.springframework.web.bind.annotation.PathVariable;
32 import org.springframework.web.bind.annotation.RequestMapping;
33 import org.springframework.web.bind.annotation.RequestMethod;
34 import org.springframework.web.bind.annotation.RestController;
35 import org.springframework.web.servlet.ModelAndView;
37 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
38 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
39 import org.openecomp.portalsdk.core.util.SystemProperties;
42 * The Class PropertyController.
45 public class PropertyController extends RestrictedBaseController{
51 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PropertyController.class);
53 /** The Constant dateFormat. */
54 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
59 * @param request the request
60 * @return the model and view
62 public ModelAndView welcome(HttpServletRequest request) {
63 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== PropertyController welcome start");
64 return new ModelAndView(getViewName());
68 * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#getViewName()
70 public String getViewName() {
75 * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#setViewName(java.lang.String)
77 public void setViewName(String viewName) {
78 this.viewName = viewName;
84 * @param name the name
85 * @param defaultvalue the defaultvalue
86 * @param request the request
87 * @return the property
88 * @throws Exception the exception
90 @RequestMapping(value = "/get_property/{name}/{defaultvalue}", method = RequestMethod.GET)
91 public ResponseEntity<String> getProperty (@PathVariable("name") String name, @PathVariable("defaultvalue") String defaultvalue,
92 HttpServletRequest request) throws Exception {
94 String methodName = "getProperty";
95 ResponseEntity<String> resp = null;
97 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
100 // convert "_" to "." in the property name
101 if (name == null || name.length() == 0 ) {
102 return ( new ResponseEntity<String> (defaultvalue, HttpStatus.OK));
104 // convert "_" to "." in the property name
105 String propertyName = name.replace('_', '.');
106 pvalue = SystemProperties.getProperty(propertyName);
107 if ( ( pvalue == null ) || ( pvalue.length() == 0 ) ) {
108 pvalue = defaultvalue;
110 resp = new ResponseEntity<String>(pvalue, HttpStatus.OK);
112 catch (Exception e) {
113 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
114 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
117 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " returning " + pvalue);