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.kernel.User;
10 import org.splat.kernel.UserDirectory;
11 import org.splat.som.Database;
12 import org.splat.som.KnowledgeElement;
13 import org.splat.som.KnowledgeElementType;
14 import org.splat.som.ProgressState;
15 import org.splat.som.SimulationContext;
16 import org.splat.som.SimulationContextType;
17 import org.splat.som.Visibility;
20 public class SearchKnowledgeAction extends SearchBaseAction {
22 private String visibility = null; // "Private", "Public", "All"
23 private String typid = null; // Knowledge type index when among all
24 private String matchamong = null; // "all" or "any"
25 private String matcontext = null; // "all" or "any"
26 private String refid = null; // Knowledge reference when among ref
27 private String words = null; // Full text search words
28 private List<KnowledgeElementType> types; // Available knowledge types filter (initialized below)
30 private static final long serialVersionUID = -3104321907432838476L;
32 // ==============================================================================================================================
34 // ==============================================================================================================================
36 public String doInitialize () {
37 // -----------------------------
38 Session connex = Database.getSession();
39 Transaction transax = connex.beginTransaction();
44 // Final initialization of the form
45 types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
47 setContextTypeOptions(getInvolvedContexts());
52 catch (Exception error) {
53 // No need to roll back the transaction as it is read only
54 logger.error("Reason: ", error);
59 protected String doSearch () throws InvalidPropertyException {
60 // ----------------------------
61 Map<String, Object> session = getSession();
62 User user = getConnectedUser();
64 KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
66 // Search matching all criteria
67 sprop.setType( KnowledgeElement.selectType(Integer.valueOf(typid)) );
68 if (words.length() > 0) sprop.setTitle(words);
69 if (refid.length() > 0) sprop.setReference(refid);
70 if (context.size() > 0) sprop.setSimulationContexts(context);
71 int index = Integer.valueOf(author);
73 User him = UserDirectory.selectUser(index);
76 // Set of the visibility
77 if (visibility.equals("all")) {
78 KnowledgeElement.Properties other = sprop.copy();
80 other.setVisibility(Visibility.PUBLIC);
81 sprop.setVisibility(Visibility.PRIVATE);
84 result = Database.selectKnowledgeElementsWhere(sprop, other);
87 Visibility reparea = null;
88 if (visibility.equals("onlypublic")) reparea = Visibility.PUBLIC;
89 else reparea = Visibility.valueOf(visibility);
90 sprop.setVisibility(reparea);
91 if (reparea == Visibility.PRIVATE) sprop.setActor(user);
93 result = Database.selectKnowledgeElementsWhere(sprop);
95 session.put("search.result", result); // For redisplaying the page without re-executing the search
99 // ==============================================================================================================================
101 // ==============================================================================================================================
103 public String getContextMatch () {
104 // --------------------------------
107 public String getCriteriaMatch () {
108 // ---------------------------------
111 public List<KnowledgeElementType> getKnowledgeTypes () {
112 // ------------------------------------------------------
115 public String getReference () {
116 // -----------------------------
119 public String getState () {
120 // ------------------------
123 public String getVisibility () {
124 // ------------------------------
127 public String getWords () {
128 // -------------------------
132 // ==============================================================================================================================
134 // ==============================================================================================================================
136 public void setContextMatch (String value) {
137 // ------------------------------------------
138 this.matcontext = value;
140 public void setCriteriaMatch (String value) {
141 // -------------------------------------------
142 this.matchamong = value;
144 public void setReference (String value) {
145 // ---------------------------------------
148 public void setState (String value) {
149 // ----------------------------------
152 public void setVisibility (String value) {
153 // ----------------------------------------
154 this.visibility = value;
156 public void setWords (String value) {
157 // -----------------------------------
161 // ==============================================================================================================================
162 // Implementation of abstract services
163 // ==============================================================================================================================
165 protected List<SimulationContextType> getInvolvedContexts () {
166 // ------------------------------------------------------------
167 return SimulationContext.selectAllTypes();
170 @SuppressWarnings("unchecked")
171 protected void loadFilter () {
172 // ----------------------------
173 Map<String,Object> session = getSession();
174 User user = getConnectedUser();
175 Map<String,Object> filter = (Map<String, Object>)session.get("knowledge.filter"); // A default filter is supposed being set at start
177 visibility = (String)filter.get("visibility");
178 matchamong = (String)filter.get("matchamong");
179 matcontext = (String)filter.get("matcontext");
180 typid = (String)filter.get("type");
181 author = (String)filter.get("author");
182 refid = (String)filter.get("reference");
183 words = (String)filter.get("title");
184 context = (List<SimulationContext>)filter.get("context");
187 visibility = "onlypublic";
191 @SuppressWarnings("unchecked")
192 protected void saveFilter () {
193 // ----------------------------
194 Map<String,Object> session = getSession();
195 Map<String,Object> filter = (Map<String, Object>)session.get("knowledge.filter"); // A default filter is supposed being set at start
197 filter.put("visibility", this.visibility);
198 filter.put("matchamong", this.matchamong);
199 filter.put("matcontext", this.matcontext);
200 filter.put("type", this.typid);
201 filter.put("author", this.author);
202 filter.put("reference", "");
203 filter.put("title", this.words);
205 context = (List<SimulationContext>)filter.get("context"); // Only criteria not part of the form
207 // Initialization required by all do functions
208 types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);