X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Frest%2FRestServiceDescription.java;h=34a1224ef68ae8200a25ec80e4a78d38973c6c36;hb=37de9310bec3501cbc6381e0c3dcb282fcaad812;hp=bf1b375b6d4a2e016938230410e046286bcb6e8e;hpb=d0e72629ac2b7d5d35f151fc8cbec6365a4c1660;p=jalview.git diff --git a/src/jalview/ws/rest/RestServiceDescription.java b/src/jalview/ws/rest/RestServiceDescription.java index bf1b375..34a1224 100644 --- a/src/jalview/ws/rest/RestServiceDescription.java +++ b/src/jalview/ws/rest/RestServiceDescription.java @@ -1,42 +1,56 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6) - * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.ws.rest; - import jalview.datamodel.SequenceI; -import jalview.io.packed.DataProvider; -import jalview.io.packed.SimpleDataProvider; import jalview.io.packed.DataProvider.JvDataType; -import jalview.util.GroupUrlLink.UrlStringTooLongException; -import jalview.util.Platform; +import jalview.util.StringUtils; import jalview.ws.rest.params.Alignment; import jalview.ws.rest.params.AnnotationFile; import jalview.ws.rest.params.SeqGroupIndexVector; +import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.Map; - +import java.util.NoSuchElementException; +import java.util.StringTokenizer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class RestServiceDescription { + private static final Pattern PARAM_ENCODED_URL_PATTERN = Pattern + .compile("([?&])([A-Za-z0-9_]+)=\\$([^$]+)\\$"); + + /** + * create a new rest service description ready to be configured + */ + public RestServiceDescription() + { + + } + /** * @param details * @param postUrl @@ -46,154 +60,250 @@ public class RestServiceDescription * @param vseparable * @param gapCharacter */ - public RestServiceDescription(String action,String description,String name, String postUrl, - String urlSuffix, Map inputParams, - boolean hseparable, boolean vseparable, char gapCharacter) + public RestServiceDescription(String action, String description, + String name, String postUrl, String urlSuffix, + Map inputParams, boolean hseparable, + boolean vseparable, char gapCharacter) { super(); this.details = new UIinfo(); - details.Action= action; - details.description = description; - details.Name = name; - this.postUrl = postUrl; - this.urlSuffix = urlSuffix; - this.inputParams = inputParams; + details.Action = action == null ? "" : action; + details.description = description == null ? "" : description; + details.Name = name == null ? "" : name; + this.postUrl = postUrl == null ? "" : postUrl; + this.urlSuffix = urlSuffix == null ? "" : urlSuffix; + if (inputParams != null) + { + this.inputParams = inputParams; + } this.hseparable = hseparable; this.vseparable = vseparable; this.gapCharacter = gapCharacter; } + + @Override + public boolean equals(Object o) + { + if (o == null || !(o instanceof RestServiceDescription)) + { + return false; + } + RestServiceDescription other = (RestServiceDescription) o; + boolean diff = (gapCharacter != other.gapCharacter); + diff |= vseparable != other.vseparable; + diff |= hseparable != other.hseparable; + diff |= !(urlSuffix == null && other.urlSuffix == null || (urlSuffix != null + && other.urlSuffix != null && urlSuffix.equals(other.urlSuffix))); + // TODO - robust diff that includes constants and reordering of URL + // diff |= !(postUrl.equals(other.postUrl)); + // diff |= !inputParams.equals(other.inputParams); + diff |= !details.Name.equals(other.details.Name); + diff |= !details.Action.equals(other.details.Action); + diff |= !details.description.equals(other.details.description); + return !diff; + } + /** * Service UI Info { Action, Specific Name of Service, Brief Description } */ - - public class UIinfo { + + 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; + String description; } - UIinfo details = new UIinfo(); - - /** Service base URL + + 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. + * suffix that should be added to any url used if it does not already end in + * the suffix. */ String urlSuffix; - - /** input info given as key/value pairs - mapped to post arguments - */ - Map inputParams=new HashMap(); + /** - * assigns the given inputType it to its corresponding input parameter token it.token + * input info given as key/value pairs - mapped to post arguments + */ + Map inputParams = new HashMap(); + + /** + * assigns the given inputType it to its corresponding input parameter token + * it.token + * * @param it */ public void setInputParam(InputType it) { inputParams.put(it.token, it); } + /** * remove the given input type it from the set of service input parameters. + * * @param it */ public void removeInputParam(InputType it) { inputParams.remove(it.token); } + /** * service requests alignment data */ boolean aligndata; + /** - * service requests alignment and/or seuqence annotationo data + * service requests alignment and/or seuqence annotationo data */ boolean annotdata; + /** * service requests partitions defined over input (alignment) data */ boolean partitiondata; - + /** - * process ths input data and set the appropriate shorthand flags describing the input the service wants + * process ths input data and set the appropriate shorthand flags describing + * the input the service wants */ - public void setInvolvesFlags() { + public void setInvolvesFlags() + { aligndata = inputInvolves(Alignment.class); annotdata = inputInvolves(AnnotationFile.class); partitiondata = inputInvolves(SeqGroupIndexVector.class); } - /** Service return info { alignment, annotation file (loaded back on to alignment), tree (loaded back on to alignment), sequence annotation - loaded back on to alignment), text report, pdb structures with sequence mapping ) - * - */ - - /** Start with bare minimum: input is alignment + groups on alignment - * - * @author JimP - * - */ - /** - * Helper class based on the UrlLink class which enables URLs to be - * constructed from sequences or IDs associated with a group of sequences. URL - * definitions consist of a pipe separated string containing a