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 * Knowledge reference when among ref.
35 private String _reference = null;
37 * Available knowledge types filter (initialized below).
39 private transient List<KnowledgeElementType> _knowledgeTypes;
41 * Injected search service.
43 private SearchService _searchService;
45 * Injected knowledge element service.
47 private KnowledgeElementTypeService _knowledgeElementTypeService;
49 // ==============================================================================================================================
51 // ==============================================================================================================================
54 * The action initialization.
56 * @return SUCCESS if succeeded, ERROR if doSearch() is failed
58 public String doInitialize() {
60 initializationFullScreenContext(Constants.OPEN, Constants.NONE,
68 // Final initialization of the form
69 _knowledgeTypes = getKnowledgeElementTypeService()
70 .selectTypesWhere(ProgressState.APPROVED);
72 setContextTypeOptions(getInvolvedContexts());
73 } catch (Exception error) {
74 // No need to roll back the transaction as it is read only
75 LOG.error("Reason: ", error);
82 protected String doSearch() throws InvalidPropertyException {
84 initializationScreenContext(Constants.OPEN);
85 Map<String, Object> session = getSession();
86 KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
88 // Search matching all criteria
89 sprop.setType(getKnowledgeElementTypeService().selectType(
90 Integer.valueOf(_state)));
91 if (getWords().length() > 0) {
92 sprop.setTitle(getWords());
94 if (_reference.length() > 0) {
95 sprop.setReference(_reference);
97 if (_context.size() > 0) {
98 sprop.setSimulationContexts(_context);
100 int index = Integer.valueOf(_author);
102 User him = getUserService().selectUser(index);
103 sprop.setAuthor(him);
105 // Set of the visibility
106 KnowledgeElement.Properties other = sprop.copy();
108 other.setVisibility(Visibility.PUBLIC);
109 sprop.setVisibility(Visibility.PRIVATE);
110 sprop.setActor(getConnectedUser());
112 _result = getSearchService().selectKnowledgeElementsWhere(sprop,
114 session.put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
118 // ==============================================================================================================================
120 // ==============================================================================================================================
122 public List<KnowledgeElementType> getKnowledgeTypes() {
123 return _knowledgeTypes;
126 public String getReference() {
130 public String getState() {
134 public void setReference(final String value) {
135 this._reference = value;
138 public void setState(final String value) {
143 protected List<SimulationContextType> getInvolvedContexts() {
144 return getSimulationContextService().selectAllTypes();
148 @SuppressWarnings("unchecked")
149 protected void loadFilter() {
150 Map<String, Object> session = getSession();
151 Map<String, Object> filter = (Map<String, Object>) session
152 .get("knowledge.filter"); // A default filter is supposed being set at start
154 setCriteriaMatch ((String) filter.get("matchamong"));
155 setContextMatch ((String) filter.get("matcontext"));
156 _state = (String) filter.get("type");
157 _author = (String) filter.get("author");
158 _reference = (String) filter.get("reference");
159 setWords ((String) filter.get("title"));
160 _context = (List<SimulationContext>) filter.get("context");
164 @SuppressWarnings("unchecked")
165 protected void saveFilter() {
166 Map<String, Object> session = getSession();
167 Map<String, Object> filter = (Map<String, Object>) session
168 .get("knowledge.filter"); // A default filter is supposed being set at start
170 filter.put("matchamong", getCriteriaMatch());
171 filter.put("matcontext", getContextMatch());
172 filter.put("type", this._state);
173 filter.put("author", this._author);
174 filter.put("reference", "");
175 filter.put("title", getWords());
177 _context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
179 // Initialization required by all do functions
180 _knowledgeTypes = getKnowledgeElementTypeService().selectTypesWhere(
181 ProgressState.APPROVED);
185 * Get the searchService.
187 * @return the searchService
189 public SearchService getSearchService() {
190 return _searchService;
194 * Set the searchService.
196 * @param searchService
197 * the searchService to set
199 public void setSearchService(final SearchService searchService) {
200 _searchService = searchService;
204 * Get the knowledgeElementTypeService.
206 * @return the knowledgeElementTypeService
208 public KnowledgeElementTypeService getKnowledgeElementTypeService() {
209 return _knowledgeElementTypeService;
213 * Set the knowledgeElementTypeService.
215 * @param knowledgeElementTypeService
216 * the knowledgeElementTypeService to set
218 public void setKnowledgeElementTypeService(
219 final KnowledgeElementTypeService knowledgeElementTypeService) {
220 _knowledgeElementTypeService = knowledgeElementTypeService;