JAL-3878 Refactoring SeqAnnotationServiceCalcWorker.
[jalview.git] / src / jalview / ws2 / operations / AlignmentOperation.java
index 14564d6..89aeb79 100644 (file)
@@ -45,7 +45,7 @@ import jalview.ws2.MenuEntryProviderI;
 import jalview.ws2.ResultSupplier;
 import jalview.ws2.WSJob;
 import jalview.ws2.WSJobStatus;
-import jalview.ws2.WebServiceExecutor;
+import jalview.ws2.PollingTaskExecutor;
 import jalview.ws2.WebServiceI;
 import jalview.ws2.WebServiceInfoUpdater;
 import jalview.ws2.WebServiceWorkerI;
@@ -110,6 +110,12 @@ public class AlignmentOperation implements Operation
   {
     return true;
   }
+  
+  @Override
+  public boolean isAlignmentAnalysis()
+  {
+    return false;
+  }
 
   @Override
   public boolean canSubmitGaps()
@@ -123,6 +129,18 @@ public class AlignmentOperation implements Operation
   {
     return false;
   }
+  
+  @Override
+  public boolean getFilterNonStandardSymbols()
+  {
+    return true;
+  }
+  
+  @Override
+  public boolean getNeedsAlignedSequences()
+  {
+    return false;
+  }
 
   @Override
   public MenuEntryProviderI getMenuBuilder()
@@ -157,7 +175,7 @@ public class AlignmentOperation implements Operation
     final var calcName = service.getName();
 
     String title = frame.getTitle();
-    WebServiceExecutor executor = frame.getViewport().getWSExecutor();
+    PollingTaskExecutor executor = frame.getViewport().getWSExecutor();
     {
       var item = new JMenuItem(MessageManager.formatMessage(
               "label.calcname_with_default_settings", calcName));
@@ -302,6 +320,8 @@ public class AlignmentOperation implements Operation
 
     private final AlignmentI dataset;
 
+    private final AlignViewport viewport;
+
     private final List<AlignedCodonFrame> codonFrame = new ArrayList<>();
 
     private List<ArgumentI> args = Collections.emptyList();
@@ -337,6 +357,7 @@ public class AlignmentOperation implements Operation
       this.alnTitle = alnTitle;
       this.submitGaps = submitGaps;
       this.preserveOrder = preserveOrder;
+      this.viewport = viewport;
       this.gapCharacter = viewport.getGapCharacter();
 
       String panelInfo = String.format("%s using service hosted at %s%n%s",
@@ -364,8 +385,9 @@ public class AlignmentOperation implements Operation
     }
 
     @Override
-    public void startJobs() throws IOException
+    public void start() throws IOException
     {
+      Cache.log.info(format("Starting new %s job.", service.getName()));
       String outputHeader = String.format("%s of %s%nJob details%n",
               submitGaps ? "Re-alignment" : "Alignment", alnTitle);
       SequenceI[][] conmsa = msa.getVisibleContigs('-');
@@ -382,7 +404,7 @@ public class AlignmentOperation implements Operation
         WSJob job = new WSJob(service.getProviderName(), service.getName(),
                 service.getHostName());
         job.setJobNum(wsInfo.addJobPane());
-        if (conmsa.length > 0)
+        if (conmsa.length > 1)
         {
           wsInfo.setProgressName(String.format("region %d", i),
                   job.getJobNum());
@@ -443,12 +465,12 @@ public class AlignmentOperation implements Operation
     }
 
     @Override
-    public boolean pollJobs()
+    public boolean poll()
     {
       boolean done = true;
       for (WSJob job : getJobs())
       {
-        if (!job.getStatus().isDone())
+        if (!job.getStatus().isDone() && !job.getStatus().isFailed())
         {
           Cache.log.debug(format("Polling job %s.", job));
           try
@@ -479,7 +501,7 @@ public class AlignmentOperation implements Operation
           Cache.log.debug(
                   format("Job %s status is %s", job, job.getStatus()));
         }
-        done &= job.getStatus().isDone();
+        done &= job.getStatus().isDone() || job.getStatus().isFailed();
       }
       updateWSInfoGlobalStatus();
       return done;
@@ -523,9 +545,11 @@ public class AlignmentOperation implements Operation
       Map<Long, AlignmentI> results = new LinkedHashMap<>();
       for (WSJob job : getJobs())
       {
+        if (job.getStatus().isFailed())
+          continue;
         try
         {
-          AlignmentI alignment = supplier.getResult(job);
+          AlignmentI alignment = supplier.getResult(job, dataset.getSequences(), viewport);
           if (alignment != null)
           {
             results.put(job.getUid(), alignment);
@@ -789,8 +813,8 @@ public class AlignmentOperation implements Operation
         }
         else
         {
-          String seqString = null;
-          if (seq.getEnd() >= seq.getStart()) // is it ever false?
+          String seqString = "";
+          if (seq.getEnd() >= seq.getStart())  // true if gaps only
           {
             seqString = seq.getSequenceAsString();
             if (!submitGaps)