Remove this unused logger private field
[music.git] / music-rest / src / main / java / org / onap / music / main / PropertiesLoader.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
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
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  * 
19  * ============LICENSE_END=============================================
20  * ====================================================================
21  */
22
23 package org.onap.music.main;
24
25 import java.util.Properties;
26
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;
34
35 @PropertySource(value = {"file:/opt/app/music/etc/music.properties", "classpath:/project.properties","file:/opt/app/music/etc/key.properties"})
36 @Component
37 public class PropertiesLoader implements InitializingBean {
38
39     @Value("${cassandra.host}")
40     public String cassandraHost;
41
42     @Value("${debug}")
43     public String debug;
44     
45     @Value("${version}")
46     public String version;
47
48     @Value("${build}")
49     public String build;
50     
51     @Value("${music.properties}")
52     public String musicProperties;
53     
54     @Value("${lock.lease.period}")
55     public String lockLeasePeriod;
56     
57     @Value("${cassandra.user}")
58     public String cassandraUser;
59     
60     @Value("${cassandra.password}")
61     public String cassandraPassword;
62     
63     @Value("${cassandra.port}")
64     public String cassandraPort;
65     
66     @Value("${cadi}")
67     public String isCadi;
68     
69     @Value("${keyspace.active}")
70     public String isKeyspaceActive;
71
72     @Value("${retry.count}")
73     public String rertryCount;
74     
75     @Value("${transId.header.prefix}")
76     private String transIdPrefix;
77
78     @Value("${conversation.header.prefix}")
79     private String conversationIdPrefix;
80
81     @Value("${clientId.header.prefix}")
82     private String clientIdPrefix;
83
84     @Value("${messageId.header.prefix}")
85     private String messageIdPrefix;    
86     
87     @Value("${transId.header.required}")
88     private Boolean transIdRequired;
89
90     @Value("${conversation.header.required}")
91     private Boolean conversationIdRequired;
92
93     @Value("${clientId.header.required}")
94     private Boolean clientIdRequired;
95
96     @Value("${messageId.header.required}")
97     private Boolean messageIdRequired;
98
99     @Value("${music.aaf.ns}")
100     private String musicAafNs;
101
102     @Value("${cipher.enc.key}")
103     private String cipherEncKey;
104     
105     @SuppressWarnings("unused")
106         private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PropertiesLoader.class);
107     
108     @Bean
109     public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
110        
111         PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
112         pspc.setIgnoreResourceNotFound(true);
113         pspc.setIgnoreUnresolvablePlaceholders(true);
114         return pspc;
115     }
116     
117     /**
118      * .
119      */
120     public void loadProperties() {
121         if(cipherEncKey != null) {
122             MusicUtil.setCipherEncKey(cipherEncKey);
123         }
124         if (musicAafNs != null) {
125             MusicUtil.setMusicAafNs(musicAafNs);
126         }
127         if (cassandraPort != null && !cassandraPort.equals("${cassandra.port}")) {
128             MusicUtil.setCassandraPort(Integer.parseInt(cassandraPort));
129         }
130         if (cassandraUser != null && !cassandraUser.equals("${cassandra.user}")) {
131             MusicUtil.setCassName(cassandraUser);
132         }
133         if (cassandraPassword != null && !cassandraPassword.equals("${cassandra.password}")) {
134             MusicUtil.setCassPwd(cassandraPassword);
135         }
136         if (debug != null && !debug.equals("${debug}")) {
137             MusicUtil.setDebug(Boolean.parseBoolean(debug));
138         }
139         if (lockLeasePeriod != null && !lockLeasePeriod.equals("${lock.lease.period}")) {
140             MusicUtil.setDefaultLockLeasePeriod(Long.parseLong(lockLeasePeriod));
141         }
142         if (musicProperties != null && !musicProperties.equals("${music.properties}")) {
143             MusicUtil.setMusicPropertiesFilePath(musicProperties);
144         }
145         if (cassandraHost != null && !cassandraHost.equals("${cassandra.host}")) {
146             MusicUtil.setMyCassaHost(cassandraHost);
147         }
148         if (version != null && !version.equals("${version}")) {
149             MusicUtil.setVersion(version);
150         }
151         if (build != null && !version.equals("${build}")) {
152             MusicUtil.setBuild(build);
153         }
154         if (isCadi != null && !isCadi.equals("${cadi}")) {
155             MusicUtil.setIsCadi(Boolean.parseBoolean(isCadi));
156         }
157         if (rertryCount != null && !rertryCount.equals("${retry.count}")) {
158             MusicUtil.setRetryCount(Integer.parseInt(rertryCount));
159         }
160         if (isKeyspaceActive != null && !isKeyspaceActive.equals("${keyspace.active}")) {
161             MusicUtil.setKeyspaceActive(Boolean.parseBoolean(isKeyspaceActive));
162         }
163         if(transIdPrefix!=null) {
164             MusicUtil.setTransIdPrefix(transIdPrefix);
165         }
166
167         if(conversationIdPrefix!=null) {
168             MusicUtil.setConversationIdPrefix(conversationIdPrefix);
169         }
170
171         if(clientIdPrefix!=null) {
172             MusicUtil.setClientIdPrefix(clientIdPrefix);
173         }
174
175         if(messageIdPrefix!=null) {
176             MusicUtil.setMessageIdPrefix(messageIdPrefix);
177         }
178
179         if(transIdRequired!=null) {
180             MusicUtil.setTransIdRequired(transIdRequired);
181         }
182
183         if(conversationIdRequired!=null) {
184             MusicUtil.setConversationIdRequired(conversationIdRequired);
185         }
186
187         if(clientIdRequired!=null) {
188             MusicUtil.setClientIdRequired(clientIdRequired);
189         }
190
191         if(messageIdRequired!=null) {
192             MusicUtil.setMessageIdRequired(messageIdRequired);
193         }
194     }
195
196     public static void loadProperties(Properties properties) {
197         if (properties.getProperty("cassandra.host")!=null) {
198             MusicUtil.setMyCassaHost(properties.getProperty("cassandra.host"));
199         }
200
201         if (properties.getProperty("cassandra.port")!=null) {
202             MusicUtil.setCassandraPort(Integer.parseInt(properties.getProperty("cassandra.port")));
203         }
204
205         if (properties.getProperty("cassandra.user")!=null) {
206             MusicUtil.setCassName(properties.getProperty("cassandra.user"));
207         }
208
209         if (properties.getProperty("cassandra.password")!=null) {
210             MusicUtil.setCassPwd(properties.getProperty("cassandra.password"));
211         }
212         
213         if (properties.getProperty("music.properties")!=null) {
214             MusicUtil.setMusicPropertiesFilePath(properties.getProperty("music.properties"));
215         }
216
217         if (properties.getProperty("debug")!=null) {
218             MusicUtil.setDebug(Boolean.parseBoolean(properties.getProperty("debug")));
219         }
220
221         if (properties.getProperty("version")!=null) {
222             MusicUtil.setVersion(properties.getProperty("version"));
223         }
224
225         if (properties.getProperty("build")!=null) {
226             MusicUtil.setBuild(properties.getProperty("build"));
227         }
228
229         if (properties.getProperty("lock.lease.period")!=null) {
230             MusicUtil.setDefaultLockLeasePeriod(Long.parseLong(properties.getProperty("lock.lease.period")));
231         }
232
233         if (properties.getProperty("cadi")!=null) {
234             MusicUtil.setIsCadi(Boolean.parseBoolean(properties.getProperty("cadi")));
235         }
236
237         if (properties.getProperty("keyspace.active")!=null) {
238             MusicUtil.setKeyspaceActive(Boolean.parseBoolean(properties.getProperty("keyspace.active")));
239         }
240
241         if (properties.getProperty("retry.count")!=null) {
242             MusicUtil.setRetryCount(Integer.parseInt(properties.getProperty("retry.count")));
243         }
244
245         if (properties.getProperty("transId.header.prefix")!=null) {
246             MusicUtil.setTransIdPrefix(properties.getProperty("transId.header.prefix"));
247         }
248
249         if (properties.getProperty("conversation.header.prefix")!=null) {
250             MusicUtil.setConversationIdPrefix(properties.getProperty("conversation.header.prefix"));
251         }
252
253         if (properties.getProperty("clientId.header.prefix")!=null) {
254             MusicUtil.setClientIdPrefix(properties.getProperty("clientId.header.prefix"));
255         }
256
257         if (properties.getProperty("messageId.header.prefix")!=null) {
258             MusicUtil.setMessageIdPrefix(properties.getProperty("messageId.header.prefix"));
259         }
260
261         if (properties.getProperty("transId.header.required")!=null) {
262             MusicUtil.setTransIdRequired(Boolean.parseBoolean(properties.getProperty("transId.header.required")));
263         }
264
265         if (properties.getProperty("conversation.header.required")!=null) {
266             MusicUtil.setConversationIdRequired(Boolean.parseBoolean(properties.getProperty("conversation.header.required")));
267         }
268
269         if (properties.getProperty("clientId.header.required")!=null) {
270             MusicUtil.setClientIdRequired(Boolean.parseBoolean(properties.getProperty("clientId.header.required")));
271         }
272
273         if (properties.getProperty("messageId.header.required")!=null) {
274             MusicUtil.setMessageIdRequired(Boolean.parseBoolean(properties.getProperty("messageId.header.required")));
275         }
276
277         if (properties.getProperty("music.aaf.ns")!=null) {
278             MusicUtil.setMusicAafNs(properties.getProperty("music.aaf.ns"));
279         }
280
281         if (properties.getProperty("cipher.enc.key")!=null) {
282             MusicUtil.setCipherEncKey(properties.getProperty("cipher.enc.key"));
283         }
284
285     }
286     
287     @Override
288     public void afterPropertiesSet() throws Exception {
289         // TODO Auto-generated method stub
290         
291     }
292
293 }