1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ws.rest; |
22 |
|
|
23 |
|
import jalview.ws.params.ArgumentI; |
24 |
|
import jalview.ws.params.InvalidArgumentException; |
25 |
|
import jalview.ws.params.OptionI; |
26 |
|
import jalview.ws.params.ParameterI; |
27 |
|
import jalview.ws.params.simple.IntegerParameter; |
28 |
|
import jalview.ws.params.simple.Option; |
29 |
|
|
30 |
|
import java.io.UnsupportedEncodingException; |
31 |
|
import java.nio.charset.Charset; |
32 |
|
import java.util.ArrayList; |
33 |
|
import java.util.Collection; |
34 |
|
import java.util.List; |
35 |
|
import java.util.regex.Matcher; |
36 |
|
import java.util.regex.Pattern; |
37 |
|
|
38 |
|
import org.apache.http.entity.mime.content.ContentBody; |
39 |
|
import org.apache.http.entity.mime.content.StringBody; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
|
|
| 38.3% |
Uncovered Elements: 66 (107) |
Complexity: 31 |
Complexity Density: 0.53 |
|
47 |
|
public abstract class InputType |
48 |
|
{ |
49 |
|
private static final Pattern URL_PATTERN = Pattern |
50 |
|
.compile("^([^=]+)=?'?([^']*)?'?"); |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
boolean replaceids; |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.25 |
|
57 |
|
public enum molType |
58 |
|
{ |
59 |
|
NUC, PROT, MIX; |
60 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
61 |
0 |
public static Collection<String> toStringValues()... |
62 |
|
{ |
63 |
0 |
Collection<String> c = new ArrayList<String>(); |
64 |
0 |
for (molType type : values()) |
65 |
|
{ |
66 |
0 |
c.add(type.toString()); |
67 |
|
} |
68 |
0 |
return c; |
69 |
|
} |
70 |
|
} |
71 |
|
|
72 |
|
public String token; |
73 |
|
|
74 |
|
public int min = 1; |
75 |
|
|
76 |
|
public int max = 0; |
77 |
|
|
78 |
|
protected ArrayList<Class> inputData = new ArrayList<Class>(); |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
@param |
85 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
86 |
4430 |
protected InputType(Class[] types)... |
87 |
|
{ |
88 |
4430 |
if (types != null) |
89 |
|
{ |
90 |
4430 |
for (Class t : types) |
91 |
|
{ |
92 |
4430 |
inputData.add(t); |
93 |
|
} |
94 |
|
} |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
@param |
102 |
|
@return |
103 |
|
|
|
|
| 60% |
Uncovered Elements: 4 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
104 |
2 |
public boolean validFor(RestJob restJob)... |
105 |
|
{ |
106 |
2 |
if (!validFor(restJob.rsd)) |
107 |
0 |
return false; |
108 |
2 |
for (Class cl : inputData) |
109 |
|
{ |
110 |
2 |
if (!restJob.hasDataOfType(cl)) |
111 |
|
{ |
112 |
0 |
return false; |
113 |
|
} |
114 |
|
} |
115 |
2 |
return true; |
116 |
|
} |
117 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
118 |
2 |
public boolean validFor(RestServiceDescription restServiceDescription)... |
119 |
|
{ |
120 |
2 |
if (!restServiceDescription.inputParams.values().contains(this)) |
121 |
0 |
return false; |
122 |
|
|
123 |
2 |
return true; |
124 |
|
} |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
126 |
0 |
protected ContentBody utf8StringBody(String content, String type)... |
127 |
|
{ |
128 |
0 |
Charset utf8 = Charset.forName("UTF-8"); |
129 |
0 |
try |
130 |
|
{ |
131 |
0 |
if (type == null) |
132 |
|
{ |
133 |
0 |
return new StringBody( |
134 |
|
utf8.encode(content).asCharBuffer().toString()); |
135 |
|
} |
136 |
|
else |
137 |
|
{ |
138 |
0 |
return new StringBody( |
139 |
|
utf8.encode(content).asCharBuffer().toString(), type, utf8); |
140 |
|
} |
141 |
|
} catch (Exception ex) |
142 |
|
{ |
143 |
0 |
System.err.println("Couldn't transform string\n" + content |
144 |
|
+ "\nException was :"); |
145 |
0 |
ex.printStackTrace(System.err); |
146 |
|
} |
147 |
0 |
return null; |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
@param |
153 |
|
|
154 |
|
@return |
155 |
|
|
156 |
|
abstract public ContentBody formatForInput(RestJob rj) |
157 |
|
throws UnsupportedEncodingException, NoValidInputDataException; |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
@return |
162 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
163 |
26 |
public boolean isConstant()... |
164 |
|
{ |
165 |
26 |
return (inputData == null || inputData.size() == 0); |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
@return |
173 |
|
|
174 |
|
public abstract List<String> getURLEncodedParameter(); |
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
@param |
180 |
|
@param |
181 |
|
|
182 |
|
@param |
183 |
|
|
184 |
|
@return |
185 |
|
|
186 |
|
public abstract boolean configureProperty(String tok, String val, |
187 |
|
StringBuffer warnings); |
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
@return |
193 |
|
|
194 |
|
|
195 |
|
public abstract String getURLtokenPrefix(); |
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
@param |
202 |
|
|
203 |
|
|
204 |
|
@param |
205 |
|
|
206 |
|
|
207 |
|
@return |
208 |
|
|
|
|
| 57.1% |
Uncovered Elements: 12 (28) |
Complexity: 7 |
Complexity Density: 0.39 |
|
209 |
2212 |
public boolean configureFromURLtokenString(List<String> tokenstring,... |
210 |
|
StringBuffer warnings) |
211 |
|
{ |
212 |
2212 |
boolean valid = true; |
213 |
2212 |
for (String tok : tokenstring) |
214 |
|
{ |
215 |
5530 |
Matcher mtch = URL_PATTERN.matcher(tok); |
216 |
5530 |
if (mtch.find()) |
217 |
|
{ |
218 |
5530 |
try |
219 |
|
{ |
220 |
5530 |
if (mtch.group(1).equals("min")) |
221 |
|
{ |
222 |
1106 |
min = Integer.parseInt(mtch.group(2)); |
223 |
1106 |
continue; |
224 |
|
|
225 |
|
} |
226 |
4424 |
else if (mtch.group(1).equals("max")) |
227 |
|
{ |
228 |
0 |
max = Integer.parseInt(mtch.group(2)); |
229 |
0 |
continue; |
230 |
|
} |
231 |
|
} catch (NumberFormatException x) |
232 |
|
{ |
233 |
0 |
valid = false; |
234 |
0 |
warnings.append("Invalid value for parameter " |
235 |
|
+ mtch.group(1).toLowerCase() + " '" + mtch.group(2) |
236 |
|
+ "' (expected an integer)\n"); |
237 |
|
} |
238 |
|
|
239 |
4424 |
if (!configureProperty(mtch.group(1), mtch.group(2), warnings)) |
240 |
|
{ |
241 |
0 |
if (warnings.length() == 0) |
242 |
|
{ |
243 |
0 |
warnings.append("Failed to configure InputType :" |
244 |
|
+ getURLtokenPrefix() + " with property string: '" |
245 |
|
+ mtch.group(0) + "'\n (token is '" + mtch.group(1) |
246 |
|
+ "' and value is '" + mtch.group(2) + "')\n"); |
247 |
|
} |
248 |
0 |
valid = false; |
249 |
|
} |
250 |
|
} |
251 |
|
} |
252 |
2212 |
return valid; |
253 |
|
} |
254 |
|
|
|
|
| 62.5% |
Uncovered Elements: 3 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
255 |
10 |
public void addBaseParams(ArrayList<String> prms)... |
256 |
|
{ |
257 |
|
|
258 |
|
|
259 |
10 |
if (min != 1) |
260 |
|
{ |
261 |
10 |
prms.add("min='" + min + "'"); |
262 |
|
} |
263 |
10 |
if (max != 0) |
264 |
|
{ |
265 |
0 |
prms.add("max='" + max + "'"); |
266 |
|
} |
267 |
|
} |
268 |
|
|
269 |
|
public abstract List<OptionI> getOptions(); |
270 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
271 |
0 |
public List<OptionI> getBaseOptions()... |
272 |
|
{ |
273 |
0 |
ArrayList<OptionI> opts = new ArrayList<OptionI>(); |
274 |
0 |
opts.add(new IntegerParameter("min", |
275 |
|
"Minimum number of data of this type", true, 1, min, 0, -1)); |
276 |
0 |
opts.add(new IntegerParameter("max", |
277 |
|
"Maximum number of data of this type", false, 0, max, 0, -1)); |
278 |
0 |
return opts; |
279 |
|
} |
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
@return |
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
@param |
291 |
|
|
292 |
|
@throws |
293 |
|
|
294 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 6 |
Complexity Density: 0.55 |
|
295 |
0 |
public void configureFromArgumentI(List<ArgumentI> currentSettings)... |
296 |
|
throws InvalidArgumentException |
297 |
|
{ |
298 |
0 |
ArrayList<String> urltoks = new ArrayList<String>(); |
299 |
0 |
String rg; |
300 |
0 |
for (ArgumentI arg : currentSettings) |
301 |
|
{ |
302 |
0 |
if (arg instanceof ParameterI) |
303 |
|
{ |
304 |
0 |
rg = arg.getName() + "='" + arg.getValue() + "'"; |
305 |
|
} |
306 |
|
else |
307 |
|
{ |
308 |
|
|
309 |
|
|
310 |
0 |
rg = (arg.getValue().length() > 0) |
311 |
0 |
? (arg.getValue().equals(arg.getName()) ? arg.getName() |
312 |
|
: arg.getName() + "='" + arg.getValue() + "'") |
313 |
|
: arg.getName(); |
314 |
|
} |
315 |
0 |
if (rg.length() > 0) |
316 |
|
{ |
317 |
0 |
urltoks.add(rg); |
318 |
|
} |
319 |
|
} |
320 |
0 |
StringBuffer warnings; |
321 |
0 |
if (!configureFromURLtokenString(urltoks, |
322 |
|
warnings = new StringBuffer())) |
323 |
|
{ |
324 |
0 |
throw new InvalidArgumentException(warnings.toString()); |
325 |
|
} |
326 |
|
} |
327 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 3 |
|
328 |
0 |
protected OptionI createMolTypeOption(String name, String descr,... |
329 |
|
boolean req, molType curType, molType defType) |
330 |
|
{ |
331 |
0 |
return new Option(name, descr, req, |
332 |
0 |
defType == null ? "" : defType.toString(), |
333 |
0 |
curType == null ? "" : curType.toString(), |
334 |
|
molType.toStringValues(), null); |
335 |
|
} |
336 |
|
} |