From 603ec5f3d10d05a8668477ad627ac3010473b579 Mon Sep 17 00:00:00 2001 From: jprocter Date: Wed, 24 Aug 2011 15:38:33 +0100 Subject: [PATCH] JAL-715 bugfixes and refactor of parsing code for use in service designer GUI --- src/jalview/ws/rest/InputType.java | 3 + src/jalview/ws/rest/RestClient.java | 5 + src/jalview/ws/rest/RestServiceDescription.java | 229 ++++++++++++++++++----- 3 files changed, 193 insertions(+), 44 deletions(-) diff --git a/src/jalview/ws/rest/InputType.java b/src/jalview/ws/rest/InputType.java index 28bfda0..3c0b511 100644 --- a/src/jalview/ws/rest/InputType.java +++ b/src/jalview/ws/rest/InputType.java @@ -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; diff --git a/src/jalview/ws/rest/RestClient.java b/src/jalview/ws/rest/RestClient.java index ac4f44e..114f51a 100644 --- a/src/jalview/ws/rest/RestClient.java +++ b/src/jalview/ws/rest/RestClient.java @@ -351,4 +351,9 @@ public class RestClient extends WSClient implements WSClientI, return service.details.Action; } + public RestServiceDescription getRestDescription() + { + return service; + } + } diff --git a/src/jalview/ws/rest/RestServiceDescription.java b/src/jalview/ws/rest/RestServiceDescription.java index dea7fc9..fe1434c 100644 --- a/src/jalview/ws/rest/RestServiceDescription.java +++ b/src/jalview/ws/rest/RestServiceDescription.java @@ -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 getInputParams() + { + return inputParams; + } + + public void setInputParams(Map 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 inputParams = new HashMap(); + Map inputParams = new HashMap(); /** * 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(); @@ -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 al = new ArrayList(); - 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 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 al = new ArrayList(); + 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; } + } -- 1.7.10.2