1 package org.splat.simer;
3 import java.util.LinkedHashMap;
7 import org.splat.dal.bo.som.ProgressState;
8 import org.splat.dal.bo.som.SimulationContextType;
9 import org.splat.dal.bo.som.Study;
10 import org.splat.kernel.InvalidPropertyException;
11 import org.splat.service.SearchService;
12 import org.splat.service.dto.StudySearchFilterDTO;
13 import org.splat.service.technical.ProjectSettingsService;
14 import org.splat.wapp.Constants;
17 * Search studies form action.
19 public class SearchStudyAction extends
20 AbstractSearchBaseAction<StudySearchFilterDTO> {
25 private static final long serialVersionUID = -1910481357051393077L;
28 * Injected project settings service.
30 private ProjectSettingsService _projectSettings;
32 * Injected search service.
34 private SearchService _searchService;
36 // ==============================================================================================================================
38 // ==============================================================================================================================
41 * Initialize study search form.
43 * @return SUCCESS if no exception, otherwise return ERROR
45 public String doInitialize() {
51 // Final initialization of the form
53 setContextTypeOptions(getInvolvedContexts());
54 initializationFullScreenContext(Constants.OPEN, Constants.NONE,
57 } catch (Exception error) {
58 // No need to roll back the transaction as it is read only
59 LOG.error("Reason: ", error);
61 initializationScreenContext(Constants.NONE);
71 * @see org.splat.simer.AbstractSearchBaseAction#doSearch()
74 protected String doSearch() throws InvalidPropertyException {
75 if (getConnectedUser() != null) {
76 getFilter().setConnectedUserId(getConnectedUser().getIndex());
78 _result = getSearchService().selectStudiesWhere(getFilter());
79 getSession().put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
83 // ==============================================================================================================================
85 // ==============================================================================================================================
90 * @see org.splat.simer.AbstractSearchBaseAction#getInvolvedContexts()
93 protected List<SimulationContextType> getInvolvedContexts() {
94 List<ProjectSettingsService.Step> steps = getProjectSettings()
95 .getStepsOf(Study.class);
96 ProjectSettingsService.Step[] number = steps
97 .toArray(new ProjectSettingsService.Step[steps.size()]);
99 return getSimulationContextService().selectTypesOf(number);
105 * @return array of options with key and value properties
107 public Map<String, String> getStateOptions() {
108 Map<String, String> options = new LinkedHashMap<String, String>();
109 addStateOption(options, "ANY");
110 if (getConnectedUser() != null) {
111 addStateOption(options, ProgressState.inWORK.name());
112 addStateOption(options, ProgressState.inDRAFT.name());
113 addStateOption(options, ProgressState.inCHECK.name());
115 addStateOption(options, ProgressState.APPROVED.name());
116 addStateOption(options, ProgressState.TEMPLATE.name());
121 * Add a state and its translation to the list (map) of options.
128 private void addStateOption(final Map<String, String> options,
129 final String state) {
130 options.put(state, getText("criterion." + state.toLowerCase()));
134 * Get the searchService.
136 * @return the searchService
138 public SearchService getSearchService() {
139 return _searchService;
143 * Set the searchService.
145 * @param searchService
146 * the searchService to set
148 public void setSearchService(final SearchService searchService) {
149 _searchService = searchService;
153 * Get project settings.
155 * @return Project settings service
157 private ProjectSettingsService getProjectSettings() {
158 return _projectSettings;
162 * Set project settings service.
164 * @param projectSettingsService
165 * project settings service
167 public void setProjectSettings(
168 final ProjectSettingsService projectSettingsService) {
169 _projectSettings = projectSettingsService;
175 * @see org.splat.simer.AbstractSearchBaseAction#getFilterName()
178 protected String getFilterName() {
179 return "study.filter";
185 * @see org.splat.simer.AbstractSearchBaseAction#getNewFilter()
188 protected StudySearchFilterDTO getNewFilter() {
189 return new StudySearchFilterDTO();