1 package org.splat.simer;
6 import org.hibernate.Session;
7 import org.hibernate.Transaction;
8 import org.splat.kernel.InvalidPropertyException;
9 import org.splat.kernel.User;
10 import org.splat.kernel.UserDirectory;
11 import org.splat.som.Database;
12 import org.splat.som.ProgressState;
13 import org.splat.som.ProjectSettings;
14 import org.splat.som.SimulationContext;
15 import org.splat.som.SimulationContextType;
16 import org.splat.som.Study;
17 import org.splat.som.Visibility;
18 import org.splat.wapp.Item;
19 import org.splat.wapp.TabBar;
22 public class SearchStudyAction extends SearchBaseAction {
24 private TabBar area = null; // Active repository area
25 private String state = null; // "inPROGRESS", "inCHECK" or "END"
26 private String among = null; // "all", "mine" or "ref"
27 private String refid = null; // Study reference when among ref
28 private String words = null; // Full text search words
30 private static final long serialVersionUID = -1910481357051393077L;
32 enum UserAction { refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext }
34 // ==============================================================================================================================
36 // ==============================================================================================================================
38 public String doInitialize () {
39 // -----------------------------
40 Session connex = Database.getSession();
41 Transaction transax = connex.beginTransaction();
44 if (newarea != null) { // New selected repository area
45 area.selects(newarea);
49 // Final initialization of the form
51 setContextTypeOptions(getInvolvedContexts());
56 catch (Exception error) {
57 // No need to roll back the transaction as it is read only
58 logger.error("Reason: ", error);
63 protected String doSearch () throws InvalidPropertyException {
64 // ----------------------------
65 Map<String, Object> session = getSession();
66 User user = getConnectedUser();
68 Study.Properties sprop = new Study.Properties();
69 Study.Properties other = null;
71 // Set of the selected repository area
72 String selectab = area.getSelection().toUpperCase();
73 Visibility reparea = Visibility.valueOf(selectab);
74 sprop.setVisibility(reparea);
76 // Search from a given reference
77 if (among.equals("ref")) {
78 if (refid.length() == 0) {
79 getSession().remove("search.result"); // The current result is obsolete
82 sprop.setReference(refid);
83 if (reparea == Visibility.PRIVATE) { // Restriction to studies in which the connected user is involved
84 other = sprop.copy().setActor(user);
85 sprop.setManager(user);
88 // Search from other available criteria
89 if (this.state != null) {
90 ProgressState state = ProgressState.APPROVED; // Trick for the Public and Reference areas to not share the APPROVED state
91 if (!this.state.equals("ARCHIVED")) state = ProgressState.valueOf(this.state);
92 sprop.setState(state);
94 if (words.length() > 0) sprop.setTitle(words);
95 if (context.size() > 0) sprop.setSimulationContexts(context);
96 if (among.equals("mine")) sprop.setManager(user);
97 else if (among.equals("his")) {
98 User him = UserDirectory.selectUser(Integer.valueOf(author));
99 sprop.setManager(him);
100 if (reparea == Visibility.PRIVATE) sprop.setActor(user);
101 } else //among.equals("all")
102 if (reparea == Visibility.PRIVATE) {
103 other = sprop.copy().setActor(user);
104 sprop.setManager(user);
107 if (other == null) result = Database.selectStudiesWhere(sprop);
108 else result = Database.selectStudiesWhere(sprop, other);
110 session.put("search.result", result); // For redisplaying the page without re-executing the search
114 // ==============================================================================================================================
116 // ==============================================================================================================================
118 public String getArea () {
119 // ------------------------
120 return area.getSelection();
122 public String getOwner () {
123 // -------------------------
126 public String getReference () {
127 // -----------------------------
130 public String getState () {
131 // -------------------------
134 public List<Item> getTabs () {
135 // ----------------------------
136 return area.asList();
138 public String getWords () {
139 // -------------------------
143 // ==============================================================================================================================
145 // ==============================================================================================================================
147 public void setOwner (String value) {
148 // -----------------------------------
151 public void setReference (String value) {
152 // ---------------------------------------
155 public void setState (String value) {
156 // -----------------------------------
159 public void setWords (String value) {
160 // -----------------------------------
164 // ==============================================================================================================================
165 // Implementation of abstract services
166 // ==============================================================================================================================
168 protected List<SimulationContextType> getInvolvedContexts () {
169 // ------------------------------------------------------------
170 List<ProjectSettings.Step> steps = ProjectSettings.getStepsOf(Study.class);
171 ProjectSettings.Step[] number = steps.toArray(new ProjectSettings.Step[steps.size()]);
173 return SimulationContext.selectTypesOf(number);
176 @SuppressWarnings("unchecked")
177 protected void loadFilter () {
178 // ----------------------------
179 Map<String,Object> session = getSession();
180 User user = getConnectedUser();
181 Map<String,Object> filter = (Map<String, Object>)session.get("study.filter"); // A default filter is supposed being set at start
183 area = (TabBar)filter.get("area");
184 state = (String)filter.get("state");
185 among = (String)filter.get("owner");
186 author = (String)filter.get("author");
187 refid = (String)filter.get("reference");
188 words = (String)filter.get("title");
189 context = (List<SimulationContext>)filter.get("context");
192 area.disables("private");
193 if (area.getSelection().equals("private")) area.selects("public");
194 if (among.equals("mine")) among = "all";
198 @SuppressWarnings("unchecked")
199 protected void saveFilter () {
200 // ----------------------------
201 Map<String, Object> session = getSession();
202 Map<String, Object> filter = (Map<String, Object>)session.get("study.filter"); // A default filter is supposed being set at start
204 area = (TabBar)filter.get("area"); // The area being not an input, it is null when submitting the form
205 if (among.equals("ref")) {
206 filter.put("owner", "ref");
207 filter.put("reference", this.refid);
209 filter.put("state", this.state);
210 filter.put("owner", this.among);
211 filter.put("author", this.author);
212 filter.put("reference", "");
213 filter.put("title", this.words);
215 context = (List<SimulationContext>)filter.get("context"); // Only criteria not part of the form