package jalview.ws.slivkaws; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import jalview.ws.params.ArgumentI; 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.StringParameter; import uk.ac.dundee.compbio.slivkaclient.Parameter; import uk.ac.dundee.compbio.slivkaclient.SlivkaService; public class SlivkaParamSet implements WsParamSetI { private SlivkaService service; private List args = new ArrayList<>(); SlivkaParamSet(SlivkaService service) throws IOException { this.service = service; for (Parameter param : service.getParameters()) { Object defaultValue = param.getDefault() instanceof List ? ((List) param.getDefault()).get(0) : param.getDefault(); if (param instanceof Parameter.FlagParameter) { args.add(new BooleanOption(param.getId(), param.getDescription(), param.getName(), param.isRequired(), (Boolean) defaultValue, null)); } else if (param instanceof Parameter.TextParameter) { args.add(new StringParameter(param.getId(), param.getDescription(), param.isRequired(), (String) defaultValue, (String) defaultValue)); } else if (param instanceof Parameter.IntegerParameter) { Integer min = ((Parameter.IntegerParameter) param).getMin(); Integer max = ((Parameter.IntegerParameter) param).getMax(); Integer defVal = defaultValue != null ? ((Number) defaultValue).intValue() : null; args.add(new IntegerParameter(param.getId(), param.getDescription(), param.isRequired(), defVal, (min == null) ? Integer.MIN_VALUE : min, (max == null) ? Integer.MAX_VALUE : max)); } else if (param instanceof Parameter.DecimalParameter) { Double min = ((Parameter.DecimalParameter) param).getMin(); Double max = ((Parameter.DecimalParameter) param).getMax(); Double defVal = defaultValue != null ? ((Number) defaultValue).doubleValue() : null; args.add(new DoubleParameter(param.getId(), param.getDescription(), param.isRequired(), defVal, (min == null) ? -Double.MAX_VALUE : min, (max == null) ? Double.MAX_VALUE : max)); } else if (param instanceof Parameter.ChoiceParameter) { List choices = ((Parameter.ChoiceParameter) param) .getChoices(); if (param.isArray()) { int i = 0; List selected = param.getDefault() != null ? (List) param.getDefault() : Collections.EMPTY_LIST; for (String choice : choices) { args.add(new BooleanOption( String.format("%s$%d", param.getId(), i++), param.getDescription(), choice, param.isRequired(), selected.contains(choice), choice, null)); } } else { args.add(new StringParameter( param.getId(), param.getDescription(), param.isRequired(), (String) param.getDefault(), (String) defaultValue, choices, choices)); } } else if (param instanceof Parameter.FileParameter) { // skip: files are provided from sequences } else { String defaultVal = param.getDefault() != null ? param.getDefault().toString() : null; args.add(new StringParameter(param.getId(), param.getDescription(), param.isRequired(), defaultVal, defaultVal)); } } } @Override public String getName() { return "Default"; } @Override public String getDescription() { return service.getDescription(); } @Override public String[] getApplicableUrls() { return new String[] { service.getUrl().toString() }; } @Override public String getSourceFile() { return null; } @Override public void setSourceFile(String newfile) { } @Override public boolean isModifiable() { return true; } @Override public List getArguments() { return args; } @Override public void setArguments(List args) { throw new RuntimeException(); } }