1 package org.splat.simer;
6 import org.splat.kernel.InvalidPropertyException;
7 import org.splat.dal.bo.kernel.User;
8 import org.splat.kernel.UserDirectory;
9 import org.splat.service.KnowledgeElementTypeService;
10 import org.splat.service.SearchService;
11 import org.splat.service.SimulationContextService;
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;
46 // ==============================================================================================================================
48 // ==============================================================================================================================
51 * The action initialization.
53 * @return SUCCESS if succeeded, ERROR if doSearch() is failed
55 public String doInitialize() {
60 // Final initialization of the form
61 types = getKnowledgeElementTypeService().selectTypesWhere(
62 ProgressState.APPROVED);
64 setContextTypeOptions(getInvolvedContexts());
67 } catch (Exception error) {
68 // No need to roll back the transaction as it is read only
69 logger.error("Reason: ", error);
74 protected String doSearch() throws InvalidPropertyException {
75 // ----------------------------
76 Map<String, Object> session = getSession();
77 User user = getConnectedUser();
79 KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
81 // Search matching all criteria
82 sprop.setType(getKnowledgeElementTypeService().selectType(
83 Integer.valueOf(typid)));
84 if (words.length() > 0)
85 sprop.setTitle(words);
86 if (refid.length() > 0)
87 sprop.setReference(refid);
88 if (context.size() > 0)
89 sprop.setSimulationContexts(context);
90 int index = Integer.valueOf(author);
92 User him = UserDirectory.selectUser(index);
95 // Set of the visibility
96 if (visibility.equals("all")) {
97 KnowledgeElement.Properties other = sprop.copy();
99 other.setVisibility(Visibility.PUBLIC);
100 sprop.setVisibility(Visibility.PRIVATE);
101 sprop.setActor(user);
103 result = getSearchService().selectKnowledgeElementsWhere(sprop,
106 Visibility reparea = null;
107 if (visibility.equals("onlypublic"))
108 reparea = Visibility.PUBLIC;
110 reparea = Visibility.valueOf(visibility);
111 sprop.setVisibility(reparea);
112 if (reparea == Visibility.PRIVATE)
113 sprop.setActor(user);
115 result = getSearchService().selectKnowledgeElementsWhere(sprop);
117 session.put("search.result", result); // For redisplaying the page without re-executing the search
121 // ==============================================================================================================================
123 // ==============================================================================================================================
125 public String getContextMatch() {
126 // --------------------------------
130 public String getCriteriaMatch() {
131 // ---------------------------------
135 public List<KnowledgeElementType> getKnowledgeTypes() {
136 // ------------------------------------------------------
140 public String getReference() {
141 // -----------------------------
145 public String getState() {
146 // ------------------------
150 public String getVisibility() {
151 // ------------------------------
155 public String getWords() {
156 // -------------------------
160 // ==============================================================================================================================
162 // ==============================================================================================================================
164 public void setContextMatch(String value) {
165 // ------------------------------------------
166 this.matcontext = value;
169 public void setCriteriaMatch(String value) {
170 // -------------------------------------------
171 this.matchamong = value;
174 public void setReference(String value) {
175 // ---------------------------------------
179 public void setState(String value) {
180 // ----------------------------------
184 public void setVisibility(String value) {
185 // ----------------------------------------
186 this.visibility = value;
189 public void setWords(String value) {
190 // -----------------------------------
194 // ==============================================================================================================================
195 // Implementation of abstract services
196 // ==============================================================================================================================
198 protected List<SimulationContextType> getInvolvedContexts() {
199 // ------------------------------------------------------------
200 return getSimulationContextService().selectAllTypes();
203 @SuppressWarnings("unchecked")
204 protected void loadFilter() {
205 // ----------------------------
206 Map<String, Object> session = getSession();
207 User user = getConnectedUser();
208 Map<String, Object> filter = (Map<String, Object>) session
209 .get("knowledge.filter"); // A default filter is supposed being set at start
211 visibility = (String) filter.get("visibility");
212 matchamong = (String) filter.get("matchamong");
213 matcontext = (String) filter.get("matcontext");
214 typid = (String) filter.get("type");
215 author = (String) filter.get("author");
216 refid = (String) filter.get("reference");
217 words = (String) filter.get("title");
218 context = (List<SimulationContext>) filter.get("context");
221 visibility = "onlypublic";
225 @SuppressWarnings("unchecked")
226 protected void saveFilter() {
227 // ----------------------------
228 Map<String, Object> session = getSession();
229 Map<String, Object> filter = (Map<String, Object>) session
230 .get("knowledge.filter"); // A default filter is supposed being set at start
232 filter.put("visibility", this.visibility);
233 filter.put("matchamong", this.matchamong);
234 filter.put("matcontext", this.matcontext);
235 filter.put("type", this.typid);
236 filter.put("author", this.author);
237 filter.put("reference", "");
238 filter.put("title", this.words);
240 context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
242 // Initialization required by all do functions
243 types = getKnowledgeElementTypeService().selectTypesWhere(ProgressState.APPROVED);
247 * Get the searchService.
249 * @return the searchService
251 public SearchService getSearchService() {
252 return _searchService;
256 * Set the searchService.
258 * @param searchService
259 * the searchService to set
261 public void setSearchService(SearchService searchService) {
262 _searchService = searchService;
266 * Get the simulationContextService.
268 * @return the simulationContextService
270 public SimulationContextService getSimulationContextService() {
271 return _simulationContextService;
275 * Set the simulationContextService.
277 * @param simulationContextService
278 * the simulationContextService to set
280 public void setSimulationContextService(
281 SimulationContextService simulationContextService) {
282 _simulationContextService = simulationContextService;
286 * Get the knowledgeElementTypeService.
288 * @return the knowledgeElementTypeService
290 public KnowledgeElementTypeService getKnowledgeElementTypeService() {
291 return _knowledgeElementTypeService;
295 * Set the knowledgeElementTypeService.
297 * @param knowledgeElementTypeService
298 * the knowledgeElementTypeService to set
300 public void setKnowledgeElementTypeService(
301 KnowledgeElementTypeService knowledgeElementTypeService) {
302 _knowledgeElementTypeService = knowledgeElementTypeService;