X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fparams%2FAutoCalcSetting.java;fp=src%2Fjalview%2Fws%2Fparams%2FAutoCalcSetting.java;h=68ec7a6b5ad8f8476907cbc44b0890787f644988;hb=c794c5033adeee182b03a5ea92c0a7495a29661f;hp=29aeef941f22e6ef361add03d766359ccc9d7191;hpb=e1dbbc5edc07f65706eeb1dda9f4c9bcdee9d3a5;p=jalview.git diff --git a/src/jalview/ws/params/AutoCalcSetting.java b/src/jalview/ws/params/AutoCalcSetting.java index 29aeef9..68ec7a6 100644 --- a/src/jalview/ws/params/AutoCalcSetting.java +++ b/src/jalview/ws/params/AutoCalcSetting.java @@ -20,9 +20,13 @@ */ 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 +public class AutoCalcSetting { protected boolean autoUpdate; @@ -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,25 +74,117 @@ 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() }; + } /** + * default WsParamFile generator method - clients with custom formats should + * override and implement their own * * @return stringified representation of the parameters for this setting */ - public abstract String getWsParamFile(); + public String getWsParamFile() + { + List opts = null; + if (jobArgset != null) + { + opts = jobArgset; + } + else + { + if (preset != null) + { + opts = preset.getArguments(); + } + } + if (opts == null || opts.size() == 0) + { + return ""; + } + StringBuffer pset = new StringBuffer(); + for (ArgumentI ps : opts) + { + pset.append(ps.getName() + "\t" + ps.getValue()); + pset.append("\n"); + } + return pset.toString(); + } + 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")); + } + } }