38062df406b3406ef74dafc850a72de6fadc0a8c
[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[] asdcModelNamespaces = null;\r
59                 String value = null;\r
60             try {\r
61                 value = SystemProperties.getProperty(ModelConstants.ASDC_MODEL_NAMESPACE);\r
62                 if ( value == null || value.isEmpty()) {\r
63                         asdcModelNamespaces = new String[1];\r
64                         asdcModelNamespaces[0] = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;\r
65                     }\r
66                 else {\r
67                         asdcModelNamespaces = value.split(",");\r
68                 }\r
69             }\r
70             catch ( Exception e ) {\r
71                 LOG.error (EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + "unable to find the value, using the default "\r
72                                 + ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE);\r
73                 asdcModelNamespaces = new String[1];\r
74                 asdcModelNamespaces[0] = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;\r
75             }\r
76             return (asdcModelNamespaces);\r
77         }\r
78         /**\r
79          * Gets the specified property value. If the property is not defined, returns a default value.\r
80          * \r
81          * @return the property value or a default value\r
82          */\r
83         public static String getPropertyWithDefault ( String propName, String defaultValue ) {\r
84                 String methodName = "getPropertyWithDefault ";\r
85                 String propValue = defaultValue;\r
86             try {\r
87                 propValue = SystemProperties.getProperty(propName);\r
88                 if ( propValue == null || propValue.isEmpty()) {\r
89                         propValue = defaultValue;\r
90                     }\r
91             }\r
92             catch ( Exception e ) {\r
93                 LOG.error (EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + "unable to find the value, using the default "\r
94                                 + defaultValue);\r
95                 propValue = defaultValue;\r
96             }\r
97             return (propValue);\r
98         }\r
99         \r
100 }\r