JAL-3949 - refactor logging from jalview.bin.Cache to jalview.bin.Console
[jalview.git] / src / jalview / ws / jws1 / SeqSearchWSThread.java
index b9ed2e7..0f28230 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
- * Copyright (C) 2015 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.
  * 
 package jalview.ws.jws1;
 
 import jalview.analysis.AlignSeq;
-import jalview.bin.Cache;
+import jalview.api.FeatureColourI;
+import jalview.bin.Console;
 import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AlignmentView;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
@@ -93,9 +95,8 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
       int nseqs = 0;
       if (minlen < 0)
       {
-        throw new Error(
-                MessageManager
-                        .getString("error.implementation_error_minlen_must_be_greater_zero"));
+        throw new Error(MessageManager.getString(
+                "error.implementation_error_minlen_must_be_greater_zero"));
       }
       for (int i = 0; i < seqs.length; i++)
       {
@@ -106,7 +107,8 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
       }
       boolean valid = nseqs >= 1; // need at least one sequence for valid input
       // TODO: generalise
-      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;
       boolean submitGaps = (nseqs == 1) ? false : true; // profile is submitted
       // with gaps
@@ -132,8 +134,8 @@ class SeqSearchWSThread 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 });
@@ -152,13 +154,13 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
      * 
      * @return true if getAlignment will return a valid alignment result.
      */
+    @Override
     public boolean hasResults()
     {
-      if (subjobComplete
-              && result != null
-              && result.isFinished()
+      if (subjobComplete && result != null && result.isFinished()
               && ((SeqSearchResult) result).getAlignment() != null
-              && ((SeqSearchResult) result).getAlignment().getSeqs() != null)
+              && ((SeqSearchResult) result).getAlignment()
+                      .getSeqs() != null)
       {
         return true;
       }
@@ -170,7 +172,8 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
      * 
      * @return null or { Alignment(+features and annotation), NewickFile)}
      */
-    public Object[] getAlignment(Alignment dataset, Map featureColours)
+    public Object[] getAlignment(AlignmentI dataset,
+            Map<String, FeatureColourI> featureColours)
     {
 
       if (result != null && result.isFinished())
@@ -180,8 +183,8 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
         // int alseq_l = 0;
         if (((SeqSearchResult) result).getAlignment() != null)
         {
-          alseqs = getVamsasAlignment(((SeqSearchResult) result)
-                  .getAlignment());
+          alseqs = getVamsasAlignment(
+                  ((SeqSearchResult) result).getAlignment());
           // alseq_gapchar = ( (SeqSearchResult)
           // result).getAlignment().getGapchar().charAt(0);
           // alseq_l = alseqs.length;
@@ -205,12 +208,12 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
           if (inFile != null && inFile.length() > 0)
           {
             new jalview.io.AnnotationFile().readAnnotationFile(al, inFile,
-                    jalview.io.AppletFormatAdapter.PASTE);
+                    jalview.io.DataSourceType.PASTE);
           }
         } catch (Exception e)
         {
-          System.err
-                  .println("Failed to parse the annotation file associated with the alignment.");
+          System.err.println(
+                  "Failed to parse the annotation file associated with the alignment.");
           System.err.println(">>>EOF" + inFile + "\n<<<EOF\n");
           e.printStackTrace(System.err);
         }
@@ -220,14 +223,14 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
           inFile = ((SeqSearchResult) result).getFeatures();
           if (inFile != null && inFile.length() > 0)
           {
-            jalview.io.FeaturesFile ff = new jalview.io.FeaturesFile(
-                    inFile, jalview.io.AppletFormatAdapter.PASTE);
+            jalview.io.FeaturesFile ff = new jalview.io.FeaturesFile(inFile,
+                    jalview.io.DataSourceType.PASTE);
             ff.parse(al, featureColours, false);
           }
         } catch (Exception e)
         {
-          System.err
-                  .println("Failed to parse the Features file associated with the alignment.");
+          System.err.println(
+                  "Failed to parse the Features file associated with the alignment.");
           System.err.println(">>>EOF" + inFile + "\n<<<EOF\n");
           e.printStackTrace(System.err);
         }
@@ -238,7 +241,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
           if (inFile != null && inFile.length() > 0)
           {
             nf = new jalview.io.NewickFile(inFile,
-                    jalview.io.AppletFormatAdapter.PASTE);
+                    jalview.io.DataSourceType.PASTE);
             if (!nf.isValid())
             {
               nf.close();
@@ -247,8 +250,8 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
           }
         } catch (Exception e)
         {
-          System.err
-                  .println("Failed to parse the treeFile associated with the alignment.");
+          System.err.println(
+                  "Failed to parse the treeFile associated with the alignment.");
           System.err.println(">>>EOF" + inFile + "\n<<<EOF\n");
           e.printStackTrace(System.err);
         }
@@ -287,6 +290,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
      * 
      * @return boolean true if job can be submitted.
      */
+    @Override
     public boolean hasValidInput()
     {
       if (seqs.getSeqs() != null)
@@ -299,7 +303,7 @@ class SeqSearchWSThread 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.
 
@@ -341,7 +345,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
   SeqSearchWSThread(ext.vamsas.SeqSearchI server, String wsUrl,
           WebserviceInfo wsinfo, jalview.gui.AlignFrame alFrame,
           String wsname, String title, AlignmentView _msa, String db,
-          Alignment seqset)
+          AlignmentI seqset)
   {
     this(server, wsUrl, wsinfo, alFrame, _msa, wsname, db);
     OutputHeader = wsInfo.getProgressText();
@@ -373,11 +377,13 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
     }
   }
 
+  @Override
   public boolean isCancellable()
   {
     return true;
   }
 
+  @Override
   public void cancelJob()
   {
     if (!jobComplete && jobs != null)
@@ -419,12 +425,12 @@ class SeqSearchWSThread 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)
@@ -444,27 +450,29 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
     }
   }
 
+  @Override
   public void pollJob(AWsJob job) throws Exception
   {
-    ((SeqSearchWSJob) job).result = server.getResult(((SeqSearchWSJob) job)
-            .getJobId());
+    ((SeqSearchWSJob) job).result = server
+            .getResult(((SeqSearchWSJob) job).getJobId());
   }
 
+  @Override
   public void StartJob(AWsJob job)
   {
     if (!(job instanceof SeqSearchWSJob))
     {
       throw new Error(MessageManager.formatMessage(
-              "error.implementation_error_msawbjob_called",
-              new String[] { job.getClass().toString() }));
+              "error.implementation_error_msawbjob_called", new String[]
+              { job.getClass().toString() }));
     }
     SeqSearchWSJob j = (SeqSearchWSJob) 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;
     }
@@ -474,14 +482,14 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
       j.setSubmitted(true);
       j.result = new MsaResult();
       j.result.setFinished(true);
-      j.result.setStatus(MessageManager
-              .getString("label.empty_alignment_job"));
+      j.result.setStatus(
+              MessageManager.getString("label.empty_alignment_job"));
       ((MsaResult) j.result).setMsa(null);
     }
     try
     {
-      vamsas.objects.simple.WsJobId jobsubmit = server.search(
-              j.seqs.getSeqs()[0], dbArg);
+      vamsas.objects.simple.WsJobId jobsubmit = server
+              .search(j.seqs.getSeqs()[0], dbArg);
 
       if ((jobsubmit != null) && (jobsubmit.getStatus() == 1))
       {
@@ -496,7 +504,8 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
         {
           throw new Exception(MessageManager.formatMessage(
                   "exception.web_service_returned_null_try_later",
-                  new String[] { WsUrl }));
+                  new String[]
+                  { WsUrl }));
         }
 
         throw new Exception(jobsubmit.getJobId());
@@ -505,11 +514,10 @@ class SeqSearchWSThread 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(),
@@ -536,6 +544,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
     return msa;
   }
 
+  @Override
   public void parseResult()
   {
     int results = 0; // number of result sets received
@@ -558,8 +567,8 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
             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,
@@ -570,8 +579,9 @@ class SeqSearchWSThread 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)
@@ -579,6 +589,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
       wsInfo.showResultsNewFrame
               .addActionListener(new java.awt.event.ActionListener()
               {
+                @Override
                 public void actionPerformed(java.awt.event.ActionEvent evt)
                 {
                   displayResults(true);
@@ -587,6 +598,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
       wsInfo.mergeResults
               .addActionListener(new java.awt.event.ActionListener()
               {
+                @Override
                 public void actionPerformed(java.awt.event.ActionEvent evt)
                 {
                   displayResults(false);
@@ -612,7 +624,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
     // NewickFile nf[] = new NewickFile[jobs.length];
     for (int j = 0; j < jobs.length; j++)
     {
-      Map featureColours = new HashMap();
+      Map<String, FeatureColourI> featureColours = new HashMap<String, FeatureColourI>();
       Alignment al = null;
       NewickFile nf = null;
       if (jobs[j].hasResults())
@@ -650,12 +662,13 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
        * propagateDatasetMappings(al); }
        */
 
-      AlignFrame af = new AlignFrame(al,// columnselection,
+      AlignFrame af = new AlignFrame(al, // columnselection,
               AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
       if (nf != null)
       {
-        af.ShowNewickTree(nf, MessageManager.formatMessage(
-                "label.tree_from", new String[] { this.alTitle }));
+        af.showNewickTree(nf,
+                MessageManager.formatMessage("label.tree_from", new String[]
+                { this.alTitle }));
       }
       // initialise with same renderer settings as in parent alignframe.
       af.getFeatureRenderer().transferSettings(this.featureSettings);
@@ -664,6 +677,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
     }
   }
 
+  @Override
   public boolean canMergeResults()
   {
     return false;