From: Jim Procter Date: Wed, 2 Oct 2019 14:14:38 +0000 (+0100) Subject: JAL-3070 pull up generic methods for an automatic alignment analysis web service... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=daff9052085d427cd0856ee07c4057d01f5f3bf4;p=jalview.git JAL-3070 pull up generic methods for an automatic alignment analysis web service calculation --- diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index aaf8519..d5f6a5d 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -2446,7 +2446,7 @@ public class Jalview2XML argList = parmSet.getArguments(); parmSet = null; } - AAConSettings settings = new AAConSettings( + AutoCalcSetting settings = new AAConSettings( calcIdParam.isAutoUpdate(), service, parmSet, argList); av.setCalcIdSettingsFor(calcIdParam.getCalcId(), settings, calcIdParam.isNeedsUpdate()); diff --git a/src/jalview/ws/jws2/Jws2ClientFactory.java b/src/jalview/ws/jws2/Jws2ClientFactory.java index 6a177dd..2a38b85 100644 --- a/src/jalview/ws/jws2/Jws2ClientFactory.java +++ b/src/jalview/ws/jws2/Jws2ClientFactory.java @@ -5,8 +5,9 @@ import jalview.bin.Cache; import jalview.gui.AlignFrame; import jalview.gui.JvSwingUtils; import jalview.util.MessageManager; +import jalview.ws.api.ServiceWithParameters; import jalview.ws.jws2.dm.AAConSettings; -import jalview.ws.jws2.jabaws2.Jws2Instance; +import jalview.ws.params.AutoCalcSetting; import jalview.ws.uimodel.AlignAnalysisUIText; import java.awt.event.ActionEvent; @@ -22,7 +23,7 @@ import javax.swing.event.MenuListener; public class Jws2ClientFactory { static boolean registerAAConWSInstance(final JMenu wsmenu, - final Jws2Instance service, final AlignFrame alignFrame) + final ServiceWithParameters service, final AlignFrame alignFrame) { final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null // ; // @@ -183,7 +184,7 @@ public class Jws2ClientFactory * AACon server to use What parameters to use */ // could actually do a class search for this too - AAConSettings fave = (AAConSettings) alignFrame.getViewport() + AutoCalcSetting fave = alignFrame.getViewport() .getCalcIdSettingsFor(aaui.getCalcId()); if (fave == null) { @@ -201,13 +202,13 @@ public class Jws2ClientFactory private static void buildCurrentAAConWorkerFor( final AlignAnalysisUIText aaui, AlignFrame alignFrame, - Jws2Instance service) + ServiceWithParameters service) { /* * preferred settings Whether AACon is automatically recalculated Which * AACon server to use What parameters to use */ - AAConSettings fave = (AAConSettings) alignFrame.getViewport() + AutoCalcSetting fave = alignFrame.getViewport() .getCalcIdSettingsFor(aaui.getCalcId()); if (fave == null) { @@ -226,14 +227,14 @@ public class Jws2ClientFactory new SequenceAnnotationWSClient(fave, alignFrame, false); } - private static AAConSettings createDefaultAAConSettings( + private static AutoCalcSetting createDefaultAAConSettings( AlignAnalysisUIText aaui) { return createDefaultAAConSettings(aaui, null); } - private static AAConSettings createDefaultAAConSettings( - AlignAnalysisUIText aaui, Jws2Instance service) + private static AutoCalcSetting createDefaultAAConSettings( + AlignAnalysisUIText aaui, ServiceWithParameters service) { if (service != null) { diff --git a/src/jalview/ws/jws2/SequenceAnnotationWSClient.java b/src/jalview/ws/jws2/SequenceAnnotationWSClient.java index a2038f0..501e93d 100644 --- a/src/jalview/ws/jws2/SequenceAnnotationWSClient.java +++ b/src/jalview/ws/jws2/SequenceAnnotationWSClient.java @@ -26,8 +26,7 @@ import jalview.gui.Desktop; import jalview.gui.JvSwingUtils; import jalview.util.MessageManager; import jalview.ws.api.ServiceWithParameters; -import jalview.ws.jws2.dm.AAConSettings; -import jalview.ws.jws2.jabaws2.Jws2Instance; +import jalview.ws.params.AutoCalcSetting; import jalview.ws.params.WsParamSetI; import jalview.ws.uimodel.AlignAnalysisUIText; @@ -153,7 +152,7 @@ public class SequenceAnnotationWSClient extends Jws2Client } } - public SequenceAnnotationWSClient(AAConSettings fave, + public SequenceAnnotationWSClient(AutoCalcSetting fave, AlignFrame alignFrame, boolean b) { super(alignFrame, fave.getPreset(), fave.getArgumentSet()); @@ -172,8 +171,8 @@ public class SequenceAnnotationWSClient extends Jws2Client final ServiceWithParameters service, final AlignFrame alignFrame) { - if (service instanceof Jws2Instance - && Jws2ClientFactory.registerAAConWSInstance(wsmenu, (Jws2Instance) service, alignFrame)) + if (Jws2ClientFactory.registerAAConWSInstance(wsmenu, + service, alignFrame)) { // Alignment dependent analysis calculation WS gui return; diff --git a/src/jalview/ws/jws2/dm/AAConSettings.java b/src/jalview/ws/jws2/dm/AAConSettings.java index 997913e..fa56874 100644 --- a/src/jalview/ws/jws2/dm/AAConSettings.java +++ b/src/jalview/ws/jws2/dm/AAConSettings.java @@ -20,19 +20,14 @@ */ package jalview.ws.jws2.dm; -import jalview.util.MessageManager; import jalview.ws.api.ServiceWithParameters; import jalview.ws.jws2.JabaParamStore; -import jalview.ws.jws2.JabaPreset; import jalview.ws.jws2.ParameterUtils; -import jalview.ws.jws2.jabaws2.Jws2Instance; import jalview.ws.params.ArgumentI; import jalview.ws.params.WsParamSetI; -import java.util.ArrayList; import java.util.List; -import compbio.metadata.Argument; import compbio.metadata.Option; /** @@ -43,74 +38,10 @@ import compbio.metadata.Option; */ public class AAConSettings extends jalview.ws.params.AutoCalcSetting { - ServiceWithParameters service; - public AAConSettings(boolean autoUpdate, ServiceWithParameters service2, WsParamSetI preset, List jobArgset) { - super(preset, jobArgset, autoUpdate); - this.service = service2; - } - - public ServiceWithParameters getService() - { - return service; - } - - public void setService(Jws2Instance service) - { - this.service = service; - if (preset != null) - { - // migrate preset to new service - for (String url : preset.getApplicableUrls()) - { - if (url.equals(service.getUri())) - { - return; - } - } - WsParamSetI pr = service.getParamStore().getPreset(preset.getName()); - if (pr instanceof JabaPreset && preset instanceof JabaPreset) - { - // easy - Presets are identical (we assume) - preset = pr; - return; - } - List oldargs = new ArrayList<>(), - newargs = new ArrayList<>(); - oldargs.addAll(preset.getArguments()); - // need to compare parameters - for (ArgumentI newparg : pr.getArguments()) - { - if (!oldargs.remove(newparg)) - { - newargs.add(newparg); - } - } - if (oldargs.size() == 0 && newargs.size() == 0) - { - // exact match. - preset = pr; - return; - } - // Try even harder to migrate arguments. - throw new Error(MessageManager - .getString("error.parameter_migration_not_implemented_yet")); - } - } - - public List getJobArgset() - { - return jobArgset == null ? null - : JabaParamStore.getJabafromJwsArgs(jobArgset); - } - - public void setJobArgset(List jobArgset) - { - // TODO: test if parameters valid for service - this.jobArgset = jobArgset == null ? null - : JabaParamStore.getJwsArgsfromJaba(jobArgset); + super(service2, preset, jobArgset, autoUpdate); } @Override @@ -140,16 +71,4 @@ public class AAConSettings extends jalview.ws.params.AutoCalcSetting } return pset.toString(); } - - @Override - public String getServiceURI() - { - return service.getNameURI(); - } - - @Override - public String[] getServiceURLs() - { - return new String[] { service.getUri() }; - } } diff --git a/src/jalview/ws/params/AutoCalcSetting.java b/src/jalview/ws/params/AutoCalcSetting.java index 29aeef9..55eeb50 100644 --- a/src/jalview/ws/params/AutoCalcSetting.java +++ b/src/jalview/ws/params/AutoCalcSetting.java @@ -20,6 +20,10 @@ */ package jalview.ws.params; +import jalview.util.MessageManager; +import jalview.ws.api.ServiceWithParameters; + +import java.util.ArrayList; import java.util.List; public abstract class AutoCalcSetting @@ -31,9 +35,13 @@ public abstract class AutoCalcSetting protected List jobArgset; - public AutoCalcSetting(WsParamSetI preset2, List jobArgset2, + protected ServiceWithParameters service; + + public AutoCalcSetting(ServiceWithParameters service2, + WsParamSetI preset2, List jobArgset2, boolean autoUpdate2) { + service = service2; autoUpdate = autoUpdate2; preset = preset2; jobArgset = jobArgset2; @@ -66,20 +74,29 @@ public abstract class AutoCalcSetting } /** + * TODO: refactor to ServiceWithParameters ? * * @return characteristic URI for this service. The URI should reflect the * type and version of this service, enabling the service client code * to recover the correct client for this calculation. */ - public abstract String getServiceURI(); + public String getServiceURI() + { + return service.getNameURI(); + } /** + * TODO: refactor to ServiceWithParameters ? + * * return any concrete service endpoints associated with this calculation. * built in services should return a zero length array * * @return */ - public abstract String[] getServiceURLs(); + public String[] getServiceURLs() + { + return new String[] { service.getUri() }; + } /** * @@ -87,4 +104,61 @@ public abstract class AutoCalcSetting */ public abstract String getWsParamFile(); + public ServiceWithParameters getService() + { + return service; + } + + public void setService(ServiceWithParameters service) + { + this.service = service; + if (preset != null) + { + // check if we need to migrate preset to a new service URL + for (String url : preset.getApplicableUrls()) + { + if (url.equals(service.getUri())) + { + // preset already verified + return; + } + } + WsParamSetI pr = service.getParamStore().getPreset(preset.getName()); + + // TODO: decide of this distinction between preset and args are needed. + // + // if (pr instanceof JabaPreset && preset instanceof JabaPreset) + // { + // // easy - Presets are identical (we assume) + // preset = pr; + // return; + // } + + // this verifies that all arguments in the existing preset are the same as + // the parameters for the preset provided by the service parameter store. + // ie the LastUsed settings or a predefined preset. + + List oldargs = new ArrayList<>(), + newargs = new ArrayList<>(); + oldargs.addAll(preset.getArguments()); + // need to compare parameters + for (ArgumentI newparg : pr.getArguments()) + { + if (!oldargs.remove(newparg)) + { + newargs.add(newparg); + } + } + if (oldargs.size() == 0 && newargs.size() == 0) + { + // exact match. + preset = pr; + return; + } + // Try even harder to migrate arguments. + throw new Error(MessageManager + .getString("error.parameter_migration_not_implemented_yet")); + } + } + }