]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/SearchStudyAction.java
Salome HOME
4e38b955f192866831434a36e9165dcd611b71cd
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / SearchStudyAction.java
1 package org.splat.simer;
2
3 import java.util.List;
4 import java.util.Map;
5
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.ProgressState;
13 import org.splat.som.ProjectSettings;
14 import org.splat.som.SimulationContext;
15 import org.splat.som.SimulationContextType;
16 import org.splat.som.Study;
17 import org.splat.som.Visibility;
18
19
20 public class SearchStudyAction extends SearchBaseAction {
21
22     private String            visibility = null;   // "Private", "Public", "All"
23     private String            state      = null;   // "In-Work", "In-Draft", "In-Check"...
24     private String            matchamong = null;   // "all" or "any"
25     private String            matcontext = null;   // "all" or "any"
26     private String            refid      = null;   // Study reference
27     private String            words      = null;   // Full text search words
28
29         private static final long serialVersionUID = -1910481357051393077L;
30
31     enum UserAction { refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext }
32
33 //  ==============================================================================================================================
34 //  Action methods
35 //  ==============================================================================================================================
36
37     public String doInitialize () {
38 //  -----------------------------
39       Session      connex  = Database.getSession();
40       Transaction  transax = connex.beginTransaction();
41       try {
42         loadFilter();
43         doSearch();
44
45 //      Final initialization of the form
46         setCandidates();
47         setContextTypeOptions(getInvolvedContexts());
48
49         transax.commit();
50         return SUCCESS;
51       }
52       catch (Exception error) {
53 //      No need to roll back the transaction as it is read only
54         logger.error("Reason: ", error);
55         return ERROR;
56       }
57     }
58
59     protected String doSearch () throws InvalidPropertyException {
60 //  ----------------------------
61       Map<String, Object> session = getSession();
62       User                user    = getConnectedUser();
63
64       Study.Properties  sprop = new Study.Properties();
65
66 //    Search matching all criteria
67         if (!this.state.equals("ANY"))     sprop.setState( ProgressState.valueOf(this.state) );
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);
72         if (index > 0) {
73           User him = UserDirectory.selectUser(index);
74           sprop.setManager(him);
75         }
76 //    Set of the visibility
77         if (visibility.equals("all")) {
78           Study.Properties  other = sprop.copy();
79
80           other.setVisibility(Visibility.PUBLIC);
81           sprop.setVisibility(Visibility.PRIVATE);
82           sprop.setActor(user);
83
84           result = Database.selectStudiesWhere(sprop, other);
85         }
86         else {
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);
92
93           result = Database.selectStudiesWhere(sprop);
94       }
95       session.put("search.result", result);                          // For redisplaying the page without re-executing the search
96       return "refresh";
97     }
98
99 //  ==============================================================================================================================
100 //  Getters
101 //  ==============================================================================================================================
102
103     public String getContextMatch () {
104 //  --------------------------------
105       return matcontext;
106     }
107     public String getCriteriaMatch () {
108 //  ---------------------------------
109       return matchamong;
110     }
111     public String getReference () {
112 //  -----------------------------
113       return refid;
114     }
115     public String getState () {
116 //  -------------------------
117       return state;
118     }
119     public String getVisibility () {
120 //  ------------------------------
121       return visibility;
122     }
123     public String getWords () {
124 //  -------------------------
125       return words;
126     }
127
128 //  ==============================================================================================================================
129 //  Setters
130 //  ==============================================================================================================================
131
132     public void setContextMatch (String value) {
133 //  ------------------------------------------
134       this.matcontext = value;
135     }
136     public void setCriteriaMatch (String value) {
137 //  -------------------------------------------
138       this.matchamong = value;
139     }
140     public void setReference (String value) {
141 //  ---------------------------------------
142       this.refid = value;
143     }
144     public void setState (String value) {
145 //  -----------------------------------
146       this.state = value;
147     }
148     public void setVisibility (String value) {
149 //  ----------------------------------------
150       this.visibility = value;
151     }
152     public void setWords (String value) {
153 //  -----------------------------------
154       this.words = value;
155     }
156
157 //  ==============================================================================================================================
158 //  Implementation of abstract services
159 //  ==============================================================================================================================
160
161         protected List<SimulationContextType> getInvolvedContexts () {
162 //  ------------------------------------------------------------
163       List<ProjectSettings.Step>  steps  = ProjectSettings.getStepsOf(Study.class);
164       ProjectSettings.Step[]      number = steps.toArray(new ProjectSettings.Step[steps.size()]);
165       
166       return SimulationContext.selectTypesOf(number);
167         }
168
169     @SuppressWarnings("unchecked")
170         protected void loadFilter () {
171 //  ----------------------------
172       Map<String,Object> session = getSession();
173       User                user    = getConnectedUser();
174       Map<String,Object> filter  = (Map<String, Object>)session.get("study.filter");   // A default filter is supposed being set at start
175
176       visibility = (String)filter.get("visibility");
177       matchamong = (String)filter.get("matchamong");
178       matcontext = (String)filter.get("matcontext");
179       state      = (String)filter.get("state");
180       author     = (String)filter.get("author");
181       refid      = (String)filter.get("reference");
182       words      = (String)filter.get("title");
183       context    = (List<SimulationContext>)filter.get("context");
184
185       if (user == null) {
186         visibility = "onlypublic";
187       }
188     }
189     
190     @SuppressWarnings("unchecked")
191         protected void saveFilter () {
192 //  ----------------------------
193       Map<String, Object> session = getSession();
194       Map<String, Object> filter  = (Map<String, Object>)session.get("study.filter");   // A default filter is supposed being set at start
195
196       filter.put("visibility", this.visibility);
197       filter.put("matchamong", this.matchamong);
198       filter.put("matcontext", this.matcontext);
199       filter.put("state",      this.state);
200       filter.put("author",     this.author);
201       filter.put("reference",  this.refid);
202       filter.put("title",      this.words);
203
204       context = (List<SimulationContext>)filter.get("context");  // Only criteria not part of the form
205
206     }
207 }