From 5838a52f20ec503ba9c29030ad2da545a61dced6 Mon Sep 17 00:00:00 2001 From: Mateusz Warowny Date: Fri, 25 Mar 2022 15:49:40 +0100 Subject: [PATCH] JAL3878 Implement slivka service discoverer --- .../client/api/AbstractWebServiceDiscoverer.java | 4 +- .../ws2/client/slivka/SlivkaParamStoreFactory.java | 224 ++++++++++++++++++++ .../ws2/client/slivka/SlivkaWSDiscoverer.java | 190 +++++++++++++++++ 3 files changed, 416 insertions(+), 2 deletions(-) create mode 100644 src/jalview/ws2/client/slivka/SlivkaParamStoreFactory.java create mode 100644 src/jalview/ws2/client/slivka/SlivkaWSDiscoverer.java diff --git a/src/jalview/ws2/client/api/AbstractWebServiceDiscoverer.java b/src/jalview/ws2/client/api/AbstractWebServiceDiscoverer.java index a526e72..965abca 100644 --- a/src/jalview/ws2/client/api/AbstractWebServiceDiscoverer.java +++ b/src/jalview/ws2/client/api/AbstractWebServiceDiscoverer.java @@ -152,7 +152,7 @@ public abstract class AbstractWebServiceDiscoverer implements WebServiceDiscover Cache.log.info("Fetching list of services from " + url); try { - allServices.addAll(getServices(url)); + allServices.addAll(fetchServices(url)); } catch (IOException e) { @@ -178,7 +178,7 @@ public abstract class AbstractWebServiceDiscoverer implements WebServiceDiscover } } - protected abstract List> getServices(URL url) throws IOException; + protected abstract List> fetchServices(URL url) throws IOException; private List listeners = new ArrayList<>(); diff --git a/src/jalview/ws2/client/slivka/SlivkaParamStoreFactory.java b/src/jalview/ws2/client/slivka/SlivkaParamStoreFactory.java new file mode 100644 index 0000000..6ac21df --- /dev/null +++ b/src/jalview/ws2/client/slivka/SlivkaParamStoreFactory.java @@ -0,0 +1,224 @@ +package jalview.ws2.client.slivka; + +import static java.util.Objects.requireNonNullElse; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import com.stevesoft.pat.NotImplementedError; + +import jalview.bin.Cache; +import jalview.ws.params.ArgumentI; +import jalview.ws.params.ParamDatastoreI; +import jalview.ws.params.ParamManager; +import jalview.ws.params.WsParamSetI; +import jalview.ws.params.simple.BooleanOption; +import jalview.ws.params.simple.DoubleParameter; +import jalview.ws.params.simple.IntegerParameter; +import jalview.ws.params.simple.Option; +import jalview.ws.params.simple.StringParameter; +import jalview.ws2.params.SimpleParamDatastore; +import jalview.ws2.params.SimpleParamSet; +import uk.ac.dundee.compbio.slivkaclient.Parameter; +import uk.ac.dundee.compbio.slivkaclient.SlivkaService; + +class SlivkaParamStoreFactory +{ + private final SlivkaService service; + private final ParamManager manager; + + SlivkaParamStoreFactory(SlivkaService service, ParamManager manager) + { + this.service = service; + this.manager = manager; + } + + ParamDatastoreI createParamDatastore() + { + URL url = null; + try + { + url = service.getUrl().toURL(); + } catch (MalformedURLException e) + { + Cache.log.warn("Invalid service url " + service.getUrl(), e); + } + List presets = new ArrayList<>(service.getPresets().size()); + for (var preset : service.getPresets()) + { + presets.add(createPreset(preset)); + } + List arguments = createPresetArguments(Collections.emptyMap()); + return new SimpleParamDatastore(url, arguments, presets, manager); + } + + WsParamSetI createPreset(SlivkaService.Preset preset) + { + var builder = SimpleParamSet.newBuilder(); + builder.name(preset.name); + builder.description(preset.description); + builder.url(service.getUrl().toString()); + builder.modifiable(false); + builder.arguments(createPresetArguments(preset.values)); + return builder.build(); + } + + List createPresetArguments(Map values) + { + var args = new ArrayList(); + for (Parameter param : service.getParameters()) + { + if (param instanceof Parameter.IntegerParameter) + { + args.add(createOption((Parameter.IntegerParameter) param, + (Integer) values.get(param.getId()))); + } + else if (param instanceof Parameter.DecimalParameter) + { + args.add(createOption((Parameter.DecimalParameter) param, + (Double) values.get(param.getId()))); + } + else if (param instanceof Parameter.TextParameter) + { + args.add(createOption((Parameter.TextParameter) param, + (String) values.get(param.getId()))); + } + else if (param instanceof Parameter.FlagParameter) + { + args.add(createOption((Parameter.FlagParameter) param, + (Boolean) values.get(param.getId()))); + } + else if (param instanceof Parameter.ChoiceParameter) + { + Object ovalue = values.get(param.getId()); + List lvalue = param.isArray() ? (List) ovalue : List.of((String) ovalue); + args.addAll(createChoiceOptions((Parameter.ChoiceParameter) param, lvalue)); + } + else if (param instanceof Parameter.FileParameter) + { + // args.add(createOption((Parameter.FileParameter) param, null)); + } + else + { + args.add(createOption(param, values.get(param.getId()))); + } + } + return args; + } + + private Option createOption(Parameter.IntegerParameter param, Integer value) + { + var builder = IntegerParameter.newBuilder(); + setCommonProperties(param, builder); + builder.setDefaultValue((Integer) param.getDefault()); + builder.setValue(value); + builder.setBounds(param.getMin(), param.getMax()); + return builder.build(); + } + + private Option createOption(Parameter.DecimalParameter param, Double value) + { + var builder = DoubleParameter.newBuilder(); + setCommonProperties(param, builder); + builder.setDefaultValue((Double) param.getDefault()); + builder.setValue(value); + builder.setBounds(param.getMin(), param.getMax()); + return builder.build(); + } + + private Option createOption(Parameter.TextParameter param, String value) + { + var builder = StringParameter.newBuilder(); + setCommonProperties(param, builder); + builder.setDefaultValue((String) param.getDefault()); + builder.setValue(value); + return builder.build(); + } + + private Option createOption(Parameter.FlagParameter param, Boolean value) + { + var builder = BooleanOption.newBuilder(); + setCommonProperties(param, builder); + builder.setDefaultValue((Boolean) param.getDefault()); + builder.setValue(value); + return builder.build(); + } + + private List