From: Mateusz Date: Thu, 21 Jan 2021 15:44:25 +0000 (+0100) Subject: Merge branch 'feature/JAL-3690_callback-based-web-services' into alpha/JAL-3066_Jalvi... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4898f0ae429e0c61ddba72ca46be89b34bb4df8b;hp=-c;p=jalview.git Merge branch 'feature/JAL-3690_callback-based-web-services' into alpha/JAL-3066_Jalview_212_slivka-integration --- 4898f0ae429e0c61ddba72ca46be89b34bb4df8b diff --combined src/jalview/ws/slivkaws/SlivkaWSInstance.java index 8a16edb,8456b55..75e5722 --- a/src/jalview/ws/slivkaws/SlivkaWSInstance.java +++ b/src/jalview/ws/slivkaws/SlivkaWSInstance.java @@@ -2,8 -2,6 +2,8 @@@ package jalview.ws.slivkaws import jalview.datamodel.SequenceI; import jalview.gui.WebserviceInfo; +import jalview.io.FileFormat; +import jalview.io.FormatAdapter; import jalview.ws.api.JalviewServiceEndpointProviderI; import jalview.ws.api.JalviewWebServiceI; import jalview.ws.api.JobId; @@@ -27,7 -25,6 +27,7 @@@ import java.util.Optional import java.util.Set; import uk.ac.dundee.compbio.slivkaclient.FieldType; +import uk.ac.dundee.compbio.slivkaclient.FileField; import uk.ac.dundee.compbio.slivkaclient.FormField; import uk.ac.dundee.compbio.slivkaclient.FormValidationException; import uk.ac.dundee.compbio.slivkaclient.JobState; @@@ -54,7 -51,7 +54,7 @@@ public abstract class SlivkaWSInstance stateMap.put(JobState.QUEUED, WsJob.JobState.QUEUED); stateMap.put(JobState.RUNNING, WsJob.JobState.RUNNING); stateMap.put(JobState.COMPLETED, WsJob.JobState.FINISHED); - stateMap.put(JobState.INTERRUPED, WsJob.JobState.CANCELLED); + stateMap.put(JobState.INTERRUPTED, WsJob.JobState.CANCELLED); stateMap.put(JobState.DELETED, WsJob.JobState.CANCELLED); stateMap.put(JobState.FAILED, WsJob.JobState.FAILED); stateMap.put(JobState.ERROR, WsJob.JobState.SERVERERROR); @@@ -67,7 -64,7 +67,7 @@@ public SlivkaWSInstance(SlivkaClient client, SlivkaService service, String action) { - super(service.getName(), action, service.getLabel(), "Slivka", client.getUrl().toString()); + super(action, action, service.getLabel(), "Slivka", client.getUrl().toString()); this.client = client; this.service = service; } @@@ -76,34 -73,21 +76,34 @@@ WsParamSetI preset, List args) throws Throwable { SlivkaForm form = service.getForm(); - Optional inputField = form.getFields().stream() - .filter(f -> f.getType() == FieldType.FILE).findFirst(); - if (inputField.isPresent()) + for (FormField field : form.getFields()) { - StringBuilder builder = new StringBuilder(); - for (SequenceI seq : sequences) + if (field.getType() == FieldType.FILE) { - builder.append(">").append(seq.getName()).append("\n") - .append(seq.getSequence()).append("\n"); + FormatAdapter fa = new FormatAdapter(); + fa.setNewlineString("\r\n"); + FileField fileField = (FileField) field; + FileFormat format; + switch (fileField.getMediaType()) + { + case "application/pfam": + format = FileFormat.Pfam; + break; + case "application/stockholm": + format = FileFormat.Stockholm; + break; + default: + case "application/fasta": + format = FileFormat.Fasta; + break; + } + InputStream stream = new ByteArrayInputStream( + fa.formatSequences(format, sequences.toArray(new SequenceI[0])) + .getBytes()); + RemoteFile rf = client.uploadFile(stream, "input", + fileField.getMediaType()); + form.insert(field.getName(), rf); } - InputStream stream = new ByteArrayInputStream( - builder.toString().getBytes()); - RemoteFile file = client.uploadFile(stream, "input.fa", - "application/fasta"); - form.insert(inputField.get().getName(), file); } if (args != null) { @@@ -145,13 -129,20 +145,20 @@@ public final boolean updateJobProgress(WsJob job) throws IOException { List files = client.getJobResults(job.getJobId()); - Optional logFile = files.stream() - .filter(f -> f.getLabel().equals("log")).findFirst(); + RemoteFile logFile=null; + for (RemoteFile f : files) + { + if (f.getLabel().equals("log")) + { + logFile = f; break; + } + } + boolean newContent = false; - if (logFile.isPresent()) + if (logFile!=null) { ByteArrayOutputStream output = new ByteArrayOutputStream(); - logFile.get().writeTo(output); + logFile.writeTo(output); if (output.size() > job.getNextChunk()) { newContent = true; @@@ -161,12 -152,21 +168,21 @@@ } if (failedStates.contains(job.getJobState())) { - Optional errLogFile = files.stream() - .filter(f -> f.getLabel().equals("error-log")).findFirst(); - if (errLogFile.isPresent()) + + RemoteFile errLogFile = null; + for (RemoteFile f : files) + { + if (f.getLabel().equals("error-log")) + { + errLogFile = f; + break; + } + } + + if (errLogFile!=null) { ByteArrayOutputStream output = new ByteArrayOutputStream(); - errLogFile.get().writeTo(output); + errLogFile.writeTo(output); if (output.size() > 0) { newContent = true;