JAL-3070 discoverers return ServiceWithParameter, now containing logic and call code...
authorJim Procter <jprocter@issues.jalview.org>
Wed, 2 Oct 2019 16:07:53 +0000 (17:07 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Wed, 2 Oct 2019 16:21:29 +0000 (17:21 +0100)
src/jalview/ws/api/ServiceWithParameters.java
src/jalview/ws/jws2/JabaWsParamTest.java
src/jalview/ws/jws2/Jws2Discoverer.java
src/jalview/ws/jws2/MsaWSClient.java
src/jalview/ws/jws2/jabaws2/Jws2Instance.java
src/jalview/ws/slivkaws/SlivkaAnnotationServiceInstance.java
src/jalview/ws/slivkaws/SlivkaMsaServiceInstance.java
test/jalview/ws/gui/Jws2ParamView.java
test/jalview/ws/jabaws/DisorderAnnotExportImport.java
test/jalview/ws/jabaws/RNAStructExportImport.java
test/jalview/ws/jws2/ParameterUtilsTest.java

index d345869..645ef34 100644 (file)
@@ -1,7 +1,13 @@
 package jalview.ws.api;
 
+import jalview.bin.Cache;
+import jalview.gui.AlignFrame;
+import jalview.ws.jws2.MsaWSClient;
+import jalview.ws.jws2.SequenceAnnotationWSClient;
 import jalview.ws.params.ParamManager;
 
+import javax.swing.JMenu;
+
 public abstract class ServiceWithParameters extends UIinfo
 {
 
@@ -79,4 +85,27 @@ public abstract class ServiceWithParameters extends UIinfo
             + getName();
   }
 
+  protected enum ServiceClient
+  {
+    MSAWSCLIENT, SEQUENCEANNOTATIONWSCLIENT;
+  };
+
+  protected ServiceClient style = null;
+
+  public void attachWSMenuEntry(JMenu atpoint, AlignFrame alignFrame)
+  {
+    switch (style)
+    {
+    case MSAWSCLIENT:
+        new MsaWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
+      break;
+    case SEQUENCEANNOTATIONWSCLIENT:
+        new SequenceAnnotationWSClient().attachWSMenuEntry(atpoint, this,
+                alignFrame);
+      break;
+    default:
+      Cache.log.warn("Implementation error ? Service " + getName()
+              + " has Unknown service style " + style);
+    }
+  }
 }
index 8c57529..98282fa 100644 (file)
@@ -2,6 +2,7 @@ package jalview.ws.jws2;
 
 import jalview.gui.WsJobParameters;
 import jalview.util.MessageManager;
+import jalview.ws.api.ServiceWithParameters;
 import jalview.ws.jws2.jabaws2.Jws2Instance;
 
 import java.awt.BorderLayout;
@@ -48,9 +49,10 @@ public class JabaWsParamTest
       return;
     }
     Jws2Instance lastserv = null;
-    for (Jws2Instance service : disc.getServices())
+    for (ServiceWithParameters service : disc.getServices())
     {
-      lastserv = service;
+      // this will fail for non-JABAWS services !
+      lastserv = (Jws2Instance) service;
       if (p >= args.length || service.getName().equalsIgnoreCase(args[p]))
       {
         if (lastserv != null)
index dc90d82..7e1bd81 100644 (file)
@@ -366,8 +366,8 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
     JMenu atpoint;
     List<Jws2Instance> enumerableServices = new ArrayList<>();
     // jws2al.removeAll();
-    Map<String, Jws2Instance> preferredHosts = new HashMap<>();
-    Map<String, List<Jws2Instance>> alternates = new HashMap<>();
+    Map<String, ServiceWithParameters> preferredHosts = new HashMap<>();
+    Map<String, List<ServiceWithParameters>> alternates = new HashMap<>();
     for (Jws2Instance service : services.toArray(new Jws2Instance[0]))
     {
       // TODO: check this behaves with refactored serviceType to getName
@@ -381,7 +381,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
       {
         if (!preferredHosts.containsKey(service.getName()))
         {
-          Jws2Instance preferredInstance = getPreferredServiceFor(
+          ServiceWithParameters preferredInstance = getPreferredServiceFor(
                   alignFrame, service.getName());
           if (preferredInstance != null)
           {
@@ -392,7 +392,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
             preferredHosts.put(service.getName(), service);
           }
         }
-        List<Jws2Instance> ph = alternates.get(service.getName());
+        List<ServiceWithParameters> ph = alternates.get(service.getName());
         if (preferredHosts.get(service.getName()) != service)
         {
           if (ph == null)
@@ -409,7 +409,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
     // create GUI element for classic services
     addEnumeratedServices(jws2al, alignFrame, enumerableServices);
     // and the instantaneous services
-    for (final Jws2Instance service : preferredHosts.values())
+    for (final ServiceWithParameters service : preferredHosts.values())
     {
       atpoint = JvSwingUtils.findOrCreateMenu(jws2al,
               service.getServiceType());
@@ -737,7 +737,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
     return urls;
   }
 
-  public Vector<Jws2Instance> getServices()
+  public Vector<ServiceWithParameters> getServices()
   {
     return (services == null) ? new Vector<>()
             : new Vector<>(services);
@@ -956,7 +956,9 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
     HashSet<String> urls = new HashSet<>();
     urls.addAll(Arrays.asList(serviceURLs));
     ServiceWithParameters match = null;
-    if (services != null)
+    List<ServiceWithParameters> ourServices = getServices();
+
+    if (ourServices != null)
     {
       for (ServiceWithParameters svc : services)
       {
@@ -982,7 +984,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
     return match;
   }
 
-  Map<String, Map<String, String>> preferredServiceMap = new HashMap<>();;
+  Map<String, Map<String, String>> preferredServiceMap = new HashMap<>();
 
   /**
    * get current preferred endpoint of the given Jabaws service, or global
@@ -995,7 +997,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
    * @return null if no service of this type is available, the preferred service
    *         for the serviceType and af if specified and if defined.
    */
-  public Jws2Instance getPreferredServiceFor(AlignFrame af,
+  public ServiceWithParameters getPreferredServiceFor(AlignFrame af,
           String serviceName)
   {
     String serviceurl = null;
index 3f0cc8e..8eb49da 100644 (file)
@@ -32,7 +32,6 @@ import jalview.ws.api.JalviewServiceEndpointProviderI;
 import jalview.ws.api.MultipleSequenceAlignmentI;
 import jalview.ws.api.ServiceWithParameters;
 import jalview.ws.gui.MsaWSThread;
-import jalview.ws.jws2.jabaws2.Jws2Instance;
 import jalview.ws.params.ArgumentI;
 import jalview.ws.params.WsParamSetI;
 
@@ -237,8 +236,8 @@ public class MsaWSClient extends Jws2Client implements WSMenuEntryProviderI
   public void attachWSMenuEntry(JMenu rmsawsmenu,
           final ServiceWithParameters service, final AlignFrame alignFrame)
   {
-    if (service instanceof Jws2Instance
-        && Jws2ClientFactory.registerAAConWSInstance(rmsawsmenu, (Jws2Instance) service, alignFrame))
+    if (Jws2ClientFactory.registerAAConWSInstance(rmsawsmenu,
+                    service, alignFrame))
     {
       // Alignment dependent analysis calculation WS gui
       return;
index 9f2d4ae..f01d872 100644 (file)
  */
 package jalview.ws.jws2.jabaws2;
 
-import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
 import jalview.util.MessageManager;
 import jalview.ws.api.JalviewServiceEndpointProviderI;
 import jalview.ws.api.ServiceWithParameters;
 import jalview.ws.jws2.JabaParamStore;
-import jalview.ws.jws2.MsaWSClient;
-import jalview.ws.jws2.SequenceAnnotationWSClient;
 import jalview.ws.params.ParamDatastoreI;
 import jalview.ws.params.ParamManager;
 
 import java.io.Closeable;
 import java.net.URL;
 
-import javax.swing.JMenu;
-
 import compbio.data.msa.JABAService;
 import compbio.data.msa.MsaWS;
 import compbio.data.msa.SequenceAnnotation;
@@ -67,6 +62,15 @@ public class Jws2Instance extends ServiceWithParameters
   {
     super(action, action, serviceType, description, hosturl);
     this.service = service;
+    if (service instanceof MsaWS<?>)
+    {
+      style = ServiceClient.MSAWSCLIENT;
+    }
+    else if (service instanceof SequenceAnnotation<?>)
+    {
+      style = ServiceClient.SEQUENCEANNOTATIONWSCLIENT;
+    }
+
     int p = description.indexOf("MORE INFORMATION:");
     if (p > -1)
     {
@@ -205,19 +209,6 @@ public class Jws2Instance extends ServiceWithParameters
     return hasParams;
   }
 
-  public void attachWSMenuEntry(JMenu atpoint, AlignFrame alignFrame)
-  {
-    if (service instanceof MsaWS<?>)
-    {
-      new MsaWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
-    }
-    else if (service instanceof SequenceAnnotation<?>)
-    {
-      new SequenceAnnotationWSClient().attachWSMenuEntry(atpoint, this,
-              alignFrame);
-    }
-  }
-
   /**
    * initialise a parameter store for this service
    * 
index 80e44ec..a0f17b7 100644 (file)
@@ -49,6 +49,7 @@ public class SlivkaAnnotationServiceInstance extends SlivkaWSInstance implements
               MessageManager.getString("label.aacon_settings"),
               MessageManager.getString("tooltip.aacon_settings")));
     }
+    style = ServiceClient.SEQUENCEANNOTATIONWSCLIENT;
   }
 
   @Override
index 726b556..db1577e 100644 (file)
@@ -29,6 +29,7 @@ public class SlivkaMsaServiceInstance extends SlivkaWSInstance implements Multip
 {
   SlivkaMsaServiceInstance(SlivkaClient client, SlivkaService service) {
     super(client, service, "Alignment");
+    style = ServiceClient.MSAWSCLIENT;
   }
 
   @Override
index 428f263..ec9d2be 100644 (file)
@@ -24,6 +24,7 @@ import jalview.bin.Cache;
 import jalview.gui.JvOptionPane;
 import jalview.gui.WsJobParameters;
 import jalview.util.MessageManager;
+import jalview.ws.api.ServiceWithParameters;
 import jalview.ws.jabaws.JalviewJabawsTestUtils;
 import jalview.ws.jws2.JabaPreset;
 import jalview.ws.jws2.Jws2Discoverer;
@@ -90,8 +91,10 @@ public class Jws2ParamView
   public void testJws2Gui()
   {
     Iterator<String> presetEnum = presetTests.iterator();
-    for (Jws2Instance service : disc.getServices())
+    for (ServiceWithParameters _service : disc.getServices())
     {
+      // This will fail for non-jabaws services
+      Jws2Instance service = (Jws2Instance) _service;
       if (serviceTests.size() == 0
               || serviceTests.contains(service.getName().toLowerCase()))
       {
index de72020..025c913 100644 (file)
@@ -32,9 +32,9 @@ import jalview.io.DataSourceType;
 import jalview.io.FileFormat;
 import jalview.io.FormatAdapter;
 import jalview.io.StockholmFileTest;
-import jalview.ws.jws2.SeqAnnotationServiceCalcWorker;
+import jalview.ws.api.ServiceWithParameters;
 import jalview.ws.jws2.Jws2Discoverer;
-import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.jws2.SeqAnnotationServiceCalcWorker;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -63,7 +63,7 @@ public class DisorderAnnotExportImport
 
   public static Jws2Discoverer disc;
 
-  public static List<Jws2Instance> iupreds;
+  public static List<ServiceWithParameters> iupreds;
 
   jalview.ws.jws2.SeqAnnotationServiceCalcWorker disorderClient;
 
@@ -83,7 +83,7 @@ public class DisorderAnnotExportImport
     }
 
     iupreds = new ArrayList<>();
-    for (Jws2Instance svc : disc.getServices())
+    for (ServiceWithParameters svc : disc.getServices())
     {
       if (svc.getNameURI().toLowerCase().contains("iupredws"))
       {
index 25d015a..292a48a 100644 (file)
@@ -33,9 +33,10 @@ import jalview.io.FileFormat;
 import jalview.io.FormatAdapter;
 import jalview.io.StockholmFileTest;
 import jalview.project.Jalview2XML;
-import jalview.ws.jws2.SeqAnnotationServiceCalcWorker;
+import jalview.ws.api.ServiceWithParameters;
 import jalview.ws.jws2.JabaParamStore;
 import jalview.ws.jws2.Jws2Discoverer;
+import jalview.ws.jws2.SeqAnnotationServiceCalcWorker;
 import jalview.ws.jws2.SequenceAnnotationWSClient;
 import jalview.ws.jws2.jabaws2.Jws2Instance;
 import jalview.ws.params.AutoCalcSetting;
@@ -96,12 +97,12 @@ public class RNAStructExportImport
       Thread.sleep(100);
     }
 
-    for (Jws2Instance svc : disc.getServices())
+    for (ServiceWithParameters svc : disc.getServices())
     {
 
       if (svc.getNameURI().toLowerCase().contains("rnaalifoldws"))
       {
-        rnaalifoldws = svc;
+        rnaalifoldws = (Jws2Instance) svc;
       }
     }
 
index 66ce169..ab245c9 100644 (file)
@@ -26,6 +26,7 @@ import static org.testng.AssertJUnit.assertTrue;
 
 import jalview.bin.Cache;
 import jalview.gui.JvOptionPane;
+import jalview.ws.api.ServiceWithParameters;
 import jalview.ws.api.UIinfo;
 import jalview.ws.jabaws.JalviewJabawsTestUtils;
 import jalview.ws.jws2.jabaws2.Jws2Instance;
@@ -78,10 +79,11 @@ public class ParameterUtilsTest
   @Test(groups = { "Network" })
   public void testWriteParameterSet() throws WrongParameterException
   {
-    for (Jws2Instance service : disc.getServices())
+    for (ServiceWithParameters _service : disc.getServices())
     {
-      if (isForTesting(service))
+      if (isForTesting(_service))
       {
+        Jws2Instance service = (Jws2Instance) _service;
 
         List<Preset> prl = null;
         PresetManager prman = service.getPresets();
@@ -138,10 +140,11 @@ public class ParameterUtilsTest
   @Test(groups = { "Network" })
   public void testCopyOption()
   {
-    for (Jws2Instance service : disc.getServices())
+    for (ServiceWithParameters _service : disc.getServices())
     {
-      if (isForTesting(service))
+      if (isForTesting(_service))
       {
+        Jws2Instance service = (Jws2Instance) _service;
         List<Option<?>> options = service.getRunnerConfig().getOptions();
         for (Option<?> o : options)
         {
@@ -162,10 +165,11 @@ public class ParameterUtilsTest
   @Test(groups = { "Network" })
   public void testCopyParameter()
   {
-    for (Jws2Instance service : disc.getServices())
+    for (ServiceWithParameters _service : disc.getServices())
     {
-      if (isForTesting(service))
+      if (isForTesting(_service))
       {
+        Jws2Instance service = (Jws2Instance) _service;
         List<Parameter> parameters = service.getRunnerConfig()
                 .getParameters();
         for (Parameter o : parameters)