X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fdbsources%2Fdas%2Fdatamodel%2FDasSourceRegistry.java;h=de7f380132869ccbc607fc1c5fcd004b2aed8676;hb=788e840cc150aa4777a370cebfdf5d17589bbbaf;hp=b17f7f25f3852bff0a16bccc722d5ddff515292a;hpb=339ed5130c391c6028e01222e8ba293b8209b524;p=jalview.git diff --git a/src/jalview/ws/dbsources/das/datamodel/DasSourceRegistry.java b/src/jalview/ws/dbsources/das/datamodel/DasSourceRegistry.java index b17f7f2..de7f380 100644 --- a/src/jalview/ws/dbsources/das/datamodel/DasSourceRegistry.java +++ b/src/jalview/ws/dbsources/das/datamodel/DasSourceRegistry.java @@ -1,41 +1,53 @@ -/** +/* + * 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. + * + * 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; +import jalview.bin.Cache; +import jalview.ws.dbsources.das.api.DasSourceRegistryI; +import jalview.ws.dbsources.das.api.jalviewSourceI; + 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; import org.biodas.jdas.dassources.Capabilities; import org.biodas.jdas.schema.sources.CAPABILITY; import org.biodas.jdas.schema.sources.SOURCE; import org.biodas.jdas.schema.sources.SOURCES; import org.biodas.jdas.schema.sources.VERSION; -import jalview.bin.Cache; -import jalview.ws.dbsources.das.api.DasSourceRegistryI; -import jalview.ws.dbsources.das.api.jalviewSourceI; - /** * */ -public class DasSourceRegistry implements DasSourceRegistryI +public class DasSourceRegistry + implements DasSourceRegistryI, MultipleConnectionPropertyProviderI { // private org.biodas.jdas.schema.sources.SOURCE[] dasSources = null; private List dasSources = null; @@ -44,7 +56,8 @@ 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/"; + public static String DEFAULT_REGISTRY = "http://www.ebi.ac.uk/das-srv/registry/das/"; /** * true if thread is running and we are talking to DAS registry service @@ -56,6 +69,7 @@ public class DasSourceRegistry implements DasSourceRegistryI return loadingDasSources; } + @Override public String getDasRegistryURL() { String registry = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL", @@ -67,6 +81,13 @@ 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; } @@ -80,7 +101,7 @@ public class DasSourceRegistry implements DasSourceRegistryI private List getDASSources() { - return getDASSources(getDasRegistryURL()); + return getDASSources(getDasRegistryURL(), this); } /** @@ -89,32 +110,52 @@ 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) { - System.err.println("Failed to contact DAS1 registry at " - + registryURL); - ex.printStackTrace(); + System.out.println( + "DAS1 registry at " + registryURL + " no longer exists"); return new ArrayList(); } } - public void run() { getSources(); @@ -136,30 +177,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) @@ -187,8 +258,8 @@ public class DasSourceRegistry implements DasSourceRegistryI } /* - * - */ + * + */ @Override public jalviewSourceI createLocalSource(String url, String name, @@ -200,7 +271,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; } @@ -225,14 +296,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); } @@ -256,6 +327,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; @@ -298,8 +372,7 @@ public class DasSourceRegistry implements DasSourceRegistryI { String token = en.nextElement().toString(); jalviewSourceI srco = localSources.get(token); - sb.append(token + "|" - + (srco.isSequenceSource() ? "sequence:" : "") + sb.append(token + "|" + (srco.isSequenceSource() ? "sequence:" : "") + srco.getUri() + "\t"); } return sb.toString(); @@ -315,8 +388,8 @@ public class DasSourceRegistry implements DasSourceRegistryI try { // TODO: allow same credentials for https and http - authStash.put(new URL( - "http://www.compbio.dundee.ac.uk/geneweb/das/myseq/"), + authStash.put( + new URL("http://www.compbio.dundee.ac.uk/geneweb/das/myseq/"), "Basic SmltOm1pSg=="); } catch (MalformedURLException e) { @@ -326,8 +399,16 @@ public class DasSourceRegistry implements DasSourceRegistryI } @Override - public Map getSessionHandler() + public MultipleConnectionPropertyProviderI getSessionHandler() + { + return this; + } + + @Override + public ConnectionPropertyProviderI getConnectionPropertyProviderFor( + String arg0) { + final ConnectionPropertyProviderI conprov = new ConnectionPropertyProviderI() { boolean authed = false; @@ -380,8 +461,8 @@ public class DasSourceRegistry implements DasSourceRegistryI if (asuc != null && asuc.trim().length() > 0) { // authentication was successful - Cache.log.debug("Authenticated successfully as " + asuc - + " with " + connection.getURL().toString()); + Cache.log.debug("Authenticated successfully to " + + connection.getURL().toString()); return false; } // it wasn't - so we should tell the user it failed and ask if they @@ -397,95 +478,7 @@ public class DasSourceRegistry implements DasSourceRegistryI } } }; - return new Map() - { - - @Override - public void clear() - { - // TODO Auto-generated method stub - - } - - @Override - public boolean containsKey(Object key) - { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean containsValue(Object value) - { - // TODO Auto-generated method stub - return false; - } - - @Override - public Set> entrySet() - { - // TODO Auto-generated method stub - return null; - } - - @Override - public ConnectionPropertyProviderI get(Object key) - { - return conprov; - } - - @Override - public boolean isEmpty() - { - // TODO Auto-generated method stub - return false; - } - - @Override - public Set keySet() - { - // TODO Auto-generated method stub - return null; - } - - @Override - public ConnectionPropertyProviderI put(String key, - ConnectionPropertyProviderI value) - { - // TODO Auto-generated method stub - return null; - } - - @Override - public void putAll( - Map m) - { - // TODO Auto-generated method stub - - } - - @Override - public ConnectionPropertyProviderI remove(Object key) - { - // TODO Auto-generated method stub - return null; - } - - @Override - public int size() - { - // TODO Auto-generated method stub - return 0; - } - - @Override - public Collection values() - { - // TODO Auto-generated method stub - return null; - } - - }; + return conprov; } }