1 package org.splat.simer;
5 import javax.servlet.http.HttpServletRequest;
7 import org.apache.struts2.interceptor.ServletRequestAware;
8 import org.hibernate.HibernateException;
9 import org.hibernate.Session;
10 import org.hibernate.Transaction;
11 import org.splat.som.ApplicationRights;
12 import org.splat.dal.dao.som.Database;
13 import org.splat.service.technical.ProjectSettingsService;
17 public class StartAction extends Action implements ServletRequestAware {
19 private HttpServletRequest request = null;
21 private ProjectSettingsService _projectSettingsService;
22 private ApplicationSettings _ApplicationSettings;
26 private static final long serialVersionUID = 5875058140682652964L;
28 // ==============================================================================================================================
30 // ==============================================================================================================================
32 public String doInitialize () throws Exception {
33 // -----------------------------
34 Session connex = Database.getSession();
35 Transaction transax = connex.beginTransaction();
36 StringBuffer wappurl = request.getRequestURL(); // "http://{server}:{port}/{webapp}/", including the leading '/'
38 logger.info( new StringBuffer("Initializing ").append(wappurl).append("...").toString() );
40 ProjectSettingsService project = getProjectSettings();
41 ApplicationSettings wapp = getApplicationSettings().init(wappurl.toString(), this.getLocale());
42 String root = wapp.getApplicationRootPath();
44 // Database configuration
45 project.configure(root + wapp.getApplicationProperty("wapp.configuration"));
47 // Application configuration
48 System.setProperty("java.security.auth.login.config", root + wapp.getApplicationProperty("wapp.login"));
49 wapp.configure(root + wapp.getApplicationProperty("wapp.customization"));
51 // Initialization of the user session
52 Map<String, Object> session = getSession();
54 session.put("user.rights", new ApplicationRights(null) ); // No user connected yet
55 session.put("study.filter", wapp.getFilter("study"));
56 session.put("knowledge.filter", wapp.getFilter("knowledge"));
61 catch (Exception error) {
62 logger.fatal("Reason:", error);
63 if (transax != null && transax.isActive()) {
64 // Second try-catch as the rollback could fail as well
67 } catch (HibernateException backerror) {
68 logger.debug("Error rolling back transaction", backerror);
75 // ==============================================================================================================================
77 // ==============================================================================================================================
79 public void setServletRequest (HttpServletRequest request) {
80 // ----------------------------------------------------------
81 this.request = request;
84 * Get project settings.
85 * @return Project settings service
87 private ProjectSettingsService getProjectSettings() {
88 return _projectSettingsService;
92 * Set project settings service.
93 * @param projectSettingsService project settings service
95 public void setProjectSettings(
96 ProjectSettingsService projectSettingsService) {
97 _projectSettingsService = projectSettingsService;
101 * Get the applicationSettings.
102 * @return the applicationSettings
104 public ApplicationSettings getApplicationSettings() {
105 return _ApplicationSettings;
109 * Set the applicationSettings.
110 * @param applicationSettings the applicationSettings to set
112 public void setApplicationSettings(ApplicationSettings applicationSettings) {
113 _ApplicationSettings = applicationSettings;