1 package org.splat.simer;
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;
20 * Action for searching a knowledge in the database.
22 public class SearchKnowledgeAction extends SearchBaseAction {
27 private static final long serialVersionUID = -3104321907432838476L;
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;
38 * Injected simulation context service.
40 private SimulationContextService _simulationContextService;
42 * Injected knowledge element service.
44 private KnowledgeElementTypeService _knowledgeElementTypeService;
47 * Injected user service.
49 private UserService _userService;
52 * Value of the menu property.
53 * It can be: none, create, open, study, knowledge, sysadmin, help.
55 private String _menuProperty;
58 * Value of the tool bar property.
59 * It can be: none, standard, study, back.
61 private String _toolProperty;
63 // ==============================================================================================================================
65 // ==============================================================================================================================
68 * The action initialization.
70 * @return SUCCESS if succeeded, ERROR if doSearch() is failed
72 public String doInitialize() {
74 setMenuProperty("open");
75 setToolProperty("none");
76 initializationScreenContext(_menuProperty, _toolProperty);
82 // Final initialization of the form
83 types = getKnowledgeElementTypeService().selectTypesWhere(
84 ProgressState.APPROVED);
86 setContextTypeOptions(getInvolvedContexts());
89 } catch (Exception error) {
90 // No need to roll back the transaction as it is read only
91 logger.error("Reason: ", error);
96 protected String doSearch() throws InvalidPropertyException {
97 // ----------------------------
98 setMenuProperty("open");
99 initializationScreenContext(_menuProperty);
101 Map<String, Object> session = getSession();
102 User user = getConnectedUser();
104 KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
106 // Search matching all criteria
107 sprop.setType(getKnowledgeElementTypeService().selectType(
108 Integer.valueOf(typid)));
109 if (words.length() > 0)
110 sprop.setTitle(words);
111 if (refid.length() > 0)
112 sprop.setReference(refid);
113 if (context.size() > 0)
114 sprop.setSimulationContexts(context);
115 int index = Integer.valueOf(author);
117 User him = getUserService().selectUser(index);
118 sprop.setAuthor(him);
120 // Set of the visibility
121 if (visibility.equals("all")) {
122 KnowledgeElement.Properties other = sprop.copy();
124 other.setVisibility(Visibility.PUBLIC);
125 sprop.setVisibility(Visibility.PRIVATE);
126 sprop.setActor(user);
128 result = getSearchService().selectKnowledgeElementsWhere(sprop,
131 Visibility reparea = null;
132 if (visibility.equals("onlypublic"))
133 reparea = Visibility.PUBLIC;
135 reparea = Visibility.valueOf(visibility);
136 sprop.setVisibility(reparea);
137 if (reparea == Visibility.PRIVATE)
138 sprop.setActor(user);
140 result = getSearchService().selectKnowledgeElementsWhere(sprop);
142 session.put("search.result", result); // For redisplaying the page without re-executing the search
146 // ==============================================================================================================================
148 // ==============================================================================================================================
150 public String getContextMatch() {
151 // --------------------------------
155 public String getCriteriaMatch() {
156 // ---------------------------------
160 public List<KnowledgeElementType> getKnowledgeTypes() {
161 // ------------------------------------------------------
165 public String getReference() {
166 // -----------------------------
170 public String getState() {
171 // ------------------------
175 public String getVisibility() {
176 // ------------------------------
180 public String getWords() {
181 // -------------------------
185 // ==============================================================================================================================
187 // ==============================================================================================================================
189 public void setContextMatch(String value) {
190 // ------------------------------------------
191 this.matcontext = value;
194 public void setCriteriaMatch(String value) {
195 // -------------------------------------------
196 this.matchamong = value;
199 public void setReference(String value) {
200 // ---------------------------------------
204 public void setState(String value) {
205 // ----------------------------------
209 public void setVisibility(String value) {
210 // ----------------------------------------
211 this.visibility = value;
214 public void setWords(String value) {
215 // -----------------------------------
219 // ==============================================================================================================================
220 // Implementation of abstract services
221 // ==============================================================================================================================
223 protected List<SimulationContextType> getInvolvedContexts() {
224 // ------------------------------------------------------------
225 return getSimulationContextService().selectAllTypes();
228 @SuppressWarnings("unchecked")
229 protected void loadFilter() {
230 // ----------------------------
231 Map<String, Object> session = getSession();
232 User user = getConnectedUser();
233 Map<String, Object> filter = (Map<String, Object>) session
234 .get("knowledge.filter"); // A default filter is supposed being set at start
236 visibility = (String) filter.get("visibility");
237 matchamong = (String) filter.get("matchamong");
238 matcontext = (String) filter.get("matcontext");
239 typid = (String) filter.get("type");
240 author = (String) filter.get("author");
241 refid = (String) filter.get("reference");
242 words = (String) filter.get("title");
243 context = (List<SimulationContext>) filter.get("context");
246 visibility = "onlypublic";
250 @SuppressWarnings("unchecked")
251 protected void saveFilter() {
252 // ----------------------------
253 Map<String, Object> session = getSession();
254 Map<String, Object> filter = (Map<String, Object>) session
255 .get("knowledge.filter"); // A default filter is supposed being set at start
257 filter.put("visibility", this.visibility);
258 filter.put("matchamong", this.matchamong);
259 filter.put("matcontext", this.matcontext);
260 filter.put("type", this.typid);
261 filter.put("author", this.author);
262 filter.put("reference", "");
263 filter.put("title", this.words);
265 context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
267 // Initialization required by all do functions
268 types = getKnowledgeElementTypeService().selectTypesWhere(ProgressState.APPROVED);
272 * Get the searchService.
274 * @return the searchService
276 public SearchService getSearchService() {
277 return _searchService;
281 * Set the searchService.
283 * @param searchService
284 * the searchService to set
286 public void setSearchService(SearchService searchService) {
287 _searchService = searchService;
291 * Get the simulationContextService.
293 * @return the simulationContextService
295 public SimulationContextService getSimulationContextService() {
296 return _simulationContextService;
300 * Set the simulationContextService.
302 * @param simulationContextService
303 * the simulationContextService to set
305 public void setSimulationContextService(
306 SimulationContextService simulationContextService) {
307 _simulationContextService = simulationContextService;
311 * Get the knowledgeElementTypeService.
313 * @return the knowledgeElementTypeService
315 public KnowledgeElementTypeService getKnowledgeElementTypeService() {
316 return _knowledgeElementTypeService;
320 * Set the knowledgeElementTypeService.
322 * @param knowledgeElementTypeService
323 * the knowledgeElementTypeService to set
325 public void setKnowledgeElementTypeService(
326 KnowledgeElementTypeService knowledgeElementTypeService) {
327 _knowledgeElementTypeService = knowledgeElementTypeService;
331 * Get the userService.
332 * @return the userService
334 public UserService getUserService() {
339 * Set the userService.
340 * @param userService the userService to set
342 public void setUserService(UserService userService) {
343 _userService = userService;
347 * Get the menuProperty.
348 * @return the menuProperty
350 public String getMenuProperty() {
351 return _menuProperty;
355 * Set the menuProperty.
356 * @param menuProperty the menuProperty to set
358 public void setMenuProperty(String menuProperty) {
359 this._menuProperty = menuProperty;
363 * Get the toolProperty.
364 * @return the toolProperty
366 public String getToolProperty() {
367 return _toolProperty;
371 * Set the toolProperty.
372 * @param toolProperty the toolProperty to set
374 public void setToolProperty(final String toolProperty) {
375 _toolProperty = toolProperty;