1 package org.splat.simer;
6 import org.splat.kernel.InvalidPropertyException;
7 import org.splat.dal.bo.kernel.User;
8 import org.splat.dal.bo.som.ProgressState;
9 import org.splat.service.SearchService;
10 import org.splat.service.SimulationContextService;
11 import org.splat.service.UserService;
12 import org.splat.service.technical.ProjectSettingsService;
13 import org.splat.dal.bo.som.SimulationContext;
14 import org.splat.dal.bo.som.SimulationContextType;
15 import org.splat.dal.bo.som.Study;
16 import org.splat.dal.bo.som.Visibility;
19 * Search studies form action.
21 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
23 public class SearchStudyAction extends SearchBaseAction {
25 private String visibility = null; // "Private", "Public", "All"
26 private String state = null; // "In-Work", "In-Draft", "In-Check"...
27 private String matchamong = null; // "all" or "any"
28 private String matcontext = null; // "all" or "any"
29 private String refid = null; // Study reference
30 private String words = null; // Full text search words
32 * Injected project settings service.
34 private ProjectSettingsService _projectSettingsService;
36 * Injected search service.
38 private SearchService _searchService;
40 * Injected simulation context service.
42 private SimulationContextService _simulationContextService;
44 * Injected user service.
46 private UserService _userService;
51 private static final long serialVersionUID = -1910481357051393077L;
54 refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext
57 // ==============================================================================================================================
59 // ==============================================================================================================================
62 * Initialize study search form.
63 * @return SUCCESS if no exception, otherwise return ERROR
65 public String doInitialize() {
70 // Final initialization of the form
72 setContextTypeOptions(getInvolvedContexts());
75 } catch (Exception error) {
76 // No need to roll back the transaction as it is read only
77 logger.error("Reason: ", error);
82 protected String doSearch() throws InvalidPropertyException {
83 // ----------------------------
84 Map<String, Object> session = getSession();
85 User user = getConnectedUser();
87 Study.Properties sprop = new Study.Properties();
89 // Search matching all criteria
90 if (!this.state.equals("ANY"))
91 sprop.setState(ProgressState.valueOf(this.state));
92 if (words.length() > 0)
93 sprop.setTitle(words);
94 if (refid.length() > 0)
95 sprop.setReference(refid);
96 if (context.size() > 0)
97 sprop.setSimulationContexts(context);
98 int index = Integer.valueOf(author);
100 User him = getUserService().selectUser(index);
101 sprop.setManager(him);
103 // Set of the visibility
104 if (visibility.equals("all")) {
105 Study.Properties other = sprop.copy();
107 other.setVisibility(Visibility.PUBLIC);
108 sprop.setVisibility(Visibility.PRIVATE);
109 sprop.setActor(user);
111 result = getSearchService().selectStudiesWhere(sprop, other);
113 Visibility reparea = null;
114 if (visibility.equals("onlypublic"))
115 reparea = Visibility.PUBLIC;
117 reparea = Visibility.valueOf(visibility);
118 sprop.setVisibility(reparea);
119 if (reparea == Visibility.PRIVATE)
120 sprop.setActor(user);
122 result = getSearchService().selectStudiesWhere(sprop);
124 session.put("search.result", result); // For redisplaying the page without re-executing the search
128 // ==============================================================================================================================
130 // ==============================================================================================================================
132 public String getContextMatch() {
133 // --------------------------------
137 public String getCriteriaMatch() {
138 // ---------------------------------
142 public String getReference() {
143 // -----------------------------
147 public String getState() {
148 // -------------------------
152 public String getVisibility() {
153 // ------------------------------
157 public String getWords() {
158 // -------------------------
162 // ==============================================================================================================================
164 // ==============================================================================================================================
166 public void setContextMatch(String value) {
167 // ------------------------------------------
168 this.matcontext = value;
171 public void setCriteriaMatch(String value) {
172 // -------------------------------------------
173 this.matchamong = value;
176 public void setReference(String value) {
177 // ---------------------------------------
181 public void setState(String value) {
182 // -----------------------------------
186 public void setVisibility(String value) {
187 // ----------------------------------------
188 this.visibility = value;
191 public void setWords(String value) {
192 // -----------------------------------
196 // ==============================================================================================================================
197 // Implementation of abstract services
198 // ==============================================================================================================================
200 protected List<SimulationContextType> getInvolvedContexts() {
201 // ------------------------------------------------------------
202 List<ProjectSettingsService.Step> steps = getProjectSettings()
203 .getStepsOf(Study.class);
204 ProjectSettingsService.Step[] number = steps
205 .toArray(new ProjectSettingsService.Step[steps.size()]);
207 return getSimulationContextService().selectTypesOf(number);
210 @SuppressWarnings("unchecked")
211 protected void loadFilter() {
212 // ----------------------------
213 Map<String, Object> session = getSession();
214 User user = getConnectedUser();
215 Map<String, Object> filter = (Map<String, Object>) session
216 .get("study.filter"); // A default filter is supposed being set at start
218 visibility = (String) filter.get("visibility");
219 matchamong = (String) filter.get("matchamong");
220 matcontext = (String) filter.get("matcontext");
221 state = (String) filter.get("state");
222 author = (String) filter.get("author");
223 refid = (String) filter.get("reference");
224 words = (String) filter.get("title");
225 context = (List<SimulationContext>) filter.get("context");
228 visibility = "onlypublic";
232 @SuppressWarnings("unchecked")
233 protected void saveFilter() {
234 // ----------------------------
235 Map<String, Object> session = getSession();
236 Map<String, Object> filter = (Map<String, Object>) session
237 .get("study.filter"); // A default filter is supposed being set at start
239 filter.put("visibility", this.visibility);
240 filter.put("matchamong", this.matchamong);
241 filter.put("matcontext", this.matcontext);
242 filter.put("state", this.state);
243 filter.put("author", this.author);
244 filter.put("reference", this.refid);
245 filter.put("title", this.words);
247 context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
252 * Get the searchService.
254 * @return the searchService
256 public SearchService getSearchService() {
257 return _searchService;
261 * Set the searchService.
263 * @param searchService
264 * the searchService to set
266 public void setSearchService(SearchService searchService) {
267 _searchService = searchService;
271 * Get project settings.
273 * @return Project settings service
275 private ProjectSettingsService getProjectSettings() {
276 return _projectSettingsService;
280 * Set project settings service.
282 * @param projectSettingsService
283 * project settings service
285 public void setProjectSettings(ProjectSettingsService projectSettingsService) {
286 _projectSettingsService = projectSettingsService;
290 * Get the simulationContextService.
292 * @return the simulationContextService
294 public SimulationContextService getSimulationContextService() {
295 return _simulationContextService;
299 * Set the simulationContextService.
301 * @param simulationContextService
302 * the simulationContextService to set
304 public void setSimulationContextService(
305 SimulationContextService simulationContextService) {
306 _simulationContextService = simulationContextService;
310 * Get the userService.
312 * @return the userService
314 public UserService getUserService() {
319 * Set the userService.
322 * the userService to set
324 public void setUserService(UserService userService) {
325 _userService = userService;