]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman/src/org/splat/simer/SearchKnowledgeAction.java
Salome HOME
Refactoring: kernel and som are moved to Siman-Common.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / SearchKnowledgeAction.java
index b426e3100c952d20828631a5d66e817c29736ad8..e71219e45384d962b42f3025ce9bfff03ec1edb1 100644 (file)
@@ -15,17 +15,16 @@ import org.splat.som.ProgressState;
 import org.splat.som.SimulationContext;
 import org.splat.som.SimulationContextType;
 import org.splat.som.Visibility;
-import org.splat.wapp.Item;
-import org.splat.wapp.TabBar;
 
 
 public class SearchKnowledgeAction extends SearchBaseAction {
 
-    private TabBar                       area    = null;   // Active repository area
-    private String                       among   = null;   // "all", "inCHECK" or "ref"
-    private String                       typid   = null;   // Knowledge type index when among all
-    private String                       refid   = null;   // Knowledge reference  when among ref
-    private String                       words   = null;   // Full text search words
+    private String                       visibility = null;   // "Private", "Public", "All"
+    private String                       typid      = null;   // Knowledge type index when among all
+    private String                       matchamong = null;   // "all" or "any"
+    private String                       matcontext = null;   // "all" or "any"
+    private String                       refid      = null;   // Knowledge reference  when among ref
+    private String                       words      = null;   // Full text search words
     private List<KnowledgeElementType>   types;            // Available knowledge types filter (initialized below)
 
     private static final long serialVersionUID = -3104321907432838476L;
@@ -40,9 +39,6 @@ public class SearchKnowledgeAction extends SearchBaseAction {
       Transaction  transax = connex.beginTransaction();      
       try {
         loadFilter();          
-        if (newarea != null) {                        // New selected repository area
-          area.selects(newarea);
-        }
         doSearch();
 
 //      Final initialization of the form
@@ -66,45 +62,36 @@ public class SearchKnowledgeAction extends SearchBaseAction {
       User                user    = getConnectedUser();
 
       KnowledgeElement.Properties  sprop = new KnowledgeElement.Properties();
-      KnowledgeElement.Properties  other = null;
-
-//    Set of the selected repository area
-      String     selectab = area.getSelection().toUpperCase();
-      Visibility reparea  = Visibility.valueOf(selectab);
-      sprop.setVisibility(reparea);
-
-//    Search from a given reference
-      if (among.equals("ref")) {
-       if (refid.length() == 0) {
-          getSession().remove("search.result");                      // The current result is obsolete
-          return "wait";
-       }
-        sprop.setReference(refid);
-        if (reparea == Visibility.PRIVATE) {                         // Restriction to studies in which the connected user is involved
-          other = sprop.copy().setActor(user);
-          sprop.setAuthor(user);
-        }
-      } else {
-//    Search from other available criteria
+
+//    Search matching all criteria
+        sprop.setType( KnowledgeElement.selectType(Integer.valueOf(typid)) );
         if (words.length() > 0)          sprop.setTitle(words);
+        if (refid.length() > 0)          sprop.setReference(refid);
         if (context.size() > 0)          sprop.setSimulationContexts(context);
-        if      ( among.equals("mine") ) sprop.setAuthor(user);
-        else if ( among.equals("his") ) {
-          User him = UserDirectory.selectUser(Integer.valueOf(author));
+        int index = Integer.valueOf(author);
+        if (index > 0) {
+          User him = UserDirectory.selectUser(index);
           sprop.setAuthor(him);
-          if (reparea == Visibility.PRIVATE) sprop.setActor(user);
-        } else {//among.equals("all")
-          KnowledgeElementType type = KnowledgeElement.selectType(Integer.valueOf(typid));
-          sprop.setType(type);
-          if (reparea == Visibility.PRIVATE) {                       // Restriction to studies in which the connected user is involved
-            other = sprop.copy().setActor(user);
-            sprop.setAuthor(user);
-          }
         }
-      }
-      if (other == null) result = Database.selectKnowledgeElementsWhere(sprop);
-      else               result = Database.selectKnowledgeElementsWhere(sprop, other);
+//      Set of the visibility
+        if (visibility.equals("all")) {
+          KnowledgeElement.Properties  other = sprop.copy();
+
+          other.setVisibility(Visibility.PUBLIC);
+          sprop.setVisibility(Visibility.PRIVATE);
+          sprop.setActor(user);
 
+          result = Database.selectKnowledgeElementsWhere(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 = Database.selectKnowledgeElementsWhere(sprop);
+      }
       session.put("search.result", result);     // For redisplaying the page without re-executing the search
       return "refresh";
        }
@@ -113,14 +100,18 @@ public class SearchKnowledgeAction extends SearchBaseAction {
 //  Getters
 //  ==============================================================================================================================
 
+    public String getContextMatch () {
+//  --------------------------------
+      return matcontext;
+    }
+    public String getCriteriaMatch () {
+//  ---------------------------------
+      return matchamong;
+    }
     public List<KnowledgeElementType> getKnowledgeTypes () {
 //  ------------------------------------------------------
       return types;
     }
-    public String getOwner () {
-//  -------------------------
-      return among;
-    }
     public String getReference () {
 //  -----------------------------
       return refid;
@@ -129,9 +120,9 @@ public class SearchKnowledgeAction extends SearchBaseAction {
 //  ------------------------
       return typid;
     }
-    public List<Item> getTabs () {
-//  ----------------------------
-      return area.asList();
+    public String getVisibility () {
+//  ------------------------------
+      return visibility;
     }
     public String getWords () {
 //  -------------------------
@@ -142,9 +133,13 @@ public class SearchKnowledgeAction extends SearchBaseAction {
 //  Setters
 //  ==============================================================================================================================
 
-    public void setOwner (String value) {
-//  -----------------------------------
-      this.among = value;
+    public void setContextMatch (String value) {
+//  ------------------------------------------
+      this.matcontext = value;
+    }
+    public void setCriteriaMatch (String value) {
+//  -------------------------------------------
+      this.matchamong = value;
     }
     public void setReference (String value) {
 //  ---------------------------------------
@@ -154,6 +149,10 @@ public class SearchKnowledgeAction extends SearchBaseAction {
 //  ----------------------------------
       this.typid = value;
     }
+    public void setVisibility (String value) {
+//  ----------------------------------------
+      this.visibility = value;
+    }
     public void setWords (String value) {
 //  -----------------------------------
       this.words = value;
@@ -175,17 +174,17 @@ public class SearchKnowledgeAction extends SearchBaseAction {
       User               user    = getConnectedUser();
       Map<String,Object> filter  = (Map<String, Object>)session.get("knowledge.filter");   // A default filter is supposed being set at start
 
-      area    = (TabBar)filter.get("area");
-      among   = (String)filter.get("owner");
-      author  = (String)filter.get("author");
-      typid   = (String)filter.get("type");
-      refid   = (String)filter.get("reference");
-      words   = (String)filter.get("title");
-      context = (List<SimulationContext>)filter.get("context");
+      visibility = (String)filter.get("visibility");
+      matchamong = (String)filter.get("matchamong");
+      matcontext = (String)filter.get("matcontext");
+      typid      = (String)filter.get("type");
+      author     = (String)filter.get("author");
+      refid      = (String)filter.get("reference");
+      words      = (String)filter.get("title");
+      context    = (List<SimulationContext>)filter.get("context");
 
       if (user == null) {
-       area.disables("private");
-       if (area.getSelection().equals("private")) area.selects("public");
+       visibility = "onlypublic";
       }
     }
 
@@ -195,19 +194,16 @@ public class SearchKnowledgeAction extends SearchBaseAction {
       Map<String,Object> session = getSession();
       Map<String,Object> filter  = (Map<String, Object>)session.get("knowledge.filter");   // A default filter is supposed being set at start
 
-      area = (TabBar)filter.get("area");   // The area being not an input, it is null when submitting the form
-      if (among.equals("ref")) {
-        filter.put("owner", "ref");
-        filter.put("reference", this.refid);
-      } else {
-        filter.put("owner", this.among);
-        filter.put("author", this.author);
-        filter.put("type", this.typid);
-        filter.put("reference", "");
-        filter.put("title", this.words);
-
-        context = (List<SimulationContext>)filter.get("context");  // Only criteria not part of the form
-      }
+      filter.put("visibility", this.visibility);
+      filter.put("matchamong", this.matchamong);
+      filter.put("matcontext", this.matcontext);
+      filter.put("type",   this.typid);
+      filter.put("author", this.author);
+      filter.put("reference", "");
+      filter.put("title", this.words);
+
+      context = (List<SimulationContext>)filter.get("context");  // Only criteria not part of the form
+
 //    Initialization required by all do functions
       types = KnowledgeElement.selectTypesWhere(ProgressState.APPROVED);
        }