Upgrade sonar plugin
[vid.git] / vid-app-common / src / main / java / org / openecomp / vid / properties / VidProperties.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * VID\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.openecomp.vid.properties;\r
22 import java.text.DateFormat;\r
23 import java.text.SimpleDateFormat;\r
24 import java.util.Date;\r
25 import org.openecomp.vid.model.ModelConstants;\r
26 import org.openecomp.portalsdk.core.util.SystemProperties;\r
27 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;\r
28 \r
29 import org.openecomp.vid.controller.VidController;\r
30 /**\r
31  * The Class VidProperties.\r
32  */\r
33 public class VidProperties extends SystemProperties {\r
34 \r
35         //VID General Properties\r
36         \r
37         /** The Constant VID_TRUSTSTORE_FILENAME. */\r
38         public static final String VID_TRUSTSTORE_FILENAME = "vid.truststore.filename";\r
39         \r
40         /** The Constant VID_TRUSTSTORE_PASSWD_X. */\r
41         public static final String VID_TRUSTSTORE_PASSWD_X = "vid.truststore.passwd.x";\r
42         \r
43         /** The Constant FILESEPARATOR. */\r
44         public static final String FILESEPARATOR = (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");\r
45         \r
46         /** The Constant LOG. */\r
47         private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidController.class);\r
48         \r
49         /** The Constant dateFormat. */\r
50         final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");\r
51         /**\r
52          * Gets the asdc model namespace prefix property\r
53          * \r
54          * @return the property value or a default value\r
55          */\r
56         public static String getAsdcModelNamespace() {\r
57                 String methodName = "getAsdcModelNamespace ";\r
58                 String asdcModelNamespace = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;\r
59             try {\r
60                 asdcModelNamespace = SystemProperties.getProperty(ModelConstants.ASDC_MODEL_NAMESPACE);\r
61                 if ( asdcModelNamespace == null || asdcModelNamespace.isEmpty()) {\r
62                         asdcModelNamespace = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;\r
63                     }\r
64             }\r
65             catch ( Exception e ) {\r
66                 LOG.error (EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + "unable to find the value, using the default "\r
67                                 + ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE);\r
68                 asdcModelNamespace = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;\r
69             }\r
70             return (asdcModelNamespace);\r
71         }\r
72         /**\r
73          * Gets the specified property value. If the property is not defined, returns a default value.\r
74          * \r
75          * @return the property value or a default value\r
76          */\r
77         public static String getPropertyWithDefault ( String propName, String defaultValue ) {\r
78                 String methodName = "getPropertyWithDefault ";\r
79                 String propValue = defaultValue;\r
80             try {\r
81                 propValue = SystemProperties.getProperty(propName);\r
82                 if ( propValue == null || propValue.isEmpty()) {\r
83                         propValue = defaultValue;\r
84                     }\r
85             }\r
86             catch ( Exception e ) {\r
87                 LOG.error (EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + "unable to find the value, using the default "\r
88                                 + defaultValue);\r
89                 propValue = defaultValue;\r
90             }\r
91             return (propValue);\r
92         }\r
93 }\r