Merge branch 'feature/JAL-3690_callback-based-web-services' into alpha/JAL-3066_Jalvi...
authorMateusz <mmzwarowny@dundee.ac.uk>
Thu, 21 Jan 2021 15:44:25 +0000 (16:44 +0100)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Mon, 22 Feb 2021 11:13:08 +0000 (12:13 +0100)
1  2 
src/jalview/ws/slivkaws/SlivkaWSInstance.java

@@@ -2,8 -2,6 +2,8 @@@ package jalview.ws.slivkaws
  
  import jalview.datamodel.SequenceI;
  import jalview.gui.WebserviceInfo;
 +import jalview.io.FileFormat;
 +import jalview.io.FormatAdapter;
  import jalview.ws.api.JalviewServiceEndpointProviderI;
  import jalview.ws.api.JalviewWebServiceI;
  import jalview.ws.api.JobId;
@@@ -27,7 -25,6 +27,7 @@@ import java.util.Optional
  import java.util.Set;
  
  import uk.ac.dundee.compbio.slivkaclient.FieldType;
 +import uk.ac.dundee.compbio.slivkaclient.FileField;
  import uk.ac.dundee.compbio.slivkaclient.FormField;
  import uk.ac.dundee.compbio.slivkaclient.FormValidationException;
  import uk.ac.dundee.compbio.slivkaclient.JobState;
@@@ -54,7 -51,7 +54,7 @@@ public abstract class SlivkaWSInstance 
      stateMap.put(JobState.QUEUED, WsJob.JobState.QUEUED);
      stateMap.put(JobState.RUNNING, WsJob.JobState.RUNNING);
      stateMap.put(JobState.COMPLETED, WsJob.JobState.FINISHED);
-     stateMap.put(JobState.INTERRUPED, WsJob.JobState.CANCELLED);
+     stateMap.put(JobState.INTERRUPTED, WsJob.JobState.CANCELLED);
      stateMap.put(JobState.DELETED, WsJob.JobState.CANCELLED);
      stateMap.put(JobState.FAILED, WsJob.JobState.FAILED);
      stateMap.put(JobState.ERROR, WsJob.JobState.SERVERERROR);
@@@ -67,7 -64,7 +67,7 @@@
  
    public SlivkaWSInstance(SlivkaClient client, SlivkaService service, String action)
    {
-     super(service.getName(), action, service.getLabel(), "Slivka", client.getUrl().toString());
+     super(action, action, service.getLabel(), "Slivka", client.getUrl().toString());
      this.client = client;
      this.service = service;
    }
            WsParamSetI preset, List<ArgumentI> args) throws Throwable
    {
      SlivkaForm form = service.getForm();
 -    Optional<FormField> inputField = form.getFields().stream()
 -            .filter(f -> f.getType() == FieldType.FILE).findFirst();
 -    if (inputField.isPresent())
 +    for (FormField field : form.getFields())
      {
 -      StringBuilder builder = new StringBuilder();
 -      for (SequenceI seq : sequences)
 +      if (field.getType() == FieldType.FILE)
        {
 -        builder.append(">").append(seq.getName()).append("\n")
 -                .append(seq.getSequence()).append("\n");
 +        FormatAdapter fa = new FormatAdapter();
 +        fa.setNewlineString("\r\n");
 +        FileField fileField = (FileField) field;
 +        FileFormat format;
 +        switch (fileField.getMediaType())
 +        {
 +        case "application/pfam":
 +          format = FileFormat.Pfam;
 +          break;
 +        case "application/stockholm":
 +          format = FileFormat.Stockholm;
 +          break;
 +        default:
 +        case "application/fasta":
 +          format = FileFormat.Fasta;
 +          break;
 +        }
 +        InputStream stream = new ByteArrayInputStream(
 +            fa.formatSequences(format, sequences.toArray(new SequenceI[0]))
 +                .getBytes());
 +        RemoteFile rf = client.uploadFile(stream, "input",
 +            fileField.getMediaType());
 +        form.insert(field.getName(), rf);
        }
 -      InputStream stream = new ByteArrayInputStream(
 -              builder.toString().getBytes());
 -      RemoteFile file = client.uploadFile(stream, "input.fa",
 -              "application/fasta");
 -      form.insert(inputField.get().getName(), file);
      }
      if (args != null)
      {
    public final boolean updateJobProgress(WsJob job) throws IOException
    {
      List<RemoteFile> files = client.getJobResults(job.getJobId());
-     Optional<RemoteFile> logFile = files.stream()
-             .filter(f -> f.getLabel().equals("log")).findFirst();
+     RemoteFile logFile=null;
+     for (RemoteFile f : files)
+     {
+       if (f.getLabel().equals("log"))
+       {
+         logFile = f; break;
+       }
+     }
      boolean newContent = false;
-     if (logFile.isPresent())
+     if (logFile!=null)
      {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
-       logFile.get().writeTo(output);
+       logFile.writeTo(output);
        if (output.size() > job.getNextChunk())
        {
          newContent = true;
      }
      if (failedStates.contains(job.getJobState()))
      {
-       Optional<RemoteFile> errLogFile = files.stream()
-               .filter(f -> f.getLabel().equals("error-log")).findFirst();
-       if (errLogFile.isPresent())
+       
+       RemoteFile errLogFile = null;
+       for (RemoteFile f : files)
+       {
+         if (f.getLabel().equals("error-log"))
+         {
+           errLogFile = f;
+           break;
+         }
+       }
+       if (errLogFile!=null)
        {
          ByteArrayOutputStream output = new ByteArrayOutputStream();
-         errLogFile.get().writeTo(output);
+         errLogFile.writeTo(output);
          if (output.size() > 0)
          {
            newContent = true;