JAL-3878 Remove throws declaration from param store construction.
[jalview.git] / src / jalview / ws / slivkaws / SlivkaParamSet.java
1 package jalview.ws.slivkaws;
2
3 import java.io.IOException;
4 import java.util.ArrayList;
5 import java.util.Collections;
6 import java.util.List;
7
8 import jalview.ws.params.ArgumentI;
9 import jalview.ws.params.WsParamSetI;
10 import jalview.ws.params.simple.BooleanOption;
11 import jalview.ws.params.simple.DoubleParameter;
12 import jalview.ws.params.simple.IntegerParameter;
13 import jalview.ws.params.simple.StringParameter;
14 import uk.ac.dundee.compbio.slivkaclient.Parameter;
15 import uk.ac.dundee.compbio.slivkaclient.SlivkaService;
16
17 public class SlivkaParamSet implements WsParamSetI
18 {
19   private SlivkaService service;
20
21   private List<ArgumentI> args = new ArrayList<>();
22
23   SlivkaParamSet(SlivkaService service)
24   {
25     this.service = service;
26     for (Parameter param : service.getParameters())
27     {
28       Object defaultValue = param.getDefault() instanceof List
29           ? ((List<?>) param.getDefault()).get(0)
30           : param.getDefault();
31       if (param instanceof Parameter.FlagParameter)
32       {
33         args.add(new BooleanOption(param.getId(), param.getDescription(),
34             param.getName(), param.isRequired(), (Boolean) defaultValue, null));
35       }
36       else if (param instanceof Parameter.TextParameter)
37       {
38         args.add(new StringParameter(param.getId(), param.getDescription(),
39             param.isRequired(), (String) defaultValue, (String) defaultValue));
40       }
41       else if (param instanceof Parameter.IntegerParameter)
42       {
43         Integer min = ((Parameter.IntegerParameter) param).getMin();
44         Integer max = ((Parameter.IntegerParameter) param).getMax();
45         Integer defVal = defaultValue != null
46             ? ((Number) defaultValue).intValue()
47             : null;
48         args.add(new IntegerParameter(param.getId(), param.getDescription(),
49             param.isRequired(), defVal, (min == null) ? Integer.MIN_VALUE : min,
50             (max == null) ? Integer.MAX_VALUE : max));
51       }
52       else if (param instanceof Parameter.DecimalParameter)
53       {
54         Double min = ((Parameter.DecimalParameter) param).getMin();
55         Double max = ((Parameter.DecimalParameter) param).getMax();
56         Double defVal = defaultValue != null
57             ? ((Number) defaultValue).doubleValue()
58             : null;
59         args.add(new DoubleParameter(param.getId(), param.getDescription(),
60             param.isRequired(), defVal, (min == null) ? -Double.MAX_VALUE : min,
61             (max == null) ? Double.MAX_VALUE : max));
62       }
63       else if (param instanceof Parameter.ChoiceParameter)
64       {
65         List<String> choices = ((Parameter.ChoiceParameter) param)
66             .getChoices();
67         if (param.isArray())
68         {
69           int i = 0;
70           List<?> selected = param.getDefault() != null
71               ? (List<?>) param.getDefault()
72               : Collections.EMPTY_LIST;
73           for (String choice : choices)
74           {
75             args.add(new BooleanOption(
76                 String.format("%s$%d", param.getId(), i++),
77                 param.getDescription(), choice, param.isRequired(),
78                 selected.contains(choice), choice, null));
79           }
80         }
81         else
82         {
83           args.add(new StringParameter(
84               param.getId(), param.getDescription(),
85               param.isRequired(), (String) param.getDefault(),
86               (String) defaultValue, choices, choices));
87         }
88       }
89       else if (param instanceof Parameter.FileParameter)
90       {
91         // skip: files are provided from sequences
92       }
93       else
94       {
95         String defaultVal = param.getDefault() != null
96             ? param.getDefault().toString()
97             : null;
98         args.add(new StringParameter(param.getId(), param.getDescription(),
99             param.isRequired(), defaultVal, defaultVal));
100       }
101     }
102   }
103
104   @Override
105   public String getName()
106   {
107     return "Default";
108   }
109
110   @Override
111   public String getDescription()
112   {
113     return service.getDescription();
114   }
115
116   @Override
117   public String[] getApplicableUrls()
118   {
119     return new String[] { service.getUrl().toString() };
120   }
121
122   @Override
123   public String getSourceFile()
124   {
125     return null;
126   }
127
128   @Override
129   public void setSourceFile(String newfile)
130   {
131   }
132
133   @Override
134   public boolean isModifiable()
135   {
136     return true;
137   }
138
139   @Override
140   public List<ArgumentI> getArguments()
141   {
142     return args;
143   }
144
145   @Override
146   public void setArguments(List<ArgumentI> args)
147   {
148     throw new RuntimeException();
149   }
150
151 }