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.dal.bo.kernel.User;
10 import org.splat.kernel.UserDirectory;
11 import org.splat.dal.dao.som.Database;
12 import org.splat.dal.bo.som.ProgressState;
13 import org.splat.service.SearchService;
14 import org.splat.service.technical.ProjectSettingsService;
15 import org.splat.dal.bo.som.SimulationContext;
16 import org.splat.dal.bo.som.SimulationContextType;
17 import org.splat.dal.bo.som.Study;
18 import org.splat.dal.bo.som.Visibility;
21 public class SearchStudyAction extends SearchBaseAction {
23 private String visibility = null; // "Private", "Public", "All"
24 private String state = null; // "In-Work", "In-Draft", "In-Check"...
25 private String matchamong = null; // "all" or "any"
26 private String matcontext = null; // "all" or "any"
27 private String refid = null; // Study reference
28 private String words = null; // Full text search words
29 private SearchService _searchService;
30 private ProjectSettingsService _projectSettingsService;
32 private static final long serialVersionUID = -1910481357051393077L;
34 enum UserAction { refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext }
36 // ==============================================================================================================================
38 // ==============================================================================================================================
40 public String doInitialize () {
41 // -----------------------------
42 Session connex = Database.getSession();
43 Transaction transax = connex.beginTransaction();
48 // Final initialization of the form
50 setContextTypeOptions(getInvolvedContexts());
55 catch (Exception error) {
56 // No need to roll back the transaction as it is read only
57 logger.error("Reason: ", error);
62 protected String doSearch () throws InvalidPropertyException {
63 // ----------------------------
64 Map<String, Object> session = getSession();
65 User user = getConnectedUser();
67 Study.Properties sprop = new Study.Properties();
69 // Search matching all criteria
70 if (!this.state.equals("ANY")) sprop.setState( ProgressState.valueOf(this.state) );
71 if (words.length() > 0) sprop.setTitle(words);
72 if (refid.length() > 0) sprop.setReference(refid);
73 if (context.size() > 0) sprop.setSimulationContexts(context);
74 int index = Integer.valueOf(author);
76 User him = UserDirectory.selectUser(index);
77 sprop.setManager(him);
79 // Set of the visibility
80 if (visibility.equals("all")) {
81 Study.Properties other = sprop.copy();
83 other.setVisibility(Visibility.PUBLIC);
84 sprop.setVisibility(Visibility.PRIVATE);
87 result = getSearchService().selectStudiesWhere(sprop, other);
90 Visibility reparea = null;
91 if (visibility.equals("onlypublic")) reparea = Visibility.PUBLIC;
92 else reparea = Visibility.valueOf(visibility);
93 sprop.setVisibility(reparea);
94 if (reparea == Visibility.PRIVATE) sprop.setActor(user);
96 result = getSearchService().selectStudiesWhere(sprop);
98 session.put("search.result", result); // For redisplaying the page without re-executing the search
102 // ==============================================================================================================================
104 // ==============================================================================================================================
106 public String getContextMatch () {
107 // --------------------------------
110 public String getCriteriaMatch () {
111 // ---------------------------------
114 public String getReference () {
115 // -----------------------------
118 public String getState () {
119 // -------------------------
122 public String getVisibility () {
123 // ------------------------------
126 public String getWords () {
127 // -------------------------
131 // ==============================================================================================================================
133 // ==============================================================================================================================
135 public void setContextMatch (String value) {
136 // ------------------------------------------
137 this.matcontext = value;
139 public void setCriteriaMatch (String value) {
140 // -------------------------------------------
141 this.matchamong = value;
143 public void setReference (String value) {
144 // ---------------------------------------
147 public void setState (String value) {
148 // -----------------------------------
151 public void setVisibility (String value) {
152 // ----------------------------------------
153 this.visibility = value;
155 public void setWords (String value) {
156 // -----------------------------------
160 // ==============================================================================================================================
161 // Implementation of abstract services
162 // ==============================================================================================================================
164 protected List<SimulationContextType> getInvolvedContexts () {
165 // ------------------------------------------------------------
166 List<ProjectSettingsService.Step> steps = getProjectSettings().getStepsOf(Study.class);
167 ProjectSettingsService.Step[] number = steps.toArray(new ProjectSettingsService.Step[steps.size()]);
169 return SimulationContext.selectTypesOf(number);
172 @SuppressWarnings("unchecked")
173 protected void loadFilter () {
174 // ----------------------------
175 Map<String,Object> session = getSession();
176 User user = getConnectedUser();
177 Map<String,Object> filter = (Map<String, Object>)session.get("study.filter"); // A default filter is supposed being set at start
179 visibility = (String)filter.get("visibility");
180 matchamong = (String)filter.get("matchamong");
181 matcontext = (String)filter.get("matcontext");
182 state = (String)filter.get("state");
183 author = (String)filter.get("author");
184 refid = (String)filter.get("reference");
185 words = (String)filter.get("title");
186 context = (List<SimulationContext>)filter.get("context");
189 visibility = "onlypublic";
193 @SuppressWarnings("unchecked")
194 protected void saveFilter () {
195 // ----------------------------
196 Map<String, Object> session = getSession();
197 Map<String, Object> filter = (Map<String, Object>)session.get("study.filter"); // A default filter is supposed being set at start
199 filter.put("visibility", this.visibility);
200 filter.put("matchamong", this.matchamong);
201 filter.put("matcontext", this.matcontext);
202 filter.put("state", this.state);
203 filter.put("author", this.author);
204 filter.put("reference", this.refid);
205 filter.put("title", this.words);
207 context = (List<SimulationContext>)filter.get("context"); // Only criteria not part of the form
211 * Get the searchService.
212 * @return the searchService
214 public SearchService getSearchService() {
215 return _searchService;
219 * Set the searchService.
220 * @param searchService the searchService to set
222 public void setSearchService(SearchService searchService) {
223 _searchService = searchService;
226 * Get project settings.
227 * @return Project settings service
229 private ProjectSettingsService getProjectSettings() {
230 return _projectSettingsService;
234 * Set project settings service.
235 * @param projectSettingsService project settings service
237 public void setProjectSettings(
238 ProjectSettingsService projectSettingsService) {
239 _projectSettingsService = projectSettingsService;