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.dal.dao.som.Database;
13 import org.splat.dal.bo.som.KnowledgeElement;
14 import org.splat.dal.bo.som.KnowledgeElementType;
15 import org.splat.dal.bo.som.ProgressState;
16 import org.splat.dal.bo.som.SimulationContext;
17 import org.splat.dal.bo.som.SimulationContextType;
18 import org.splat.dal.bo.som.Visibility;
21 public class SearchKnowledgeAction extends SearchBaseAction {
23 private String visibility = null; // "Private", "Public", "All"
24 private String typid = null; // Knowledge type index when among all
25 private String matchamong = null; // "all" or "any"
26 private String matcontext = null; // "all" or "any"
27 private String refid = null; // Knowledge reference when among ref
28 private String words = null; // Full text search words
29 private List<KnowledgeElementType> types; // Available knowledge types filter (initialized below)
30 private SearchService _searchService;
32 private static final long serialVersionUID = -3104321907432838476L;
34 // ==============================================================================================================================
36 // ==============================================================================================================================
38 public String doInitialize () {
39 // -----------------------------
40 Session connex = Database.getSession();
41 Transaction transax = connex.beginTransaction();
46 // Final initialization of the form
47 types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
49 setContextTypeOptions(getInvolvedContexts());
54 catch (Exception error) {
55 // No need to roll back the transaction as it is read only
56 logger.error("Reason: ", error);
61 protected String doSearch () throws InvalidPropertyException {
62 // ----------------------------
63 Map<String, Object> session = getSession();
64 User user = getConnectedUser();
66 KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
68 // Search matching all criteria
69 sprop.setType( KnowledgeElement.selectType(Integer.valueOf(typid)) );
70 if (words.length() > 0) sprop.setTitle(words);
71 if (refid.length() > 0) sprop.setReference(refid);
72 if (context.size() > 0) sprop.setSimulationContexts(context);
73 int index = Integer.valueOf(author);
75 User him = UserDirectory.selectUser(index);
78 // Set of the visibility
79 if (visibility.equals("all")) {
80 KnowledgeElement.Properties other = sprop.copy();
82 other.setVisibility(Visibility.PUBLIC);
83 sprop.setVisibility(Visibility.PRIVATE);
86 result = getSearchService().selectKnowledgeElementsWhere(sprop, other);
89 Visibility reparea = null;
90 if (visibility.equals("onlypublic")) reparea = Visibility.PUBLIC;
91 else reparea = Visibility.valueOf(visibility);
92 sprop.setVisibility(reparea);
93 if (reparea == Visibility.PRIVATE) sprop.setActor(user);
95 result = getSearchService().selectKnowledgeElementsWhere(sprop);
97 session.put("search.result", result); // For redisplaying the page without re-executing the search
101 // ==============================================================================================================================
103 // ==============================================================================================================================
105 public String getContextMatch () {
106 // --------------------------------
109 public String getCriteriaMatch () {
110 // ---------------------------------
113 public List<KnowledgeElementType> getKnowledgeTypes () {
114 // ------------------------------------------------------
117 public String getReference () {
118 // -----------------------------
121 public String getState () {
122 // ------------------------
125 public String getVisibility () {
126 // ------------------------------
129 public String getWords () {
130 // -------------------------
134 // ==============================================================================================================================
136 // ==============================================================================================================================
138 public void setContextMatch (String value) {
139 // ------------------------------------------
140 this.matcontext = value;
142 public void setCriteriaMatch (String value) {
143 // -------------------------------------------
144 this.matchamong = value;
146 public void setReference (String value) {
147 // ---------------------------------------
150 public void setState (String value) {
151 // ----------------------------------
154 public void setVisibility (String value) {
155 // ----------------------------------------
156 this.visibility = value;
158 public void setWords (String value) {
159 // -----------------------------------
163 // ==============================================================================================================================
164 // Implementation of abstract services
165 // ==============================================================================================================================
167 protected List<SimulationContextType> getInvolvedContexts () {
168 // ------------------------------------------------------------
169 return SimulationContext.selectAllTypes();
172 @SuppressWarnings("unchecked")
173 protected void loadFilter () {
174 // ----------------------------
175 Map<String,Object> session = getSession();
176 User user = getConnectedUser();
177 Map<String,Object> filter = (Map<String, Object>)session.get("knowledge.filter"); // A default filter is supposed being set at start
179 visibility = (String)filter.get("visibility");
180 matchamong = (String)filter.get("matchamong");
181 matcontext = (String)filter.get("matcontext");
182 typid = (String)filter.get("type");
183 author = (String)filter.get("author");
184 refid = (String)filter.get("reference");
185 words = (String)filter.get("title");
186 context = (List<SimulationContext>)filter.get("context");
189 visibility = "onlypublic";
193 @SuppressWarnings("unchecked")
194 protected void saveFilter () {
195 // ----------------------------
196 Map<String,Object> session = getSession();
197 Map<String,Object> filter = (Map<String, Object>)session.get("knowledge.filter"); // A default filter is supposed being set at start
199 filter.put("visibility", this.visibility);
200 filter.put("matchamong", this.matchamong);
201 filter.put("matcontext", this.matcontext);
202 filter.put("type", this.typid);
203 filter.put("author", this.author);
204 filter.put("reference", "");
205 filter.put("title", this.words);
207 context = (List<SimulationContext>)filter.get("context"); // Only criteria not part of the form
209 // Initialization required by all do functions
210 types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
213 * Get the searchService.
214 * @return the searchService
216 public SearchService getSearchService() {
217 return _searchService;
221 * Set the searchService.
222 * @param searchService the searchService to set
224 public void setSearchService(SearchService searchService) {
225 _searchService = searchService;