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