1 package org.splat.simer;
6 import org.hibernate.Session;
7 import org.hibernate.Transaction;
8 import org.splat.kernel.InvalidPropertyException;
9 import org.splat.dal.bo.kernel.User;
10 import org.splat.kernel.UserDirectory;
11 import org.splat.service.SearchService;
12 import org.splat.service.SimulationContextService;
13 import org.splat.dal.dao.som.Database;
14 import org.splat.dal.bo.som.KnowledgeElement;
15 import org.splat.dal.bo.som.KnowledgeElementType;
16 import org.splat.dal.bo.som.ProgressState;
17 import org.splat.dal.bo.som.SimulationContext;
18 import org.splat.dal.bo.som.SimulationContextType;
19 import org.splat.dal.bo.som.Visibility;
22 public class SearchKnowledgeAction extends SearchBaseAction {
24 private String visibility = null; // "Private", "Public", "All"
25 private String typid = null; // Knowledge type index when among all
26 private String matchamong = null; // "all" or "any"
27 private String matcontext = null; // "all" or "any"
28 private String refid = null; // Knowledge reference when among ref
29 private String words = null; // Full text search words
30 private List<KnowledgeElementType> types; // Available knowledge types filter (initialized below)
31 private SearchService _searchService;
33 * Injected simulation context service.
35 private SimulationContextService _simulationContextService;
40 private static final long serialVersionUID = -3104321907432838476L;
42 // ==============================================================================================================================
44 // ==============================================================================================================================
46 public String doInitialize () {
47 // -----------------------------
48 Session connex = Database.getSession();
49 Transaction transax = connex.beginTransaction();
54 // Final initialization of the form
55 types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
57 setContextTypeOptions(getInvolvedContexts());
62 catch (Exception error) {
63 // No need to roll back the transaction as it is read only
64 logger.error("Reason: ", error);
69 protected String doSearch () throws InvalidPropertyException {
70 // ----------------------------
71 Map<String, Object> session = getSession();
72 User user = getConnectedUser();
74 KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
76 // Search matching all criteria
77 sprop.setType( KnowledgeElement.selectType(Integer.valueOf(typid)) );
78 if (words.length() > 0) sprop.setTitle(words);
79 if (refid.length() > 0) sprop.setReference(refid);
80 if (context.size() > 0) sprop.setSimulationContexts(context);
81 int index = Integer.valueOf(author);
83 User him = UserDirectory.selectUser(index);
86 // Set of the visibility
87 if (visibility.equals("all")) {
88 KnowledgeElement.Properties other = sprop.copy();
90 other.setVisibility(Visibility.PUBLIC);
91 sprop.setVisibility(Visibility.PRIVATE);
94 result = getSearchService().selectKnowledgeElementsWhere(sprop, other);
97 Visibility reparea = null;
98 if (visibility.equals("onlypublic")) reparea = Visibility.PUBLIC;
99 else reparea = Visibility.valueOf(visibility);
100 sprop.setVisibility(reparea);
101 if (reparea == Visibility.PRIVATE) sprop.setActor(user);
103 result = getSearchService().selectKnowledgeElementsWhere(sprop);
105 session.put("search.result", result); // For redisplaying the page without re-executing the search
109 // ==============================================================================================================================
111 // ==============================================================================================================================
113 public String getContextMatch () {
114 // --------------------------------
117 public String getCriteriaMatch () {
118 // ---------------------------------
121 public List<KnowledgeElementType> getKnowledgeTypes () {
122 // ------------------------------------------------------
125 public String getReference () {
126 // -----------------------------
129 public String getState () {
130 // ------------------------
133 public String getVisibility () {
134 // ------------------------------
137 public String getWords () {
138 // -------------------------
142 // ==============================================================================================================================
144 // ==============================================================================================================================
146 public void setContextMatch (String value) {
147 // ------------------------------------------
148 this.matcontext = value;
150 public void setCriteriaMatch (String value) {
151 // -------------------------------------------
152 this.matchamong = value;
154 public void setReference (String value) {
155 // ---------------------------------------
158 public void setState (String value) {
159 // ----------------------------------
162 public void setVisibility (String value) {
163 // ----------------------------------------
164 this.visibility = value;
166 public void setWords (String value) {
167 // -----------------------------------
171 // ==============================================================================================================================
172 // Implementation of abstract services
173 // ==============================================================================================================================
175 protected List<SimulationContextType> getInvolvedContexts () {
176 // ------------------------------------------------------------
177 return getSimulationContextService().selectAllTypes();
180 @SuppressWarnings("unchecked")
181 protected void loadFilter () {
182 // ----------------------------
183 Map<String,Object> session = getSession();
184 User user = getConnectedUser();
185 Map<String,Object> filter = (Map<String, Object>)session.get("knowledge.filter"); // A default filter is supposed being set at start
187 visibility = (String)filter.get("visibility");
188 matchamong = (String)filter.get("matchamong");
189 matcontext = (String)filter.get("matcontext");
190 typid = (String)filter.get("type");
191 author = (String)filter.get("author");
192 refid = (String)filter.get("reference");
193 words = (String)filter.get("title");
194 context = (List<SimulationContext>)filter.get("context");
197 visibility = "onlypublic";
201 @SuppressWarnings("unchecked")
202 protected void saveFilter () {
203 // ----------------------------
204 Map<String,Object> session = getSession();
205 Map<String,Object> filter = (Map<String, Object>)session.get("knowledge.filter"); // A default filter is supposed being set at start
207 filter.put("visibility", this.visibility);
208 filter.put("matchamong", this.matchamong);
209 filter.put("matcontext", this.matcontext);
210 filter.put("type", this.typid);
211 filter.put("author", this.author);
212 filter.put("reference", "");
213 filter.put("title", this.words);
215 context = (List<SimulationContext>)filter.get("context"); // Only criteria not part of the form
217 // Initialization required by all do functions
218 types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
221 * Get the searchService.
222 * @return the searchService
224 public SearchService getSearchService() {
225 return _searchService;
229 * Set the searchService.
230 * @param searchService the searchService to set
232 public void setSearchService(SearchService searchService) {
233 _searchService = searchService;
237 * Get the simulationContextService.
239 * @return the simulationContextService
241 public SimulationContextService getSimulationContextService() {
242 return _simulationContextService;
246 * Set the simulationContextService.
248 * @param simulationContextService
249 * the simulationContextService to set
251 public void setSimulationContextService(
252 SimulationContextService simulationContextService) {
253 _simulationContextService = simulationContextService;