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;
57 // ==============================================================================================================================
59 // ==============================================================================================================================
62 * The action initialization.
64 * @return SUCCESS if succeeded, ERROR if doSearch() is failed
66 public String doInitialize() {
68 setMenuProperty("open");
69 initializationScreenContext(_menuProperty);
75 // Final initialization of the form
76 types = getKnowledgeElementTypeService().selectTypesWhere(
77 ProgressState.APPROVED);
79 setContextTypeOptions(getInvolvedContexts());
82 } catch (Exception error) {
83 // No need to roll back the transaction as it is read only
84 logger.error("Reason: ", error);
89 protected String doSearch() throws InvalidPropertyException {
90 // ----------------------------
91 setMenuProperty("open");
92 initializationScreenContext(_menuProperty);
94 Map<String, Object> session = getSession();
95 User user = getConnectedUser();
97 KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
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);
110 User him = getUserService().selectUser(index);
111 sprop.setAuthor(him);
113 // Set of the visibility
114 if (visibility.equals("all")) {
115 KnowledgeElement.Properties other = sprop.copy();
117 other.setVisibility(Visibility.PUBLIC);
118 sprop.setVisibility(Visibility.PRIVATE);
119 sprop.setActor(user);
121 result = getSearchService().selectKnowledgeElementsWhere(sprop,
124 Visibility reparea = null;
125 if (visibility.equals("onlypublic"))
126 reparea = Visibility.PUBLIC;
128 reparea = Visibility.valueOf(visibility);
129 sprop.setVisibility(reparea);
130 if (reparea == Visibility.PRIVATE)
131 sprop.setActor(user);
133 result = getSearchService().selectKnowledgeElementsWhere(sprop);
135 session.put("search.result", result); // For redisplaying the page without re-executing the search
139 // ==============================================================================================================================
141 // ==============================================================================================================================
143 public String getContextMatch() {
144 // --------------------------------
148 public String getCriteriaMatch() {
149 // ---------------------------------
153 public List<KnowledgeElementType> getKnowledgeTypes() {
154 // ------------------------------------------------------
158 public String getReference() {
159 // -----------------------------
163 public String getState() {
164 // ------------------------
168 public String getVisibility() {
169 // ------------------------------
173 public String getWords() {
174 // -------------------------
178 // ==============================================================================================================================
180 // ==============================================================================================================================
182 public void setContextMatch(String value) {
183 // ------------------------------------------
184 this.matcontext = value;
187 public void setCriteriaMatch(String value) {
188 // -------------------------------------------
189 this.matchamong = value;
192 public void setReference(String value) {
193 // ---------------------------------------
197 public void setState(String value) {
198 // ----------------------------------
202 public void setVisibility(String value) {
203 // ----------------------------------------
204 this.visibility = value;
207 public void setWords(String value) {
208 // -----------------------------------
212 // ==============================================================================================================================
213 // Implementation of abstract services
214 // ==============================================================================================================================
216 protected List<SimulationContextType> getInvolvedContexts() {
217 // ------------------------------------------------------------
218 return getSimulationContextService().selectAllTypes();
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
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");
239 visibility = "onlypublic";
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
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);
258 context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
260 // Initialization required by all do functions
261 types = getKnowledgeElementTypeService().selectTypesWhere(ProgressState.APPROVED);
265 * Get the searchService.
267 * @return the searchService
269 public SearchService getSearchService() {
270 return _searchService;
274 * Set the searchService.
276 * @param searchService
277 * the searchService to set
279 public void setSearchService(SearchService searchService) {
280 _searchService = searchService;
284 * Get the simulationContextService.
286 * @return the simulationContextService
288 public SimulationContextService getSimulationContextService() {
289 return _simulationContextService;
293 * Set the simulationContextService.
295 * @param simulationContextService
296 * the simulationContextService to set
298 public void setSimulationContextService(
299 SimulationContextService simulationContextService) {
300 _simulationContextService = simulationContextService;
304 * Get the knowledgeElementTypeService.
306 * @return the knowledgeElementTypeService
308 public KnowledgeElementTypeService getKnowledgeElementTypeService() {
309 return _knowledgeElementTypeService;
313 * Set the knowledgeElementTypeService.
315 * @param knowledgeElementTypeService
316 * the knowledgeElementTypeService to set
318 public void setKnowledgeElementTypeService(
319 KnowledgeElementTypeService knowledgeElementTypeService) {
320 _knowledgeElementTypeService = knowledgeElementTypeService;
324 * Get the userService.
325 * @return the userService
327 public UserService getUserService() {
332 * Set the userService.
333 * @param userService the userService to set
335 public void setUserService(UserService userService) {
336 _userService = userService;
340 * Get the menuProperty.
341 * @return the menuProperty
343 public String getMenuProperty() {
344 return _menuProperty;
348 * Set the menuProperty.
349 * @param menuProperty the menuProperty to set
351 public void setMenuProperty(String menuProperty) {
352 this._menuProperty = menuProperty;