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.dal.dao.som.Database;
11 import org.splat.dal.bo.som.ProgressState;
12 import org.splat.service.SearchService;
13 import org.splat.service.SimulationContextService;
14 import org.splat.service.UserService;
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;
37 * Injected user service.
39 private UserService _userService;
44 private static final long serialVersionUID = -1910481357051393077L;
46 enum UserAction { refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext }
48 // ==============================================================================================================================
50 // ==============================================================================================================================
52 public String doInitialize () {
53 // -----------------------------
54 Session connex = Database.getCurSession();
55 Transaction transax = connex.beginTransaction();
60 // Final initialization of the form
62 setContextTypeOptions(getInvolvedContexts());
67 catch (Exception error) {
68 // No need to roll back the transaction as it is read only
69 logger.error("Reason: ", error);
74 protected String doSearch () throws InvalidPropertyException {
75 // ----------------------------
76 Map<String, Object> session = getSession();
77 User user = getConnectedUser();
79 Study.Properties sprop = new Study.Properties();
81 // Search matching all criteria
82 if (!this.state.equals("ANY")) sprop.setState( ProgressState.valueOf(this.state) );
83 if (words.length() > 0) sprop.setTitle(words);
84 if (refid.length() > 0) sprop.setReference(refid);
85 if (context.size() > 0) sprop.setSimulationContexts(context);
86 int index = Integer.valueOf(author);
88 User him = getUserService().selectUser(index);
89 sprop.setManager(him);
91 // Set of the visibility
92 if (visibility.equals("all")) {
93 Study.Properties other = sprop.copy();
95 other.setVisibility(Visibility.PUBLIC);
96 sprop.setVisibility(Visibility.PRIVATE);
99 result = getSearchService().selectStudiesWhere(sprop, other);
102 Visibility reparea = null;
103 if (visibility.equals("onlypublic")) reparea = Visibility.PUBLIC;
104 else reparea = Visibility.valueOf(visibility);
105 sprop.setVisibility(reparea);
106 if (reparea == Visibility.PRIVATE) sprop.setActor(user);
108 result = getSearchService().selectStudiesWhere(sprop);
110 session.put("search.result", result); // For redisplaying the page without re-executing the search
114 // ==============================================================================================================================
116 // ==============================================================================================================================
118 public String getContextMatch () {
119 // --------------------------------
122 public String getCriteriaMatch () {
123 // ---------------------------------
126 public String getReference () {
127 // -----------------------------
130 public String getState () {
131 // -------------------------
134 public String getVisibility () {
135 // ------------------------------
138 public String getWords () {
139 // -------------------------
143 // ==============================================================================================================================
145 // ==============================================================================================================================
147 public void setContextMatch (String value) {
148 // ------------------------------------------
149 this.matcontext = value;
151 public void setCriteriaMatch (String value) {
152 // -------------------------------------------
153 this.matchamong = value;
155 public void setReference (String value) {
156 // ---------------------------------------
159 public void setState (String value) {
160 // -----------------------------------
163 public void setVisibility (String value) {
164 // ----------------------------------------
165 this.visibility = value;
167 public void setWords (String value) {
168 // -----------------------------------
172 // ==============================================================================================================================
173 // Implementation of abstract services
174 // ==============================================================================================================================
176 protected List<SimulationContextType> getInvolvedContexts () {
177 // ------------------------------------------------------------
178 List<ProjectSettingsService.Step> steps = getProjectSettings().getStepsOf(Study.class);
179 ProjectSettingsService.Step[] number = steps.toArray(new ProjectSettingsService.Step[steps.size()]);
181 return getSimulationContextService().selectTypesOf(number);
184 @SuppressWarnings("unchecked")
185 protected void loadFilter () {
186 // ----------------------------
187 Map<String,Object> session = getSession();
188 User user = getConnectedUser();
189 Map<String,Object> filter = (Map<String, Object>)session.get("study.filter"); // A default filter is supposed being set at start
191 visibility = (String)filter.get("visibility");
192 matchamong = (String)filter.get("matchamong");
193 matcontext = (String)filter.get("matcontext");
194 state = (String)filter.get("state");
195 author = (String)filter.get("author");
196 refid = (String)filter.get("reference");
197 words = (String)filter.get("title");
198 context = (List<SimulationContext>)filter.get("context");
201 visibility = "onlypublic";
205 @SuppressWarnings("unchecked")
206 protected void saveFilter () {
207 // ----------------------------
208 Map<String, Object> session = getSession();
209 Map<String, Object> filter = (Map<String, Object>)session.get("study.filter"); // A default filter is supposed being set at start
211 filter.put("visibility", this.visibility);
212 filter.put("matchamong", this.matchamong);
213 filter.put("matcontext", this.matcontext);
214 filter.put("state", this.state);
215 filter.put("author", this.author);
216 filter.put("reference", this.refid);
217 filter.put("title", this.words);
219 context = (List<SimulationContext>)filter.get("context"); // Only criteria not part of the form
223 * Get the searchService.
224 * @return the searchService
226 public SearchService getSearchService() {
227 return _searchService;
231 * Set the searchService.
232 * @param searchService the searchService to set
234 public void setSearchService(SearchService searchService) {
235 _searchService = searchService;
238 * Get project settings.
239 * @return Project settings service
241 private ProjectSettingsService getProjectSettings() {
242 return _projectSettingsService;
246 * Set project settings service.
247 * @param projectSettingsService project settings service
249 public void setProjectSettings(
250 ProjectSettingsService projectSettingsService) {
251 _projectSettingsService = projectSettingsService;
255 * Get the simulationContextService.
257 * @return the simulationContextService
259 public SimulationContextService getSimulationContextService() {
260 return _simulationContextService;
264 * Set the simulationContextService.
266 * @param simulationContextService
267 * the simulationContextService to set
269 public void setSimulationContextService(
270 SimulationContextService simulationContextService) {
271 _simulationContextService = simulationContextService;
275 * Get the userService.
276 * @return the userService
278 public UserService getUserService() {
283 * Set the userService.
284 * @param userService the userService to set
286 public void setUserService(UserService userService) {
287 _userService = userService;