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;
49 * Value of the menu property.
50 * It can be: none, create, open, study, knowledge, sysadmin, help.
52 private String _menuProperty;
55 * Value of the tool bar property.
56 * It can be: none, standard, study, back.
58 private String _toolProperty;
61 * Value of the left menu property.
62 * It can be: open, study, knowledge, scenario.
64 private String _leftMenuProperty;
69 private static final long serialVersionUID = -1910481357051393077L;
72 refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext
75 // ==============================================================================================================================
77 // ==============================================================================================================================
80 * Initialize study search form.
81 * @return SUCCESS if no exception, otherwise return ERROR
83 public String doInitialize() {
88 // Final initialization of the form
90 setContextTypeOptions(getInvolvedContexts());
92 setMenuProperty("open");
93 setToolProperty("none");
94 setLeftMenuProperty("open");
95 initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
98 } catch (Exception error) {
99 // No need to roll back the transaction as it is read only
100 logger.error("Reason: ", error);
102 setMenuProperty("none");
103 initializationScreenContext(_menuProperty);
109 protected String doSearch() throws InvalidPropertyException {
110 // ----------------------------
111 Map<String, Object> session = getSession();
112 User user = getConnectedUser();
114 Study.Properties sprop = new Study.Properties();
116 // Search matching all criteria
117 if (!this.state.equals("ANY"))
118 sprop.setState(ProgressState.valueOf(this.state));
119 if (words.length() > 0)
120 sprop.setTitle(words);
121 if (refid.length() > 0)
122 sprop.setReference(refid);
123 if (context.size() > 0)
124 sprop.setSimulationContexts(context);
125 int index = Integer.valueOf(author);
127 User him = getUserService().selectUser(index);
128 sprop.setManager(him);
130 // Set of the visibility
131 if (visibility.equals("all")) {
132 Study.Properties other = sprop.copy();
134 other.setVisibility(Visibility.PUBLIC);
135 sprop.setVisibility(Visibility.PRIVATE);
136 sprop.setActor(user);
138 result = getSearchService().selectStudiesWhere(sprop, other);
140 Visibility reparea = null;
141 if (visibility.equals("onlypublic"))
142 reparea = Visibility.PUBLIC;
144 reparea = Visibility.valueOf(visibility);
145 sprop.setVisibility(reparea);
146 if (reparea == Visibility.PRIVATE)
147 sprop.setActor(user);
149 result = getSearchService().selectStudiesWhere(sprop);
151 session.put("search.result", result); // For redisplaying the page without re-executing the search
155 // ==============================================================================================================================
157 // ==============================================================================================================================
159 public String getContextMatch() {
160 // --------------------------------
164 public String getCriteriaMatch() {
165 // ---------------------------------
169 public String getReference() {
170 // -----------------------------
174 public String getState() {
175 // -------------------------
179 public String getVisibility() {
180 // ------------------------------
184 public String getWords() {
185 // -------------------------
189 // ==============================================================================================================================
191 // ==============================================================================================================================
193 public void setContextMatch(String value) {
194 // ------------------------------------------
195 this.matcontext = value;
198 public void setCriteriaMatch(String value) {
199 // -------------------------------------------
200 this.matchamong = value;
203 public void setReference(String value) {
204 // ---------------------------------------
208 public void setState(String value) {
209 // -----------------------------------
213 public void setVisibility(String value) {
214 // ----------------------------------------
215 this.visibility = value;
218 public void setWords(String value) {
219 // -----------------------------------
223 // ==============================================================================================================================
224 // Implementation of abstract services
225 // ==============================================================================================================================
227 protected List<SimulationContextType> getInvolvedContexts() {
228 // ------------------------------------------------------------
229 List<ProjectSettingsService.Step> steps = getProjectSettings()
230 .getStepsOf(Study.class);
231 ProjectSettingsService.Step[] number = steps
232 .toArray(new ProjectSettingsService.Step[steps.size()]);
234 return getSimulationContextService().selectTypesOf(number);
237 @SuppressWarnings("unchecked")
238 protected void loadFilter() {
239 // ----------------------------
240 Map<String, Object> session = getSession();
241 User user = getConnectedUser();
242 Map<String, Object> filter = (Map<String, Object>) session
243 .get("study.filter"); // A default filter is supposed being set at start
245 visibility = (String) filter.get("visibility");
246 matchamong = (String) filter.get("matchamong");
247 matcontext = (String) filter.get("matcontext");
248 state = (String) filter.get("state");
249 author = (String) filter.get("author");
250 refid = (String) filter.get("reference");
251 words = (String) filter.get("title");
252 context = (List<SimulationContext>) filter.get("context");
255 visibility = "onlypublic";
259 @SuppressWarnings("unchecked")
260 protected void saveFilter() {
261 // ----------------------------
262 Map<String, Object> session = getSession();
263 Map<String, Object> filter = (Map<String, Object>) session
264 .get("study.filter"); // A default filter is supposed being set at start
266 filter.put("visibility", this.visibility);
267 filter.put("matchamong", this.matchamong);
268 filter.put("matcontext", this.matcontext);
269 filter.put("state", this.state);
270 filter.put("author", this.author);
271 filter.put("reference", this.refid);
272 filter.put("title", this.words);
274 context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
279 * Get the searchService.
281 * @return the searchService
283 public SearchService getSearchService() {
284 return _searchService;
288 * Set the searchService.
290 * @param searchService
291 * the searchService to set
293 public void setSearchService(SearchService searchService) {
294 _searchService = searchService;
298 * Get project settings.
300 * @return Project settings service
302 private ProjectSettingsService getProjectSettings() {
303 return _projectSettingsService;
307 * Set project settings service.
309 * @param projectSettingsService
310 * project settings service
312 public void setProjectSettings(ProjectSettingsService projectSettingsService) {
313 _projectSettingsService = projectSettingsService;
317 * Get the simulationContextService.
319 * @return the simulationContextService
321 public SimulationContextService getSimulationContextService() {
322 return _simulationContextService;
326 * Set the simulationContextService.
328 * @param simulationContextService
329 * the simulationContextService to set
331 public void setSimulationContextService(
332 SimulationContextService simulationContextService) {
333 _simulationContextService = simulationContextService;
337 * Get the userService.
339 * @return the userService
341 public UserService getUserService() {
346 * Set the userService.
349 * the userService to set
351 public void setUserService(UserService userService) {
352 _userService = userService;
356 * Get the menuProperty.
357 * @return the menuProperty
359 public String getMenuProperty() {
360 return _menuProperty;
364 * Set the menuProperty.
365 * @param menuProperty the menuProperty to set
367 public void setMenuProperty(String menuProperty) {
368 this._menuProperty = menuProperty;
372 * Get the toolProperty.
373 * @return the toolProperty
375 public String getToolProperty() {
376 return _toolProperty;
380 * Set the toolProperty.
381 * @param toolProperty the toolProperty to set
383 public void setToolProperty(final String toolProperty) {
384 _toolProperty = toolProperty;
388 * Get the leftMenuProperty.
389 * @return the leftMenuProperty
391 public String getLeftMenuProperty() {
392 return _leftMenuProperty;
396 * Set the leftMenuProperty.
397 * @param leftMenuProperty the leftMenuProperty to set
399 public void setLeftMenuProperty(final String leftMenuProperty) {
400 _leftMenuProperty = leftMenuProperty;