Set job title correctly and pass reason why
[jalview.git] / src / jalview / ws / rest / RestJobThread.java
index 39f26ae..799c7b4 100644 (file)
@@ -177,6 +177,7 @@ public class RestJobThread extends AWSThread
   {
     String postUrl = rj.getPostUrl();
     doHttpReq(Stage.SUBMIT, rj, postUrl);
+    wsInfo.invalidate();
   }
 
   /**
@@ -404,7 +405,16 @@ public class RestJobThread extends AWSThread
     {
       System.err.println("Debug RestJob: Posting Job");
       doPost((RestJob) job);
-    } catch (Exception ex)
+    }
+    catch (NoValidInputDataException erex)
+    {
+      job.setSubjobComplete(true);
+      job.setSubmitted(true);
+      ((RestJob)job).statMessage="<br>It looks like there was a problem with the data sent to the service :<br>"+erex.getMessage()+"\n";
+      ((RestJob)job).error=true;
+      
+    }
+    catch (Exception ex)
     {
       job.setSubjobComplete(true);
       job.setAllowedServerExceptions(-1);
@@ -459,7 +469,8 @@ public class RestJobThread extends AWSThread
        */
       if (true)
       {
-        wsInfo.setViewResultsImmediatly(false);
+        // preserver current jalview behaviour
+        wsInfo.setViewResultsImmediatly(true);
       }
       else
       {
@@ -495,6 +506,8 @@ public class RestJobThread extends AWSThread
     else
     {
       // tell the user nothing was returned.
+      wsInfo.setStatus(wsInfo.STATE_STOPPED_ERROR);
+      wsInfo.setFinishedNoResults();
     }
   }
 
@@ -985,8 +998,7 @@ public class RestJobThread extends AWSThread
       AlignmentI destal;
       ColumnSelection destcs;
       String alTitle = restClient.service.details.Action + " using "
-              + restClient.service.details.Name + " on "
-              + " whatever you clicked on." + "(set " + als + ")";
+              + restClient.service.details.Name + " on "+restClient.viewTitle;
       switch (action)
       {
       case newAlignment:
@@ -1014,12 +1026,13 @@ public class RestJobThread extends AWSThread
          * i++) { af.addSortByOrderMenuItem( WebServiceName + ((String)
          * names.get(i)) + " Ordering", (AlignmentOrder) alorders.get(i)); } } }
          */
+        // TODO: modify this and previous alignment's title if many alignments have been returned.
         Desktop.addInternalFrame(destaf, alTitle, AlignFrame.DEFAULT_WIDTH,
                 AlignFrame.DEFAULT_HEIGHT);
 
         break;
       case newView:
-
+        // TODO: determine title for view
         break;
       case currentView:
         break;
@@ -1193,6 +1206,8 @@ public class RestJobThread extends AWSThread
    */
   public boolean isValid()
   {
+    ArrayList<String> _warnings=new ArrayList<String>();
+    boolean validt=true;
     if (jobs != null)
     {
       for (RestJob rj : (RestJob[]) jobs)
@@ -1201,14 +1216,42 @@ public class RestJobThread extends AWSThread
         {
           // invalid input for this job
           System.err.println("Job " + rj.getJobnum()
-                  + " has invalid input.");
-          return false;
+                  + " has invalid input. ( "+rj.getStatus()+")");
+          if (rj.hasStatus() && !_warnings.contains(rj.getStatus()))
+          {
+            _warnings.add(rj.getStatus());
+          }
+          validt=false;
+        }
+      }
+    }
+    if (!validt)
+    {
+      warnings = "";
+      for (String st : _warnings) {
+        if (warnings.length()>0) { warnings+="\n";
         }
+        warnings += st;
+        
       }
-      return true;
     }
+    return validt;
+  }
+
+  protected String warnings;
+  public boolean hasWarnings()
+  {
     // TODO Auto-generated method stub
-    return false;
+    return warnings!=null && warnings.length()>0;
+  }
+
+  /**
+   * get any informative messages about why the job thread couldn't start.
+   * @return
+   */
+  public String getWarnings()
+  {
+    return isValid() ? "Job can be started. No warnings." :  hasWarnings() ? warnings : "";
   }
 
 }