1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ws.jws2; |
22 |
|
|
23 |
|
import jalview.util.MessageManager; |
24 |
|
import jalview.ws.jws2.dm.JabaOption; |
25 |
|
import jalview.ws.jws2.dm.JabaParameter; |
26 |
|
import jalview.ws.jws2.dm.JabaWsParamSet; |
27 |
|
import jalview.ws.jws2.jabaws2.Jws2Instance; |
28 |
|
import jalview.ws.params.ArgumentI; |
29 |
|
import jalview.ws.params.ParamDatastoreI; |
30 |
|
import jalview.ws.params.ParamManager; |
31 |
|
import jalview.ws.params.WsParamSetI; |
32 |
|
|
33 |
|
import java.io.IOException; |
34 |
|
import java.util.ArrayList; |
35 |
|
import java.util.Arrays; |
36 |
|
import java.util.Hashtable; |
37 |
|
import java.util.List; |
38 |
|
import java.util.StringTokenizer; |
39 |
|
|
40 |
|
import compbio.metadata.Argument; |
41 |
|
import compbio.metadata.Option; |
42 |
|
import compbio.metadata.Parameter; |
43 |
|
import compbio.metadata.Preset; |
44 |
|
import compbio.metadata.PresetManager; |
45 |
|
import compbio.metadata.RunnerConfig; |
46 |
|
|
|
|
| 14.6% |
Uncovered Elements: 164 (192) |
Complexity: 45 |
Complexity Density: 0.37 |
|
47 |
|
public class JabaParamStore implements ParamDatastoreI |
48 |
|
{ |
49 |
|
|
50 |
|
Hashtable<String, JabaWsParamSet> editedParams = new Hashtable<String, JabaWsParamSet>(); |
51 |
|
|
52 |
|
private Jws2Instance service; |
53 |
|
|
54 |
|
private RunnerConfig serviceOptions; |
55 |
|
|
56 |
|
private Hashtable<String, JabaPreset> servicePresets; |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
0 |
public JabaParamStore(Jws2Instance service)... |
59 |
|
{ |
60 |
0 |
this(service, null); |
61 |
|
} |
62 |
|
|
63 |
|
ParamManager manager; |
64 |
|
|
|
|
| 52.9% |
Uncovered Elements: 8 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
65 |
259 |
public JabaParamStore(Jws2Instance service, ParamManager manager)... |
66 |
|
{ |
67 |
259 |
this.service = service; |
68 |
259 |
serviceOptions = service.getRunnerConfig(); |
69 |
259 |
this.manager = manager; |
70 |
|
|
71 |
|
|
72 |
259 |
if (manager != null) |
73 |
|
{ |
74 |
259 |
manager.registerParser(service.getUri(), this); |
75 |
259 |
WsParamSetI[] prams = manager.getParameterSet(null, service.getUri(), |
76 |
|
true, false); |
77 |
259 |
if (prams != null) |
78 |
|
{ |
79 |
0 |
for (WsParamSetI paramset : prams) |
80 |
|
{ |
81 |
0 |
if (paramset instanceof JabaWsParamSet) |
82 |
|
{ |
83 |
0 |
editedParams.put(paramset.getName(), (JabaWsParamSet) paramset); |
84 |
|
} |
85 |
|
else |
86 |
|
{ |
87 |
0 |
jalview.bin.Console.errPrintln( |
88 |
|
"Warning: Ignoring parameter set instance of type " |
89 |
|
+ paramset.getClass() |
90 |
|
+ " : Bound but not applicable for service at " |
91 |
|
+ service.getUri()); |
92 |
|
} |
93 |
|
} |
94 |
|
} |
95 |
|
} |
96 |
|
} |
97 |
|
|
|
|
| 81% |
Uncovered Elements: 4 (21) |
Complexity: 4 |
Complexity Density: 0.27 |
|
98 |
3484 |
@Override... |
99 |
|
public List<WsParamSetI> getPresets() |
100 |
|
{ |
101 |
3484 |
List<WsParamSetI> prefs = new ArrayList<>(); |
102 |
3484 |
if (servicePresets == null) |
103 |
|
{ |
104 |
259 |
servicePresets = new Hashtable<String, JabaPreset>(); |
105 |
259 |
PresetManager prman; |
106 |
? |
if ((prman = service.getPresets()) != null) |
107 |
|
{ |
108 |
137 |
List pset = prman.getPresets(); |
109 |
137 |
if (pset != null) |
110 |
|
{ |
111 |
137 |
for (Object pr : pset) |
112 |
|
{ |
113 |
480 |
JabaPreset prset = new JabaPreset(service, (Preset) pr); |
114 |
480 |
servicePresets.put(prset.getName(), prset); |
115 |
|
} |
116 |
|
} |
117 |
|
} |
118 |
|
} |
119 |
3484 |
for (JabaPreset pr : servicePresets.values()) |
120 |
|
{ |
121 |
12654 |
prefs.add(pr); |
122 |
|
} |
123 |
3484 |
for (WsParamSetI wspset : editedParams.values()) |
124 |
|
{ |
125 |
0 |
prefs.add(wspset); |
126 |
|
} |
127 |
3484 |
return prefs; |
128 |
|
} |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
130 |
0 |
@Override... |
131 |
|
public WsParamSetI getPreset(String name) |
132 |
|
{ |
133 |
0 |
for (WsParamSetI pr : getPresets()) |
134 |
|
{ |
135 |
0 |
if (pr.getName().equals(name)) |
136 |
|
{ |
137 |
0 |
return pr; |
138 |
|
} |
139 |
|
} |
140 |
0 |
return null; |
141 |
|
} |
142 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
143 |
0 |
public static List<ArgumentI> getJwsArgsfromJaba(List jabargs)... |
144 |
|
{ |
145 |
0 |
return getJwsArgsfromJaba(jabargs, true); |
146 |
|
} |
147 |
|
|
|
|
| 0% |
Uncovered Elements: 37 (37) |
Complexity: 6 |
Complexity Density: 0.22 |
|
148 |
0 |
public static List<ArgumentI> getJwsArgsfromJaba(List jabargs,... |
149 |
|
boolean sortByOpt) |
150 |
|
{ |
151 |
0 |
List<ArgumentI> rgs = new ArrayList<ArgumentI>(); |
152 |
0 |
List<String> rgnames = new ArrayList<String>(); |
153 |
0 |
for (Object rg : jabargs) |
154 |
|
{ |
155 |
0 |
ArgumentI narg = null; |
156 |
0 |
String nargstring = null; |
157 |
0 |
if (rg instanceof Parameter) |
158 |
|
{ |
159 |
0 |
narg = new JabaParameter((Parameter) rg); |
160 |
0 |
nargstring = narg.getName(); |
161 |
|
} |
162 |
0 |
else if (rg instanceof Option) |
163 |
|
{ |
164 |
0 |
narg = new JabaOption((Option) rg); |
165 |
0 |
nargstring = (String) ((Option) rg).getOptionNames().get(0); |
166 |
|
} |
167 |
0 |
if (narg == null) |
168 |
|
{ |
169 |
0 |
throw new Error(MessageManager.formatMessage( |
170 |
|
"error.implementation_error_cannot_handle_jaba_param", |
171 |
|
new String[] |
172 |
|
{ rg.getClass().toString() })); |
173 |
|
} |
174 |
|
else |
175 |
|
{ |
176 |
0 |
rgs.add(narg); |
177 |
0 |
rgnames.add(nargstring); |
178 |
|
} |
179 |
|
} |
180 |
0 |
if (!sortByOpt) |
181 |
|
{ |
182 |
0 |
return rgs; |
183 |
|
} |
184 |
0 |
ArgumentI[] rgssort = rgs.toArray(new ArgumentI[rgs.size()]); |
185 |
0 |
String[] rgssorton = rgnames.toArray(new String[rgs.size()]); |
186 |
0 |
jalview.util.QuickSort.sort(rgssorton, rgssort); |
187 |
0 |
ArgumentI tmp1; |
188 |
0 |
int i = 0; |
189 |
0 |
while (rgssort.length - i > i) |
190 |
|
{ |
191 |
0 |
tmp1 = rgssort[rgssort.length - i - 1]; |
192 |
0 |
rgssort[rgssort.length - i - 1] = rgssort[i]; |
193 |
0 |
rgssort[i++] = tmp1; |
194 |
|
} |
195 |
0 |
return Arrays.asList(rgssort); |
196 |
|
} |
197 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
198 |
0 |
public static List getJabafromJwsArgs(List<ArgumentI> jwsargs)... |
199 |
|
{ |
200 |
0 |
List rgs = new ArrayList(); |
201 |
0 |
for (ArgumentI rg : jwsargs) |
202 |
|
{ |
203 |
0 |
Argument narg = (rg instanceof JabaOption) |
204 |
|
? ((JabaOption) rg).getOption() |
205 |
|
: null; |
206 |
0 |
if (narg == null) |
207 |
|
{ |
208 |
0 |
throw new Error(MessageManager.formatMessage( |
209 |
|
"error.implementation_error_cannot_handle_jaba_param", |
210 |
|
new String[] |
211 |
|
{ rg.getClass().toString() })); |
212 |
|
} |
213 |
|
else |
214 |
|
{ |
215 |
0 |
rgs.add(narg); |
216 |
|
} |
217 |
|
} |
218 |
0 |
return rgs; |
219 |
|
} |
220 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
221 |
0 |
@Override... |
222 |
|
public List<ArgumentI> getServiceParameters() |
223 |
|
{ |
224 |
0 |
return getJwsArgsfromJaba(serviceOptions.getArguments()); |
225 |
|
} |
226 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
227 |
0 |
@Override... |
228 |
|
public boolean presetExists(String name) |
229 |
|
{ |
230 |
0 |
return (editedParams.containsKey(name) |
231 |
|
|| servicePresets.containsKey(name)); |
232 |
|
} |
233 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
234 |
0 |
@Override... |
235 |
|
public void deletePreset(String name) |
236 |
|
{ |
237 |
0 |
if (editedParams.containsKey(name)) |
238 |
|
{ |
239 |
0 |
WsParamSetI parameterSet = editedParams.get(name); |
240 |
0 |
editedParams.remove(name); |
241 |
0 |
if (manager != null) |
242 |
|
{ |
243 |
0 |
manager.deleteParameterSet(parameterSet); |
244 |
|
} |
245 |
0 |
return; |
246 |
|
} |
247 |
0 |
if (servicePresets.containsKey(name)) |
248 |
|
{ |
249 |
0 |
throw new Error(MessageManager.getString( |
250 |
|
"error.implementation_error_attempt_to_delete_service_preset")); |
251 |
|
} |
252 |
|
} |
253 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
254 |
0 |
@Override... |
255 |
|
public void storePreset(String presetName, String text, |
256 |
|
List<ArgumentI> jobParams) |
257 |
|
{ |
258 |
0 |
JabaWsParamSet jps = new JabaWsParamSet(presetName, text, jobParams); |
259 |
0 |
jps.setApplicableUrls(new String[] { service.getUri() }); |
260 |
0 |
editedParams.put(jps.getName(), jps); |
261 |
0 |
if (manager != null) |
262 |
|
{ |
263 |
0 |
manager.storeParameterSet(jps); |
264 |
|
} |
265 |
|
} |
266 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 6 |
Complexity Density: 0.5 |
|
267 |
0 |
@Override... |
268 |
|
public void updatePreset(String oldName, String presetName, String text, |
269 |
|
List<ArgumentI> jobParams) |
270 |
|
{ |
271 |
0 |
JabaWsParamSet jps = (JabaWsParamSet) ((oldName != null) |
272 |
|
? getPreset(oldName) |
273 |
|
: getPreset(presetName)); |
274 |
0 |
if (jps == null) |
275 |
|
{ |
276 |
0 |
throw new Error(MessageManager.formatMessage( |
277 |
|
"error.implementation_error_cannot_locate_oldname_presetname", |
278 |
|
new String[] |
279 |
|
{ oldName, presetName })); |
280 |
|
} |
281 |
0 |
jps.setName(presetName); |
282 |
0 |
jps.setDescription(text); |
283 |
0 |
jps.setArguments(jobParams); |
284 |
0 |
jps.setApplicableUrls(new String[] { service.getUri() }); |
285 |
0 |
if (oldName != null && !oldName.equals(jps.getName())) |
286 |
|
{ |
287 |
0 |
editedParams.remove(oldName); |
288 |
|
} |
289 |
0 |
editedParams.put(jps.getName(), jps); |
290 |
|
|
291 |
0 |
if (manager != null) |
292 |
|
{ |
293 |
0 |
manager.storeParameterSet(jps); |
294 |
|
} |
295 |
|
} |
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
@return |
301 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
302 |
0 |
WsParamSetI newWsParamSet()... |
303 |
|
{ |
304 |
0 |
return new JabaWsParamSet(); |
305 |
|
}; |
306 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
307 |
0 |
private boolean involves(String[] urls)... |
308 |
|
{ |
309 |
0 |
boolean found = false; |
310 |
0 |
for (String url : urls) |
311 |
|
{ |
312 |
0 |
if (service.getServiceTypeURI().equals(url) |
313 |
|
|| service.getUri().equalsIgnoreCase(url)) |
314 |
|
{ |
315 |
0 |
found = true; |
316 |
0 |
break; |
317 |
|
} |
318 |
|
} |
319 |
0 |
return found; |
320 |
|
} |
321 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
322 |
0 |
@Override... |
323 |
|
public WsParamSetI parseServiceParameterFile(String name, String descr, |
324 |
|
String[] urls, String parameterfile) throws IOException |
325 |
|
{ |
326 |
0 |
if (!involves(urls)) |
327 |
|
{ |
328 |
0 |
throw new IOException(MessageManager.getString( |
329 |
|
"error.implementation_error_cannot_find_service_url_in_given_set")); |
330 |
|
|
331 |
|
} |
332 |
0 |
JabaWsParamSet wsp = new JabaWsParamSet(); |
333 |
0 |
wsp.setName(name); |
334 |
0 |
wsp.setDescription(descr); |
335 |
0 |
wsp.setApplicableUrls(urls.clone()); |
336 |
|
|
337 |
0 |
List<String> lines = new ArrayList<String>(); |
338 |
0 |
StringTokenizer st = new StringTokenizer(parameterfile, "\n"); |
339 |
0 |
while (st.hasMoreTokens()) |
340 |
|
{ |
341 |
0 |
lines.add(st.nextToken()); |
342 |
|
} |
343 |
0 |
wsp.setjabaArguments( |
344 |
|
ParameterUtils.processParameters(lines, serviceOptions, " ")); |
345 |
0 |
return wsp; |
346 |
|
} |
347 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
348 |
0 |
@Override... |
349 |
|
public String generateServiceParameterFile(WsParamSetI pset) |
350 |
|
throws IOException |
351 |
|
{ |
352 |
0 |
if (!involves(pset.getApplicableUrls())) |
353 |
|
{ |
354 |
0 |
throw new IOException(MessageManager.formatMessage( |
355 |
|
"error.implementation_error_cannot_find_service_url_in_given_set_param_store", |
356 |
|
new String[] |
357 |
|
{ service.getUri() })); |
358 |
|
} |
359 |
0 |
if (!(pset instanceof JabaWsParamSet)) |
360 |
|
{ |
361 |
0 |
throw new Error(MessageManager.getString( |
362 |
|
"error.implementation_error_jabaws_param_set_only_handled_by")); |
363 |
|
} |
364 |
|
|
365 |
0 |
StringBuffer rslt = new StringBuffer(); |
366 |
0 |
for (String ln : ParameterUtils.writeParameterSet( |
367 |
|
((JabaWsParamSet) pset).getjabaArguments(), " ")) |
368 |
|
{ |
369 |
0 |
rslt.append(ln); |
370 |
0 |
rslt.append("\n"); |
371 |
|
} |
372 |
0 |
; |
373 |
0 |
return rslt.toString(); |
374 |
|
} |
375 |
|
|
376 |
|
} |