001 package org.hackystat.projectbrowser; 002 003 import java.util.Properties; 004 import java.util.logging.Logger; 005 006 import org.apache.wicket.Page; 007 import org.apache.wicket.Request; 008 import org.apache.wicket.Response; 009 import org.apache.wicket.Session; 010 import org.apache.wicket.protocol.http.WebApplication; 011 import org.apache.wicket.request.target.coding.IndexedParamUrlCodingStrategy; 012 import org.hackystat.projectbrowser.authentication.SigninPage; 013 import org.hackystat.projectbrowser.page.ProjectBrowserPageAuthentication; 014 import org.hackystat.projectbrowser.page.crap.CrapPage; 015 import org.hackystat.projectbrowser.page.dailyprojectdata.DailyProjectDataPage; 016 import org.hackystat.projectbrowser.page.projectportfolio.ProjectPortfolioPage; 017 import org.hackystat.projectbrowser.page.projects.ProjectsPage; 018 import org.hackystat.projectbrowser.page.sensordata.SensorDataPage; 019 import org.hackystat.projectbrowser.page.telemetry.TelemetryPage; 020 import org.hackystat.projectbrowser.page.trajectory.TrajectoryPage; 021 import org.hackystat.projectbrowser.page.trajectory.dtwpanel.TrajectoryDTWPage; 022 import org.hackystat.utilities.logger.HackystatLogger; 023 024 /** 025 * The top-level web application instance for this ProjectBrowser. 026 * @author Philip Johnson 027 */ 028 public class ProjectBrowserApplication extends WebApplication { 029 030 /** 031 * Project properties are read from ~/.hackystat/projectbrowser/projectbrowser.properties, 032 * however some of those values (i.e. the locations of the hackystat services) can be 033 * overridden for testing purposes. 034 */ 035 private ProjectBrowserProperties properties; 036 037 /** Holds the HackystatLogger for this Service. */ 038 private Logger logger; 039 040 /** 041 * Creates a ProjectBrowserApplication, obtaining all ProjectBrowserProperties 042 * from the properties file. 043 */ 044 public ProjectBrowserApplication() { 045 this(null); 046 } 047 048 /** 049 * Creates a ProjectBrowserApplication, in which the passed properties override the entries 050 * in the properties file. 051 * @param properties A properties instance, the contents of which will override any other 052 * property settings. 053 */ 054 public ProjectBrowserApplication(Properties properties) { 055 this.logger = HackystatLogger.getLogger("org.hackystat.projectbrowser", "projectbrowser"); 056 this.properties = new ProjectBrowserProperties(properties); 057 this.logger.info(this.properties.echoProperties()); 058 } 059 060 061 /** 062 * Returns the home page for this application (SigninPage). 063 * @return The home page. 064 */ 065 @Override 066 public Class<? extends Page> getHomePage() { 067 return SigninPage.class; 068 } 069 070 071 /** 072 * Defines ProjectBrowserSession as the session instance created in this app. 073 * @param request The request. 074 * @param response The response. 075 * @return The current ProjectBrowserSession instance. 076 */ 077 @Override 078 public Session newSession(Request request, Response response) { 079 return new ProjectBrowserSession(request); 080 } 081 082 /** 083 * Do default setup and initialization when this web application is started up. 084 */ 085 @Override 086 public void init() { 087 if (isPageAvailable("sensordata")) { 088 mountBookmarkablePage("sensordata", SensorDataPage.class); 089 } 090 if (isPageAvailable("projects")) { 091 mountBookmarkablePage("projects", ProjectsPage.class); 092 } 093 if (isPageAvailable("dailyprojectdata")) { 094 mount(new IndexedParamUrlCodingStrategy("dailyprojectdata", DailyProjectDataPage.class)); 095 } 096 if (isPageAvailable("telemetry")) { 097 mount(new IndexedParamUrlCodingStrategy("telemetry", TelemetryPage.class)); 098 } 099 if (isPageAvailable("trajectory")) { 100 mountBookmarkablePage("trajectory", TrajectoryPage.class); 101 mountBookmarkablePage("dtw", TrajectoryDTWPage.class); 102 } 103 if (isPageAvailable("projectportfolio")) { 104 mount(new IndexedParamUrlCodingStrategy("projectportfolio", ProjectPortfolioPage.class)); 105 } 106 if (isPageAvailable("crap")) { 107 mountBookmarkablePage("crap", CrapPage.class); 108 } 109 getSecuritySettings().setAuthorizationStrategy(new ProjectBrowserPageAuthentication()); 110 super.init(); 111 112 } 113 114 /** 115 * @param pageName name of the page. 116 * @return true if the user set the page as available. 117 */ 118 public boolean isPageAvailable (String pageName) { 119 return properties.isPageAvailable(pageName); 120 } 121 122 /** 123 * Return the directroy of portfolio definition xmls. 124 * @return the file path. 125 */ 126 public String getPortfolioDefinitionDir() { 127 return properties.getPortfolioDefinitionDir(); 128 } 129 130 /** 131 * @param pageName name of the page. 132 * @return true if the user set the background process of the page enable. 133 */ 134 public boolean isBackgroundProcessEnable (String pageName) { 135 return properties.isBackgroundProcessEnable(pageName); 136 } 137 138 /** 139 * Returns the ProjectBrowserProperties instance associated with this web app. 140 * @return The properties. 141 */ 142 public ProjectBrowserProperties getProjectBrowserProperties() { 143 return this.properties; 144 } 145 146 /** 147 * Returns the value associated with key, or null if not found. Key should be one of the public 148 * static strings declared in ProjectBrowserProperties. 149 * @param key The key. 150 * @return The value associated with this key, or null if not found. 151 */ 152 public String getProjectBrowserProperty(String key) { 153 return this.properties.get(key); 154 } 155 156 /** 157 * Returns the logger for this service. 158 * @return The logger. 159 */ 160 public Logger getLogger() { 161 return this.logger; 162 } 163 164 /** 165 * Returns the DPD host. 166 * @return The DPD host. 167 */ 168 public String getDailyProjectDataHost() { 169 return getProjectBrowserProperty(ProjectBrowserProperties.DAILYPROJECTDATA_HOST_KEY); 170 } 171 172 /** 173 * Returns the sensorbase host. 174 * @return The sensorbase host. 175 */ 176 public String getSensorBaseHost() { 177 return getProjectBrowserProperty(ProjectBrowserProperties.SENSORBASE_HOST_KEY); 178 } 179 180 /** 181 * Returns the telemetry host. 182 * @return The telemetry host. 183 */ 184 public String getTelemetryHost() { 185 return getProjectBrowserProperty(ProjectBrowserProperties.TELEMETRY_HOST_KEY); 186 } 187 188 /** 189 * Returns the application name. 190 * @return The application name. 191 */ 192 public String getApplicationName() { 193 return getProjectBrowserProperty(ProjectBrowserProperties.APPLICATION_NAME_KEY); 194 } 195 196 /** 197 * Returns the application logo. 198 * @return The application logo. 199 */ 200 public String getApplicationLogo() { 201 return getProjectBrowserProperty(ProjectBrowserProperties.APPLICATION_LOGO_KEY); 202 } 203 204 /** 205 * Returns true if the user has supplied an application logo. 206 * @return True if application logo exists. 207 */ 208 public boolean hasApplicationLogo() { 209 return this.properties.hasApplicationLogo(); 210 } 211 212 /** 213 * @return true if the user set to enable usage logging 214 */ 215 public boolean isLoggingUserUsage() { 216 return this.properties.isLoggingUserUsage(); 217 } 218 }