Some bug fixes and Minor Chages.
[music.git] / 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 org.onap.music.eelf.logging.EELFLoggerDelegate;
26 import org.springframework.beans.factory.InitializingBean;
27 import org.springframework.beans.factory.annotation.Value;
28 import org.springframework.context.annotation.Bean;
29 import org.springframework.context.annotation.PropertySource;
30 import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
31 import org.springframework.stereotype.Component;
32
33 @PropertySource(value = {"file:/opt/app/music/etc/music.properties", "classpath:/project.properties","file:/opt/app/music/etc/key.properties"})
34 @Component
35 public class PropertiesLoader implements InitializingBean {
36
37     @Value("${cassandra.host}")
38     public String cassandraHost;
39     
40     @Value("${music.ip}")
41     public String musicIp;        
42     
43     @Value("${debug}")
44     public String debug;
45     
46     @Value("${version}")
47     public String version;
48
49     @Value("${build}")
50     public String build;
51     
52     @Value("${music.properties}")
53     public String musicProperties;
54     
55     @Value("${lock.lease.period}")
56     public String lockLeasePeriod;
57     
58     @Value("${cassandra.user}")
59     public String cassandraUser;
60     
61     @Value("${cassandra.password}")
62     public String cassandraPassword;
63     
64     @Value("${cassandra.port}")
65     public String cassandraPort;
66     
67     @Value("${cadi}")
68     public String isCadi;
69     
70     @Value("${keyspace.active}")
71     public String isKeyspaceActive;
72
73     @Value("${retry.count}")
74     public String rertryCount;
75     
76     @Value("${transId.header.prefix}")
77     private String transIdPrefix;
78
79     @Value("${conversation.header.prefix}")
80     private String conversationIdPrefix;
81
82     @Value("${clientId.header.prefix}")
83     private String clientIdPrefix;
84
85     @Value("${messageId.header.prefix}")
86     private String messageIdPrefix;    
87     
88     @Value("${transId.header.required}")
89     private Boolean transIdRequired;
90
91     @Value("${conversation.header.required}")
92     private Boolean conversationIdRequired;
93
94     @Value("${clientId.header.required}")
95     private Boolean clientIdRequired;
96
97     @Value("${messageId.header.required}")
98     private Boolean messageIdRequired;
99
100     @Value("${music.aaf.ns}")
101     private String musicAafNs;
102
103     @Value("${cipher.enc.key}")
104     private String cipherEncKey;
105     
106     private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PropertiesLoader.class);
107     
108     @Bean
109     public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
110         //return new PropertySourcesPlaceholderConfigurer();
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
197     
198     
199     @Override
200     public void afterPropertiesSet() throws Exception {
201         // TODO Auto-generated method stub
202         
203     }
204         
205 }