Salome HOME
Remove the scenario functionality is implemented
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / SearchStudyAction.java
1 package org.splat.simer;
2
3 import java.util.LinkedHashMap;
4 import java.util.List;
5 import java.util.Map;
6
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;
16
17 /**
18  * Search studies form action.
19  */
20 public class SearchStudyAction extends
21                 AbstractSearchBaseAction<StudySearchFilterDTO> {
22
23         /**
24          * Serial version ID.
25          */
26         private static final long serialVersionUID = -1910481357051393077L;
27
28         /**
29          * Injected project settings service.
30          */
31         private StepsConfigService _stepsConfigService;
32         /**
33          * Injected search service.
34          */
35         private SearchService _searchService;
36
37         // ==============================================================================================================================
38         // Action methods
39         // ==============================================================================================================================
40
41         /**
42          * Initialize study search form.
43          * 
44          * @return SUCCESS if no exception, otherwise return ERROR
45          */
46         public String doInitialize() {
47                 String res = SUCCESS;
48                 try {
49                         loadFilter();
50                         doSearch();
51
52                         // Final initialization of the form
53                         setCandidates();
54                         setContextTypeOptions(getInvolvedContexts());
55                         initializationFullScreenContext(Constants.OPEN, Constants.NONE,
56                                         Constants.OPEN);
57
58                 } catch (Exception error) {
59                         // No need to roll back the transaction as it is read only
60                         LOG.error("Reason: ", error);
61
62                         initializationScreenContext(Constants.NONE);
63
64                         res = ERROR;
65                 }
66                 return res;
67         }
68
69         /**
70          * {@inheritDoc}
71          * 
72          * @see org.splat.simer.AbstractSearchBaseAction#doSearch()
73          */
74         @Override
75         protected String doSearch() throws InvalidPropertyException {
76                 if (getConnectedUser() != null) {
77                         getFilter().setConnectedUserId(getConnectedUser().getIndex());
78                 }
79                 _result = getSearchService().selectStudiesWhere(getFilter());
80                 getSession().put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
81                 return "refresh";
82         }
83
84         // ==============================================================================================================================
85         // Getters
86         // ==============================================================================================================================
87
88         /**
89          * {@inheritDoc}
90          * 
91          * @see org.splat.simer.AbstractSearchBaseAction#getInvolvedContexts()
92          */
93         @Override
94         protected List<SimulationContextType> getInvolvedContexts() {
95                 List<ProjectSettingsService.Step> steps = getStepsConfigService()
96                                 .getStepsOf(Study.class);
97                 ProjectSettingsService.Step[] number = steps
98                                 .toArray(new ProjectSettingsService.Step[steps.size()]);
99
100                 return getSimulationContextService().selectTypesOf(number);
101         }
102
103         /**
104          * Get match options.
105          * 
106          * @return array of options with key and value properties
107          */
108         public Map<String, String> getStateOptions() {
109                 Map<String, String> options = new LinkedHashMap<String, String>();
110                 addStateOption(options, "ANY");
111                 if (getConnectedUser() != null) {
112                         addStateOption(options, ProgressState.inWORK.name());
113                         addStateOption(options, ProgressState.inDRAFT.name());
114                         addStateOption(options, ProgressState.inCHECK.name());
115                 }
116                 addStateOption(options, ProgressState.APPROVED.name());
117                 addStateOption(options, ProgressState.TEMPLATE.name());
118                 return options;
119         }
120
121         /**
122          * Add a state and its translation to the list (map) of options.
123          * 
124          * @param options
125          *            the map of options
126          * @param state
127          *            the state to add
128          */
129         private void addStateOption(final Map<String, String> options,
130                         final String state) {
131                 options.put(state, getText("criterion." + state.toLowerCase()));
132         }
133
134         /**
135          * Get the searchService.
136          * 
137          * @return the searchService
138          */
139         public SearchService getSearchService() {
140                 return _searchService;
141         }
142
143         /**
144          * Set the searchService.
145          * 
146          * @param searchService
147          *            the searchService to set
148          */
149         public void setSearchService(final SearchService searchService) {
150                 _searchService = searchService;
151         }
152
153         /**
154          * Get StepsConfigService.
155          * 
156          * @return StepsConfigService
157          */
158         private StepsConfigService getStepsConfigService() {
159                 return _stepsConfigService;
160         }
161
162         /**
163          * Set StepsConfigService.
164          * 
165          * @param stepsConfigService
166          *            StepsConfigService
167          */
168         public void setStepsConfigService(
169                         final StepsConfigService stepsConfigService) {
170                 _stepsConfigService = stepsConfigService;
171         }
172
173         /**
174          * {@inheritDoc}
175          * 
176          * @see org.splat.simer.AbstractSearchBaseAction#getFilterName()
177          */
178         @Override
179         protected String getFilterName() {
180                 return "study.filter";
181         }
182
183         /**
184          * {@inheritDoc}
185          * 
186          * @see org.splat.simer.AbstractSearchBaseAction#getNewFilter()
187          */
188         @Override
189         protected StudySearchFilterDTO getNewFilter() {
190                 return new StudySearchFilterDTO();
191         }
192 }