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 * "Private", "Public", "All".
31 private String _visibility = null;
33 * Knowledge type index when among all.
35 private String _state = null;
37 * Criteria match: "all" or "any".
39 private String _criteriaMatch = null;
41 * Simulation context match: "all" or "any".
43 private String _contextMatch = null;
45 * Knowledge reference when among ref.
47 private String _reference = null;
49 * Full text search words.
51 private String _words = null;
53 * Available knowledge types filter (initialized below).
55 private transient List<KnowledgeElementType> _knowledgeTypes;
57 * Injected search service.
59 private SearchService _searchService;
61 * Injected knowledge element service.
63 private KnowledgeElementTypeService _knowledgeElementTypeService;
65 // ==============================================================================================================================
67 // ==============================================================================================================================
70 * The action initialization.
72 * @return SUCCESS if succeeded, ERROR if doSearch() is failed
74 public String doInitialize() {
76 initializationFullScreenContext(Constants.OPEN, Constants.NONE,
84 // Final initialization of the form
85 _knowledgeTypes = getKnowledgeElementTypeService()
86 .selectTypesWhere(ProgressState.APPROVED);
88 setContextTypeOptions(getInvolvedContexts());
89 } catch (Exception error) {
90 // No need to roll back the transaction as it is read only
91 LOG.error("Reason: ", error);
98 protected String doSearch() throws InvalidPropertyException {
100 initializationScreenContext(Constants.OPEN);
101 Map<String, Object> session = getSession();
102 KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
104 // Search matching all criteria
105 sprop.setType(getKnowledgeElementTypeService().selectType(
106 Integer.valueOf(_state)));
107 if (_words.length() > 0) {
108 sprop.setTitle(_words);
110 if (_reference.length() > 0) {
111 sprop.setReference(_reference);
113 if (_context.size() > 0) {
114 sprop.setSimulationContexts(_context);
116 int index = Integer.valueOf(_author);
118 User him = getUserService().selectUser(index);
119 sprop.setAuthor(him);
121 // Set of the visibility
122 if ("all".equals(_visibility)) {
123 KnowledgeElement.Properties other = sprop.copy();
125 other.setVisibility(Visibility.PUBLIC);
126 sprop.setVisibility(Visibility.PRIVATE);
127 sprop.setActor(getConnectedUser());
129 _result = getSearchService().selectKnowledgeElementsWhere(sprop,
133 if ("onlypublic".equals(_visibility)) {
134 reparea = Visibility.PUBLIC;
136 reparea = Visibility.valueOf(_visibility);
138 sprop.setVisibility(reparea);
139 if (reparea == Visibility.PRIVATE) {
140 sprop.setActor(getConnectedUser());
143 _result = getSearchService().selectKnowledgeElementsWhere(sprop);
145 session.put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
149 // ==============================================================================================================================
151 // ==============================================================================================================================
153 public String getContextMatch() {
154 return _contextMatch;
157 public String getCriteriaMatch() {
158 return _criteriaMatch;
161 public List<KnowledgeElementType> getKnowledgeTypes() {
162 return _knowledgeTypes;
165 public String getReference() {
169 public String getState() {
173 public String getVisibility() {
177 public String getWords() {
181 // ==============================================================================================================================
183 // ==============================================================================================================================
185 public void setContextMatch(final String value) {
186 this._contextMatch = value;
189 public void setCriteriaMatch(final String value) {
190 this._criteriaMatch = value;
193 public void setReference(final String value) {
194 this._reference = value;
197 public void setState(final String value) {
201 public void setVisibility(final String value) {
202 this._visibility = value;
205 public void setWords(final String value) {
209 // ==============================================================================================================================
210 // Implementation of abstract services
211 // ==============================================================================================================================
214 protected List<SimulationContextType> getInvolvedContexts() {
215 return getSimulationContextService().selectAllTypes();
219 @SuppressWarnings("unchecked")
220 protected void loadFilter() {
221 Map<String, Object> session = getSession();
222 User user = getConnectedUser();
223 Map<String, Object> filter = (Map<String, Object>) session
224 .get("knowledge.filter"); // A default filter is supposed being set at start
226 _visibility = (String) filter.get("visibility");
227 _criteriaMatch = (String) filter.get("matchamong");
228 _contextMatch = (String) filter.get("matcontext");
229 _state = (String) filter.get("type");
230 _author = (String) filter.get("author");
231 _reference = (String) filter.get("reference");
232 _words = (String) filter.get("title");
233 _context = (List<SimulationContext>) filter.get("context");
236 _visibility = "onlypublic";
241 @SuppressWarnings("unchecked")
242 protected void saveFilter() {
243 Map<String, Object> session = getSession();
244 Map<String, Object> filter = (Map<String, Object>) session
245 .get("knowledge.filter"); // A default filter is supposed being set at start
247 filter.put("visibility", this._visibility);
248 filter.put("matchamong", this._criteriaMatch);
249 filter.put("matcontext", this._contextMatch);
250 filter.put("type", this._state);
251 filter.put("author", this._author);
252 filter.put("reference", "");
253 filter.put("title", this._words);
255 _context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
257 // Initialization required by all do functions
258 _knowledgeTypes = getKnowledgeElementTypeService().selectTypesWhere(
259 ProgressState.APPROVED);
263 * Get the searchService.
265 * @return the searchService
267 public SearchService getSearchService() {
268 return _searchService;
272 * Set the searchService.
274 * @param searchService
275 * the searchService to set
277 public void setSearchService(final SearchService searchService) {
278 _searchService = searchService;
282 * Get the knowledgeElementTypeService.
284 * @return the knowledgeElementTypeService
286 public KnowledgeElementTypeService getKnowledgeElementTypeService() {
287 return _knowledgeElementTypeService;
291 * Set the knowledgeElementTypeService.
293 * @param knowledgeElementTypeService
294 * the knowledgeElementTypeService to set
296 public void setKnowledgeElementTypeService(
297 final KnowledgeElementTypeService knowledgeElementTypeService) {
298 _knowledgeElementTypeService = knowledgeElementTypeService;