(JAL-978) discover JABA1 and JABA2 services and generate GUI elements for each servic...
authorjprocter <jprocter@compbio.dundee.ac.uk>
Thu, 3 Nov 2011 18:11:47 +0000 (18:11 +0000)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Thu, 3 Nov 2011 18:11:47 +0000 (18:11 +0000)
src/jalview/gui/AlignFrame.java
src/jalview/ws/jws2/JabaWsServerQuery.java
src/jalview/ws/jws2/Jws2Discoverer.java

index 99cd936..51a119e 100755 (executable)
@@ -4082,22 +4082,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             }
           }
 
-          // TODO: move into separate menu builder class.
-          if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
-          {
-            Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
-            if (jws2servs != null)
-            {
-              if (jws2servs.hasServices())
-              {
-                jws2servs.attachWSMenuEntry(msawsmenu, me);
-              }
-            }
-          }
+          
           // Add all submenus in the order they should appear on the web services menu
           wsmenu.add(msawsmenu);
           wsmenu.add(secstrmenu);
+          wsmenu.add(new JMenu("Disorder"));
           wsmenu.add(analymenu);
+          
           // No search services yet
           // wsmenu.add(seqsrchmenu);
 
@@ -4120,6 +4111,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                 {
                   webService.add(me.webServiceNoServices);
                 }
+                // TODO: move into separate menu builder class.
+                if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
+                {
+                  Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
+                  if (jws2servs != null)
+                  {
+                    if (jws2servs.hasServices())
+                    {
+                      jws2servs.attachWSMenuEntry(webService, me);
+                    }
+                  }
+                }
+
                 build_urlServiceMenu(me.webService);
                 build_fetchdbmenu(webService);
               } catch (Exception e)
index b956246..61810e8 100644 (file)
 package jalview.ws.jws2;
 
 import jalview.bin.Cache;
+import jalview.ws.jws2.jabaws2.Jws2Instance;
 
-import compbio.data.msa.MsaWS;
+import java.util.HashSet;
+import java.util.Set;
+
+import compbio.data.msa.Category;
+import compbio.data.msa.JABAService;
 import compbio.ws.client.Jws2Client;
 import compbio.ws.client.Services;
 
 /**
  * @author JimP
- *
+ * 
  */
 public class JabaWsServerQuery implements Runnable
 {
 
-  Jws2Discoverer jws2Discoverer=null;
-  String jwsservers=null;
-  boolean quit=false,
-  running=false;
+  Jws2Discoverer jws2Discoverer = null;
+
+  String jwsservers = null;
+
+  boolean quit = false, running = false;
+
   /**
    * @return the running
    */
-  public  boolean isRunning()
+  public boolean isRunning()
   {
     return running;
   }
 
   /**
-   * @param quit the quit to set
+   * @param quit
+   *          the quit to set
    */
   public void setQuit(boolean quit)
   {
@@ -56,52 +64,118 @@ public class JabaWsServerQuery implements Runnable
   public JabaWsServerQuery(Jws2Discoverer jws2Discoverer, String jwsservers)
   {
     this.jws2Discoverer = jws2Discoverer;
-    this.jwsservers=jwsservers;
+    this.jwsservers = jwsservers;
   }
 
-  /* (non-Javadoc)
+  /*
+   * (non-Javadoc)
+   * 
    * @see java.lang.Runnable#run()
    */
   @Override
   public void run()
   {
-    running=true;
-        try
+    running = true;
+    try
     {
       if (Jws2Client.validURL(jwsservers))
       {
-        boolean noservices=true;
+        compbio.data.msa.RegistryWS registry = null;
+        Set svccategories = null;
+        boolean noservices = true;
         // look for services
-        for (Services srv : Services.values())
+        boolean jabasws2 = false;
+        // If we are dealing with a JABAWS2 service, then just go and ask the
+        // JABAWS 2 service registry
+        Set<Services> srv_set = new HashSet<Services>();
+
+        Set<Category> categories = Category.getCategories();
+        String svc_cat;
+
+        try
         {
-          if (quit)
+          // JBPNote: why is RegistryWS in compbio.data.msa ?
+          registry = Jws2Client.connectToRegistry(jwsservers);
+          if (registry != null)
           {
-            running=false;
-            return;
+            // System.err.println("Test Services Output\n"
+            // + registry.testAllServices());
+            // TODO: enumerate services and test those that haven't been tested
+            // in the last n-days/hours/etc.
+
+            jabasws2 = true;
+            srv_set = registry.getSupportedServices();
+            svccategories = registry.getServiceCategories();
+
           }
-          MsaWS service = null;
-          try
+        } catch (Exception ex)
+        {
+          System.err.println("Exception whilst trying to get at registry:");
+          ex.printStackTrace();
+          // if that failed, then we are probably working with a JABAWS1 server.
+          // in that case, look for each service endpoint
+          System.err.println("JWS2 Discoverer: " + jwsservers
+                  + " is a JABAWS1 server. Using hardwired list.");
+          for (Services srv : new Services[]
+          { Services.ClustalWS, Services.MuscleWS, Services.MafftWS,
+              Services.ProbconsWS, Services.TcoffeeWS })
           {
-            service = Jws2Client.connect(jwsservers, srv);
-          } catch (Exception e)
+            srv_set.add(srv);
+          }
+        }
+        for (Category cat : categories)
+        {
+          for (Services srv : cat.getServices())
           {
-            System.err.println("Jws2 Discoverer: Problem on "
-                    + jwsservers + " with service " + srv + ":\n"
-                    + e.getMessage());
-            if (!(e instanceof javax.xml.ws.WebServiceException))
+            if (quit)
             {
-              e.printStackTrace();
+              running = false;
+              return;
             }
-            // For moment, report service as a problem.
-            jws2Discoverer.addInvalidServiceUrl(jwsservers);
-          }
-          ;
-          if (service != null)
-          {
-            noservices=false;
-            jws2Discoverer.addService(jwsservers, srv, service);
+            if (!srv_set.contains(srv))
+            {
+              continue;
+            }
+            JABAService service = null;
+            try
+            {
+              service = Jws2Client.connect(jwsservers, srv);
+            } catch (Exception e)
+            {
+              System.err.println("Jws2 Discoverer: Problem on "
+                      + jwsservers + " with service " + srv + ":\n"
+                      + e.getMessage());
+              if (!(e instanceof javax.xml.ws.WebServiceException))
+              {
+                e.printStackTrace();
+              }
+              // For moment, report service as a problem.
+              jws2Discoverer.addInvalidServiceUrl(jwsservers);
+            }
+            ;
+            if (service != null)
+            {
+              noservices = false;
+              Jws2Instance svc = null;
+              if (registry != null)
+              {
+
+                String description = registry.getServiceDescription(srv);
+
+                svc = new Jws2Instance(jwsservers, srv.toString(),
+                        cat.name, description, service);
+              }
+              if (svc == null)
+              {
+                svc = new Jws2Instance(jwsservers, srv.toString(), cat.name,
+                        "JABAWS 1 Alignment Service", service);
+              }
+              jws2Discoverer.addService(jwsservers, svc);
+            }
+
           }
         }
+
         if (noservices)
         {
           jws2Discoverer.addUrlwithnoservices(jwsservers);
@@ -122,7 +196,7 @@ public class JabaWsServerQuery implements Runnable
       Cache.log.error("Exception when discovering Jws2 services.", e);
       jws2Discoverer.addInvalidServiceUrl(jwsservers);
     }
-    running=false;
+    running = false;
   }
 
 }
index 8907b58..1c912d8 100644 (file)
@@ -205,17 +205,16 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
    * @param srv
    * @param service2
    */
-  synchronized void addService(String jwsservers, Services srv,
-          MsaWS service2)
+  synchronized void addService(String jwsservers, Jws2Instance service)
   {
     if (services == null)
     {
       services = new Vector<Jws2Instance>();
     }
     System.out.println("Discovered service: " + jwsservers + " "
-            + srv.toString());
-    Jws2Instance service = new Jws2Instance(jwsservers, srv.toString(),
-            service2);
+            + service.toString());
+//    Jws2Instance service = new Jws2Instance(jwsservers, srv.toString(),
+//            service2);
 
     services.add(service);
     // retrieve the presets and parameter set and cache now
@@ -227,41 +226,16 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
    * holds list of services.
    */
   protected Vector<Jws2Instance> services;
-
+  /**
+   * attach all available web services to the appropriate submenu in the given JMenu
+   */
   public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame)
   {
     // dynamically regenerate service list.
-    final JMenu jws2al = wsmenu; // new JMenu("JABAWS Alignment");
-    jws2al.addMenuListener(new MenuListener()
-    {
-      // TODO: future: add menu listener to parent menu - so submenus are
-      // populated *before* they are selected.
-      @Override
-      public void menuSelected(MenuEvent e)
-      {
-        populateWSMenuEntry(jws2al, alignFrame);
-      }
-
-      @Override
-      public void menuDeselected(MenuEvent e)
-      {
-        // TODO Auto-generated method stub
-
-      }
-
-      @Override
-      public void menuCanceled(MenuEvent e)
-      {
-        // TODO Auto-generated method stub
-
-      }
-
-    });
-    wsmenu.add(jws2al);
-
+    populateWSMenuEntry(wsmenu, alignFrame, null);
   }
 
-  private void populateWSMenuEntry(JMenu jws2al, final AlignFrame alignFrame)
+  private void populateWSMenuEntry(JMenu jws2al, final AlignFrame alignFrame, String typeFilter)
   {
     if (running || services == null || services.size() == 0)
     {
@@ -305,7 +279,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
       jalview.util.QuickSort.sort(sortbytype, orderedsvcs);
       for (final Jws2Instance service : orderedsvcs)
       {
-        atpoint = jws2al;
+        atpoint = JvSwingUtils.findOrCreateMenu(jws2al,service.action);
         String type = service.serviceType;
         if (byhost)
         {
@@ -357,7 +331,8 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
           // hostLabels.addElement(host + (bytype ?
           // service.serviceType+service.getActionText() : ""));
         }
-        msacl.attachWSMenuEntry(atpoint, service, alignFrame);
+        
+        service.attachWSMenuEntry(atpoint, alignFrame);
         /*
          * JMenuItem sitem = new JMenuItem(service.serviceType);
          * sitem.setToolTipText("Hosted at " + service.hosturl);
@@ -377,6 +352,14 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
 
   public static void main(String[] args)
   {
+    if (args.length>0)
+    {
+      testUrls = new Vector<String>();
+      for (String url:args)
+      {
+        testUrls.add(url);
+      };
+    }
     Thread runner = getDiscoverer().startDiscoverer(
             new PropertyChangeListener()
             {
@@ -450,8 +433,14 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
     }
   }
 
+  private static Vector<String> testUrls=null;
   public static Vector<String> getServiceUrls()
   {
+    if (testUrls!=null)
+    {
+      // return test urls, if there are any, instead of touching cache
+      return testUrls;
+    }
     String surls = Cache.getDefault(JWS2HOSTURLS,
             "http://www.compbio.dundee.ac.uk/jabaws");
     Vector<String> urls = new Vector<String>();
@@ -660,5 +649,4 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
     }
     return null;
   }
-
 }