Revision: 14631
          http://gate.svn.sourceforge.net/gate/?rev=14631&view=rev
Author:   valyt
Date:     2011-12-01 17:13:01 +0000 (Thu, 01 Dec 2011)
Log Message:
-----------
More work on the new GWT: we can now post queries.

Modified Paths:
--------------
    
mimir/trunk/mimir-web/grails-app/controllers/gate/mimir/web/SearchController.groovy
    
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/SearchService.groovy
    mimir/trunk/mimir-web/grails-app/views/search/index.gsp
    mimir/trunk/mimir-web/src/gwt/gate/mimir/web/client/UI.java

Added Paths:
-----------
    
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/GwtRpcService.groovy
    mimir/trunk/mimir-web/src/java/gate/mimir/web/
    mimir/trunk/mimir-web/src/java/gate/mimir/web/client/
    mimir/trunk/mimir-web/src/java/gate/mimir/web/client/GwtRpcException.java
    mimir/trunk/mimir-web/src/java/gate/mimir/web/client/GwtRpcService.java
    mimir/trunk/mimir-web/src/java/gate/mimir/web/client/GwtRpcServiceAsync.java

Modified: 
mimir/trunk/mimir-web/grails-app/controllers/gate/mimir/web/SearchController.groovy
===================================================================
--- 
mimir/trunk/mimir-web/grails-app/controllers/gate/mimir/web/SearchController.groovy
 2011-12-01 17:12:19 UTC (rev 14630)
+++ 
mimir/trunk/mimir-web/grails-app/controllers/gate/mimir/web/SearchController.groovy
 2011-12-01 17:13:01 UTC (rev 14631)
@@ -101,8 +101,16 @@
     return [index:request.theIndex]
   }
   
+  /**
+  * Action that forwards to the real GWT RPC controller.
+  */
+ def gwtRpc = {
+   forward(controller:'gwt', action:'index', 
+     params:[module:'gate.mimir.web.client.UI'])
+ }
   
   
+  
 // ==================== XML-over-HTTP Interface ===============================
   
   def info = {

Added: 
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/GwtRpcService.groovy
===================================================================
--- 
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/GwtRpcService.groovy   
                            (rev 0)
+++ 
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/GwtRpcService.groovy   
    2011-12-01 17:13:01 UTC (rev 14631)
@@ -0,0 +1,99 @@
+package gate.mimir.web
+
+import gate.mimir.gus.client.SearchException;
+import grails.converters.JSON;
+
+import java.util.Set;
+
+import org.springframework.beans.factory.DisposableBean;
+import org.springframework.beans.factory.InitializingBean;
+
+import gate.mimir.web.client.GwtRpcException
+
+class GwtRpcService implements InitializingBean, DisposableBean {
+
+  static transactional = false
+
+  /**
+   * The SearchService that does the actual work (autowired by Grails)
+   */
+  def searchService
+
+  // scope the service to the web session, so one instance per user
+  static scope = "session"
+
+  // expose for GWT RPC
+  static expose = ["gwt:gate.mimir.web.client"]
+
+  /**
+   * Set of in-progress queries for this session. The values are qeury IDs
+   * obtained from the search service
+   */
+  def Set<String> runningQueries = new HashSet<String>()
+
+  public void afterPropertiesSet() {
+  }
+
+  /**
+   * Close the executors and free any running queries
+   */
+  public void destroy() {
+    runningQueries.each(this.&releaseQuery)
+  }
+
+  /**
+   * Post a query
+   */
+  String search(String indexId, String query) {
+    Index.withTransaction {
+      try {
+        def index = Index.findByIndexId(indexId)
+        if(!index) {
+          throw new GwtRpcException("Invalid index ID ${indexId}")
+        }
+        else if(index.state != Index.SEARCHING) {
+          throw new GwtRpcException("Index ${indexId} is not open for 
searching")
+        }
+        else {
+          String queryId = searchService.postQuery(index, query)
+          runningQueries.add(queryId)
+          return [id:queryId] as JSON
+        }
+      } catch(GwtRpcException e) {
+        log.warn("Exception starting search", e)
+        throw e
+      } catch(Exception e) {
+        log.warn("Exception starting search", e)
+        throw new GwtRpcException("Could not start search. Error 
was:\n${e.message}");
+      }
+    }
+  }
+
+  /**
+   * Release the resources associated with a given query.  Does nothing
+   * if the given ID does not correspond to a running query.
+   */
+  void releaseQuery(String id) {
+    //check if it's one of our queries
+    if(runningQueries.remove(id)){
+      searchService.closeQueryRunner(id)
+    }
+  }
+
+  /**
+  * Obtains the types of annotation known to the index, and their features.
+   * This method supports auto-completion in the GWT UI.
+  */
+  String[][] getAnnotationsConfig(String indexId){
+    Index.withTransaction {
+      Index index = Index.findByIndexId(indexId)
+      if(index) {
+        return index.annotationsConfig()
+      }
+      else {
+        return ([] as String[][])
+      }
+    }
+  }
+
+}


Property changes on: 
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/GwtRpcService.groovy
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Modified: 
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/SearchService.groovy
===================================================================
--- 
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/SearchService.groovy   
    2011-12-01 17:12:19 UTC (rev 14630)
+++ 
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/SearchService.groovy   
    2011-12-01 17:13:01 UTC (rev 14631)
@@ -60,8 +60,6 @@
     if(aRunner){
       String runnerId = UUID.randomUUID()
       queryRunners.put(runnerId, aRunner)
-      //as a courtesy to the user, we'll start the search for them
-      aRunner.getMoreHits()
       return runnerId
     }
     throw new RuntimeException("Could not start query")

Modified: mimir/trunk/mimir-web/grails-app/views/search/index.gsp
===================================================================
--- mimir/trunk/mimir-web/grails-app/views/search/index.gsp     2011-12-01 
17:12:19 UTC (rev 14630)
+++ mimir/trunk/mimir-web/grails-app/views/search/index.gsp     2011-12-01 
17:13:01 UTC (rev 14631)
@@ -3,7 +3,7 @@
   <!-- Integrate with Sitemesh layouts           -->
   <meta name="layout" content="mimir" />
 
-  <title>M&icute;mir Index ${index?.name}</title>
+  <title>M&iacute;mir Index ${index?.name}</title>
 
   <!-- Pass some variable to the GWT code -->
   <g:javascript>

Modified: mimir/trunk/mimir-web/src/gwt/gate/mimir/web/client/UI.java
===================================================================
--- mimir/trunk/mimir-web/src/gwt/gate/mimir/web/client/UI.java 2011-12-01 
17:12:19 UTC (rev 14630)
+++ mimir/trunk/mimir-web/src/gwt/gate/mimir/web/client/UI.java 2011-12-01 
17:13:01 UTC (rev 14631)
@@ -14,12 +14,18 @@
 
 package gate.mimir.web.client;
 
+import gate.mimir.gus.client.GusService;
+import gate.mimir.gus.client.GusServiceAsync;
+
 import com.google.gwt.core.client.EntryPoint;
+import com.google.gwt.core.client.GWT;
 import com.google.gwt.dom.client.Document;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
 import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.rpc.ServiceDefTarget;
 import com.google.gwt.user.client.ui.Button;
 import com.google.gwt.user.client.ui.HTMLPanel;
 import com.google.gwt.user.client.ui.Panel;
@@ -30,15 +36,27 @@
  */
 public class UI implements EntryPoint {
   
+  
+  private GwtRpcServiceAsync gwtRpcService;
+  
   protected TextArea searchBox;
   
   protected Button searchButton;
   
+  protected String queryId;
   
   /**
    * This is the entry point method.
    */
   public void onModuleLoad() {
+    // connect to the server RPC endpoint
+    gwtRpcService = (GwtRpcServiceAsync) GWT.create(GwtRpcService.class);
+    ServiceDefTarget endpoint = (ServiceDefTarget) gwtRpcService;
+    String rpcUrl = GWT.getHostPageBaseURL() + "gwtRpc";
+    endpoint.setServiceEntryPoint(rpcUrl);
+    
+    queryId = null;
+    
     initGui();
     initListeners();
   }
@@ -66,6 +84,26 @@
   }
   
   protected void startSearch() {
-    Window.alert("Search pressed");
+    String query = searchBox.getText();
+    gwtRpcService.search(getIndexId(), query, new AsyncCallback<String>() {
+      @Override
+      public void onFailure(Throwable caught) {
+        // TODO Auto-generated method stub
+        
+      }
+      @Override
+      public void onSuccess(String result) {
+        queryId = result;
+        Window.alert("Search started");    
+      }
+    });
   }
+  
+  private native String getIndexId() /*-{
+    return $wnd.indexId;
+  }-*/;
+
+  private native String getUriIsLink() /*-{
+    return $wnd.uriIsLink;
+  }-*/;
 }

Added: mimir/trunk/mimir-web/src/java/gate/mimir/web/client/GwtRpcException.java
===================================================================
--- mimir/trunk/mimir-web/src/java/gate/mimir/web/client/GwtRpcException.java   
                        (rev 0)
+++ mimir/trunk/mimir-web/src/java/gate/mimir/web/client/GwtRpcException.java   
2011-12-01 17:13:01 UTC (rev 14631)
@@ -0,0 +1,15 @@
+package gate.mimir.web.client;
+
+import com.google.gwt.user.client.rpc.IsSerializable;
+
+public class GwtRpcException extends Exception implements IsSerializable {
+  private static final long serialVersionUID = 1L;
+
+  public GwtRpcException() {
+    super();
+  }
+
+  public GwtRpcException(String message) {
+    super(message);
+  }
+}


Property changes on: 
mimir/trunk/mimir-web/src/java/gate/mimir/web/client/GwtRpcException.java
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Added: mimir/trunk/mimir-web/src/java/gate/mimir/web/client/GwtRpcService.java
===================================================================
--- mimir/trunk/mimir-web/src/java/gate/mimir/web/client/GwtRpcService.java     
                        (rev 0)
+++ mimir/trunk/mimir-web/src/java/gate/mimir/web/client/GwtRpcService.java     
2011-12-01 17:13:01 UTC (rev 14631)
@@ -0,0 +1,9 @@
+package gate.mimir.web.client;
+
+
+import com.google.gwt.user.client.rpc.RemoteService;
+
+public interface GwtRpcService extends RemoteService {
+    String search(java.lang.String indexId, java.lang.String query) throws 
GwtRpcException;
+    void releaseQuery(java.lang.String queryId);
+}


Property changes on: 
mimir/trunk/mimir-web/src/java/gate/mimir/web/client/GwtRpcService.java
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Added: 
mimir/trunk/mimir-web/src/java/gate/mimir/web/client/GwtRpcServiceAsync.java
===================================================================
--- 
mimir/trunk/mimir-web/src/java/gate/mimir/web/client/GwtRpcServiceAsync.java    
                            (rev 0)
+++ 
mimir/trunk/mimir-web/src/java/gate/mimir/web/client/GwtRpcServiceAsync.java    
    2011-12-01 17:13:01 UTC (rev 14631)
@@ -0,0 +1,8 @@
+package gate.mimir.web.client;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+public interface GwtRpcServiceAsync {
+    void search(java.lang.String indexId, java.lang.String query, 
AsyncCallback<String> callback);
+    void releaseQuery(java.lang.String queryId, AsyncCallback callback);
+}


Property changes on: 
mimir/trunk/mimir-web/src/java/gate/mimir/web/client/GwtRpcServiceAsync.java
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to