]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/SearchStudyAction.java
Salome HOME
Modifications to respect PMD rules.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / SearchStudyAction.java
1 package org.splat.simer;
2
3 import java.util.List;
4 import java.util.Map;
5
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;
17
18 /**
19  * Search studies form action.
20  *
21  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
22  */
23 public class SearchStudyAction extends SearchBaseAction {
24
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
31         /**
32          * Injected project settings service.
33          */
34         private ProjectSettingsService _projectSettingsService;
35         /**
36          * Injected search service.
37          */
38         private SearchService _searchService;
39         /**
40          * Injected simulation context service.
41          */
42         private SimulationContextService _simulationContextService;
43         /**
44          * Injected user service.
45          */
46         private UserService _userService;
47         
48         /**
49          * Value of the menu property. 
50          * It can be: none, create, open, study, knowledge, sysadmin, help.
51          */
52         private String _menuProperty;
53         
54         /**
55          * Value of the tool bar property. 
56          * It can be: none, standard, study, back.
57          */
58         private String _toolProperty;
59         
60         /**
61          * Value of the left menu property. 
62          * It can be: open, study, knowledge, scenario.
63          */
64         private String _leftMenuProperty;
65
66         /**
67          * Serial version ID.
68          */
69         private static final long serialVersionUID = -1910481357051393077L;
70
71         enum UserAction {
72                 refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext
73         }
74
75         // ==============================================================================================================================
76         // Action methods
77         // ==============================================================================================================================
78
79         /**
80          * Initialize study search form.
81          * @return SUCCESS if no exception, otherwise return ERROR
82          */
83         public String doInitialize() {
84                 try {
85                         loadFilter();
86                         doSearch();
87
88                         // Final initialization of the form
89                         setCandidates();
90                         setContextTypeOptions(getInvolvedContexts());
91                         
92                         setMenuProperty("open");
93                         setToolProperty("none");
94                         setLeftMenuProperty("open");
95                         initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
96
97                         return SUCCESS;
98                 } catch (Exception error) {
99                         // No need to roll back the transaction as it is read only
100                         LOG.error("Reason: ", error);
101                         
102                         setMenuProperty("none");
103                         initializationScreenContext(_menuProperty);
104                         
105                         return ERROR;
106                 }
107         }
108
109         protected String doSearch() throws InvalidPropertyException {
110                 // ----------------------------
111                 Map<String, Object> session = getSession();
112                 User user = getConnectedUser();
113
114                 Study.Properties sprop = new Study.Properties();
115
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);
126                 if (index > 0) {
127                         User him = getUserService().selectUser(index);
128                         sprop.setManager(him);
129                 }
130                 // Set of the visibility
131                 if (visibility.equals("all")) {
132                         Study.Properties other = sprop.copy();
133
134                         other.setVisibility(Visibility.PUBLIC);
135                         sprop.setVisibility(Visibility.PRIVATE);
136                         sprop.setActor(user);
137
138                         result = getSearchService().selectStudiesWhere(sprop, other);
139                 } else {
140                         Visibility reparea = null;
141                         if (visibility.equals("onlypublic"))
142                                 reparea = Visibility.PUBLIC;
143                         else
144                                 reparea = Visibility.valueOf(visibility);
145                         sprop.setVisibility(reparea);
146                         if (reparea == Visibility.PRIVATE)
147                                 sprop.setActor(user);
148
149                         result = getSearchService().selectStudiesWhere(sprop);
150                 }
151                 session.put("search.result", result); // For redisplaying the page without re-executing the search
152                 return "refresh";
153         }
154
155         // ==============================================================================================================================
156         // Getters
157         // ==============================================================================================================================
158
159         public String getContextMatch() {
160                 // --------------------------------
161                 return matcontext;
162         }
163
164         public String getCriteriaMatch() {
165                 // ---------------------------------
166                 return matchamong;
167         }
168
169         public String getReference() {
170                 // -----------------------------
171                 return refid;
172         }
173
174         public String getState() {
175                 // -------------------------
176                 return state;
177         }
178
179         public String getVisibility() {
180                 // ------------------------------
181                 return visibility;
182         }
183
184         public String getWords() {
185                 // -------------------------
186                 return words;
187         }
188
189         // ==============================================================================================================================
190         // Setters
191         // ==============================================================================================================================
192
193         public void setContextMatch(String value) {
194                 // ------------------------------------------
195                 this.matcontext = value;
196         }
197
198         public void setCriteriaMatch(String value) {
199                 // -------------------------------------------
200                 this.matchamong = value;
201         }
202
203         public void setReference(String value) {
204                 // ---------------------------------------
205                 this.refid = value;
206         }
207
208         public void setState(String value) {
209                 // -----------------------------------
210                 this.state = value;
211         }
212
213         public void setVisibility(String value) {
214                 // ----------------------------------------
215                 this.visibility = value;
216         }
217
218         public void setWords(String value) {
219                 // -----------------------------------
220                 this.words = value;
221         }
222
223         // ==============================================================================================================================
224         // Implementation of abstract services
225         // ==============================================================================================================================
226
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()]);
233
234                 return getSimulationContextService().selectTypesOf(number);
235         }
236
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
244
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");
253
254                 if (user == null) {
255                         visibility = "onlypublic";
256                 }
257         }
258
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
265
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);
273
274                 context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
275
276         }
277
278         /**
279          * Get the searchService.
280          * 
281          * @return the searchService
282          */
283         public SearchService getSearchService() {
284                 return _searchService;
285         }
286
287         /**
288          * Set the searchService.
289          * 
290          * @param searchService
291          *            the searchService to set
292          */
293         public void setSearchService(SearchService searchService) {
294                 _searchService = searchService;
295         }
296
297         /**
298          * Get project settings.
299          * 
300          * @return Project settings service
301          */
302         private ProjectSettingsService getProjectSettings() {
303                 return _projectSettingsService;
304         }
305
306         /**
307          * Set project settings service.
308          * 
309          * @param projectSettingsService
310          *            project settings service
311          */
312         public void setProjectSettings(ProjectSettingsService projectSettingsService) {
313                 _projectSettingsService = projectSettingsService;
314         }
315
316         /**
317          * Get the simulationContextService.
318          * 
319          * @return the simulationContextService
320          */
321         public SimulationContextService getSimulationContextService() {
322                 return _simulationContextService;
323         }
324
325         /**
326          * Set the simulationContextService.
327          * 
328          * @param simulationContextService
329          *            the simulationContextService to set
330          */
331         public void setSimulationContextService(
332                         SimulationContextService simulationContextService) {
333                 _simulationContextService = simulationContextService;
334         }
335
336         /**
337          * Get the userService.
338          * 
339          * @return the userService
340          */
341         public UserService getUserService() {
342                 return _userService;
343         }
344
345         /**
346          * Set the userService.
347          * 
348          * @param userService
349          *            the userService to set
350          */
351         public void setUserService(UserService userService) {
352                 _userService = userService;
353         }
354         
355         /**
356          * Get the menuProperty.
357          * @return the menuProperty
358          */
359         public String getMenuProperty() {
360                 return _menuProperty;
361         }
362
363         /**
364          * Set the menuProperty.
365          * @param menuProperty the menuProperty to set
366          */
367         public void setMenuProperty(String menuProperty) {
368                 this._menuProperty = menuProperty;
369         }
370         
371         /**
372          * Get the toolProperty.
373          * @return the toolProperty
374          */
375         public String getToolProperty() {
376                 return _toolProperty;
377         }
378
379         /**
380          * Set the toolProperty.
381          * @param toolProperty the toolProperty to set
382          */
383         public void setToolProperty(final String toolProperty) {
384                 _toolProperty = toolProperty;
385         }
386         
387         /**
388          * Get the leftMenuProperty.
389          * @return the leftMenuProperty
390          */
391         public String getLeftMenuProperty() {
392                 return _leftMenuProperty;
393         }
394
395         /**
396          * Set the leftMenuProperty.
397          * @param leftMenuProperty the leftMenuProperty to set
398          */
399         public void setLeftMenuProperty(final String leftMenuProperty) {
400                 _leftMenuProperty = leftMenuProperty;
401         }
402 }