Clover Coverage Report - itracker
Coverage timestamp: Tue May 1 2012 16:42:12 CEST
23   118   7   7.67
2   54   0.3   3
3     2.33  
1    
 
 
  ApplicationInitialization       Line # 51 23 7 0% 0.0
 
No Tests
 
1    /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10    * the Free Software Foundation; either version 2 of the License, or
11    * (at your option) any later version.
12    *
13    * This program is distributed in the hope that it will be useful,
14    * but WITHOUT ANY WARRANTY; without even the implied warranty of
15    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16    * GNU General Public License for more details.
17    */
18   
19    package org.itracker.core;
20   
21    import org.apache.log4j.Logger;
22    import org.itracker.core.resources.ITrackerResources;
23    import org.itracker.model.User;
24    import org.itracker.persistence.dao.NoSuchEntityException;
25    import org.itracker.services.ConfigurationService;
26    import org.itracker.services.ReportService;
27    import org.itracker.services.UserService;
28    import org.itracker.services.exceptions.PasswordException;
29    import org.itracker.services.exceptions.UserException;
30    import org.itracker.services.util.SystemConfigurationUtilities;
31    import org.itracker.services.util.UserUtilities;
32   
33    import javax.jws.soap.InitParam;
34   
35   
36    /**
37    * TODO: Add Javadocs here: please comment this for documentation reasons. What is this Class used for?
38    *
39    * It seems like this gets started when the application starts up...
40    *
41    * What's the general idea?
42    *
43    * Why is processAttachmentFiles commented and therefore not used currently?
44    * Where does itracker store its attachments?
45    * What's the idea behind the attachment_dir ?
46    *
47    * @author ready
48    *
49    */
50   
 
51    public class ApplicationInitialization {
52   
53    private final Logger logger;
54    private UserService userService;
55    private ConfigurationService configurationService;
56   
 
57  0 toggle public ApplicationInitialization(UserService userService, ConfigurationService configurationService, ReportService reportService) {
58  0 this.userService = userService;
59  0 this.configurationService = configurationService;
60  0 this.logger = Logger.getLogger(getClass());
61    }
62   
 
63  0 toggle public void init() {
64  0 try {
65  0 ITrackerResources.setDefaultLocale(configurationService.getProperty("default_locale", ITrackerResources.DEFAULT_LOCALE));
66  0 logger.info("Set system default locale to '" + ITrackerResources.getDefaultLocale() + "'");
67   
68  0 logger.info("Checking and initializing languages in the database.");
69  0 SystemConfigurationUtilities.initializeAllLanguages(configurationService, false);
70   
71  0 logger.info("Checking and initializing default system configuration in the database.");
72  0 configurationService.initializeConfiguration();
73   
74    // logger.info("Checking for issue attachment files.");
75    // processAttachmentFiles(configurationService.getProperty("attachment_dir", IssueAttachmentUtilities.DEFAULT_ATTACHMENT_DIR));
76   
77  0 logger.info("Setting up cached configuration entries");
78  0 configurationService.resetConfigurationCache();
79   
80    // Preinitialize all of the PDF fonts available. Do it in a
81    // separate thread to speed up the rest of the startup.
82    // TODO: I think this should be removed... why do we need to pre-init ? (rjst)
83    // old code to pre-init fonts for jfree reports. make sure we can delete it
84    // BaseFontFactory fontFactory = BaseFontFactory.getFontFactory();
85    // fontFactory.registerDefaultFontPath();
86   
87    // check for and create admin user, if so configured
88  0 createAdminUser(configurationService);
89    } catch (PasswordException pe) {
90  0 logger.info("Unable to create admin user. Error: " + pe.getMessage());
91    } catch (UserException ue) {
92  0 logger.warn("Exception while creating admin user.", ue);
93    }
94    }
95   
96    /**
97    * Check if we should create the admin user, if so, do it.
98    *
99    * @param configurationService
100    * @throws PasswordException
101    * @throws UserException
102    */
 
103  0 toggle private void createAdminUser(ConfigurationService configurationService) throws PasswordException, UserException {
104  0 boolean createAdmin = configurationService.getBooleanProperty("create_super_user", false);
105  0 if (createAdmin) {
106  0 logger.info("Create default admin user option set to true. Checking for existing admin user.");
107  0 try {
108  0 userService.getUserByLogin("admin");
109    } catch (NoSuchEntityException e) {
110  0 logger.debug("Attempting to create admin user.");
111  0 User adminUser = new User("admin", UserUtilities.encryptPassword("admin"), "Super", "User",
112    "", true);
113  0 userService.createUser(adminUser);
114    }
115    }
116    }
117   
118    }