]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/SearchKnowledgeAction.java
Salome HOME
Menus are improved
[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.kernel.InvalidPropertyException;
7 import org.splat.dal.bo.kernel.User;
8 import org.splat.service.KnowledgeElementTypeService;
9 import org.splat.service.SearchService;
10 import org.splat.service.SimulationContextService;
11 import org.splat.service.UserService;
12 import org.splat.dal.bo.som.KnowledgeElement;
13 import org.splat.dal.bo.som.KnowledgeElementType;
14 import org.splat.dal.bo.som.ProgressState;
15 import org.splat.dal.bo.som.SimulationContext;
16 import org.splat.dal.bo.som.SimulationContextType;
17 import org.splat.dal.bo.som.Visibility;
18
19 /**
20  * Action for searching a knowledge in the database.
21  */
22 public class SearchKnowledgeAction extends SearchBaseAction {
23
24         /**
25          * Serial version ID.
26          */
27         private static final long serialVersionUID = -3104321907432838476L;
28
29         private String visibility = null; // "Private", "Public", "All"
30         private String typid = null; // Knowledge type index when among all
31         private String matchamong = null; // "all" or "any"
32         private String matcontext = null; // "all" or "any"
33         private String refid = null; // Knowledge reference when among ref
34         private String words = null; // Full text search words
35         private List<KnowledgeElementType> types; // Available knowledge types filter (initialized below)
36         private SearchService _searchService;
37         /**
38          * Injected simulation context service.
39          */
40         private SimulationContextService _simulationContextService;
41         /**
42          * Injected knowledge element service.
43          */
44         private KnowledgeElementTypeService _knowledgeElementTypeService;
45
46         /**
47          * Injected user service.
48          */
49         private UserService _userService;
50         
51         /**
52          * Value of the menu property. 
53          * It can be: none, create, open, study, knowledge, sysadmin, help.
54          */
55         private String _menuProperty;
56
57         // ==============================================================================================================================
58         // Action methods
59         // ==============================================================================================================================
60
61         /**
62          * The action initialization.
63          * 
64          * @return SUCCESS if succeeded, ERROR if doSearch() is failed
65          */
66         public String doInitialize() {
67                 
68                 setMenuProperty("open");
69                 initializationScreenContext(_menuProperty);
70                 
71                 try {
72                         loadFilter();
73                         doSearch();
74
75                         // Final initialization of the form
76                         types = getKnowledgeElementTypeService().selectTypesWhere(
77                                         ProgressState.APPROVED);
78                         setCandidates();
79                         setContextTypeOptions(getInvolvedContexts());
80
81                         return SUCCESS;
82                 } catch (Exception error) {
83                         // No need to roll back the transaction as it is read only
84                         logger.error("Reason: ", error);
85                         return ERROR;
86                 }
87         }
88
89         protected String doSearch() throws InvalidPropertyException {
90                 // ----------------------------
91                 setMenuProperty("open");
92                 initializationScreenContext(_menuProperty);
93                 
94                 Map<String, Object> session = getSession();
95                 User user = getConnectedUser();
96
97                 KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
98
99                 // Search matching all criteria
100                 sprop.setType(getKnowledgeElementTypeService().selectType(
101                                 Integer.valueOf(typid)));
102                 if (words.length() > 0)
103                         sprop.setTitle(words);
104                 if (refid.length() > 0)
105                         sprop.setReference(refid);
106                 if (context.size() > 0)
107                         sprop.setSimulationContexts(context);
108                 int index = Integer.valueOf(author);
109                 if (index > 0) {
110                         User him = getUserService().selectUser(index);
111                         sprop.setAuthor(him);
112                 }
113                 // Set of the visibility
114                 if (visibility.equals("all")) {
115                         KnowledgeElement.Properties other = sprop.copy();
116
117                         other.setVisibility(Visibility.PUBLIC);
118                         sprop.setVisibility(Visibility.PRIVATE);
119                         sprop.setActor(user);
120
121                         result = getSearchService().selectKnowledgeElementsWhere(sprop,
122                                         other);
123                 } else {
124                         Visibility reparea = null;
125                         if (visibility.equals("onlypublic"))
126                                 reparea = Visibility.PUBLIC;
127                         else
128                                 reparea = Visibility.valueOf(visibility);
129                         sprop.setVisibility(reparea);
130                         if (reparea == Visibility.PRIVATE)
131                                 sprop.setActor(user);
132
133                         result = getSearchService().selectKnowledgeElementsWhere(sprop);
134                 }
135                 session.put("search.result", result); // For redisplaying the page without re-executing the search
136                 return "refresh";
137         }
138
139         // ==============================================================================================================================
140         // Getters
141         // ==============================================================================================================================
142
143         public String getContextMatch() {
144                 // --------------------------------
145                 return matcontext;
146         }
147
148         public String getCriteriaMatch() {
149                 // ---------------------------------
150                 return matchamong;
151         }
152
153         public List<KnowledgeElementType> getKnowledgeTypes() {
154                 // ------------------------------------------------------
155                 return types;
156         }
157
158         public String getReference() {
159                 // -----------------------------
160                 return refid;
161         }
162
163         public String getState() {
164                 // ------------------------
165                 return typid;
166         }
167
168         public String getVisibility() {
169                 // ------------------------------
170                 return visibility;
171         }
172
173         public String getWords() {
174                 // -------------------------
175                 return words;
176         }
177
178         // ==============================================================================================================================
179         // Setters
180         // ==============================================================================================================================
181
182         public void setContextMatch(String value) {
183                 // ------------------------------------------
184                 this.matcontext = value;
185         }
186
187         public void setCriteriaMatch(String value) {
188                 // -------------------------------------------
189                 this.matchamong = value;
190         }
191
192         public void setReference(String value) {
193                 // ---------------------------------------
194                 this.refid = value;
195         }
196
197         public void setState(String value) {
198                 // ----------------------------------
199                 this.typid = value;
200         }
201
202         public void setVisibility(String value) {
203                 // ----------------------------------------
204                 this.visibility = value;
205         }
206
207         public void setWords(String value) {
208                 // -----------------------------------
209                 this.words = value;
210         }
211
212         // ==============================================================================================================================
213         // Implementation of abstract services
214         // ==============================================================================================================================
215
216         protected List<SimulationContextType> getInvolvedContexts() {
217                 // ------------------------------------------------------------
218                 return getSimulationContextService().selectAllTypes();
219         }
220
221         @SuppressWarnings("unchecked")
222         protected void loadFilter() {
223                 // ----------------------------
224                 Map<String, Object> session = getSession();
225                 User user = getConnectedUser();
226                 Map<String, Object> filter = (Map<String, Object>) session
227                                 .get("knowledge.filter"); // A default filter is supposed being set at start
228
229                 visibility = (String) filter.get("visibility");
230                 matchamong = (String) filter.get("matchamong");
231                 matcontext = (String) filter.get("matcontext");
232                 typid = (String) filter.get("type");
233                 author = (String) filter.get("author");
234                 refid = (String) filter.get("reference");
235                 words = (String) filter.get("title");
236                 context = (List<SimulationContext>) filter.get("context");
237
238                 if (user == null) {
239                         visibility = "onlypublic";
240                 }
241         }
242
243         @SuppressWarnings("unchecked")
244         protected void saveFilter() {
245                 // ----------------------------
246                 Map<String, Object> session = getSession();
247                 Map<String, Object> filter = (Map<String, Object>) session
248                                 .get("knowledge.filter"); // A default filter is supposed being set at start
249
250                 filter.put("visibility", this.visibility);
251                 filter.put("matchamong", this.matchamong);
252                 filter.put("matcontext", this.matcontext);
253                 filter.put("type", this.typid);
254                 filter.put("author", this.author);
255                 filter.put("reference", "");
256                 filter.put("title", this.words);
257
258                 context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
259
260                 // Initialization required by all do functions
261                 types = getKnowledgeElementTypeService().selectTypesWhere(ProgressState.APPROVED);
262         }
263
264         /**
265          * Get the searchService.
266          * 
267          * @return the searchService
268          */
269         public SearchService getSearchService() {
270                 return _searchService;
271         }
272
273         /**
274          * Set the searchService.
275          * 
276          * @param searchService
277          *            the searchService to set
278          */
279         public void setSearchService(SearchService searchService) {
280                 _searchService = searchService;
281         }
282
283         /**
284          * Get the simulationContextService.
285          * 
286          * @return the simulationContextService
287          */
288         public SimulationContextService getSimulationContextService() {
289                 return _simulationContextService;
290         }
291
292         /**
293          * Set the simulationContextService.
294          * 
295          * @param simulationContextService
296          *            the simulationContextService to set
297          */
298         public void setSimulationContextService(
299                         SimulationContextService simulationContextService) {
300                 _simulationContextService = simulationContextService;
301         }
302
303         /**
304          * Get the knowledgeElementTypeService.
305          * 
306          * @return the knowledgeElementTypeService
307          */
308         public KnowledgeElementTypeService getKnowledgeElementTypeService() {
309                 return _knowledgeElementTypeService;
310         }
311
312         /**
313          * Set the knowledgeElementTypeService.
314          * 
315          * @param knowledgeElementTypeService
316          *            the knowledgeElementTypeService to set
317          */
318         public void setKnowledgeElementTypeService(
319                         KnowledgeElementTypeService knowledgeElementTypeService) {
320                 _knowledgeElementTypeService = knowledgeElementTypeService;
321         }
322
323         /**
324          * Get the userService.
325          * @return the userService
326          */
327         public UserService getUserService() {
328                 return _userService;
329         }
330
331         /**
332          * Set the userService.
333          * @param userService the userService to set
334          */
335         public void setUserService(UserService userService) {
336                 _userService = userService;
337         }
338         
339         /**
340          * Get the menuProperty.
341          * @return the menuProperty
342          */
343         public String getMenuProperty() {
344                 return _menuProperty;
345         }
346
347         /**
348          * Set the menuProperty.
349          * @param menuProperty the menuProperty to set
350          */
351         public void setMenuProperty(String menuProperty) {
352                 this._menuProperty = menuProperty;
353         }
354 }