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;
18 import org.splat.wapp.Item;
19 import org.splat.wapp.TabBar;
22 public class SearchKnowledgeAction extends SearchBaseAction {
24 private TabBar area = null; // Active repository area
25 private String among = null; // "all", "inCHECK" or "ref"
26 private String typid = null; // Knowledge type index when among all
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)
31 private static final long serialVersionUID = -3104321907432838476L;
33 // ==============================================================================================================================
35 // ==============================================================================================================================
37 public String doInitialize () {
38 // -----------------------------
39 Session connex = Database.getSession();
40 Transaction transax = connex.beginTransaction();
43 if (newarea != null) { // New selected repository area
44 area.selects(newarea);
48 // Final initialization of the form
49 types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
51 setContextTypeOptions(getInvolvedContexts());
56 catch (Exception error) {
57 // No need to roll back the transaction as it is read only
58 logger.error("Reason: ", error);
63 protected String doSearch () throws InvalidPropertyException {
64 // ----------------------------
65 Map<String, Object> session = getSession();
66 User user = getConnectedUser();
68 KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
69 KnowledgeElement.Properties other = null;
71 // Set of the selected repository area
72 String selectab = area.getSelection().toUpperCase();
73 Visibility reparea = Visibility.valueOf(selectab);
74 sprop.setVisibility(reparea);
76 // Search from a given reference
77 if (among.equals("ref")) {
78 if (refid.length() == 0) {
79 getSession().remove("search.result"); // The current result is obsolete
82 sprop.setReference(refid);
83 if (reparea == Visibility.PRIVATE) { // Restriction to studies in which the connected user is involved
84 other = sprop.copy().setActor(user);
85 sprop.setAuthor(user);
88 // Search from other available criteria
89 if (words.length() > 0) sprop.setTitle(words);
90 if (context.size() > 0) sprop.setSimulationContexts(context);
91 if ( among.equals("mine") ) sprop.setAuthor(user);
92 else if ( among.equals("his") ) {
93 User him = UserDirectory.selectUser(Integer.valueOf(author));
95 if (reparea == Visibility.PRIVATE) sprop.setActor(user);
96 } else {//among.equals("all")
97 KnowledgeElementType type = KnowledgeElement.selectType(Integer.valueOf(typid));
99 if (reparea == Visibility.PRIVATE) { // Restriction to studies in which the connected user is involved
100 other = sprop.copy().setActor(user);
101 sprop.setAuthor(user);
105 if (other == null) result = Database.selectKnowledgeElementsWhere(sprop);
106 else result = Database.selectKnowledgeElementsWhere(sprop, other);
108 session.put("search.result", result); // For redisplaying the page without re-executing the search
112 // ==============================================================================================================================
114 // ==============================================================================================================================
116 public List<KnowledgeElementType> getKnowledgeTypes () {
117 // ------------------------------------------------------
120 public String getOwner () {
121 // -------------------------
124 public String getReference () {
125 // -----------------------------
128 public String getState () {
129 // ------------------------
132 public List<Item> getTabs () {
133 // ----------------------------
134 return area.asList();
136 public String getWords () {
137 // -------------------------
141 // ==============================================================================================================================
143 // ==============================================================================================================================
145 public void setOwner (String value) {
146 // -----------------------------------
149 public void setReference (String value) {
150 // ---------------------------------------
153 public void setState (String value) {
154 // ----------------------------------
157 public void setWords (String value) {
158 // -----------------------------------
162 // ==============================================================================================================================
163 // Implementation of abstract services
164 // ==============================================================================================================================
166 protected List<SimulationContextType> getInvolvedContexts () {
167 // ------------------------------------------------------------
168 return SimulationContext.selectAllTypes();
171 @SuppressWarnings("unchecked")
172 protected void loadFilter () {
173 // ----------------------------
174 Map<String,Object> session = getSession();
175 User user = getConnectedUser();
176 Map<String,Object> filter = (Map<String, Object>)session.get("knowledge.filter"); // A default filter is supposed being set at start
178 area = (TabBar)filter.get("area");
179 among = (String)filter.get("owner");
180 author = (String)filter.get("author");
181 typid = (String)filter.get("type");
182 refid = (String)filter.get("reference");
183 words = (String)filter.get("title");
184 context = (List<SimulationContext>)filter.get("context");
187 area.disables("private");
188 if (area.getSelection().equals("private")) area.selects("public");
192 @SuppressWarnings("unchecked")
193 protected void saveFilter () {
194 // ----------------------------
195 Map<String,Object> session = getSession();
196 Map<String,Object> filter = (Map<String, Object>)session.get("knowledge.filter"); // A default filter is supposed being set at start
198 area = (TabBar)filter.get("area"); // The area being not an input, it is null when submitting the form
199 if (among.equals("ref")) {
200 filter.put("owner", "ref");
201 filter.put("reference", this.refid);
203 filter.put("owner", this.among);
204 filter.put("author", this.author);
205 filter.put("type", this.typid);
206 filter.put("reference", "");
207 filter.put("title", this.words);
209 context = (List<SimulationContext>)filter.get("context"); // Only criteria not part of the form
211 // Initialization required by all do functions
212 types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);