JAL-2890 submit/valid jobs now return the actual job objects
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Thu, 1 Feb 2018 16:50:31 +0000 (16:50 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Thu, 1 Feb 2018 16:50:31 +0000 (16:50 +0000)
src/jalview/ext/cipres/TreeJob.java

index 8bdc9c2..4bfd7da 100644 (file)
@@ -116,19 +116,20 @@ public class TreeJob
    * doesn't actually run the job. This is a lightweight way to validate that
    * the given parameters are correct for a specified tool.
    */
-  public void validateJobParams(String toolName)
+  public CiJob validateJobParams(String toolName)
   {
+    CiJob validateJob = null;
     try
     {
-      CiJob validateJob = cipresClient
+      validateJob = cipresClient
               .validateJob(toolName, vParams, inputParams, metadata);
       validateJob.show(true); // currently outputs just to console, should be
                               // graphical
       paramsValidated = true;
 
+
     } catch (CiCipresException ce)
     {
-      paramsValidated = false; // parameters gave an error.
       ErrorData ed = ce.getErrorData();
       System.out.println(
               "Cipres error while trying to validate parameters, code="
@@ -143,17 +144,53 @@ public class TreeJob
         }
       }
     }
-
+    return validateJob;
   }
 
-  public void submitJob(String toolName)
+  /**
+   * Sends the job to CIPRES. If the job hasn't been validated beforehand this
+   * method will do so before submitting.
+   * 
+   * @param toolName
+   */
+  public CiJob submitJob(String toolName)
   {
+    CiJob submittedJob = null;
     if (!paramsValidated)
     {
-      validateJobParams(toolName); // validate before running some expensive job
-                                   // first
+      // validate before running some expensive job first.
+      CiJob validateJob = validateJobParams(toolName);
+
+      // should be redundant but extra check here anyway.
+      if (!validateJob.isError())
+      {
+        submittedJob = submitJob(toolName);
+      }
     }
+    else
+    {
+      try
+      {
+        submittedJob = cipresClient
+                .submitJob(toolName, vParams, inputParams, metadata);
+      } catch (CiCipresException ce)
+      {
+        ErrorData ed = ce.getErrorData();
+        System.out.println(
+                "Cipres error in submitted job, code="
+                        + ed.code + ", message=" + ed.displayMessage);
 
+                if (ed.code == ErrorData.FORM_VALIDATION)
+        {
+          for (ParamError pe : ed.paramError)
+          // invalid parameters shouldn't be possible here but just in case.
+          {
+            System.out.println(pe.param + ": " + pe.error);
+          }
+        }
+      }
+    }
+    return submittedJob;
   }