]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/StartAction.java
Salome HOME
90665711b77651f06d5f7fdff40afebcf018885a
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / StartAction.java
1 package org.splat.simer;
2
3 import java.util.Map;
4
5 import javax.servlet.http.HttpServletRequest;
6
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;
14
15
16
17 public class StartAction extends Action implements ServletRequestAware {
18
19     private HttpServletRequest  request = null;
20
21         private ProjectSettingsService _projectSettingsService;
22         private ApplicationSettings _ApplicationSettings;
23         private static final long   serialVersionUID = 5875058140682652964L;
24
25 //  ==============================================================================================================================
26 //  Action execution
27 //  ==============================================================================================================================
28
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 '/'
34
35       logger.info( new StringBuffer("Initializing ").append(wappurl).append("...").toString() );
36           try {
37                 ProjectSettingsService project = getProjectSettings();
38         ApplicationSettings wapp    = getApplicationSettings().init(wappurl.toString(), this.getLocale());
39         String              root    = wapp.getApplicationRootPath();
40
41 //      Database configuration
42                 project.configure(root + wapp.getApplicationProperty("wapp.configuration"));
43
44 //      Application configuration
45             System.setProperty("java.security.auth.login.config", root + wapp.getApplicationProperty("wapp.login"));        
46             wapp.configure(root + wapp.getApplicationProperty("wapp.customization"));
47
48 //      Initialization of the user session
49                 Map<String, Object> session = getSession();
50
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"));
54
55             transax.commit();
56             return SUCCESS;
57       }
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
62           try {
63             transax.rollback();
64           } catch (HibernateException backerror) {
65             logger.debug("Error rolling back transaction", backerror);
66           }
67         }
68         return ERROR;
69       }
70         }
71
72 //  ==============================================================================================================================
73 //  Setter
74 //  ==============================================================================================================================
75
76         public void setServletRequest (HttpServletRequest request) {
77 //  ----------------------------------------------------------
78       this.request = request;
79         }
80     /**
81      * Get project settings.
82          * @return Project settings service
83          */
84         private ProjectSettingsService getProjectSettings() {
85                 return _projectSettingsService;
86         }
87
88         /**
89          * Set project settings service.
90          * @param projectSettingsService project settings service
91          */
92         public void setProjectSettings(
93                         ProjectSettingsService projectSettingsService) {
94                 _projectSettingsService = projectSettingsService;
95         }
96
97         /**
98          * Get the applicationSettings.
99          * @return the applicationSettings
100          */
101         public ApplicationSettings getApplicationSettings() {
102                 return _ApplicationSettings;
103         }
104
105         /**
106          * Set the applicationSettings.
107          * @param applicationSettings the applicationSettings to set
108          */
109         public void setApplicationSettings(ApplicationSettings applicationSettings) {
110                 _ApplicationSettings = applicationSettings;
111         }
112 }