JAL-3066 Read parameters directly from args list allowing for multiple values.
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Wed, 9 Oct 2019 15:40:19 +0000 (16:40 +0100)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Wed, 9 Oct 2019 16:52:35 +0000 (17:52 +0100)
j11lib/slivka-client.jar
src/jalview/ws/slivkaws/SlivkaMsaServiceInstance.java

index 28a92da..1725efb 100644 (file)
Binary files a/j11lib/slivka-client.jar and b/j11lib/slivka-client.jar differ
index db1577e..f09ba16 100644 (file)
@@ -16,9 +16,10 @@ import java.io.IOError;
 import java.io.IOException;
 import java.io.InputStream;
 import java.rmi.ServerError;
-import java.util.HashMap;
 import java.util.List;
+import java.util.Optional;
 
+import uk.ac.dundee.compbio.slivkaclient.FieldType;
 import uk.ac.dundee.compbio.slivkaclient.FormField;
 import uk.ac.dundee.compbio.slivkaclient.RemoteFile;
 import uk.ac.dundee.compbio.slivkaclient.SlivkaClient;
@@ -44,26 +45,25 @@ public class SlivkaMsaServiceInstance extends SlivkaWSInstance implements Multip
     InputStream stream = new ByteArrayInputStream(builder.toString().getBytes());
     RemoteFile file = client.uploadFile(stream, "input.fasta", "application/fasta");
     SlivkaForm form = service.getForm();
-    HashMap<String, String> values = new HashMap<>(list != null ? list.size() : 0);
+    Optional<FormField> inputField = form.getFields().stream()
+        .filter(f -> f.getType() == FieldType.FILE).findFirst();
+    if (inputField.isPresent())
+    {
+      form.insert(inputField.get().getName(), file);
+    }
     if (list != null)
     {
       for (ArgumentI arg : list)
       {
-        values.put(arg.getName(), arg.getValue());
-      }
-    }
-    for (FormField field : form.getFields())
-    {
-      switch (field.getType()) {
-      case FILE:
-        form.insert(field.getName(), file);
-        break;
-      case BOOLEAN:
-        String value = values.get(field.getName());
-        form.insert(field.getName(), (value != null && !value.isBlank()) ? true : false);
-        break;
-      default:
-        form.insert(field.getName(), field.valueOf(values.get(field.getName())));
+        FormField field = form.getField(arg.getName());
+        if (field.getType() == FieldType.BOOLEAN)
+        {
+          form.insert(arg.getName(), (arg.getValue() != null && !arg.getValue().isBlank()) ? true : false);
+        }
+        else
+        {
+          form.insert(arg.getName(), field.valueOf(arg.getValue()));
+        }
       }
     }
     return new JobId(service.getName(), service.getName(), form.submit());