1 package org.splat.simer;
3 import java.util.Comparator;
5 import java.util.ResourceBundle;
7 import javax.security.auth.login.LoginContext;
8 import javax.servlet.http.HttpServletRequest;
10 import org.apache.log4j.Logger;
11 import org.apache.struts2.interceptor.ServletRequestAware;
12 import org.apache.struts2.interceptor.SessionAware;
13 import org.splat.dal.bo.kernel.User;
14 import org.splat.dal.bo.som.DocumentType;
15 import org.splat.dal.bo.som.SimulationContextType;
16 import org.splat.dal.bo.som.Study;
17 import org.splat.service.dto.KnowledgeElementDTO;
18 import org.splat.som.ApplicationRights;
19 import org.splat.som.StudyRights;
20 import org.splat.wapp.Menu;
21 import org.splat.wapp.PopupMenu;
23 import com.opensymphony.xwork2.ActionSupport;
28 public class Action extends ActionSupport implements ServletRequestAware,
34 private static final long serialVersionUID = -895295026709526501L;
38 protected static final Logger LOG = Logger.getLogger(Action.class);
41 * Open knowledge key in session.
43 public static final String KNOWLEDGE_OPEN = "knowledge.open";
46 * Open study key in session.
48 public static final String STUDY_OPEN = "study.open";
51 * User rights key in session.
53 public static final String USER_RIGHTS = "user.rights";
56 * Login context key in session.
58 public static final String LOGIN_CONTEXT = "login.context";
61 * Http servlet request.
63 private HttpServletRequest _servletRequest;
65 * Http session container.
67 private Map<String, Object> _session;
71 private String _errorCode;
73 * ActionType for specifying the type of the operaion.
75 private String _actionType;
77 * Current open study facade object.
79 private OpenStudy _openStudy;
81 * Current open knowledge facade object.
83 private OpenKnowledge _openKnowledge;
86 * MenuBarSettings bean.
88 private MenuBarSettings _menuBarSettings;
91 * TitleBarSettings bean.
93 private TitleBarSettings _titleBarSettings;
95 * ToolBarSettings bean.
97 private ToolBarSettings _toolBarSettings;
100 * LeftMenuSettings bean.
102 private LeftMenuSettings _leftMenuSettings;
105 * Injected application settings bean.
107 private ApplicationSettings _applicationSettings;
110 * Will be removed!!! It's temporary solution for menuitem.jsp
112 private static Menu staticMenu;
115 * Comparator for sorting document types with localized names.
117 public class DocumentTypeComparator implements Comparator<DocumentType> {
121 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
123 public int compare(final DocumentType t1, final DocumentType t2) {
124 ResourceBundle locale = ResourceBundle.getBundle("som",
125 ApplicationSettings.getCurrentLocale());
126 String name1 = t1.getName();
127 if (t1.isApproved()) {
128 name1 = locale.getString("type.document." + name1);
130 String name2 = t2.getName();
131 if (t2.isApproved()) {
132 name2 = locale.getString("type.document." + name2);
135 return name1.compareToIgnoreCase(name2);
140 * Comparator for sorting simulation context types with localized names.
142 public class ContextTypeComparator implements
143 Comparator<SimulationContextType> {
147 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
149 public int compare(final SimulationContextType t1,
150 final SimulationContextType t2) {
151 ResourceBundle locale = ResourceBundle.getBundle("som",
152 ApplicationSettings.getCurrentLocale());
153 String name1 = t1.getName();
154 if (t1.isApproved()) {
155 name1 = locale.getString("type.context." + name1);
157 String name2 = t2.getName();
158 if (t2.isApproved()) {
159 name2 = locale.getString("type.context." + name2);
162 return name1.compareToIgnoreCase(name2);
166 // ==============================================================================================================================
168 // ==============================================================================================================================
171 * Remove the currently open knowledge from the session.
173 protected void closeKnowledge() {
174 AbstractOpenObject open = (AbstractOpenObject) _session.remove(KNOWLEDGE_OPEN);
175 if ((open != null) && (_session.get(STUDY_OPEN) == null)) {
176 open.clearFacades(); // For eventually reopening the knowledge from a fresh context
181 * Remove the currently open study from the session.
183 protected void closeStudy() {
184 AbstractOpenObject open = (AbstractOpenObject) _session.remove(STUDY_OPEN);
185 if ((open != null) && (_session.get(KNOWLEDGE_OPEN) == null)) {
186 open.clearFacades(); // For eventually reopening the study from a fresh context
191 * Connect the given user to SIMAN. Store his rights and login context in HTTP session.
196 * the user to connect
198 protected void connect(final LoginContext context, final User user) {
199 OpenStudy open = getOpenStudy();
201 open.changeUser(user);
203 _session.put(USER_RIGHTS, new ApplicationRights(user));
204 _session.put(LOGIN_CONTEXT, context); // For executing the deconnection, when requested
208 * Disconnect the currently connected user from SIMAN. Remove his rihgts and login context from the session.
210 protected void disconnect() {
211 OpenStudy open = getOpenStudy();
213 open.changeUser(null);
215 _session.put(USER_RIGHTS, new ApplicationRights(null)); // Disables user rights
216 _session.remove(LOGIN_CONTEXT);
220 * Get the currently connected user from HTTP session.
224 public User getConnectedUser() {
225 ApplicationRights rights = (ApplicationRights) _session
227 User connected = null;
228 if (rights != null) {
229 connected = rights.getUser();
231 return connected; // May be null
235 * Get a menu named as "menu." with the given suffix from HTTP session.
238 * the menu name suffix
241 protected Menu getMenu(final String name) {
242 return (Menu) _session.get("menu." + name);
246 * Open knowledge setter.
249 * the OpenKnowledge to set
251 public void setOpenKnowledge(final OpenKnowledge kelm) {
252 _openKnowledge = kelm;
256 * Open knowledge getter.
258 * @return the currently open knowledge wrapper. May be null
260 protected OpenKnowledge getOpenKnowledge() {
261 // _openKnowledge = (OpenKnowledge)session.get(KNOWLEDGE_OPEN); // May be null
262 return _openKnowledge;
269 * the OpenStudy to set
271 public void setOpenStudy(final OpenStudy aStudy) {
278 * @return the currently open stydy wrapper. May be null.
280 public OpenStudy getOpenStudy() {
281 // _openStudy = (OpenStudy)session.get(STUDY_OPEN);
282 return _openStudy; // May be null
286 * Open the given knowledge in the current HTTP session. Replace the previose one in the session if any.
289 * the knowledge element to open
290 * @return OpenKnowledge wrapper object
292 protected OpenKnowledge open(final KnowledgeElementDTO kelm) {
293 OpenKnowledge open = _openKnowledge.open(kelm);
295 closeKnowledge(); // Just in case
296 _session.put(KNOWLEDGE_OPEN, open);
301 * Open the given study in the current HTTP session. Replace the previose one in the session if any.
305 * @return OpenStudy wrapper object
307 protected OpenStudy open(final Study study) {
308 OpenStudy open = _openStudy.open(getConnectedUser(), study); // The connected user may be null
310 closeStudy(); // Just in case
311 _session.put(STUDY_OPEN, open);
316 * Initialization the Context for menubar and toolbar.
318 public void initializationContext() {
319 getMenuBarSettings().initializeInitialMenuProperties();
321 if (_session.get(STUDY_OPEN) == null) {
322 getMenuBarSettings().setIsStudyNull(true);
324 getMenuBarSettings().setIsStudyNull(false);
326 // for initialization ToolBarSettings.canUserEdit property
327 // and ToolBarSettings.isEnabledScript property.
329 OpenStudy currentStudy = (OpenStudy) _session.get(STUDY_OPEN);
330 PopupMenu popup = currentStudy.getPopup();
331 StudyRights user = currentStudy.getStudyRights();
333 if (user.canEditProperties()) {
334 getToolBarSettings().setCanUserEdit(true);
336 getToolBarSettings().setCanUserEdit(false);
340 getToolBarSettings().setIsEnabledScript(false);
341 } else if (popup.isEnabled("script")) {
342 getToolBarSettings().setIsEnabledScript(true);
344 getToolBarSettings().setIsEnabledScript(false);
348 if (_session.get(KNOWLEDGE_OPEN) == null) {
349 getMenuBarSettings().setIsKnowledgeNull(true);
351 getMenuBarSettings().setIsKnowledgeNull(false);
354 ApplicationRights userRights = (ApplicationRights) _session
357 if ((userRights != null) && userRights.canCreateStudy()) {
358 getMenuBarSettings().setCanUserCreateStudy(true);
360 getMenuBarSettings().setCanUserCreateStudy(false);
363 if ((userRights != null) && userRights.canManageDatabase()) {
364 getMenuBarSettings().setCanUserManageDatabase(true);
366 getMenuBarSettings().setCanUserManageDatabase(false);
372 * Initialization the Context for left menu.
374 * @param leftMenuProperty -
375 * the property of the left menu.
377 public void initializationContextLeftMenus(final String leftMenuProperty) {
379 Menu menu = (Menu) _session.get("menu." + leftMenuProperty);
381 getLeftMenuSettings().setMenu(menu);
383 getLeftMenuSettings().setMenuName(menu.getName());
384 getLeftMenuSettings().setMenuNamespace(menu.getNamespace());
388 * Initialization the Context for Menu Bar and Tool Bar.
390 * @param titleProperty -
391 * The title of the open study/knowledge.
392 * @param editDisabledProperty -
393 * Property that indicates whether the current open study is editable or not.
395 public void initializationContext(final String titleProperty,
396 final String editDisabledProperty) {
398 initializationContext();
400 AbstractOpenObject entity = (AbstractOpenObject) _session.get(titleProperty + ".open");
402 getTitleBarSettings().setProgressState(
403 entity.getProgressState().toString());
404 getTitleBarSettings().setSelectionState(entity.getSelection());
405 getTitleBarSettings().setEntryType(entity.getType().toLowerCase());
406 getTitleBarSettings().setEntryTypeTitle(entity.getType());
407 getTitleBarSettings().setEntryTitle(entity.getTitle());
408 getTitleBarSettings().setEditDisabledProperty(editDisabledProperty);
412 * Initialization of the screen context for menu bar.
414 * @param menuProperty -
415 * the property of the menu bar.
417 public void initializationScreenContext(final String menuProperty) {
419 initializationContext();
420 getMenuBarSettings().intializeMenuBar(menuProperty);
424 * Initialization of the screen context for menu bar and title bar.
426 * @param menuProperty -
427 * the property of the menu bar.
428 * @param titleProperty -
429 * The title of the open study/knowledge.
430 * @param editDisabledProperty -
431 * Property that indicates whether the current open study is editable or not.
433 public void initializationScreenContext(final String menuProperty,
434 final String titleProperty, final String editDisabledProperty) {
436 initializationContext(titleProperty, editDisabledProperty);
437 getMenuBarSettings().intializeMenuBar(menuProperty);
441 * Initialization of the screen context for menu bar, title bar and tool bar.
443 * @param menuProperty -
444 * the property of the menu bar.
445 * @param titleProperty -
446 * The title of the open study/knowledge.
447 * @param editDisabledProperty -
448 * Property that indicates whether the current open study is editable or not.
449 * @param toolProperty -
450 * the property of the tool bar.
452 public void initializationScreenContext(final String menuProperty,
453 final String titleProperty, final String editDisabledProperty,
454 final String toolProperty) {
456 initializationScreenContext(menuProperty, titleProperty,
457 editDisabledProperty);
458 getToolBarSettings().intializeMenuBar(toolProperty);
462 * Initialization of the screen context for menu bar and tool bar.
464 * @param menuProperty -
465 * the property of the menu bar.
466 * @param toolProperty -
467 * the property of the tool bar.
469 public void initializationScreenContext(final String menuProperty,
470 final String toolProperty) {
472 initializationContext();
473 getMenuBarSettings().intializeMenuBar(menuProperty);
474 getToolBarSettings().intializeMenuBar(toolProperty);
478 * Initialization of the screen context for menu bar, title bar and tool bar.
480 * @param menuProperty -
481 * the property of the menu bar.
482 * @param titleProperty -
483 * The title of the open study/knowledge.
484 * @param editDisabledProperty -
485 * Property that indicates whether the current open study is editable or not.
486 * @param toolProperty -
487 * the property of the tool bar.
488 * @param leftMenuProperty -
489 * the property of the left menu.
491 public void initializationFullScreenContext(final String menuProperty,
492 final String titleProperty, final String editDisabledProperty,
493 final String toolProperty, final String leftMenuProperty) {
495 initializationScreenContext(menuProperty, titleProperty,
496 editDisabledProperty);
497 initializationContextLeftMenus(leftMenuProperty);
498 getToolBarSettings().intializeMenuBar(toolProperty);
502 * Initialization of the screen context for menu bar and tool bar.
504 * @param menuProperty -
505 * the property of the menu bar.
506 * @param toolProperty -
507 * the property of the tool bar.
508 * @param leftMenuProperty -
509 * the property of the left menu.
511 public void initializationFullScreenContext(final String menuProperty,
512 final String toolProperty, final String leftMenuProperty) {
514 initializationContext();
515 initializationContextLeftMenus(leftMenuProperty);
516 getMenuBarSettings().intializeMenuBar(menuProperty);
517 getToolBarSettings().intializeMenuBar(toolProperty);
520 // ==============================================================================================================================
521 // Getters and setters
522 // ==============================================================================================================================
527 * @see org.apache.struts2.interceptor.ServletRequestAware#setServletRequest(javax.servlet.http.HttpServletRequest)
529 public void setServletRequest(final HttpServletRequest request) {
530 this._servletRequest = request;
534 * Get current HTTP request.
536 * @return HTTP request
538 public HttpServletRequest getServletRequest() {
539 return _servletRequest;
543 * Get current error code.
547 public String getErrorCode() {
554 * @return session map
556 public Map<String, Object> getSession() {
564 * the error code to set
566 public void setErrorCode(final String code) {
567 this._errorCode = code;
573 * @see org.apache.struts2.interceptor.SessionAware#setSession(java.util.Map)
575 public void setSession(final Map<String, Object> session) {
576 this._session = session;
580 * Get the menuBarSettings.
582 * @return the menuBarSettings
584 public MenuBarSettings getMenuBarSettings() {
585 return _menuBarSettings;
589 * Set the menuBarSettings.
591 * @param menuBarSettings
592 * the menuBarSettings to set
594 public void setMenuBarSettings(final MenuBarSettings menuBarSettings) {
595 _menuBarSettings = menuBarSettings;
599 * Get the _titleBarSettings.
601 * @return the _titleBarSettings
603 public TitleBarSettings getTitleBarSettings() {
604 return _titleBarSettings;
608 * Set the titleBarSettings.
610 * @param titleBarSettings
611 * the titleBarSettings to set
613 public void setTitleBarSettings(final TitleBarSettings titleBarSettings) {
614 _titleBarSettings = titleBarSettings;
618 * Get the toolBarSettings.
620 * @return the toolBarSettings
622 public final ToolBarSettings getToolBarSettings() {
623 return _toolBarSettings;
627 * Set the toolBarSettings.
629 * @param toolBarSettings
630 * the toolBarSettings to set
632 public final void setToolBarSettings(final ToolBarSettings toolBarSettings) {
633 _toolBarSettings = toolBarSettings;
637 * Get the applicationSettings.
639 * @return the applicationSettings
641 public ApplicationSettings getApplicationSettings() {
642 return _applicationSettings;
646 * Set the applicationSettings.
648 * @param applicationSettings
649 * the applicationSettings to set
651 public void setApplicationSettings(
652 final ApplicationSettings applicationSettings) {
653 _applicationSettings = applicationSettings;
657 * Get the leftMenuSettings.
659 * @return the leftMenuSettings
661 public LeftMenuSettings getLeftMenuSettings() {
662 return _leftMenuSettings;
666 * Get the staticMenu.
668 * @return the staticMenu
670 public static Menu getStaticMenu() {
675 * Set the staticMenu.
678 * the staticMenu to set
680 public static void setStaticMenu(final Menu staticMenu) {
681 Action.staticMenu = staticMenu;
685 * Set the leftMenuSettings.
687 * @param leftMenuSettings
688 * the leftMenuSettings to set
690 public void setLeftMenuSettings(final LeftMenuSettings leftMenuSettings) {
691 _leftMenuSettings = leftMenuSettings;
695 * Get the actionType.
696 * @return the actionType
698 public String getActionType() {
703 * Set the actionType.
704 * @param actionType the actionType to set
706 public void setActionType(final String actionType) {
707 _actionType = actionType;