X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fws%2Fdbsources%2Fdas%2Fdatamodel%2FDasSourceRegistry.java;h=98140d71bff40dbd6630744999249b603599f864;hb=a8f483d04205bb8273ee311c12968b7e86d205fa;hp=cf782024e4326487e06d4693822d49e03bb4a08a;hpb=daf7e11e56c1c5d99c2c1bc0113f33d2f0375f93;p=jalview.git diff --git a/src/jalview/ws/dbsources/das/datamodel/DasSourceRegistry.java b/src/jalview/ws/dbsources/das/datamodel/DasSourceRegistry.java index cf78202..98140d7 100644 --- a/src/jalview/ws/dbsources/das/datamodel/DasSourceRegistry.java +++ b/src/jalview/ws/dbsources/das/datamodel/DasSourceRegistry.java @@ -1,5 +1,20 @@ -/** +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) + * Copyright (C) 2014 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.dbsources.das.datamodel; @@ -7,19 +22,12 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; -import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; import java.util.List; -import java.util.Map; -import java.util.Set; import java.util.StringTokenizer; -import java.util.Vector; - -import javax.swing.JOptionPane; -import org.apache.http.auth.InvalidCredentialsException; import org.biodas.jdas.client.ConnectionPropertyProviderI; import org.biodas.jdas.client.SourcesClient; import org.biodas.jdas.client.threads.MultipleConnectionPropertyProviderI; @@ -46,7 +54,7 @@ public class DasSourceRegistry implements DasSourceRegistryI, private Hashtable localSources = null; - public static String DEFAULT_REGISTRY = "http://www.dasregistry.org/das1/sources/"; + public static String DEFAULT_REGISTRY = "http://www.dasregistry.org/das/"; /** * true if thread is running and we are talking to DAS registry service @@ -69,6 +77,14 @@ public class DasSourceRegistry implements DasSourceRegistryI, DEFAULT_REGISTRY); registry = DEFAULT_REGISTRY; } + if (registry.lastIndexOf("sources.xml") == registry.length() - 11) + { + // no trailing sources.xml document for registry in JDAS + jalview.bin.Cache.setProperty( + jalview.bin.Cache.DAS_REGISTRY_URL, + registry = registry.substring(0, + registry.lastIndexOf("sources.xml"))); + } return registry; } @@ -82,7 +98,7 @@ public class DasSourceRegistry implements DasSourceRegistryI, private List getDASSources() { - return getDASSources(getDasRegistryURL()); + return getDASSources(getDasRegistryURL(), this); } /** @@ -91,20 +107,42 @@ public class DasSourceRegistry implements DasSourceRegistryI, * @param registryURL * return sources from registryURL */ - private static List getDASSources(String registryURL) + private static List getDASSources(String registryURL, + MultipleConnectionPropertyProviderI registry) { try { URL url = new URL(registryURL); org.biodas.jdas.client.SourcesClientInterface client = new SourcesClient(); - SOURCES sources = client.fetchDataRegistry(registryURL, null, null, null, null, null, null); + SOURCES sources = client.fetchDataRegistry(registryURL, null, null, + null, null, null, null); List dassources = sources.getSOURCE(); ArrayList dsrc = new ArrayList(); + HashMap latests = new HashMap(); + Integer latest; for (SOURCE src : dassources) { - dsrc.add(new JalviewSource(src, false)); + JalviewSource jsrc = new JalviewSource(src, registry, false); + latest = latests.get(jsrc.getSourceURL()); + if (latest != null) + { + if (jsrc.isNewerThan(dsrc.get(latest.intValue()))) + { + dsrc.set(latest.intValue(), jsrc); + } + else + { + System.out.println("Debug: Ignored older source " + + jsrc.getTitle()); + } + } + else + { + latests.put(jsrc.getSourceURL(), Integer.valueOf(dsrc.size())); + dsrc.add(jsrc); + } } return dsrc; } catch (Exception ex) @@ -116,7 +154,6 @@ public class DasSourceRegistry implements DasSourceRegistryI, } } - public void run() { getSources(); @@ -138,30 +175,60 @@ public class DasSourceRegistry implements DasSourceRegistryI, */ private void addLocalDasSources() { - String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE"); - if (local != null) + if (localSources == null) { - StringTokenizer st = new StringTokenizer(local, "\t"); - while (st.hasMoreTokens()) + // get local sources from properties and initialise the local source list + String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE"); + + if (local != null) { - String token = st.nextToken(); - int bar = token.indexOf("|"); - String url = token.substring(bar + 1); - boolean features = true, sequence = false; - if (url.startsWith("sequence:")) + int n = 1; + StringTokenizer st = new StringTokenizer(local, "\t"); + while (st.hasMoreTokens()) { - url = url.substring(9); - // this source also serves sequences as well as features - sequence = true; + String token = st.nextToken(); + int bar = token.indexOf("|"); + if (bar == -1) + { + System.err + .println("Warning: DAS user local source appears to have no nickname (expected a '|' followed by nickname)\nOffending definition: '" + + token + "'"); + } + String url = token.substring(bar + 1); + boolean features = true, sequence = false; + if (url.startsWith("sequence:")) + { + url = url.substring(9); + // this source also serves sequences as well as features + sequence = true; + } + try + { + if (bar > -1) + { + createLocalSource(url, token.substring(0, bar), sequence, + features); + } + else + { + createLocalSource(url, "User Source" + n, sequence, features); + } + } catch (Exception q) + { + System.err + .println("Unexpected exception when creating local source from '" + + token + "'"); + q.printStackTrace(); + } + n++; } - createLocalSource(url, token.substring(0, bar), sequence, features); } } } private List appendLocalSources() { - List srclist=new ArrayList(); + List srclist = new ArrayList(); addLocalDasSources(); sourceNames = new Hashtable(); if (dasSources != null) @@ -202,7 +269,7 @@ public class DasSourceRegistry implements DasSourceRegistryI, { localSources = new Hashtable(); } - jalviewSourceI src=new JalviewSource(local, true); + jalviewSourceI src = new JalviewSource(local, this, true); localSources.put(local.getTitle(), src); return src; } @@ -227,14 +294,14 @@ public class DasSourceRegistry implements DasSourceRegistryI, */ CAPABILITY cap = new CAPABILITY(); cap.setType("das1:" + Capabilities.SEQUENCE.getName()); - cap.setQueryUri(url+"/sequence"); + cap.setQueryUri(url + "/sequence"); cp.add(cap); } if (features) { CAPABILITY cap = new CAPABILITY(); cap.setType("das1:" + Capabilities.FEATURES.getName()); - cap.setQueryUri(url+"/features"); + cap.setQueryUri(url + "/features"); cp.add(cap); } @@ -258,6 +325,9 @@ public class DasSourceRegistry implements DasSourceRegistryI, localSources.remove(source.getTitle()); sourceNames.remove(source.getTitle()); dasSources.remove(source); + jalview.bin.Cache.setProperty("DAS_LOCAL_SOURCE", + getLocalSourceString()); + return true; } return false;