1 package org.splat.simer;
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.service.SimulationContextService;
17 import org.splat.service.UserService;
20 * Action for searching a knowledge in the database.
22 public class SearchKnowledgeAction extends AbstractSearchBaseAction {
27 private static final long serialVersionUID = -3104321907432838476L;
30 * "Private", "Public", "All".
32 private String _visibility = null;
34 * Knowledge type index when among all.
36 private String _state = null;
38 * Criteria match: "all" or "any".
40 private String _criteriaMatch = null;
42 * Simulation context match: "all" or "any".
44 private String _contextMatch = null;
46 * Knowledge reference when among ref.
48 private String _reference = null;
50 * Full text search words.
52 private String _words = null;
54 * Available knowledge types filter (initialized below).
56 private transient List<KnowledgeElementType> _knowledgeTypes;
58 * Injected search service.
60 private SearchService _searchService;
62 * Injected simulation context service.
64 private SimulationContextService _simulationContextService;
66 * Injected knowledge element service.
68 private KnowledgeElementTypeService _knowledgeElementTypeService;
71 * Injected user service.
73 private UserService _userService;
76 * Value of the menu property.
77 * It can be: none, create, open, study, knowledge, sysadmin, help.
79 private String _menuProperty;
82 * Value of the tool bar property.
83 * It can be: none, standard, study, back.
85 private String _toolProperty;
88 * Value of the left menu property.
89 * It can be: open, study, knowledge, scenario.
91 private String _leftMenuProperty;
93 // ==============================================================================================================================
95 // ==============================================================================================================================
98 * The action initialization.
100 * @return SUCCESS if succeeded, ERROR if doSearch() is failed
102 public String doInitialize() {
104 setMenuProperty("open");
105 setToolProperty("none");
106 setLeftMenuProperty("open");
107 initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
109 String res = SUCCESS;
114 // Final initialization of the form
115 _knowledgeTypes = getKnowledgeElementTypeService().selectTypesWhere(
116 ProgressState.APPROVED);
118 setContextTypeOptions(getInvolvedContexts());
119 } catch (Exception error) {
120 // No need to roll back the transaction as it is read only
121 LOG.error("Reason: ", error);
128 protected String doSearch() throws InvalidPropertyException {
129 // ----------------------------
130 setMenuProperty("open");
131 initializationScreenContext(_menuProperty);
133 Map<String, Object> session = getSession();
135 KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
137 // Search matching all criteria
138 sprop.setType(getKnowledgeElementTypeService().selectType(
139 Integer.valueOf(_state)));
140 if (_words.length() > 0) {
141 sprop.setTitle(_words);
143 if (_reference.length() > 0) {
144 sprop.setReference(_reference);
146 if (_context.size() > 0) {
147 sprop.setSimulationContexts(_context);
149 int index = Integer.valueOf(_author);
151 User him = getUserService().selectUser(index);
152 sprop.setAuthor(him);
154 // Set of the visibility
155 if ("all".equals(_visibility)) {
156 KnowledgeElement.Properties other = sprop.copy();
158 other.setVisibility(Visibility.PUBLIC);
159 sprop.setVisibility(Visibility.PRIVATE);
160 sprop.setActor(getConnectedUser());
162 _result = getSearchService().selectKnowledgeElementsWhere(sprop,
166 if ("onlypublic".equals(_visibility)) {
167 reparea = Visibility.PUBLIC;
169 reparea = Visibility.valueOf(_visibility);
171 sprop.setVisibility(reparea);
172 if (reparea == Visibility.PRIVATE) {
173 sprop.setActor(getConnectedUser());
176 _result = getSearchService().selectKnowledgeElementsWhere(sprop);
178 session.put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
182 // ==============================================================================================================================
184 // ==============================================================================================================================
186 public String getContextMatch() {
187 // --------------------------------
188 return _contextMatch;
191 public String getCriteriaMatch() {
192 // ---------------------------------
193 return _criteriaMatch;
196 public List<KnowledgeElementType> getKnowledgeTypes() {
197 // ------------------------------------------------------
198 return _knowledgeTypes;
201 public String getReference() {
202 // -----------------------------
206 public String getState() {
207 // ------------------------
211 public String getVisibility() {
212 // ------------------------------
216 public String getWords() {
217 // -------------------------
221 // ==============================================================================================================================
223 // ==============================================================================================================================
225 public void setContextMatch(final String value) {
226 // ------------------------------------------
227 this._contextMatch = value;
230 public void setCriteriaMatch(final String value) {
231 // -------------------------------------------
232 this._criteriaMatch = value;
235 public void setReference(final String value) {
236 // ---------------------------------------
237 this._reference = value;
240 public void setState(final String value) {
241 // ----------------------------------
245 public void setVisibility(final String value) {
246 // ----------------------------------------
247 this._visibility = value;
250 public void setWords(final String value) {
251 // -----------------------------------
255 // ==============================================================================================================================
256 // Implementation of abstract services
257 // ==============================================================================================================================
260 protected List<SimulationContextType> getInvolvedContexts() {
261 // ------------------------------------------------------------
262 return getSimulationContextService().selectAllTypes();
266 @SuppressWarnings("unchecked")
267 protected void loadFilter() {
268 // ----------------------------
269 Map<String, Object> session = getSession();
270 User user = getConnectedUser();
271 Map<String, Object> filter = (Map<String, Object>) session
272 .get("knowledge.filter"); // A default filter is supposed being set at start
274 _visibility = (String) filter.get("visibility");
275 _criteriaMatch = (String) filter.get("matchamong");
276 _contextMatch = (String) filter.get("matcontext");
277 _state = (String) filter.get("type");
278 _author = (String) filter.get("author");
279 _reference = (String) filter.get("reference");
280 _words = (String) filter.get("title");
281 _context = (List<SimulationContext>) filter.get("context");
284 _visibility = "onlypublic";
289 @SuppressWarnings("unchecked")
290 protected void saveFilter() {
291 // ----------------------------
292 Map<String, Object> session = getSession();
293 Map<String, Object> filter = (Map<String, Object>) session
294 .get("knowledge.filter"); // A default filter is supposed being set at start
296 filter.put("visibility", this._visibility);
297 filter.put("matchamong", this._criteriaMatch);
298 filter.put("matcontext", this._contextMatch);
299 filter.put("type", this._state);
300 filter.put("author", this._author);
301 filter.put("reference", "");
302 filter.put("title", this._words);
304 _context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
306 // Initialization required by all do functions
307 _knowledgeTypes = getKnowledgeElementTypeService().selectTypesWhere(ProgressState.APPROVED);
311 * Get the searchService.
313 * @return the searchService
315 public SearchService getSearchService() {
316 return _searchService;
320 * Set the searchService.
322 * @param searchService
323 * the searchService to set
325 public void setSearchService(final SearchService searchService) {
326 _searchService = searchService;
330 * Get the simulationContextService.
332 * @return the simulationContextService
335 public SimulationContextService getSimulationContextService() {
336 return _simulationContextService;
340 * Set the simulationContextService.
342 * @param simulationContextService
343 * the simulationContextService to set
346 public void setSimulationContextService(
347 final SimulationContextService simulationContextService) {
348 _simulationContextService = simulationContextService;
352 * Get the knowledgeElementTypeService.
354 * @return the knowledgeElementTypeService
356 public KnowledgeElementTypeService getKnowledgeElementTypeService() {
357 return _knowledgeElementTypeService;
361 * Set the knowledgeElementTypeService.
363 * @param knowledgeElementTypeService
364 * the knowledgeElementTypeService to set
366 public void setKnowledgeElementTypeService(
367 final KnowledgeElementTypeService knowledgeElementTypeService) {
368 _knowledgeElementTypeService = knowledgeElementTypeService;
372 * Get the userService.
373 * @return the userService
376 public UserService getUserService() {
381 * Set the userService.
382 * @param userService the userService to set
385 public void setUserService(final UserService userService) {
386 _userService = userService;
390 * Get the menuProperty.
391 * @return the menuProperty
393 public String getMenuProperty() {
394 return _menuProperty;
398 * Set the menuProperty.
399 * @param menuProperty the menuProperty to set
401 public void setMenuProperty(final String menuProperty) {
402 this._menuProperty = menuProperty;
406 * Get the toolProperty.
407 * @return the toolProperty
409 public String getToolProperty() {
410 return _toolProperty;
414 * Set the toolProperty.
415 * @param toolProperty the toolProperty to set
417 public void setToolProperty(final String toolProperty) {
418 _toolProperty = toolProperty;
422 * Get the leftMenuProperty.
423 * @return the leftMenuProperty
425 public String getLeftMenuProperty() {
426 return _leftMenuProperty;
430 * Set the leftMenuProperty.
431 * @param leftMenuProperty the leftMenuProperty to set
433 public void setLeftMenuProperty(final String leftMenuProperty) {
434 _leftMenuProperty = leftMenuProperty;