• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmrs / openmrs-core / 14719695478

28 Apr 2025 11:11PM UTC coverage: 65.187% (+0.1%) from 65.081%
14719695478

push

github

web-flow
TRUNK-6335: Remove all vestiges of the core modules concept (#5019)

1 of 5 new or added lines in 3 files covered. (20.0%)

5 existing lines in 4 files now uncovered.

23400 of 35897 relevant lines covered (65.19%)

0.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/web/src/main/java/org/openmrs/web/filter/initialization/InitializationFilter.java
1
/**
2
 * This Source Code Form is subject to the terms of the Mozilla Public License,
3
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5
 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6
 * 
7
 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8
 * graphic logo is a trademark of OpenMRS Inc.
9
 */
10
package org.openmrs.web.filter.initialization;
11

12
import java.io.File;
13
import java.io.FileInputStream;
14
import java.io.FileOutputStream;
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.io.PrintWriter;
18
import java.net.URI;
19
import java.nio.charset.StandardCharsets;
20
import java.sql.Connection;
21
import java.sql.DriverManager;
22
import java.sql.SQLException;
23
import java.sql.Statement;
24
import java.util.ArrayList;
25
import java.util.Base64;
26
import java.util.Base64.Encoder;
27
import java.util.HashMap;
28
import java.util.List;
29
import java.util.Locale;
30
import java.util.Map;
31
import java.util.Properties;
32
import java.util.Random;
33
import java.util.concurrent.ExecutionException;
34
import java.util.concurrent.Future;
35
import java.util.zip.ZipInputStream;
36
import javax.servlet.FilterChain;
37
import javax.servlet.FilterConfig;
38
import javax.servlet.ServletException;
39
import javax.servlet.ServletRequest;
40
import javax.servlet.ServletResponse;
41
import javax.servlet.http.HttpServletRequest;
42
import javax.servlet.http.HttpServletResponse;
43

44
import liquibase.changelog.ChangeSet;
45
import org.apache.commons.io.IOUtils;
46
import org.openmrs.ImplementationId;
47
import org.openmrs.api.APIAuthenticationException;
48
import org.openmrs.api.PasswordException;
49
import org.openmrs.api.UserService;
50
import org.openmrs.api.context.Context;
51
import org.openmrs.api.context.ContextAuthenticationException;
52
import org.openmrs.api.context.UsernamePasswordCredentials;
53
import org.openmrs.liquibase.ChangeLogDetective;
54
import org.openmrs.liquibase.ChangeLogVersionFinder;
55
import org.openmrs.module.MandatoryModuleException;
56
import org.openmrs.module.web.WebModuleUtil;
57
import org.openmrs.util.DatabaseUpdateException;
58
import org.openmrs.util.DatabaseUpdater;
59
import org.openmrs.liquibase.ChangeSetExecutorCallback;
60
import org.openmrs.util.DatabaseUpdaterLiquibaseProvider;
61
import org.openmrs.util.DatabaseUtil;
62
import org.openmrs.util.InputRequiredException;
63
import org.openmrs.util.OpenmrsConstants;
64
import org.openmrs.util.OpenmrsThreadPoolHolder;
65
import org.openmrs.util.OpenmrsUtil;
66
import org.openmrs.util.PrivilegeConstants;
67
import org.openmrs.util.Security;
68
import org.openmrs.web.Listener;
69
import org.openmrs.web.WebConstants;
70
import org.openmrs.web.WebDaemon;
71
import org.openmrs.web.filter.StartupFilter;
72
import org.openmrs.web.filter.update.UpdateFilter;
73
import org.openmrs.web.filter.util.CustomResourceLoader;
74
import org.openmrs.web.filter.util.ErrorMessageConstants;
75
import org.openmrs.web.filter.util.FilterUtil;
76
import org.slf4j.LoggerFactory;
77
import org.springframework.util.StringUtils;
78
import org.springframework.web.context.ContextLoader;
79

80
/**
81
 * This is the first filter that is processed. It is only active when starting OpenMRS for the very
82
 * first time. It will redirect all requests to the {@link WebConstants#SETUP_PAGE_URL} if the
83
 * {@link Listener} wasn't able to find any runtime properties
84
 */
85
public class InitializationFilter extends StartupFilter {
×
86
        
87
        private static final org.slf4j.Logger log = LoggerFactory.getLogger(InitializationFilter.class);
×
88
        
89
        private static final String DATABASE_POSTGRESQL = "postgresql";
90
        
91
        private static final String DATABASE_MYSQL = "mysql";
92
        
93
        private static final String DATABASE_SQLSERVER = "sqlserver";
94
        
95
        private static final String DATABASE_H2 = "h2";
96
        
97
        private static final String LIQUIBASE_DEMO_DATA = "liquibase-demo-data.xml";
98
        
99
        /**
100
         * The very first page of wizard, that asks user for select his preferred language
101
         */
102
        private static final String CHOOSE_LANG = "chooselang.vm";
103
        
104
        /**
105
         * The second page of the wizard that asks for simple or advanced installation.
106
         */
107
        private static final String INSTALL_METHOD = "installmethod.vm";
108
        
109
        /**
110
         * The simple installation setup page.
111
         */
112
        private static final String SIMPLE_SETUP = "simplesetup.vm";
113
        
114
        /**
115
         * The first page of the advanced installation of the wizard that asks for a current or past
116
         * database
117
         */
118
        private static final String DATABASE_SETUP = "databasesetup.vm";
119
        
120
        /**
121
         * The page from where the user specifies the url to a remote system, username and password
122
         */
123
        private static final String TESTING_REMOTE_DETAILS_SETUP = "remotedetails.vm";
124
        
125
        /**
126
         * The velocity macro page to redirect to if an error occurs or on initial startup
127
         */
128
        private static final String DEFAULT_PAGE = CHOOSE_LANG;
129
        
130
        /**
131
         * This page asks whether database tables/demo data should be inserted and what the
132
         * username/password that will be put into the runtime properties is
133
         */
134
        private static final String DATABASE_TABLES_AND_USER = "databasetablesanduser.vm";
135
        
136
        /**
137
         * This page lets the user define the admin user
138
         */
139
        private static final String ADMIN_USER_SETUP = "adminusersetup.vm";
140
        
141
        /**
142
         * This page lets the user pick an implementation id
143
         */
144
        private static final String IMPLEMENTATION_ID_SETUP = "implementationidsetup.vm";
145
        
146
        /**
147
         * This page asks for settings that will be put into the runtime properties files
148
         */
149
        private static final String OTHER_RUNTIME_PROPS = "otherruntimeproperties.vm";
150
        
151
        /**
152
         * A page that tells the user that everything is collected and will now be processed
153
         */
154
        private static final String WIZARD_COMPLETE = "wizardcomplete.vm";
155
        
156
        /**
157
         * A page that lists off what is happening while it is going on. This page has ajax that callst he
158
         * {@value #PROGRESS_VM_AJAXREQUEST} page
159
         */
160
        private static final String PROGRESS_VM = "progress.vm";
161
        
162
        /**
163
         * This url is called by javascript to get the status of the install
164
         */
165
        private static final String PROGRESS_VM_AJAXREQUEST = "progress.vm.ajaxRequest";
166
        
167
        public static final String RELEASE_TESTING_MODULE_PATH = "/module/releasetestinghelper/";
168
        
169
        /**
170
         * The model object that holds all the properties that the rendered templates use. All attributes on
171
         * this object are made available to all templates via reflection in the
172
         * {@link org.openmrs.web.filter.StartupFilter#renderTemplate(String, Map, HttpServletResponse)} method.
173
         */
174
        private InitializationWizardModel wizardModel = null;
×
175
        
176
        private InitializationCompletion initJob;
177
        
178
        /**
179
         * Variable set to true as soon as the installation begins and set to false when the process ends
180
         * This thread should only be accesses through the synchronized method.
181
         */
182
        private static boolean isInstallationStarted = false;
×
183
        
184
        // the actual driver loaded by the DatabaseUpdater class
185
        private String loadedDriverString;
186
        
187
        /**
188
         * Variable set at the end of the wizard when spring is being restarted
189
         */
190
        private static boolean initializationComplete = false;
×
191
        
192
        protected synchronized void setInitializationComplete(boolean initializationComplete) {
193
                InitializationFilter.initializationComplete = initializationComplete;
×
194
        }
×
195
        
196
        /**
197
         * Called by {@link #doFilter(ServletRequest, ServletResponse, FilterChain)} on GET requests
198
         *
199
         * @param httpRequest
200
         * @param httpResponse
201
         */
202
        @Override
203
        protected void doGet(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
204
                throws IOException, ServletException {
205
                loadInstallationScriptIfPresent();
×
206
                
207
                // we need to save current user language in references map since it will be used when template
208
                // will be rendered
209
                if (httpRequest.getSession().getAttribute(FilterUtil.LOCALE_ATTRIBUTE) == null) {
×
210
                        checkLocaleAttributesForFirstTime(httpRequest);
×
211
                }
212
                
213
                Map<String, Object> referenceMap = new HashMap<>();
×
214
                String page = httpRequest.getParameter("page");
×
215
                
216
                referenceMap.put(FilterUtil.LOCALE_ATTRIBUTE, httpRequest.getSession().getAttribute(FilterUtil.LOCALE_ATTRIBUTE));
×
217
                
218
                httpResponse.setHeader("Cache-Control", "no-cache");
×
219
                
220
                // if any body has already started installation and this is not an ajax request for the progress
221
                if (isInstallationStarted() && !PROGRESS_VM_AJAXREQUEST.equals(page)) {
×
222
                        referenceMap.put("isInstallationStarted", true);
×
223
                        httpResponse.setContentType("text/html");
×
224
                        renderTemplate(PROGRESS_VM, referenceMap, httpResponse);
×
225
                } else if (PROGRESS_VM_AJAXREQUEST.equals(page)) {
×
226
                        httpResponse.setContentType("text/json");
×
227
                        Map<String, Object> result = new HashMap<>();
×
228
                        if (initJob != null) {
×
229
                                result.put("hasErrors", initJob.hasErrors());
×
230
                                if (initJob.hasErrors()) {
×
231
                                        result.put("errorPage", initJob.getErrorPage());
×
232
                                        errors.putAll(initJob.getErrors());
×
233
                                }
234
                                
235
                                result.put("initializationComplete", isInitializationComplete());
×
236
                                result.put("message", initJob.getMessage());
×
237
                                result.put("actionCounter", initJob.getStepsComplete());
×
238
                                if (!isInitializationComplete()) {
×
239
                                        result.put("executingTask", initJob.getExecutingTask());
×
240
                                        result.put("executedTasks", initJob.getExecutedTasks());
×
241
                                        result.put("completedPercentage", initJob.getCompletedPercentage());
×
242
                                }
243
                                
244
                                addLogLinesToResponse(result);
×
245
                        }
246
                        
247
                        PrintWriter writer = httpResponse.getWriter();
×
248
                        writer.write(toJSONString(result));
×
249
                        writer.close();
×
250
                } else if (InitializationWizardModel.INSTALL_METHOD_AUTO.equals(wizardModel.installMethod)
×
251
                        || httpRequest.getServletPath().equals("/" + AUTO_RUN_OPENMRS)) {
×
252
                        autoRunOpenMRS(httpRequest);
×
253
                        referenceMap.put("isInstallationStarted", true);
×
254
                        httpResponse.setContentType("text/html");
×
255
                        renderTemplate(PROGRESS_VM, referenceMap, httpResponse);
×
256
                } else if (page == null) {
×
257
                        httpResponse.setContentType("text/html");// if any body has already started installation
×
258
                        
259
                        //If someone came straight here without setting the hidden page input,
260
                        // then we need to clear out all the passwords
261
                        clearPasswords();
×
262
                        
263
                        renderTemplate(DEFAULT_PAGE, referenceMap, httpResponse);
×
264
                } else if (INSTALL_METHOD.equals(page)) {
×
265
                        // get props and render the second page
266
                        File runtimeProperties = getRuntimePropertiesFile();
×
267
                        
268
                        if (!runtimeProperties.exists()) {
×
269
                                try {
270
                                        runtimeProperties.createNewFile();
×
271
                                        // reset the error objects in case of refresh
272
                                        wizardModel.canCreate = true;
×
273
                                        wizardModel.cannotCreateErrorMessage = "";
×
274
                                }
275
                                catch (IOException io) {
×
276
                                        wizardModel.canCreate = false;
×
277
                                        wizardModel.cannotCreateErrorMessage = io.getMessage();
×
278
                                }
×
279
                                
280
                                // check this before deleting the file again
281
                                wizardModel.canWrite = runtimeProperties.canWrite();
×
282
                                
283
                                // delete the file again after testing the create/write
284
                                // so that if the user stops the webapp before finishing
285
                                // this wizard, they can still get back into it
286
                                runtimeProperties.delete();
×
287
                                
288
                        } else {
289
                                wizardModel.canWrite = runtimeProperties.canWrite();
×
290
                                
291
                                wizardModel.databaseConnection = Context.getRuntimeProperties().getProperty("connection.url",
×
292
                                        wizardModel.databaseConnection);
293
                                
294
                                wizardModel.currentDatabaseUsername = Context.getRuntimeProperties().getProperty("connection.username",
×
295
                                        wizardModel.currentDatabaseUsername);
296
                                
297
                                wizardModel.currentDatabasePassword = Context.getRuntimeProperties().getProperty("connection.password",
×
298
                                        wizardModel.currentDatabasePassword);
299
                        }
300
                        
301
                        wizardModel.runtimePropertiesPath = runtimeProperties.getAbsolutePath();
×
302
                        
303
                        // do step one of the wizard
304
                        httpResponse.setContentType("text/html");
×
305
                        renderTemplate(INSTALL_METHOD, referenceMap, httpResponse);
×
306
                }
307
        }
×
308
        
309
        private void loadInstallationScriptIfPresent() {
310
                Properties script = getInstallationScript();
×
311
                if (!script.isEmpty()) {
×
312
                        wizardModel.installMethod = script.getProperty("install_method", wizardModel.installMethod);
×
313
                        
314
                        wizardModel.databaseConnection = script.getProperty("connection.url", wizardModel.databaseConnection);
×
315
                        wizardModel.databaseDriver = script.getProperty("connection.driver_class", wizardModel.databaseDriver);
×
316
                        wizardModel.currentDatabaseUsername = script.getProperty("connection.username",
×
317
                                wizardModel.currentDatabaseUsername);
318
                        wizardModel.currentDatabasePassword = script.getProperty("connection.password",
×
319
                                wizardModel.currentDatabasePassword);
320
                        
321
                        String hasCurrentOpenmrsDatabase = script.getProperty("has_current_openmrs_database");
×
322
                        if (hasCurrentOpenmrsDatabase != null) {
×
323
                                wizardModel.hasCurrentOpenmrsDatabase = Boolean.valueOf(hasCurrentOpenmrsDatabase);
×
324
                        }
325
                        wizardModel.createDatabaseUsername = script.getProperty("create_database_username",
×
326
                                wizardModel.createDatabaseUsername);
327
                        wizardModel.createDatabasePassword = script.getProperty("create_database_password",
×
328
                                wizardModel.createDatabasePassword);
329
                        
330
                        String createTables = script.getProperty("create_tables");
×
331
                        if (createTables != null) {
×
332
                                wizardModel.createTables = Boolean.valueOf(createTables);
×
333
                        }
334
                        
335
                        String createDatabaseUser = script.getProperty("create_database_user");
×
336
                        if (createDatabaseUser != null) {
×
337
                                wizardModel.createDatabaseUser = Boolean.valueOf(createDatabaseUser);
×
338
                        }
339
                        wizardModel.createUserUsername = script.getProperty("create_user_username", wizardModel.createUserUsername);
×
340
                        wizardModel.createUserPassword = script.getProperty("create_user_password", wizardModel.createUserPassword);
×
341
                        
342
                        String addDemoData = script.getProperty("add_demo_data");
×
343
                        if (addDemoData != null) {
×
344
                                wizardModel.addDemoData = Boolean.valueOf(addDemoData);
×
345
                        }
346
                        
347
                        String moduleWebAdmin = script.getProperty("module_web_admin");
×
348
                        if (moduleWebAdmin != null) {
×
349
                                wizardModel.moduleWebAdmin = Boolean.valueOf(moduleWebAdmin);
×
350
                        }
351
                        
352
                        String autoUpdateDatabase = script.getProperty("auto_update_database");
×
353
                        if (autoUpdateDatabase != null) {
×
354
                                wizardModel.autoUpdateDatabase = Boolean.valueOf(autoUpdateDatabase);
×
355
                        }
356
                        
357
                        wizardModel.adminUserPassword = script.getProperty("admin_user_password", wizardModel.adminUserPassword);
×
358
                }
359
        }
×
360
        
361
        private void clearPasswords() {
362
                wizardModel.databaseRootPassword = "";
×
363
                wizardModel.createDatabasePassword = "";
×
364
                wizardModel.createUserPassword = "";
×
365
                wizardModel.currentDatabasePassword = "";
×
366
                wizardModel.remotePassword = "";
×
367
        }
×
368
        
369
        /**
370
         * Called by {@link #doFilter(ServletRequest, ServletResponse, FilterChain)} on POST requests
371
         *
372
         * @param httpRequest
373
         * @param httpResponse
374
         */
375
        @Override
376
        protected void doPost(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
377
                throws IOException, ServletException {
378
                String page = httpRequest.getParameter("page");
×
379
                Map<String, Object> referenceMap = new HashMap<>();
×
380
                // we need to save current user language in references map since it will be used when template
381
                // will be rendered
382
                if (httpRequest.getSession().getAttribute(FilterUtil.LOCALE_ATTRIBUTE) != null) {
×
383
                        referenceMap.put(FilterUtil.LOCALE_ATTRIBUTE,
×
384
                                httpRequest.getSession().getAttribute(FilterUtil.LOCALE_ATTRIBUTE));
×
385
                }
386
                
387
                // if any body has already started installation
388
                if (isInstallationStarted()) {
×
389
                        referenceMap.put("isInstallationStarted", true);
×
390
                        httpResponse.setContentType("text/html");
×
391
                        renderTemplate(PROGRESS_VM, referenceMap, httpResponse);
×
392
                        return;
×
393
                }
394
                if (DEFAULT_PAGE.equals(page)) {
×
395
                        // get props and render the first page
396
                        File runtimeProperties = getRuntimePropertiesFile();
×
397
                        if (!runtimeProperties.exists()) {
×
398
                                try {
399
                                        runtimeProperties.createNewFile();
×
400
                                        // reset the error objects in case of refresh
401
                                        wizardModel.canCreate = true;
×
402
                                        wizardModel.cannotCreateErrorMessage = "";
×
403
                                }
404
                                catch (IOException io) {
×
405
                                        wizardModel.canCreate = false;
×
406
                                        wizardModel.cannotCreateErrorMessage = io.getMessage();
×
407
                                }
×
408
                                // check this before deleting the file again
409
                                wizardModel.canWrite = runtimeProperties.canWrite();
×
410
                                
411
                                // delete the file again after testing the create/write
412
                                // so that if the user stops the webapp before finishing
413
                                // this wizard, they can still get back into it
414
                                runtimeProperties.delete();
×
415
                        } else {
416
                                wizardModel.canWrite = runtimeProperties.canWrite();
×
417
                                
418
                                wizardModel.databaseConnection = Context.getRuntimeProperties().getProperty("connection.url",
×
419
                                        wizardModel.databaseConnection);
420
                                
421
                                wizardModel.currentDatabaseUsername = Context.getRuntimeProperties().getProperty("connection.username",
×
422
                                        wizardModel.currentDatabaseUsername);
423
                                
424
                                wizardModel.currentDatabasePassword = Context.getRuntimeProperties().getProperty("connection.password",
×
425
                                        wizardModel.currentDatabasePassword);
426
                        }
427
                        
428
                        wizardModel.runtimePropertiesPath = runtimeProperties.getAbsolutePath();
×
429
                        
430
                        checkLocaleAttributes(httpRequest);
×
431
                        referenceMap.put(FilterUtil.LOCALE_ATTRIBUTE,
×
432
                                httpRequest.getSession().getAttribute(FilterUtil.LOCALE_ATTRIBUTE));
×
433
                        log.info("Locale stored in session is " + httpRequest.getSession().getAttribute(FilterUtil.LOCALE_ATTRIBUTE));
×
434
                        
435
                        httpResponse.setContentType("text/html");
×
436
                        // otherwise do step one of the wizard
437
                        renderTemplate(INSTALL_METHOD, referenceMap, httpResponse);
×
438
                } else if (INSTALL_METHOD.equals(page)) {
×
439
                        if (goBack(httpRequest)) {
×
440
                                referenceMap.put(FilterUtil.REMEMBER_ATTRIBUTE,
×
441
                                        httpRequest.getSession().getAttribute(FilterUtil.REMEMBER_ATTRIBUTE) != null);
×
442
                                referenceMap.put(FilterUtil.LOCALE_ATTRIBUTE,
×
443
                                        httpRequest.getSession().getAttribute(FilterUtil.LOCALE_ATTRIBUTE));
×
444
                                renderTemplate(CHOOSE_LANG, referenceMap, httpResponse);
×
445
                                return;
×
446
                        }
447
                        wizardModel.installMethod = httpRequest.getParameter("install_method");
×
448
                        if (InitializationWizardModel.INSTALL_METHOD_SIMPLE.equals(wizardModel.installMethod)) {
×
449
                                page = SIMPLE_SETUP;
×
450
                        } else if (InitializationWizardModel.INSTALL_METHOD_TESTING.equals(wizardModel.installMethod)) {
×
451
                                page = TESTING_REMOTE_DETAILS_SETUP;
×
452
                                wizardModel.currentStepNumber = 1;
×
453
                                wizardModel.numberOfSteps = skipDatabaseSetupPage() ? 1 : 3;
×
454
                        } else {
455
                                page = DATABASE_SETUP;
×
456
                                wizardModel.currentStepNumber = 1;
×
457
                                wizardModel.numberOfSteps = 5;
×
458
                        }
459
                        renderTemplate(page, referenceMap, httpResponse);
×
460
                } // simple method
461
                else if (SIMPLE_SETUP.equals(page)) {
×
462
                        if (goBack(httpRequest)) {
×
463
                                renderTemplate(INSTALL_METHOD, referenceMap, httpResponse);
×
464
                                return;
×
465
                        }
466
                        wizardModel.databaseConnection = httpRequest.getParameter("database_connection");
×
467
                        ;
468
                        
469
                        wizardModel.createDatabaseUsername = Context.getRuntimeProperties().getProperty("connection.username",
×
470
                                wizardModel.createDatabaseUsername);
471
                        
472
                        wizardModel.createUserUsername = wizardModel.createDatabaseUsername;
×
473
                        
474
                        wizardModel.databaseRootPassword = httpRequest.getParameter("database_root_password");
×
475
                        checkForEmptyValue(wizardModel.databaseRootPassword, errors, ErrorMessageConstants.ERROR_DB_PSDW_REQ);
×
476
                        
477
                        wizardModel.hasCurrentOpenmrsDatabase = false;
×
478
                        wizardModel.createTables = true;
×
479
                        // default wizardModel.databaseName is openmrs
480
                        // default wizardModel.createDatabaseUsername is root
481
                        wizardModel.createDatabasePassword = wizardModel.databaseRootPassword;
×
482
                        wizardModel.addDemoData = "yes".equals(httpRequest.getParameter("add_demo_data"));
×
483
                        
484
                        wizardModel.hasCurrentDatabaseUser = false;
×
485
                        wizardModel.createDatabaseUser = true;
×
486
                        // default wizardModel.createUserUsername is root
487
                        wizardModel.createUserPassword = wizardModel.databaseRootPassword;
×
488
                        
489
                        wizardModel.moduleWebAdmin = true;
×
490
                        wizardModel.autoUpdateDatabase = false;
×
491
                        
492
                        wizardModel.adminUserPassword = InitializationWizardModel.ADMIN_DEFAULT_PASSWORD;
×
493
                        
494
                        createSimpleSetup(httpRequest.getParameter("database_root_password"), httpRequest.getParameter("add_demo_data"));
×
495
                        
496
                        try {
497
                                loadedDriverString = DatabaseUtil.loadDatabaseDriver(wizardModel.databaseConnection,
×
498
                                        wizardModel.databaseDriver);
499
                        }
500
                        catch (ClassNotFoundException e) {
×
501
                                errors.put(ErrorMessageConstants.ERROR_DB_DRIVER_CLASS_REQ, null);
×
502
                                renderTemplate(page, referenceMap, httpResponse);
×
503
                                return;
×
504
                        }
×
505
                        
506
                        if (errors.isEmpty()) {
×
507
                                page = WIZARD_COMPLETE;
×
508
                        }
509
                        renderTemplate(page, referenceMap, httpResponse);
×
510
                } // step one
511
                else if (DATABASE_SETUP.equals(page)) {
×
512
                        if (goBack(httpRequest)) {
×
513
                                wizardModel.currentStepNumber -= 1;
×
514
                                if (InitializationWizardModel.INSTALL_METHOD_TESTING.equals(wizardModel.installMethod)) {
×
515
                                        renderTemplate(TESTING_REMOTE_DETAILS_SETUP, referenceMap, httpResponse);
×
516
                                } else {
517
                                        renderTemplate(INSTALL_METHOD, referenceMap, httpResponse);
×
518
                                }
519
                                return;
×
520
                        }
521
                        
522
                        wizardModel.databaseConnection = httpRequest.getParameter("database_connection");
×
523
                        checkForEmptyValue(wizardModel.databaseConnection, errors, ErrorMessageConstants.ERROR_DB_CONN_REQ);
×
524
                        
525
                        wizardModel.databaseDriver = httpRequest.getParameter("database_driver");
×
526
                        checkForEmptyValue(wizardModel.databaseConnection, errors, ErrorMessageConstants.ERROR_DB_DRIVER_REQ);
×
527
                        
528
                        loadedDriverString = loadDriver(wizardModel.databaseConnection, wizardModel.databaseDriver);
×
529
                        if (!StringUtils.hasText(loadedDriverString)) {
×
530
                                errors.put(ErrorMessageConstants.ERROR_DB_DRIVER_CLASS_REQ, null);
×
531
                                renderTemplate(page, referenceMap, httpResponse);
×
532
                                return;
×
533
                        }
534
                        
535
                        //TODO make each bit of page logic a (unit testable) method
536
                        
537
                        // asked the user for their desired database name
538
                        
539
                        if ("yes".equals(httpRequest.getParameter("current_openmrs_database"))) {
×
540
                                wizardModel.databaseName = httpRequest.getParameter("openmrs_current_database_name");
×
541
                                checkForEmptyValue(wizardModel.databaseName, errors, ErrorMessageConstants.ERROR_DB_CURR_NAME_REQ);
×
542
                                wizardModel.hasCurrentOpenmrsDatabase = true;
×
543
                                // TODO check to see if this is an active database
544
                                
545
                        } else {
546
                                // mark this wizard as a "to create database" (done at the end)
547
                                wizardModel.hasCurrentOpenmrsDatabase = false;
×
548
                                
549
                                wizardModel.createTables = true;
×
550
                                
551
                                wizardModel.databaseName = httpRequest.getParameter("openmrs_new_database_name");
×
552
                                checkForEmptyValue(wizardModel.databaseName, errors, ErrorMessageConstants.ERROR_DB_NEW_NAME_REQ);
×
553
                                // TODO create database now to check if its possible?
554
                                
555
                                wizardModel.createDatabaseUsername = httpRequest.getParameter("create_database_username");
×
556
                                checkForEmptyValue(wizardModel.createDatabaseUsername, errors, ErrorMessageConstants.ERROR_DB_USER_NAME_REQ);
×
557
                                wizardModel.createDatabasePassword = httpRequest.getParameter("create_database_password");
×
558
                                checkForEmptyValue(wizardModel.createDatabasePassword, errors, ErrorMessageConstants.ERROR_DB_USER_PSWD_REQ);
×
559
                        }
560
                        
561
                        if (errors.isEmpty()) {
×
562
                                page = DATABASE_TABLES_AND_USER;
×
563
                                
564
                                if (InitializationWizardModel.INSTALL_METHOD_TESTING.equals(wizardModel.installMethod)) {
×
565
                                        wizardModel.currentStepNumber = 3;
×
566
                                } else {
567
                                        wizardModel.currentStepNumber = 2;
×
568
                                }
569
                        }
570
                        
571
                        renderTemplate(page, referenceMap, httpResponse);
×
572
                        
573
                } // step two
574
                else if (DATABASE_TABLES_AND_USER.equals(page)) {
×
575
                        
576
                        if (goBack(httpRequest)) {
×
577
                                wizardModel.currentStepNumber -= 1;
×
578
                                renderTemplate(DATABASE_SETUP, referenceMap, httpResponse);
×
579
                                return;
×
580
                        }
581
                        
582
                        if (wizardModel.hasCurrentOpenmrsDatabase) {
×
583
                                wizardModel.createTables = "yes".equals(httpRequest.getParameter("create_tables"));
×
584
                        }
585
                        
586
                        wizardModel.addDemoData = "yes".equals(httpRequest.getParameter("add_demo_data"));
×
587
                        
588
                        if ("yes".equals(httpRequest.getParameter("current_database_user"))) {
×
589
                                wizardModel.currentDatabaseUsername = httpRequest.getParameter("current_database_username");
×
590
                                checkForEmptyValue(wizardModel.currentDatabaseUsername, errors,
×
591
                                        ErrorMessageConstants.ERROR_DB_CUR_USER_NAME_REQ);
592
                                wizardModel.currentDatabasePassword = httpRequest.getParameter("current_database_password");
×
593
                                checkForEmptyValue(wizardModel.currentDatabasePassword, errors,
×
594
                                        ErrorMessageConstants.ERROR_DB_CUR_USER_PSWD_REQ);
595
                                wizardModel.hasCurrentDatabaseUser = true;
×
596
                                wizardModel.createDatabaseUser = false;
×
597
                        } else {
598
                                wizardModel.hasCurrentDatabaseUser = false;
×
599
                                wizardModel.createDatabaseUser = true;
×
600
                                // asked for the root mysql username/password
601
                                wizardModel.createUserUsername = httpRequest.getParameter("create_user_username");
×
602
                                checkForEmptyValue(wizardModel.createUserUsername, errors, ErrorMessageConstants.ERROR_DB_USER_NAME_REQ);
×
603
                                wizardModel.createUserPassword = httpRequest.getParameter("create_user_password");
×
604
                                checkForEmptyValue(wizardModel.createUserPassword, errors, ErrorMessageConstants.ERROR_DB_USER_PSWD_REQ);
×
605
                        }
606
                        
607
                        if (errors.isEmpty()) { // go to next page
×
608
                                page = InitializationWizardModel.INSTALL_METHOD_TESTING.equals(wizardModel.installMethod) ? WIZARD_COMPLETE
×
609
                                        : OTHER_RUNTIME_PROPS;
610
                        }
611
                        
612
                        renderTemplate(page, referenceMap, httpResponse);
×
613
                } // step three
614
                else if (OTHER_RUNTIME_PROPS.equals(page)) {
×
615
                        
616
                        if (goBack(httpRequest)) {
×
617
                                renderTemplate(DATABASE_TABLES_AND_USER, referenceMap, httpResponse);
×
618
                                return;
×
619
                        }
620
                        
621
                        wizardModel.moduleWebAdmin = "yes".equals(httpRequest.getParameter("module_web_admin"));
×
622
                        wizardModel.autoUpdateDatabase = "yes".equals(httpRequest.getParameter("auto_update_database"));
×
623
                        
624
                        if (wizardModel.createTables) { // go to next page if they are creating tables
×
625
                                page = ADMIN_USER_SETUP;
×
626
                        } else { // skip a page
627
                                page = IMPLEMENTATION_ID_SETUP;
×
628
                        }
629
                        
630
                        renderTemplate(page, referenceMap, httpResponse);
×
631
                        
632
                } // optional step four
633
                else if (ADMIN_USER_SETUP.equals(page)) {
×
634
                        
635
                        if (goBack(httpRequest)) {
×
636
                                renderTemplate(OTHER_RUNTIME_PROPS, referenceMap, httpResponse);
×
637
                                return;
×
638
                        }
639
                        
640
                        wizardModel.adminUserPassword = httpRequest.getParameter("new_admin_password");
×
641
                        String adminUserConfirm = httpRequest.getParameter("new_admin_password_confirm");
×
642
                        
643
                        // throw back to admin user if passwords don't match
644
                        if (!wizardModel.adminUserPassword.equals(adminUserConfirm)) {
×
645
                                errors.put(ErrorMessageConstants.ERROR_DB_ADM_PSWDS_MATCH, null);
×
646
                                renderTemplate(ADMIN_USER_SETUP, referenceMap, httpResponse);
×
647
                                return;
×
648
                        }
649
                        
650
                        // throw back if the user didn't put in a password
651
                        if ("".equals(wizardModel.adminUserPassword)) {
×
652
                                errors.put(ErrorMessageConstants.ERROR_DB_ADM_PSDW_EMPTY, null);
×
653
                                renderTemplate(ADMIN_USER_SETUP, referenceMap, httpResponse);
×
654
                                return;
×
655
                        }
656
                        
657
                        try {
658
                                OpenmrsUtil.validatePassword("admin", wizardModel.adminUserPassword, "admin");
×
659
                        }
660
                        catch (PasswordException p) {
×
661
                                errors.put(ErrorMessageConstants.ERROR_DB_ADM_PSDW_WEAK, null);
×
662
                                renderTemplate(ADMIN_USER_SETUP, referenceMap, httpResponse);
×
663
                                return;
×
664
                        }
×
665
                        
666
                        if (errors.isEmpty()) { // go to next page
×
667
                                page = IMPLEMENTATION_ID_SETUP;
×
668
                        }
669
                        
670
                        renderTemplate(page, referenceMap, httpResponse);
×
671
                        
672
                } // optional step five
×
673
                else if (IMPLEMENTATION_ID_SETUP.equals(page)) {
×
674
                        
675
                        if (goBack(httpRequest)) {
×
676
                                if (wizardModel.createTables) {
×
677
                                        renderTemplate(ADMIN_USER_SETUP, referenceMap, httpResponse);
×
678
                                } else {
679
                                        renderTemplate(OTHER_RUNTIME_PROPS, referenceMap, httpResponse);
×
680
                                }
681
                                return;
×
682
                        }
683
                        
684
                        wizardModel.implementationIdName = httpRequest.getParameter("implementation_name");
×
685
                        wizardModel.implementationId = httpRequest.getParameter("implementation_id");
×
686
                        wizardModel.implementationIdPassPhrase = httpRequest.getParameter("pass_phrase");
×
687
                        wizardModel.implementationIdDescription = httpRequest.getParameter("description");
×
688
                        
689
                        // throw back if the user-specified ID is invalid (contains ^ or |).
690
                        if (wizardModel.implementationId.indexOf('^') != -1 || wizardModel.implementationId.indexOf('|') != -1) {
×
691
                                errors.put(ErrorMessageConstants.ERROR_DB_IMPL_ID_REQ, null);
×
692
                                renderTemplate(IMPLEMENTATION_ID_SETUP, referenceMap, httpResponse);
×
693
                                return;
×
694
                        }
695
                        
696
                        if (errors.isEmpty()) { // go to next page
×
697
                                page = WIZARD_COMPLETE;
×
698
                        }
699
                        
700
                        renderTemplate(page, referenceMap, httpResponse);
×
701
                } else if (WIZARD_COMPLETE.equals(page)) {
×
702
                        
703
                        if (goBack(httpRequest)) {
×
704
                                
705
                                if (InitializationWizardModel.INSTALL_METHOD_SIMPLE.equals(wizardModel.installMethod)) {
×
706
                                        page = SIMPLE_SETUP;
×
707
                                } else if (InitializationWizardModel.INSTALL_METHOD_TESTING.equals(wizardModel.installMethod)) {
×
708
                                        if (skipDatabaseSetupPage()) {
×
709
                                                page = TESTING_REMOTE_DETAILS_SETUP;
×
710
                                        } else {
711
                                                page = DATABASE_TABLES_AND_USER;
×
712
                                        }
713
                                } else {
714
                                        page = IMPLEMENTATION_ID_SETUP;
×
715
                                }
716
                                renderTemplate(page, referenceMap, httpResponse);
×
717
                                return;
×
718
                        }
719
                        
720
                        wizardModel.tasksToExecute = new ArrayList<>();
×
721
                        createDatabaseTask();
×
722
                        if (InitializationWizardModel.INSTALL_METHOD_TESTING.equals(wizardModel.installMethod)) {
×
723
                                wizardModel.importTestData = true;
×
724
                                wizardModel.createTables = false;
×
725
                                wizardModel.addDemoData = false;
×
726
                                //if we have a runtime properties file
727
                                if (skipDatabaseSetupPage()) {
×
728
                                        wizardModel.hasCurrentOpenmrsDatabase = false;
×
729
                                        wizardModel.hasCurrentDatabaseUser = true;
×
730
                                        wizardModel.createDatabaseUser = false;
×
731
                                        Properties props = OpenmrsUtil.getRuntimeProperties(WebConstants.WEBAPP_NAME);
×
732
                                        wizardModel.currentDatabaseUsername = props.getProperty("connection.username");
×
733
                                        wizardModel.currentDatabasePassword = props.getProperty("connection.password");
×
734
                                        wizardModel.createDatabaseUsername = wizardModel.currentDatabaseUsername;
×
735
                                        wizardModel.createDatabasePassword = wizardModel.currentDatabasePassword;
×
736
                                }
737
                                
738
                                wizardModel.tasksToExecute.add(WizardTask.IMPORT_TEST_DATA);
×
739
                                wizardModel.tasksToExecute.add(WizardTask.ADD_MODULES);
×
740
                        } else {
741
                                createTablesTask();
×
742
                                createDemoDataTask();
×
743
                        }
744
                        wizardModel.tasksToExecute.add(WizardTask.UPDATE_TO_LATEST);
×
745
                        
746
                        referenceMap.put("tasksToExecute", wizardModel.tasksToExecute);
×
747
                        startInstallation();
×
748
                        renderTemplate(PROGRESS_VM, referenceMap, httpResponse);
×
749
                } else if (TESTING_REMOTE_DETAILS_SETUP.equals(page)) {
×
750
                        if (goBack(httpRequest)) {
×
751
                                wizardModel.currentStepNumber -= 1;
×
752
                                renderTemplate(INSTALL_METHOD, referenceMap, httpResponse);
×
753
                                return;
×
754
                        }
755
                        
756
                        wizardModel.remoteUrl = httpRequest.getParameter("remoteUrl");
×
757
                        checkForEmptyValue(wizardModel.remoteUrl, errors, "install.testing.remote.url.required");
×
758
                        if (errors.isEmpty()) {
×
759
                                //Check if the remote system is running
760
                                if (TestInstallUtil.testConnection(wizardModel.remoteUrl)) {
×
761
                                        //Check if the test module is installed by connecting to its setting page
762
                                        if (TestInstallUtil
×
763
                                                .testConnection(wizardModel.remoteUrl.concat(RELEASE_TESTING_MODULE_PATH + "settings.htm"))) {
×
764
                                                
765
                                                wizardModel.remoteUsername = httpRequest.getParameter("username");
×
766
                                                wizardModel.remotePassword = httpRequest.getParameter("password");
×
767
                                                checkForEmptyValue(wizardModel.remoteUsername, errors, "install.testing.username.required");
×
768
                                                checkForEmptyValue(wizardModel.remotePassword, errors, "install.testing.password.required");
×
769
                                                
770
                                                if (errors.isEmpty()) {
×
771
                                                        //check if the username and password are valid
772
                                                        try {
773
                                                                TestInstallUtil.getResourceInputStream(
×
774
                                                                        wizardModel.remoteUrl + RELEASE_TESTING_MODULE_PATH + "verifycredentials.htm",
775
                                                                        wizardModel.remoteUsername, wizardModel.remotePassword);
776
                                                        }
777
                                                        catch (APIAuthenticationException e) {
×
778
                                                                log.debug("Error generated: ", e);
×
779
                                                                page = TESTING_REMOTE_DETAILS_SETUP;
×
780
                                                                errors.put(ErrorMessageConstants.UPDATE_ERROR_UNABLE_AUTHENTICATE, null);
×
781
                                                                renderTemplate(page, referenceMap, httpResponse);
×
782
                                                                return;
×
783
                                                        }
×
784
                                                        
785
                                                        //If we have a runtime properties file, get the database setup details from it
786
                                                        if (skipDatabaseSetupPage()) {
×
787
                                                                Properties props = OpenmrsUtil.getRuntimeProperties(WebConstants.WEBAPP_NAME);
×
788
                                                                wizardModel.databaseConnection = props.getProperty("connection.url");
×
789
                                                                loadedDriverString = loadDriver(wizardModel.databaseConnection, wizardModel.databaseDriver);
×
790
                                                                if (!StringUtils.hasText(loadedDriverString)) {
×
791
                                                                        page = TESTING_REMOTE_DETAILS_SETUP;
×
792
                                                                        errors.put(ErrorMessageConstants.ERROR_DB_DRIVER_CLASS_REQ, null);
×
793
                                                                        renderTemplate(page, referenceMap, httpResponse);
×
794
                                                                        return;
×
795
                                                                }
796
                                                                
797
                                                                wizardModel.databaseName = InitializationWizardModel.DEFAULT_DATABASE_NAME;
×
798
                                                                page = WIZARD_COMPLETE;
×
799
                                                        } else {
×
800
                                                                page = DATABASE_SETUP;
×
801
                                                                wizardModel.currentStepNumber = 2;
×
802
                                                        }
803
                                                        msgs.put("install.testing.testingModuleFound", null);
×
804
                                                } else {
805
                                                        renderTemplate(page, referenceMap, httpResponse);
×
806
                                                        return;
×
807
                                                }
808
                                        } else {
809
                                                errors.put("install.testing.noTestingModule", null);
×
810
                                        }
811
                                } else {
812
                                        errors.put("install.testing.invalidProductionUrl", new Object[] { wizardModel.remoteUrl });
×
813
                                }
814
                        }
815
                        
816
                        renderTemplate(page, referenceMap, httpResponse);
×
817
                }
818
        }
×
819
        
820
        private void startInstallation() {
821
                //if no one has run any installation
822
                if (!isInstallationStarted()) {
×
823
                        initJob = new InitializationCompletion();
×
824
                        setInstallationStarted(true);
×
825
                        initJob.start();
×
826
                }
827
        }
×
828
        
829
        private void createDemoDataTask() {
830
                if (wizardModel.addDemoData) {
×
831
                        wizardModel.tasksToExecute.add(WizardTask.ADD_DEMO_DATA);
×
832
                }
833
        }
×
834
        
835
        private void createTablesTask() {
836
                if (wizardModel.createTables) {
×
837
                        wizardModel.tasksToExecute.add(WizardTask.CREATE_TABLES);
×
838
                        wizardModel.tasksToExecute.add(WizardTask.ADD_CORE_DATA);
×
839
                }
840
        }
×
841
        
842
        private void createDatabaseTask() {
843
                if (!wizardModel.hasCurrentOpenmrsDatabase) {
×
844
                        wizardModel.tasksToExecute.add(WizardTask.CREATE_SCHEMA);
×
845
                }
846
                if (wizardModel.createDatabaseUser) {
×
847
                        wizardModel.tasksToExecute.add(WizardTask.CREATE_DB_USER);
×
848
                }
849
        }
×
850
        
851
        private void createSimpleSetup(String databaseRootPassword, String addDemoData) {
852
                setDatabaseNameIfInTestMode();
×
853
                wizardModel.databaseConnection = Context.getRuntimeProperties().getProperty("connection.url",
×
854
                        wizardModel.databaseConnection);
855
                
856
                wizardModel.createDatabaseUsername = Context.getRuntimeProperties().getProperty("connection.username",
×
857
                        wizardModel.createDatabaseUsername);
858
                
859
                wizardModel.createUserUsername = wizardModel.createDatabaseUsername;
×
860
                
861
                wizardModel.databaseRootPassword = databaseRootPassword;
×
862
                checkForEmptyValue(wizardModel.databaseRootPassword, errors, ErrorMessageConstants.ERROR_DB_PSDW_REQ);
×
863
                
864
                wizardModel.hasCurrentOpenmrsDatabase = false;
×
865
                wizardModel.createTables = true;
×
866
                // default wizardModel.databaseName is openmrs
867
                // default wizardModel.createDatabaseUsername is root
868
                wizardModel.createDatabasePassword = wizardModel.databaseRootPassword;
×
869
                wizardModel.addDemoData = "yes".equals(addDemoData);
×
870
                
871
                wizardModel.hasCurrentDatabaseUser = false;
×
872
                wizardModel.createDatabaseUser = true;
×
873
                // default wizardModel.createUserUsername is root
874
                wizardModel.createUserPassword = wizardModel.databaseRootPassword;
×
875
                
876
                wizardModel.moduleWebAdmin = true;
×
877
                wizardModel.autoUpdateDatabase = false;
×
878
                
879
                wizardModel.adminUserPassword = InitializationWizardModel.ADMIN_DEFAULT_PASSWORD;
×
880
        }
×
881
        
882
        private void setDatabaseNameIfInTestMode() {
883
                if (OpenmrsUtil.isTestMode()) {
×
884
                        wizardModel.databaseName = OpenmrsUtil.getOpenMRSVersionInTestMode();
×
885
                }
886
        }
×
887
        
888
        private void autoRunOpenMRS(HttpServletRequest httpRequest) {
889
                File runtimeProperties = getRuntimePropertiesFile();
×
890
                wizardModel.runtimePropertiesPath = runtimeProperties.getAbsolutePath();
×
891
                
892
                if (!InitializationWizardModel.INSTALL_METHOD_AUTO.equals(wizardModel.installMethod)) {
×
893
                        if (httpRequest.getParameter("database_user_name") != null) {
×
894
                                wizardModel.createDatabaseUsername = httpRequest.getParameter("database_user_name");
×
895
                        }
896
                        
897
                        createSimpleSetup(httpRequest.getParameter("database_root_password"), "yes");
×
898
                }
899
                
900
                checkLocaleAttributes(httpRequest);
×
901
                try {
902
                        loadedDriverString = DatabaseUtil.loadDatabaseDriver(wizardModel.databaseConnection, wizardModel.databaseDriver);
×
903
                }
904
                catch (ClassNotFoundException e) {
×
905
                        errors.put(ErrorMessageConstants.ERROR_DB_DRIVER_CLASS_REQ, null);
×
906
                        return;
×
907
                }
×
908
                wizardModel.tasksToExecute = new ArrayList<>();
×
909
                createDatabaseTask();
×
910
                createTablesTask();
×
911
                createDemoDataTask();
×
912
                wizardModel.tasksToExecute.add(WizardTask.UPDATE_TO_LATEST);
×
913
                startInstallation();
×
914
        }
×
915
        
916
        /**
917
         * This method should be called after the user has left wizard's first page (i.e. choose language).
918
         * It checks if user has changed any of locale related parameters and makes appropriate corrections
919
         * with filter's model or/and with locale attribute inside user's session.
920
         *
921
         * @param httpRequest the http request object
922
         */
923
        private void checkLocaleAttributes(HttpServletRequest httpRequest) {
924
                String localeParameter = httpRequest.getParameter(FilterUtil.LOCALE_ATTRIBUTE);
×
925
                Boolean rememberLocale = false;
×
926
                // we need to check if user wants that system will remember his selection of language
927
                if (httpRequest.getParameter(FilterUtil.REMEMBER_ATTRIBUTE) != null) {
×
928
                        rememberLocale = true;
×
929
                }
930
                if (localeParameter != null) {
×
931
                        String storedLocale = null;
×
932
                        if (httpRequest.getSession().getAttribute(FilterUtil.LOCALE_ATTRIBUTE) != null) {
×
933
                                storedLocale = httpRequest.getSession().getAttribute(FilterUtil.LOCALE_ATTRIBUTE).toString();
×
934
                        }
935
                        // if user has changed locale parameter to new one
936
                        // or chooses it parameter at first page loading
937
                        if (storedLocale == null || !storedLocale.equals(localeParameter)) {
×
938
                                log.info("Stored locale parameter to session " + localeParameter);
×
939
                                httpRequest.getSession().setAttribute(FilterUtil.LOCALE_ATTRIBUTE, localeParameter);
×
940
                        }
941
                        if (rememberLocale) {
×
942
                                httpRequest.getSession().setAttribute(FilterUtil.LOCALE_ATTRIBUTE, localeParameter);
×
943
                                httpRequest.getSession().setAttribute(FilterUtil.REMEMBER_ATTRIBUTE, true);
×
944
                                wizardModel.localeToSave = localeParameter;
×
945
                        } else {
946
                                // we need to reset it if it was set before
947
                                httpRequest.getSession().setAttribute(FilterUtil.REMEMBER_ATTRIBUTE, null);
×
948
                                wizardModel.localeToSave = null;
×
949
                        }
950
                }
951
        }
×
952
        
953
        /**
954
         * It sets locale parameter for current session when user is making first GET http request to
955
         * application. It retrieves user locale from request object and checks if this locale is supported
956
         * by application. If not, it uses {@link Locale#ENGLISH} by default
957
         *
958
         * @param httpRequest the http request object
959
         */
960
        public void checkLocaleAttributesForFirstTime(HttpServletRequest httpRequest) {
961
                Locale locale = httpRequest.getLocale();
×
962
                if (CustomResourceLoader.getInstance(httpRequest).getAvailablelocales().contains(locale)) {
×
963
                        httpRequest.getSession().setAttribute(FilterUtil.LOCALE_ATTRIBUTE, locale.toString());
×
964
                } else {
965
                        httpRequest.getSession().setAttribute(FilterUtil.LOCALE_ATTRIBUTE, Locale.ENGLISH.toString());
×
966
                }
967
        }
×
968
        
969
        /**
970
         * Verify the database connection works.
971
         *
972
         * @param connectionUsername
973
         * @param connectionPassword
974
         * @param databaseConnectionFinalUrl
975
         * @return true/false whether it was verified or not
976
         */
977
        private boolean verifyConnection(String connectionUsername, String connectionPassword,
978
                String databaseConnectionFinalUrl) {
979
                try {
980
                        // verify connection
981
                        //Set Database Driver using driver String
982
                        Class.forName(loadedDriverString).newInstance();
×
983
                        Connection tempConnection = DriverManager.getConnection(databaseConnectionFinalUrl, connectionUsername,
×
984
                                connectionPassword);
985
                        tempConnection.close();
×
986
                        return true;
×
987
                        
988
                }
989
                catch (Exception e) {
×
990
                        errors.put("User account " + connectionUsername + " does not work. " + e.getMessage()
×
991
                                        + " See the error log for more details",
992
                                null); // TODO internationalize this
993
                        log.warn("Error while checking the connection user account", e);
×
994
                        return false;
×
995
                }
996
        }
997
        
998
        /**
999
         * Convenience method to load the runtime properties file.
1000
         *
1001
         * @return the runtime properties file.
1002
         */
1003
        private File getRuntimePropertiesFile() {
1004
                File file;
1005
                
1006
                String pathName = OpenmrsUtil.getRuntimePropertiesFilePathName(WebConstants.WEBAPP_NAME);
×
1007
                if (pathName != null) {
×
1008
                        file = new File(pathName);
×
1009
                } else {
1010
                        file = new File(OpenmrsUtil.getApplicationDataDirectory(), getRuntimePropertiesFileName());
×
1011
                }
1012
                
1013
                log.debug("Using file: " + file.getAbsolutePath());
×
1014
                
1015
                return file;
×
1016
        }
1017
        
1018
        private String getRuntimePropertiesFileName() {
1019
                String fileName = OpenmrsUtil.getRuntimePropertiesFileNameInTestMode();
×
1020
                if (fileName == null) {
×
1021
                        fileName = WebConstants.WEBAPP_NAME + "-runtime.properties";
×
1022
                }
1023
                return fileName;
×
1024
        }
1025
        
1026
        /**
1027
         * @see org.openmrs.web.filter.StartupFilter#getTemplatePrefix()
1028
         */
1029
        @Override
1030
        protected String getTemplatePrefix() {
1031
                return "org/openmrs/web/filter/initialization/";
×
1032
        }
1033
        
1034
        /**
1035
         * @see org.openmrs.web.filter.StartupFilter#getUpdateFilterModel()
1036
         */
1037
        @Override
1038
        protected Object getUpdateFilterModel() {
1039
                return wizardModel;
×
1040
        }
1041
        
1042
        /**
1043
         * @see org.openmrs.web.filter.StartupFilter#skipFilter(HttpServletRequest)
1044
         */
1045
        @Override
1046
        public boolean skipFilter(HttpServletRequest httpRequest) {
1047
                // If progress.vm makes an ajax request even immediately after initialization has completed
1048
                // let the request pass in order to let progress.vm load the start page of OpenMRS
1049
                // (otherwise progress.vm is displayed "forever")
1050
                return !PROGRESS_VM_AJAXREQUEST.equals(httpRequest.getParameter("page")) && !initializationRequired();
×
1051
        }
1052
        
1053
        /**
1054
         * Public method that returns true if database+runtime properties initialization is required
1055
         *
1056
         * @return true if this initialization wizard needs to run
1057
         */
1058
        public static boolean initializationRequired() {
1059
                return !isInitializationComplete();
×
1060
        }
1061
        
1062
        /**
1063
         * @param isInstallationStarted the value to set
1064
         */
1065
        protected static synchronized void setInstallationStarted(boolean isInstallationStarted) {
1066
                InitializationFilter.isInstallationStarted = isInstallationStarted;
×
1067
        }
×
1068
        
1069
        /**
1070
         * @return true if installation has been started
1071
         */
1072
        protected static boolean isInstallationStarted() {
1073
                return isInstallationStarted;
×
1074
        }
1075
        
1076
        /**
1077
         * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
1078
         */
1079
        @Override
1080
        public void init(FilterConfig filterConfig) throws ServletException {
1081
                super.init(filterConfig);
×
1082
                wizardModel = new InitializationWizardModel();
×
1083
                DatabaseDetective databaseDetective = new DatabaseDetective();
×
1084
                //set whether need to do initialization work
1085
                if (databaseDetective.isDatabaseEmpty(OpenmrsUtil.getRuntimeProperties(WebConstants.WEBAPP_NAME))) {
×
1086
                        //if runtime-properties file doesn't exist, have to do initialization work
1087
                        setInitializationComplete(false);
×
1088
                } else {
1089
                        //if database is not empty, then let UpdaterFilter to judge whether need database update
1090
                        setInitializationComplete(true);
×
1091
                }
1092
        }
×
1093
        
1094
        private void importTestDataSet(InputStream in, String connectionUrl, String connectionUsername,
1095
                String connectionPassword) throws IOException {
1096
                File tempFile = null;
×
1097
                FileOutputStream fileOut = null;
×
1098
                try {
1099
                        ZipInputStream zipIn = new ZipInputStream(in);
×
1100
                        zipIn.getNextEntry();
×
1101
                        
1102
                        tempFile = File.createTempFile("testDataSet", "dump");
×
1103
                        fileOut = new FileOutputStream(tempFile);
×
1104
                        
1105
                        IOUtils.copy(zipIn, fileOut);
×
1106
                        
1107
                        fileOut.close();
×
1108
                        zipIn.close();
×
1109
                        
1110
                        //Cater for the stand-alone connection url with has :mxj:
1111
                        if (connectionUrl.contains(":mxj:")) {
×
1112
                                connectionUrl = connectionUrl.replace(":mxj:", ":");
×
1113
                        }
1114
                        
1115
                        URI uri = URI.create(connectionUrl.substring(5)); //remove 'jdbc:' prefix to conform to the URI format
×
1116
                        String host = uri.getHost();
×
1117
                        int port = uri.getPort();
×
1118
                        
1119
                        TestInstallUtil.addTestData(host, port, wizardModel.databaseName, connectionUsername, connectionPassword,
×
1120
                                tempFile.getAbsolutePath());
×
1121
                }
1122
                finally {
1123
                        IOUtils.closeQuietly(in);
×
1124
                        IOUtils.closeQuietly(fileOut);
×
1125
                        
1126
                        if (tempFile != null) {
×
1127
                                tempFile.delete();
×
1128
                        }
1129
                }
1130
        }
×
1131
        
1132
        private boolean isCurrentDatabase(String database) {
1133
                return wizardModel.databaseConnection.contains(database);
×
1134
        }
1135
        
1136
        /**
1137
         * @param silent if this statement fails do not display stack trace or record an error in the wizard
1138
         *            object.
1139
         * @param user username to connect with
1140
         * @param pw password to connect with
1141
         * @param sql String containing sql and question marks
1142
         * @param args the strings to fill into the question marks in the given sql
1143
         * @return result of executeUpdate or -1 for error
1144
         */
1145
        private int executeStatement(boolean silent, String user, String pw, String sql, String... args) {
1146
                
1147
                Connection connection = null;
×
1148
                Statement statement = null;
×
1149
                try {
1150
                        String replacedSql = sql;
×
1151
                        
1152
                        // TODO how to get the driver for the other dbs...
1153
                        if (isCurrentDatabase(DATABASE_MYSQL)) {
×
1154
                                Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
×
1155
                        } else if (isCurrentDatabase(DATABASE_POSTGRESQL)) {
×
1156
                                Class.forName("org.postgresql.Driver").newInstance();
×
1157
                                replacedSql = replacedSql.replaceAll("`", "\"");
×
1158
                        } else {
1159
                                replacedSql = replacedSql.replaceAll("`", "\"");
×
1160
                        }
1161
                        
1162
                        String tempDatabaseConnection;
1163
                        if (sql.contains("create database")) {
×
1164
                                tempDatabaseConnection = wizardModel.databaseConnection.replace("@DBNAME@",
×
1165
                                        ""); // make this dbname agnostic so we can create the db
1166
                        } else {
1167
                                tempDatabaseConnection = wizardModel.databaseConnection.replace("@DBNAME@", wizardModel.databaseName);
×
1168
                        }
1169
                        
1170
                        connection = DriverManager.getConnection(tempDatabaseConnection, user, pw);
×
1171
                        
1172
                        for (String arg : args) {
×
1173
                                arg = arg.replace(";", "&#094"); // to prevent any sql injection
×
1174
                                replacedSql = replacedSql.replaceFirst("\\?", arg);
×
1175
                        }
1176
                        
1177
                        // run the sql statement
1178
                        statement = connection.createStatement();
×
1179
                        
1180
                        return statement.executeUpdate(replacedSql);
×
1181
                        
1182
                }
1183
                catch (SQLException sqlex) {
×
1184
                        if (!silent) {
×
1185
                                // log and add error
1186
                                log.warn("error executing sql: " + sql, sqlex);
×
1187
                                errors.put("Error executing sql: " + sql + " - " + sqlex.getMessage(), null);
×
1188
                        }
1189
                }
1190
                catch (InstantiationException | ClassNotFoundException | IllegalAccessException e) {
×
1191
                        log.error("Error generated", e);
×
1192
                }
1193
                finally {
1194
                        try {
1195
                                if (statement != null) {
×
1196
                                        statement.close();
×
1197
                                }
1198
                        }
1199
                        catch (SQLException e) {
×
1200
                                log.warn("Error while closing statement");
×
1201
                        }
×
1202
                        try {
1203
                                
1204
                                if (connection != null) {
×
1205
                                        connection.close();
×
1206
                                }
1207
                        }
1208
                        catch (Exception e) {
×
1209
                                log.warn("Error while closing connection", e);
×
1210
                        }
×
1211
                }
1212
                
1213
                return -1;
×
1214
        }
1215
        
1216
        /**
1217
         * Convenience variable to know if this wizard has completed successfully and that this wizard does
1218
         * not need to be executed again
1219
         *
1220
         * @return true if this has been run already
1221
         */
1222
        private static synchronized boolean isInitializationComplete() {
1223
                return initializationComplete;
×
1224
        }
1225
        
1226
        /**
1227
         * Check if the given value is null or a zero-length String
1228
         *
1229
         * @param value the string to check
1230
         * @param errors the list of errors to append the errorMessage to if value is empty
1231
         * @param errorMessageCode the string with code of error message translation to append if value is
1232
         *            empty
1233
         * @return true if the value is non-empty
1234
         */
1235
        private boolean checkForEmptyValue(String value, Map<String, Object[]> errors, String errorMessageCode) {
1236
                if (!StringUtils.isEmpty(value)) {
×
1237
                        return true;
×
1238
                }
1239
                errors.put(errorMessageCode, null);
×
1240
                return false;
×
1241
        }
1242
        
1243
        /**
1244
         * Separate thread that will run through all tasks to complete the initialization. The database is
1245
         * created, user's created, etc here
1246
         */
1247
        private class InitializationCompletion {
1248
                
1249
                private final Future<Void> future;
1250
                
1251
                private int steps = 0;
×
1252
                
1253
                private String message = "";
×
1254
                
1255
                private Map<String, Object[]> errors = new HashMap<>();
×
1256
                
1257
                private String errorPage = null;
×
1258
                
1259
                private boolean erroneous = false;
×
1260
                
1261
                private int completedPercentage = 0;
×
1262
                
1263
                private WizardTask executingTask;
1264
                
1265
                private List<WizardTask> executedTasks = new ArrayList<>();
×
1266
                
1267
                public synchronized void reportError(String error, String errorPage, Object... params) {
1268
                        errors.put(error, params);
×
1269
                        this.errorPage = errorPage;
×
1270
                        erroneous = true;
×
1271
                }
×
1272
                
1273
                public synchronized boolean hasErrors() {
1274
                        return erroneous;
×
1275
                }
1276
                
1277
                public synchronized String getErrorPage() {
1278
                        return errorPage;
×
1279
                }
1280
                
1281
                public synchronized Map<String, Object[]> getErrors() {
1282
                        return errors;
×
1283
                }
1284
                
1285
                /**
1286
                 * Start the completion stage. This fires up the thread to do all the work.
1287
                 */
1288
                public void start() {
1289
                        setStepsComplete(0);
×
1290
                        setInitializationComplete(false);
×
1291
                }
×
1292
                
1293
                public void waitForCompletion() {
1294
                        try {
1295
                                future.get();
×
1296
                        } catch (InterruptedException | ExecutionException e) {
×
1297
                                throw new RuntimeException(e);
×
1298
                        }
×
1299
                }
×
1300
                
1301
                protected synchronized void setStepsComplete(int steps) {
1302
                        this.steps = steps;
×
1303
                }
×
1304
                
1305
                protected synchronized int getStepsComplete() {
1306
                        return steps;
×
1307
                }
1308
                
1309
                public synchronized String getMessage() {
1310
                        return message;
×
1311
                }
1312
                
1313
                public synchronized void setMessage(String message) {
1314
                        this.message = message;
×
1315
                        setStepsComplete(getStepsComplete() + 1);
×
1316
                }
×
1317
                
1318
                /**
1319
                 * @return the executingTask
1320
                 */
1321
                protected synchronized WizardTask getExecutingTask() {
1322
                        return executingTask;
×
1323
                }
1324
                
1325
                /**
1326
                 * @return the completedPercentage
1327
                 */
1328
                protected synchronized int getCompletedPercentage() {
1329
                        return completedPercentage;
×
1330
                }
1331
                
1332
                /**
1333
                 * @param completedPercentage the completedPercentage to set
1334
                 */
1335
                protected synchronized void setCompletedPercentage(int completedPercentage) {
1336
                        this.completedPercentage = completedPercentage;
×
1337
                }
×
1338
                
1339
                /**
1340
                 * Adds a task that has been completed to the list of executed tasks
1341
                 *
1342
                 * @param task
1343
                 */
1344
                protected synchronized void addExecutedTask(WizardTask task) {
1345
                        this.executedTasks.add(task);
×
1346
                }
×
1347
                
1348
                /**
1349
                 * @param executingTask the executingTask to set
1350
                 */
1351
                protected synchronized void setExecutingTask(WizardTask executingTask) {
1352
                        this.executingTask = executingTask;
×
1353
                }
×
1354
                
1355
                /**
1356
                 * @return the executedTasks
1357
                 */
1358
                protected synchronized List<WizardTask> getExecutedTasks() {
1359
                        return this.executedTasks;
×
1360
                }
1361
                
1362
                /**
1363
                 * This class does all the work of creating the desired database, user, updates, etc
1364
                 */
1365
                public InitializationCompletion() {
×
1366
                        Runnable r = new Runnable() {
×
1367
                                
1368
                                /**
1369
                                 * TODO split this up into multiple testable methods
1370
                                 *
1371
                                 * @see java.lang.Runnable#run()
1372
                                 */
1373
                                @Override
1374
                                public void run() {
1375
                                        try {
1376
                                                String connectionUsername;
1377
                                                StringBuilder connectionPassword = new StringBuilder();
×
1378
                                                ChangeLogDetective changeLogDetective = ChangeLogDetective.getInstance();
×
1379
                                                ChangeLogVersionFinder changeLogVersionFinder = new ChangeLogVersionFinder();
×
1380
                                                
1381
                                                if (!wizardModel.hasCurrentOpenmrsDatabase) {
×
1382
                                                        setMessage("Create database");
×
1383
                                                        setExecutingTask(WizardTask.CREATE_SCHEMA);
×
1384
                                                        // connect via jdbc and create a database
1385
                                                        String sql;
1386
                                                        if (isCurrentDatabase(DATABASE_MYSQL)) {
×
1387
                                                                sql = "create database if not exists `?` default character set utf8";
×
1388
                                                        } else if (isCurrentDatabase(DATABASE_POSTGRESQL)) {
×
1389
                                                                sql = "create database `?` encoding 'utf8'";
×
1390
                                                        } else if (isCurrentDatabase(DATABASE_H2)) {
×
1391
                                                                sql = null;
×
1392
                                                        } else {
1393
                                                                sql = "create database `?`";
×
1394
                                                        }
1395
                                                        
1396
                                                        int result;
1397
                                                        if (sql != null) {
×
1398
                                                                result = executeStatement(false, wizardModel.createDatabaseUsername,
×
1399
                                                                        wizardModel.createDatabasePassword, sql, wizardModel.databaseName);
×
1400
                                                        } else {
1401
                                                                result = 1;
×
1402
                                                        }
1403
                                                        // throw the user back to the main screen if this error occurs
1404
                                                        if (result < 0) {
×
1405
                                                                reportError(ErrorMessageConstants.ERROR_DB_CREATE_NEW, DEFAULT_PAGE);
×
1406
                                                                return;
×
1407
                                                        } else {
1408
                                                                wizardModel.workLog.add("Created database " + wizardModel.databaseName);
×
1409
                                                        }
1410
                                                        
1411
                                                        addExecutedTask(WizardTask.CREATE_SCHEMA);
×
1412
                                                }
1413
                                                
1414
                                                if (wizardModel.createDatabaseUser) {
×
1415
                                                        setMessage("Create database user");
×
1416
                                                        setExecutingTask(WizardTask.CREATE_DB_USER);
×
1417
                                                        connectionUsername = wizardModel.databaseName + "_user";
×
1418
                                                        if (connectionUsername.length() > 16) {
×
1419
                                                                connectionUsername = wizardModel.databaseName.substring(0, 11)
×
1420
                                                                        + "_user"; // trim off enough to leave space for _user at the end
1421
                                                        }
1422
                                                        
1423
                                                        connectionPassword.append("");
×
1424
                                                        // generate random password from this subset of alphabet
1425
                                                        // intentionally left out these characters: ufsb$() to prevent certain words forming randomly
1426
                                                        String chars = "acdeghijklmnopqrtvwxyzACDEGHIJKLMNOPQRTVWXYZ0123456789.|~@#^&";
×
1427
                                                        Random r = new Random();
×
1428
                                                        StringBuilder randomStr = new StringBuilder("");
×
1429
                                                        for (int x = 0; x < 12; x++) {
×
1430
                                                                randomStr.append(chars.charAt(r.nextInt(chars.length())));
×
1431
                                                        }
1432
                                                        connectionPassword.append(randomStr);
×
1433
                                                        
1434
                                                        // connect via jdbc with root user and create an openmrs user
1435
                                                        String host = "'%'";
×
1436
                                                        if (wizardModel.databaseConnection.contains("localhost")
×
1437
                                                                || wizardModel.databaseConnection.contains("127.0.0.1")) {
×
1438
                                                                host = "'localhost'";
×
1439
                                                        }
1440
                                                        
1441
                                                        String sql = "";
×
1442
                                                        if (isCurrentDatabase(DATABASE_MYSQL)) {
×
1443
                                                                sql = "drop user '?'@" + host;
×
1444
                                                        } else if (isCurrentDatabase(DATABASE_POSTGRESQL)) {
×
1445
                                                                sql = "drop user `?`";
×
1446
                                                        }
1447
                                                        
1448
                                                        executeStatement(true, wizardModel.createUserUsername, wizardModel.createUserPassword, sql,
×
1449
                                                                connectionUsername);
1450
                                                        
1451
                                                        if (isCurrentDatabase(DATABASE_MYSQL)) {
×
1452
                                                                sql = "create user '?'@" + host + " identified by '?'";
×
1453
                                                        } else if (isCurrentDatabase(DATABASE_POSTGRESQL)) {
×
1454
                                                                sql = "create user `?` with password '?'";
×
1455
                                                        }
1456
                                                        
1457
                                                        if (-1 != executeStatement(false, wizardModel.createUserUsername, wizardModel.createUserPassword,
×
1458
                                                                sql, connectionUsername, connectionPassword.toString())) {
×
1459
                                                                wizardModel.workLog.add("Created user " + connectionUsername);
×
1460
                                                        } else {
1461
                                                                // if error occurs stop
1462
                                                                reportError(ErrorMessageConstants.ERROR_DB_CREATE_DB_USER, DEFAULT_PAGE);
×
1463
                                                                return;
×
1464
                                                        }
1465
                                                        
1466
                                                        // grant the roles
1467
                                                        int result = 1;
×
1468
                                                        if (isCurrentDatabase(DATABASE_MYSQL)) {
×
1469
                                                                sql = "GRANT ALL ON `?`.* TO '?'@" + host;
×
1470
                                                                result = executeStatement(false, wizardModel.createUserUsername,
×
1471
                                                                        wizardModel.createUserPassword, sql, wizardModel.databaseName, connectionUsername);
×
1472
                                                        } else if (isCurrentDatabase(DATABASE_POSTGRESQL)) {
×
1473
                                                                sql = "ALTER USER `?` WITH SUPERUSER";
×
1474
                                                                result = executeStatement(false, wizardModel.createUserUsername,
×
1475
                                                                        wizardModel.createUserPassword, sql, connectionUsername);
×
1476
                                                        }
1477
                                                        
1478
                                                        // throw the user back to the main screen if this error occurs
1479
                                                        if (result < 0) {
×
1480
                                                                reportError(ErrorMessageConstants.ERROR_DB_GRANT_PRIV, DEFAULT_PAGE);
×
1481
                                                                return;
×
1482
                                                        } else {
1483
                                                                wizardModel.workLog.add("Granted user " + connectionUsername + " all privileges to database "
×
1484
                                                                        + wizardModel.databaseName);
×
1485
                                                        }
1486
                                                        
1487
                                                        addExecutedTask(WizardTask.CREATE_DB_USER);
×
1488
                                                } else {
×
1489
                                                        connectionUsername = wizardModel.currentDatabaseUsername;
×
1490
                                                        connectionPassword.setLength(0);
×
1491
                                                        connectionPassword.append(wizardModel.currentDatabasePassword);
×
1492
                                                }
1493
                                                
1494
                                                String finalDatabaseConnectionString = wizardModel.databaseConnection.replace("@DBNAME@",
×
1495
                                                        wizardModel.databaseName);
×
1496
                                                
1497
                                                finalDatabaseConnectionString = finalDatabaseConnectionString.replace("@APPLICATIONDATADIR@",
×
1498
                                                        OpenmrsUtil.getApplicationDataDirectory().replace("\\", "/"));
×
1499
                                                
1500
                                                // verify that the database connection works
1501
                                                if (!verifyConnection(connectionUsername, connectionPassword.toString(),
×
1502
                                                        finalDatabaseConnectionString)) {
1503
                                                        setMessage("Verify that the database connection works");
×
1504
                                                        // redirect to setup page if we got an error
1505
                                                        reportError("Unable to connect to database", DEFAULT_PAGE);
×
1506
                                                        return;
×
1507
                                                }
1508
                                                
1509
                                                // save the properties for startup purposes
1510
                                                Properties runtimeProperties = new Properties();
×
1511
                                                
1512
                                                runtimeProperties.put("connection.url", finalDatabaseConnectionString);
×
1513
                                                runtimeProperties.put("connection.username", connectionUsername);
×
1514
                                                runtimeProperties.put("connection.password", connectionPassword.toString());
×
1515
                                                if (StringUtils.hasText(wizardModel.databaseDriver)) {
×
1516
                                                        runtimeProperties.put("connection.driver_class", wizardModel.databaseDriver);
×
1517
                                                }
1518
                                                if (finalDatabaseConnectionString.contains(DATABASE_POSTGRESQL)) {
×
1519
                                                        runtimeProperties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQL82Dialect");
×
1520
                                                }
1521
                                                if (finalDatabaseConnectionString.contains(DATABASE_SQLSERVER)) {
×
1522
                                                        runtimeProperties.put("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect");
×
1523
                                                }
1524
                                                if (finalDatabaseConnectionString.contains(DATABASE_H2)) {
×
1525
                                                        runtimeProperties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
×
1526
                                                }
1527
                                                runtimeProperties.put("module.allow_web_admin", wizardModel.moduleWebAdmin.toString());
×
1528
                                                runtimeProperties.put("auto_update_database", wizardModel.autoUpdateDatabase.toString());
×
1529
                                                final Encoder base64 = Base64.getEncoder();
×
1530
                                                runtimeProperties.put(OpenmrsConstants.ENCRYPTION_VECTOR_RUNTIME_PROPERTY,
×
1531
                                                        new String(base64.encode(Security.generateNewInitVector()), StandardCharsets.UTF_8));
×
1532
                                                runtimeProperties.put(OpenmrsConstants.ENCRYPTION_KEY_RUNTIME_PROPERTY,
×
1533
                                                        new String(base64.encode(Security.generateNewSecretKey()), StandardCharsets.UTF_8));
×
1534
                                                
1535
                                                Properties properties = Context.getRuntimeProperties();
×
1536
                                                properties.putAll(runtimeProperties);
×
1537
                                                runtimeProperties = properties;
×
1538
                                                Context.setRuntimeProperties(runtimeProperties);
×
1539
                                                
1540
                                                /**
1541
                                                 * A callback class that prints out info about liquibase changesets
1542
                                                 */
1543
                                                class PrintingChangeSetExecutorCallback implements ChangeSetExecutorCallback {
1544
                                                        
1545
                                                        private int i = 1;
×
1546
                                                        
1547
                                                        private String message;
1548
                                                        
1549
                                                        public PrintingChangeSetExecutorCallback(String message) {
×
1550
                                                                this.message = message;
×
1551
                                                        }
×
1552
                                                        
1553
                                                        /**
1554
                                                         * @see ChangeSetExecutorCallback#executing(liquibase.changelog.ChangeSet, int)
1555
                                                         */
1556
                                                        @Override
1557
                                                        public void executing(ChangeSet changeSet, int numChangeSetsToRun) {
1558
                                                                setMessage(message + " (" + i++ + "/" + numChangeSetsToRun + "): Author: "
×
1559
                                                                        + changeSet.getAuthor() + " Comments: " + changeSet.getComments() + " Description: "
×
1560
                                                                        + changeSet.getDescription());
×
1561
                                                                float numChangeSetsToRunFloat = (float) numChangeSetsToRun;
×
1562
                                                                float j = (float) i;
×
1563
                                                                setCompletedPercentage(Math.round(j * 100 / numChangeSetsToRunFloat));
×
1564
                                                        }
×
1565
                                                        
1566
                                                }
1567
                                                
1568
                                                if (wizardModel.createTables) {
×
1569
                                                        // use liquibase to create core data + tables
1570
                                                        try {
1571
                                                                String liquibaseSchemaFileName = changeLogVersionFinder.getLatestSchemaSnapshotFilename()
×
1572
                                                                        .get();
×
1573
                                                                String liquibaseCoreDataFileName = changeLogVersionFinder.getLatestCoreDataSnapshotFilename()
×
1574
                                                                        .get();
×
1575
                                                                
1576
                                                                setMessage("Executing " + liquibaseSchemaFileName);
×
1577
                                                                setExecutingTask(WizardTask.CREATE_TABLES);
×
1578
                                                                
1579
                                                                log.debug("executing Liquibase file '{}' ", liquibaseSchemaFileName);
×
1580
                                                                
1581
                                                                DatabaseUpdater.executeChangelog(liquibaseSchemaFileName,
×
1582
                                                                        new PrintingChangeSetExecutorCallback("OpenMRS schema file"));
1583
                                                                addExecutedTask(WizardTask.CREATE_TABLES);
×
1584
                                                                
1585
                                                                //reset for this task
1586
                                                                setCompletedPercentage(0);
×
1587
                                                                setExecutingTask(WizardTask.ADD_CORE_DATA);
×
1588
                                                                
1589
                                                                log.debug("executing Liquibase file '{}' ", liquibaseCoreDataFileName);
×
1590
                                                                
1591
                                                                DatabaseUpdater.executeChangelog(liquibaseCoreDataFileName,
×
1592
                                                                        new PrintingChangeSetExecutorCallback("OpenMRS core data file"));
1593
                                                                wizardModel.workLog.add("Created database tables and added core data");
×
1594
                                                                addExecutedTask(WizardTask.ADD_CORE_DATA);
×
1595
                                                                
1596
                                                        }
1597
                                                        catch (Exception e) {
×
1598
                                                                reportError(ErrorMessageConstants.ERROR_DB_CREATE_TABLES_OR_ADD_DEMO_DATA, DEFAULT_PAGE,
×
1599
                                                                        e.getMessage());
×
1600
                                                                log.warn("Error while trying to create tables and demo data", e);
×
1601
                                                        }
×
1602
                                                }
1603
                                                
1604
                                                if (wizardModel.importTestData) {
×
1605
                                                        try {
1606
                                                                setMessage("Importing test data");
×
1607
                                                                setExecutingTask(WizardTask.IMPORT_TEST_DATA);
×
1608
                                                                setCompletedPercentage(0);
×
1609
                                                                
1610
                                                                try {
1611
                                                                        InputStream inData = TestInstallUtil.getResourceInputStream(
×
1612
                                                                                wizardModel.remoteUrl + RELEASE_TESTING_MODULE_PATH + "generateTestDataSet.form",
×
1613
                                                                                wizardModel.remoteUsername, wizardModel.remotePassword);
×
1614
                                                                        
1615
                                                                        setCompletedPercentage(40);
×
1616
                                                                        setMessage("Loading imported test data...");
×
1617
                                                                        importTestDataSet(inData, finalDatabaseConnectionString, connectionUsername,
×
1618
                                                                                connectionPassword.toString());
×
1619
                                                                        wizardModel.workLog.add("Imported test data");
×
1620
                                                                        addExecutedTask(WizardTask.IMPORT_TEST_DATA);
×
1621
                                                                        
1622
                                                                        //reset the progress for the next task
1623
                                                                        setCompletedPercentage(0);
×
1624
                                                                        setMessage("Importing modules from remote server...");
×
1625
                                                                        setExecutingTask(WizardTask.ADD_MODULES);
×
1626
                                                                        
1627
                                                                        InputStream inModules = TestInstallUtil.getResourceInputStream(
×
1628
                                                                                wizardModel.remoteUrl + RELEASE_TESTING_MODULE_PATH + "getModules.htm",
×
1629
                                                                                wizardModel.remoteUsername, wizardModel.remotePassword);
×
1630
                                                                        
1631
                                                                        setCompletedPercentage(90);
×
1632
                                                                        setMessage("Adding imported modules...");
×
1633
                                                                        if (!TestInstallUtil.addZippedTestModules(inModules)) {
×
1634
                                                                                reportError(ErrorMessageConstants.ERROR_DB_UNABLE_TO_ADD_MODULES, DEFAULT_PAGE, "");
×
1635
                                                                                return;
×
1636
                                                                        } else {
1637
                                                                                wizardModel.workLog.add("Added Modules");
×
1638
                                                                                addExecutedTask(WizardTask.ADD_MODULES);
×
1639
                                                                        }
1640
                                                                }
1641
                                                                catch (APIAuthenticationException e) {
×
1642
                                                                        log.warn("Unable to authenticate as a User with the System Developer role");
×
1643
                                                                        reportError(ErrorMessageConstants.UPDATE_ERROR_UNABLE_AUTHENTICATE,
×
1644
                                                                                TESTING_REMOTE_DETAILS_SETUP, "");
1645
                                                                        return;
×
1646
                                                                }
×
1647
                                                        }
1648
                                                        catch (Exception e) {
×
1649
                                                                reportError(ErrorMessageConstants.ERROR_DB_IMPORT_TEST_DATA, DEFAULT_PAGE, e.getMessage());
×
1650
                                                                log.warn("Error while trying to import test data", e);
×
1651
                                                                return;
×
1652
                                                        }
×
1653
                                                }
1654
                                                
1655
                                                // add demo data only if creating tables fresh and user selected the option add demo data
1656
                                                if (wizardModel.createTables && wizardModel.addDemoData) {
×
1657
                                                        try {
1658
                                                                setMessage("Adding demo data");
×
1659
                                                                setCompletedPercentage(0);
×
1660
                                                                setExecutingTask(WizardTask.ADD_DEMO_DATA);
×
1661
                                                                
1662
                                                                log.debug("executing Liquibase file '{}' ", LIQUIBASE_DEMO_DATA);
×
1663
                                                                
1664
                                                                DatabaseUpdater.executeChangelog(LIQUIBASE_DEMO_DATA,
×
1665
                                                                        new PrintingChangeSetExecutorCallback("OpenMRS demo patients, users, and forms"));
1666
                                                                wizardModel.workLog.add("Added demo data");
×
1667
                                                                
1668
                                                                addExecutedTask(WizardTask.ADD_DEMO_DATA);
×
1669
                                                        }
1670
                                                        catch (Exception e) {
×
1671
                                                                reportError(ErrorMessageConstants.ERROR_DB_CREATE_TABLES_OR_ADD_DEMO_DATA, DEFAULT_PAGE,
×
1672
                                                                        e.getMessage());
×
1673
                                                                log.warn("Error while trying to add demo data", e);
×
1674
                                                        }
×
1675
                                                }
1676
                                                
1677
                                                // update the database to the latest version
1678
                                                try {
1679
                                                        setMessage("Updating the database to the latest version");
×
1680
                                                        setCompletedPercentage(0);
×
1681
                                                        setExecutingTask(WizardTask.UPDATE_TO_LATEST);
×
1682
                                                        
1683
                                                        String version = null;
×
1684
                                                        
1685
                                                        if (wizardModel.createTables) {
×
1686
                                                                version = changeLogVersionFinder.getLatestSnapshotVersion().get();
×
1687
                                                        } else {
1688
                                                                version = changeLogDetective.getInitialLiquibaseSnapshotVersion(DatabaseUpdater.CONTEXT,
×
1689
                                                                        new DatabaseUpdaterLiquibaseProvider());
1690
                                                        }
1691
                                                        
1692
                                                        log.debug(
×
1693
                                                                "updating the database with versions of liquibase-update-to-latest files greater than '{}'",
1694
                                                                version);
1695
                                                        
1696
                                                        List<String> changelogs = changeLogVersionFinder
×
1697
                                                                .getUpdateFileNames(changeLogVersionFinder.getUpdateVersionsGreaterThan(version));
×
1698
                                                        
1699
                                                        for (String changelog : changelogs) {
×
1700
                                                                log.debug("applying Liquibase changelog '{}'", changelog);
×
1701
                                                                
1702
                                                                DatabaseUpdater.executeChangelog(changelog,
×
1703
                                                                        new PrintingChangeSetExecutorCallback("executing Liquibase changelog " + changelog));
1704
                                                        }
×
1705
                                                        addExecutedTask(WizardTask.UPDATE_TO_LATEST);
×
1706
                                                }
1707
                                                catch (Exception e) {
×
1708
                                                        reportError(ErrorMessageConstants.ERROR_DB_UPDATE_TO_LATEST, DEFAULT_PAGE, e.getMessage());
×
1709
                                                        log.warn("Error while trying to update to the latest database version", e);
×
1710
                                                        return;
×
1711
                                                }
×
1712
                                                
1713
                                                setExecutingTask(null);
×
1714
                                                setMessage("Starting OpenMRS");
×
1715
                                                
1716
                                                // start spring
1717
                                                // after this point, all errors need to also call: contextLoader.closeWebApplicationContext(event.getServletContext())
1718
                                                // logic copied from org.springframework.web.context.ContextLoaderListener
1719
                                                ContextLoader contextLoader = new ContextLoader();
×
1720
                                                contextLoader.initWebApplicationContext(filterConfig.getServletContext());
×
1721
                                                
1722
                                                // output properties to the openmrs runtime properties file so that this wizard is not run again
1723
                                                FileOutputStream fos = null;
×
1724
                                                try {
1725
                                                        fos = new FileOutputStream(getRuntimePropertiesFile());
×
1726
                                                        OpenmrsUtil.storeProperties(runtimeProperties, fos,
×
1727
                                                                "Auto generated by OpenMRS initialization wizard");
1728
                                                        wizardModel.workLog.add("Saved runtime properties file " + getRuntimePropertiesFile());
×
1729
                                                        
1730
                                                        /*
1731
                                                         * Fix file readability permissions:
1732
                                                         * first revoke read permission from everyone, then set read permissions for only the user
1733
                                                         * there is no function to set specific readability for only one user
1734
                                                         * and revoke everyone else's, therefore this is the only way to accomplish this.
1735
                                                         */
1736
                                                        wizardModel.workLog.add("Adjusting file posix properties to user readonly");
×
1737
                                                        if (getRuntimePropertiesFile().setReadable(false, false)
×
1738
                                                                && getRuntimePropertiesFile().setReadable(true)) {
×
1739
                                                                wizardModel.workLog
×
1740
                                                                        .add("Successfully adjusted RuntimePropertiesFile to disallow world to read it");
×
1741
                                                        } else {
1742
                                                                wizardModel.workLog
×
1743
                                                                        .add("Unable to adjust RuntimePropertiesFile to disallow world to read it");
×
1744
                                                        }
1745
                                                        // don't need to catch errors here because we tested it at the beginning of the wizard
1746
                                                }
1747
                                                finally {
1748
                                                        if (fos != null) {
×
1749
                                                                fos.close();
×
1750
                                                        }
1751
                                                }
1752
                                                
1753
                                                Context.openSession();
×
1754
                                                
1755
                                                if (!"".equals(wizardModel.implementationId)) {
×
1756
                                                        try {
1757
                                                                Context.addProxyPrivilege(PrivilegeConstants.MANAGE_GLOBAL_PROPERTIES);
×
1758
                                                                Context.addProxyPrivilege(PrivilegeConstants.MANAGE_CONCEPT_SOURCES);
×
1759
                                                                Context.addProxyPrivilege(PrivilegeConstants.GET_CONCEPT_SOURCES);
×
1760
                                                                Context.addProxyPrivilege(PrivilegeConstants.MANAGE_IMPLEMENTATION_ID);
×
1761
                                                                
1762
                                                                ImplementationId implId = new ImplementationId();
×
1763
                                                                implId.setName(wizardModel.implementationIdName);
×
1764
                                                                implId.setImplementationId(wizardModel.implementationId);
×
1765
                                                                implId.setPassphrase(wizardModel.implementationIdPassPhrase);
×
1766
                                                                implId.setDescription(wizardModel.implementationIdDescription);
×
1767
                                                                
1768
                                                                Context.getAdministrationService().setImplementationId(implId);
×
1769
                                                        }
1770
                                                        catch (Exception e) {
×
1771
                                                                reportError(ErrorMessageConstants.ERROR_SET_INPL_ID, DEFAULT_PAGE, e.getMessage());
×
1772
                                                                log.warn("Implementation ID could not be set.", e);
×
1773
                                                                Context.shutdown();
×
1774
                                                                WebModuleUtil.shutdownModules(filterConfig.getServletContext());
×
1775
                                                                contextLoader.closeWebApplicationContext(filterConfig.getServletContext());
×
1776
                                                                return;
×
1777
                                                        }
1778
                                                        finally {
1779
                                                                Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_GLOBAL_PROPERTIES);
×
1780
                                                                Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_CONCEPT_SOURCES);
×
1781
                                                                Context.removeProxyPrivilege(PrivilegeConstants.GET_CONCEPT_SOURCES);
×
1782
                                                                Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_IMPLEMENTATION_ID);
×
1783
                                                        }
1784
                                                }
1785
                                                
1786
                                                try {
1787
                                                        // change the admin user password from "test" to what they input above
1788
                                                        if (wizardModel.createTables) {
×
1789
                                                                try {
1790
                                                                        Context.authenticate(new UsernamePasswordCredentials("admin", "test"));
×
1791
                                                                        
1792
                                                                        Properties props = Context.getRuntimeProperties();
×
1793
                                                                        String initValue = props.getProperty(UserService.ADMIN_PASSWORD_LOCKED_PROPERTY);
×
1794
                                                                        props.setProperty(UserService.ADMIN_PASSWORD_LOCKED_PROPERTY, "false");
×
1795
                                                                        Context.setRuntimeProperties(props);
×
1796
                                                                        
1797
                                                                        Context.getUserService().changePassword("test", wizardModel.adminUserPassword);
×
1798
                                                                        
1799
                                                                        if (initValue == null) {
×
1800
                                                                                props.remove(UserService.ADMIN_PASSWORD_LOCKED_PROPERTY);
×
1801
                                                                        } else {
1802
                                                                                props.setProperty(UserService.ADMIN_PASSWORD_LOCKED_PROPERTY, initValue);
×
1803
                                                                        }
1804
                                                                        Context.setRuntimeProperties(props);
×
1805
                                                                        Context.logout();
×
1806
                                                                }
1807
                                                                catch (ContextAuthenticationException ex) {
×
1808
                                                                        log.info("No need to change admin password.", ex);
×
1809
                                                                }
×
1810
                                                        }
1811
                                                }
1812
                                                catch (Exception e) {
×
1813
                                                        Context.shutdown();
×
1814
                                                        WebModuleUtil.shutdownModules(filterConfig.getServletContext());
×
1815
                                                        contextLoader.closeWebApplicationContext(filterConfig.getServletContext());
×
1816
                                                        reportError(ErrorMessageConstants.ERROR_COMPLETE_STARTUP, DEFAULT_PAGE, e.getMessage());
×
1817
                                                        log.warn("Unable to complete the startup.", e);
×
1818
                                                        return;
×
1819
                                                }
×
1820
                                                
1821
                                                try {
1822
                                                        // Update PostgreSQL Sequences after insertion of core data
1823
                                                        Context.getAdministrationService().updatePostgresSequence();
×
1824
                                                }
1825
                                                catch (Exception e) {
×
1826
                                                        log.warn("Not able to update PostgreSQL sequence. Startup failed for PostgreSQL", e);
×
1827
                                                        reportError(ErrorMessageConstants.ERROR_COMPLETE_STARTUP, DEFAULT_PAGE, e.getMessage());
×
1828
                                                        return;
×
1829
                                                }
×
1830
                                                
1831
                                                // set this so that the wizard isn't run again on next page load
1832
                                                Context.closeSession();
×
1833
                                                
1834
                                                // start openmrs
1835
                                                try {
1836
                                                        UpdateFilter.setUpdatesRequired(false);
×
1837
                                                        WebDaemon.startOpenmrs(filterConfig.getServletContext());
×
1838
                                                }
1839
                                                catch (DatabaseUpdateException updateEx) {
×
1840
                                                        log.warn("Error while running the database update file", updateEx);
×
1841
                                                        reportError(ErrorMessageConstants.ERROR_DB_UPDATE, DEFAULT_PAGE, updateEx.getMessage());
×
1842
                                                        return;
×
1843
                                                }
1844
                                                catch (InputRequiredException inputRequiredEx) {
×
1845
                                                        // TODO display a page looping over the required input and ask the user for each.
1846
                                                        //                 When done and the user and put in their say, call DatabaseUpdater.update(Map);
1847
                                                        //                with the user's question/answer pairs
1848
                                                        log.warn(
×
1849
                                                                "Unable to continue because user input is required for the db updates and we cannot do anything about that right now");
1850
                                                        reportError(ErrorMessageConstants.ERROR_INPUT_REQ, DEFAULT_PAGE);
×
1851
                                                        return;
×
1852
                                                }
1853
                                                catch (MandatoryModuleException mandatoryModEx) {
×
1854
                                                        log.warn(
×
1855
                                                                "A mandatory module failed to start. Fix the error or unmark it as mandatory to continue.",
1856
                                                                mandatoryModEx);
1857
                                                        reportError(ErrorMessageConstants.ERROR_MANDATORY_MOD_REQ, DEFAULT_PAGE,
×
1858
                                                                mandatoryModEx.getMessage());
×
1859
                                                        return;
×
UNCOV
1860
                                                }
×
1861
                                                
1862
                                                // TODO catch openmrs errors here and drop the user back out to the setup screen
1863
                                                
1864
                                        }
1865
                                        catch (IOException e) {
×
1866
                                                reportError(ErrorMessageConstants.ERROR_COMPLETE_STARTUP, DEFAULT_PAGE, e.getMessage());
×
1867
                                        }
1868
                                        finally {
1869
                                                if (!hasErrors()) {
×
1870
                                                        // set this so that the wizard isn't run again on next page load
1871
                                                        setInitializationComplete(true);
×
1872
                                                        // we should also try to store selected by user language
1873
                                                        // if user wants to system will do it for him 
1874
                                                        FilterUtil.storeLocale(wizardModel.localeToSave);
×
1875
                                                }
1876
                                                setInstallationStarted(false);
×
1877
                                        }
1878
                                }
×
1879
                        };
1880
                        
1881
                        future = OpenmrsThreadPoolHolder.threadExecutor.submit(() -> { r.run(); return null; });
×
1882
                }
×
1883
        }
1884
        
1885
        /**
1886
         * Convenience method that loads the database driver
1887
         *
1888
         * @param connection the database connection string
1889
         * @param databaseDriver the database driver class name to load
1890
         * @return the loaded driver string
1891
         */
1892
        public static String loadDriver(String connection, String databaseDriver) {
1893
                String loadedDriverString = null;
×
1894
                try {
1895
                        loadedDriverString = DatabaseUtil.loadDatabaseDriver(connection, databaseDriver);
×
1896
                        log.info("using database driver :" + loadedDriverString);
×
1897
                }
1898
                catch (ClassNotFoundException e) {
×
1899
                        log.error("The given database driver class was not found. "
×
1900
                                + "Please ensure that the database driver jar file is on the class path "
1901
                                + "(like in the webapp's lib folder)");
1902
                }
×
1903
                
1904
                return loadedDriverString;
×
1905
        }
1906
        
1907
        /**
1908
         * Utility method that checks if there is a runtime properties file containing database connection
1909
         * credentials
1910
         *
1911
         * @return
1912
         */
1913
        private static boolean skipDatabaseSetupPage() {
1914
                Properties props = OpenmrsUtil.getRuntimeProperties(WebConstants.WEBAPP_NAME);
×
1915
                return (props != null && StringUtils.hasText(props.getProperty("connection.url"))
×
1916
                        && StringUtils.hasText(props.getProperty("connection.username"))
×
1917
                        && StringUtils.hasText(props.getProperty("connection.password")));
×
1918
        }
1919
        
1920
        /**
1921
         * Utility methods that checks if the user clicked the back image
1922
         *
1923
         * @param httpRequest
1924
         * @return
1925
         */
1926
        private static boolean goBack(HttpServletRequest httpRequest) {
1927
                return "Back".equals(httpRequest.getParameter("back"))
×
1928
                        || (httpRequest.getParameter("back.x") != null && httpRequest.getParameter("back.y") != null);
×
1929
        }
1930
        
1931
        /**
1932
         * Convenience method to get custom installation script
1933
         *
1934
         * @return Properties from custom installation script or empty if none specified
1935
         * @throws RuntimeException if path to installation script is invalid
1936
         */
1937
        private Properties getInstallationScript() {
1938
                Properties prop = new Properties();
×
1939
                
1940
                String fileName = System.getProperty("OPENMRS_INSTALLATION_SCRIPT");
×
1941
                if (fileName == null) {
×
1942
                        return prop;
×
1943
                }
1944
                if (fileName.startsWith("classpath:")) {
×
1945
                        fileName = fileName.substring(10);
×
1946
                        InputStream input = null;
×
1947
                        try {
1948
                                input = getClass().getClassLoader().getResourceAsStream(fileName);
×
1949
                                prop.load(input);
×
1950
                                log.info("Using installation script from classpath: " + fileName);
×
1951
                                
1952
                                input.close();
×
1953
                        }
1954
                        catch (IOException ex) {
×
1955
                                log.error("Failed to load installation script from classpath: " + fileName, ex);
×
1956
                                throw new RuntimeException(ex);
×
1957
                        }
1958
                        finally {
1959
                                IOUtils.closeQuietly(input);
×
1960
                        }
1961
                } else {
×
1962
                        File file = new File(fileName);
×
1963
                        if (file.exists()) {
×
1964
                                InputStream input = null;
×
1965
                                try {
1966
                                        input = new FileInputStream(fileName);
×
1967
                                        prop.load(input);
×
1968
                                        log.info("Using installation script from absolute path: " + file.getAbsolutePath());
×
1969
                                        
1970
                                        input.close();
×
1971
                                }
1972
                                catch (IOException ex) {
×
1973
                                        log.error("Failed to load installation script from absolute path: " + file.getAbsolutePath(), ex);
×
1974
                                        throw new RuntimeException(ex);
×
1975
                                }
1976
                                finally {
1977
                                        IOUtils.closeQuietly(input);
×
1978
                                }
1979
                        }
1980
                }
1981
                return prop;
×
1982
        }
1983
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc