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 * Current open study facade object.
75 private OpenStudy _openStudy;
77 * Current open knowledge facade object.
79 private OpenKnowledge _openKnowledge;
82 * MenuBarSettings bean.
84 private MenuBarSettings _menuBarSettings;
87 * TitleBarSettings bean.
89 private TitleBarSettings _titleBarSettings;
91 * ToolBarSettings bean.
93 private ToolBarSettings _toolBarSettings;
96 * LeftMenuSettings bean.
98 private LeftMenuSettings _leftMenuSettings;
101 * Injected application settings bean.
103 private ApplicationSettings _applicationSettings;
106 * Will be removed!!! It's temporary solution for menuitem.jsp
108 private static Menu staticMenu;
111 * Comparator for sorting document types with localized names.
113 public class DocumentTypeComparator implements Comparator<DocumentType> {
117 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
119 public int compare(final DocumentType t1, final DocumentType t2) {
120 ResourceBundle locale = ResourceBundle.getBundle("som",
121 ApplicationSettings.getCurrentLocale());
122 String name1 = t1.getName();
123 if (t1.isApproved()) {
124 name1 = locale.getString("type.document." + name1);
126 String name2 = t2.getName();
127 if (t2.isApproved()) {
128 name2 = locale.getString("type.document." + name2);
131 return name1.compareToIgnoreCase(name2);
136 * Comparator for sorting simulation context types with localized names.
138 public class ContextTypeComparator implements
139 Comparator<SimulationContextType> {
143 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
145 public int compare(final SimulationContextType t1,
146 final SimulationContextType t2) {
147 ResourceBundle locale = ResourceBundle.getBundle("som",
148 ApplicationSettings.getCurrentLocale());
149 String name1 = t1.getName();
150 if (t1.isApproved()) {
151 name1 = locale.getString("type.context." + name1);
153 String name2 = t2.getName();
154 if (t2.isApproved()) {
155 name2 = locale.getString("type.context." + name2);
158 return name1.compareToIgnoreCase(name2);
162 // ==============================================================================================================================
164 // ==============================================================================================================================
167 * Remove the currently open knowledge from the session.
169 protected void closeKnowledge() {
170 AbstractOpenObject open = (AbstractOpenObject) _session.remove(KNOWLEDGE_OPEN);
171 if ((open != null) && (_session.get(STUDY_OPEN) == null)) {
172 open.clearFacades(); // For eventually reopening the knowledge from a fresh context
177 * Remove the currently open study from the session.
179 protected void closeStudy() {
180 AbstractOpenObject open = (AbstractOpenObject) _session.remove(STUDY_OPEN);
181 if ((open != null) && (_session.get(KNOWLEDGE_OPEN) == null)) {
182 open.clearFacades(); // For eventually reopening the study from a fresh context
187 * Connect the given user to SIMAN. Store his rights and login context in HTTP session.
192 * the user to connect
194 protected void connect(final LoginContext context, final User user) {
195 OpenStudy open = getOpenStudy();
197 open.changeUser(user);
199 _session.put(USER_RIGHTS, new ApplicationRights(user));
200 _session.put(LOGIN_CONTEXT, context); // For executing the deconnection, when requested
204 * Disconnect the currently connected user from SIMAN. Remove his rihgts and login context from the session.
206 protected void disconnect() {
207 OpenStudy open = getOpenStudy();
209 open.changeUser(null);
211 _session.put(USER_RIGHTS, new ApplicationRights(null)); // Disables user rights
212 _session.remove(LOGIN_CONTEXT);
216 * Get the currently connected user from HTTP session.
220 public User getConnectedUser() {
221 ApplicationRights rights = (ApplicationRights) _session
223 User connected = null;
224 if (rights != null) {
225 connected = rights.getUser();
227 return connected; // May be null
231 * Get a menu named as "menu." with the given suffix from HTTP session.
234 * the menu name suffix
237 protected Menu getMenu(final String name) {
238 return (Menu) _session.get("menu." + name);
242 * Open knowledge setter.
245 * the OpenKnowledge to set
247 public void setOpenKnowledge(final OpenKnowledge kelm) {
248 _openKnowledge = kelm;
252 * Open knowledge getter.
254 * @return the currently open knowledge wrapper. May be null
256 protected OpenKnowledge getOpenKnowledge() {
257 // _openKnowledge = (OpenKnowledge)session.get(KNOWLEDGE_OPEN); // May be null
258 return _openKnowledge;
265 * the OpenStudy to set
267 public void setOpenStudy(final OpenStudy aStudy) {
274 * @return the currently open stydy wrapper. May be null.
276 public OpenStudy getOpenStudy() {
277 // _openStudy = (OpenStudy)session.get(STUDY_OPEN);
278 return _openStudy; // May be null
282 * Open the given knowledge in the current HTTP session. Replace the previose one in the session if any.
285 * the knowledge element to open
286 * @return OpenKnowledge wrapper object
288 protected OpenKnowledge open(final KnowledgeElementDTO kelm) {
289 OpenKnowledge open = _openKnowledge.open(kelm);
291 closeKnowledge(); // Just in case
292 _session.put(KNOWLEDGE_OPEN, open);
297 * Open the given study in the current HTTP session. Replace the previose one in the session if any.
301 * @return OpenStudy wrapper object
303 protected OpenStudy open(final Study study) {
304 OpenStudy open = _openStudy.open(getConnectedUser(), study); // The connected user may be null
306 closeStudy(); // Just in case
307 _session.put(STUDY_OPEN, open);
312 * Initialization the Context for menubar and toolbar.
314 public void initializationContext() {
315 getMenuBarSettings().initializeInitialMenuProperties();
317 if (_session.get(STUDY_OPEN) == null) {
318 getMenuBarSettings().setIsStudyNull(true);
320 getMenuBarSettings().setIsStudyNull(false);
322 // for initialization ToolBarSettings.canUserEdit property
323 // and ToolBarSettings.isEnabledScript property.
325 OpenStudy currentStudy = (OpenStudy) _session.get(STUDY_OPEN);
326 PopupMenu popup = currentStudy.getPopup();
327 StudyRights user = currentStudy.getStudyRights();
329 if (user.canEditProperties()) {
330 getToolBarSettings().setCanUserEdit(true);
332 getToolBarSettings().setCanUserEdit(false);
336 getToolBarSettings().setIsEnabledScript(false);
337 } else if (popup.isEnabled("script")) {
338 getToolBarSettings().setIsEnabledScript(true);
340 getToolBarSettings().setIsEnabledScript(false);
344 if (_session.get(KNOWLEDGE_OPEN) == null) {
345 getMenuBarSettings().setIsKnowledgeNull(true);
347 getMenuBarSettings().setIsKnowledgeNull(false);
350 ApplicationRights userRights = (ApplicationRights) _session
353 if ((userRights != null) && userRights.canCreateStudy()) {
354 getMenuBarSettings().setCanUserCreateStudy(true);
356 getMenuBarSettings().setCanUserCreateStudy(false);
359 if ((userRights != null) && userRights.canManageDatabase()) {
360 getMenuBarSettings().setCanUserManageDatabase(true);
362 getMenuBarSettings().setCanUserManageDatabase(false);
368 * Initialization the Context for left menu.
370 * @param leftMenuProperty -
371 * the property of the left menu.
373 public void initializationContextLeftMenus(final String leftMenuProperty) {
375 Menu menu = (Menu) _session.get("menu." + leftMenuProperty);
377 getLeftMenuSettings().setMenu(menu);
379 getLeftMenuSettings().setMenuName(menu.getName());
380 getLeftMenuSettings().setMenuNamespace(menu.getNamespace());
384 * Initialization the Context for Menu Bar and Tool Bar.
386 * @param titleProperty -
387 * The title of the open study/knowledge.
388 * @param editDisabledProperty -
389 * Property that indicates whether the current open study is editable or not.
391 public void initializationContext(final String titleProperty,
392 final String editDisabledProperty) {
394 initializationContext();
396 AbstractOpenObject entity = (AbstractOpenObject) _session.get(titleProperty + ".open");
398 getTitleBarSettings().setProgressState(
399 entity.getProgressState().toString());
400 getTitleBarSettings().setSelectionState(entity.getSelection());
401 getTitleBarSettings().setEntryType(entity.getType().toLowerCase());
402 getTitleBarSettings().setEntryTypeTitle(entity.getType());
403 getTitleBarSettings().setEntryTitle(entity.getTitle());
404 getTitleBarSettings().setEditDisabledProperty(editDisabledProperty);
408 * Initialization of the screen context for menu bar.
410 * @param menuProperty -
411 * the property of the menu bar.
413 public void initializationScreenContext(final String menuProperty) {
415 initializationContext();
416 getMenuBarSettings().intializeMenuBar(menuProperty);
420 * Initialization of the screen context for menu bar and title bar.
422 * @param menuProperty -
423 * the property of the menu bar.
424 * @param titleProperty -
425 * The title of the open study/knowledge.
426 * @param editDisabledProperty -
427 * Property that indicates whether the current open study is editable or not.
429 public void initializationScreenContext(final String menuProperty,
430 final String titleProperty, final String editDisabledProperty) {
432 initializationContext(titleProperty, editDisabledProperty);
433 getMenuBarSettings().intializeMenuBar(menuProperty);
437 * Initialization of the screen context for menu bar, title bar and tool bar.
439 * @param menuProperty -
440 * the property of the menu bar.
441 * @param titleProperty -
442 * The title of the open study/knowledge.
443 * @param editDisabledProperty -
444 * Property that indicates whether the current open study is editable or not.
445 * @param toolProperty -
446 * the property of the tool bar.
448 public void initializationScreenContext(final String menuProperty,
449 final String titleProperty, final String editDisabledProperty,
450 final String toolProperty) {
452 initializationScreenContext(menuProperty, titleProperty,
453 editDisabledProperty);
454 getToolBarSettings().intializeMenuBar(toolProperty);
458 * Initialization of the screen context for menu bar and tool bar.
460 * @param menuProperty -
461 * the property of the menu bar.
462 * @param toolProperty -
463 * the property of the tool bar.
465 public void initializationScreenContext(final String menuProperty,
466 final String toolProperty) {
468 initializationContext();
469 getMenuBarSettings().intializeMenuBar(menuProperty);
470 getToolBarSettings().intializeMenuBar(toolProperty);
474 * Initialization of the screen context for menu bar, title bar and tool bar.
476 * @param menuProperty -
477 * the property of the menu bar.
478 * @param titleProperty -
479 * The title of the open study/knowledge.
480 * @param editDisabledProperty -
481 * Property that indicates whether the current open study is editable or not.
482 * @param toolProperty -
483 * the property of the tool bar.
484 * @param leftMenuProperty -
485 * the property of the left menu.
487 public void initializationFullScreenContext(final String menuProperty,
488 final String titleProperty, final String editDisabledProperty,
489 final String toolProperty, final String leftMenuProperty) {
491 initializationScreenContext(menuProperty, titleProperty,
492 editDisabledProperty);
493 initializationContextLeftMenus(leftMenuProperty);
494 getToolBarSettings().intializeMenuBar(toolProperty);
498 * Initialization of the screen context for menu bar and tool bar.
500 * @param menuProperty -
501 * the property of the menu bar.
502 * @param toolProperty -
503 * the property of the tool bar.
504 * @param leftMenuProperty -
505 * the property of the left menu.
507 public void initializationFullScreenContext(final String menuProperty,
508 final String toolProperty, final String leftMenuProperty) {
510 initializationContext();
511 initializationContextLeftMenus(leftMenuProperty);
512 getMenuBarSettings().intializeMenuBar(menuProperty);
513 getToolBarSettings().intializeMenuBar(toolProperty);
516 // ==============================================================================================================================
517 // Getters and setters
518 // ==============================================================================================================================
523 * @see org.apache.struts2.interceptor.ServletRequestAware#setServletRequest(javax.servlet.http.HttpServletRequest)
525 public void setServletRequest(final HttpServletRequest request) {
526 this._servletRequest = request;
530 * Get current HTTP request.
532 * @return HTTP request
534 public HttpServletRequest getServletRequest() {
535 return _servletRequest;
539 * Get current error code.
543 public String getErrorCode() {
550 * @return session map
552 public Map<String, Object> getSession() {
560 * the error code to set
562 public void setErrorCode(final String code) {
563 this._errorCode = code;
569 * @see org.apache.struts2.interceptor.SessionAware#setSession(java.util.Map)
571 public void setSession(final Map<String, Object> session) {
572 this._session = session;
576 * Get the menuBarSettings.
578 * @return the menuBarSettings
580 public MenuBarSettings getMenuBarSettings() {
581 return _menuBarSettings;
585 * Set the menuBarSettings.
587 * @param menuBarSettings
588 * the menuBarSettings to set
590 public void setMenuBarSettings(final MenuBarSettings menuBarSettings) {
591 _menuBarSettings = menuBarSettings;
595 * Get the _titleBarSettings.
597 * @return the _titleBarSettings
599 public TitleBarSettings getTitleBarSettings() {
600 return _titleBarSettings;
604 * Set the titleBarSettings.
606 * @param titleBarSettings
607 * the titleBarSettings to set
609 public void setTitleBarSettings(final TitleBarSettings titleBarSettings) {
610 _titleBarSettings = titleBarSettings;
614 * Get the toolBarSettings.
616 * @return the toolBarSettings
618 public final ToolBarSettings getToolBarSettings() {
619 return _toolBarSettings;
623 * Set the toolBarSettings.
625 * @param toolBarSettings
626 * the toolBarSettings to set
628 public final void setToolBarSettings(final ToolBarSettings toolBarSettings) {
629 _toolBarSettings = toolBarSettings;
633 * Get the applicationSettings.
635 * @return the applicationSettings
637 public ApplicationSettings getApplicationSettings() {
638 return _applicationSettings;
642 * Set the applicationSettings.
644 * @param applicationSettings
645 * the applicationSettings to set
647 public void setApplicationSettings(
648 final ApplicationSettings applicationSettings) {
649 _applicationSettings = applicationSettings;
653 * Get the leftMenuSettings.
655 * @return the leftMenuSettings
657 public LeftMenuSettings getLeftMenuSettings() {
658 return _leftMenuSettings;
662 * Get the staticMenu.
664 * @return the staticMenu
666 public static Menu getStaticMenu() {
671 * Set the staticMenu.
674 * the staticMenu to set
676 public static void setStaticMenu(final Menu staticMenu) {
677 Action.staticMenu = staticMenu;
681 * Set the leftMenuSettings.
683 * @param leftMenuSettings
684 * the leftMenuSettings to set
686 public void setLeftMenuSettings(final LeftMenuSettings leftMenuSettings) {
687 _leftMenuSettings = leftMenuSettings;