1 package org.splat.simer;
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;
19 * Search studies form action.
21 public class SearchStudyAction extends AbstractSearchBaseAction {
24 * "Private", "Public", "All".
26 private String _visibility = null;
28 * "In-Work", "In-Draft", "In-Check"...
30 private String _state = null;
32 * Criteria match: "all" or "any".
34 private String _criteriaMatch = null;
36 * Simulation context match: "all" or "any".
38 private String _contextMatch = null;
42 private String _reference = null;
44 * Full text search words.
46 private String _words = null;
48 * Injected project settings service.
50 private ProjectSettingsService _projectSettings;
52 * Injected search service.
54 private SearchService _searchService;
56 * Injected simulation context service.
58 private SimulationContextService _simulationContextService;
60 * Injected user service.
62 private UserService _userService;
65 * Value of the menu property.
66 * It can be: none, create, open, study, knowledge, sysadmin, help.
68 private String _menuProperty;
71 * Value of the tool bar property.
72 * It can be: none, standard, study, back.
74 private String _toolProperty;
77 * Value of the left menu property.
78 * It can be: open, study, knowledge, scenario.
80 private String _leftMenuProperty;
85 private static final long serialVersionUID = -1910481357051393077L;
88 refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext
91 // ==============================================================================================================================
93 // ==============================================================================================================================
96 * Initialize study search form.
97 * @return SUCCESS if no exception, otherwise return ERROR
99 public String doInitialize() {
100 String res = SUCCESS;
105 // Final initialization of the form
107 setContextTypeOptions(getInvolvedContexts());
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);
117 setMenuProperty("none");
118 initializationScreenContext(_menuProperty);
127 * @see org.splat.simer.AbstractSearchBaseAction#doSearch()
130 protected String doSearch() throws InvalidPropertyException {
131 Map<String, Object> session = getSession();
132 Study.Properties sprop = new Study.Properties();
134 // Search matching all criteria
135 if (!this._state.equals("ANY")) {
136 sprop.setState(ProgressState.valueOf(this._state));
138 if (_words.length() > 0) {
139 sprop.setTitle(_words);
141 if (_reference.length() > 0) {
142 sprop.setReference(_reference);
144 if (_context.size() > 0) {
145 sprop.setSimulationContexts(_context);
147 int index = Integer.valueOf(_author);
149 User him = getUserService().selectUser(index);
150 sprop.setManager(him);
152 // Set of the visibility
153 if ("all".equals(_visibility)) {
154 Study.Properties other = sprop.copy();
156 other.setVisibility(Visibility.PUBLIC);
157 sprop.setVisibility(Visibility.PRIVATE);
158 sprop.setActor(getConnectedUser());
160 _result = getSearchService().selectStudiesWhere(sprop, other);
162 Visibility reparea = null;
163 if ("onlypublic".equals(_visibility)) {
164 reparea = Visibility.PUBLIC;
166 reparea = Visibility.valueOf(_visibility);
168 sprop.setVisibility(reparea);
169 if (reparea == Visibility.PRIVATE) {
170 sprop.setActor(getConnectedUser());
173 _result = getSearchService().selectStudiesWhere(sprop);
175 session.put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
179 // ==============================================================================================================================
181 // ==============================================================================================================================
183 public String getContextMatch() {
184 return _contextMatch;
187 public String getCriteriaMatch() {
188 return _criteriaMatch;
191 public String getReference() {
195 public String getState() {
199 public String getVisibility() {
203 public String getWords() {
207 // ==============================================================================================================================
209 // ==============================================================================================================================
211 public void setContextMatch(final String value) {
212 this._contextMatch = value;
215 public void setCriteriaMatch(final String value) {
216 this._criteriaMatch = value;
219 public void setReference(final String value) {
220 this._reference = value;
223 public void setState(final String value) {
227 public void setVisibility(final String value) {
228 this._visibility = value;
231 public void setWords(final String value) {
235 // ==============================================================================================================================
236 // Implementation of abstract services
237 // ==============================================================================================================================
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()]);
246 return getSimulationContextService().selectTypesOf(number);
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
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");
267 _visibility = "onlypublic";
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
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);
286 _context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
291 * Get the searchService.
293 * @return the searchService
295 public SearchService getSearchService() {
296 return _searchService;
300 * Set the searchService.
302 * @param searchService
303 * the searchService to set
305 public void setSearchService(final SearchService searchService) {
306 _searchService = searchService;
310 * Get project settings.
312 * @return Project settings service
314 private ProjectSettingsService getProjectSettings() {
315 return _projectSettings;
319 * Set project settings service.
321 * @param projectSettingsService
322 * project settings service
324 public void setProjectSettings(final ProjectSettingsService projectSettingsService) {
325 _projectSettings = projectSettingsService;
329 * Get the simulationContextService.
331 * @return the simulationContextService
334 public SimulationContextService getSimulationContextService() {
335 return _simulationContextService;
339 * Set the simulationContextService.
341 * @param simulationContextService
342 * the simulationContextService to set
345 public void setSimulationContextService(
346 final SimulationContextService simulationContextService) {
347 _simulationContextService = simulationContextService;
351 * Get the userService.
353 * @return the userService
356 public UserService getUserService() {
361 * Set the userService.
364 * the userService to set
367 public void setUserService(final UserService userService) {
368 _userService = userService;
372 * Get the menuProperty.
373 * @return the menuProperty
375 public String getMenuProperty() {
376 return _menuProperty;
380 * Set the menuProperty.
381 * @param menuProperty the menuProperty to set
383 public void setMenuProperty(final String menuProperty) {
384 this._menuProperty = menuProperty;
388 * Get the toolProperty.
389 * @return the toolProperty
391 public String getToolProperty() {
392 return _toolProperty;
396 * Set the toolProperty.
397 * @param toolProperty the toolProperty to set
399 public void setToolProperty(final String toolProperty) {
400 _toolProperty = toolProperty;
404 * Get the leftMenuProperty.
405 * @return the leftMenuProperty
407 public String getLeftMenuProperty() {
408 return _leftMenuProperty;
412 * Set the leftMenuProperty.
413 * @param leftMenuProperty the leftMenuProperty to set
415 public void setLeftMenuProperty(final String leftMenuProperty) {
416 _leftMenuProperty = leftMenuProperty;