Implement simple media type recognition.
authorMMWarowny <mmzwarowny@dundee.ac.uk>
Thu, 6 Feb 2020 17:25:05 +0000 (17:25 +0000)
committerMMWarowny <mmzwarowny@dundee.ac.uk>
Thu, 6 Feb 2020 17:25:05 +0000 (17:25 +0000)
j11lib/slivka-client.jar
src/jalview/ws/slivkaws/SlivkaWSInstance.java

index b29679f..6c289d1 100644 (file)
Binary files a/j11lib/slivka-client.jar and b/j11lib/slivka-client.jar differ
index 952aab6..fd89a2e 100644 (file)
@@ -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<ArgumentI> args) throws Throwable
   {
     SlivkaForm form = service.getForm();
-    Optional<FormField> 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)
     {