1 package org.splat.simer;
6 import org.splat.kernel.InvalidPropertyException;
7 import org.splat.dal.bo.kernel.User;
8 import org.splat.dal.bo.som.ProgressState;
9 import org.splat.service.SearchService;
10 import org.splat.service.SimulationContextService;
11 import org.splat.service.UserService;
12 import org.splat.service.technical.ProjectSettingsService;
13 import org.splat.dal.bo.som.SimulationContext;
14 import org.splat.dal.bo.som.SimulationContextType;
15 import org.splat.dal.bo.som.Study;
16 import org.splat.dal.bo.som.Visibility;
19 * Search studies form action.
21 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
23 public class SearchStudyAction extends SearchBaseAction {
25 private String visibility = null; // "Private", "Public", "All"
26 private String state = null; // "In-Work", "In-Draft", "In-Check"...
27 private String matchamong = null; // "all" or "any"
28 private String matcontext = null; // "all" or "any"
29 private String refid = null; // Study reference
30 private String words = null; // Full text search words
32 * Injected project settings service.
34 private ProjectSettingsService _projectSettingsService;
36 * Injected search service.
38 private SearchService _searchService;
40 * Injected simulation context service.
42 private SimulationContextService _simulationContextService;
44 * Injected user service.
46 private UserService _userService;
49 * Value of the menu property.
50 * It can be: none, create, open, study, knowledge, sysadmin, help.
52 private String _menuProperty;
57 private static final long serialVersionUID = -1910481357051393077L;
60 refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext
63 // ==============================================================================================================================
65 // ==============================================================================================================================
68 * Initialize study search form.
69 * @return SUCCESS if no exception, otherwise return ERROR
71 public String doInitialize() {
76 // Final initialization of the form
78 setContextTypeOptions(getInvolvedContexts());
80 setMenuProperty("open");
81 initializationScreenContext(_menuProperty);
84 } catch (Exception error) {
85 // No need to roll back the transaction as it is read only
86 logger.error("Reason: ", error);
88 setMenuProperty("none");
89 initializationScreenContext(_menuProperty);
95 protected String doSearch() throws InvalidPropertyException {
96 // ----------------------------
97 Map<String, Object> session = getSession();
98 User user = getConnectedUser();
100 Study.Properties sprop = new Study.Properties();
102 // Search matching all criteria
103 if (!this.state.equals("ANY"))
104 sprop.setState(ProgressState.valueOf(this.state));
105 if (words.length() > 0)
106 sprop.setTitle(words);
107 if (refid.length() > 0)
108 sprop.setReference(refid);
109 if (context.size() > 0)
110 sprop.setSimulationContexts(context);
111 int index = Integer.valueOf(author);
113 User him = getUserService().selectUser(index);
114 sprop.setManager(him);
116 // Set of the visibility
117 if (visibility.equals("all")) {
118 Study.Properties other = sprop.copy();
120 other.setVisibility(Visibility.PUBLIC);
121 sprop.setVisibility(Visibility.PRIVATE);
122 sprop.setActor(user);
124 result = getSearchService().selectStudiesWhere(sprop, other);
126 Visibility reparea = null;
127 if (visibility.equals("onlypublic"))
128 reparea = Visibility.PUBLIC;
130 reparea = Visibility.valueOf(visibility);
131 sprop.setVisibility(reparea);
132 if (reparea == Visibility.PRIVATE)
133 sprop.setActor(user);
135 result = getSearchService().selectStudiesWhere(sprop);
137 session.put("search.result", result); // For redisplaying the page without re-executing the search
141 // ==============================================================================================================================
143 // ==============================================================================================================================
145 public String getContextMatch() {
146 // --------------------------------
150 public String getCriteriaMatch() {
151 // ---------------------------------
155 public String getReference() {
156 // -----------------------------
160 public String getState() {
161 // -------------------------
165 public String getVisibility() {
166 // ------------------------------
170 public String getWords() {
171 // -------------------------
175 // ==============================================================================================================================
177 // ==============================================================================================================================
179 public void setContextMatch(String value) {
180 // ------------------------------------------
181 this.matcontext = value;
184 public void setCriteriaMatch(String value) {
185 // -------------------------------------------
186 this.matchamong = value;
189 public void setReference(String value) {
190 // ---------------------------------------
194 public void setState(String value) {
195 // -----------------------------------
199 public void setVisibility(String value) {
200 // ----------------------------------------
201 this.visibility = value;
204 public void setWords(String value) {
205 // -----------------------------------
209 // ==============================================================================================================================
210 // Implementation of abstract services
211 // ==============================================================================================================================
213 protected List<SimulationContextType> getInvolvedContexts() {
214 // ------------------------------------------------------------
215 List<ProjectSettingsService.Step> steps = getProjectSettings()
216 .getStepsOf(Study.class);
217 ProjectSettingsService.Step[] number = steps
218 .toArray(new ProjectSettingsService.Step[steps.size()]);
220 return getSimulationContextService().selectTypesOf(number);
223 @SuppressWarnings("unchecked")
224 protected void loadFilter() {
225 // ----------------------------
226 Map<String, Object> session = getSession();
227 User user = getConnectedUser();
228 Map<String, Object> filter = (Map<String, Object>) session
229 .get("study.filter"); // A default filter is supposed being set at start
231 visibility = (String) filter.get("visibility");
232 matchamong = (String) filter.get("matchamong");
233 matcontext = (String) filter.get("matcontext");
234 state = (String) filter.get("state");
235 author = (String) filter.get("author");
236 refid = (String) filter.get("reference");
237 words = (String) filter.get("title");
238 context = (List<SimulationContext>) filter.get("context");
241 visibility = "onlypublic";
245 @SuppressWarnings("unchecked")
246 protected void saveFilter() {
247 // ----------------------------
248 Map<String, Object> session = getSession();
249 Map<String, Object> filter = (Map<String, Object>) session
250 .get("study.filter"); // A default filter is supposed being set at start
252 filter.put("visibility", this.visibility);
253 filter.put("matchamong", this.matchamong);
254 filter.put("matcontext", this.matcontext);
255 filter.put("state", this.state);
256 filter.put("author", this.author);
257 filter.put("reference", this.refid);
258 filter.put("title", this.words);
260 context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
265 * Get the searchService.
267 * @return the searchService
269 public SearchService getSearchService() {
270 return _searchService;
274 * Set the searchService.
276 * @param searchService
277 * the searchService to set
279 public void setSearchService(SearchService searchService) {
280 _searchService = searchService;
284 * Get project settings.
286 * @return Project settings service
288 private ProjectSettingsService getProjectSettings() {
289 return _projectSettingsService;
293 * Set project settings service.
295 * @param projectSettingsService
296 * project settings service
298 public void setProjectSettings(ProjectSettingsService projectSettingsService) {
299 _projectSettingsService = projectSettingsService;
303 * Get the simulationContextService.
305 * @return the simulationContextService
307 public SimulationContextService getSimulationContextService() {
308 return _simulationContextService;
312 * Set the simulationContextService.
314 * @param simulationContextService
315 * the simulationContextService to set
317 public void setSimulationContextService(
318 SimulationContextService simulationContextService) {
319 _simulationContextService = simulationContextService;
323 * Get the userService.
325 * @return the userService
327 public UserService getUserService() {
332 * Set the userService.
335 * the userService to set
337 public void setUserService(UserService userService) {
338 _userService = userService;
342 * Get the menuProperty.
343 * @return the menuProperty
345 public String getMenuProperty() {
346 return _menuProperty;
350 * Set the menuProperty.
351 * @param menuProperty the menuProperty to set
353 public void setMenuProperty(String menuProperty) {
354 this._menuProperty = menuProperty;