org.onap migration
[vid.git] / vid-app-common / src / main / java / org / onap / vid / properties / VidProperties.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.vid.properties;
22
23 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
24 import org.openecomp.portalsdk.core.util.SystemProperties;
25 import org.onap.vid.model.ModelConstants;
26
27 import java.text.DateFormat;
28 import java.text.SimpleDateFormat;
29 import java.util.Date;
30 /**
31  * The Class VidProperties.
32  */
33 public class VidProperties extends SystemProperties {
34
35         //VID General Properties
36         
37         /** The Constant VID_TRUSTSTORE_FILENAME. */
38         public static final String VID_TRUSTSTORE_FILENAME = "vid.truststore.filename";
39         
40         /** The Constant VID_TRUSTSTORE_PASSWD_X. */
41         public static final String VID_TRUSTSTORE_PASSWD_X = "vid.truststore.passwd.x";
42         
43         /** The Constant FILESEPARATOR. */
44         public static final String FILESEPARATOR = (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
45         
46         /** The Constant LOG. */
47         private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidProperties.class);
48         
49         /** The Constant dateFormat. */
50         final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
51         /**
52          * Gets the asdc model namespace prefix property
53          * 
54          * @return the property value or a default value
55          */
56         public static String getAsdcModelNamespace() {
57                 String methodName = "getAsdcModelNamespace ";
58                 String asdcModelNamespace = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;
59             try {
60                 asdcModelNamespace = SystemProperties.getProperty(ModelConstants.ASDC_MODEL_NAMESPACE);
61                 if ( asdcModelNamespace == null || asdcModelNamespace.isEmpty()) {
62                         asdcModelNamespace = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;
63                     }
64             }
65             catch ( Exception e ) {
66                 LOG.error (EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + "unable to find the value, using the default "
67                                 + ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE);
68                 asdcModelNamespace = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;
69             }
70             return (asdcModelNamespace);
71         }
72         /**
73          * Gets the specified property value. If the property is not defined, returns a default value.
74          * 
75          * @return the property value or a default value
76          */
77         public static String getPropertyWithDefault ( String propName, String defaultValue ) {
78                 String methodName = "getPropertyWithDefault ";
79                 String propValue = defaultValue;
80             try {
81                 propValue = SystemProperties.getProperty(propName);
82                 if ( propValue == null || propValue.isEmpty()) {
83                         propValue = defaultValue;
84                     }
85             }
86             catch ( Exception e ) {
87                 LOG.error (EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + "unable to find the value, using the default "
88                                 + defaultValue);
89                 propValue = defaultValue;
90             }
91             return (propValue);
92         }
93 }