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;
16 public class StartAction extends Action implements ServletRequestAware {
18 private HttpServletRequest request = null;
20 private ProjectSettingsService _projectSettingsService;
21 private ApplicationSettings _ApplicationSettings;
23 private static final long serialVersionUID = 5875058140682652964L;
25 // ==============================================================================================================================
27 // ==============================================================================================================================
29 public String doInitialize () throws Exception {
30 // -----------------------------
31 Session connex = Database.getSession();
32 Transaction transax = connex.beginTransaction();
33 StringBuffer wappurl = request.getRequestURL(); // "http://{server}:{port}/{webapp}/", including the leading '/'
35 logger.info( new StringBuffer("Initializing ").append(wappurl).append("...").toString() );
37 ProjectSettingsService project = getProjectSettings();
38 ApplicationSettings wapp = getApplicationSettings().init(wappurl.toString(), this.getLocale());
39 String root = wapp.getApplicationRootPath();
41 // Database configuration
42 project.configure(root + wapp.getApplicationProperty("wapp.configuration"));
44 // Application configuration
45 System.setProperty("java.security.auth.login.config", root + wapp.getApplicationProperty("wapp.login"));
46 wapp.configure(root + wapp.getApplicationProperty("wapp.customization"));
48 // Initialization of the user session
49 Map<String, Object> session = getSession();
51 session.put("user.rights", new ApplicationRights(null) ); // No user connected yet
52 session.put("study.filter", wapp.getFilter("study"));
53 session.put("knowledge.filter", wapp.getFilter("knowledge"));
58 catch (Exception error) {
59 logger.fatal("Reason:", error);
60 if (transax != null && transax.isActive()) {
61 // Second try-catch as the rollback could fail as well
64 } catch (HibernateException backerror) {
65 logger.debug("Error rolling back transaction", backerror);
72 // ==============================================================================================================================
74 // ==============================================================================================================================
76 public void setServletRequest (HttpServletRequest request) {
77 // ----------------------------------------------------------
78 this.request = request;
81 * Get project settings.
82 * @return Project settings service
84 private ProjectSettingsService getProjectSettings() {
85 return _projectSettingsService;
89 * Set project settings service.
90 * @param projectSettingsService project settings service
92 public void setProjectSettings(
93 ProjectSettingsService projectSettingsService) {
94 _projectSettingsService = projectSettingsService;
98 * Get the applicationSettings.
99 * @return the applicationSettings
101 public ApplicationSettings getApplicationSettings() {
102 return _ApplicationSettings;
106 * Set the applicationSettings.
107 * @param applicationSettings the applicationSettings to set
109 public void setApplicationSettings(ApplicationSettings applicationSettings) {
110 _ApplicationSettings = applicationSettings;