JAL-972 workaround for working out source URL for pre DAS 1.6 sources.
authorjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 11 May 2012 13:22:08 +0000 (14:22 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 11 May 2012 13:22:08 +0000 (14:22 +0100)
note - certain sources currently in registry have invalid URLs in their capability elements (missing '/' between URL and command)

src/jalview/ws/dbsources/das/datamodel/JalviewSource.java

index 11bdf02..139bafe 100644 (file)
@@ -311,9 +311,23 @@ public class JalviewSource implements jalviewSourceI
   {
     try
     {
-      String url = new RegistrySourceAdapter(source)
-              .getOriginalDataSourceUri();
-      return url;
+      // kind of dumb, since org.biodas.jdas.dassources.utils.VersionAdapter.getSourceUriFromQueryUri() does this,
+      // but this way, we can access non DAS 1.6 compliant sources (which have to have a URL like <sourcename>/das/ and cause a validation exception)
+      
+      for (CAPABILITY cap : getVersion().getCAPABILITY())
+      {
+        String capname = cap.getType().substring(
+                cap.getType().indexOf(":") + 1);
+        int p=cap.getQueryUri().lastIndexOf(capname);
+        if (p<-1) {
+          throw new Exception("Invalid das source: "+source.getUri());
+        } 
+        if (cap.getQueryUri().charAt(p)=='/')
+        {
+          p--;
+        }
+        return cap.getQueryUri().substring(0,p);
+      }
     } catch (Exception x)
     {
       System.err.println("Serious: Couldn't get the URL for source "