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.service.dto.KnowledgeElementDTO;
17 import org.splat.som.ApplicationRights;
18 import org.splat.som.StudyRights;
19 import org.splat.dal.bo.som.KnowledgeElement;
20 import org.splat.dal.bo.som.SimulationContextType;
21 import org.splat.dal.bo.som.Study;
22 import org.splat.dal.bo.som.DocumentType;
23 import org.splat.wapp.Menu;
24 import org.splat.wapp.PopupMenu;
30 public class Action extends ActionSupport implements ServletRequestAware, SessionAware {
35 private static final long serialVersionUID = -895295026709526501L;
39 protected static final Logger logger = Logger.getLogger(Action.class);
42 * Http servlet request.
44 private HttpServletRequest request;
46 * Http session container.
48 private Map<String, Object> session;
52 private String mercode;
54 * Current open study facade object.
56 private OpenStudy _openStudy;
58 * Current open knowledge facade object.
60 private OpenKnowledge _openKnowledge;
64 * MenuBarSettings bean.
66 private MenuBarSettings _menuBarSettings;
69 * TitleBarSettings bean.
71 private TitleBarSettings _titleBarSettings;
73 * ToolBarSettings bean.
75 private ToolBarSettings _toolBarSettings;
78 * LeftMenuSettings bean.
80 private LeftMenuSettings _leftMenuSettings;
83 * Injected application settings bean.
85 private ApplicationSettings _applicationSettings;
89 * It's temporary solution for menuitem.jsp
91 private static Menu staticMenu;
93 public class DocumentTypeComparator implements Comparator<DocumentType> {
94 public int compare(DocumentType t1, DocumentType t2)
96 ResourceBundle locale = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale());
97 String name1 = t1.getName();
98 if (t1.isApproved()) name1 = locale.getString("type.document." + name1);
99 String name2 = t2.getName();
100 if (t2.isApproved()) name2 = locale.getString("type.document." + name2);
102 return name1.compareToIgnoreCase(name2);
105 public class ContextTypeComparator implements Comparator<SimulationContextType> {
106 public int compare(SimulationContextType t1, SimulationContextType t2)
108 ResourceBundle locale = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale());
109 String name1 = t1.getName();
110 if (t1.isApproved()) name1 = locale.getString("type.context." + name1);
111 String name2 = t2.getName();
112 if (t2.isApproved()) name2 = locale.getString("type.context." + name2);
114 return name1.compareToIgnoreCase(name2);
118 // ==============================================================================================================================
120 // ==============================================================================================================================
122 protected void closeKnowledge () {
123 OpenObject open = (OpenObject)session.remove("knowledge.open");
125 if (session.get("study.open") == null) open.clearFacades(); // For eventually reopening the knowledge from a fresh context
128 protected void closeStudy () {
129 OpenObject open = (OpenObject)session.remove("study.open");
131 if (session.get("knowledge.open") == null) open.clearFacades(); // For eventually reopening the study from a fresh context
134 protected void connect (LoginContext context, User user) {
135 OpenStudy open = getOpenStudy();
137 open.changeUser(user);
139 session.put("user.rights", new ApplicationRights(user) );
140 session.put("login.context", context); // For executing the deconnection, when requested
142 protected void disconnect () {
143 OpenStudy open = getOpenStudy();
145 open.changeUser(null);
147 session.put("user.rights", new ApplicationRights(null) ); // Disables user rights
148 session.remove("login.context");
150 public User getConnectedUser () {
151 ApplicationRights rights = (ApplicationRights)session.get("user.rights");
152 User connected = null;
153 if (rights != null) {
154 connected = rights.getUser();
156 return connected; // May be null
158 protected Menu getMenu (String name) {
159 return (Menu)session.get("menu." + name);
161 public void setOpenKnowledge (OpenKnowledge kelm) {
162 _openKnowledge = kelm;
164 protected OpenKnowledge getOpenKnowledge () {
165 // _openKnowledge = (OpenKnowledge)session.get("knowledge.open"); // May be null
166 return _openKnowledge;
168 public void setOpenStudy (OpenStudy aStudy) {
171 public OpenStudy getOpenStudy () {
172 // _openStudy = (OpenStudy)session.get("study.open");
173 return _openStudy; // May be null
175 protected OpenKnowledge open (KnowledgeElementDTO kelm) {
176 OpenKnowledge open = _openKnowledge.open(kelm);
178 closeKnowledge(); // Just in case
179 session.put("knowledge.open", open);
182 protected OpenStudy open (Study study) {
183 OpenStudy open = _openStudy.open(getConnectedUser(), study); // The connected user may be null
185 closeStudy(); // Just in case
186 session.put("study.open", open);
191 * Initialization the Context for menubar and toolbar.
193 public void initializationContext() {
194 getMenuBarSettings().initializeInitialMenuProperties();
196 if (session.get("study.open") == null) {
197 getMenuBarSettings().setIsStudyNull(true);
199 getMenuBarSettings().setIsStudyNull(false);
201 //for initialization ToolBarSettings.canUserEdit property
202 // and ToolBarSettings.isEnabledScript property.
204 OpenStudy currentStudy = (OpenStudy)session.get("study.open");
205 PopupMenu popup = currentStudy.getPopup();
206 StudyRights user = currentStudy.getStudyRights();
208 if(user.canEditProperties()) {
209 getToolBarSettings().setCanUserEdit(true);
211 getToolBarSettings().setCanUserEdit(false);
215 getToolBarSettings().setIsEnabledScript(false);
216 } else if (popup.isEnabled("script")) {
217 getToolBarSettings().setIsEnabledScript(true);
219 getToolBarSettings().setIsEnabledScript(false);
223 if (session.get("knowledge.open") == null) {
224 getMenuBarSettings().setIsKnowledgeNull(true);
226 getMenuBarSettings().setIsKnowledgeNull(false);
229 ApplicationRights userRights = (ApplicationRights)session.get("user.rights");
231 if ((userRights != null) && userRights.canCreateStudy()) {
232 getMenuBarSettings().setCanUserCreateStudy(true);
234 getMenuBarSettings().setCanUserCreateStudy(false);
237 if ((userRights != null) && userRights.canManageDatabase()) {
238 getMenuBarSettings().setCanUserManageDatabase(true);
240 getMenuBarSettings().setCanUserManageDatabase(false);
246 * Initialization the Context for left menu.
247 * @param leftMenuProperty - the property of the left menu.
249 public void initializationContextLeftMenus(final String leftMenuProperty) {
251 Menu menu = (Menu)session.get("menu." + leftMenuProperty);
253 getLeftMenuSettings().setMenu(menu);
255 getLeftMenuSettings().setMenuName(menu.getName());
256 getLeftMenuSettings().setMenuNamespace(menu.getNamespace());
260 * Initialization the Context for Menu Bar and Tool Bar.
262 * @param titleProperty - The title of the open study/knowledge.
263 * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
265 public void initializationContext(final String titleProperty, final String editDisabledProperty) {
267 initializationContext();
269 OpenObject entity = (OpenObject)session.get(titleProperty + ".open");
271 getTitleBarSettings().setProgressState(entity.getProgressState().toString());
272 getTitleBarSettings().setSelectionState(entity.getSelection());
273 getTitleBarSettings().setEntryType(entity.getType().toLowerCase());
274 getTitleBarSettings().setEntryTypeTitle(entity.getType());
275 getTitleBarSettings().setEntryTitle(entity.getTitle());
276 getTitleBarSettings().setEditDisabledProperty(editDisabledProperty);
280 * Initialization of the screen context for menu bar.
282 * @param menuProperty - the property of the menu bar.
284 public void initializationScreenContext(final String menuProperty) {
286 initializationContext();
287 getMenuBarSettings().intializeMenuBar(menuProperty);
291 * Initialization of the screen context for menu bar and title bar.
293 * @param menuProperty - the property of the menu bar.
294 * @param titleProperty - The title of the open study/knowledge.
295 * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
297 public void initializationScreenContext(final String menuProperty,
298 final String titleProperty, final String editDisabledProperty) {
300 initializationContext(titleProperty, editDisabledProperty);
301 getMenuBarSettings().intializeMenuBar(menuProperty);
305 * Initialization of the screen context for menu bar, title bar and tool bar.
307 * @param menuProperty - the property of the menu bar.
308 * @param titleProperty - The title of the open study/knowledge.
309 * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
310 * @param toolProperty - the property of the tool bar.
312 public void initializationScreenContext(final String menuProperty,
313 final String titleProperty, final String editDisabledProperty,
314 final String toolProperty) {
316 initializationScreenContext(menuProperty, titleProperty, editDisabledProperty);
317 getToolBarSettings().intializeMenuBar(toolProperty);
321 * Initialization of the screen context for menu bar and tool bar.
323 * @param menuProperty - the property of the menu bar.
324 * @param toolProperty - the property of the tool bar.
326 public void initializationScreenContext(final String menuProperty,
327 final String toolProperty) {
329 initializationContext();
330 getMenuBarSettings().intializeMenuBar(menuProperty);
331 getToolBarSettings().intializeMenuBar(toolProperty);
335 * Initialization of the screen context for menu bar, title bar and tool bar.
337 * @param menuProperty - the property of the menu bar.
338 * @param titleProperty - The title of the open study/knowledge.
339 * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
340 * @param toolProperty - the property of the tool bar.
341 * @param leftMenuProperty - the property of the left menu.
343 public void initializationFullScreenContext(final String menuProperty,
344 final String titleProperty, final String editDisabledProperty,
345 final String toolProperty, final String leftMenuProperty) {
347 initializationScreenContext(menuProperty, titleProperty, editDisabledProperty);
348 initializationContextLeftMenus(leftMenuProperty);
349 getToolBarSettings().intializeMenuBar(toolProperty);
353 * Initialization of the screen context for menu bar and tool bar.
355 * @param menuProperty - the property of the menu bar.
356 * @param toolProperty - the property of the tool bar.
357 * @param leftMenuProperty - the property of the left menu.
359 public void initializationFullScreenContext(final String menuProperty,
360 final String toolProperty, final String leftMenuProperty) {
362 initializationContext();
363 initializationContextLeftMenus(leftMenuProperty);
364 getMenuBarSettings().intializeMenuBar(menuProperty);
365 getToolBarSettings().intializeMenuBar(toolProperty);
367 // ==============================================================================================================================
368 // Getters and setters
369 // ==============================================================================================================================
371 public void setServletRequest (HttpServletRequest request) {
372 this.request = request;
375 public HttpServletRequest getServletRequest() {
379 public String getErrorCode () {
382 public Map<String, Object> getSession () {
386 public void setErrorCode (String code) {
389 public void setSession (Map<String, Object> session) {
390 this.session = session;
394 * Get the menuBarSettings.
395 * @return the menuBarSettings
397 public MenuBarSettings getMenuBarSettings() {
398 return _menuBarSettings;
402 * Set the menuBarSettings.
403 * @param menuBarSettings the menuBarSettings to set
405 public void setMenuBarSettings(final MenuBarSettings menuBarSettings) {
406 _menuBarSettings = menuBarSettings;
410 * Get the _titleBarSettings.
411 * @return the _titleBarSettings
413 public TitleBarSettings getTitleBarSettings() {
414 return _titleBarSettings;
417 * Set the titleBarSettings.
418 * @param titleBarSettings the titleBarSettings to set
420 public void setTitleBarSettings(TitleBarSettings titleBarSettings) {
421 _titleBarSettings = titleBarSettings;
424 * Get the toolBarSettings.
425 * @return the toolBarSettings
427 public final ToolBarSettings getToolBarSettings() {
428 return _toolBarSettings;
431 * Set the toolBarSettings.
432 * @param toolBarSettings the toolBarSettings to set
434 public final void setToolBarSettings(ToolBarSettings toolBarSettings) {
435 _toolBarSettings = toolBarSettings;
439 * Get the applicationSettings.
440 * @return the applicationSettings
442 public ApplicationSettings getApplicationSettings() {
443 return _applicationSettings;
446 * Set the applicationSettings.
447 * @param applicationSettings the applicationSettings to set
449 public void setApplicationSettings(ApplicationSettings applicationSettings) {
450 _applicationSettings = applicationSettings;
453 * Get the leftMenuSettings.
454 * @return the leftMenuSettings
456 public LeftMenuSettings getLeftMenuSettings() {
457 return _leftMenuSettings;
461 * Get the staticMenu.
462 * @return the staticMenu
464 public static Menu getStaticMenu() {
468 * Set the staticMenu.
469 * @param staticMenu the staticMenu to set
471 public static void setStaticMenu(Menu staticMenu) {
472 Action.staticMenu = staticMenu;
475 * Set the leftMenuSettings.
476 * @param leftMenuSettings the leftMenuSettings to set
478 public void setLeftMenuSettings(LeftMenuSettings leftMenuSettings) {
479 _leftMenuSettings = leftMenuSettings;