summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicProperties.java
blob: 9aae97704767cab9c4f727cc334fbbccd19f6e78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 * ============LICENSE_START==========================================
 * ONAP Portal SDK
 * ===================================================================
 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
 * ===================================================================
 *
 * Unless otherwise specified, all software contained herein is licensed
 * under the Apache License, Version 2.0 (the "License");
 * you may not use this software except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *             http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Unless otherwise specified, all documentation contained herein is licensed
 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
 * you may not use this documentation except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *             https://creativecommons.org/licenses/by/4.0/
 *
 * Unless required by applicable law or agreed to in writing, documentation
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * ============LICENSE_END============================================
 *
 * 
 */

package org.onap.portalapp.music.util;


import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.onap.music.eelf.logging.EELFLoggerDelegate;


public class MusicProperties {
	
	public static final String MUSIC_ENDPOINT = "music.endpoint";
	
	public static final String MUSIC_VERSION = "music.version";
	
	public static final String MUSIC_KEYSPACE = "music.keyspace";
	
	public static final String MUSIC_SESSION_KEYSPACE = "music.session.keyspace";

	public static final String MUSIC_TABLES = "TABLES";
	
	public static final String MUSIC_SESSION_ATTR_TABLES = "music.session.attr.tables";
	
	public static final String MUSIC_SESSION_META_TABLES = "music.session.meta.tables";
	
	public static final String MUSIC_ROWS = "ROW";
	
	public static final String MUSIC_SESSION_ROW = "music.sesion.rows";

	public static final String MUSIC_X_MINOR_VERSION = "music.x.minor.version";
	
	public static final String MUSIC_X_PATCH_VERSION = "music.x.patch.version";
	
	public static final String MUSIC_AID = "AID";
	
	public static final String MUSIC_NS = "music.ns";
	
	public static final String MUSIC_USER_ID = "music.user.id";
	
	public static final String MUSIC_PASSWORD = "music.password";
	
	public static final String MUSIC_CONSISTENCYINFO = "music.consistency.info";
	
	public static final String MUSIC_CONSISTENCYINFO_VALUE = "music.consistency.info.value";
	
	public static final String MUSIC_CACHE = "music.cache";
	
	public static final String MUSIC_SERIALIZE_COMPRESS = "music.serialize.compress";

	public static final String MUSIC_ATOMIC_GET = "music.atomic.get";
		
	public static final String MUSIC_ATOMIC_PUT = "music.atomic.put";
		
	public static final String MUSIC_ATOMIC_POST = "music.atomic.post";
	
	public static final String MUSIC_EXCLUDE_API = "music.exclude.api";
	
	public static final String MUSIC_CLEAN_UP_FREQUENCY = "music.cleanup.frequency";
	
	public static final String MUSIC_CLEAN_UP_THRESHOLD = "music.cleanup.threshold";
	
	public static final String MUSIC_ENABLE = "music.enable";
	
	public static final String SESSION_MAX_INACTIVE_INTERVAL_SECONDS = "music.session.max.inactive.interval.seconds";
	
	public static final String ATTRIBUTE_NAME = "ATTRIBUTE_NAME";
	
	public static final String ATTRIBUTE_BYTES = "ATTRIBUTE_BYTES";
	
	public static final String ATTRIBUTE_CLASS = "ATTRIBUTE_CLASS";
	
	public static final String PRIMARY_ID = "PRIMARY_ID";
	
	public static final String SESSION_ID = "SESSION_ID";
	
	public static final String CREATION_TIME = "CREATION_TIME";
	
	public static final String LAST_ACCESS_TIME = "LAST_ACCESS_TIME";
	
	public static final String MAX_INACTIVE_INTERVAL = "MAX_INACTIVE_INTERVAL";
	
	public static final String EXPIRY_TIME = "EXPIRY_TIME";
	
	public static final String PRINCIPAL_NAME = "PRINCIPAL_NAME";
	
	private MusicProperties(){}

	private static Properties properties;
	
	private static String propertyFileName = "music.properties";

	private static final Object lockObject = new Object();
	
	private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicProperties.class);

	/**
	 * Gets the property value for the specified key. If a value is found, leading
	 * and trailing space is trimmed.
	 *
	 * @param property
	 *            Property key
	 * @return Value for the named property; null if the property file was not
	 *         loaded or the key was not found.
	 */
	public static String getProperty(String property) {
		if (properties == null) {
			synchronized (lockObject) {
				try {
					if (!initialize()) {
						logger.error(EELFLoggerDelegate.errorLogger, "Failed to read property file " + propertyFileName);
						return null;
					}
				} catch (IOException e) {
					logger.error(EELFLoggerDelegate.errorLogger, "Failed to read property file " + propertyFileName ,e);
					return null;
				}
			}
		}
		String value = properties.getProperty(property);
		if (value != null)
			value = value.trim();
		return value;
	}

	/**
	 * Reads properties from a portal.properties file on the classpath.
	 * 
	 * Clients do NOT need to call this method. Clients MAY call this method to test
	 * whether the properties file can be loaded successfully.
	 * 
	 * @return True if properties were successfully loaded, else false.
	 * @throws IOException
	 *             On failure
	 */
	private static boolean initialize() throws IOException {
		if (properties != null)
			return true;
		InputStream in = MusicProperties.class.getClassLoader().getResourceAsStream(propertyFileName);
		if (in == null)
			return false;
		properties = new Properties();
		try {
			properties.load(in);
		} finally {
			in.close();
		}
		return true;
	}
	
	/**
	 * Tests whether a property value is available for the specified key.
	 * 
	 * @param key
	 *            Property key
	 * @return True if the key is known, otherwise false.
	 */
/*	public static boolean containsProperty(String key) {
		return environment.containsProperty(key);
	}*/

	/**
	 * Returns the property value associated with the given key (never
	 * {@code null}), after trimming any trailing space.
	 * 
	 * @param key
	 *            Property key
	 * @return Property value; the empty string if the environment was not
	 *         autowired, which should never happen.
	 * @throws IllegalStateException
	 *             if the key is not found
	 */
/*	public static String getProperty(String key) {
		String value = "";
		if (environment == null) {
		//	logger.error(EELFLoggerDelegate.errorLogger, "getProperty: environment is null, should never happen!");
		} else {
			value = environment.getRequiredProperty(key);
			// java.util.Properties preserves trailing space
			if (value != null)
				value = value.trim();
		}
		return value;
	}*/

}