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.SimulationContextService;
15 import org.splat.service.technical.ProjectSettingsService;
16 import org.splat.dal.bo.som.SimulationContext;
17 import org.splat.dal.bo.som.SimulationContextType;
18 import org.splat.dal.bo.som.Study;
19 import org.splat.dal.bo.som.Visibility;
22 public class SearchStudyAction extends SearchBaseAction {
24 private String visibility = null; // "Private", "Public", "All"
25 private String state = null; // "In-Work", "In-Draft", "In-Check"...
26 private String matchamong = null; // "all" or "any"
27 private String matcontext = null; // "all" or "any"
28 private String refid = null; // Study reference
29 private String words = null; // Full text search words
30 private SearchService _searchService;
31 private ProjectSettingsService _projectSettingsService;
33 * Injected simulation context service.
35 private SimulationContextService _simulationContextService;
40 private static final long serialVersionUID = -1910481357051393077L;
42 enum UserAction { refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext }
44 // ==============================================================================================================================
46 // ==============================================================================================================================
48 public String doInitialize () {
49 // -----------------------------
50 Session connex = Database.getSession();
51 Transaction transax = connex.beginTransaction();
56 // Final initialization of the form
58 setContextTypeOptions(getInvolvedContexts());
63 catch (Exception error) {
64 // No need to roll back the transaction as it is read only
65 logger.error("Reason: ", error);
70 protected String doSearch () throws InvalidPropertyException {
71 // ----------------------------
72 Map<String, Object> session = getSession();
73 User user = getConnectedUser();
75 Study.Properties sprop = new Study.Properties();
77 // Search matching all criteria
78 if (!this.state.equals("ANY")) sprop.setState( ProgressState.valueOf(this.state) );
79 if (words.length() > 0) sprop.setTitle(words);
80 if (refid.length() > 0) sprop.setReference(refid);
81 if (context.size() > 0) sprop.setSimulationContexts(context);
82 int index = Integer.valueOf(author);
84 User him = UserDirectory.selectUser(index);
85 sprop.setManager(him);
87 // Set of the visibility
88 if (visibility.equals("all")) {
89 Study.Properties other = sprop.copy();
91 other.setVisibility(Visibility.PUBLIC);
92 sprop.setVisibility(Visibility.PRIVATE);
95 result = getSearchService().selectStudiesWhere(sprop, other);
98 Visibility reparea = null;
99 if (visibility.equals("onlypublic")) reparea = Visibility.PUBLIC;
100 else reparea = Visibility.valueOf(visibility);
101 sprop.setVisibility(reparea);
102 if (reparea == Visibility.PRIVATE) sprop.setActor(user);
104 result = getSearchService().selectStudiesWhere(sprop);
106 session.put("search.result", result); // For redisplaying the page without re-executing the search
110 // ==============================================================================================================================
112 // ==============================================================================================================================
114 public String getContextMatch () {
115 // --------------------------------
118 public String getCriteriaMatch () {
119 // ---------------------------------
122 public String getReference () {
123 // -----------------------------
126 public String getState () {
127 // -------------------------
130 public String getVisibility () {
131 // ------------------------------
134 public String getWords () {
135 // -------------------------
139 // ==============================================================================================================================
141 // ==============================================================================================================================
143 public void setContextMatch (String value) {
144 // ------------------------------------------
145 this.matcontext = value;
147 public void setCriteriaMatch (String value) {
148 // -------------------------------------------
149 this.matchamong = value;
151 public void setReference (String value) {
152 // ---------------------------------------
155 public void setState (String value) {
156 // -----------------------------------
159 public void setVisibility (String value) {
160 // ----------------------------------------
161 this.visibility = value;
163 public void setWords (String value) {
164 // -----------------------------------
168 // ==============================================================================================================================
169 // Implementation of abstract services
170 // ==============================================================================================================================
172 protected List<SimulationContextType> getInvolvedContexts () {
173 // ------------------------------------------------------------
174 List<ProjectSettingsService.Step> steps = getProjectSettings().getStepsOf(Study.class);
175 ProjectSettingsService.Step[] number = steps.toArray(new ProjectSettingsService.Step[steps.size()]);
177 return getSimulationContextService().selectTypesOf(number);
180 @SuppressWarnings("unchecked")
181 protected void loadFilter () {
182 // ----------------------------
183 Map<String,Object> session = getSession();
184 User user = getConnectedUser();
185 Map<String,Object> filter = (Map<String, Object>)session.get("study.filter"); // A default filter is supposed being set at start
187 visibility = (String)filter.get("visibility");
188 matchamong = (String)filter.get("matchamong");
189 matcontext = (String)filter.get("matcontext");
190 state = (String)filter.get("state");
191 author = (String)filter.get("author");
192 refid = (String)filter.get("reference");
193 words = (String)filter.get("title");
194 context = (List<SimulationContext>)filter.get("context");
197 visibility = "onlypublic";
201 @SuppressWarnings("unchecked")
202 protected void saveFilter () {
203 // ----------------------------
204 Map<String, Object> session = getSession();
205 Map<String, Object> filter = (Map<String, Object>)session.get("study.filter"); // A default filter is supposed being set at start
207 filter.put("visibility", this.visibility);
208 filter.put("matchamong", this.matchamong);
209 filter.put("matcontext", this.matcontext);
210 filter.put("state", this.state);
211 filter.put("author", this.author);
212 filter.put("reference", this.refid);
213 filter.put("title", this.words);
215 context = (List<SimulationContext>)filter.get("context"); // Only criteria not part of the form
219 * Get the searchService.
220 * @return the searchService
222 public SearchService getSearchService() {
223 return _searchService;
227 * Set the searchService.
228 * @param searchService the searchService to set
230 public void setSearchService(SearchService searchService) {
231 _searchService = searchService;
234 * Get project settings.
235 * @return Project settings service
237 private ProjectSettingsService getProjectSettings() {
238 return _projectSettingsService;
242 * Set project settings service.
243 * @param projectSettingsService project settings service
245 public void setProjectSettings(
246 ProjectSettingsService projectSettingsService) {
247 _projectSettingsService = projectSettingsService;
251 * Get the simulationContextService.
253 * @return the simulationContextService
255 public SimulationContextService getSimulationContextService() {
256 return _simulationContextService;
260 * Set the simulationContextService.
262 * @param simulationContextService
263 * the simulationContextService to set
265 public void setSimulationContextService(
266 SimulationContextService simulationContextService) {
267 _simulationContextService = simulationContextService;