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;
51 // ==============================================================================================================================
53 // ==============================================================================================================================
56 * The action initialization.
58 * @return SUCCESS if succeeded, ERROR if doSearch() is failed
60 public String doInitialize() {
65 // Final initialization of the form
66 types = getKnowledgeElementTypeService().selectTypesWhere(
67 ProgressState.APPROVED);
69 setContextTypeOptions(getInvolvedContexts());
72 } catch (Exception error) {
73 // No need to roll back the transaction as it is read only
74 logger.error("Reason: ", error);
79 protected String doSearch() throws InvalidPropertyException {
80 // ----------------------------
81 Map<String, Object> session = getSession();
82 User user = getConnectedUser();
84 KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
86 // Search matching all criteria
87 sprop.setType(getKnowledgeElementTypeService().selectType(
88 Integer.valueOf(typid)));
89 if (words.length() > 0)
90 sprop.setTitle(words);
91 if (refid.length() > 0)
92 sprop.setReference(refid);
93 if (context.size() > 0)
94 sprop.setSimulationContexts(context);
95 int index = Integer.valueOf(author);
97 User him = getUserService().selectUser(index);
100 // Set of the visibility
101 if (visibility.equals("all")) {
102 KnowledgeElement.Properties other = sprop.copy();
104 other.setVisibility(Visibility.PUBLIC);
105 sprop.setVisibility(Visibility.PRIVATE);
106 sprop.setActor(user);
108 result = getSearchService().selectKnowledgeElementsWhere(sprop,
111 Visibility reparea = null;
112 if (visibility.equals("onlypublic"))
113 reparea = Visibility.PUBLIC;
115 reparea = Visibility.valueOf(visibility);
116 sprop.setVisibility(reparea);
117 if (reparea == Visibility.PRIVATE)
118 sprop.setActor(user);
120 result = getSearchService().selectKnowledgeElementsWhere(sprop);
122 session.put("search.result", result); // For redisplaying the page without re-executing the search
126 // ==============================================================================================================================
128 // ==============================================================================================================================
130 public String getContextMatch() {
131 // --------------------------------
135 public String getCriteriaMatch() {
136 // ---------------------------------
140 public List<KnowledgeElementType> getKnowledgeTypes() {
141 // ------------------------------------------------------
145 public String getReference() {
146 // -----------------------------
150 public String getState() {
151 // ------------------------
155 public String getVisibility() {
156 // ------------------------------
160 public String getWords() {
161 // -------------------------
165 // ==============================================================================================================================
167 // ==============================================================================================================================
169 public void setContextMatch(String value) {
170 // ------------------------------------------
171 this.matcontext = value;
174 public void setCriteriaMatch(String value) {
175 // -------------------------------------------
176 this.matchamong = value;
179 public void setReference(String value) {
180 // ---------------------------------------
184 public void setState(String value) {
185 // ----------------------------------
189 public void setVisibility(String value) {
190 // ----------------------------------------
191 this.visibility = value;
194 public void setWords(String value) {
195 // -----------------------------------
199 // ==============================================================================================================================
200 // Implementation of abstract services
201 // ==============================================================================================================================
203 protected List<SimulationContextType> getInvolvedContexts() {
204 // ------------------------------------------------------------
205 return getSimulationContextService().selectAllTypes();
208 @SuppressWarnings("unchecked")
209 protected void loadFilter() {
210 // ----------------------------
211 Map<String, Object> session = getSession();
212 User user = getConnectedUser();
213 Map<String, Object> filter = (Map<String, Object>) session
214 .get("knowledge.filter"); // A default filter is supposed being set at start
216 visibility = (String) filter.get("visibility");
217 matchamong = (String) filter.get("matchamong");
218 matcontext = (String) filter.get("matcontext");
219 typid = (String) filter.get("type");
220 author = (String) filter.get("author");
221 refid = (String) filter.get("reference");
222 words = (String) filter.get("title");
223 context = (List<SimulationContext>) filter.get("context");
226 visibility = "onlypublic";
230 @SuppressWarnings("unchecked")
231 protected void saveFilter() {
232 // ----------------------------
233 Map<String, Object> session = getSession();
234 Map<String, Object> filter = (Map<String, Object>) session
235 .get("knowledge.filter"); // A default filter is supposed being set at start
237 filter.put("visibility", this.visibility);
238 filter.put("matchamong", this.matchamong);
239 filter.put("matcontext", this.matcontext);
240 filter.put("type", this.typid);
241 filter.put("author", this.author);
242 filter.put("reference", "");
243 filter.put("title", this.words);
245 context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
247 // Initialization required by all do functions
248 types = getKnowledgeElementTypeService().selectTypesWhere(ProgressState.APPROVED);
252 * Get the searchService.
254 * @return the searchService
256 public SearchService getSearchService() {
257 return _searchService;
261 * Set the searchService.
263 * @param searchService
264 * the searchService to set
266 public void setSearchService(SearchService searchService) {
267 _searchService = searchService;
271 * Get the simulationContextService.
273 * @return the simulationContextService
275 public SimulationContextService getSimulationContextService() {
276 return _simulationContextService;
280 * Set the simulationContextService.
282 * @param simulationContextService
283 * the simulationContextService to set
285 public void setSimulationContextService(
286 SimulationContextService simulationContextService) {
287 _simulationContextService = simulationContextService;
291 * Get the knowledgeElementTypeService.
293 * @return the knowledgeElementTypeService
295 public KnowledgeElementTypeService getKnowledgeElementTypeService() {
296 return _knowledgeElementTypeService;
300 * Set the knowledgeElementTypeService.
302 * @param knowledgeElementTypeService
303 * the knowledgeElementTypeService to set
305 public void setKnowledgeElementTypeService(
306 KnowledgeElementTypeService knowledgeElementTypeService) {
307 _knowledgeElementTypeService = knowledgeElementTypeService;
311 * Get the userService.
312 * @return the userService
314 public UserService getUserService() {
319 * Set the userService.
320 * @param userService the userService to set
322 public void setUserService(UserService userService) {
323 _userService = userService;