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.kernel.InvalidPropertyException;
12 import org.splat.service.SearchService;
13 import org.splat.service.technical.ProjectSettingsService;
14 import org.splat.wapp.Constants;
17 * Search studies form action.
19 public class SearchStudyAction extends AbstractSearchBaseAction {
24 private static final long serialVersionUID = -1910481357051393077L;
27 * "In-Work", "In-Draft", "In-Check"...
29 private String _state = null;
31 * Criteria match: "all" or "any".
33 private String _criteriaMatch = null;
35 * Simulation context match: "all" or "any".
37 private String _contextMatch = null;
41 private String _reference = null;
43 * Full text search words.
45 private String _words = null;
47 * Injected project settings service.
49 private ProjectSettingsService _projectSettings;
51 * Injected search service.
53 private SearchService _searchService;
56 refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext
59 // ==============================================================================================================================
61 // ==============================================================================================================================
64 * Initialize study search form.
66 * @return SUCCESS if no exception, otherwise return ERROR
68 public String doInitialize() {
74 // Final initialization of the form
76 setContextTypeOptions(getInvolvedContexts());
77 initializationFullScreenContext(Constants.OPEN, Constants.NONE,
80 } catch (Exception error) {
81 // No need to roll back the transaction as it is read only
82 LOG.error("Reason: ", error);
84 initializationScreenContext(Constants.NONE);
94 * @see org.splat.simer.AbstractSearchBaseAction#doSearch()
97 protected String doSearch() throws InvalidPropertyException {
98 Map<String, Object> session = getSession();
99 Study.Properties sprop = new Study.Properties();
101 // Search matching all criteria
102 if (!this._state.equals("ANY")) {
103 sprop.setState(ProgressState.valueOf(this._state));
105 if (_words.length() > 0) {
106 sprop.setTitle(_words);
108 if (_reference.length() > 0) {
109 sprop.setReference(_reference);
111 if (_context.size() > 0) {
112 sprop.setSimulationContexts(_context);
114 int index = Integer.valueOf(_author);
116 User him = getUserService().selectUser(index);
117 sprop.setManager(him);
119 sprop.setActor(getConnectedUser());
121 _result = getSearchService().selectStudiesWhere(
122 "all".equals(_criteriaMatch), "all".equals(_contextMatch),
124 session.put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
128 // ==============================================================================================================================
130 // ==============================================================================================================================
132 public String getContextMatch() {
133 return _contextMatch;
136 public String getCriteriaMatch() {
137 return _criteriaMatch;
140 public String getReference() {
144 public String getState() {
148 public String getWords() {
152 // ==============================================================================================================================
154 // ==============================================================================================================================
156 public void setContextMatch(final String value) {
157 this._contextMatch = value;
160 public void setCriteriaMatch(final String value) {
161 this._criteriaMatch = value;
164 public void setReference(final String value) {
165 this._reference = value;
168 public void setState(final String value) {
172 public void setWords(final String value) {
176 // ==============================================================================================================================
177 // Implementation of abstract services
178 // ==============================================================================================================================
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()]);
187 return getSimulationContextService().selectTypesOf(number);
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
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");
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
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);
220 _context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
225 * Get the searchService.
227 * @return the searchService
229 public SearchService getSearchService() {
230 return _searchService;
234 * Set the searchService.
236 * @param searchService
237 * the searchService to set
239 public void setSearchService(final SearchService searchService) {
240 _searchService = searchService;
244 * Get project settings.
246 * @return Project settings service
248 private ProjectSettingsService getProjectSettings() {
249 return _projectSettings;
253 * Set project settings service.
255 * @param projectSettingsService
256 * project settings service
258 public void setProjectSettings(
259 final ProjectSettingsService projectSettingsService) {
260 _projectSettings = projectSettingsService;