JAL-2461 Removed DAS error stack trace, updated message
[jalview.git] / src / jalview / ws / dbsources / das / datamodel / DasSourceRegistry.java
index 777c4a4..e0f7f70 100644 (file)
@@ -1,26 +1,39 @@
-/**
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * 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.HashSet;
 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;
@@ -30,10 +43,6 @@ 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;
-
 /**
  *
  */
@@ -47,7 +56,8 @@ public class DasSourceRegistry implements DasSourceRegistryI,
 
   private Hashtable<String, jalviewSourceI> localSources = null;
 
-  public static String DEFAULT_REGISTRY = "http://www.dasregistry.org/das/";
+  // 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
@@ -59,6 +69,7 @@ public class DasSourceRegistry implements DasSourceRegistryI,
     return loadingDasSources;
   }
 
+  @Override
   public String getDasRegistryURL()
   {
     String registry = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",
@@ -73,8 +84,10 @@ public class DasSourceRegistry implements DasSourceRegistryI,
     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")));
+      jalview.bin.Cache.setProperty(
+              jalview.bin.Cache.DAS_REGISTRY_URL,
+              registry = registry.substring(0,
+                      registry.lastIndexOf("sources.xml")));
     }
     return registry;
   }
@@ -98,7 +111,8 @@ public class DasSourceRegistry implements DasSourceRegistryI,
    * @param registryURL
    *          return sources from registryURL
    */
-  private static List<jalviewSourceI> getDASSources(String registryURL, MultipleConnectionPropertyProviderI registry)
+  private static List<jalviewSourceI> getDASSources(String registryURL,
+          MultipleConnectionPropertyProviderI registry)
   {
     try
     {
@@ -110,21 +124,26 @@ public class DasSourceRegistry implements DasSourceRegistryI,
 
       List<SOURCE> dassources = sources.getSOURCE();
       ArrayList<jalviewSourceI> dsrc = new ArrayList<jalviewSourceI>();
-      HashMap<String,Integer> latests=new HashMap<String, Integer>();
+      HashMap<String, Integer> latests = new HashMap<String, Integer>();
       Integer latest;
       for (SOURCE src : dassources)
       {
-        JalviewSource jsrc=new JalviewSource(src, registry, false);
-        latest=latests.get(jsrc.getSourceURL());
-        if (latest!=null)
+        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: Ingored older source "+jsrc.getTitle());
           }
-        } else {
+          else
+          {
+            System.out.println("Debug: Ignored older source "
+                    + jsrc.getTitle());
+          }
+        }
+        else
+        {
           latests.put(jsrc.getSourceURL(), Integer.valueOf(dsrc.size()));
           dsrc.add(jsrc);
         }
@@ -132,9 +151,8 @@ public class DasSourceRegistry implements DasSourceRegistryI,
       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<jalviewSourceI>();
     }
   }
@@ -153,7 +171,7 @@ public class DasSourceRegistry implements DasSourceRegistryI,
     }
     return appendLocalSources();
   }
-  
+
   /**
    * generate Sources from the local das source list
    * 
@@ -164,13 +182,21 @@ public class DasSourceRegistry implements DasSourceRegistryI,
     {
       // get local sources from properties and initialise the local source list
       String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");
+
       if (local != null)
       {
+        int n = 1;
         StringTokenizer st = new StringTokenizer(local, "\t");
         while (st.hasMoreTokens())
         {
           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:"))
@@ -179,8 +205,25 @@ public class DasSourceRegistry implements DasSourceRegistryI,
             // this source also serves sequences as well as features
             sequence = true;
           }
-          createLocalSource(url, token.substring(0, bar), sequence,
-                  features);
+          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++;
         }
       }
     }
@@ -216,8 +259,8 @@ public class DasSourceRegistry implements DasSourceRegistryI,
   }
 
   /*
- * 
- */
+  * 
+  */
 
   @Override
   public jalviewSourceI createLocalSource(String url, String name,