]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/StartAction.java
Salome HOME
ab2832e0868652e6289411a15d37a3d4d9b77b7c
[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();
78                         wapp.setLocale(this.getLocale());
79                         String root = ApplicationSettings.getApplicationRootPath();
80                         LOG.debug("Application root: " + root);
81
82                         // Database configuration
83                         project.configure(root
84                                         + ApplicationSettings.getApplicationProperty("wapp.configuration"));
85
86                         // Configure menus for the current user
87                         wapp.configure();
88                         
89                         // Initialization of the user session
90                         Map<String, Object> session = getSession();
91
92                         session.put("user.rights", new ApplicationRights(null)); // No user connected yet
93                         session.put("study.filter", wapp.getFilter(Constants.STUDY_MENU));
94                         session.put("knowledge.filter", wapp
95                                         .getFilter(Constants.KNOWLEDGE_MENU));
96
97                         setMenuProperty(Constants.NONE);
98                         initializationScreenContext(_menuProperty);
99                         
100                 } catch (Exception error) {
101                         LOG.fatal("Reason:", error);
102
103                         setMenuProperty(Constants.STUDY_MENU);
104                         setTitleProperty(Constants.STUDY_MENU);
105                         setEditDisabledProperty("true");
106                         setToolProperty(Constants.NONE);
107                         setLeftMenuProperty(Constants.STUDY_MENU);
108                         initializationFullScreenContext(_menuProperty, _titleProperty,
109                                         _editDisabledProperty, _toolProperty, _leftMenuProperty);
110
111                         res = ERROR;
112                 }
113                 return res;
114         }
115
116         // ==============================================================================================================================
117         // Setter
118         // ==============================================================================================================================
119
120         /** 
121          * {@inheritDoc}
122          * @see org.splat.simer.Action#setServletRequest(javax.servlet.http.HttpServletRequest)
123          */
124         @Override
125         public void setServletRequest(final HttpServletRequest request) {
126                 this._request = request;
127         }
128
129         /**
130          * Get project settings.
131          * 
132          * @return Project settings service
133          */
134         private ProjectSettingsService getProjectSettings() {
135                 return _projectSettings;
136         }
137
138         /**
139          * Set project settings service.
140          * 
141          * @param projectSettingsService
142          *            project settings service
143          */
144         public void setProjectSettings(
145                         final ProjectSettingsService projectSettingsService) {
146                 _projectSettings = projectSettingsService;
147         }
148
149         /**
150          * Get the applicationSettings.
151          * 
152          * @return the applicationSettings
153          */
154         @Override
155         public ApplicationSettings getApplicationSettings() {
156                 return _applicationSettings;
157         }
158
159         /**
160          * Set the applicationSettings.
161          * 
162          * @param applicationSettings
163          *            the applicationSettings to set
164          */
165         @Override
166         public void setApplicationSettings(
167                         final ApplicationSettings applicationSettings) {
168                 _applicationSettings = applicationSettings;
169         }
170
171         /**
172          * Get the menuProperty.
173          * 
174          * @return the menuProperty
175          */
176         public String getMenuProperty() {
177                 return _menuProperty;
178         }
179
180         /**
181          * Set the menuProperty.
182          * 
183          * @param menuProperty
184          *            the menuProperty to set
185          */
186         public void setMenuProperty(final String menuProperty) {
187                 this._menuProperty = menuProperty;
188         }
189
190         /**
191          * Get the _titleProperty.
192          * 
193          * @return the _titleProperty
194          */
195         public String getTitleProperty() {
196                 return _titleProperty;
197         }
198
199         /**
200          * Set the titleProperty.
201          * 
202          * @param titleProperty
203          *            the titleProperty to set
204          */
205         public void setTitleProperty(final String titleProperty) {
206                 _titleProperty = titleProperty;
207         }
208
209         /**
210          * Get the editDisabledProperty.
211          * 
212          * @return the editDisabledProperty
213          */
214         public final String getEditDisabledProperty() {
215                 return _editDisabledProperty;
216         }
217
218         /**
219          * Set the editDisabledProperty.
220          * 
221          * @param editDisabledProperty
222          *            the editDisabledProperty to set
223          */
224         public final void setEditDisabledProperty(final String editDisabledProperty) {
225                 _editDisabledProperty = editDisabledProperty;
226         }
227
228         /**
229          * Get the toolProperty.
230          * 
231          * @return the toolProperty
232          */
233         public String getToolProperty() {
234                 return _toolProperty;
235         }
236
237         /**
238          * Set the toolProperty.
239          * 
240          * @param toolProperty
241          *            the toolProperty to set
242          */
243         public void setToolProperty(final String toolProperty) {
244                 _toolProperty = toolProperty;
245         }
246
247         /**
248          * Get the leftMenuProperty.
249          * 
250          * @return the leftMenuProperty
251          */
252         public String getLeftMenuProperty() {
253                 return _leftMenuProperty;
254         }
255
256         /**
257          * Set the leftMenuProperty.
258          * 
259          * @param leftMenuProperty
260          *            the leftMenuProperty to set
261          */
262         public void setLeftMenuProperty(final String leftMenuProperty) {
263                 _leftMenuProperty = leftMenuProperty;
264         }
265 }