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.wapp.Constants;
19 * Action for searching a knowledge in the database.
21 public class SearchKnowledgeAction extends AbstractSearchBaseAction {
26 private static final long serialVersionUID = -3104321907432838476L;
29 * Knowledge type index when among all.
31 private String _state = null;
33 * Criteria match: "all" or "any".
35 private String _criteriaMatch = null;
37 * Simulation context match: "all" or "any".
39 private String _contextMatch = null;
41 * Knowledge reference when among ref.
43 private String _reference = null;
45 * Full text search words.
47 private String _words = null;
49 * Available knowledge types filter (initialized below).
51 private transient List<KnowledgeElementType> _knowledgeTypes;
53 * Injected search service.
55 private SearchService _searchService;
57 * Injected knowledge element service.
59 private KnowledgeElementTypeService _knowledgeElementTypeService;
61 // ==============================================================================================================================
63 // ==============================================================================================================================
66 * The action initialization.
68 * @return SUCCESS if succeeded, ERROR if doSearch() is failed
70 public String doInitialize() {
72 initializationFullScreenContext(Constants.OPEN, Constants.NONE,
80 // Final initialization of the form
81 _knowledgeTypes = getKnowledgeElementTypeService()
82 .selectTypesWhere(ProgressState.APPROVED);
84 setContextTypeOptions(getInvolvedContexts());
85 } catch (Exception error) {
86 // No need to roll back the transaction as it is read only
87 LOG.error("Reason: ", error);
94 protected String doSearch() throws InvalidPropertyException {
96 initializationScreenContext(Constants.OPEN);
97 Map<String, Object> session = getSession();
98 KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
100 // Search matching all criteria
101 sprop.setType(getKnowledgeElementTypeService().selectType(
102 Integer.valueOf(_state)));
103 if (_words.length() > 0) {
104 sprop.setTitle(_words);
106 if (_reference.length() > 0) {
107 sprop.setReference(_reference);
109 if (_context.size() > 0) {
110 sprop.setSimulationContexts(_context);
112 int index = Integer.valueOf(_author);
114 User him = getUserService().selectUser(index);
115 sprop.setAuthor(him);
117 // Set of the visibility
118 KnowledgeElement.Properties other = sprop.copy();
120 other.setVisibility(Visibility.PUBLIC);
121 sprop.setVisibility(Visibility.PRIVATE);
122 sprop.setActor(getConnectedUser());
124 _result = getSearchService().selectKnowledgeElementsWhere(sprop,
126 session.put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
130 // ==============================================================================================================================
132 // ==============================================================================================================================
134 public String getContextMatch() {
135 return _contextMatch;
138 public String getCriteriaMatch() {
139 return _criteriaMatch;
142 public List<KnowledgeElementType> getKnowledgeTypes() {
143 return _knowledgeTypes;
146 public String getReference() {
150 public String getState() {
154 public String getWords() {
158 // ==============================================================================================================================
160 // ==============================================================================================================================
162 public void setContextMatch(final String value) {
163 this._contextMatch = value;
166 public void setCriteriaMatch(final String value) {
167 this._criteriaMatch = value;
170 public void setReference(final String value) {
171 this._reference = value;
174 public void setState(final String value) {
178 public void setWords(final String value) {
182 // ==============================================================================================================================
183 // Implementation of abstract services
184 // ==============================================================================================================================
187 protected List<SimulationContextType> getInvolvedContexts() {
188 return getSimulationContextService().selectAllTypes();
192 @SuppressWarnings("unchecked")
193 protected void loadFilter() {
194 Map<String, Object> session = getSession();
195 Map<String, Object> filter = (Map<String, Object>) session
196 .get("knowledge.filter"); // A default filter is supposed being set at start
198 _criteriaMatch = (String) filter.get("matchamong");
199 _contextMatch = (String) filter.get("matcontext");
200 _state = (String) filter.get("type");
201 _author = (String) filter.get("author");
202 _reference = (String) filter.get("reference");
203 _words = (String) filter.get("title");
204 _context = (List<SimulationContext>) filter.get("context");
208 @SuppressWarnings("unchecked")
209 protected void saveFilter() {
210 Map<String, Object> session = getSession();
211 Map<String, Object> filter = (Map<String, Object>) session
212 .get("knowledge.filter"); // A default filter is supposed being set at start
214 filter.put("matchamong", this._criteriaMatch);
215 filter.put("matcontext", this._contextMatch);
216 filter.put("type", this._state);
217 filter.put("author", this._author);
218 filter.put("reference", "");
219 filter.put("title", this._words);
221 _context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
223 // Initialization required by all do functions
224 _knowledgeTypes = getKnowledgeElementTypeService().selectTypesWhere(
225 ProgressState.APPROVED);
229 * Get the searchService.
231 * @return the searchService
233 public SearchService getSearchService() {
234 return _searchService;
238 * Set the searchService.
240 * @param searchService
241 * the searchService to set
243 public void setSearchService(final SearchService searchService) {
244 _searchService = searchService;
248 * Get the knowledgeElementTypeService.
250 * @return the knowledgeElementTypeService
252 public KnowledgeElementTypeService getKnowledgeElementTypeService() {
253 return _knowledgeElementTypeService;
257 * Set the knowledgeElementTypeService.
259 * @param knowledgeElementTypeService
260 * the knowledgeElementTypeService to set
262 public void setKnowledgeElementTypeService(
263 final KnowledgeElementTypeService knowledgeElementTypeService) {
264 _knowledgeElementTypeService = knowledgeElementTypeService;