From: Mateusz Warowny Date: Wed, 14 Jun 2023 14:24:35 +0000 (+0200) Subject: JAL-4199 Update slivka client X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=df8e2545932852b0f257a3d67b33996afdfd259b;p=jalview.git JAL-4199 Update slivka client This is a library update that moves all client functionality to SlivkaClient class, making all other classes simple data objects. --- diff --git a/j11lib/slivka-client.jar b/j11lib/slivka-client.jar index 49ab4fc..3c5290d 100644 Binary files a/j11lib/slivka-client.jar and b/j11lib/slivka-client.jar differ diff --git a/src/jalview/ws/slivkaws/SlivkaAnnotationServiceInstance.java b/src/jalview/ws/slivkaws/SlivkaAnnotationServiceInstance.java index 999951a..5c98cbe 100644 --- a/src/jalview/ws/slivkaws/SlivkaAnnotationServiceInstance.java +++ b/src/jalview/ws/slivkaws/SlivkaAnnotationServiceInstance.java @@ -65,8 +65,7 @@ public class SlivkaAnnotationServiceInstance extends SlivkaWSInstance implements RemoteFile featFile = null; try { - var slivkaJob = client.getJob(jobId.getJobId()); - Collection files = slivkaJob.getResults(); + Collection files = client.fetchFilesList(jobId.getJobId()); for (RemoteFile f : files) { if (f.getMediaType().equals("application/jalview-annotations")) diff --git a/src/jalview/ws/slivkaws/SlivkaMsaServiceInstance.java b/src/jalview/ws/slivkaws/SlivkaMsaServiceInstance.java index 374d2eb..337073e 100644 --- a/src/jalview/ws/slivkaws/SlivkaMsaServiceInstance.java +++ b/src/jalview/ws/slivkaws/SlivkaMsaServiceInstance.java @@ -40,8 +40,7 @@ public class SlivkaMsaServiceInstance extends SlivkaWSInstance implements Multip Collection files; try { - var slivkaJob = client.getJob(jobId.getJobId()); - files = slivkaJob.getResults(); + files = client.fetchFilesList(jobId.getJobId()); for (RemoteFile f : files) { if (f.getMediaType().equals("application/clustal")) diff --git a/src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java b/src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java index d21d5d1..104560a 100644 --- a/src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java +++ b/src/jalview/ws/slivkaws/SlivkaWSDiscoverer.java @@ -94,7 +94,7 @@ public class SlivkaWSDiscoverer implements WSDiscovererI for (String url : getServiceUrls()) { - SlivkaClient client = new SlivkaClient(url); + SlivkaClient client = SlivkaClient.newInstance(url); List services; try @@ -220,7 +220,7 @@ public class SlivkaWSDiscoverer implements WSDiscovererI { try { - List services = new SlivkaClient(url).getServices(); + List services = SlivkaClient.newInstance(url).getServices(); return services.isEmpty() ? STATUS_NO_SERVICES : STATUS_OK; } catch (IOException | org.json.JSONException e) { diff --git a/src/jalview/ws/slivkaws/SlivkaWSInstance.java b/src/jalview/ws/slivkaws/SlivkaWSInstance.java index 613c702..d3701ac 100644 --- a/src/jalview/ws/slivkaws/SlivkaWSInstance.java +++ b/src/jalview/ws/slivkaws/SlivkaWSInstance.java @@ -30,7 +30,7 @@ import javajs.http.ClientProtocolException; import java.util.Collection; import uk.ac.dundee.compbio.slivkaclient.Job; -import uk.ac.dundee.compbio.slivkaclient.JobRequest; +import uk.ac.dundee.compbio.slivkaclient.RequestValues; import uk.ac.dundee.compbio.slivkaclient.Parameter; import uk.ac.dundee.compbio.slivkaclient.RemoteFile; import uk.ac.dundee.compbio.slivkaclient.SlivkaClient; @@ -75,7 +75,7 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters WsParamSetI preset, List args) throws Throwable { var parameters = service.getParameters(); - var request = new JobRequest(); + var request = new RequestValues(); for (Parameter param : parameters) { if (param instanceof Parameter.FileParameter) @@ -126,8 +126,8 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters } } } - var job = service.submitJob(request); - return new JobId(service.getName(), service.getName(), job.getId()); + var jobId = client.submitJob(service, request); + return new JobId(service.getName(), service.getName(), jobId); } @Override @@ -135,8 +135,7 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters { try { - var slivkaJob = client.getJob(job.getJobId()); - job.setState(stateMap.get(slivkaJob.getStatus())); + job.setState(stateMap.get(client.fetchJobStatus(job.getJobId()))); } catch (IOException e) { throw new IOError(e); @@ -146,8 +145,7 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters @Override public final boolean updateJobProgress(WsJob job) throws IOException { - var slivkaJob = client.getJob(job.getJobId()); - Collection files = slivkaJob.getResults(); + Collection files = client.fetchFilesList(job.getJobId()); RemoteFile logFile=null; for (RemoteFile f : files) { @@ -161,7 +159,7 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters if (logFile!=null) { ByteArrayOutputStream output = new ByteArrayOutputStream(); - logFile.writeTo(output); + client.writeFileTo(logFile, output); if (output.size() > job.getNextChunk()) { newContent = true; @@ -185,7 +183,7 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters if (errLogFile!=null) { ByteArrayOutputStream output = new ByteArrayOutputStream(); - errLogFile.writeTo(output); + client.writeFileTo(errLogFile, output); if (output.size() > 0) { newContent = true; diff --git a/src/jalview/ws2/client/slivka/SlivkaWSClient.java b/src/jalview/ws2/client/slivka/SlivkaWSClient.java index bef502b..7dcdae1 100644 --- a/src/jalview/ws2/client/slivka/SlivkaWSClient.java +++ b/src/jalview/ws2/client/slivka/SlivkaWSClient.java @@ -46,10 +46,10 @@ public class SlivkaWSClient implements WebServiceClientI final SlivkaClient client; - SlivkaWSClient(SlivkaService service) + SlivkaWSClient(SlivkaClient client, SlivkaService service) { this.service = service; - this.client = service.getClient(); + this.client = client; } @Override @@ -72,7 +72,7 @@ public class SlivkaWSClient implements WebServiceClientI public WebServiceJobHandle submit(List sequences, List args, Credentials credentials) throws IOException { - var request = new uk.ac.dundee.compbio.slivkaclient.JobRequest(); + var request = new uk.ac.dundee.compbio.slivkaclient.RequestValues(); for (Parameter param : service.getParameters()) { // TODO: restrict input sequences parameter name to "sequences" @@ -131,8 +131,8 @@ public class SlivkaWSClient implements WebServiceClientI } } } - var job = service.submitJob(request); - return createJobHandle(job.getId()); + var jobId = client.submitJob(service, request); + return createJobHandle(jobId); } protected WebServiceJobHandle createJobHandle(String jobId) @@ -145,8 +145,7 @@ public class SlivkaWSClient implements WebServiceClientI @Override public JobStatus getStatus(WebServiceJobHandle job) throws IOException { - var slivkaJob = client.getJob(job.getJobId()); - return statusMap.getOrDefault(slivkaJob.getStatus(), JobStatus.UNKNOWN); + return statusMap.getOrDefault(client.fetchJobStatus(job.getJobId()), JobStatus.UNKNOWN); } protected static final EnumMap statusMap = new EnumMap<>(Job.Status.class); @@ -168,13 +167,12 @@ public class SlivkaWSClient implements WebServiceClientI @Override public String getLog(WebServiceJobHandle job) throws IOException { - var slivkaJob = client.getJob(job.getJobId()); - for (var f : slivkaJob.getResults()) + for (var f : client.fetchFilesList(job.getJobId())) { if (f.getLabel().equals("log")) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); - f.writeTo(stream); + client.writeFileTo(f, stream); return stream.toString("UTF-8"); } } @@ -184,13 +182,12 @@ public class SlivkaWSClient implements WebServiceClientI @Override public String getErrorLog(WebServiceJobHandle job) throws IOException { - var slivkaJob = client.getJob(job.getJobId()); - for (var f : slivkaJob.getResults()) + for (var f : client.fetchFilesList(job.getJobId())) { if (f.getLabel().equals("error-log")) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); - f.writeTo(stream); + client.writeFileTo(f, stream); return stream.toString("UTF-8"); } } @@ -210,16 +207,15 @@ class SlivkaAlignmentWSClient extends SlivkaWSClient implements AlignmentWebServiceClientI { - SlivkaAlignmentWSClient(SlivkaService service) + SlivkaAlignmentWSClient(SlivkaClient client, SlivkaService service) { - super(service); + super(client, service); } @Override public AlignmentI getAlignment(WebServiceJobHandle job) throws IOException { - var slivkaJob = client.getJob(job.getJobId()); - for (var f : slivkaJob.getResults()) + for (var f : client.fetchFilesList(job.getJobId())) { // TODO: restrict result file label to "alignment" FileFormat format; @@ -245,9 +241,9 @@ class SlivkaAlignmentWSClient extends SlivkaWSClient class SlivkaAnnotationWSClient extends SlivkaWSClient implements AnnotationWebServiceClientI { - SlivkaAnnotationWSClient(SlivkaService service) + SlivkaAnnotationWSClient(SlivkaClient client, SlivkaService service) { - super(service); + super(client, service); } @Override @@ -255,10 +251,9 @@ class SlivkaAnnotationWSClient extends SlivkaWSClient List sequences, Map colours, Map filters) throws IOException { - var slivkaJob = client.getJob(job.getJobId()); var aln = new Alignment(sequences.toArray(new SequenceI[sequences.size()])); boolean featPresent = false, annotPresent = false; - for (var f : slivkaJob.getResults()) + for (var f : client.fetchFilesList(job.getJobId())) { // TODO: restrict file label to "annotations" or "features" var match = mediaTypePattern.matcher(f.getMediaType()); diff --git a/src/jalview/ws2/client/slivka/SlivkaWSDiscoverer.java b/src/jalview/ws2/client/slivka/SlivkaWSDiscoverer.java index 70e1c94..2509a19 100644 --- a/src/jalview/ws2/client/slivka/SlivkaWSDiscoverer.java +++ b/src/jalview/ws2/client/slivka/SlivkaWSDiscoverer.java @@ -2,10 +2,12 @@ package jalview.ws2.client.slivka; import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.function.Function; import jalview.bin.Cache; import jalview.bin.Console; @@ -36,15 +38,18 @@ public class SlivkaWSDiscoverer extends AbstractWebServiceDiscoverer private static SlivkaWSDiscoverer instance = null; private static ParamManager paramManager = null; + + private final Function clientFactory; - private SlivkaWSDiscoverer() + SlivkaWSDiscoverer(Function clientFactory) { + this.clientFactory = clientFactory; } public static SlivkaWSDiscoverer getInstance() { if (instance == null) - instance = new SlivkaWSDiscoverer(); + instance = new SlivkaWSDiscoverer(SlivkaClient::newInstance); return instance; } @@ -58,8 +63,12 @@ public class SlivkaWSDiscoverer extends AbstractWebServiceDiscoverer { try { - List services = new SlivkaClient(url.toString()).getServices(); + List services = clientFactory.apply(url.toURI()).getServices(); return services.isEmpty() ? STATUS_NO_SERVICES : STATUS_OK; + } catch (URISyntaxException e) + { + Console.error("invalid URL " + url, e); + return STATUS_INVALID; } catch (IOException e) { Console.error("slivka could not retrieve services from " + url, e); @@ -86,7 +95,7 @@ public class SlivkaWSDiscoverer extends AbstractWebServiceDiscoverer SlivkaClient slivkaClient; try { - slivkaClient = new SlivkaClient(url.toURI()); + slivkaClient = clientFactory.apply(url.toURI()); } catch (URISyntaxException e) { throw new MalformedURLException(e.getMessage()); @@ -97,14 +106,14 @@ public class SlivkaWSDiscoverer extends AbstractWebServiceDiscoverer if (serviceClass == SERVICE_CLASS_MSA) { var wsb = WebService. newBuilder(); - initServiceBuilder(slivkaService, wsb); + initServiceBuilder(slivkaClient, slivkaService, wsb); wsb.category("Alignment"); wsb.interactive(false); wsb.actionClass(AlignmentAction.class); var msaService = wsb.build(); boolean canRealign = msaService.getName().contains("lustal"); - var client = new SlivkaAlignmentWSClient(slivkaService); + var client = new SlivkaAlignmentWSClient(slivkaClient, slivkaService); var actionBuilder = AlignmentAction.newBuilder(client); actionBuilder.name("Alignment"); actionBuilder.webService(msaService); @@ -124,12 +133,12 @@ public class SlivkaWSDiscoverer extends AbstractWebServiceDiscoverer else if (serviceClass == SERVICE_CLASS_PROT_SEQ_ANALYSIS) { var wsb = WebService. newBuilder(); - initServiceBuilder(slivkaService, wsb); + initServiceBuilder(slivkaClient, slivkaService, wsb); wsb.category("Protein Disorder"); wsb.interactive(false); wsb.actionClass(AnnotationAction.class); var psaService = wsb.build(); - var client = new SlivkaAnnotationWSClient(slivkaService); + var client = new SlivkaAnnotationWSClient(slivkaClient, slivkaService); var actionBuilder = AnnotationAction.newBuilder(client); actionBuilder.webService(psaService); actionBuilder.name("Analysis"); @@ -139,12 +148,12 @@ public class SlivkaWSDiscoverer extends AbstractWebServiceDiscoverer else if (serviceClass == SERVICE_CLASS_CONSERVATION) { var wsb = WebService. newBuilder(); - initServiceBuilder(slivkaService, wsb); + initServiceBuilder(slivkaClient, slivkaService, wsb); wsb.category("Conservation"); wsb.interactive(true); wsb.actionClass(AnnotationAction.class); var conService = wsb.build(); - var client = new SlivkaAnnotationWSClient(slivkaService); + var client = new SlivkaAnnotationWSClient(slivkaClient, slivkaService); var actionBuilder = AnnotationAction.newBuilder(client); actionBuilder.webService(conService); actionBuilder.name(""); @@ -157,12 +166,12 @@ public class SlivkaWSDiscoverer extends AbstractWebServiceDiscoverer else if (serviceClass == SERVICE_CLASS_RNA_SEC_STR_PRED) { var wsb = WebService. newBuilder(); - initServiceBuilder(slivkaService, wsb); + initServiceBuilder(slivkaClient, slivkaService, wsb); wsb.category("Secondary Structure Prediction"); wsb.interactive(true); wsb.actionClass(AnnotationAction.class); var predService = wsb.build(); - var client = new SlivkaAnnotationWSClient(slivkaService); + var client = new SlivkaAnnotationWSClient(slivkaClient, slivkaService); var actionBuilder = AnnotationAction.newBuilder(client); actionBuilder.webService(predService); actionBuilder.name("Prediction"); @@ -183,11 +192,11 @@ public class SlivkaWSDiscoverer extends AbstractWebServiceDiscoverer return allServices; } - private void initServiceBuilder(SlivkaService service, WebService.Builder wsBuilder) + private void initServiceBuilder(SlivkaClient client, SlivkaService service, WebService.Builder wsBuilder) { try { - wsBuilder.url(service.getClient().getUrl().toURL()); + wsBuilder.url(client.getUrl().toURL()); } catch (MalformedURLException e) { e.printStackTrace(); diff --git a/utils/jalviewjs/libjs/slivka-client-site.zip b/utils/jalviewjs/libjs/slivka-client-site.zip index 2e64029..c0b582d 100644 Binary files a/utils/jalviewjs/libjs/slivka-client-site.zip and b/utils/jalviewjs/libjs/slivka-client-site.zip differ