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.ServletActionContext;
13 import org.apache.struts2.interceptor.ServletRequestAware;
14 import org.apache.struts2.interceptor.SessionAware;
15 import org.apache.log4j.Logger;
16 import org.splat.dal.bo.kernel.User;
17 import org.splat.som.ApplicationRights;
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;
25 public class Action extends ActionSupport implements ServletRequestAware, SessionAware {
27 private Map<String, Object> session;
28 private String mercode;
29 private OpenStudy _openStudy;
30 private OpenKnowledge _openKnowledge;
33 * MenuBarSettings bean.
35 private MenuBarSettings _menuBarSettings;
38 * TitleBarSettings bean.
40 private TitleBarSettings _titleBarSettings;
42 private HttpServletRequest request;
47 private static final long serialVersionUID = -895295026709526501L;
51 protected static final Logger logger = Logger.getLogger(Action.class);
53 public class DocumentTypeComparator implements Comparator<DocumentType> {
54 // -----------------------------------------------------------------------
55 public int compare(DocumentType t1, DocumentType t2)
57 ResourceBundle locale = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale());
58 String name1 = t1.getName();
59 if (t1.isApproved()) name1 = locale.getString("type.document." + name1);
60 String name2 = t2.getName();
61 if (t2.isApproved()) name2 = locale.getString("type.document." + name2);
63 return name1.compareToIgnoreCase(name2);
66 public class ContextTypeComparator implements Comparator<SimulationContextType> {
67 // --------------------------------------------------------------------------------
68 public int compare(SimulationContextType t1, SimulationContextType t2)
70 ResourceBundle locale = ResourceBundle.getBundle("som", ApplicationSettings.getCurrentLocale());
71 String name1 = t1.getName();
72 if (t1.isApproved()) name1 = locale.getString("type.context." + name1);
73 String name2 = t2.getName();
74 if (t2.isApproved()) name2 = locale.getString("type.context." + name2);
76 return name1.compareToIgnoreCase(name2);
80 // ==============================================================================================================================
82 // ==============================================================================================================================
84 protected void closeKnowledge () {
85 // --------------------------------
86 OpenObject open = (OpenObject)session.remove("knowledge.open");
88 if (session.get("study.open") == null) open.clearFacades(); // For eventually reopening the knowledge from a fresh context
91 protected void closeStudy () {
92 // ----------------------------
93 OpenObject open = (OpenObject)session.remove("study.open");
95 if (session.get("knowledge.open") == null) open.clearFacades(); // For eventually reopening the study from a fresh context
98 protected void connect (LoginContext context, User user) {
99 // --------------------------------------------------------
100 OpenStudy open = getOpenStudy();
102 open.changeUser(user);
104 session.put("user.rights", new ApplicationRights(user) );
105 session.put("login.context", context); // For executing the deconnection, when requested
107 protected void disconnect () {
108 // ----------------------------
109 OpenStudy open = getOpenStudy();
111 open.changeUser(null);
113 session.put("user.rights", new ApplicationRights(null) ); // Disables user rights
114 session.remove("login.context");
116 protected User getConnectedUser () {
117 // ----------------------------------
118 ApplicationRights rights = (ApplicationRights)session.get("user.rights");
119 return rights.getUser(); // May be null
121 protected Menu getMenu (String name) {
122 // ------------------------------------
123 return (Menu)session.get("menu." + name);
125 public void setOpenKnowledge (OpenKnowledge kelm) {
126 _openKnowledge = kelm;
128 protected OpenKnowledge getOpenKnowledge () {
129 // _openKnowledge = (OpenKnowledge)session.get("knowledge.open"); // May be null
130 return _openKnowledge;
132 public void setOpenStudy (OpenStudy aStudy) {
135 public OpenStudy getOpenStudy () {
136 // _openStudy = (OpenStudy)session.get("study.open");
137 return _openStudy; // May be null
139 protected OpenKnowledge open (KnowledgeElement kelm) {
140 // ----------------------------------------------------
141 OpenKnowledge open = _openKnowledge.open(kelm);
143 closeKnowledge(); // Just in case
144 session.put("knowledge.open", open);
147 protected OpenStudy open (Study study) {
148 // --------------------------------------
149 OpenStudy open = _openStudy.open(getConnectedUser(), study); // The connected user may be null
151 closeStudy(); // Just in case
152 session.put("study.open", open);
157 * Initialization the Context for menubar.
159 public void initializationContext() {
160 getMenuBarSettings().initializeInitialMenuProperties();
162 if (session.get("study.open") == null) {
163 getMenuBarSettings().setIsStudyNull(true);
165 getMenuBarSettings().setIsStudyNull(false);
168 if (session.get("knowledge.open") == null) {
169 getMenuBarSettings().setIsKnowledgeNull(true);
171 getMenuBarSettings().setIsKnowledgeNull(false);
174 ApplicationRights userRights = (ApplicationRights)session.get("user.rights");
176 if (userRights.canCreateStudy()) {
177 getMenuBarSettings().setCanUserCreateStudy(true);
179 getMenuBarSettings().setCanUserCreateStudy(false);
182 if (userRights.canManageDatabase()) {
183 getMenuBarSettings().setCanUserManageDatabase(true);
185 getMenuBarSettings().setCanUserManageDatabase(false);
191 * Initialization the Context for Menu Bar and Tool Bar.
193 * @param titleProperty - The title of the open study/knowledge.
194 * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
196 public void initializationContext(final String titleProperty, final String editDisabledProperty) {
198 initializationContext();
200 OpenObject entity = (OpenObject)session.get(titleProperty + ".open");
202 getTitleBarSettings().setProgressState(entity.getProgressState().toString());
203 getTitleBarSettings().setSelectionState(entity.getSelection());
204 getTitleBarSettings().setEntryType(entity.getType());
205 getTitleBarSettings().setEntryTitle(entity.getTitle());
206 getTitleBarSettings().setEditDisabledProperty(editDisabledProperty);
210 * Initialization of the screen context for menu bar.
212 * @param menuProperty - the property of the menu bar.
214 public void initializationScreenContext(final String menuProperty) {
216 initializationContext();
217 getMenuBarSettings().intializeMenuBar(menuProperty);
221 * Initialization of the screen context for menu bar and tool bar.
223 * @param menuProperty - the property of the menu bar.
224 * @param titleProperty - The title of the open study/knowledge.
225 * @param editDisabledProperty - Property that indicates whether the current open study is editable or not.
227 public void initializationScreenContext(final String menuProperty,
228 final String titleProperty, final String editDisabledProperty) {
230 initializationContext(titleProperty, editDisabledProperty);
231 getMenuBarSettings().intializeMenuBar(menuProperty);
233 // ==============================================================================================================================
234 // Getters and setters
235 // ==============================================================================================================================
237 public void setServletRequest (HttpServletRequest request) {
238 this.request = request;
241 public HttpServletRequest getServletRequest() {
245 public String getErrorCode () {
246 // -----------------------------
249 public Map<String, Object> getSession () {
250 // ----------------------------------------
254 public void setErrorCode (String code) {
255 // --------------------------------------
258 public void setSession (Map<String, Object> session) {
259 // ----------------------------------------------------
260 this.session = session;
264 * Get the menuBarSettings.
265 * @return the menuBarSettings
267 public MenuBarSettings getMenuBarSettings() {
268 return _menuBarSettings;
272 * Set the menuBarSettings.
273 * @param menuBarSettings the menuBarSettings to set
275 public void setMenuBarSettings(final MenuBarSettings menuBarSettings) {
276 _menuBarSettings = menuBarSettings;
280 * Get the _titleBarSettings.
281 * @return the _titleBarSettings
283 public TitleBarSettings getTitleBarSettings() {
284 return _titleBarSettings;
287 * Set the titleBarSettings.
288 * @param titleBarSettings the titleBarSettings to set
290 public void setTitleBarSettings(TitleBarSettings titleBarSettings) {
291 _titleBarSettings = titleBarSettings;