From 48697417aee5316f9ca530d191b8ace5af961d80 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 2 Oct 2019 17:07:53 +0100 Subject: [PATCH] JAL-3070 discoverers return ServiceWithParameter, now containing logic and call code for MsaWSClient or SequenceAnnotationWSClient.attachWSMenuEntry --- src/jalview/ws/api/ServiceWithParameters.java | 29 ++++++++++++++++++++ src/jalview/ws/jws2/JabaWsParamTest.java | 6 ++-- src/jalview/ws/jws2/Jws2Discoverer.java | 20 ++++++++------ src/jalview/ws/jws2/MsaWSClient.java | 5 ++-- src/jalview/ws/jws2/jabaws2/Jws2Instance.java | 27 ++++++------------ .../slivkaws/SlivkaAnnotationServiceInstance.java | 1 + .../ws/slivkaws/SlivkaMsaServiceInstance.java | 1 + test/jalview/ws/gui/Jws2ParamView.java | 5 +++- .../ws/jabaws/DisorderAnnotExportImport.java | 8 +++--- test/jalview/ws/jabaws/RNAStructExportImport.java | 7 +++-- test/jalview/ws/jws2/ParameterUtilsTest.java | 16 +++++++---- 11 files changed, 79 insertions(+), 46 deletions(-) diff --git a/src/jalview/ws/api/ServiceWithParameters.java b/src/jalview/ws/api/ServiceWithParameters.java index d345869..645ef34 100644 --- a/src/jalview/ws/api/ServiceWithParameters.java +++ b/src/jalview/ws/api/ServiceWithParameters.java @@ -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); + } + } } diff --git a/src/jalview/ws/jws2/JabaWsParamTest.java b/src/jalview/ws/jws2/JabaWsParamTest.java index 8c57529..98282fa 100644 --- a/src/jalview/ws/jws2/JabaWsParamTest.java +++ b/src/jalview/ws/jws2/JabaWsParamTest.java @@ -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) diff --git a/src/jalview/ws/jws2/Jws2Discoverer.java b/src/jalview/ws/jws2/Jws2Discoverer.java index dc90d82..7e1bd81 100644 --- a/src/jalview/ws/jws2/Jws2Discoverer.java +++ b/src/jalview/ws/jws2/Jws2Discoverer.java @@ -366,8 +366,8 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI JMenu atpoint; List enumerableServices = new ArrayList<>(); // jws2al.removeAll(); - Map preferredHosts = new HashMap<>(); - Map> alternates = new HashMap<>(); + Map preferredHosts = new HashMap<>(); + Map> 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 ph = alternates.get(service.getName()); + List 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 getServices() + public Vector getServices() { return (services == null) ? new Vector<>() : new Vector<>(services); @@ -956,7 +956,9 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI HashSet urls = new HashSet<>(); urls.addAll(Arrays.asList(serviceURLs)); ServiceWithParameters match = null; - if (services != null) + List ourServices = getServices(); + + if (ourServices != null) { for (ServiceWithParameters svc : services) { @@ -982,7 +984,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI return match; } - Map> preferredServiceMap = new HashMap<>();; + Map> 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; diff --git a/src/jalview/ws/jws2/MsaWSClient.java b/src/jalview/ws/jws2/MsaWSClient.java index 3f0cc8e..8eb49da 100644 --- a/src/jalview/ws/jws2/MsaWSClient.java +++ b/src/jalview/ws/jws2/MsaWSClient.java @@ -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; diff --git a/src/jalview/ws/jws2/jabaws2/Jws2Instance.java b/src/jalview/ws/jws2/jabaws2/Jws2Instance.java index 9f2d4ae..f01d872 100644 --- a/src/jalview/ws/jws2/jabaws2/Jws2Instance.java +++ b/src/jalview/ws/jws2/jabaws2/Jws2Instance.java @@ -20,22 +20,17 @@ */ 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 * diff --git a/src/jalview/ws/slivkaws/SlivkaAnnotationServiceInstance.java b/src/jalview/ws/slivkaws/SlivkaAnnotationServiceInstance.java index 80e44ec..a0f17b7 100644 --- a/src/jalview/ws/slivkaws/SlivkaAnnotationServiceInstance.java +++ b/src/jalview/ws/slivkaws/SlivkaAnnotationServiceInstance.java @@ -49,6 +49,7 @@ public class SlivkaAnnotationServiceInstance extends SlivkaWSInstance implements MessageManager.getString("label.aacon_settings"), MessageManager.getString("tooltip.aacon_settings"))); } + style = ServiceClient.SEQUENCEANNOTATIONWSCLIENT; } @Override diff --git a/src/jalview/ws/slivkaws/SlivkaMsaServiceInstance.java b/src/jalview/ws/slivkaws/SlivkaMsaServiceInstance.java index 726b556..db1577e 100644 --- a/src/jalview/ws/slivkaws/SlivkaMsaServiceInstance.java +++ b/src/jalview/ws/slivkaws/SlivkaMsaServiceInstance.java @@ -29,6 +29,7 @@ public class SlivkaMsaServiceInstance extends SlivkaWSInstance implements Multip { SlivkaMsaServiceInstance(SlivkaClient client, SlivkaService service) { super(client, service, "Alignment"); + style = ServiceClient.MSAWSCLIENT; } @Override diff --git a/test/jalview/ws/gui/Jws2ParamView.java b/test/jalview/ws/gui/Jws2ParamView.java index 428f263..ec9d2be 100644 --- a/test/jalview/ws/gui/Jws2ParamView.java +++ b/test/jalview/ws/gui/Jws2ParamView.java @@ -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 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())) { diff --git a/test/jalview/ws/jabaws/DisorderAnnotExportImport.java b/test/jalview/ws/jabaws/DisorderAnnotExportImport.java index de72020..025c913 100644 --- a/test/jalview/ws/jabaws/DisorderAnnotExportImport.java +++ b/test/jalview/ws/jabaws/DisorderAnnotExportImport.java @@ -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 iupreds; + public static List 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")) { diff --git a/test/jalview/ws/jabaws/RNAStructExportImport.java b/test/jalview/ws/jabaws/RNAStructExportImport.java index 25d015a..292a48a 100644 --- a/test/jalview/ws/jabaws/RNAStructExportImport.java +++ b/test/jalview/ws/jabaws/RNAStructExportImport.java @@ -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; } } diff --git a/test/jalview/ws/jws2/ParameterUtilsTest.java b/test/jalview/ws/jws2/ParameterUtilsTest.java index 66ce169..ab245c9 100644 --- a/test/jalview/ws/jws2/ParameterUtilsTest.java +++ b/test/jalview/ws/jws2/ParameterUtilsTest.java @@ -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 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> 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 parameters = service.getRunnerConfig() .getParameters(); for (Parameter o : parameters) -- 1.7.10.2