]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/SearchStudyAction.java
Salome HOME
766971abfa3fded3a78e7fbca56e3e9a08a8bbcf
[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.dal.bo.kernel.User;
7 import org.splat.dal.bo.som.ProgressState;
8 import org.splat.dal.bo.som.SimulationContext;
9 import org.splat.dal.bo.som.SimulationContextType;
10 import org.splat.dal.bo.som.Study;
11 import org.splat.dal.bo.som.Visibility;
12 import org.splat.kernel.InvalidPropertyException;
13 import org.splat.service.SearchService;
14 import org.splat.service.SimulationContextService;
15 import org.splat.service.UserService;
16 import org.splat.service.technical.ProjectSettingsService;
17
18 /**
19  * Search studies form action.
20  */
21 public class SearchStudyAction extends AbstractSearchBaseAction {
22
23         /**
24          * "Private", "Public", "All".
25          */
26         private String _visibility = null;
27         /**
28          * "In-Work", "In-Draft", "In-Check"...
29          */
30         private String _state = null;
31         /**
32          * Criteria match: "all" or "any".
33          */
34         private String _criteriaMatch = null;
35         /**
36          * Simulation context match: "all" or "any".
37          */
38         private String _contextMatch = null;
39         /**
40          * Study reference.
41          */
42         private String _reference = null;
43         /**
44          * Full text search words.
45          */
46         private String _words = null;
47         /**
48          * Injected project settings service.
49          */
50         private ProjectSettingsService _projectSettings;
51         /**
52          * Injected search service.
53          */
54         private SearchService _searchService;
55         /**
56          * Injected simulation context service.
57          */
58         private SimulationContextService _simulationContextService;
59         /**
60          * Injected user service.
61          */
62         private UserService _userService;
63         
64         /**
65          * Value of the menu property. 
66          * It can be: none, create, open, study, knowledge, sysadmin, help.
67          */
68         private String _menuProperty;
69         
70         /**
71          * Value of the tool bar property. 
72          * It can be: none, standard, study, back.
73          */
74         private String _toolProperty;
75         
76         /**
77          * Value of the left menu property. 
78          * It can be: open, study, knowledge, scenario.
79          */
80         private String _leftMenuProperty;
81
82         /**
83          * Serial version ID.
84          */
85         private static final long serialVersionUID = -1910481357051393077L;
86
87         enum UserAction {
88                 refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext
89         }
90
91         // ==============================================================================================================================
92         // Action methods
93         // ==============================================================================================================================
94
95         /**
96          * Initialize study search form.
97          * @return SUCCESS if no exception, otherwise return ERROR
98          */
99         public String doInitialize() {
100                 String res = SUCCESS;
101                 try {
102                         loadFilter();
103                         doSearch();
104
105                         // Final initialization of the form
106                         setCandidates();
107                         setContextTypeOptions(getInvolvedContexts());
108                         
109                         setMenuProperty("open");
110                         setToolProperty("none");
111                         setLeftMenuProperty("open");
112                         initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
113                 } catch (Exception error) {
114                         // No need to roll back the transaction as it is read only
115                         LOG.error("Reason: ", error);
116                         
117                         setMenuProperty("none");
118                         initializationScreenContext(_menuProperty);
119                         
120                         res = ERROR;
121                 }
122                 return res;
123         }
124
125         /** 
126          * {@inheritDoc}
127          * @see org.splat.simer.AbstractSearchBaseAction#doSearch()
128          */
129         @Override
130         protected String doSearch() throws InvalidPropertyException {
131                 Map<String, Object> session = getSession();
132                 Study.Properties sprop = new Study.Properties();
133
134                 // Search matching all criteria
135                 if (!this._state.equals("ANY")) {
136                         sprop.setState(ProgressState.valueOf(this._state));
137                 }
138                 if (_words.length() > 0) {
139                         sprop.setTitle(_words);
140                 }
141                 if (_reference.length() > 0) {
142                         sprop.setReference(_reference);
143                 }
144                 if (_context.size() > 0) {
145                         sprop.setSimulationContexts(_context);
146                 }
147                 int index = Integer.valueOf(_author);
148                 if (index > 0) {
149                         User him = getUserService().selectUser(index);
150                         sprop.setManager(him);
151                 }
152                 // Set of the visibility
153                 if ("all".equals(_visibility)) {
154                         Study.Properties other = sprop.copy();
155
156                         other.setVisibility(Visibility.PUBLIC);
157                         sprop.setVisibility(Visibility.PRIVATE);
158                         sprop.setActor(getConnectedUser());
159
160                         _result = getSearchService().selectStudiesWhere(sprop, other);
161                 } else {
162                         Visibility reparea = null;
163                         if ("onlypublic".equals(_visibility)) {
164                                 reparea = Visibility.PUBLIC;
165                         } else {
166                                 reparea = Visibility.valueOf(_visibility);
167                         }
168                         sprop.setVisibility(reparea);
169                         if (reparea == Visibility.PRIVATE) {
170                                 sprop.setActor(getConnectedUser());
171                         }
172
173                         _result = getSearchService().selectStudiesWhere(sprop);
174                 }
175                 session.put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
176                 return "refresh";
177         }
178
179         // ==============================================================================================================================
180         // Getters
181         // ==============================================================================================================================
182
183         public String getContextMatch() {
184                 return _contextMatch;
185         }
186
187         public String getCriteriaMatch() {
188                 return _criteriaMatch;
189         }
190
191         public String getReference() {
192                 return _reference;
193         }
194
195         public String getState() {
196                 return _state;
197         }
198
199         public String getVisibility() {
200                 return _visibility;
201         }
202
203         public String getWords() {
204                 return _words;
205         }
206
207         // ==============================================================================================================================
208         // Setters
209         // ==============================================================================================================================
210
211         public void setContextMatch(final String value) {
212                 this._contextMatch = value;
213         }
214
215         public void setCriteriaMatch(final String value) {
216                 this._criteriaMatch = value;
217         }
218
219         public void setReference(final String value) {
220                 this._reference = value;
221         }
222
223         public void setState(final String value) {
224                 this._state = value;
225         }
226
227         public void setVisibility(final String value) {
228                 this._visibility = value;
229         }
230
231         public void setWords(final String value) {
232                 this._words = value;
233         }
234
235         // ==============================================================================================================================
236         // Implementation of abstract services
237         // ==============================================================================================================================
238
239         @Override
240         protected List<SimulationContextType> getInvolvedContexts() {
241                 List<ProjectSettingsService.Step> steps = getProjectSettings()
242                                 .getStepsOf(Study.class);
243                 ProjectSettingsService.Step[] number = steps
244                                 .toArray(new ProjectSettingsService.Step[steps.size()]);
245
246                 return getSimulationContextService().selectTypesOf(number);
247         }
248
249         @Override
250         @SuppressWarnings("unchecked")
251         protected void loadFilter() {
252                 Map<String, Object> session = getSession();
253                 User user = getConnectedUser();
254                 Map<String, Object> filter = (Map<String, Object>) session
255                                 .get("study.filter"); // A default filter is supposed being set at start
256
257                 _visibility = (String) filter.get("visibility");
258                 _criteriaMatch = (String) filter.get("matchamong");
259                 _contextMatch = (String) filter.get("matcontext");
260                 _state = (String) filter.get("state");
261                 _author = (String) filter.get("author");
262                 _reference = (String) filter.get("reference");
263                 _words = (String) filter.get("title");
264                 _context = (List<SimulationContext>) filter.get("context");
265
266                 if (user == null) {
267                         _visibility = "onlypublic";
268                 }
269         }
270
271         @Override
272         @SuppressWarnings("unchecked")
273         protected void saveFilter() {
274                 Map<String, Object> session = getSession();
275                 Map<String, Object> filter = (Map<String, Object>) session
276                                 .get("study.filter"); // A default filter is supposed being set at start
277
278                 filter.put("visibility", this._visibility);
279                 filter.put("matchamong", this._criteriaMatch);
280                 filter.put("matcontext", this._contextMatch);
281                 filter.put("state", this._state);
282                 filter.put("author", this._author);
283                 filter.put("reference", this._reference);
284                 filter.put("title", this._words);
285
286                 _context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
287
288         }
289
290         /**
291          * Get the searchService.
292          * 
293          * @return the searchService
294          */
295         public SearchService getSearchService() {
296                 return _searchService;
297         }
298
299         /**
300          * Set the searchService.
301          * 
302          * @param searchService
303          *            the searchService to set
304          */
305         public void setSearchService(final SearchService searchService) {
306                 _searchService = searchService;
307         }
308
309         /**
310          * Get project settings.
311          * 
312          * @return Project settings service
313          */
314         private ProjectSettingsService getProjectSettings() {
315                 return _projectSettings;
316         }
317
318         /**
319          * Set project settings service.
320          * 
321          * @param projectSettingsService
322          *            project settings service
323          */
324         public void setProjectSettings(final ProjectSettingsService projectSettingsService) {
325                 _projectSettings = projectSettingsService;
326         }
327
328         /**
329          * Get the simulationContextService.
330          * 
331          * @return the simulationContextService
332          */
333         @Override
334         public SimulationContextService getSimulationContextService() {
335                 return _simulationContextService;
336         }
337
338         /**
339          * Set the simulationContextService.
340          * 
341          * @param simulationContextService
342          *            the simulationContextService to set
343          */
344         @Override
345         public void setSimulationContextService(
346                         final SimulationContextService simulationContextService) {
347                 _simulationContextService = simulationContextService;
348         }
349
350         /**
351          * Get the userService.
352          * 
353          * @return the userService
354          */
355         @Override
356         public UserService getUserService() {
357                 return _userService;
358         }
359
360         /**
361          * Set the userService.
362          * 
363          * @param userService
364          *            the userService to set
365          */
366         @Override
367         public void setUserService(final UserService userService) {
368                 _userService = userService;
369         }
370         
371         /**
372          * Get the menuProperty.
373          * @return the menuProperty
374          */
375         public String getMenuProperty() {
376                 return _menuProperty;
377         }
378
379         /**
380          * Set the menuProperty.
381          * @param menuProperty the menuProperty to set
382          */
383         public void setMenuProperty(final String menuProperty) {
384                 this._menuProperty = menuProperty;
385         }
386         
387         /**
388          * Get the toolProperty.
389          * @return the toolProperty
390          */
391         public String getToolProperty() {
392                 return _toolProperty;
393         }
394
395         /**
396          * Set the toolProperty.
397          * @param toolProperty the toolProperty to set
398          */
399         public void setToolProperty(final String toolProperty) {
400                 _toolProperty = toolProperty;
401         }
402         
403         /**
404          * Get the leftMenuProperty.
405          * @return the leftMenuProperty
406          */
407         public String getLeftMenuProperty() {
408                 return _leftMenuProperty;
409         }
410
411         /**
412          * Set the leftMenuProperty.
413          * @param leftMenuProperty the leftMenuProperty to set
414          */
415         public void setLeftMenuProperty(final String leftMenuProperty) {
416                 _leftMenuProperty = leftMenuProperty;
417         }
418 }