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 * Injected application settings bean.
79 private ApplicationSettings _applicationSettings;
81 public class DocumentTypeComparator implements Comparator<DocumentType> {
82 public int compare(DocumentType t1, DocumentType t2)
84 ResourceBundle locale = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale());
85 String name1 = t1.getName();
86 if (t1.isApproved()) name1 = locale.getString("type.document." + name1);
87 String name2 = t2.getName();
88 if (t2.isApproved()) name2 = locale.getString("type.document." + name2);
90 return name1.compareToIgnoreCase(name2);
93 public class ContextTypeComparator implements Comparator<SimulationContextType> {
94 public int compare(SimulationContextType t1, SimulationContextType t2)
96 ResourceBundle locale = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale());
97 String name1 = t1.getName();
98 if (t1.isApproved()) name1 = locale.getString("type.context." + name1);
99 String name2 = t2.getName();
100 if (t2.isApproved()) name2 = locale.getString("type.context." + name2);
102 return name1.compareToIgnoreCase(name2);
106 // ==============================================================================================================================
108 // ==============================================================================================================================
110 protected void closeKnowledge () {
111 OpenObject open = (OpenObject)session.remove("knowledge.open");
113 if (session.get("study.open") == null) open.clearFacades(); // For eventually reopening the knowledge from a fresh context
116 protected void closeStudy () {
117 OpenObject open = (OpenObject)session.remove("study.open");
119 if (session.get("knowledge.open") == null) open.clearFacades(); // For eventually reopening the study from a fresh context
122 protected void connect (LoginContext context, User user) {
123 OpenStudy open = getOpenStudy();
125 open.changeUser(user);
127 session.put("user.rights", new ApplicationRights(user) );
128 session.put("login.context", context); // For executing the deconnection, when requested
130 protected void disconnect () {
131 OpenStudy open = getOpenStudy();
133 open.changeUser(null);
135 session.put("user.rights", new ApplicationRights(null) ); // Disables user rights
136 session.remove("login.context");
138 protected User getConnectedUser () {
139 ApplicationRights rights = (ApplicationRights)session.get("user.rights");
140 return rights.getUser(); // May be null
142 protected Menu getMenu (String name) {
143 return (Menu)session.get("menu." + name);
145 public void setOpenKnowledge (OpenKnowledge kelm) {
146 _openKnowledge = kelm;
148 protected OpenKnowledge getOpenKnowledge () {
149 // _openKnowledge = (OpenKnowledge)session.get("knowledge.open"); // May be null
150 return _openKnowledge;
152 public void setOpenStudy (OpenStudy aStudy) {
155 public OpenStudy getOpenStudy () {
156 // _openStudy = (OpenStudy)session.get("study.open");
157 return _openStudy; // May be null
159 protected OpenKnowledge open (KnowledgeElement kelm) {
160 OpenKnowledge open = _openKnowledge.open(kelm);
162 closeKnowledge(); // Just in case
163 session.put("knowledge.open", open);
166 protected OpenStudy open (Study study) {
167 OpenStudy open = _openStudy.open(getConnectedUser(), study); // The connected user may be null
169 closeStudy(); // Just in case
170 session.put("study.open", open);
175 * Initialization the Context for menubar.
177 public void initializationContext() {
178 getMenuBarSettings().initializeInitialMenuProperties();
180 if (session.get("study.open") == null) {
181 getMenuBarSettings().setIsStudyNull(true);
183 getMenuBarSettings().setIsStudyNull(false);
185 //for initialization ToolBarSettings.canUserEdit property
186 // and ToolBarSettings.isEnabledScript property.
188 OpenStudy currentStudy = (OpenStudy)session.get("study.open");
189 PopupMenu popup = currentStudy.getPopup();
190 StudyRights user = currentStudy.getStudyRights();
192 if(user.canEditProperties()) {
193 getToolBarSettings().setCanUserEdit(true);
195 getToolBarSettings().setCanUserEdit(false);
199 getToolBarSettings().setIsEnabledScript(false);
200 } else if (popup.isEnabled("script")) {
201 getToolBarSettings().setIsEnabledScript(true);
203 getToolBarSettings().setIsEnabledScript(false);
207 if (session.get("knowledge.open") == null) {
208 getMenuBarSettings().setIsKnowledgeNull(true);
210 getMenuBarSettings().setIsKnowledgeNull(false);
213 ApplicationRights userRights = (ApplicationRights)session.get("user.rights");
215 if (userRights.canCreateStudy()) {
216 getMenuBarSettings().setCanUserCreateStudy(true);
218 getMenuBarSettings().setCanUserCreateStudy(false);
221 if (userRights.canManageDatabase()) {
222 getMenuBarSettings().setCanUserManageDatabase(true);
224 getMenuBarSettings().setCanUserManageDatabase(false);
230 * Initialization the Context for Menu Bar and Tool Bar.
232 * @param titleProperty - The title of the open study/knowledge.
233 * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
235 public void initializationContext(final String titleProperty, final String editDisabledProperty) {
237 initializationContext();
239 OpenObject entity = (OpenObject)session.get(titleProperty + ".open");
241 getTitleBarSettings().setProgressState(entity.getProgressState().toString());
242 getTitleBarSettings().setSelectionState(entity.getSelection());
243 getTitleBarSettings().setEntryType(entity.getType().toLowerCase());
244 getTitleBarSettings().setEntryTypeTitle(entity.getType());
245 getTitleBarSettings().setEntryTitle(entity.getTitle());
246 getTitleBarSettings().setEditDisabledProperty(editDisabledProperty);
250 * Initialization of the screen context for menu bar.
252 * @param menuProperty - the property of the menu bar.
254 public void initializationScreenContext(final String menuProperty) {
256 initializationContext();
257 getMenuBarSettings().intializeMenuBar(menuProperty);
261 * Initialization of the screen context for menu bar and title bar.
263 * @param menuProperty - the property of the menu bar.
264 * @param titleProperty - The title of the open study/knowledge.
265 * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
267 public void initializationScreenContext(final String menuProperty,
268 final String titleProperty, final String editDisabledProperty) {
270 initializationContext(titleProperty, editDisabledProperty);
271 getMenuBarSettings().intializeMenuBar(menuProperty);
275 * Initialization of the screen context for menu bar, title bar and tool bar.
277 * @param menuProperty - the property of the menu bar.
278 * @param titleProperty - The title of the open study/knowledge.
279 * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
280 * @param toolProperty - the property of the tool bar.
282 public void initializationScreenContext(final String menuProperty,
283 final String titleProperty, final String editDisabledProperty,
284 final String toolProperty) {
286 initializationScreenContext(menuProperty, titleProperty, editDisabledProperty);
287 getToolBarSettings().intializeMenuBar(toolProperty);
291 * Initialization of the screen context for menu bar and tool bar.
293 * @param menuProperty - the property of the menu bar.
294 * @param toolProperty - the property of the tool bar.
296 public void initializationScreenContext(final String menuProperty,
297 final String toolProperty) {
299 initializationContext();
300 getMenuBarSettings().intializeMenuBar(menuProperty);
301 getToolBarSettings().intializeMenuBar(toolProperty);
303 // ==============================================================================================================================
304 // Getters and setters
305 // ==============================================================================================================================
307 public void setServletRequest (HttpServletRequest request) {
308 this.request = request;
311 public HttpServletRequest getServletRequest() {
315 public String getErrorCode () {
318 public Map<String, Object> getSession () {
322 public void setErrorCode (String code) {
325 public void setSession (Map<String, Object> session) {
326 this.session = session;
330 * Get the menuBarSettings.
331 * @return the menuBarSettings
333 public MenuBarSettings getMenuBarSettings() {
334 return _menuBarSettings;
338 * Set the menuBarSettings.
339 * @param menuBarSettings the menuBarSettings to set
341 public void setMenuBarSettings(final MenuBarSettings menuBarSettings) {
342 _menuBarSettings = menuBarSettings;
346 * Get the _titleBarSettings.
347 * @return the _titleBarSettings
349 public TitleBarSettings getTitleBarSettings() {
350 return _titleBarSettings;
353 * Set the titleBarSettings.
354 * @param titleBarSettings the titleBarSettings to set
356 public void setTitleBarSettings(TitleBarSettings titleBarSettings) {
357 _titleBarSettings = titleBarSettings;
360 * Get the toolBarSettings.
361 * @return the toolBarSettings
363 public final ToolBarSettings getToolBarSettings() {
364 return _toolBarSettings;
367 * Set the toolBarSettings.
368 * @param toolBarSettings the toolBarSettings to set
370 public final void setToolBarSettings(ToolBarSettings toolBarSettings) {
371 _toolBarSettings = toolBarSettings;
375 * Get the applicationSettings.
376 * @return the applicationSettings
378 public ApplicationSettings getApplicationSettings() {
379 return _applicationSettings;
382 * Set the applicationSettings.
383 * @param applicationSettings the applicationSettings to set
385 public void setApplicationSettings(ApplicationSettings applicationSettings) {
386 _applicationSettings = applicationSettings;