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.bin.Cache; |
24 |
|
import jalview.datamodel.AlignmentView; |
25 |
|
import jalview.gui.AlignFrame; |
26 |
|
import jalview.gui.AlignViewport; |
27 |
|
import jalview.gui.AlignmentPanel; |
28 |
|
import jalview.gui.Desktop; |
29 |
|
import jalview.gui.JvOptionPane; |
30 |
|
import jalview.gui.WebserviceInfo; |
31 |
|
import jalview.io.packed.DataProvider.JvDataType; |
32 |
|
import jalview.util.MessageManager; |
33 |
|
import jalview.ws.WSClient; |
34 |
|
import jalview.ws.WSClientI; |
35 |
|
import jalview.ws.WSMenuEntryProviderI; |
36 |
|
|
37 |
|
import java.awt.event.ActionEvent; |
38 |
|
import java.awt.event.ActionListener; |
39 |
|
import java.util.Hashtable; |
40 |
|
import java.util.Vector; |
41 |
|
|
42 |
|
import javax.swing.JMenu; |
43 |
|
import javax.swing.JMenuItem; |
44 |
|
import javax.swing.event.MenuEvent; |
45 |
|
import javax.swing.event.MenuListener; |
46 |
|
|
47 |
|
|
48 |
|
@author |
49 |
|
|
50 |
|
|
|
|
| 51.9% |
Uncovered Elements: 75 (156) |
Complexity: 44 |
Complexity Density: 0.44 |
|
51 |
|
public class RestClient extends WSClient |
52 |
|
implements WSClientI, WSMenuEntryProviderI |
53 |
|
{ |
54 |
|
RestServiceDescription service; |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
2870 |
public RestClient(RestServiceDescription rsd)... |
57 |
|
{ |
58 |
2870 |
service = rsd; |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
AlignFrame af; |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
AlignViewport av; |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
@return |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
0 |
protected AlignFrame recoverAlignFrameForView()... |
77 |
|
{ |
78 |
0 |
return jalview.gui.Desktop.getAlignFrameFor(av); |
79 |
|
} |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
0 |
public RestClient(RestServiceDescription service2, AlignFrame alignFrame)... |
82 |
|
{ |
83 |
0 |
this(service2, alignFrame, false); |
84 |
|
} |
85 |
|
|
86 |
|
boolean headless = false; |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
88 |
1 |
public RestClient(RestServiceDescription service2, AlignFrame alignFrame,... |
89 |
|
boolean nogui) |
90 |
|
{ |
91 |
1 |
service = service2; |
92 |
1 |
af = alignFrame; |
93 |
1 |
av = alignFrame.getViewport(); |
94 |
1 |
headless = nogui; |
95 |
1 |
constructJob(); |
96 |
|
} |
97 |
|
|
|
|
| 66.7% |
Uncovered Elements: 4 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
98 |
1 |
public void setWebserviceInfo(boolean headless)... |
99 |
|
{ |
100 |
1 |
WebServiceJobTitle = MessageManager |
101 |
|
.formatMessage("label.webservice_job_title", new String[] |
102 |
|
{ service.details.Action, service.details.Name }); |
103 |
1 |
WebServiceName = service.details.Name; |
104 |
1 |
WebServiceReference = "No reference - go to url for more info"; |
105 |
1 |
if (service.details.description != null) |
106 |
|
{ |
107 |
1 |
WebServiceReference = service.details.description; |
108 |
|
} |
109 |
1 |
if (!headless) |
110 |
|
{ |
111 |
0 |
wsInfo = new WebserviceInfo(WebServiceJobTitle, |
112 |
|
WebServiceName + "\n" + WebServiceReference, true); |
113 |
0 |
wsInfo.setRenderAsHtml(true); |
114 |
|
} |
115 |
|
|
116 |
|
} |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
0 |
@Override... |
119 |
|
public boolean isCancellable() |
120 |
|
{ |
121 |
|
|
122 |
0 |
return false; |
123 |
|
} |
124 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
125 |
0 |
@Override... |
126 |
|
public boolean canMergeResults() |
127 |
|
{ |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
0 |
return false; |
132 |
|
} |
133 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
134 |
0 |
@Override... |
135 |
|
public void cancelJob() |
136 |
|
{ |
137 |
0 |
jalview.bin.Console |
138 |
|
.errPrintln("Cannot cancel this job type: " + service); |
139 |
|
} |
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
141 |
2860 |
@Override... |
142 |
|
public void attachWSMenuEntry(final JMenu wsmenu, |
143 |
|
final AlignFrame alignFrame) |
144 |
|
{ |
145 |
2860 |
JMenuItem submit = new JMenuItem(service.details.Name); |
146 |
2860 |
submit.setToolTipText(MessageManager |
147 |
|
.formatMessage("label.rest_client_submit", new String[] |
148 |
|
{ service.details.Action, service.details.Name })); |
149 |
2860 |
submit.addActionListener(new ActionListener() |
150 |
|
{ |
151 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
152 |
0 |
@Override... |
153 |
|
public void actionPerformed(ActionEvent e) |
154 |
|
{ |
155 |
0 |
new RestClient(service, alignFrame); |
156 |
|
} |
157 |
|
|
158 |
|
}); |
159 |
2860 |
wsmenu.add(submit); |
160 |
|
|
161 |
|
|
162 |
2860 |
wsmenu.addMenuListener(new MenuListener() |
163 |
|
{ |
164 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
165 |
0 |
@Override... |
166 |
|
public void menuSelected(MenuEvent e) |
167 |
|
{ |
168 |
|
|
169 |
|
|
170 |
|
} |
171 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
172 |
0 |
@Override... |
173 |
|
public void menuDeselected(MenuEvent e) |
174 |
|
{ |
175 |
|
|
176 |
|
|
177 |
|
} |
178 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
179 |
0 |
@Override... |
180 |
|
public void menuCanceled(MenuEvent e) |
181 |
|
{ |
182 |
|
|
183 |
|
|
184 |
|
} |
185 |
|
|
186 |
|
}); |
187 |
|
|
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
long[] undoredo = null; |
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
@return |
204 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 5 |
Complexity Density: 1 |
|
205 |
0 |
protected boolean isAlignmentModified()... |
206 |
|
{ |
207 |
0 |
if (undoredo == null || av == null || av.getAlignment() == null) |
208 |
|
{ |
209 |
|
|
210 |
|
|
211 |
0 |
return true; |
212 |
|
} |
213 |
0 |
if (av.isUndoRedoHashModified(undoredo)) |
214 |
|
{ |
215 |
|
|
216 |
0 |
return true; |
217 |
|
} |
218 |
|
|
219 |
|
|
220 |
0 |
return false; |
221 |
|
|
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
AlignmentView _input; |
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
jalview.io.packed.JalviewDataset jds; |
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
public String viewTitle; |
238 |
|
|
|
|
| 35.7% |
Uncovered Elements: 27 (42) |
Complexity: 12 |
Complexity Density: 0.55 |
|
239 |
1 |
protected void constructJob()... |
240 |
|
{ |
241 |
1 |
service.setInvolvesFlags(); |
242 |
|
|
243 |
|
|
244 |
1 |
undoredo = av.getUndoRedoHash(); |
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
1 |
boolean selExists = (av.getSelectionGroup() != null) |
251 |
|
&& (av.getSelectionGroup().getSize() > 1); |
252 |
|
|
253 |
|
|
254 |
1 |
if (selExists) |
255 |
|
{ |
256 |
0 |
if (service.partitiondata) |
257 |
|
{ |
258 |
0 |
if (av.getAlignment().getGroups() != null |
259 |
|
&& av.getAlignment().getGroups().size() > 0) |
260 |
|
{ |
261 |
|
|
262 |
0 |
_input = new AlignmentView(av.getAlignment(), |
263 |
|
av.getAlignment().getHiddenColumns(), |
264 |
|
av.getSelectionGroup(), av.hasHiddenColumns(), true, |
265 |
|
true); |
266 |
0 |
viewTitle = MessageManager.formatMessage( |
267 |
|
"label.select_visible_region_of", new String[] |
268 |
0 |
{ (av.hasHiddenColumns() |
269 |
|
? MessageManager.getString("label.visible") |
270 |
|
: ""), |
271 |
|
af.getTitle() }); |
272 |
|
} |
273 |
|
else |
274 |
|
{ |
275 |
|
|
276 |
0 |
_input = new AlignmentView(av.getAlignment(), |
277 |
|
av.getAlignment().getHiddenColumns(), |
278 |
|
av.getSelectionGroup(), av.hasHiddenColumns(), false, |
279 |
|
true); |
280 |
|
} |
281 |
0 |
viewTitle = MessageManager.formatMessage( |
282 |
|
"label.select_unselect_visible_regions_from", new String[] |
283 |
0 |
{ (av.hasHiddenColumns() |
284 |
|
? MessageManager.getString("label.visible") |
285 |
|
: ""), |
286 |
|
af.getTitle() }); |
287 |
|
} |
288 |
|
else |
289 |
|
{ |
290 |
|
|
291 |
0 |
_input = new AlignmentView(av.getAlignment(), |
292 |
|
av.getAlignment().getHiddenColumns(), |
293 |
|
av.getSelectionGroup(), av.hasHiddenColumns(), true, true); |
294 |
0 |
viewTitle = MessageManager.formatMessage( |
295 |
|
"label.select_visible_region_of", new String[] |
296 |
0 |
{ (av.hasHiddenColumns() |
297 |
|
? MessageManager.getString("label.visible") |
298 |
|
: ""), |
299 |
|
af.getTitle() }); |
300 |
|
} |
301 |
|
} |
302 |
|
else |
303 |
|
{ |
304 |
|
|
305 |
1 |
_input = new AlignmentView(av.getAlignment(), |
306 |
|
av.getAlignment().getHiddenColumns(), null, |
307 |
|
av.hasHiddenColumns(), false, true); |
308 |
1 |
viewTitle = "" |
309 |
1 |
+ (av.hasHiddenColumns() |
310 |
|
? (new StringBuffer(" ") |
311 |
|
.append(MessageManager |
312 |
|
.getString("label.visible_region_of")) |
313 |
|
.toString()) |
314 |
|
: "") |
315 |
|
+ af.getTitle(); |
316 |
|
} |
317 |
|
|
318 |
1 |
RestJobThread jobsthread = new RestJobThread(this); |
319 |
|
|
320 |
1 |
if (jobsthread.isValid()) |
321 |
|
{ |
322 |
1 |
setWebserviceInfo(headless); |
323 |
1 |
if (!headless) |
324 |
|
{ |
325 |
0 |
wsInfo.setthisService(this); |
326 |
0 |
jobsthread.setWebServiceInfo(wsInfo); |
327 |
|
} |
328 |
1 |
jobsthread.start(); |
329 |
|
} |
330 |
|
else |
331 |
|
{ |
332 |
|
|
333 |
0 |
JvOptionPane.showMessageDialog(Desktop.desktop, |
334 |
0 |
(jobsthread.hasWarnings() ? jobsthread.getWarnings() |
335 |
|
: MessageManager.getString( |
336 |
|
"label.job_couldnt_be_started_check_input")), |
337 |
|
MessageManager |
338 |
|
.getString("label.unable_start_web_service_analysis"), |
339 |
|
JvOptionPane.WARNING_MESSAGE); |
340 |
|
} |
341 |
|
} |
342 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
|
343 |
8 |
public static RestClient makeShmmrRestClient()... |
344 |
|
{ |
345 |
8 |
String action = "Analysis", |
346 |
|
description = "Sequence Harmony and Multi-Relief (Brandt et al. 2010)", |
347 |
|
name = MessageManager.getString("label.multiharmony"); |
348 |
8 |
Hashtable<String, InputType> iparams = new Hashtable<String, InputType>(); |
349 |
8 |
jalview.ws.rest.params.JobConstant toolp; |
350 |
|
|
351 |
|
|
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
8 |
jalview.ws.rest.params.Alignment aliinput = new jalview.ws.rest.params.Alignment(); |
363 |
|
|
364 |
|
|
365 |
8 |
aliinput.token = "ali_file"; |
366 |
8 |
aliinput.writeAsFile = true; |
367 |
8 |
iparams.put(aliinput.token, aliinput); |
368 |
8 |
jalview.ws.rest.params.SeqGroupIndexVector sgroups = new jalview.ws.rest.params.SeqGroupIndexVector(); |
369 |
8 |
sgroups.setMinsize(2); |
370 |
8 |
sgroups.min = 2; |
371 |
8 |
iparams.put("groups", sgroups); |
372 |
8 |
sgroups.token = "groups"; |
373 |
8 |
sgroups.sep = " "; |
374 |
8 |
RestServiceDescription shmrService = new RestServiceDescription(action, |
375 |
|
description, name, |
376 |
|
"http://zeus.few.vu.nl/programs/shmrwww/index.php?tool=jalview", |
377 |
|
"?tool=jalview", iparams, true, false, '-'); |
378 |
|
|
379 |
8 |
shmrService.addResultDatatype(JvDataType.ANNOTATION); |
380 |
8 |
return new RestClient(shmrService); |
381 |
|
} |
382 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
383 |
0 |
public AlignmentPanel recoverAlignPanelForView()... |
384 |
|
{ |
385 |
0 |
AlignmentPanel[] aps = Desktop |
386 |
|
.getAlignmentPanels(av.getSequenceSetId()); |
387 |
0 |
for (AlignmentPanel alp : aps) |
388 |
|
{ |
389 |
0 |
if (alp.av == av) |
390 |
|
{ |
391 |
0 |
return alp; |
392 |
|
} |
393 |
|
} |
394 |
0 |
return null; |
395 |
|
} |
396 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
397 |
0 |
public boolean isShowResultsInNewView()... |
398 |
|
{ |
399 |
|
|
400 |
0 |
return true; |
401 |
|
} |
402 |
|
|
403 |
|
protected static Vector<String> services = null; |
404 |
|
|
405 |
|
public static final String RSBS_SERVICES = "RSBS_SERVICES"; |
406 |
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 3 |
Complexity Density: 0.25 |
|
407 |
2862 |
public static RestClient[] getRestClients()... |
408 |
|
{ |
409 |
2862 |
if (services == null) |
410 |
|
{ |
411 |
6 |
services = new Vector<String>(); |
412 |
6 |
try |
413 |
|
{ |
414 |
6 |
for (RestServiceDescription descr : RestServiceDescription |
415 |
|
.parseDescriptions(Cache.getDefault(RSBS_SERVICES, |
416 |
|
makeShmmrRestClient().service.toString()))) |
417 |
|
{ |
418 |
6 |
services.add(descr.toString()); |
419 |
|
} |
420 |
|
} catch (Exception ex) |
421 |
|
{ |
422 |
0 |
jalview.bin.Console.errPrintln( |
423 |
|
"Serious - RSBS descriptions in user preferences are corrupt!"); |
424 |
0 |
ex.printStackTrace(); |
425 |
|
} |
426 |
|
|
427 |
|
} |
428 |
2862 |
RestClient[] lst = new RestClient[services.size()]; |
429 |
2862 |
int i = 0; |
430 |
2862 |
for (String svc : services) |
431 |
|
{ |
432 |
2862 |
lst[i++] = new RestClient(new RestServiceDescription(svc)); |
433 |
|
} |
434 |
2862 |
return lst; |
435 |
|
} |
436 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
437 |
2860 |
public String getAction()... |
438 |
|
{ |
439 |
2860 |
return service.details.Action; |
440 |
|
} |
441 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
442 |
2 |
public RestServiceDescription getRestDescription()... |
443 |
|
{ |
444 |
2 |
return service; |
445 |
|
} |
446 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
447 |
0 |
public static Vector<String> getRsbsDescriptions()... |
448 |
|
{ |
449 |
0 |
Vector<String> rsbsDescrs = new Vector<String>(); |
450 |
0 |
for (RestClient rsbs : getRestClients()) |
451 |
|
{ |
452 |
0 |
rsbsDescrs.add(rsbs.getRestDescription().toString()); |
453 |
|
} |
454 |
0 |
return rsbsDescrs; |
455 |
|
} |
456 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
457 |
1 |
public static void setRsbsServices(Vector<String> rsbsUrls)... |
458 |
|
{ |
459 |
1 |
if (rsbsUrls != null) |
460 |
|
{ |
461 |
|
|
462 |
1 |
services = new Vector<String>(rsbsUrls); |
463 |
1 |
StringBuffer sprop = new StringBuffer(); |
464 |
1 |
for (String s : services) |
465 |
|
{ |
466 |
1 |
sprop.append(s); |
467 |
|
} |
468 |
1 |
Cache.setProperty(RSBS_SERVICES, sprop.toString()); |
469 |
|
} |
470 |
|
else |
471 |
|
{ |
472 |
0 |
Cache.removeProperty(RSBS_SERVICES); |
473 |
|
} |
474 |
|
} |
475 |
|
|
476 |
|
} |