]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/SearchKnowledgeAction.java
Salome HOME
Rename the scenario functionality is implemented
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / SearchKnowledgeAction.java
1 package org.splat.simer;
2
3 import java.util.List;
4 import java.util.Map;
5
6 import org.splat.dal.bo.kernel.User;
7 import org.splat.dal.bo.som.KnowledgeElement;
8 import org.splat.dal.bo.som.KnowledgeElementType;
9 import org.splat.dal.bo.som.ProgressState;
10 import org.splat.dal.bo.som.SimulationContext;
11 import org.splat.dal.bo.som.SimulationContextType;
12 import org.splat.dal.bo.som.Visibility;
13 import org.splat.kernel.InvalidPropertyException;
14 import org.splat.service.KnowledgeElementTypeService;
15 import org.splat.service.SearchService;
16 import org.splat.wapp.Constants;
17
18 /**
19  * Action for searching a knowledge in the database.
20  */
21 public class SearchKnowledgeAction extends AbstractSearchBaseAction {
22
23         /**
24          * Serial version ID.
25          */
26         private static final long serialVersionUID = -3104321907432838476L;
27
28         /**
29          * Knowledge type index when among all.
30          */
31         private String _state = null;
32         /**
33          * Criteria match: "all" or "any".
34          */
35         private String _criteriaMatch = null;
36         /**
37          * Simulation context match: "all" or "any".
38          */
39         private String _contextMatch = null;
40         /**
41          * Knowledge reference when among ref.
42          */
43         private String _reference = null;
44         /**
45          * Full text search words.
46          */
47         private String _words = null;
48         /**
49          * Available knowledge types filter (initialized below).
50          */
51         private transient List<KnowledgeElementType> _knowledgeTypes;
52         /**
53          * Injected search service.
54          */
55         private SearchService _searchService;
56         /**
57          * Injected knowledge element service.
58          */
59         private KnowledgeElementTypeService _knowledgeElementTypeService;
60
61         // ==============================================================================================================================
62         // Action methods
63         // ==============================================================================================================================
64
65         /**
66          * The action initialization.
67          * 
68          * @return SUCCESS if succeeded, ERROR if doSearch() is failed
69          */
70         public String doInitialize() {
71
72                 initializationFullScreenContext(Constants.OPEN, Constants.NONE,
73                                 Constants.OPEN);
74
75                 String res = SUCCESS;
76                 try {
77                         loadFilter();
78                         doSearch();
79
80                         // Final initialization of the form
81                         _knowledgeTypes = getKnowledgeElementTypeService()
82                                         .selectTypesWhere(ProgressState.APPROVED);
83                         setCandidates();
84                         setContextTypeOptions(getInvolvedContexts());
85                 } catch (Exception error) {
86                         // No need to roll back the transaction as it is read only
87                         LOG.error("Reason: ", error);
88                         res = ERROR;
89                 }
90                 return res;
91         }
92
93         @Override
94         protected String doSearch() throws InvalidPropertyException {
95
96                 initializationScreenContext(Constants.OPEN);
97                 Map<String, Object> session = getSession();
98                 KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
99
100                 // Search matching all criteria
101                 sprop.setType(getKnowledgeElementTypeService().selectType(
102                                 Integer.valueOf(_state)));
103                 if (_words.length() > 0) {
104                         sprop.setTitle(_words);
105                 }
106                 if (_reference.length() > 0) {
107                         sprop.setReference(_reference);
108                 }
109                 if (_context.size() > 0) {
110                         sprop.setSimulationContexts(_context);
111                 }
112                 int index = Integer.valueOf(_author);
113                 if (index > 0) {
114                         User him = getUserService().selectUser(index);
115                         sprop.setAuthor(him);
116                 }
117                 // Set of the visibility
118                         KnowledgeElement.Properties other = sprop.copy();
119
120                         other.setVisibility(Visibility.PUBLIC);
121                         sprop.setVisibility(Visibility.PRIVATE);
122                         sprop.setActor(getConnectedUser());
123
124                         _result = getSearchService().selectKnowledgeElementsWhere(sprop,
125                                         other);
126                 session.put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
127                 return "refresh";
128         }
129
130         // ==============================================================================================================================
131         // Getters
132         // ==============================================================================================================================
133
134         public String getContextMatch() {
135                 return _contextMatch;
136         }
137
138         public String getCriteriaMatch() {
139                 return _criteriaMatch;
140         }
141
142         public List<KnowledgeElementType> getKnowledgeTypes() {
143                 return _knowledgeTypes;
144         }
145
146         public String getReference() {
147                 return _reference;
148         }
149
150         public String getState() {
151                 return _state;
152         }
153
154         public String getWords() {
155                 return _words;
156         }
157
158         // ==============================================================================================================================
159         // Setters
160         // ==============================================================================================================================
161
162         public void setContextMatch(final String value) {
163                 this._contextMatch = value;
164         }
165
166         public void setCriteriaMatch(final String value) {
167                 this._criteriaMatch = value;
168         }
169
170         public void setReference(final String value) {
171                 this._reference = value;
172         }
173
174         public void setState(final String value) {
175                 this._state = value;
176         }
177
178         public void setWords(final String value) {
179                 this._words = value;
180         }
181
182         // ==============================================================================================================================
183         // Implementation of abstract services
184         // ==============================================================================================================================
185
186         @Override
187         protected List<SimulationContextType> getInvolvedContexts() {
188                 return getSimulationContextService().selectAllTypes();
189         }
190
191         @Override
192         @SuppressWarnings("unchecked")
193         protected void loadFilter() {
194                 Map<String, Object> session = getSession();
195                 Map<String, Object> filter = (Map<String, Object>) session
196                                 .get("knowledge.filter"); // A default filter is supposed being set at start
197
198                 _criteriaMatch = (String) filter.get("matchamong");
199                 _contextMatch = (String) filter.get("matcontext");
200                 _state = (String) filter.get("type");
201                 _author = (String) filter.get("author");
202                 _reference = (String) filter.get("reference");
203                 _words = (String) filter.get("title");
204                 _context = (List<SimulationContext>) filter.get("context");
205         }
206
207         @Override
208         @SuppressWarnings("unchecked")
209         protected void saveFilter() {
210                 Map<String, Object> session = getSession();
211                 Map<String, Object> filter = (Map<String, Object>) session
212                                 .get("knowledge.filter"); // A default filter is supposed being set at start
213
214                 filter.put("matchamong", this._criteriaMatch);
215                 filter.put("matcontext", this._contextMatch);
216                 filter.put("type", this._state);
217                 filter.put("author", this._author);
218                 filter.put("reference", "");
219                 filter.put("title", this._words);
220
221                 _context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
222
223                 // Initialization required by all do functions
224                 _knowledgeTypes = getKnowledgeElementTypeService().selectTypesWhere(
225                                 ProgressState.APPROVED);
226         }
227
228         /**
229          * Get the searchService.
230          * 
231          * @return the searchService
232          */
233         public SearchService getSearchService() {
234                 return _searchService;
235         }
236
237         /**
238          * Set the searchService.
239          * 
240          * @param searchService
241          *            the searchService to set
242          */
243         public void setSearchService(final SearchService searchService) {
244                 _searchService = searchService;
245         }
246
247         /**
248          * Get the knowledgeElementTypeService.
249          * 
250          * @return the knowledgeElementTypeService
251          */
252         public KnowledgeElementTypeService getKnowledgeElementTypeService() {
253                 return _knowledgeElementTypeService;
254         }
255
256         /**
257          * Set the knowledgeElementTypeService.
258          * 
259          * @param knowledgeElementTypeService
260          *            the knowledgeElementTypeService to set
261          */
262         public void setKnowledgeElementTypeService(
263                         final KnowledgeElementTypeService knowledgeElementTypeService) {
264                 _knowledgeElementTypeService = knowledgeElementTypeService;
265         }
266 }