1 package org.splat.simer;
4 import java.util.Comparator;
5 import java.util.ResourceBundle;
7 import javax.security.auth.login.LoginContext;
8 import javax.servlet.http.HttpServletRequest;
10 import com.opensymphony.xwork2.ActionSupport;
12 import org.apache.struts2.interceptor.ServletRequestAware;
13 import org.apache.struts2.interceptor.SessionAware;
14 import org.apache.log4j.Logger;
15 import org.splat.dal.bo.kernel.User;
16 import org.splat.som.ApplicationRights;
17 import org.splat.som.StudyRights;
18 import org.splat.dal.bo.som.KnowledgeElement;
19 import org.splat.dal.bo.som.SimulationContextType;
20 import org.splat.dal.bo.som.Study;
21 import org.splat.dal.bo.som.DocumentType;
22 import org.splat.wapp.Menu;
23 import org.splat.wapp.PopupMenu;
29 public class Action extends ActionSupport implements ServletRequestAware, SessionAware {
34 private static final long serialVersionUID = -895295026709526501L;
38 protected static final Logger logger = Logger.getLogger(Action.class);
41 * Http servlet request.
43 private HttpServletRequest request;
45 * Http session container.
47 private Map<String, Object> session;
51 private String mercode;
53 * Current open study facade object.
55 private OpenStudy _openStudy;
57 * Current open knowledge facade object.
59 private OpenKnowledge _openKnowledge;
63 * MenuBarSettings bean.
65 private MenuBarSettings _menuBarSettings;
68 * TitleBarSettings bean.
70 private TitleBarSettings _titleBarSettings;
72 * ToolBarSettings bean.
74 private ToolBarSettings _toolBarSettings;
77 * LeftMenuSettings bean.
79 private LeftMenuSettings _leftMenuSettings;
82 * Injected application settings bean.
84 private ApplicationSettings _applicationSettings;
88 * It's temporary solution for menuitem.jsp
90 private static Menu staticMenu;
92 public class DocumentTypeComparator implements Comparator<DocumentType> {
93 public int compare(DocumentType t1, DocumentType t2)
95 ResourceBundle locale = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale());
96 String name1 = t1.getName();
97 if (t1.isApproved()) name1 = locale.getString("type.document." + name1);
98 String name2 = t2.getName();
99 if (t2.isApproved()) name2 = locale.getString("type.document." + name2);
101 return name1.compareToIgnoreCase(name2);
104 public class ContextTypeComparator implements Comparator<SimulationContextType> {
105 public int compare(SimulationContextType t1, SimulationContextType t2)
107 ResourceBundle locale = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale());
108 String name1 = t1.getName();
109 if (t1.isApproved()) name1 = locale.getString("type.context." + name1);
110 String name2 = t2.getName();
111 if (t2.isApproved()) name2 = locale.getString("type.context." + name2);
113 return name1.compareToIgnoreCase(name2);
117 // ==============================================================================================================================
119 // ==============================================================================================================================
121 protected void closeKnowledge () {
122 OpenObject open = (OpenObject)session.remove("knowledge.open");
124 if (session.get("study.open") == null) open.clearFacades(); // For eventually reopening the knowledge from a fresh context
127 protected void closeStudy () {
128 OpenObject open = (OpenObject)session.remove("study.open");
130 if (session.get("knowledge.open") == null) open.clearFacades(); // For eventually reopening the study from a fresh context
133 protected void connect (LoginContext context, User user) {
134 OpenStudy open = getOpenStudy();
136 open.changeUser(user);
138 session.put("user.rights", new ApplicationRights(user) );
139 session.put("login.context", context); // For executing the deconnection, when requested
141 protected void disconnect () {
142 OpenStudy open = getOpenStudy();
144 open.changeUser(null);
146 session.put("user.rights", new ApplicationRights(null) ); // Disables user rights
147 session.remove("login.context");
149 public User getConnectedUser () {
150 ApplicationRights rights = (ApplicationRights)session.get("user.rights");
151 User connected = null;
152 if (rights != null) {
153 connected = rights.getUser();
155 return connected; // May be null
157 protected Menu getMenu (String name) {
158 return (Menu)session.get("menu." + name);
160 public void setOpenKnowledge (OpenKnowledge kelm) {
161 _openKnowledge = kelm;
163 protected OpenKnowledge getOpenKnowledge () {
164 // _openKnowledge = (OpenKnowledge)session.get("knowledge.open"); // May be null
165 return _openKnowledge;
167 public void setOpenStudy (OpenStudy aStudy) {
170 public OpenStudy getOpenStudy () {
171 // _openStudy = (OpenStudy)session.get("study.open");
172 return _openStudy; // May be null
174 protected OpenKnowledge open (KnowledgeElement kelm) {
175 OpenKnowledge open = _openKnowledge.open(kelm);
177 closeKnowledge(); // Just in case
178 session.put("knowledge.open", open);
181 protected OpenStudy open (Study study) {
182 OpenStudy open = _openStudy.open(getConnectedUser(), study); // The connected user may be null
184 closeStudy(); // Just in case
185 session.put("study.open", open);
190 * Initialization the Context for menubar and toolbar.
192 public void initializationContext() {
193 getMenuBarSettings().initializeInitialMenuProperties();
195 if (session.get("study.open") == null) {
196 getMenuBarSettings().setIsStudyNull(true);
198 getMenuBarSettings().setIsStudyNull(false);
200 //for initialization ToolBarSettings.canUserEdit property
201 // and ToolBarSettings.isEnabledScript property.
203 OpenStudy currentStudy = (OpenStudy)session.get("study.open");
204 PopupMenu popup = currentStudy.getPopup();
205 StudyRights user = currentStudy.getStudyRights();
207 if(user.canEditProperties()) {
208 getToolBarSettings().setCanUserEdit(true);
210 getToolBarSettings().setCanUserEdit(false);
214 getToolBarSettings().setIsEnabledScript(false);
215 } else if (popup.isEnabled("script")) {
216 getToolBarSettings().setIsEnabledScript(true);
218 getToolBarSettings().setIsEnabledScript(false);
222 if (session.get("knowledge.open") == null) {
223 getMenuBarSettings().setIsKnowledgeNull(true);
225 getMenuBarSettings().setIsKnowledgeNull(false);
228 ApplicationRights userRights = (ApplicationRights)session.get("user.rights");
230 if ((userRights != null) && userRights.canCreateStudy()) {
231 getMenuBarSettings().setCanUserCreateStudy(true);
233 getMenuBarSettings().setCanUserCreateStudy(false);
236 if ((userRights != null) && userRights.canManageDatabase()) {
237 getMenuBarSettings().setCanUserManageDatabase(true);
239 getMenuBarSettings().setCanUserManageDatabase(false);
245 * Initialization the Context for left menu.
246 * @param leftMenuProperty - the property of the left menu.
248 public void initializationContextLeftMenus(final String leftMenuProperty) {
250 Menu menu = (Menu)session.get("menu." + leftMenuProperty);
252 getLeftMenuSettings().setMenu(menu);
254 getLeftMenuSettings().setMenuName(menu.getName());
255 getLeftMenuSettings().setMenuNamespace(menu.getNamespace());
259 * Initialization the Context for Menu Bar and Tool Bar.
261 * @param titleProperty - The title of the open study/knowledge.
262 * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
264 public void initializationContext(final String titleProperty, final String editDisabledProperty) {
266 initializationContext();
268 OpenObject entity = (OpenObject)session.get(titleProperty + ".open");
270 getTitleBarSettings().setProgressState(entity.getProgressState().toString());
271 getTitleBarSettings().setSelectionState(entity.getSelection());
272 getTitleBarSettings().setEntryType(entity.getType().toLowerCase());
273 getTitleBarSettings().setEntryTypeTitle(entity.getType());
274 getTitleBarSettings().setEntryTitle(entity.getTitle());
275 getTitleBarSettings().setEditDisabledProperty(editDisabledProperty);
279 * Initialization of the screen context for menu bar.
281 * @param menuProperty - the property of the menu bar.
283 public void initializationScreenContext(final String menuProperty) {
285 initializationContext();
286 getMenuBarSettings().intializeMenuBar(menuProperty);
290 * Initialization of the screen context for menu bar and title bar.
292 * @param menuProperty - the property of the menu bar.
293 * @param titleProperty - The title of the open study/knowledge.
294 * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
296 public void initializationScreenContext(final String menuProperty,
297 final String titleProperty, final String editDisabledProperty) {
299 initializationContext(titleProperty, editDisabledProperty);
300 getMenuBarSettings().intializeMenuBar(menuProperty);
304 * Initialization of the screen context for menu bar, title bar and tool bar.
306 * @param menuProperty - the property of the menu bar.
307 * @param titleProperty - The title of the open study/knowledge.
308 * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
309 * @param toolProperty - the property of the tool bar.
311 public void initializationScreenContext(final String menuProperty,
312 final String titleProperty, final String editDisabledProperty,
313 final String toolProperty) {
315 initializationScreenContext(menuProperty, titleProperty, editDisabledProperty);
316 getToolBarSettings().intializeMenuBar(toolProperty);
320 * Initialization of the screen context for menu bar and tool bar.
322 * @param menuProperty - the property of the menu bar.
323 * @param toolProperty - the property of the tool bar.
325 public void initializationScreenContext(final String menuProperty,
326 final String toolProperty) {
328 initializationContext();
329 getMenuBarSettings().intializeMenuBar(menuProperty);
330 getToolBarSettings().intializeMenuBar(toolProperty);
334 * Initialization of the screen context for menu bar, title bar and tool bar.
336 * @param menuProperty - the property of the menu bar.
337 * @param titleProperty - The title of the open study/knowledge.
338 * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
339 * @param toolProperty - the property of the tool bar.
340 * @param leftMenuProperty - the property of the left menu.
342 public void initializationFullScreenContext(final String menuProperty,
343 final String titleProperty, final String editDisabledProperty,
344 final String toolProperty, final String leftMenuProperty) {
346 initializationScreenContext(menuProperty, titleProperty, editDisabledProperty);
347 initializationContextLeftMenus(leftMenuProperty);
348 getToolBarSettings().intializeMenuBar(toolProperty);
352 * Initialization of the screen context for menu bar and tool bar.
354 * @param menuProperty - the property of the menu bar.
355 * @param toolProperty - the property of the tool bar.
356 * @param leftMenuProperty - the property of the left menu.
358 public void initializationFullScreenContext(final String menuProperty,
359 final String toolProperty, final String leftMenuProperty) {
361 initializationContext();
362 initializationContextLeftMenus(leftMenuProperty);
363 getMenuBarSettings().intializeMenuBar(menuProperty);
364 getToolBarSettings().intializeMenuBar(toolProperty);
366 // ==============================================================================================================================
367 // Getters and setters
368 // ==============================================================================================================================
370 public void setServletRequest (HttpServletRequest request) {
371 this.request = request;
374 public HttpServletRequest getServletRequest() {
378 public String getErrorCode () {
381 public Map<String, Object> getSession () {
385 public void setErrorCode (String code) {
388 public void setSession (Map<String, Object> session) {
389 this.session = session;
393 * Get the menuBarSettings.
394 * @return the menuBarSettings
396 public MenuBarSettings getMenuBarSettings() {
397 return _menuBarSettings;
401 * Set the menuBarSettings.
402 * @param menuBarSettings the menuBarSettings to set
404 public void setMenuBarSettings(final MenuBarSettings menuBarSettings) {
405 _menuBarSettings = menuBarSettings;
409 * Get the _titleBarSettings.
410 * @return the _titleBarSettings
412 public TitleBarSettings getTitleBarSettings() {
413 return _titleBarSettings;
416 * Set the titleBarSettings.
417 * @param titleBarSettings the titleBarSettings to set
419 public void setTitleBarSettings(TitleBarSettings titleBarSettings) {
420 _titleBarSettings = titleBarSettings;
423 * Get the toolBarSettings.
424 * @return the toolBarSettings
426 public final ToolBarSettings getToolBarSettings() {
427 return _toolBarSettings;
430 * Set the toolBarSettings.
431 * @param toolBarSettings the toolBarSettings to set
433 public final void setToolBarSettings(ToolBarSettings toolBarSettings) {
434 _toolBarSettings = toolBarSettings;
438 * Get the applicationSettings.
439 * @return the applicationSettings
441 public ApplicationSettings getApplicationSettings() {
442 return _applicationSettings;
445 * Set the applicationSettings.
446 * @param applicationSettings the applicationSettings to set
448 public void setApplicationSettings(ApplicationSettings applicationSettings) {
449 _applicationSettings = applicationSettings;
452 * Get the leftMenuSettings.
453 * @return the leftMenuSettings
455 public LeftMenuSettings getLeftMenuSettings() {
456 return _leftMenuSettings;
460 * Get the staticMenu.
461 * @return the staticMenu
463 public static Menu getStaticMenu() {
467 * Set the staticMenu.
468 * @param staticMenu the staticMenu to set
470 public static void setStaticMenu(Menu staticMenu) {
471 Action.staticMenu = staticMenu;
474 * Set the leftMenuSettings.
475 * @param leftMenuSettings the leftMenuSettings to set
477 public void setLeftMenuSettings(LeftMenuSettings leftMenuSettings) {
478 _leftMenuSettings = leftMenuSettings;