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