added proper state check for failedJob flag.
[jalview.git] / src / jalview / ws / MsaWSClient.java
index 13a3a9c..23c4ed4 100755 (executable)
@@ -16,20 +16,13 @@ import vamsas.objects.*;
 
 
 public class MsaWSClient
+    extends WSClient
 {
-  int jobsRunning = 0;
-  ext.vamsas.MuscleWS server;
-  WebserviceInfo wsInfo;
-  /**
-   * MsaWSClient
-   *
-   * @param msa SequenceI[]
-   */
-
-  String WebServiceName;
-  String WebServiceJobTitle;
-  String WebServiceReference;
-  String WsURL;
+    /**
+     * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
+     */
+    ext.vamsas.MuscleWS server;
+
   private boolean setWebService(String MsaWSName) {
     if (MsaWServices.info.containsKey(MsaWSName)) {
       WebServiceName = MsaWSName;
@@ -43,9 +36,6 @@ public class MsaWSClient
     }
   }
 
-//  public MsaWSClient(String MsaWSName, SequenceI[] msa) {
-//    MsaWSClient(MsaWSName, msa, true);
-//  }
 
   public MsaWSClient(String MsaWSName, String altitle, SequenceI[] msa, boolean submitGaps, boolean preserveOrder)
   {
@@ -62,8 +52,7 @@ public class MsaWSClient
     // TODO: MuscleWS transmuted to generic MsaWS client
     MuscleWSServiceLocator loc = new MuscleWSServiceLocator(); // Default
     try {
-      this.server = (MuscleWS) loc.getMuscleWS(// JBPNote will be set from properties
-      new java.net.URL(WsURL));
+      this.server = (MuscleWS) loc.getMuscleWS(new java.net.URL(WsURL));
     }
     catch (Exception ex) {
       wsInfo.setProgressText("Serious! "+WebServiceName+" Service location failed\nfor URL :"
@@ -113,11 +102,12 @@ public class MsaWSClient
 
       for (int i = 0; i < msa.length; i++)
       {
-        String newname = new String("Sequence"+i);
-        // uniquify as we go - JBPNote: TODO: this is a ubiquitous transformation
-        SeqNames.put(newname, msa[i].getName());
+        String newname = jalview.analysis.SeqsetUtils.unique_name(i);
+        // uniquify as we go
+        // TODO: JBPNote: this is a ubiquitous transformation - set of jalview seq objects to vamsas sequences with name preservation
+        SeqNames.put(newname, jalview.analysis.SeqsetUtils.SeqCharacterHash(msa[i]));
         seqarray[i] = new vamsas.objects.simple.Sequence();
-        seqarray[i].setId(new String("Sequence"+i));
+        seqarray[i].setId(newname);
         seqarray[i].setSeq((submitGaps) ? msa[i].getSequence()
                            : AlignSeq.extractGaps("-. ", msa[i].getSequence()));
       }
@@ -184,11 +174,14 @@ public class MsaWSClient
           }
           else
           {
-            wsInfo.setProgressText(OutputHeader + "\n" + result.getStatus());
+            if (result.getStatus()!=null)
+              wsInfo.setProgressText(OutputHeader + "\n" + result.getStatus());
             if (! (result.isJobFailed() || result.isServerError()))
             {
               Thread.sleep(5000);
               //  System.out.println("I'm alive "+seqid+" "+jobid);
+            } else {
+              break;
             }
           }
         }
@@ -199,12 +192,16 @@ public class MsaWSClient
           ex.printStackTrace();
         }
       }
-
-      if (! (result!=null && (result.isJobFailed() || result.isServerError())))
-        wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
-      else
+      if (allowedServerExceptions==0) {
         wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
-    }
+      } else {
+        if (! (result!=null && (result.isJobFailed() || result.isServerError())))
+          wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
+        else {
+          if (result.isJobFailed()
+
+          wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
+        }
 
     void StartJob()
     {
@@ -212,14 +209,15 @@ public class MsaWSClient
       {
         vamsas.objects.simple.WsJobId jobsubmit = server.align(seqs);
         if (jobsubmit.getStatus()==1) {
-          System.out.println(jobId=jobsubmit.getJobId());
+          jobId=jobsubmit.getJobId();
+          System.out.println(WsURL+" Job Id '"+jobId+"'");
         } else {
           throw new Exception(jobsubmit.getJobId());
         }
       }
       catch (Exception e)
       {
-        System.out.println(ServiceName + " Client: Failed to submit the prediction\n" +
+        System.err.println(ServiceName + " Client: Failed to submit the prediction\n" +
                            e.toString() + "\n");
         e.printStackTrace();
       }