]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/SearchStudyAction.java
Salome HOME
Simulation context type selection is fixed in study search. Lucene is no more used...
[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.kernel.InvalidPropertyException;
12 import org.splat.service.SearchService;
13 import org.splat.service.technical.ProjectSettingsService;
14 import org.splat.wapp.Constants;
15
16 /**
17  * Search studies form action.
18  */
19 public class SearchStudyAction extends AbstractSearchBaseAction {
20
21         /**
22          * Serial version ID.
23          */
24         private static final long serialVersionUID = -1910481357051393077L;
25
26         /**
27          * "In-Work", "In-Draft", "In-Check"...
28          */
29         private String _state = null;
30         /**
31          * Criteria match: "all" or "any".
32          */
33         private String _criteriaMatch = null;
34         /**
35          * Simulation context match: "all" or "any".
36          */
37         private String _contextMatch = null;
38         /**
39          * Study reference.
40          */
41         private String _reference = null;
42         /**
43          * Full text search words.
44          */
45         private String _words = null;
46         /**
47          * Injected project settings service.
48          */
49         private ProjectSettingsService _projectSettings;
50         /**
51          * Injected search service.
52          */
53         private SearchService _searchService;
54
55         enum UserAction {
56                 refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext
57         }
58
59         // ==============================================================================================================================
60         // Action methods
61         // ==============================================================================================================================
62
63         /**
64          * Initialize study search form.
65          * 
66          * @return SUCCESS if no exception, otherwise return ERROR
67          */
68         public String doInitialize() {
69                 String res = SUCCESS;
70                 try {
71                         loadFilter();
72                         doSearch();
73
74                         // Final initialization of the form
75                         setCandidates();
76                         setContextTypeOptions(getInvolvedContexts());
77                         initializationFullScreenContext(Constants.OPEN, Constants.NONE,
78                                         Constants.OPEN);
79
80                 } catch (Exception error) {
81                         // No need to roll back the transaction as it is read only
82                         LOG.error("Reason: ", error);
83
84                         initializationScreenContext(Constants.NONE);
85
86                         res = ERROR;
87                 }
88                 return res;
89         }
90
91         /**
92          * {@inheritDoc}
93          * 
94          * @see org.splat.simer.AbstractSearchBaseAction#doSearch()
95          */
96         @Override
97         protected String doSearch() throws InvalidPropertyException {
98                 Map<String, Object> session = getSession();
99                 Study.Properties sprop = new Study.Properties();
100
101                 // Search matching all criteria
102                 if (!this._state.equals("ANY")) {
103                         sprop.setState(ProgressState.valueOf(this._state));
104                 }
105                 if (_words.length() > 0) {
106                         sprop.setTitle(_words);
107                 }
108                 if (_reference.length() > 0) {
109                         sprop.setReference(_reference);
110                 }
111                 if (_context.size() > 0) {
112                         sprop.setSimulationContexts(_context);
113                 }
114                 int index = Integer.valueOf(_author);
115                 if (index > 0) {
116                         User him = getUserService().selectUser(index);
117                         sprop.setManager(him);
118                 }
119                 sprop.setActor(getConnectedUser());
120
121                 _result = getSearchService().selectStudiesWhere(
122                                 "all".equals(_criteriaMatch), "all".equals(_contextMatch),
123                                 sprop);
124                 session.put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
125                 return "refresh";
126         }
127
128         // ==============================================================================================================================
129         // Getters
130         // ==============================================================================================================================
131
132         public String getContextMatch() {
133                 return _contextMatch;
134         }
135
136         public String getCriteriaMatch() {
137                 return _criteriaMatch;
138         }
139
140         public String getReference() {
141                 return _reference;
142         }
143
144         public String getState() {
145                 return _state;
146         }
147
148         public String getWords() {
149                 return _words;
150         }
151
152         // ==============================================================================================================================
153         // Setters
154         // ==============================================================================================================================
155
156         public void setContextMatch(final String value) {
157                 this._contextMatch = value;
158         }
159
160         public void setCriteriaMatch(final String value) {
161                 this._criteriaMatch = value;
162         }
163
164         public void setReference(final String value) {
165                 this._reference = value;
166         }
167
168         public void setState(final String value) {
169                 this._state = value;
170         }
171
172         public void setWords(final String value) {
173                 this._words = value;
174         }
175
176         // ==============================================================================================================================
177         // Implementation of abstract services
178         // ==============================================================================================================================
179
180         @Override
181         protected List<SimulationContextType> getInvolvedContexts() {
182                 List<ProjectSettingsService.Step> steps = getProjectSettings()
183                                 .getStepsOf(Study.class);
184                 ProjectSettingsService.Step[] number = steps
185                                 .toArray(new ProjectSettingsService.Step[steps.size()]);
186
187                 return getSimulationContextService().selectTypesOf(number);
188         }
189
190         @Override
191         @SuppressWarnings("unchecked")
192         protected void loadFilter() {
193                 Map<String, Object> session = getSession();
194                 Map<String, Object> filter = (Map<String, Object>) session
195                                 .get("study.filter"); // A default filter is supposed being set at start
196
197                 _criteriaMatch = (String) filter.get("matchamong");
198                 _contextMatch = (String) filter.get("matcontext");
199                 _state = (String) filter.get("state");
200                 _author = (String) filter.get("author");
201                 _reference = (String) filter.get("reference");
202                 _words = (String) filter.get("title");
203                 _context = (List<SimulationContext>) filter.get("context");
204         }
205
206         @Override
207         @SuppressWarnings("unchecked")
208         protected void saveFilter() {
209                 Map<String, Object> session = getSession();
210                 Map<String, Object> filter = (Map<String, Object>) session
211                                 .get("study.filter"); // A default filter is supposed being set at start
212
213                 filter.put("matchamong", this._criteriaMatch);
214                 filter.put("matcontext", this._contextMatch);
215                 filter.put("state", this._state);
216                 filter.put("author", this._author);
217                 filter.put("reference", this._reference);
218                 filter.put("title", this._words);
219
220                 _context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
221
222         }
223
224         /**
225          * Get the searchService.
226          * 
227          * @return the searchService
228          */
229         public SearchService getSearchService() {
230                 return _searchService;
231         }
232
233         /**
234          * Set the searchService.
235          * 
236          * @param searchService
237          *            the searchService to set
238          */
239         public void setSearchService(final SearchService searchService) {
240                 _searchService = searchService;
241         }
242
243         /**
244          * Get project settings.
245          * 
246          * @return Project settings service
247          */
248         private ProjectSettingsService getProjectSettings() {
249                 return _projectSettings;
250         }
251
252         /**
253          * Set project settings service.
254          * 
255          * @param projectSettingsService
256          *            project settings service
257          */
258         public void setProjectSettings(
259                         final ProjectSettingsService projectSettingsService) {
260                 _projectSettings = projectSettingsService;
261         }
262 }