From 7a48c84f54f4b395e76cebb2fcd25c4fc67c2514 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 2 Oct 2019 17:44:36 +0100 Subject: [PATCH] JAL-3070 reorganise prior to refactor --- src/jalview/ws/jws2/Jws2Discoverer.java | 228 +++++++++++++++---------------- 1 file changed, 114 insertions(+), 114 deletions(-) diff --git a/src/jalview/ws/jws2/Jws2Discoverer.java b/src/jalview/ws/jws2/Jws2Discoverer.java index d270c85..77f2440 100644 --- a/src/jalview/ws/jws2/Jws2Discoverer.java +++ b/src/jalview/ws/jws2/Jws2Discoverer.java @@ -582,6 +582,120 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI } } + /** + * pick the user's preferred service based on a set of URLs (jaba server + * locations) and service URIs (specifying version and service interface + * class) + * + * @param serviceURL + * @return null or best match for given uri/ls. + */ + public ServiceWithParameters getPreferredServiceFor(String[] serviceURLs) + { + HashSet urls = new HashSet<>(); + urls.addAll(Arrays.asList(serviceURLs)); + ServiceWithParameters match = null; + List ourServices = getServices(); + + if (ourServices != null) + { + for (ServiceWithParameters svc : ourServices) + { + // TODO getNameURI Should return a versioned URI for the service, but + // doesn't as of 2.11 + if (urls.contains(svc.getNameURI())) + { + if (match == null) + { + // for moment we always pick service from server ordered first in + // user's preferences + match = svc; + } + if (urls.contains(svc.getUri())) + { + // stop and return - we've matched type URI and URI for service + // endpoint + return svc; + } + } + } + } + return match; + } + + Map> preferredServiceMap = new HashMap<>(); + + /** + * get current preferred endpoint of the given Jabaws service, or global + * default + * + * @param af + * null or a specific alignFrame + * @param serviceName + * Jws2Instance.getName() for service + * @return null if no service of this type is available, the preferred service + * for the serviceType and af if specified and if defined. + */ + public ServiceWithParameters getPreferredServiceFor(AlignFrame af, + String serviceName) + { + String serviceurl = null; + synchronized (preferredServiceMap) + { + String afid = (af == null) ? "" : af.getViewport().getSequenceSetId(); + Map prefmap = preferredServiceMap.get(afid); + if (afid.length() > 0 && prefmap == null) + { + // recover global setting, if any + prefmap = preferredServiceMap.get(""); + } + if (prefmap != null) + { + serviceurl = prefmap.get(serviceName); + } + + } + ServiceWithParameters response = null; + for (ServiceWithParameters svc : getServices()) + { + if (svc.getName().equals(serviceName)) + { + if (serviceurl == null || serviceurl.equals(svc.getHostURL())) + { + response = svc; + break; + } + } + } + return response; + } + + public void setPreferredServiceFor(AlignFrame af, String serviceName, + String serviceAction, ServiceWithParameters selectedServer) + { + // TODO: pull out and generalise for the selectedServer's attributes + String afid = (af == null) ? "" : af.getViewport().getSequenceSetId(); + if (preferredServiceMap == null) + { + preferredServiceMap = new HashMap<>(); + } + Map prefmap = preferredServiceMap.get(afid); + if (prefmap == null) + { + prefmap = new HashMap<>(); + preferredServiceMap.put(afid, prefmap); + } + prefmap.put(serviceName, selectedServer.getHostURL()); + prefmap.put(serviceAction, selectedServer.getHostURL()); + } + + public void setPreferredServiceFor(String serviceType, + String serviceAction, ServiceWithParameters selectedServer) + { + setPreferredServiceFor(null, serviceType, serviceAction, + selectedServer); + } + public static void main(String[] args) { if (args.length > 0) @@ -944,120 +1058,6 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI } /** - * pick the user's preferred service based on a set of URLs (jaba server - * locations) and service URIs (specifying version and service interface - * class) - * - * @param serviceURL - * @return null or best match for given uri/ls. - */ - public ServiceWithParameters getPreferredServiceFor(String[] serviceURLs) - { - HashSet urls = new HashSet<>(); - urls.addAll(Arrays.asList(serviceURLs)); - ServiceWithParameters match = null; - List ourServices = getServices(); - - if (ourServices != null) - { - for (ServiceWithParameters svc : ourServices) - { - // TODO getNameURI Should return a versioned URI for the service, but - // doesn't as of 2.11 - if (urls.contains(svc.getNameURI())) - { - if (match == null) - { - // for moment we always pick service from server ordered first in - // user's preferences - match = svc; - } - if (urls.contains(svc.getUri())) - { - // stop and return - we've matched type URI and URI for service - // endpoint - return svc; - } - } - } - } - return match; - } - - Map> preferredServiceMap = new HashMap<>(); - - /** - * get current preferred endpoint of the given Jabaws service, or global - * default - * - * @param af - * null or a specific alignFrame - * @param serviceName - * Jws2Instance.getName() for service - * @return null if no service of this type is available, the preferred service - * for the serviceType and af if specified and if defined. - */ - public ServiceWithParameters getPreferredServiceFor(AlignFrame af, - String serviceName) - { - String serviceurl = null; - synchronized (preferredServiceMap) - { - String afid = (af == null) ? "" : af.getViewport().getSequenceSetId(); - Map prefmap = preferredServiceMap.get(afid); - if (afid.length() > 0 && prefmap == null) - { - // recover global setting, if any - prefmap = preferredServiceMap.get(""); - } - if (prefmap != null) - { - serviceurl = prefmap.get(serviceName); - } - - } - ServiceWithParameters response = null; - for (ServiceWithParameters svc : getServices()) - { - if (svc.getName().equals(serviceName)) - { - if (serviceurl == null || serviceurl.equals(svc.getHostURL())) - { - response = svc; - break; - } - } - } - return response; - } - - public void setPreferredServiceFor(AlignFrame af, String serviceName, - String serviceAction, ServiceWithParameters selectedServer) - { - // TODO: pull out and generalise for the selectedServer's attributes - String afid = (af == null) ? "" : af.getViewport().getSequenceSetId(); - if (preferredServiceMap == null) - { - preferredServiceMap = new HashMap<>(); - } - Map prefmap = preferredServiceMap.get(afid); - if (prefmap == null) - { - prefmap = new HashMap<>(); - preferredServiceMap.put(afid, prefmap); - } - prefmap.put(serviceName, selectedServer.getHostURL()); - prefmap.put(serviceAction, selectedServer.getHostURL()); - } - - public void setPreferredServiceFor(String serviceType, - String serviceAction, ServiceWithParameters selectedServer) - { - setPreferredServiceFor(null, serviceType, serviceAction, - selectedServer); - } - - /** * Set a URL to try before any others. For use with command-line parameter to * configure a local Jabaws installation without the need to add to property * files. -- 1.7.10.2