Salome HOME
Modifications to respect PMD rules.
[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.ServletContext;
6 import javax.servlet.http.HttpServletRequest;
7
8 import org.apache.struts2.interceptor.ServletRequestAware;
9 import org.apache.struts2.util.ServletContextAware;
10 import org.hibernate.HibernateException;
11 import org.hibernate.Session;
12 import org.hibernate.Transaction;
13 import org.splat.som.ApplicationRights;
14 import org.splat.dal.dao.som.Database;
15 import org.splat.service.technical.ProjectSettingsService;
16
17
18
19 public class StartAction extends Action implements ServletRequestAware {
20
21     private HttpServletRequest  request = null;
22
23         private ProjectSettingsService _projectSettingsService;
24         private ApplicationSettings _ApplicationSettings;
25         
26         /**
27          * Value of the menu property. 
28          * It can be: none, create, open, study, knowledge, sysadmin, help.
29          */
30         private String _menuProperty;
31         
32         /**
33          * Value of the title bar property. 
34          * It can be: study, knowledge.
35          */
36         private String _titleProperty;
37         
38         /**
39          * Property that indicates whether the current open study is editable or not.
40          * On the screen it looks like pen on the status icon, pop-up menu also can be called.
41          * It is necessary for correct building the title bar.
42          */
43         private String _editDisabledProperty = "false";
44         
45         /**
46          * Value of the tool bar property. 
47          * It can be: none, standard, study, back.
48          */
49         private String _toolProperty;
50         
51         /**
52          * Value of the left menu property. 
53          * It can be: open, study, knowledge, scenario.
54          */
55         private String _leftMenuProperty;
56
57         /**
58          * Serial version ID.
59          */
60         private static final long   serialVersionUID = 5875058140682652964L;
61
62 //  ==============================================================================================================================
63 //  Action execution
64 //  ==============================================================================================================================
65
66         public String doInitialize () throws Exception {
67 //  -----------------------------
68 //      Session      connex  = Database.getSession();
69 //      Transaction  transax = connex.beginTransaction();                 
70           StringBuffer wappurl = request.getRequestURL();     // "http://{server}:{port}/{webapp}/", including the leading '/'
71
72       LOG.info( new StringBuffer("Initializing ").append(wappurl).append("...").toString() );
73           try {
74                 ProjectSettingsService project = getProjectSettings();
75         ApplicationSettings wapp    = getApplicationSettings().init(wappurl.toString(), this.getLocale());
76         String              root    = wapp.getApplicationRootPath();
77         LOG.debug("Application root: " + root);
78
79 //      Database configuration
80                 project.configure(root + wapp.getApplicationProperty("wapp.configuration"));
81
82 //      Application configuration
83             System.setProperty("java.security.auth.login.config", root + wapp.getApplicationProperty("wapp.login"));        
84             wapp.configure(root + wapp.getApplicationProperty("wapp.customization"));
85
86 //      Initialization of the user session
87                 Map<String, Object> session = getSession();
88
89         session.put("user.rights", new ApplicationRights(null) );      // No user connected yet
90                 session.put("study.filter",     wapp.getFilter("study"));
91                 session.put("knowledge.filter", wapp.getFilter("knowledge"));
92
93 //          transax.commit();
94             
95                 setMenuProperty("none");
96                 initializationScreenContext(_menuProperty);
97             
98             return SUCCESS;
99       }
100       catch (Exception error) {
101         LOG.fatal("Reason:", error);
102         
103         setMenuProperty("study");
104         setTitleProperty("study");
105         setEditDisabledProperty("true");
106         setToolProperty("none");
107         setLeftMenuProperty("study");
108         initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
109         
110         return ERROR;
111       }
112         }
113
114 //  ==============================================================================================================================
115 //  Setter
116 //  ==============================================================================================================================
117
118         public void setServletRequest (HttpServletRequest request) {
119 //  ----------------------------------------------------------
120       this.request = request;
121         }
122     /**
123      * Get project settings.
124          * @return Project settings service
125          */
126         private ProjectSettingsService getProjectSettings() {
127                 return _projectSettingsService;
128         }
129
130         /**
131          * Set project settings service.
132          * @param projectSettingsService project settings service
133          */
134         public void setProjectSettings(
135                         ProjectSettingsService projectSettingsService) {
136                 _projectSettingsService = projectSettingsService;
137         }
138
139         /**
140          * Get the applicationSettings.
141          * @return the applicationSettings
142          */
143         public ApplicationSettings getApplicationSettings() {
144                 return _ApplicationSettings;
145         }
146
147         /**
148          * Set the applicationSettings.
149          * @param applicationSettings the applicationSettings to set
150          */
151         public void setApplicationSettings(ApplicationSettings applicationSettings) {
152                 _ApplicationSettings = applicationSettings;
153         }
154         
155         /**
156          * Get the menuProperty.
157          * @return the menuProperty
158          */
159         public String getMenuProperty() {
160                 return _menuProperty;
161         }
162
163         /**
164          * Set the menuProperty.
165          * @param menuProperty the menuProperty to set
166          */
167         public void setMenuProperty(String menuProperty) {
168                 this._menuProperty = menuProperty;
169         }
170         
171         /**
172          * Get the _titleProperty.
173          * @return the _titleProperty
174          */
175         public String getTitleProperty() {
176                 return _titleProperty;
177         }
178
179         /**
180          * Set the _titleProperty.
181          * @param _titleProperty the titleProperty to set
182          */
183         public void setTitleProperty(String titleProperty) {
184                 _titleProperty = titleProperty;
185         }
186
187         /**
188          * Get the editDisabledProperty.
189          * @return the editDisabledProperty
190          */
191         public final String getEditDisabledProperty() {
192                 return _editDisabledProperty;
193         }
194
195         /**
196          * Set the editDisabledProperty.
197          * @param editDisabledProperty the editDisabledProperty to set
198          */
199         public final void setEditDisabledProperty(String editDisabledProperty) {
200                 _editDisabledProperty = editDisabledProperty;
201         }
202
203         /**
204          * Get the toolProperty.
205          * @return the toolProperty
206          */
207         public String getToolProperty() {
208                 return _toolProperty;
209         }
210
211         /**
212          * Set the toolProperty.
213          * @param toolProperty the toolProperty to set
214          */
215         public void setToolProperty(final String toolProperty) {
216                 _toolProperty = toolProperty;
217         }
218         
219         /**
220          * Get the leftMenuProperty.
221          * @return the leftMenuProperty
222          */
223         public String getLeftMenuProperty() {
224                 return _leftMenuProperty;
225         }
226
227         /**
228          * Set the leftMenuProperty.
229          * @param leftMenuProperty the leftMenuProperty to set
230          */
231         public void setLeftMenuProperty(final String leftMenuProperty) {
232                 _leftMenuProperty = leftMenuProperty;
233         }
234 }