/* * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9) * Copyright (C) 2015 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. * * 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 . * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.ws.rest; import jalview.datamodel.SequenceI; import jalview.io.packed.DataProvider.JvDataType; 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 * @param urlSuffix * @param inputParams * @param hseparable * @param vseparable * @param 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 == 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 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; } 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. */ 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 * * @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 */ 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 */ 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 * */ private String invalidMessage = null; /** * parse the given linkString of the form '