d670e978358319be962e0ec7db55ce47e527cbc9
[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.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
24 import org.onap.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         public static final String MSO_DISPLAY_TEST_API_ON_SCREEN="mso.displayTestAPIOnScreen";
37         public static final String MSO_DEFAULT_TEST_API="mso.defaultTestAPI";
38         public static final String MSO_MAX_OPENED_INSTANTIATION_REQUESTS="mso.maxOpenedInstantiationRequests";
39         public static final String MSO_ASYNC_POLLING_INTERVAL_SECONDS="mso.asyncPollingIntervalSeconds";
40
41         /** The Constant VID_TRUSTSTORE_FILENAME. */
42         public static final String VID_TRUSTSTORE_FILENAME = "vid.truststore.filename";
43         
44         /** The Constant VID_TRUSTSTORE_PASSWD_X. */
45         public static final String VID_TRUSTSTORE_PASSWD_X = "vid.truststore.passwd.x";
46         
47         /** The Constant FILESEPARATOR. */
48         public static final String FILESEPARATOR = (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
49         
50         /** The Constant LOG. */
51         private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidProperties.class);
52         
53         /** The Constant dateFormat. */
54         final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
55         /**
56          * Gets the asdc model namespace prefix property
57          * 
58          * @return the property value or a default value
59          */
60         public static String getAsdcModelNamespace() {
61                 String methodName = "getAsdcModelNamespace ";
62                 String asdcModelNamespace = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;
63             try {
64                 asdcModelNamespace = SystemProperties.getProperty(ModelConstants.ASDC_MODEL_NAMESPACE);
65                 if ( asdcModelNamespace == null || asdcModelNamespace.isEmpty()) {
66                         asdcModelNamespace = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;
67                     }
68             }
69             catch ( Exception e ) {
70                 LOG.error (EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + "unable to find the value, using the default "
71                                 + ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE);
72                 asdcModelNamespace = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;
73             }
74             return (asdcModelNamespace);
75         }
76         /**
77          * Gets the specified property value. If the property is not defined, returns a default value.
78          * 
79          * @return the property value or a default value
80          */
81         public static String getPropertyWithDefault ( String propName, String defaultValue ) {
82                 String methodName = "getPropertyWithDefault ";
83                 String propValue = defaultValue;
84             try {
85                 propValue = SystemProperties.getProperty(propName);
86                 if ( propValue == null || propValue.isEmpty()) {
87                         propValue = defaultValue;
88                     }
89             }
90             catch ( Exception e ) {
91                 LOG.error (EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + "unable to find the value, using the default "
92                                 + defaultValue);
93                 propValue = defaultValue;
94             }
95             return (propValue);
96         }
97 }