]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman/src/org/splat/simer/SearchBaseAction.java
Salome HOME
Refactoring of Database, replacing SQL by DAOs calls. Methods for search by criteria...
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / SearchBaseAction.java
index 6258bbf24fa6a1fbf12f0b92681d32a8fc5ecf8b..2c321176fc3a7b51ea54aaa5ff84e6e6b11f7228 100644 (file)
@@ -13,222 +13,271 @@ import org.splat.dal.bo.kernel.User;
 import org.splat.kernel.UserDirectory;
 import org.splat.som.ApplicationRights;
 import org.splat.dal.dao.som.Database;
+import org.splat.service.SimulationContextService;
 import org.splat.service.technical.ProjectSettingsService;
 import org.splat.service.dto.Proxy;
 import org.splat.dal.bo.som.SimulationContext;
 import org.splat.dal.bo.som.SimulationContextType;
 
-
 public abstract class SearchBaseAction extends Action {
 
-       protected String                      ctype    = null;   // Context type  index, when selected
-       protected String                      cvalue   = null;   // Context value index, when selected
-       protected String                      cindex   = "";     // Context index, when removed
-    protected String                      author  = null;
-    protected List<Name>                  manager = null;
-       protected SimulationContextType       newtype;           // Context type  to be valued
-       protected List<SimulationContext>     newvalue;          // Context value to be selected
-       protected List<SimulationContextType> critext;           // Addable context types
-       protected List<SimulationContext>     context;           // Current contexts search criteria
-       protected List<Proxy>                 result;
-
-       private static final long   serialVersionUID = 7863055790228544510L;
-
-    enum UserAction { refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext }
-
-//  ==============================================================================================================================
-//  Action methods
-//  ==============================================================================================================================
-
-       public String doSubmitForm () {
-//  -----------------------------
-//  Identification of the user action
-      UserAction                                              action = UserAction.refreshResult; 
-      if      (ctype  != null && Integer.valueOf(ctype)  > 0) action = UserAction.selectContextType;
-      else if (cvalue != null && Integer.valueOf(cvalue) > 0) action = UserAction.selectContextValue;
-      else if (cindex.length() > 0) {
-       int      index = Integer.valueOf(cindex);
-        if      (index > 0)                                   action = UserAction.removeContext;
-        else if (index < 0)                                   action = UserAction.cancelSelect;
-      }
-//  Execution of the user action
-      Session      connex  = Database.getSession();
-      Transaction  transax = connex.beginTransaction();
-      String       done;
-      try {
-        saveFilter();                                      // Also reinitializes the form, if needed
-
-        if (action == UserAction.selectContextType) {
-          done = doSelectContextType();
-        } else
-        if (action == UserAction.selectContextValue) {
-          done = doAddContext();
-        } else
-        if (action == UserAction.removeContext) {
-          done = doRemoveContext();
-        } else
-        if (action == UserAction.cancelSelect) {
-          done = doCancel();
-        }
-        else {     // UserAction.refreshResult
-          done = doSearch();
-          setContextTypeOptions(getInvolvedContexts());    // Done in other do functions, when required
-        }
-        setCandidates();
-        transax.commit();
-        return done;
-      }
-      catch (Exception error) {
-//      No need to roll back the transaction as it is read only
-       logger.error("Reason: ", error);
-        return ERROR;
-      }
-       }
-
-    @SuppressWarnings("unchecked")
-       protected String doSelectContextType () {
-//  ---------------------------------------
-      SimulationContext.Properties  sprop = new SimulationContext.Properties();
-
-      newtype  = SimulationContext.selectType(Integer.valueOf(ctype));
-      newvalue = Database.selectSimulationContextsWhere(sprop.setType(newtype));
-      if (cindex.length() > 0 && Integer.valueOf(cindex) == 0)
-       getSession().remove("search.result");
-      else
-        result = (List<Proxy>)getSession().get("search.result");   // We keep the previous result search, if valid
-      return "selectype";
-    }
-
-    protected String doAddContext () {
-//  --------------------------------
-      SimulationContext  selected = Database.selectSimulationContext(Integer.valueOf(cvalue));
-
-      context.add(selected);
-      setContextTypeOptions(getInvolvedContexts());                // Sets critext
-      getSession().remove("search.result");                        // The current result is obsolete
-      return "refresh";
-    }
-
-    protected String doRemoveContext () {
-//  -----------------------------------
-      int  index = Integer.valueOf(cindex);
-      for (Iterator<SimulationContext> selected=context.iterator(); selected.hasNext();) {
-       if (selected.next().getIndex() == index) {
-          selected.remove();
-          break;
-       }
-      }
-      setContextTypeOptions(getInvolvedContexts());                // Sets critext
-      getSession().remove("search.result");                        // The current result is obsolete
-      return "refresh";
-    }
-
-    @SuppressWarnings("unchecked")
-       protected String doCancel () {
-//  ----------------------------
-      result = (List<Proxy>)getSession().get("search.result");     // Current result search
-      setContextTypeOptions(getInvolvedContexts());                // Sets critext
-      return "refresh";
-    }
-
-//  ==============================================================================================================================
-//  Getters
-//  ==============================================================================================================================
-
-    public String getAuthor () {
-//  --------------------------
-      return author;
-    }
-    public List<Name> getCandidates () {
-//  ----------------------------------
-      return manager;
-    }
-    public List<SimulationContextType> getContextTypeOptions () {
-//  -----------------------------------------------------------
-      return critext;
-    }
-    public List<SimulationContext> getContextValueOptions () {
-//  --------------------------------------------------------
-      return newvalue;
-    }
-    public SimulationContextType getSelectedContextType () {
-//  ------------------------------------------------------
-      return newtype;
-    }
-    public List<SimulationContext> getSimulationContexts () {
-//  -------------------------------------------------------
-      return context;
-    }
-    public List<Proxy> getResult () {
-//  -------------------------------
-      return result;
-    }
-
-//  ==============================================================================================================================
-//  Setters
-//  ==============================================================================================================================
-    
-    public void setAuthor (String index) {
-//  ------------------------------------
-      this.author = index;
-    }
-    public void setContextType (String type) {
-//  ----------------------------------------
-      this.ctype = type;
-    }
-    public void setContextValue (String value) {
-//  ------------------------------------------
-      this.cvalue = value;
-    }
-    public void setContextIndex (String value) {
-//  ------------------------------------------
-      this.cindex = value;
-    }
-
-    protected void setCandidates () {
-//  -------------------------------
-      manager = new Vector<Name>();
-      List<User> users = UserDirectory.selectAllUsers();
-      User       me    = getConnectedUser();        // May be null
-      for (Iterator<User> i=users.iterator(); i.hasNext(); ) {
-        User               next = i.next();
-        ApplicationRights  he   = new ApplicationRights(next);
-        if (he.canCreateStudy()) {
-          if (next.equals(me)) manager.add(0, new ValidationFacade.ByManager(me));
-          else                 manager.add(next);
-        }
-      }
-    }
-
-    protected void setContextTypeOptions (List<SimulationContextType> critext) {
-//  --------------------------------------------------------------------------
-      for (Iterator<SimulationContext> i=context.iterator(); i.hasNext();) {
-        critext.remove(i.next().getType());                        // Already used context type
-      }
-//    Ordering by alphabetical order of localized context types
-      SimulationContextType[] types   = critext.toArray( new SimulationContextType[critext.size()] );
-      ContextTypeComparator   compare = new ContextTypeComparator();
-      ProjectSettingsService.Step    step    = types[0].getAttachedStep();
-      int  from = 0;
-      int  to   = 0;
-      while (to < types.length-1) {
-        to += 1;
-       if (types[to].isAttachedTo(step)) continue;
-
-        if (to > from+1) Arrays.sort(types, from, to, compare);
-        from = to;
-       step = types[to].getAttachedStep();
-      }
-      if (to > from) Arrays.sort(types, from, to+1, compare);
-      this.critext  =  Arrays.asList(types);
-    }
-
-//  ==============================================================================================================================
-//  Abstract services
-//  ==============================================================================================================================
-
-       protected abstract String                      doSearch () throws InvalidPropertyException;
-       protected abstract List<SimulationContextType> getInvolvedContexts ();
-       protected abstract void                        loadFilter ();
-       protected abstract void                        saveFilter ();
+       /**
+        * Serial version ID.
+        */
+       private static final long serialVersionUID = 7863055790228544510L;
+
+       protected String ctype = null; // Context type index, when selected
+       protected String cvalue = null; // Context value index, when selected
+       protected String cindex = ""; // Context index, when removed
+       protected String author = null;
+       protected List<Name> manager = null;
+       protected SimulationContextType newtype; // Context type to be valued
+       protected List<SimulationContext> newvalue; // Context value to be selected
+       protected List<SimulationContextType> critext; // Addable context types
+       protected List<SimulationContext> context; // Current contexts search criteria
+       protected List<Proxy> result;
+       /**
+        * Injected simulation context service.
+        */
+       private SimulationContextService _simulationContextService;
+
+       enum UserAction {
+               refreshResult, selectContextType, selectContextValue, cancelSelect, removeContext
+       }
+
+       // ==============================================================================================================================
+       // Action methods
+       // ==============================================================================================================================
+
+       public String doSubmitForm() {
+               // -----------------------------
+               // Identification of the user action
+               UserAction action = UserAction.refreshResult;
+               if (ctype != null && Integer.valueOf(ctype) > 0)
+                       action = UserAction.selectContextType;
+               else if (cvalue != null && Integer.valueOf(cvalue) > 0)
+                       action = UserAction.selectContextValue;
+               else if (cindex.length() > 0) {
+                       int index = Integer.valueOf(cindex);
+                       if (index > 0)
+                               action = UserAction.removeContext;
+                       else if (index < 0)
+                               action = UserAction.cancelSelect;
+               }
+               // Execution of the user action
+               Session connex = Database.getSession();
+               Transaction transax = connex.beginTransaction();
+               String done;
+               try {
+                       saveFilter(); // Also reinitializes the form, if needed
+
+                       if (action == UserAction.selectContextType) {
+                               done = doSelectContextType();
+                       } else if (action == UserAction.selectContextValue) {
+                               done = doAddContext();
+                       } else if (action == UserAction.removeContext) {
+                               done = doRemoveContext();
+                       } else if (action == UserAction.cancelSelect) {
+                               done = doCancel();
+                       } else { // UserAction.refreshResult
+                               done = doSearch();
+                               setContextTypeOptions(getInvolvedContexts()); // Done in other do functions, when required
+                       }
+                       setCandidates();
+                       transax.commit();
+                       return done;
+               } catch (Exception error) {
+                       // No need to roll back the transaction as it is read only
+                       logger.error("Reason: ", error);
+                       return ERROR;
+               }
+       }
+
+       @SuppressWarnings("unchecked")
+       protected String doSelectContextType() {
+               // ---------------------------------------
+               SimulationContext.Properties sprop = new SimulationContext.Properties();
+
+               newtype = getSimulationContextService().selectType(Integer.valueOf(ctype));
+               newvalue = getSimulationContextService().selectSimulationContextsWhere(
+                               sprop.setType(newtype));
+               if (cindex.length() > 0 && Integer.valueOf(cindex) == 0)
+                       getSession().remove("search.result");
+               else
+                       result = (List<Proxy>) getSession().get("search.result"); // We keep the previous result search, if valid
+               return "selectype";
+       }
+
+       protected String doAddContext() {
+               // --------------------------------
+               SimulationContext selected = getSimulationContextService()
+                               .selectSimulationContext(Integer.valueOf(cvalue));
+
+               context.add(selected);
+               setContextTypeOptions(getInvolvedContexts()); // Sets critext
+               getSession().remove("search.result"); // The current result is obsolete
+               return "refresh";
+       }
+
+       protected String doRemoveContext() {
+               // -----------------------------------
+               int index = Integer.valueOf(cindex);
+               for (Iterator<SimulationContext> selected = context.iterator(); selected
+                               .hasNext();) {
+                       if (selected.next().getIndex() == index) {
+                               selected.remove();
+                               break;
+                       }
+               }
+               setContextTypeOptions(getInvolvedContexts()); // Sets critext
+               getSession().remove("search.result"); // The current result is obsolete
+               return "refresh";
+       }
+
+       @SuppressWarnings("unchecked")
+       protected String doCancel() {
+               // ----------------------------
+               result = (List<Proxy>) getSession().get("search.result"); // Current result search
+               setContextTypeOptions(getInvolvedContexts()); // Sets critext
+               return "refresh";
+       }
+
+       // ==============================================================================================================================
+       // Getters
+       // ==============================================================================================================================
+
+       public String getAuthor() {
+               // --------------------------
+               return author;
+       }
+
+       public List<Name> getCandidates() {
+               // ----------------------------------
+               return manager;
+       }
+
+       public List<SimulationContextType> getContextTypeOptions() {
+               // -----------------------------------------------------------
+               return critext;
+       }
+
+       public List<SimulationContext> getContextValueOptions() {
+               // --------------------------------------------------------
+               return newvalue;
+       }
+
+       public SimulationContextType getSelectedContextType() {
+               // ------------------------------------------------------
+               return newtype;
+       }
+
+       public List<SimulationContext> getSimulationContexts() {
+               // -------------------------------------------------------
+               return context;
+       }
+
+       public List<Proxy> getResult() {
+               // -------------------------------
+               return result;
+       }
+
+       // ==============================================================================================================================
+       // Setters
+       // ==============================================================================================================================
+
+       public void setAuthor(String index) {
+               // ------------------------------------
+               this.author = index;
+       }
+
+       public void setContextType(String type) {
+               // ----------------------------------------
+               this.ctype = type;
+       }
+
+       public void setContextValue(String value) {
+               // ------------------------------------------
+               this.cvalue = value;
+       }
+
+       public void setContextIndex(String value) {
+               // ------------------------------------------
+               this.cindex = value;
+       }
+
+       protected void setCandidates() {
+               // -------------------------------
+               manager = new Vector<Name>();
+               List<User> users = UserDirectory.selectAllUsers();
+               User me = getConnectedUser(); // May be null
+               for (Iterator<User> i = users.iterator(); i.hasNext();) {
+                       User next = i.next();
+                       ApplicationRights he = new ApplicationRights(next);
+                       if (he.canCreateStudy()) {
+                               if (next.equals(me))
+                                       manager.add(0, new ValidationFacade.ByManager(me));
+                               else
+                                       manager.add(next);
+                       }
+               }
+       }
+
+       protected void setContextTypeOptions(List<SimulationContextType> critext) {
+               // --------------------------------------------------------------------------
+               for (Iterator<SimulationContext> i = context.iterator(); i.hasNext();) {
+                       critext.remove(i.next().getType()); // Already used context type
+               }
+               // Ordering by alphabetical order of localized context types
+               SimulationContextType[] types = critext
+                               .toArray(new SimulationContextType[critext.size()]);
+               ContextTypeComparator compare = new ContextTypeComparator();
+               ProjectSettingsService.Step step = types[0].getAttachedStep();
+               int from = 0;
+               int to = 0;
+               while (to < types.length - 1) {
+                       to += 1;
+                       if (types[to].isAttachedTo(step))
+                               continue;
+
+                       if (to > from + 1)
+                               Arrays.sort(types, from, to, compare);
+                       from = to;
+                       step = types[to].getAttachedStep();
+               }
+               if (to > from)
+                       Arrays.sort(types, from, to + 1, compare);
+               this.critext = Arrays.asList(types);
+       }
+
+       // ==============================================================================================================================
+       // Abstract services
+       // ==============================================================================================================================
+
+       protected abstract String doSearch() throws InvalidPropertyException;
+
+       protected abstract List<SimulationContextType> getInvolvedContexts();
+
+       protected abstract void loadFilter();
+
+       protected abstract void saveFilter();
+
+       /**
+        * 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;
+       }
 }
\ No newline at end of file