JAL-3949 - refactor logging from jalview.bin.Cache to jalview.bin.Console
[jalview.git] / src / jalview / ws / jws1 / MsaWSThread.java
index 3807a26..e027038 100644 (file)
@@ -1,32 +1,44 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  * Jalview is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License 
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
  *  
  * Jalview is distributed in the hope that it will be useful, but 
  * WITHOUT ANY WARRANTY; without even the implied warranty 
  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
  * PURPOSE.  See the GNU General Public License for more details.
  * 
- * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
  * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
 package jalview.ws.jws1;
 
-import java.util.*;
-
-import jalview.analysis.*;
-import jalview.bin.*;
-import jalview.datamodel.*;
-import jalview.gui.*;
+import jalview.analysis.AlignSeq;
+import jalview.bin.Console;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.AlignmentOrder;
+import jalview.datamodel.AlignmentView;
+import jalview.datamodel.HiddenColumns;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
+import jalview.gui.Desktop;
+import jalview.gui.WebserviceInfo;
+import jalview.util.MessageManager;
 import jalview.ws.AWsJob;
 import jalview.ws.JobStateSummary;
 import jalview.ws.WSClientI;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
 import vamsas.objects.simple.MsaResult;
 
 class MsaWSThread extends JWS1Thread implements WSClientI
@@ -61,7 +73,7 @@ class MsaWSThread extends JWS1Thread implements WSClientI
         subjobComplete = true;
         result = new MsaResult();
         result.setFinished(true);
-        result.setStatus("Job never ran - input returned to user.");
+        result.setStatus(MessageManager.getString("label.job_never_ran"));
       }
 
     }
@@ -84,8 +96,8 @@ class MsaWSThread extends JWS1Thread implements WSClientI
       int nseqs = 0;
       if (minlen < 0)
       {
-        throw new Error(
-                "Implementation error: minlen must be zero or more.");
+        throw new Error(MessageManager.getString(
+                "error.implementation_error_minlen_must_be_greater_zero"));
       }
       for (int i = 0; i < seqs.length; i++)
       {
@@ -95,7 +107,8 @@ class MsaWSThread extends JWS1Thread implements WSClientI
         }
       }
       boolean valid = nseqs > 1; // need at least two seqs
-      vamsas.objects.simple.Sequence[] seqarray = (valid) ? new vamsas.objects.simple.Sequence[nseqs]
+      vamsas.objects.simple.Sequence[] seqarray = (valid)
+              ? new vamsas.objects.simple.Sequence[nseqs]
               : null;
       for (int i = 0, n = 0; i < seqs.length; i++)
       {
@@ -119,12 +132,11 @@ class MsaWSThread extends JWS1Thread implements WSClientI
           String empty = null;
           if (seqs[i].getEnd() >= seqs[i].getStart())
           {
-            empty = (submitGaps) ? seqs[i].getSequenceAsString() : AlignSeq
-                    .extractGaps(jalview.util.Comparison.GapChars,
+            empty = (submitGaps) ? seqs[i].getSequenceAsString()
+                    : AlignSeq.extractGaps(jalview.util.Comparison.GapChars,
                             seqs[i].getSequenceAsString());
           }
-          emptySeqs.add(new String[]
-          { newname, empty });
+          emptySeqs.add(new String[] { newname, empty });
         }
       }
       this.seqs = new vamsas.objects.simple.SequenceSet();
@@ -136,6 +148,7 @@ class MsaWSThread extends JWS1Thread implements WSClientI
      * 
      * @return true if getAlignment will return a valid alignment result.
      */
+    @Override
     public boolean hasResults()
     {
       if (subjobComplete && result != null && result.isFinished()
@@ -243,8 +256,7 @@ class MsaWSThread extends JWS1Thread implements WSClientI
         jalview.analysis.AlignmentSorter.recoverOrder(alseqs);
         // account for any missing sequences
         jalview.analysis.SeqsetUtils.deuniquify(SeqNames, alseqs);
-        return new Object[]
-        { alseqs, msaorder };
+        return new Object[] { alseqs, msaorder };
       }
       return null;
     }
@@ -263,6 +275,7 @@ class MsaWSThread extends JWS1Thread implements WSClientI
      * 
      * @return boolean true if job can be submitted.
      */
+    @Override
     public boolean hasValidInput()
     {
       if (seqs.getSeqs() != null)
@@ -275,7 +288,7 @@ class MsaWSThread extends JWS1Thread implements WSClientI
 
   String alTitle; // name which will be used to form new alignment window.
 
-  Alignment dataset; // dataset to which the new alignment will be
+  AlignmentI dataset; // dataset to which the new alignment will be
 
   // associated.
 
@@ -317,7 +330,7 @@ class MsaWSThread extends JWS1Thread implements WSClientI
   MsaWSThread(ext.vamsas.MuscleWS server, String wsUrl,
           WebserviceInfo wsinfo, jalview.gui.AlignFrame alFrame,
           String wsname, String title, AlignmentView _msa, boolean subgaps,
-          boolean presorder, Alignment seqset)
+          boolean presorder, AlignmentI seqset)
   {
     this(server, wsUrl, wsinfo, alFrame, _msa, wsname, subgaps, presorder);
     OutputHeader = wsInfo.getProgressText();
@@ -349,11 +362,13 @@ class MsaWSThread extends JWS1Thread implements WSClientI
     }
   }
 
+  @Override
   public boolean isCancellable()
   {
     return true;
   }
 
+  @Override
   public void cancelJob()
   {
     if (!jobComplete && jobs != null)
@@ -395,12 +410,12 @@ class MsaWSThread extends JWS1Thread implements WSClientI
           {
             cancelledMessage += ("\nProblems cancelling the job : Exception received...\n"
                     + exc + "\n");
-            Cache.log.warn(
+            Console.warn(
                     "Exception whilst cancelling " + jobs[job].getJobId(),
                     exc);
           }
-          wsInfo.setProgressText(jobs[job].getJobnum(), OutputHeader
-                  + cancelledMessage + "\n");
+          wsInfo.setProgressText(jobs[job].getJobnum(),
+                  OutputHeader + cancelledMessage + "\n");
         }
       }
       if (cancelled)
@@ -420,25 +435,28 @@ class MsaWSThread extends JWS1Thread implements WSClientI
     }
   }
 
+  @Override
   public void pollJob(AWsJob job) throws Exception
   {
     ((MsaWSJob) job).result = server.getResult(((MsaWSJob) job).getJobId());
   }
 
+  @Override
   public void StartJob(AWsJob job)
   {
     if (!(job instanceof MsaWSJob))
     {
-      throw new Error("StartJob(MsaWSJob) called on a WSJobInstance "
-              + job.getClass());
+      throw new Error(MessageManager.formatMessage(
+              "error.implementation_error_msawbjob_called", new String[]
+              { job.getClass().toString() }));
     }
     MsaWSJob j = (MsaWSJob) job;
     if (j.isSubmitted())
     {
-      if (Cache.log.isDebugEnabled())
+      if (Console.isDebugEnabled())
       {
-        Cache.log.debug("Tried to submit an already submitted job "
-                + j.getJobId());
+        Console.debug(
+                "Tried to submit an already submitted job " + j.getJobId());
       }
       return;
     }
@@ -448,7 +466,8 @@ class MsaWSThread extends JWS1Thread implements WSClientI
       j.setSubmitted(true);
       j.result = new MsaResult();
       j.result.setFinished(true);
-      j.result.setStatus("Empty Alignment Job");
+      j.result.setStatus(
+              MessageManager.getString("label.empty_alignment_job"));
       ((MsaResult) j.result).setMsa(null);
     }
     try
@@ -466,10 +485,10 @@ class MsaWSThread extends JWS1Thread implements WSClientI
       {
         if (jobsubmit == null)
         {
-          throw new Exception(
-                  "Server at "
-                          + WsUrl
-                          + " returned null object, it probably cannot be contacted. Try again later ?");
+          throw new Exception(MessageManager.formatMessage(
+                  "exception.web_service_returned_null_try_later",
+                  new String[]
+                  { WsUrl }));
         }
 
         throw new Exception(jobsubmit.getJobId());
@@ -478,20 +497,16 @@ class MsaWSThread extends JWS1Thread implements WSClientI
     {
       // TODO: JBPNote catch timeout or other fault types explicitly
       // For unexpected errors
-      System.err
-              .println(WebServiceName
-                      + "Client: Failed to submit the sequences for alignment (probably a server side problem)\n"
-                      + "When contacting Server:" + WsUrl + "\n"
-                      + e.toString() + "\n");
+      System.err.println(WebServiceName
+              + "Client: Failed to submit the sequences for alignment (probably a server side problem)\n"
+              + "When contacting Server:" + WsUrl + "\n" + e.toString()
+              + "\n");
       j.setAllowedServerExceptions(0);
       wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
       wsInfo.setStatus(j.getJobnum(),
               WebserviceInfo.STATE_STOPPED_SERVERERROR);
-      wsInfo.appendProgressText(
-              j.getJobnum(),
-              "Failed to submit sequences for alignment.\n"
-                      + "It is most likely that there is a problem with the server.\n"
-                      + "Just close the window\n");
+      wsInfo.appendProgressText(j.getJobnum(), MessageManager
+              .getString("info.failed_to_submit_sequences_for_alignment"));
 
       // e.printStackTrace(); // TODO: JBPNote DEBUG
     }
@@ -513,6 +528,7 @@ class MsaWSThread extends JWS1Thread implements WSClientI
     return msa;
   }
 
+  @Override
   public void parseResult()
   {
     int results = 0; // number of result sets received
@@ -526,9 +542,10 @@ class MsaWSThread extends JWS1Thread implements WSClientI
                 && jobs[j].hasResults())
         {
           results++;
-          // if (Cache.log.isDebugEnabled())
+          // if (Cache.isDebugEnabled())
           // {
-          // System.out.println("Job lob for job "+jobs[j].getJobId()+":"+jobs[j].getJobnum());
+          // System.out.println("Job lob for job
+          // "+jobs[j].getJobId()+":"+jobs[j].getJobnum());
           // System.out.println(jobs[j].getStatus());
           // }
 
@@ -536,13 +553,13 @@ class MsaWSThread extends JWS1Thread implements WSClientI
                   .getMsa();
           if (valign != null)
           {
-            wsInfo.appendProgressText(jobs[j].getJobnum(),
-                    "\nAlignment Object Method Notes\n");
+            wsInfo.appendProgressText(jobs[j].getJobnum(), MessageManager
+                    .getString("info.alignment_object_method_notes"));
             String[] lines = valign.getMethod();
             for (int line = 0; line < lines.length; line++)
             {
-              wsInfo.appendProgressText(jobs[j].getJobnum(), lines[line]
-                      + "\n");
+              wsInfo.appendProgressText(jobs[j].getJobnum(),
+                      lines[line] + "\n");
             }
             // JBPNote The returned files from a webservice could be
             // hidden behind icons in the monitor window that,
@@ -554,8 +571,9 @@ class MsaWSThread extends JWS1Thread implements WSClientI
     } catch (Exception ex)
     {
 
-      Cache.log.error("Unexpected exception when processing results for "
-              + alTitle, ex);
+      Console.error(
+              "Unexpected exception when processing results for " + alTitle,
+              ex);
       wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
     }
     if (results > 0)
@@ -563,6 +581,7 @@ class MsaWSThread extends JWS1Thread implements WSClientI
       wsInfo.showResultsNewFrame
               .addActionListener(new java.awt.event.ActionListener()
               {
+                @Override
                 public void actionPerformed(java.awt.event.ActionEvent evt)
                 {
                   displayResults(true);
@@ -571,6 +590,7 @@ class MsaWSThread extends JWS1Thread implements WSClientI
       wsInfo.mergeResults
               .addActionListener(new java.awt.event.ActionListener()
               {
+                @Override
                 public void actionPerformed(java.awt.event.ActionEvent evt)
                 {
                   displayResults(false);
@@ -614,7 +634,7 @@ class MsaWSThread extends JWS1Thread implements WSClientI
       orders[j] = null;
     }
     SequenceI[] alignment = (SequenceI[]) newview[0];
-    ColumnSelection columnselection = (ColumnSelection) newview[1];
+    HiddenColumns hidden = (HiddenColumns) newview[1];
     Alignment al = new Alignment(alignment);
     // TODO: add 'provenance' property to alignment from the method notes
     // accompanying each subjob
@@ -628,8 +648,8 @@ class MsaWSThread extends JWS1Thread implements WSClientI
 
     if (newFrame)
     {
-      AlignFrame af = new AlignFrame(al, columnselection,
-              AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+      AlignFrame af = new AlignFrame(al, hidden, AlignFrame.DEFAULT_WIDTH,
+              AlignFrame.DEFAULT_HEIGHT);
 
       // initialise with same renderer settings as in parent alignframe.
       af.getFeatureRenderer().transferSettings(this.featureSettings);
@@ -653,7 +673,7 @@ class MsaWSThread extends JWS1Thread implements WSClientI
             while (j < l)
             {
               if (((AlignmentOrder) alorders.get(i))
-                      .equals(((AlignmentOrder) alorders.get(j))))
+                      .equals((alorders.get(j))))
               {
                 alorders.remove(j);
                 l--;
@@ -696,6 +716,7 @@ class MsaWSThread extends JWS1Thread implements WSClientI
     }
   }
 
+  @Override
   public boolean canMergeResults()
   {
     return false;