1 package org.splat.simer;
3 import java.util.LinkedHashMap;
7 import org.splat.dal.bo.kernel.User;
8 import org.splat.dal.bo.som.ProgressState;
9 import org.splat.dal.bo.som.SimulationContext;
10 import org.splat.dal.bo.som.SimulationContextType;
11 import org.splat.dal.bo.som.Study;
12 import org.splat.kernel.InvalidPropertyException;
13 import org.splat.service.SearchService;
14 import org.splat.service.technical.ProjectSettingsService;
15 import org.splat.wapp.Constants;
18 * Search studies form action.
20 public class SearchStudyAction extends AbstractSearchBaseAction {
25 private static final long serialVersionUID = -1910481357051393077L;
28 * "In-Work", "In-Draft", "In-Check"...
30 private String _state = null;
34 private String _reference = null;
36 * Injected project settings service.
38 private ProjectSettingsService _projectSettings;
40 * Injected search service.
42 private SearchService _searchService;
45 refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext
48 // ==============================================================================================================================
50 // ==============================================================================================================================
53 * Initialize study search form.
55 * @return SUCCESS if no exception, otherwise return ERROR
57 public String doInitialize() {
63 // Final initialization of the form
65 setContextTypeOptions(getInvolvedContexts());
66 initializationFullScreenContext(Constants.OPEN, Constants.NONE,
69 } catch (Exception error) {
70 // No need to roll back the transaction as it is read only
71 LOG.error("Reason: ", error);
73 initializationScreenContext(Constants.NONE);
83 * @see org.splat.simer.AbstractSearchBaseAction#doSearch()
86 protected String doSearch() throws InvalidPropertyException {
87 Map<String, Object> session = getSession();
88 Study.Properties sprop = new Study.Properties();
90 // Search matching all criteria
91 if (!this._state.equals("ANY")) {
92 sprop.setState(ProgressState.valueOf(this._state));
94 if (getWords().length() > 0) {
95 sprop.setTitle(getWords());
97 if (_reference.length() > 0) {
98 sprop.setReference(_reference);
100 if (_context.size() > 0) {
101 sprop.setSimulationContexts(_context);
103 int index = Integer.valueOf(_author);
105 User him = getUserService().selectUser(index);
106 sprop.setManager(him);
108 sprop.setActor(getConnectedUser());
110 _result = getSearchService().selectStudiesWhere(
111 "all".equals(getCriteriaMatch()),
112 "all".equals(getContextMatch()), sprop);
113 session.put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
117 // ==============================================================================================================================
119 // ==============================================================================================================================
121 public String getReference() {
125 public String getState() {
129 public void setReference(final String value) {
130 this._reference = value;
133 public void setState(final String value) {
138 protected List<SimulationContextType> getInvolvedContexts() {
139 List<ProjectSettingsService.Step> steps = getProjectSettings()
140 .getStepsOf(Study.class);
141 ProjectSettingsService.Step[] number = steps
142 .toArray(new ProjectSettingsService.Step[steps.size()]);
144 return getSimulationContextService().selectTypesOf(number);
148 @SuppressWarnings("unchecked")
149 protected void loadFilter() {
150 Map<String, Object> session = getSession();
151 Map<String, Object> filter = (Map<String, Object>) session
152 .get("study.filter"); // A default filter is supposed being set at start
154 setCriteriaMatch((String) filter.get("matchamong"));
155 setContextMatch((String) filter.get("matcontext"));
156 _state = (String) filter.get("state");
157 _author = (String) filter.get("author");
158 _reference = (String) filter.get("reference");
159 setWords((String) filter.get("title"));
160 _context = (List<SimulationContext>) filter.get("context");
164 @SuppressWarnings("unchecked")
165 protected void saveFilter() {
166 Map<String, Object> session = getSession();
167 Map<String, Object> filter = (Map<String, Object>) session
168 .get("study.filter"); // A default filter is supposed being set at start
170 filter.put("matchamong", getCriteriaMatch());
171 filter.put("matcontext", getContextMatch());
172 filter.put("state", this._state);
173 filter.put("author", this._author);
174 filter.put("reference", this._reference);
175 filter.put("title", getWords());
177 _context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
184 * @return array of options with key and value properties
186 public Map<String, String> getStateOptions() {
187 Map<String, String> options = new LinkedHashMap<String, String>();
188 addStateOption(options, "ANY");
189 if (getConnectedUser() != null) {
190 addStateOption(options, ProgressState.inWORK.name());
191 addStateOption(options, ProgressState.inDRAFT.name());
192 addStateOption(options, ProgressState.inCHECK.name());
194 addStateOption(options, ProgressState.APPROVED.name());
195 addStateOption(options, ProgressState.TEMPLATE.name());
200 * Add a state and its translation to the list (map) of options.
207 private void addStateOption(final Map<String, String> options,
208 final String state) {
209 options.put(state, getText("criterion." + state.toLowerCase()));
213 * Get the searchService.
215 * @return the searchService
217 public SearchService getSearchService() {
218 return _searchService;
222 * Set the searchService.
224 * @param searchService
225 * the searchService to set
227 public void setSearchService(final SearchService searchService) {
228 _searchService = searchService;
232 * Get project settings.
234 * @return Project settings service
236 private ProjectSettingsService getProjectSettings() {
237 return _projectSettings;
241 * Set project settings service.
243 * @param projectSettingsService
244 * project settings service
246 public void setProjectSettings(
247 final ProjectSettingsService projectSettingsService) {
248 _projectSettings = projectSettingsService;