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.service.technical.StepsConfigService;
15 import org.splat.wapp.Constants;
18 * Search studies form action.
20 public class SearchStudyAction extends
21 AbstractSearchBaseAction<StudySearchFilterDTO> {
26 private static final long serialVersionUID = -1910481357051393077L;
29 * Injected project settings service.
31 private StepsConfigService _stepsConfigService;
33 * Injected search service.
35 private SearchService _searchService;
37 // ==============================================================================================================================
39 // ==============================================================================================================================
42 * Initialize study search form.
44 * @return SUCCESS if no exception, otherwise return ERROR
46 public String doInitialize() {
52 // Final initialization of the form
54 setContextTypeOptions(getInvolvedContexts());
55 initializationFullScreenContext(Constants.OPEN, Constants.NONE,
58 } catch (Exception error) {
59 // No need to roll back the transaction as it is read only
60 LOG.error("Reason: ", error);
62 initializationScreenContext(Constants.NONE);
72 * @see org.splat.simer.AbstractSearchBaseAction#doSearch()
75 protected String doSearch() throws InvalidPropertyException {
76 if (getConnectedUser() != null) {
77 getFilter().setConnectedUserId(getConnectedUser().getIndex());
79 _result = getSearchService().selectStudiesWhere(getFilter());
80 getSession().put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
81 getSession().put(ORDER_KEY, false);
82 getSession().put(CRITERION_KEY, SortCriterion.NAME);
86 // ==============================================================================================================================
88 // ==============================================================================================================================
93 * @see org.splat.simer.AbstractSearchBaseAction#getInvolvedContexts()
96 protected List<SimulationContextType> getInvolvedContexts() {
97 List<ProjectSettingsService.Step> steps = getStepsConfigService()
98 .getStepsOf(Study.class);
99 ProjectSettingsService.Step[] number = steps
100 .toArray(new ProjectSettingsService.Step[steps.size()]);
102 return getSimulationContextService().selectTypesOf(number);
108 * @return array of options with key and value properties
110 public Map<String, String> getStateOptions() {
111 Map<String, String> options = new LinkedHashMap<String, String>();
112 addStateOption(options, "ANY");
113 if (getConnectedUser() != null) {
114 addStateOption(options, ProgressState.inWORK.name());
115 addStateOption(options, ProgressState.inDRAFT.name());
116 addStateOption(options, ProgressState.inCHECK.name());
118 addStateOption(options, ProgressState.APPROVED.name());
119 addStateOption(options, ProgressState.TEMPLATE.name());
124 * Add a state and its translation to the list (map) of options.
131 private void addStateOption(final Map<String, String> options,
132 final String state) {
133 options.put(state, getText("criterion." + state.toLowerCase()));
137 * Get the searchService.
139 * @return the searchService
141 public SearchService getSearchService() {
142 return _searchService;
146 * Set the searchService.
148 * @param searchService
149 * the searchService to set
151 public void setSearchService(final SearchService searchService) {
152 _searchService = searchService;
156 * Get StepsConfigService.
158 * @return StepsConfigService
160 private StepsConfigService getStepsConfigService() {
161 return _stepsConfigService;
165 * Set StepsConfigService.
167 * @param stepsConfigService
170 public void setStepsConfigService(
171 final StepsConfigService stepsConfigService) {
172 _stepsConfigService = stepsConfigService;
178 * @see org.splat.simer.AbstractSearchBaseAction#getFilterName()
181 protected String getFilterName() {
182 return "study.filter";
188 * @see org.splat.simer.AbstractSearchBaseAction#getNewFilter()
191 protected StudySearchFilterDTO getNewFilter() {
192 return new StudySearchFilterDTO();