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 public User getConnectedUser () {
139 ApplicationRights rights = (ApplicationRights)session.get("user.rights");
140 User connected = null;
141 if (rights != null) {
142 connected = rights.getUser();
144 return connected; // May be null
146 protected Menu getMenu (String name) {
147 return (Menu)session.get("menu." + name);
149 public void setOpenKnowledge (OpenKnowledge kelm) {
150 _openKnowledge = kelm;
152 protected OpenKnowledge getOpenKnowledge () {
153 // _openKnowledge = (OpenKnowledge)session.get("knowledge.open"); // May be null
154 return _openKnowledge;
156 public void setOpenStudy (OpenStudy aStudy) {
159 public OpenStudy getOpenStudy () {
160 // _openStudy = (OpenStudy)session.get("study.open");
161 return _openStudy; // May be null
163 protected OpenKnowledge open (KnowledgeElement kelm) {
164 OpenKnowledge open = _openKnowledge.open(kelm);
166 closeKnowledge(); // Just in case
167 session.put("knowledge.open", open);
170 protected OpenStudy open (Study study) {
171 OpenStudy open = _openStudy.open(getConnectedUser(), study); // The connected user may be null
173 closeStudy(); // Just in case
174 session.put("study.open", open);
179 * Initialization the Context for menubar.
181 public void initializationContext() {
182 getMenuBarSettings().initializeInitialMenuProperties();
184 if (session.get("study.open") == null) {
185 getMenuBarSettings().setIsStudyNull(true);
187 getMenuBarSettings().setIsStudyNull(false);
189 //for initialization ToolBarSettings.canUserEdit property
190 // and ToolBarSettings.isEnabledScript property.
192 OpenStudy currentStudy = (OpenStudy)session.get("study.open");
193 PopupMenu popup = currentStudy.getPopup();
194 StudyRights user = currentStudy.getStudyRights();
196 if(user.canEditProperties()) {
197 getToolBarSettings().setCanUserEdit(true);
199 getToolBarSettings().setCanUserEdit(false);
203 getToolBarSettings().setIsEnabledScript(false);
204 } else if (popup.isEnabled("script")) {
205 getToolBarSettings().setIsEnabledScript(true);
207 getToolBarSettings().setIsEnabledScript(false);
211 if (session.get("knowledge.open") == null) {
212 getMenuBarSettings().setIsKnowledgeNull(true);
214 getMenuBarSettings().setIsKnowledgeNull(false);
217 ApplicationRights userRights = (ApplicationRights)session.get("user.rights");
219 if ((userRights != null) && userRights.canCreateStudy()) {
220 getMenuBarSettings().setCanUserCreateStudy(true);
222 getMenuBarSettings().setCanUserCreateStudy(false);
225 if ((userRights != null) && userRights.canManageDatabase()) {
226 getMenuBarSettings().setCanUserManageDatabase(true);
228 getMenuBarSettings().setCanUserManageDatabase(false);
234 * Initialization the Context for Menu Bar and Tool Bar.
236 * @param titleProperty - The title of the open study/knowledge.
237 * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
239 public void initializationContext(final String titleProperty, final String editDisabledProperty) {
241 initializationContext();
243 OpenObject entity = (OpenObject)session.get(titleProperty + ".open");
245 getTitleBarSettings().setProgressState(entity.getProgressState().toString());
246 getTitleBarSettings().setSelectionState(entity.getSelection());
247 getTitleBarSettings().setEntryType(entity.getType().toLowerCase());
248 getTitleBarSettings().setEntryTypeTitle(entity.getType());
249 getTitleBarSettings().setEntryTitle(entity.getTitle());
250 getTitleBarSettings().setEditDisabledProperty(editDisabledProperty);
254 * Initialization of the screen context for menu bar.
256 * @param menuProperty - the property of the menu bar.
258 public void initializationScreenContext(final String menuProperty) {
260 initializationContext();
261 getMenuBarSettings().intializeMenuBar(menuProperty);
265 * Initialization of the screen context for menu bar and title bar.
267 * @param menuProperty - the property of the menu bar.
268 * @param titleProperty - The title of the open study/knowledge.
269 * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
271 public void initializationScreenContext(final String menuProperty,
272 final String titleProperty, final String editDisabledProperty) {
274 initializationContext(titleProperty, editDisabledProperty);
275 getMenuBarSettings().intializeMenuBar(menuProperty);
279 * Initialization of the screen context for menu bar, title bar and tool bar.
281 * @param menuProperty - the property of the menu bar.
282 * @param titleProperty - The title of the open study/knowledge.
283 * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
284 * @param toolProperty - the property of the tool bar.
286 public void initializationScreenContext(final String menuProperty,
287 final String titleProperty, final String editDisabledProperty,
288 final String toolProperty) {
290 initializationScreenContext(menuProperty, titleProperty, editDisabledProperty);
291 getToolBarSettings().intializeMenuBar(toolProperty);
295 * Initialization of the screen context for menu bar and tool bar.
297 * @param menuProperty - the property of the menu bar.
298 * @param toolProperty - the property of the tool bar.
300 public void initializationScreenContext(final String menuProperty,
301 final String toolProperty) {
303 initializationContext();
304 getMenuBarSettings().intializeMenuBar(menuProperty);
305 getToolBarSettings().intializeMenuBar(toolProperty);
307 // ==============================================================================================================================
308 // Getters and setters
309 // ==============================================================================================================================
311 public void setServletRequest (HttpServletRequest request) {
312 this.request = request;
315 public HttpServletRequest getServletRequest() {
319 public String getErrorCode () {
322 public Map<String, Object> getSession () {
326 public void setErrorCode (String code) {
329 public void setSession (Map<String, Object> session) {
330 this.session = session;
334 * Get the menuBarSettings.
335 * @return the menuBarSettings
337 public MenuBarSettings getMenuBarSettings() {
338 return _menuBarSettings;
342 * Set the menuBarSettings.
343 * @param menuBarSettings the menuBarSettings to set
345 public void setMenuBarSettings(final MenuBarSettings menuBarSettings) {
346 _menuBarSettings = menuBarSettings;
350 * Get the _titleBarSettings.
351 * @return the _titleBarSettings
353 public TitleBarSettings getTitleBarSettings() {
354 return _titleBarSettings;
357 * Set the titleBarSettings.
358 * @param titleBarSettings the titleBarSettings to set
360 public void setTitleBarSettings(TitleBarSettings titleBarSettings) {
361 _titleBarSettings = titleBarSettings;
364 * Get the toolBarSettings.
365 * @return the toolBarSettings
367 public final ToolBarSettings getToolBarSettings() {
368 return _toolBarSettings;
371 * Set the toolBarSettings.
372 * @param toolBarSettings the toolBarSettings to set
374 public final void setToolBarSettings(ToolBarSettings toolBarSettings) {
375 _toolBarSettings = toolBarSettings;
379 * Get the applicationSettings.
380 * @return the applicationSettings
382 public ApplicationSettings getApplicationSettings() {
383 return _applicationSettings;
386 * Set the applicationSettings.
387 * @param applicationSettings the applicationSettings to set
389 public void setApplicationSettings(ApplicationSettings applicationSettings) {
390 _applicationSettings = applicationSettings;