39750246b1de280e34f72a153baa6764b9a0d3a2
[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 - 2019 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.apache.commons.lang3.StringUtils;
24 import org.onap.vid.model.ModelConstants;
25 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
26 import org.onap.portalsdk.core.util.SystemProperties;
27 /**
28  * The Class VidProperties.
29  */
30 public class VidProperties extends SystemProperties {
31
32         //VID General Properties
33         public static final String MSO_DISPLAY_TEST_API_ON_SCREEN="mso.displayTestAPIOnScreen";
34         public static final String HOMEPAGE_CONTACT_US_URL = "homepage_contact_us_url";
35         public static final String MSO_DEFAULT_TEST_API="mso.defaultTestAPI";
36         public static final String MSO_MAX_OPENED_INSTANTIATION_REQUESTS="mso.maxOpenedInstantiationRequests";
37         public static final String MSO_ASYNC_POLLING_INTERVAL_SECONDS="mso.asyncPollingIntervalSeconds";
38         public static final String PROBE_SDC_MODEL_UUID="probe.sdc.model.uuid";
39
40         /** The Constant VID_TRUSTSTORE_FILENAME. */
41         public static final String VID_TRUSTSTORE_FILENAME = "vid.truststore.filename";
42
43         /** The Constant VID_TRUSTSTORE_PASSWD_X. */
44         public static final String VID_TRUSTSTORE_PASSWD_X = "vid.truststore.passwd.x";
45
46         /** The Constant FILESEPARATOR. */
47         public static final String FILESEPARATOR = (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
48
49         /** The Constant LOG. */
50         private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidProperties.class);
51
52         public static final String VID_JOB_MAX_HOURS_IN_PROGRESS = "vid.asyncJob.maxHoursInProgress";
53
54         public static final String VID_THREAD_COUNT = "vid.thread.count";
55         public static final String VID_THREAD_TIMEOUT = "vid.thread.timeout";
56
57         /**
58          * Gets the asdc model namespace prefix property
59          *
60          * @return the property value or a default value
61          */
62         public static String getAsdcModelNamespace() {
63                 String methodName = "getAsdcModelNamespace ";
64                 String asdcModelNamespace = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;
65                 try {
66                         asdcModelNamespace = SystemProperties.getProperty(ModelConstants.ASDC_MODEL_NAMESPACE);
67                         if ( asdcModelNamespace == null || asdcModelNamespace.isEmpty()) {
68                                 asdcModelNamespace = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;
69                         }
70                 }
71                 catch ( Exception e ) {
72                         LOG.error (EELFLoggerDelegate.errorLogger, methodName + "unable to find the value, using the default "
73                                         + ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE);
74                         asdcModelNamespace = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE;
75                 }
76                 return (asdcModelNamespace);
77         }
78         /**
79          * Gets the specified property value. If the property is not defined, returns a default value.
80          *
81          * @return the property value or a default value
82          */
83         public static String getPropertyWithDefault ( String propName, String defaultValue ) {
84                 String methodName = "getPropertyWithDefault ";
85                 String propValue = defaultValue;
86                 try {
87                         propValue = SystemProperties.getProperty(propName);
88                         if ( propValue == null || propValue.isEmpty()) {
89                                 propValue = defaultValue;
90                         }
91                 }
92                 catch ( Exception e ) {
93                         LOG.error (EELFLoggerDelegate.errorLogger, methodName + "unable to find the value, using the default "
94                                         + defaultValue);
95                         propValue = defaultValue;
96                 }
97                 return (propValue);
98         }
99
100         public static long getLongProperty(String key) {
101                 return getLongProperty(key, 0);
102         }
103
104         public static long getLongProperty(String key, long defaultValue) {
105                 if (!containsProperty(key)) {
106                         LOG.debug(EELFLoggerDelegate.debugLogger, "No such property: {}. {} value is used", key, defaultValue);
107                         return defaultValue;
108                 }
109                 String configValue = getProperty(key);
110                 if (StringUtils.isNumeric(configValue)) {
111                         return Long.parseLong(configValue);
112                 } else {
113                         LOG.debug(EELFLoggerDelegate.debugLogger, "{} property value is not valid: {}. {} value is used", key, configValue, defaultValue);
114                         return defaultValue;
115                 }
116         }
117 }