From: MMWarowny Date: Thu, 6 Feb 2020 17:25:05 +0000 (+0000) Subject: Implement simple media type recognition. X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=d02166c8801f0005ac9c1fbffdf0c26c7ca912aa;p=jalview.git Implement simple media type recognition. --- diff --git a/j11lib/slivka-client.jar b/j11lib/slivka-client.jar index b29679f..6c289d1 100644 Binary files a/j11lib/slivka-client.jar and b/j11lib/slivka-client.jar differ diff --git a/src/jalview/ws/slivkaws/SlivkaWSInstance.java b/src/jalview/ws/slivkaws/SlivkaWSInstance.java index 952aab6..fd89a2e 100644 --- a/src/jalview/ws/slivkaws/SlivkaWSInstance.java +++ b/src/jalview/ws/slivkaws/SlivkaWSInstance.java @@ -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; @@ -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; @@ -73,21 +76,34 @@ public abstract class SlivkaWSInstance extends ServiceWithParameters 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) {