]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/SearchStudyAction.java
Salome HOME
Sort study and knowledge results functionalities are 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                 getSession().put(ORDER_KEY, false);
82                 getSession().put(CRITERION_KEY, SortCriterion.NAME);
83                 return "refresh";
84         }
85
86         // ==============================================================================================================================
87         // Getters
88         // ==============================================================================================================================
89
90         /**
91          * {@inheritDoc}
92          * 
93          * @see org.splat.simer.AbstractSearchBaseAction#getInvolvedContexts()
94          */
95         @Override
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()]);
101
102                 return getSimulationContextService().selectTypesOf(number);
103         }
104
105         /**
106          * Get match options.
107          * 
108          * @return array of options with key and value properties
109          */
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());
117                 }
118                 addStateOption(options, ProgressState.APPROVED.name());
119                 addStateOption(options, ProgressState.TEMPLATE.name());
120                 return options;
121         }
122
123         /**
124          * Add a state and its translation to the list (map) of options.
125          * 
126          * @param options
127          *            the map of options
128          * @param state
129          *            the state to add
130          */
131         private void addStateOption(final Map<String, String> options,
132                         final String state) {
133                 options.put(state, getText("criterion." + state.toLowerCase()));
134         }
135
136         /**
137          * Get the searchService.
138          * 
139          * @return the searchService
140          */
141         public SearchService getSearchService() {
142                 return _searchService;
143         }
144
145         /**
146          * Set the searchService.
147          * 
148          * @param searchService
149          *            the searchService to set
150          */
151         public void setSearchService(final SearchService searchService) {
152                 _searchService = searchService;
153         }
154
155         /**
156          * Get StepsConfigService.
157          * 
158          * @return StepsConfigService
159          */
160         private StepsConfigService getStepsConfigService() {
161                 return _stepsConfigService;
162         }
163
164         /**
165          * Set StepsConfigService.
166          * 
167          * @param stepsConfigService
168          *            StepsConfigService
169          */
170         public void setStepsConfigService(
171                         final StepsConfigService stepsConfigService) {
172                 _stepsConfigService = stepsConfigService;
173         }
174
175         /**
176          * {@inheritDoc}
177          * 
178          * @see org.splat.simer.AbstractSearchBaseAction#getFilterName()
179          */
180         @Override
181         protected String getFilterName() {
182                 return "study.filter";
183         }
184
185         /**
186          * {@inheritDoc}
187          * 
188          * @see org.splat.simer.AbstractSearchBaseAction#getNewFilter()
189          */
190         @Override
191         protected StudySearchFilterDTO getNewFilter() {
192                 return new StudySearchFilterDTO();
193         }
194 }