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;
20 public class SearchStudyAction extends SearchBaseAction {
22 private String visibility = null; // "Private", "Public", "All"
23 private String state = null; // "In-Work", "In-Draft", "In-Check"...
24 private String matchamong = null; // "all" or "any"
25 private String matcontext = null; // "all" or "any"
26 private String refid = null; // Study reference
27 private String words = null; // Full text search words
29 private static final long serialVersionUID = -1910481357051393077L;
31 enum UserAction { refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext }
33 // ==============================================================================================================================
35 // ==============================================================================================================================
37 public String doInitialize () {
38 // -----------------------------
39 Session connex = Database.getSession();
40 Transaction transax = connex.beginTransaction();
45 // Final initialization of the form
47 setContextTypeOptions(getInvolvedContexts());
52 catch (Exception error) {
53 // No need to roll back the transaction as it is read only
54 logger.error("Reason: ", error);
59 protected String doSearch () throws InvalidPropertyException {
60 // ----------------------------
61 Map<String, Object> session = getSession();
62 User user = getConnectedUser();
64 Study.Properties sprop = new Study.Properties();
66 // Search matching all criteria
67 if (!this.state.equals("ANY")) sprop.setState( ProgressState.valueOf(this.state) );
68 if (words.length() > 0) sprop.setTitle(words);
69 if (refid.length() > 0) sprop.setReference(refid);
70 if (context.size() > 0) sprop.setSimulationContexts(context);
71 int index = Integer.valueOf(author);
73 User him = UserDirectory.selectUser(index);
74 sprop.setManager(him);
76 // Set of the visibility
77 if (visibility.equals("all")) {
78 Study.Properties other = sprop.copy();
80 other.setVisibility(Visibility.PUBLIC);
81 sprop.setVisibility(Visibility.PRIVATE);
84 result = Database.selectStudiesWhere(sprop, other);
87 Visibility reparea = null;
88 if (visibility.equals("onlypublic")) reparea = Visibility.PUBLIC;
89 else reparea = Visibility.valueOf(visibility);
90 sprop.setVisibility(reparea);
91 if (reparea == Visibility.PRIVATE) sprop.setActor(user);
93 result = Database.selectStudiesWhere(sprop);
95 session.put("search.result", result); // For redisplaying the page without re-executing the search
99 // ==============================================================================================================================
101 // ==============================================================================================================================
103 public String getContextMatch () {
104 // --------------------------------
107 public String getCriteriaMatch () {
108 // ---------------------------------
111 public String getReference () {
112 // -----------------------------
115 public String getState () {
116 // -------------------------
119 public String getVisibility () {
120 // ------------------------------
123 public String getWords () {
124 // -------------------------
128 // ==============================================================================================================================
130 // ==============================================================================================================================
132 public void setContextMatch (String value) {
133 // ------------------------------------------
134 this.matcontext = value;
136 public void setCriteriaMatch (String value) {
137 // -------------------------------------------
138 this.matchamong = value;
140 public void setReference (String value) {
141 // ---------------------------------------
144 public void setState (String value) {
145 // -----------------------------------
148 public void setVisibility (String value) {
149 // ----------------------------------------
150 this.visibility = value;
152 public void setWords (String value) {
153 // -----------------------------------
157 // ==============================================================================================================================
158 // Implementation of abstract services
159 // ==============================================================================================================================
161 protected List<SimulationContextType> getInvolvedContexts () {
162 // ------------------------------------------------------------
163 List<ProjectSettings.Step> steps = ProjectSettings.getStepsOf(Study.class);
164 ProjectSettings.Step[] number = steps.toArray(new ProjectSettings.Step[steps.size()]);
166 return SimulationContext.selectTypesOf(number);
169 @SuppressWarnings("unchecked")
170 protected void loadFilter () {
171 // ----------------------------
172 Map<String,Object> session = getSession();
173 User user = getConnectedUser();
174 Map<String,Object> filter = (Map<String, Object>)session.get("study.filter"); // A default filter is supposed being set at start
176 visibility = (String)filter.get("visibility");
177 matchamong = (String)filter.get("matchamong");
178 matcontext = (String)filter.get("matcontext");
179 state = (String)filter.get("state");
180 author = (String)filter.get("author");
181 refid = (String)filter.get("reference");
182 words = (String)filter.get("title");
183 context = (List<SimulationContext>)filter.get("context");
186 visibility = "onlypublic";
190 @SuppressWarnings("unchecked")
191 protected void saveFilter () {
192 // ----------------------------
193 Map<String, Object> session = getSession();
194 Map<String, Object> filter = (Map<String, Object>)session.get("study.filter"); // A default filter is supposed being set at start
196 filter.put("visibility", this.visibility);
197 filter.put("matchamong", this.matchamong);
198 filter.put("matcontext", this.matcontext);
199 filter.put("state", this.state);
200 filter.put("author", this.author);
201 filter.put("reference", this.refid);
202 filter.put("title", this.words);
204 context = (List<SimulationContext>)filter.get("context"); // Only criteria not part of the form