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;
55 * Value of the tool bar property.
56 * It can be: none, standard, study, back.
58 private String _toolProperty;
63 private static final long serialVersionUID = -1910481357051393077L;
66 refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext
69 // ==============================================================================================================================
71 // ==============================================================================================================================
74 * Initialize study search form.
75 * @return SUCCESS if no exception, otherwise return ERROR
77 public String doInitialize() {
82 // Final initialization of the form
84 setContextTypeOptions(getInvolvedContexts());
86 setMenuProperty("open");
87 setToolProperty("none");
88 initializationScreenContext(_menuProperty, _toolProperty);
91 } catch (Exception error) {
92 // No need to roll back the transaction as it is read only
93 logger.error("Reason: ", error);
95 setMenuProperty("none");
96 initializationScreenContext(_menuProperty);
102 protected String doSearch() throws InvalidPropertyException {
103 // ----------------------------
104 Map<String, Object> session = getSession();
105 User user = getConnectedUser();
107 Study.Properties sprop = new Study.Properties();
109 // Search matching all criteria
110 if (!this.state.equals("ANY"))
111 sprop.setState(ProgressState.valueOf(this.state));
112 if (words.length() > 0)
113 sprop.setTitle(words);
114 if (refid.length() > 0)
115 sprop.setReference(refid);
116 if (context.size() > 0)
117 sprop.setSimulationContexts(context);
118 int index = Integer.valueOf(author);
120 User him = getUserService().selectUser(index);
121 sprop.setManager(him);
123 // Set of the visibility
124 if (visibility.equals("all")) {
125 Study.Properties other = sprop.copy();
127 other.setVisibility(Visibility.PUBLIC);
128 sprop.setVisibility(Visibility.PRIVATE);
129 sprop.setActor(user);
131 result = getSearchService().selectStudiesWhere(sprop, other);
133 Visibility reparea = null;
134 if (visibility.equals("onlypublic"))
135 reparea = Visibility.PUBLIC;
137 reparea = Visibility.valueOf(visibility);
138 sprop.setVisibility(reparea);
139 if (reparea == Visibility.PRIVATE)
140 sprop.setActor(user);
142 result = getSearchService().selectStudiesWhere(sprop);
144 session.put("search.result", result); // For redisplaying the page without re-executing the search
148 // ==============================================================================================================================
150 // ==============================================================================================================================
152 public String getContextMatch() {
153 // --------------------------------
157 public String getCriteriaMatch() {
158 // ---------------------------------
162 public String getReference() {
163 // -----------------------------
167 public String getState() {
168 // -------------------------
172 public String getVisibility() {
173 // ------------------------------
177 public String getWords() {
178 // -------------------------
182 // ==============================================================================================================================
184 // ==============================================================================================================================
186 public void setContextMatch(String value) {
187 // ------------------------------------------
188 this.matcontext = value;
191 public void setCriteriaMatch(String value) {
192 // -------------------------------------------
193 this.matchamong = value;
196 public void setReference(String value) {
197 // ---------------------------------------
201 public void setState(String value) {
202 // -----------------------------------
206 public void setVisibility(String value) {
207 // ----------------------------------------
208 this.visibility = value;
211 public void setWords(String value) {
212 // -----------------------------------
216 // ==============================================================================================================================
217 // Implementation of abstract services
218 // ==============================================================================================================================
220 protected List<SimulationContextType> getInvolvedContexts() {
221 // ------------------------------------------------------------
222 List<ProjectSettingsService.Step> steps = getProjectSettings()
223 .getStepsOf(Study.class);
224 ProjectSettingsService.Step[] number = steps
225 .toArray(new ProjectSettingsService.Step[steps.size()]);
227 return getSimulationContextService().selectTypesOf(number);
230 @SuppressWarnings("unchecked")
231 protected void loadFilter() {
232 // ----------------------------
233 Map<String, Object> session = getSession();
234 User user = getConnectedUser();
235 Map<String, Object> filter = (Map<String, Object>) session
236 .get("study.filter"); // A default filter is supposed being set at start
238 visibility = (String) filter.get("visibility");
239 matchamong = (String) filter.get("matchamong");
240 matcontext = (String) filter.get("matcontext");
241 state = (String) filter.get("state");
242 author = (String) filter.get("author");
243 refid = (String) filter.get("reference");
244 words = (String) filter.get("title");
245 context = (List<SimulationContext>) filter.get("context");
248 visibility = "onlypublic";
252 @SuppressWarnings("unchecked")
253 protected void saveFilter() {
254 // ----------------------------
255 Map<String, Object> session = getSession();
256 Map<String, Object> filter = (Map<String, Object>) session
257 .get("study.filter"); // A default filter is supposed being set at start
259 filter.put("visibility", this.visibility);
260 filter.put("matchamong", this.matchamong);
261 filter.put("matcontext", this.matcontext);
262 filter.put("state", this.state);
263 filter.put("author", this.author);
264 filter.put("reference", this.refid);
265 filter.put("title", this.words);
267 context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
272 * Get the searchService.
274 * @return the searchService
276 public SearchService getSearchService() {
277 return _searchService;
281 * Set the searchService.
283 * @param searchService
284 * the searchService to set
286 public void setSearchService(SearchService searchService) {
287 _searchService = searchService;
291 * Get project settings.
293 * @return Project settings service
295 private ProjectSettingsService getProjectSettings() {
296 return _projectSettingsService;
300 * Set project settings service.
302 * @param projectSettingsService
303 * project settings service
305 public void setProjectSettings(ProjectSettingsService projectSettingsService) {
306 _projectSettingsService = projectSettingsService;
310 * Get the simulationContextService.
312 * @return the simulationContextService
314 public SimulationContextService getSimulationContextService() {
315 return _simulationContextService;
319 * Set the simulationContextService.
321 * @param simulationContextService
322 * the simulationContextService to set
324 public void setSimulationContextService(
325 SimulationContextService simulationContextService) {
326 _simulationContextService = simulationContextService;
330 * Get the userService.
332 * @return the userService
334 public UserService getUserService() {
339 * Set the userService.
342 * the userService to set
344 public void setUserService(UserService userService) {
345 _userService = userService;
349 * Get the menuProperty.
350 * @return the menuProperty
352 public String getMenuProperty() {
353 return _menuProperty;
357 * Set the menuProperty.
358 * @param menuProperty the menuProperty to set
360 public void setMenuProperty(String menuProperty) {
361 this._menuProperty = menuProperty;
365 * Get the toolProperty.
366 * @return the toolProperty
368 public String getToolProperty() {
369 return _toolProperty;
373 * Set the toolProperty.
374 * @param toolProperty the toolProperty to set
376 public void setToolProperty(final String toolProperty) {
377 _toolProperty = toolProperty;