2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2017 AT&T Intellectual Property
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * ============LICENSE_END=============================================
20 * ====================================================================
23 package org.onap.music.main;
25 import java.util.Properties;
27 import org.onap.music.eelf.logging.EELFLoggerDelegate;
28 import org.springframework.beans.factory.InitializingBean;
29 import org.springframework.beans.factory.annotation.Value;
30 import org.springframework.context.annotation.Bean;
31 import org.springframework.context.annotation.PropertySource;
32 import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
33 import org.springframework.stereotype.Component;
35 @PropertySource(value = {"file:/opt/app/music/etc/music.properties", "classpath:/project.properties","file:/opt/app/music/etc/key.properties"})
37 public class PropertiesLoader implements InitializingBean {
39 @Value("${cassandra.host}")
40 public String cassandraHost;
46 public String version;
51 @Value("${music.properties}")
52 public String musicProperties;
54 @Value("${lock.lease.period}")
55 public String lockLeasePeriod;
57 @Value("${cassandra.user}")
58 public String cassandraUser;
60 @Value("${cassandra.password}")
61 public String cassandraPassword;
63 @Value("${cassandra.port}")
64 public String cassandraPort;
69 @Value("${keyspace.active}")
70 public String isKeyspaceActive;
72 @Value("${retry.count}")
73 public String rertryCount;
75 @Value("${transId.header.prefix}")
76 private String transIdPrefix;
78 @Value("${conversation.header.prefix}")
79 private String conversationIdPrefix;
81 @Value("${clientId.header.prefix}")
82 private String clientIdPrefix;
84 @Value("${messageId.header.prefix}")
85 private String messageIdPrefix;
87 @Value("${transId.header.required}")
88 private Boolean transIdRequired;
90 @Value("${conversation.header.required}")
91 private Boolean conversationIdRequired;
93 @Value("${clientId.header.required}")
94 private Boolean clientIdRequired;
96 @Value("${messageId.header.required}")
97 private Boolean messageIdRequired;
99 @Value("${music.aaf.ns}")
100 private String musicAafNs;
102 @Value("${cipher.enc.key}")
103 private String cipherEncKey;
105 @SuppressWarnings("unused")
106 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PropertiesLoader.class);
109 public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
111 PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
112 pspc.setIgnoreResourceNotFound(true);
113 pspc.setIgnoreUnresolvablePlaceholders(true);
120 public void loadProperties() {
121 if(cipherEncKey != null) {
122 MusicUtil.setCipherEncKey(cipherEncKey);
124 if (musicAafNs != null) {
125 MusicUtil.setMusicAafNs(musicAafNs);
127 if (cassandraPort != null && !cassandraPort.equals("${cassandra.port}")) {
128 MusicUtil.setCassandraPort(Integer.parseInt(cassandraPort));
130 if (cassandraUser != null && !cassandraUser.equals("${cassandra.user}")) {
131 MusicUtil.setCassName(cassandraUser);
133 if (cassandraPassword != null && !cassandraPassword.equals("${cassandra.password}")) {
134 MusicUtil.setCassPwd(cassandraPassword);
136 if (debug != null && !debug.equals("${debug}")) {
137 MusicUtil.setDebug(Boolean.parseBoolean(debug));
139 if (lockLeasePeriod != null && !lockLeasePeriod.equals("${lock.lease.period}")) {
140 MusicUtil.setDefaultLockLeasePeriod(Long.parseLong(lockLeasePeriod));
142 if (musicProperties != null && !musicProperties.equals("${music.properties}")) {
143 MusicUtil.setMusicPropertiesFilePath(musicProperties);
145 if (cassandraHost != null && !cassandraHost.equals("${cassandra.host}")) {
146 MusicUtil.setMyCassaHost(cassandraHost);
148 if (version != null && !version.equals("${version}")) {
149 MusicUtil.setVersion(version);
151 if (build != null && !version.equals("${build}")) {
152 MusicUtil.setBuild(build);
154 if (isCadi != null && !isCadi.equals("${cadi}")) {
155 MusicUtil.setIsCadi(Boolean.parseBoolean(isCadi));
157 if (rertryCount != null && !rertryCount.equals("${retry.count}")) {
158 MusicUtil.setRetryCount(Integer.parseInt(rertryCount));
160 if (isKeyspaceActive != null && !isKeyspaceActive.equals("${keyspace.active}")) {
161 MusicUtil.setKeyspaceActive(Boolean.parseBoolean(isKeyspaceActive));
163 if(transIdPrefix!=null) {
164 MusicUtil.setTransIdPrefix(transIdPrefix);
167 if(conversationIdPrefix!=null) {
168 MusicUtil.setConversationIdPrefix(conversationIdPrefix);
171 if(clientIdPrefix!=null) {
172 MusicUtil.setClientIdPrefix(clientIdPrefix);
175 if(messageIdPrefix!=null) {
176 MusicUtil.setMessageIdPrefix(messageIdPrefix);
179 if(transIdRequired!=null) {
180 MusicUtil.setTransIdRequired(transIdRequired);
183 if(conversationIdRequired!=null) {
184 MusicUtil.setConversationIdRequired(conversationIdRequired);
187 if(clientIdRequired!=null) {
188 MusicUtil.setClientIdRequired(clientIdRequired);
191 if(messageIdRequired!=null) {
192 MusicUtil.setMessageIdRequired(messageIdRequired);
196 public static void loadProperties(Properties properties) {
197 if (properties.getProperty("cassandra.host")!=null) {
198 MusicUtil.setMyCassaHost(properties.getProperty("cassandra.host"));
201 if (properties.getProperty("cassandra.port")!=null) {
202 MusicUtil.setCassandraPort(Integer.parseInt(properties.getProperty("cassandra.port")));
205 if (properties.getProperty("cassandra.user")!=null) {
206 MusicUtil.setCassName(properties.getProperty("cassandra.user"));
209 if (properties.getProperty("cassandra.password")!=null) {
210 MusicUtil.setCassPwd(properties.getProperty("cassandra.password"));
213 if (properties.getProperty("music.properties")!=null) {
214 MusicUtil.setMusicPropertiesFilePath(properties.getProperty("music.properties"));
217 if (properties.getProperty("debug")!=null) {
218 MusicUtil.setDebug(Boolean.parseBoolean(properties.getProperty("debug")));
221 if (properties.getProperty("version")!=null) {
222 MusicUtil.setVersion(properties.getProperty("version"));
225 if (properties.getProperty("build")!=null) {
226 MusicUtil.setBuild(properties.getProperty("build"));
229 if (properties.getProperty("lock.lease.period")!=null) {
230 MusicUtil.setDefaultLockLeasePeriod(Long.parseLong(properties.getProperty("lock.lease.period")));
233 if (properties.getProperty("cadi")!=null) {
234 MusicUtil.setIsCadi(Boolean.parseBoolean(properties.getProperty("cadi")));
237 if (properties.getProperty("keyspace.active")!=null) {
238 MusicUtil.setKeyspaceActive(Boolean.parseBoolean(properties.getProperty("keyspace.active")));
241 if (properties.getProperty("retry.count")!=null) {
242 MusicUtil.setRetryCount(Integer.parseInt(properties.getProperty("retry.count")));
245 if (properties.getProperty("transId.header.prefix")!=null) {
246 MusicUtil.setTransIdPrefix(properties.getProperty("transId.header.prefix"));
249 if (properties.getProperty("conversation.header.prefix")!=null) {
250 MusicUtil.setConversationIdPrefix(properties.getProperty("conversation.header.prefix"));
253 if (properties.getProperty("clientId.header.prefix")!=null) {
254 MusicUtil.setClientIdPrefix(properties.getProperty("clientId.header.prefix"));
257 if (properties.getProperty("messageId.header.prefix")!=null) {
258 MusicUtil.setMessageIdPrefix(properties.getProperty("messageId.header.prefix"));
261 if (properties.getProperty("transId.header.required")!=null) {
262 MusicUtil.setTransIdRequired(Boolean.parseBoolean(properties.getProperty("transId.header.required")));
265 if (properties.getProperty("conversation.header.required")!=null) {
266 MusicUtil.setConversationIdRequired(Boolean.parseBoolean(properties.getProperty("conversation.header.required")));
269 if (properties.getProperty("clientId.header.required")!=null) {
270 MusicUtil.setClientIdRequired(Boolean.parseBoolean(properties.getProperty("clientId.header.required")));
273 if (properties.getProperty("messageId.header.required")!=null) {
274 MusicUtil.setMessageIdRequired(Boolean.parseBoolean(properties.getProperty("messageId.header.required")));
277 if (properties.getProperty("music.aaf.ns")!=null) {
278 MusicUtil.setMusicAafNs(properties.getProperty("music.aaf.ns"));
281 if (properties.getProperty("cipher.enc.key")!=null) {
282 MusicUtil.setCipherEncKey(properties.getProperty("cipher.enc.key"));
288 public void afterPropertiesSet() throws Exception {
289 // TODO Auto-generated method stub