JAL-3848 Update slivka client library.
[jalview.git] / src / jalview / ws / slivkaws / SlivkaAnnotationServiceInstance.java
index 3a5899b..3c80fbc 100644 (file)
@@ -16,33 +16,29 @@ import jalview.ws.params.ArgumentI;
 import jalview.ws.params.WsParamSetI;
 import jalview.ws.uimodel.AlignAnalysisUIText;
 
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
 import java.io.IOError;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.util.Arrays;
-import java.util.HashMap;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
-import uk.ac.dundee.compbio.slivkaclient.FormField;
+import compbio.data.msa.Category;
 import uk.ac.dundee.compbio.slivkaclient.RemoteFile;
 import uk.ac.dundee.compbio.slivkaclient.SlivkaClient;
-import uk.ac.dundee.compbio.slivkaclient.SlivkaForm;
 import uk.ac.dundee.compbio.slivkaclient.SlivkaService;
 
 public class SlivkaAnnotationServiceInstance extends SlivkaWSInstance implements SequenceAnnotationServiceI
 {
   public SlivkaAnnotationServiceInstance(SlivkaClient client,
-          SlivkaService service, boolean conservation)
+          SlivkaService service, String category)
   {
-    super(client, service, !conservation ? "Annotations disorder"
-            : "Alignment Conservation");
-    if (conservation)
+    super(client, service, category);
+    if (category == Category.CATEGORY_CONSERVATION)
     {
-      setAlignAnalysisUI(new AlignAnalysisUIText(service.getName(),
+      /* FIXME: the category name is hardcoded for AACon, names other than
+       * "AAConWS" doesn't work. */
+      setAlignAnalysisUI(new AlignAnalysisUIText(getName(),
               SlivkaAnnotationServiceInstance.class,
               "Slivka.AACons", false, true, true, true, true, 2,
               MessageManager.getString("label.aacon_calculations"),
@@ -56,43 +52,11 @@ public class SlivkaAnnotationServiceInstance extends SlivkaWSInstance implements
   @Override
   public JobId submitToService(List<SequenceI> seqs, WsParamSetI preset, List<ArgumentI> paramset) throws Throwable
   {
-    StringBuilder builder = new StringBuilder();
-    for (SequenceI seq : seqs)
-    {
-      builder.append(">").append(seq.getName()).append("\n");
-      builder.append(seq.getSequence()).append("\n");
-    }
-    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<>(paramset != null ? paramset.size() : 0);
-    if (paramset != null)
-    {
-      for (ArgumentI arg : paramset)
-      {
-        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())));
-      }
-    }
-    return new JobId(service.getName(), service.getName(), form.submit());
+    return super.submit(seqs, preset, paramset);
   }
 
   @Override
-  public List<AlignmentAnnotation> getAnnotationResult(JobId job,
+  public List<AlignmentAnnotation> getAnnotationResult(JobId jobId,
           List<SequenceI> seqs, Map<String, FeatureColourI> featureColours,
           Map<String, FeatureMatcherSetI> featureFilters) throws Throwable
   {
@@ -100,14 +64,15 @@ public class SlivkaAnnotationServiceInstance extends SlivkaWSInstance implements
     RemoteFile featFile = null;
     try
     {
-      List<RemoteFile> files = client.getJobResults(job.getJobId());
+      var slivkaJob = client.getJob(jobId.getJobId());
+      Collection<RemoteFile> files = slivkaJob.getResults();
       for (RemoteFile f : files)
       {
-        if (f.getMimeType().equals("application/jalview-annotations"))
+        if (f.getMediaType().equals("application/jalview-annotations"))
         {
           annotFile = f;
         }
-        else if (f.getMimeType().equals("application/jalview-features"))
+        else if (f.getMediaType().equals("application/jalview-features"))
         {
           featFile = f;
         }
@@ -117,18 +82,21 @@ public class SlivkaAnnotationServiceInstance extends SlivkaWSInstance implements
       throw new IOError(e);
     }
     Alignment aln = new Alignment(seqs.toArray(new SequenceI[0]));
-    BufferedReader readerIn = new BufferedReader(new InputStreamReader(annotFile.getContent()));
-    if (!new AnnotationFile().parseAnnotationFrom(aln, null, readerIn))
+    if (annotFile == null
+        || !new AnnotationFile().readAnnotationFile(aln, annotFile.getContentUrl().toString(), DataSourceType.URL))
     {
       Cache.log.debug("No annotation from slivka job\n" + annotFile);
     }
-    if (featFile != null)
+    else {
+      Cache.log.debug("Annotation file loaded " + annotFile);
+    }
+    if (featFile == null
+        || !new FeaturesFile(featFile.getContentUrl().toString(), DataSourceType.URL).parse(aln, featureColours, true))
     {
-      if (!new FeaturesFile(featFile.getURL().toString(),
-              DataSourceType.URL).parse(aln, featureColours, true))
-      {
-        Cache.log.debug("No features from slivka job\n" + featFile);
-      }
+      Cache.log.debug("No features from slivka job\n" + featFile);
+    }
+    else {
+      Cache.log.debug("Features feil loaded " + featFile);
     }
     return Arrays.asList(aln.getAlignmentAnnotation());
   }