Salome HOME
Rename the scenario functionality is implemented
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / SearchStudyAction.java
index 18ed3fdb61e277a26dae391a04a788a9ad92da19..423e39c374d2f9f9c7def02e8e134f1a9807eb68 100644 (file)
@@ -3,70 +3,55 @@ package org.splat.simer;
 import java.util.List;
 import java.util.Map;
 
-import org.splat.kernel.InvalidPropertyException;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.ProgressState;
-import org.splat.service.SearchService;
-import org.splat.service.SimulationContextService;
-import org.splat.service.UserService;
-import org.splat.service.technical.ProjectSettingsService;
 import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.SimulationContextType;
 import org.splat.dal.bo.som.Study;
 import org.splat.dal.bo.som.Visibility;
+import org.splat.kernel.InvalidPropertyException;
+import org.splat.service.SearchService;
+import org.splat.service.technical.ProjectSettingsService;
+import org.splat.wapp.Constants;
 
 /**
  * Search studies form action.
- *
- * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
  */
-public class SearchStudyAction extends SearchBaseAction {
-
-       private String visibility = null; // "Private", "Public", "All"
-       private String state = null; // "In-Work", "In-Draft", "In-Check"...
-       private String matchamong = null; // "all" or "any"
-       private String matcontext = null; // "all" or "any"
-       private String refid = null; // Study reference
-       private String words = null; // Full text search words
+public class SearchStudyAction extends AbstractSearchBaseAction {
+
        /**
-        * Injected project settings service.
+        * Serial version ID.
         */
-       private ProjectSettingsService _projectSettingsService;
+       private static final long serialVersionUID = -1910481357051393077L;
+
        /**
-        * Injected search service.
+        * "In-Work", "In-Draft", "In-Check"...
         */
-       private SearchService _searchService;
+       private String _state = null;
        /**
-        * Injected simulation context service.
+        * Criteria match: "all" or "any".
         */
-       private SimulationContextService _simulationContextService;
+       private String _criteriaMatch = null;
        /**
-        * Injected user service.
+        * Simulation context match: "all" or "any".
         */
-       private UserService _userService;
-       
+       private String _contextMatch = null;
        /**
-        * Value of the menu property. 
-        * It can be: none, create, open, study, knowledge, sysadmin, help.
+        * Study reference.
         */
-       private String _menuProperty;
-       
+       private String _reference = null;
        /**
-        * Value of the tool bar property. 
-        * It can be: none, standard, study, back.
+        * Full text search words.
         */
-       private String _toolProperty;
-       
+       private String _words = null;
        /**
-        * Value of the left menu property. 
-        * It can be: open, study, knowledge, scenario.
+        * Injected project settings service.
         */
-       private String _leftMenuProperty;
-
+       private ProjectSettingsService _projectSettings;
        /**
-        * Serial version ID.
+        * Injected search service.
         */
-       private static final long serialVersionUID = -1910481357051393077L;
+       private SearchService _searchService;
 
        enum UserAction {
                refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext
@@ -78,9 +63,11 @@ public class SearchStudyAction extends SearchBaseAction {
 
        /**
         * Initialize study search form.
+        * 
         * @return SUCCESS if no exception, otherwise return ERROR
         */
        public String doInitialize() {
+               String res = SUCCESS;
                try {
                        loadFilter();
                        doSearch();
@@ -88,67 +75,57 @@ public class SearchStudyAction extends SearchBaseAction {
                        // Final initialization of the form
                        setCandidates();
                        setContextTypeOptions(getInvolvedContexts());
-                       
-                       setMenuProperty("open");
-                       setToolProperty("none");
-                       setLeftMenuProperty("open");
-                       initializationFullScreenContext(_menuProperty, _toolProperty, _leftMenuProperty);
+                       initializationFullScreenContext(Constants.OPEN, Constants.NONE,
+                                       Constants.OPEN);
 
-                       return SUCCESS;
                } catch (Exception error) {
                        // No need to roll back the transaction as it is read only
-                       logger.error("Reason: ", error);
-                       
-                       setMenuProperty("none");
-                       initializationScreenContext(_menuProperty);
-                       
-                       return ERROR;
+                       LOG.error("Reason: ", error);
+
+                       initializationScreenContext(Constants.NONE);
+
+                       res = ERROR;
                }
+               return res;
        }
 
+       /**
+        * {@inheritDoc}
+        * 
+        * @see org.splat.simer.AbstractSearchBaseAction#doSearch()
+        */
+       @Override
        protected String doSearch() throws InvalidPropertyException {
-               // ----------------------------
                Map<String, Object> session = getSession();
-               User user = getConnectedUser();
-
                Study.Properties sprop = new Study.Properties();
 
                // Search matching all criteria
-               if (!this.state.equals("ANY"))
-                       sprop.setState(ProgressState.valueOf(this.state));
-               if (words.length() > 0)
-                       sprop.setTitle(words);
-               if (refid.length() > 0)
-                       sprop.setReference(refid);
-               if (context.size() > 0)
-                       sprop.setSimulationContexts(context);
-               int index = Integer.valueOf(author);
+               if (!this._state.equals("ANY")) {
+                       sprop.setState(ProgressState.valueOf(this._state));
+               }
+               if (_words.length() > 0) {
+                       sprop.setTitle(_words);
+               }
+               if (_reference.length() > 0) {
+                       sprop.setReference(_reference);
+               }
+               if (_context.size() > 0) {
+                       sprop.setSimulationContexts(_context);
+               }
+               int index = Integer.valueOf(_author);
                if (index > 0) {
                        User him = getUserService().selectUser(index);
                        sprop.setManager(him);
                }
                // Set of the visibility
-               if (visibility.equals("all")) {
-                       Study.Properties other = sprop.copy();
-
-                       other.setVisibility(Visibility.PUBLIC);
-                       sprop.setVisibility(Visibility.PRIVATE);
-                       sprop.setActor(user);
-
-                       result = getSearchService().selectStudiesWhere(sprop, other);
-               } else {
-                       Visibility reparea = null;
-                       if (visibility.equals("onlypublic"))
-                               reparea = Visibility.PUBLIC;
-                       else
-                               reparea = Visibility.valueOf(visibility);
-                       sprop.setVisibility(reparea);
-                       if (reparea == Visibility.PRIVATE)
-                               sprop.setActor(user);
-
-                       result = getSearchService().selectStudiesWhere(sprop);
-               }
-               session.put("search.result", result); // For redisplaying the page without re-executing the search
+               Study.Properties other = sprop.copy();
+
+               other.setVisibility(Visibility.PUBLIC);
+               sprop.setVisibility(Visibility.PRIVATE);
+               sprop.setActor(getConnectedUser());
+
+               _result = getSearchService().selectStudiesWhere(sprop, other);
+               session.put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
                return "refresh";
        }
 
@@ -157,75 +134,55 @@ public class SearchStudyAction extends SearchBaseAction {
        // ==============================================================================================================================
 
        public String getContextMatch() {
-               // --------------------------------
-               return matcontext;
+               return _contextMatch;
        }
 
        public String getCriteriaMatch() {
-               // ---------------------------------
-               return matchamong;
+               return _criteriaMatch;
        }
 
        public String getReference() {
-               // -----------------------------
-               return refid;
+               return _reference;
        }
 
        public String getState() {
-               // -------------------------
-               return state;
-       }
-
-       public String getVisibility() {
-               // ------------------------------
-               return visibility;
+               return _state;
        }
 
        public String getWords() {
-               // -------------------------
-               return words;
+               return _words;
        }
 
        // ==============================================================================================================================
        // Setters
        // ==============================================================================================================================
 
-       public void setContextMatch(String value) {
-               // ------------------------------------------
-               this.matcontext = value;
+       public void setContextMatch(final String value) {
+               this._contextMatch = value;
        }
 
-       public void setCriteriaMatch(String value) {
-               // -------------------------------------------
-               this.matchamong = value;
+       public void setCriteriaMatch(final String value) {
+               this._criteriaMatch = value;
        }
 
-       public void setReference(String value) {
-               // ---------------------------------------
-               this.refid = value;
+       public void setReference(final String value) {
+               this._reference = value;
        }
 
-       public void setState(String value) {
-               // -----------------------------------
-               this.state = value;
+       public void setState(final String value) {
+               this._state = value;
        }
 
-       public void setVisibility(String value) {
-               // ----------------------------------------
-               this.visibility = value;
-       }
-
-       public void setWords(String value) {
-               // -----------------------------------
-               this.words = value;
+       public void setWords(final String value) {
+               this._words = value;
        }
 
        // ==============================================================================================================================
        // Implementation of abstract services
        // ==============================================================================================================================
 
+       @Override
        protected List<SimulationContextType> getInvolvedContexts() {
-               // ------------------------------------------------------------
                List<ProjectSettingsService.Step> steps = getProjectSettings()
                                .getStepsOf(Study.class);
                ProjectSettingsService.Step[] number = steps
@@ -234,44 +191,37 @@ public class SearchStudyAction extends SearchBaseAction {
                return getSimulationContextService().selectTypesOf(number);
        }
 
+       @Override
        @SuppressWarnings("unchecked")
        protected void loadFilter() {
-               // ----------------------------
                Map<String, Object> session = getSession();
-               User user = getConnectedUser();
                Map<String, Object> filter = (Map<String, Object>) session
                                .get("study.filter"); // A default filter is supposed being set at start
 
-               visibility = (String) filter.get("visibility");
-               matchamong = (String) filter.get("matchamong");
-               matcontext = (String) filter.get("matcontext");
-               state = (String) filter.get("state");
-               author = (String) filter.get("author");
-               refid = (String) filter.get("reference");
-               words = (String) filter.get("title");
-               context = (List<SimulationContext>) filter.get("context");
-
-               if (user == null) {
-                       visibility = "onlypublic";
-               }
+               _criteriaMatch = (String) filter.get("matchamong");
+               _contextMatch = (String) filter.get("matcontext");
+               _state = (String) filter.get("state");
+               _author = (String) filter.get("author");
+               _reference = (String) filter.get("reference");
+               _words = (String) filter.get("title");
+               _context = (List<SimulationContext>) filter.get("context");
        }
 
+       @Override
        @SuppressWarnings("unchecked")
        protected void saveFilter() {
-               // ----------------------------
                Map<String, Object> session = getSession();
                Map<String, Object> filter = (Map<String, Object>) session
                                .get("study.filter"); // A default filter is supposed being set at start
 
-               filter.put("visibility", this.visibility);
-               filter.put("matchamong", this.matchamong);
-               filter.put("matcontext", this.matcontext);
-               filter.put("state", this.state);
-               filter.put("author", this.author);
-               filter.put("reference", this.refid);
-               filter.put("title", this.words);
+               filter.put("matchamong", this._criteriaMatch);
+               filter.put("matcontext", this._contextMatch);
+               filter.put("state", this._state);
+               filter.put("author", this._author);
+               filter.put("reference", this._reference);
+               filter.put("title", this._words);
 
-               context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
+               _context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
 
        }
 
@@ -290,7 +240,7 @@ public class SearchStudyAction extends SearchBaseAction {
         * @param searchService
         *            the searchService to set
         */
-       public void setSearchService(SearchService searchService) {
+       public void setSearchService(final SearchService searchService) {
                _searchService = searchService;
        }
 
@@ -300,7 +250,7 @@ public class SearchStudyAction extends SearchBaseAction {
         * @return Project settings service
         */
        private ProjectSettingsService getProjectSettings() {
-               return _projectSettingsService;
+               return _projectSettings;
        }
 
        /**
@@ -309,94 +259,8 @@ public class SearchStudyAction extends SearchBaseAction {
         * @param projectSettingsService
         *            project settings service
         */
-       public void setProjectSettings(ProjectSettingsService projectSettingsService) {
-               _projectSettingsService = projectSettingsService;
-       }
-
-       /**
-        * Get the simulationContextService.
-        * 
-        * @return the simulationContextService
-        */
-       public SimulationContextService getSimulationContextService() {
-               return _simulationContextService;
-       }
-
-       /**
-        * Set the simulationContextService.
-        * 
-        * @param simulationContextService
-        *            the simulationContextService to set
-        */
-       public void setSimulationContextService(
-                       SimulationContextService simulationContextService) {
-               _simulationContextService = simulationContextService;
-       }
-
-       /**
-        * Get the userService.
-        * 
-        * @return the userService
-        */
-       public UserService getUserService() {
-               return _userService;
-       }
-
-       /**
-        * Set the userService.
-        * 
-        * @param userService
-        *            the userService to set
-        */
-       public void setUserService(UserService userService) {
-               _userService = userService;
-       }
-       
-       /**
-        * Get the menuProperty.
-        * @return the menuProperty
-        */
-       public String getMenuProperty() {
-               return _menuProperty;
-       }
-
-       /**
-        * Set the menuProperty.
-        * @param menuProperty the menuProperty to set
-        */
-       public void setMenuProperty(String menuProperty) {
-               this._menuProperty = menuProperty;
-       }
-       
-       /**
-        * Get the toolProperty.
-        * @return the toolProperty
-        */
-       public String getToolProperty() {
-               return _toolProperty;
-       }
-
-       /**
-        * Set the toolProperty.
-        * @param toolProperty the toolProperty to set
-        */
-       public void setToolProperty(final String toolProperty) {
-               _toolProperty = toolProperty;
-       }
-       
-       /**
-        * Get the leftMenuProperty.
-        * @return the leftMenuProperty
-        */
-       public String getLeftMenuProperty() {
-               return _leftMenuProperty;
-       }
-
-       /**
-        * Set the leftMenuProperty.
-        * @param leftMenuProperty the leftMenuProperty to set
-        */
-       public void setLeftMenuProperty(final String leftMenuProperty) {
-               _leftMenuProperty = leftMenuProperty;
+       public void setProjectSettings(
+                       final ProjectSettingsService projectSettingsService) {
+               _projectSettings = projectSettingsService;
        }
 }
\ No newline at end of file