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;
64 * Value of the left menu property.
65 * It can be: open, study, knowledge, scenario.
67 private String _leftMenuProperty;
69 // ==============================================================================================================================
71 // ==============================================================================================================================
74 * The action initialization.
76 * @return SUCCESS if succeeded, ERROR if doSearch() is failed
78 public String doInitialize() {
80 setMenuProperty("open");
81 setToolProperty("none");
82 setLeftMenuProperty("open");
83 initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
89 // Final initialization of the form
90 types = getKnowledgeElementTypeService().selectTypesWhere(
91 ProgressState.APPROVED);
93 setContextTypeOptions(getInvolvedContexts());
96 } catch (Exception error) {
97 // No need to roll back the transaction as it is read only
98 logger.error("Reason: ", error);
103 protected String doSearch() throws InvalidPropertyException {
104 // ----------------------------
105 setMenuProperty("open");
106 initializationScreenContext(_menuProperty);
108 Map<String, Object> session = getSession();
109 User user = getConnectedUser();
111 KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
113 // Search matching all criteria
114 sprop.setType(getKnowledgeElementTypeService().selectType(
115 Integer.valueOf(typid)));
116 if (words.length() > 0)
117 sprop.setTitle(words);
118 if (refid.length() > 0)
119 sprop.setReference(refid);
120 if (context.size() > 0)
121 sprop.setSimulationContexts(context);
122 int index = Integer.valueOf(author);
124 User him = getUserService().selectUser(index);
125 sprop.setAuthor(him);
127 // Set of the visibility
128 if (visibility.equals("all")) {
129 KnowledgeElement.Properties other = sprop.copy();
131 other.setVisibility(Visibility.PUBLIC);
132 sprop.setVisibility(Visibility.PRIVATE);
133 sprop.setActor(user);
135 result = getSearchService().selectKnowledgeElementsWhere(sprop,
138 Visibility reparea = null;
139 if (visibility.equals("onlypublic"))
140 reparea = Visibility.PUBLIC;
142 reparea = Visibility.valueOf(visibility);
143 sprop.setVisibility(reparea);
144 if (reparea == Visibility.PRIVATE)
145 sprop.setActor(user);
147 result = getSearchService().selectKnowledgeElementsWhere(sprop);
149 session.put("search.result", result); // For redisplaying the page without re-executing the search
153 // ==============================================================================================================================
155 // ==============================================================================================================================
157 public String getContextMatch() {
158 // --------------------------------
162 public String getCriteriaMatch() {
163 // ---------------------------------
167 public List<KnowledgeElementType> getKnowledgeTypes() {
168 // ------------------------------------------------------
172 public String getReference() {
173 // -----------------------------
177 public String getState() {
178 // ------------------------
182 public String getVisibility() {
183 // ------------------------------
187 public String getWords() {
188 // -------------------------
192 // ==============================================================================================================================
194 // ==============================================================================================================================
196 public void setContextMatch(String value) {
197 // ------------------------------------------
198 this.matcontext = value;
201 public void setCriteriaMatch(String value) {
202 // -------------------------------------------
203 this.matchamong = value;
206 public void setReference(String value) {
207 // ---------------------------------------
211 public void setState(String value) {
212 // ----------------------------------
216 public void setVisibility(String value) {
217 // ----------------------------------------
218 this.visibility = value;
221 public void setWords(String value) {
222 // -----------------------------------
226 // ==============================================================================================================================
227 // Implementation of abstract services
228 // ==============================================================================================================================
230 protected List<SimulationContextType> getInvolvedContexts() {
231 // ------------------------------------------------------------
232 return getSimulationContextService().selectAllTypes();
235 @SuppressWarnings("unchecked")
236 protected void loadFilter() {
237 // ----------------------------
238 Map<String, Object> session = getSession();
239 User user = getConnectedUser();
240 Map<String, Object> filter = (Map<String, Object>) session
241 .get("knowledge.filter"); // A default filter is supposed being set at start
243 visibility = (String) filter.get("visibility");
244 matchamong = (String) filter.get("matchamong");
245 matcontext = (String) filter.get("matcontext");
246 typid = (String) filter.get("type");
247 author = (String) filter.get("author");
248 refid = (String) filter.get("reference");
249 words = (String) filter.get("title");
250 context = (List<SimulationContext>) filter.get("context");
253 visibility = "onlypublic";
257 @SuppressWarnings("unchecked")
258 protected void saveFilter() {
259 // ----------------------------
260 Map<String, Object> session = getSession();
261 Map<String, Object> filter = (Map<String, Object>) session
262 .get("knowledge.filter"); // A default filter is supposed being set at start
264 filter.put("visibility", this.visibility);
265 filter.put("matchamong", this.matchamong);
266 filter.put("matcontext", this.matcontext);
267 filter.put("type", this.typid);
268 filter.put("author", this.author);
269 filter.put("reference", "");
270 filter.put("title", this.words);
272 context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
274 // Initialization required by all do functions
275 types = getKnowledgeElementTypeService().selectTypesWhere(ProgressState.APPROVED);
279 * Get the searchService.
281 * @return the searchService
283 public SearchService getSearchService() {
284 return _searchService;
288 * Set the searchService.
290 * @param searchService
291 * the searchService to set
293 public void setSearchService(SearchService searchService) {
294 _searchService = searchService;
298 * Get the simulationContextService.
300 * @return the simulationContextService
302 public SimulationContextService getSimulationContextService() {
303 return _simulationContextService;
307 * Set the simulationContextService.
309 * @param simulationContextService
310 * the simulationContextService to set
312 public void setSimulationContextService(
313 SimulationContextService simulationContextService) {
314 _simulationContextService = simulationContextService;
318 * Get the knowledgeElementTypeService.
320 * @return the knowledgeElementTypeService
322 public KnowledgeElementTypeService getKnowledgeElementTypeService() {
323 return _knowledgeElementTypeService;
327 * Set the knowledgeElementTypeService.
329 * @param knowledgeElementTypeService
330 * the knowledgeElementTypeService to set
332 public void setKnowledgeElementTypeService(
333 KnowledgeElementTypeService knowledgeElementTypeService) {
334 _knowledgeElementTypeService = knowledgeElementTypeService;
338 * Get the userService.
339 * @return the userService
341 public UserService getUserService() {
346 * Set the userService.
347 * @param userService the userService to set
349 public void setUserService(UserService userService) {
350 _userService = userService;
354 * Get the menuProperty.
355 * @return the menuProperty
357 public String getMenuProperty() {
358 return _menuProperty;
362 * Set the menuProperty.
363 * @param menuProperty the menuProperty to set
365 public void setMenuProperty(String menuProperty) {
366 this._menuProperty = menuProperty;
370 * Get the toolProperty.
371 * @return the toolProperty
373 public String getToolProperty() {
374 return _toolProperty;
378 * Set the toolProperty.
379 * @param toolProperty the toolProperty to set
381 public void setToolProperty(final String toolProperty) {
382 _toolProperty = toolProperty;
386 * Get the leftMenuProperty.
387 * @return the leftMenuProperty
389 public String getLeftMenuProperty() {
390 return _leftMenuProperty;
394 * Set the leftMenuProperty.
395 * @param leftMenuProperty the leftMenuProperty to set
397 public void setLeftMenuProperty(final String leftMenuProperty) {
398 _leftMenuProperty = leftMenuProperty;