JAL-715 bugfixes and refactor of parsing code for use in service designer GUI
authorjprocter <jprocter@compbio.dundee.ac.uk>
Wed, 24 Aug 2011 14:38:33 +0000 (15:38 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Wed, 24 Aug 2011 14:38:33 +0000 (15:38 +0100)
src/jalview/ws/rest/InputType.java
src/jalview/ws/rest/RestClient.java
src/jalview/ws/rest/RestServiceDescription.java

index 28bfda0..3c0b511 100644 (file)
@@ -1,5 +1,7 @@
 package jalview.ws.rest;
 
+import jalview.ws.rest.params.SeqGroupIndexVector;
+
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
@@ -9,6 +11,7 @@ import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
index ac4f44e..114f51a 100644 (file)
@@ -351,4 +351,9 @@ public class RestClient extends WSClient implements WSClientI,
     return service.details.Action;
   }
 
+  public RestServiceDescription getRestDescription()
+  {
+    return service;
+  }
+
 }
index dea7fc9..fe1434c 100644 (file)
@@ -101,6 +101,36 @@ public class RestServiceDescription
 
   public class UIinfo
   {
+    public String getAction()
+    {
+      return Action;
+    }
+
+    public void setAction(String action)
+    {
+      Action = action;
+    }
+
+    public String getName()
+    {
+      return Name;
+    }
+
+    public void setName(String name)
+    {
+      Name = name;
+    }
+
+    public String getDescription()
+    {
+      return description;
+    }
+
+    public void setDescription(String description)
+    {
+      this.description = description;
+    }
+
     String Action;
 
     String Name;
@@ -110,11 +140,86 @@ public class RestServiceDescription
 
   public UIinfo details = new UIinfo();
 
+  public String getAction()
+  {
+    return details.getAction();
+  }
+
+  public void setAction(String action)
+  {
+    details.setAction(action);
+  }
+
+  public String getName()
+  {
+    return details.getName();
+  }
+
+  public void setName(String name)
+  {
+    details.setName(name);
+  }
+
+  public String getDescription()
+  {
+    return details.getDescription();
+  }
+
+  public void setDescription(String description)
+  {
+    details.setDescription(description);
+  }
+
   /**
    * Service base URL
    */
   String postUrl;
 
+  public String getPostUrl()
+  {
+    return postUrl;
+  }
+
+  public void setPostUrl(String postUrl)
+  {
+    this.postUrl = postUrl;
+  }
+
+  public String getUrlSuffix()
+  {
+    return urlSuffix;
+  }
+
+  public void setUrlSuffix(String urlSuffix)
+  {
+    this.urlSuffix = urlSuffix;
+  }
+
+  public Map<String, InputType> getInputParams()
+  {
+    return inputParams;
+  }
+
+  public void setInputParams(Map<String, InputType> inputParams)
+  {
+    this.inputParams = inputParams;
+  }
+
+  public void setHseparable(boolean hseparable)
+  {
+    this.hseparable = hseparable;
+  }
+
+  public void setVseparable(boolean vseparable)
+  {
+    this.vseparable = vseparable;
+  }
+
+  public void setGapCharacter(char gapCharacter)
+  {
+    this.gapCharacter = gapCharacter;
+  }
+
   /**
    * suffix that should be added to any url used if it does not already end in
    * the suffix.
@@ -124,7 +229,7 @@ public class RestServiceDescription
   /**
    * input info given as key/value pairs - mapped to post arguments
    */
-  Map<String, InputType> inputParams = new HashMap();
+  Map<String, InputType> inputParams = new HashMap<String,InputType>();
 
   /**
    * assigns the given inputType it to its corresponding input parameter token
@@ -213,11 +318,31 @@ public class RestServiceDescription
 
   public RestServiceDescription(RestServiceDescription toedit)
   {
+    // Rather then do the above, we cheat and use our human readable serialization code to clone everything
+    this(toedit.toString());
+    /**
     if (toedit == null)
     {
       return;
     }
-    // TODO Implement copy constructor NOW
+    /**
+    urlSuffix = toedit.urlSuffix;
+    postUrl = toedit.postUrl;
+    hseparable = toedit.hseparable;
+    vseparable = toedit.vseparable;
+    gapCharacter = toedit.gapCharacter;
+    details = new RestServiceDescription.UIinfo();
+    details.Action = toedit.details.Action;
+    details.description = toedit.details.description;
+    details.Name = toedit.details.Name;
+    for (InputType itype: toedit.inputParams.values())
+    {
+      inputParams.put(itype.token, itype.clone());
+      
+    }
+            
+       */
+    // TODO Implement copy constructor NOW*/
   }
 
   /**
@@ -257,7 +382,7 @@ public class RestServiceDescription
     int cp = 0, pos, escape;
     boolean wasescaped = false;
     String lstitem = null;
-    while ((pos = list.indexOf(separator, cp)) > cp)
+    while ((pos = list.indexOf(separator, cp)) >= cp)
     {
       escape = (list.charAt(pos - 1) == '\\') ? -1 : 0;
       if (wasescaped)
@@ -408,7 +533,7 @@ public class RestServiceDescription
       }
       if (prop.equals("returns"))
       {
-        _configureOurputFormatFrom(val, warnings);
+        _configureOutputFormatFrom(val, warnings);
       }
     }
   }
@@ -431,9 +556,13 @@ public class RestServiceDescription
     return buff;
   }
 
-  private void _configureOurputFormatFrom(String outstring,
+  private void _configureOutputFormatFrom(String outstring,
           StringBuffer warnings)
   {
+    if (outstring.indexOf(";")==-1) {
+      // we add a token, for simplicity
+      outstring = outstring+";";
+    }
     StringTokenizer st = new StringTokenizer(outstring, ";");
     String tok = "";
     resultData = new ArrayList<JvDataType>();
@@ -612,45 +741,7 @@ public class RestServiceDescription
         iprmparams = iprm.substring(colon + 1);
         iprm = iprm.substring(0, colon);
       }
-      // TODO - find a better way of maintaining this classlist
-      for (Class type : new Class[]
-      { jalview.ws.rest.params.Alignment.class,
-          jalview.ws.rest.params.AnnotationFile.class,
-          SeqGroupIndexVector.class,
-          jalview.ws.rest.params.SeqIdVector.class,
-          jalview.ws.rest.params.SeqVector.class,
-          jalview.ws.rest.params.Tree.class })
-      {
-        try
-        {
-          jinput = (InputType) (type.getConstructor().newInstance(null));
-          if (iprm.equalsIgnoreCase(jinput.getURLtokenPrefix()))
-          {
-            ArrayList<String> al = new ArrayList<String>();
-            for (String prprm : separatorListToArray(iprmparams, ","))
-            {
-              al.add(prprm);
-            }
-            if (!jinput.configureFromURLtokenString(al, warnings))
-            {
-              valid = false;
-              warnings.append("Failed to parse '" + prms.group(0)
-                      + "' as a " + jinput.getURLtokenPrefix()
-                      + " input tag.\n");
-            }
-            else
-            {
-              jinput.token = tok;
-              iparams.put(tok, jinput);
-            }
-            break;
-          }
-
-        } catch (Throwable thr)
-        {
-        }
-        ;
-      }
+      valid = parseTypeString(prms.group(0), tok,  iprm, iprmparams, iparams, warnings);
     }
     if (valid)
     {
@@ -668,6 +759,55 @@ public class RestServiceDescription
     return valid;
   }
 
+  public static boolean parseTypeString(String fullstring, String tok, String iprm, String iprmparams,
+           Map<String, InputType> iparams, StringBuffer warnings)
+  {
+    boolean valid=true;
+    InputType jinput;
+    // TODO - find a better way of maintaining this classlist
+    for (Class type : new Class[]
+    { jalview.ws.rest.params.Alignment.class,
+        jalview.ws.rest.params.AnnotationFile.class,
+        SeqGroupIndexVector.class,
+        jalview.ws.rest.params.SeqIdVector.class,
+        jalview.ws.rest.params.SeqVector.class,
+        jalview.ws.rest.params.Tree.class })
+    {
+      try
+      {
+        jinput = (InputType) (type.getConstructor().newInstance(null));
+        if (iprm.equalsIgnoreCase(jinput.getURLtokenPrefix()))
+        {
+          ArrayList<String> al = new ArrayList<String>();
+          for (String prprm : separatorListToArray(iprmparams, ","))
+          {
+            al.add(prprm.trim());
+          }
+          if (!jinput.configureFromURLtokenString(al, warnings))
+          {
+            valid = false;
+            warnings.append("Failed to parse '" + fullstring
+                    + "' as a " + jinput.getURLtokenPrefix()
+                    + " input tag.\n");
+          }
+          else
+          {
+            jinput.token = tok;
+            iparams.put(tok, jinput);
+            valid=true;
+          }
+          break;
+        }
+
+      } catch (Throwable thr)
+      {
+      }
+      ;
+    }
+    return valid;
+  }
+
+
   public static void main(String argv[])
   {
     if (argv.length == 0)
@@ -858,4 +998,5 @@ public class RestServiceDescription
   {
     return resultData;
   }
+  
 }