2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
26 * https://creativecommons.org/licenses/by/4.0/
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.
34 * ============LICENSE_END============================================
39 package org.onap.portalapp.music.util;
42 import java.io.IOException;
43 import java.io.InputStream;
44 import java.util.Properties;
46 import org.onap.music.eelf.logging.EELFLoggerDelegate;
47 import org.onap.portalapp.music.service.MusicService;
50 public class MusicProperties {
52 public static final String MUSIC_ENDPOINT = "music.endpoint";
54 public static final String MUSIC_VERSION = "music.version";
56 public static final String MUSIC_KEYSPACE = "music.keyspace";
58 public static final String MUSIC_SESSION_KEYSPACE = "music.session.keyspace";
60 public static final String MUSIC_TABLES = "TABLES";
62 public static final String MUSIC_SESSION_ATTR_TABLES = "music.session.attr.tables";
64 public static final String MUSIC_SESSION_META_TABLES = "music.session.meta.tables";
66 public static final String MUSIC_ROWS = "ROW";
68 public static final String MUSIC_SESSION_ROW = "music.sesion.rows";
70 public static final String MUSIC_X_MINOR_VERSION = "music.x.minor.version";
72 public static final String MUSIC_X_PATCH_VERSION = "music.x.patch.version";
74 public static final String MUSIC_AID = "AID";
76 public static final String MUSIC_NS = "music.ns";
78 public static final String MUSIC_USER_ID = "music.user.id";
80 public static final String MUSIC_PASSWORD = "music.password";
82 public static final String MUSIC_CONSISTENCYINFO = "music.consistency.info";
84 public static final String MUSIC_CONSISTENCYINFO_VALUE = "music.consistency.info.value";
86 public static final String MUSIC_CACHE = "music.cache";
88 public static final String MUSIC_SERIALIZE_COMPRESS = "music.serialize.compress";
90 public static final String MUSIC_ATOMIC_GET = "music.atomic.get";
92 public static final String MUSIC_ATOMIC_PUT = "music.atomic.put";
94 public static final String MUSIC_ATOMIC_POST = "music.atomic.post";
96 public static final String MUSIC_EXCLUDE_API = "music.exclude.api";
98 public static final String MUSIC_CLEAN_UP_FREQUENCY = "music.cleanup.frequency";
100 public static final String MUSIC_CLEAN_UP_THRESHOLD = "music.cleanup.threshold";
102 public static final String MUSIC_ENABLE = "music.enable";
104 public static final String SESSION_MAX_INACTIVE_INTERVAL_SECONDS = "music.session.max.inactive.interval.seconds";
106 public static final String ATTRIBUTE_NAME = "ATTRIBUTE_NAME";
108 public static final String ATTRIBUTE_BYTES = "ATTRIBUTE_BYTES";
110 public static final String ATTRIBUTE_CLASS = "ATTRIBUTE_CLASS";
112 public static final String PRIMARY_ID = "PRIMARY_ID";
114 public static final String SESSION_ID = "SESSION_ID";
116 public static final String CREATION_TIME = "CREATION_TIME";
118 public static final String LAST_ACCESS_TIME = "LAST_ACCESS_TIME";
120 public static final String MAX_INACTIVE_INTERVAL = "MAX_INACTIVE_INTERVAL";
122 public static final String EXPIRY_TIME = "EXPIRY_TIME";
124 public static final String PRINCIPAL_NAME = "PRINCIPAL_NAME";
126 private MusicProperties(){}
128 private static Properties properties;
130 private static String propertyFileName = "music.properties";
132 private static final Object lockObject = new Object();
134 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicProperties.class);
137 * Gets the property value for the specified key. If a value is found, leading
138 * and trailing space is trimmed.
142 * @return Value for the named property; null if the property file was not
143 * loaded or the key was not found.
145 public static String getProperty(String property) {
146 if (properties == null) {
147 synchronized (lockObject) {
150 logger.error(EELFLoggerDelegate.errorLogger, "Failed to read property file " + propertyFileName);
153 } catch (IOException e) {
154 logger.error(EELFLoggerDelegate.errorLogger, "Failed to read property file " + propertyFileName ,e);
159 String value = properties.getProperty(property);
161 value = value.trim();
166 * Reads properties from a portal.properties file on the classpath.
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.
171 * @return True if properties were successfully loaded, else false.
172 * @throws IOException
175 private static boolean initialize() throws IOException {
176 if (properties != null)
178 InputStream in = MusicProperties.class.getClassLoader().getResourceAsStream(propertyFileName);
181 properties = new Properties();
191 * Tests whether a property value is available for the specified key.
195 * @return True if the key is known, otherwise false.
197 /* public static boolean containsProperty(String key) {
198 return environment.containsProperty(key);
202 * Returns the property value associated with the given key (never
203 * {@code null}), after trimming any trailing space.
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
212 /* public static String getProperty(String key) {
214 if (environment == null) {
215 // logger.error(EELFLoggerDelegate.errorLogger, "getProperty: environment is null, should never happen!");
217 value = environment.getRequiredProperty(key);
218 // java.util.Properties preserves trailing space
220 value = value.trim();