1717
1818/***
1919 *
20- * @author mturiana This class is used to get the value of the keys in
21- * application.properties
20+ * @author mturiana
21+ *
22+ * This class is used to get the value of the keys from the properties file
2223 */
2324@ Component
2425public class EnvironmentConfiguration {
2526
2627 private static final Logger LOGGER = LoggerFactory
2728 .getLogger (EnvironmentConfiguration .class );
2829
29- private static final String PROPERTIES_FILENAME = "environment.properties" ;
30+ private static final String ENVIRONMENT_PROPERTIES_FILENAME = "environment.properties" ;
31+ private static final String FLOW_PROPERTIES_FILENAME = "flow.properties" ;
3032 private static final String DEFAULT_SUFFIX = ".default" ;
3133 private static final String SERVER_PORT = "server.port" ;
3234 private static final String ML_HOST = "mlHost" ;
@@ -41,183 +43,194 @@ public class EnvironmentConfiguration {
4143 @ Autowired
4244 private Environment environment ;
4345
44- private Properties properties = new Properties ();
46+ private Properties environmentProperties = new Properties ();
47+ private Properties flowProperties = new Properties ();
4548
4649 public String getServerPort () {
4750 return this .environment .getProperty (SERVER_PORT );
4851 }
4952
5053 public String getMLHost () {
51- String value = this .properties .getProperty (ML_HOST );
54+ String value = this .environmentProperties .getProperty (ML_HOST );
5255 if (value != null ) {
5356 return value ;
5457 }
5558 value = this .environment .getProperty (ML_HOST );
5659 if (value != null ) {
57- this .properties .setProperty (ML_HOST , value );
60+ this .environmentProperties .setProperty (ML_HOST , value );
5861 return value ;
5962 }
6063 return this .environment .getProperty (ML_HOST + DEFAULT_SUFFIX );
6164 }
6265
6366 public String getMLUsername () {
64- String value = this .properties .getProperty (ML_USERNAME );
67+ String value = this .environmentProperties .getProperty (ML_USERNAME );
6568 if (value != null ) {
6669 return value ;
6770 }
6871 value = this .environment .getProperty (ML_USERNAME );
6972 if (value != null ) {
70- this .properties .setProperty (ML_USERNAME , value );
73+ this .environmentProperties .setProperty (ML_USERNAME , value );
7174 return value ;
7275 }
7376 return this .environment .getProperty (ML_USERNAME + DEFAULT_SUFFIX );
7477 }
7578
7679 public String getMLPassword () {
77- String value = this .properties .getProperty ("mlPassword" );
80+ String value = this .environmentProperties .getProperty ("mlPassword" );
7881 if (value != null ) {
7982 return value ;
8083 }
8184 value = this .environment .getProperty (ML_PASSWORD );
8285 if (value != null ) {
83- this .properties .setProperty (ML_PASSWORD , value );
86+ this .environmentProperties .setProperty (ML_PASSWORD , value );
8487 return value ;
8588 }
8689 return this .environment .getProperty (ML_PASSWORD + DEFAULT_SUFFIX );
8790 }
8891
8992 public String getMLStagingRestPort () {
90- String value = this .properties .getProperty (ML_STAGING_REST_PORT );
93+ String value = this .environmentProperties .getProperty (ML_STAGING_REST_PORT );
9194 if (value != null ) {
9295 return value ;
9396 }
9497 value = this .environment .getProperty (ML_STAGING_REST_PORT );
9598 if (value != null ) {
96- this .properties .setProperty (ML_STAGING_REST_PORT , value );
99+ this .environmentProperties .setProperty (ML_STAGING_REST_PORT , value );
97100 return value ;
98101 }
99102 return this .environment .getProperty (ML_STAGING_REST_PORT + DEFAULT_SUFFIX );
100103 }
101104
102105 public String getMLFinalRestPort () {
103- String value = this .properties .getProperty (ML_FINAL_REST_PORT );
106+ String value = this .environmentProperties .getProperty (ML_FINAL_REST_PORT );
104107 if (value != null ) {
105108 return value ;
106109 }
107110 value = this .environment .getProperty (ML_FINAL_REST_PORT );
108111 if (value != null ) {
109- this .properties .setProperty (ML_FINAL_REST_PORT , value );
112+ this .environmentProperties .setProperty (ML_FINAL_REST_PORT , value );
110113 return value ;
111114 }
112115 return this .environment .getProperty (ML_FINAL_REST_PORT + DEFAULT_SUFFIX );
113116 }
114117
115118 public String getMLAuth () {
116- String value = this .properties .getProperty (ML_AUTH );
119+ String value = this .environmentProperties .getProperty (ML_AUTH );
117120 if (value != null ) {
118121 return value ;
119122 }
120123 value = this .environment .getProperty (ML_AUTH );
121124 if (value != null ) {
122- this .properties .setProperty (ML_AUTH , value );
125+ this .environmentProperties .setProperty (ML_AUTH , value );
123126 return value ;
124127 }
125128 return this .environment .getProperty (ML_AUTH + DEFAULT_SUFFIX );
126129 }
127130
128131 public String getUserPluginDir () {
129- String value = this .properties .getProperty (USER_PLUGIN_DIR );
132+ String value = this .environmentProperties .getProperty (USER_PLUGIN_DIR );
130133 if (value != null ) {
131134 return value ;
132135 }
133136 value = this .environment .getProperty (USER_PLUGIN_DIR );
134137 if (value != null ) {
135- this .properties .setProperty (USER_PLUGIN_DIR , value );
138+ this .environmentProperties .setProperty (USER_PLUGIN_DIR , value );
136139 return value ;
137140 }
138141 return this .environment .getProperty (USER_PLUGIN_DIR + DEFAULT_SUFFIX );
139142 }
140143
141144 public String getAssetInstallTimeFilePath () {
142- String value = this .properties .getProperty (ASSET_INSTALL_TIME_FILE );
145+ String value = this .environmentProperties .getProperty (ASSET_INSTALL_TIME_FILE );
143146 if (value != null ) {
144147 return value ;
145148 }
146149 value = this .environment .getProperty (ASSET_INSTALL_TIME_FILE );
147150 if (value != null ) {
148- this .properties .setProperty (ASSET_INSTALL_TIME_FILE , value );
151+ this .environmentProperties .setProperty (ASSET_INSTALL_TIME_FILE , value );
149152 return value ;
150153 }
151154 return "./assetInstallTime.properties" ;
152155 }
153156
154157 public void setMLHost (String mlHost ) {
155- this .properties .setProperty (ML_HOST , mlHost );
158+ this .environmentProperties .setProperty (ML_HOST , mlHost );
156159 }
157160
158161 public void setMLStagingRestPort (String mlStagingRestPort ) {
159- this .properties .setProperty (ML_STAGING_REST_PORT , mlStagingRestPort );
162+ this .environmentProperties .setProperty (ML_STAGING_REST_PORT , mlStagingRestPort );
160163 }
161164
162165 public void setMLFinalRestPort (String mlFinalRestPort ) {
163- this .properties .setProperty (ML_FINAL_REST_PORT , mlFinalRestPort );
166+ this .environmentProperties .setProperty (ML_FINAL_REST_PORT , mlFinalRestPort );
164167 }
165168
166169 public void setMLUsername (String mlUsername ) {
167- this .properties .setProperty (ML_USERNAME , mlUsername );
170+ this .environmentProperties .setProperty (ML_USERNAME , mlUsername );
168171 }
169172
170173 public void setMLPassword (String mlPassword ) {
171- this .properties .setProperty (ML_PASSWORD , mlPassword );
174+ this .environmentProperties .setProperty (ML_PASSWORD , mlPassword );
172175 }
173176
174177 public void setUserPluginDir (String userPluginDir ) {
175- this .properties .setProperty (USER_PLUGIN_DIR , userPluginDir );
178+ this .environmentProperties .setProperty (USER_PLUGIN_DIR , userPluginDir );
176179 }
177180
178181 public void setAssetInstallTimeFilePath (String assetInstallTimeFilePath ) {
179- this .properties .setProperty (ASSET_INSTALL_TIME_FILE , assetInstallTimeFilePath );
180- }
181-
182- public void loadConfigurationFromFile () {
183- InputStream is = null ;
184- try {
185- File file = new File (PROPERTIES_FILENAME );
186- if (file .exists ()) {
187- is = new FileInputStream ( file );
188- properties .load ( is );
189- }
190- } catch ( Exception e ) {
191- is = null ;
192- }
182+ this .environmentProperties .setProperty (ASSET_INSTALL_TIME_FILE , assetInstallTimeFilePath );
193183 }
194184
195- public void saveConfigurationToFile () {
196- OutputStream out = null ;
197- try {
198- out = new FileOutputStream (new File (PROPERTIES_FILENAME ));
199- this .properties .store (out , null );
200- } catch (FileNotFoundException e ) {
201- LOGGER .error ("environment.properties is not found" , e .getMessage ());
202- } catch (IOException e ) {
203- LOGGER .error ("Error saving configuration." , e .getMessage ());
204- } finally {
205- if (out != null ) {
206- try {
207- out .close ();
208- } catch (IOException e ) {
209- LOGGER .error ("Error closing output stream." , e .getMessage ());
210- }
211- }
212- }
185+ public void loadConfigurationFromFiles () {
186+ loadConfigurationFromFile (environmentProperties , ENVIRONMENT_PROPERTIES_FILENAME );
187+ loadConfigurationFromFile (environmentProperties , FLOW_PROPERTIES_FILENAME );
213188 }
189+
190+ public void loadConfigurationFromFile (Properties configProperties , String fileName ) {
191+ InputStream is = null ;
192+ try {
193+ File file = new File (fileName );
194+ if (file .exists ()) {
195+ is = new FileInputStream ( file );
196+ configProperties .load ( is );
197+ }
198+ } catch ( Exception e ) {
199+ is = null ;
200+ }
201+ }
214202
215- public void removeSavedConfiguration () {
216- this .properties = new Properties ();
217- File file = new File (PROPERTIES_FILENAME );
218- if (file .exists ()) {
219- file .delete ();
220- }
203+ public void saveConfigurationToFile () {
204+ saveConfigurationToFile (environmentProperties , ENVIRONMENT_PROPERTIES_FILENAME );
221205 }
206+
207+ private void saveConfigurationToFile (Properties configProperties , String fileName ) {
208+ OutputStream out = null ;
209+ try {
210+ out = new FileOutputStream (new File (fileName ));
211+ configProperties .store (out , null );
212+ } catch (FileNotFoundException e ) {
213+ LOGGER .error (fileName + " is not found" , e .getMessage ());
214+ } catch (IOException e ) {
215+ LOGGER .error ("Error saving configuration." , e .getMessage ());
216+ } finally {
217+ if (out != null ) {
218+ try {
219+ out .close ();
220+ } catch (IOException e ) {
221+ LOGGER .error ("Error closing output stream." , e .getMessage ());
222+ }
223+ }
224+ }
225+ }
226+
227+ public void saveOrUpdateFlowInputPath (String entityName , String flowName , String inputPath ) {
228+ this .flowProperties .setProperty (entityName + "-" + flowName , inputPath );
229+ saveConfigurationToFile (flowProperties , FLOW_PROPERTIES_FILENAME );
230+ }
231+
232+ public String getFlowInputPath (String entityName , String flowName ) {
233+ return this .flowProperties .getProperty (entityName + "-" + flowName );
234+ }
222235
223236}
0 commit comments