e867deb1ce36f67e4baa11610c0a2d45219b8835
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / music / util / MusicProperties.java
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38
39 package org.onap.portalapp.music.util;
40
41
42 import java.io.IOException;
43 import java.io.InputStream;
44 import java.util.Properties;
45
46 import org.onap.music.eelf.logging.EELFLoggerDelegate;
47 import org.onap.portalapp.music.service.MusicService;
48
49
50 public class MusicProperties {
51         
52         public static final String MUSIC_ENDPOINT = "music.endpoint";
53         
54         public static final String MUSIC_VERSION = "music.version";
55         
56         public static final String MUSIC_KEYSPACE = "music.keyspace";
57         
58         public static final String MUSIC_SESSION_KEYSPACE = "music.session.keyspace";
59
60         public static final String MUSIC_TABLES = "TABLES";
61         
62         public static final String MUSIC_SESSION_ATTR_TABLES = "music.session.attr.tables";
63         
64         public static final String MUSIC_SESSION_META_TABLES = "music.session.meta.tables";
65         
66         public static final String MUSIC_ROWS = "ROW";
67         
68         public static final String MUSIC_SESSION_ROW = "music.sesion.rows";
69
70         public static final String MUSIC_X_MINOR_VERSION = "music.x.minor.version";
71         
72         public static final String MUSIC_X_PATCH_VERSION = "music.x.patch.version";
73         
74         public static final String MUSIC_AID = "AID";
75         
76         public static final String MUSIC_NS = "music.ns";
77         
78         public static final String MUSIC_USER_ID = "music.user.id";
79         
80         public static final String MUSIC_PASSWORD = "music.password";
81         
82         public static final String MUSIC_CONSISTENCYINFO = "music.consistency.info";
83         
84         public static final String MUSIC_CONSISTENCYINFO_VALUE = "music.consistency.info.value";
85         
86         public static final String MUSIC_CACHE = "music.cache";
87         
88         public static final String MUSIC_SERIALIZE_COMPRESS = "music.serialize.compress";
89
90         public static final String MUSIC_ATOMIC_GET = "music.atomic.get";
91                 
92         public static final String MUSIC_ATOMIC_PUT = "music.atomic.put";
93                 
94         public static final String MUSIC_ATOMIC_POST = "music.atomic.post";
95         
96         public static final String MUSIC_EXCLUDE_API = "music.exclude.api";
97         
98         public static final String MUSIC_CLEAN_UP_FREQUENCY = "music.cleanup.frequency";
99         
100         public static final String MUSIC_CLEAN_UP_THRESHOLD = "music.cleanup.threshold";
101         
102         public static final String MUSIC_ENABLE = "music.enable";
103         
104         public static final String SESSION_MAX_INACTIVE_INTERVAL_SECONDS = "music.session.max.inactive.interval.seconds";
105         
106         public static final String ATTRIBUTE_NAME = "ATTRIBUTE_NAME";
107         
108         public static final String ATTRIBUTE_BYTES = "ATTRIBUTE_BYTES";
109         
110         public static final String ATTRIBUTE_CLASS = "ATTRIBUTE_CLASS";
111         
112         public static final String PRIMARY_ID = "PRIMARY_ID";
113         
114         public static final String SESSION_ID = "SESSION_ID";
115         
116         public static final String CREATION_TIME = "CREATION_TIME";
117         
118         public static final String LAST_ACCESS_TIME = "LAST_ACCESS_TIME";
119         
120         public static final String MAX_INACTIVE_INTERVAL = "MAX_INACTIVE_INTERVAL";
121         
122         public static final String EXPIRY_TIME = "EXPIRY_TIME";
123         
124         public static final String PRINCIPAL_NAME = "PRINCIPAL_NAME";
125         
126         private MusicProperties(){}
127
128         private static Properties properties;
129         
130         private static String propertyFileName = "music.properties";
131
132         private static final Object lockObject = new Object();
133         
134         private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicProperties.class);
135
136         /**
137          * Gets the property value for the specified key. If a value is found, leading
138          * and trailing space is trimmed.
139          *
140          * @param property
141          *            Property key
142          * @return Value for the named property; null if the property file was not
143          *         loaded or the key was not found.
144          */
145         public static String getProperty(String property) {
146                 if (properties == null) {
147                         synchronized (lockObject) {
148                                 try {
149                                         if (!initialize()) {
150                                                 logger.error(EELFLoggerDelegate.errorLogger, "Failed to read property file " + propertyFileName);
151                                                 return null;
152                                         }
153                                 } catch (IOException e) {
154                                         logger.error(EELFLoggerDelegate.errorLogger, "Failed to read property file " + propertyFileName ,e);
155                                         return null;
156                                 }
157                         }
158                 }
159                 String value = properties.getProperty(property);
160                 if (value != null)
161                         value = value.trim();
162                 return value;
163         }
164
165         /**
166          * Reads properties from a portal.properties file on the classpath.
167          * 
168          * Clients do NOT need to call this method. Clients MAY call this method to test
169          * whether the properties file can be loaded successfully.
170          * 
171          * @return True if properties were successfully loaded, else false.
172          * @throws IOException
173          *             On failure
174          */
175         private static boolean initialize() throws IOException {
176                 if (properties != null)
177                         return true;
178                 InputStream in = MusicProperties.class.getClassLoader().getResourceAsStream(propertyFileName);
179                 if (in == null)
180                         return false;
181                 properties = new Properties();
182                 try {
183                         properties.load(in);
184                 } finally {
185                         in.close();
186                 }
187                 return true;
188         }
189         
190         /**
191          * Tests whether a property value is available for the specified key.
192          * 
193          * @param key
194          *            Property key
195          * @return True if the key is known, otherwise false.
196          */
197 /*      public static boolean containsProperty(String key) {
198                 return environment.containsProperty(key);
199         }*/
200
201         /**
202          * Returns the property value associated with the given key (never
203          * {@code null}), after trimming any trailing space.
204          * 
205          * @param key
206          *            Property key
207          * @return Property value; the empty string if the environment was not
208          *         autowired, which should never happen.
209          * @throws IllegalStateException
210          *             if the key is not found
211          */
212 /*      public static String getProperty(String key) {
213                 String value = "";
214                 if (environment == null) {
215                 //      logger.error(EELFLoggerDelegate.errorLogger, "getProperty: environment is null, should never happen!");
216                 } else {
217                         value = environment.getRequiredProperty(key);
218                         // java.util.Properties preserves trailing space
219                         if (value != null)
220                                 value = value.trim();
221                 }
222                 return value;
223         }*/
224
225 }