1 package jalview.ws2.slivka;
3 import java.io.IOException;
4 import java.net.MalformedURLException;
7 import java.util.concurrent.*;
9 import jalview.bin.Cache;
11 import jalview.ws2.operations.*;
12 import uk.ac.dundee.compbio.slivkaclient.SlivkaClient;
13 import uk.ac.dundee.compbio.slivkaclient.SlivkaService;
15 public class SlivkaWSDiscoverer implements WebServiceDiscovererI
17 private static final String SLIVKA_HOST_URLS = "SLIVKSHOSTURLS";
19 private static final String DEFAULT_URL = "https://www.compbio.dundee.ac.uk/slivka/";
21 private static SlivkaWSDiscoverer instance = null;
23 private List<Operation> operations = List.of();
25 private SlivkaWSDiscoverer()
29 public static SlivkaWSDiscoverer getInstance()
33 instance = new SlivkaWSDiscoverer();
39 public List<String> getUrls()
41 String surls = Cache.getDefault(SLIVKA_HOST_URLS, DEFAULT_URL);
42 String urls[] = surls.split(",");
43 ArrayList<String> valid = new ArrayList<>(urls.length);
44 for (String url : urls)
50 } catch (MalformedURLException e)
52 Cache.log.warn("Problem whilst trying to make a URL from '"
53 + Objects.toString(url, "<null>") + "'. "
54 + "This was probably due to malformed comma-separated-list "
55 + "in the " + SLIVKA_HOST_URLS
56 + " entry of ${HOME}/.jalview_properties");
57 Cache.log.debug("Exception occurred while reading url list", e);
64 public void setUrls(List<String> wsUrls)
66 if (wsUrls != null && !wsUrls.isEmpty())
68 Cache.setProperty(SLIVKA_HOST_URLS, String.join(",", wsUrls));
72 Cache.removeProperty(SLIVKA_HOST_URLS);
77 public boolean testUrl(URL url)
79 return getStatusForUrl(url.toString()) == STATUS_OK;
83 public int getStatusForUrl(String url)
87 List<?> services = new SlivkaClient(url).getServices();
88 return services.isEmpty() ? STATUS_NO_SERVICES : STATUS_OK;
89 } catch (IOException e)
91 Cache.log.error("Slivka could not retrieve services list from " + url,
93 return STATUS_INVALID;
98 public List<Operation> getOperations()
100 return Collections.unmodifiableList(operations);
104 public boolean hasServices()
106 return !isRunning() && operations.size() > 0;
109 public boolean isRunning()
111 for (Future<?> task : discoveryTasks)
121 public boolean isDone()
123 return !isRunning() && discoveryTasks.size() > 0;
126 private Vector<Future<?>> discoveryTasks = new Vector<>();
129 public CompletableFuture<WebServiceDiscovererI> startDiscoverer()
131 CompletableFuture<WebServiceDiscovererI> task = CompletableFuture
134 return SlivkaWSDiscoverer.this;
136 task.thenRun(() -> fireOperationsChanged(getOperations()));
137 discoveryTasks.add(task);
141 private List<Operation> reloadServices()
143 Cache.log.info("Reloading Slivka services");
144 fireOperationsChanged(Collections.emptyList());
145 ArrayList<Operation> allOperations= new ArrayList<>();
146 for (String url : getUrls())
148 SlivkaClient client = new SlivkaClient(url);
149 List<SlivkaService> services;
152 services = client.getServices();
153 } catch (IOException e)
155 Cache.log.error("Unable to fetch services from " + url, e);
158 for (SlivkaService service : services)
160 SlivkaWebService webService = new SlivkaWebService(client, service);
161 AbstractOperation op = null;
162 for (String classifier : service.classifiers)
164 String[] path = classifier.split("\\s*::\\s*");
165 if (path.length >= 3 && path[0].toLowerCase().equals("operation")
166 && path[1].toLowerCase().equals("analysis"))
168 switch (path[path.length - 1].toLowerCase())
170 case "rna secondary structure prediction":
171 op = new OperationStub(webService, "Secondary Structure Prediction");
172 op.setInteractive(true);
173 op.setAlignmentAnalysis(true);
174 op.setProteinOperation(false);
176 case "sequence alignment analysis (conservation)":
177 op = new OperationStub(webService, "Conservation");
178 op.setAlignmentAnalysis(true);
179 op.setInteractive(true);
181 case "protein sequence analysis":
182 op = new OperationStub(webService, "Protein Disorder");
184 case "multiple sequence alignment":
185 op = new OperationStub(webService, "Alignment");
195 allOperations.add(op);
199 this.operations = allOperations;
200 Cache.log.info("Reloading slivka services finished");
201 return allOperations;
205 public String getErrorMessages()