From c66f1df6d7a4f9c800a7006e5195b32fdbfda9cf Mon Sep 17 00:00:00 2001
From: cramakri <cramakri>
Date: Wed, 2 Jun 2010 11:37:58 +0000
Subject: [PATCH] MINOR: Fix problem obtaining data store base URL.

SVN: 16258
---
 .../dss/client/api/v1/impl/DssComponent.java  | 28 ++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/v1/impl/DssComponent.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/v1/impl/DssComponent.java
index 39e7c04d26d..72b13d87fd1 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/v1/impl/DssComponent.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/v1/impl/DssComponent.java
@@ -16,6 +16,8 @@
 
 package ch.systemsx.cisd.openbis.dss.client.api.v1.impl;
 
+import static ch.systemsx.cisd.openbis.generic.shared.GenericSharedConstants.DATA_STORE_SERVER_WEB_APPLICATION_NAME;
+
 import java.io.InputStream;
 import java.util.Collection;
 
@@ -335,7 +337,7 @@ class AuthenticatedState extends AbstractDssComponentState
         }
         DataStore dataStore = dataSetOpenBis.getDataStore();
 
-        String url = dataStore.getDownloadUrl();
+        String url = getDataStoreUrlFromDataStore(dataStore);
 
         IDssServiceRpcGeneric dssService = getDssServiceForUrl(url);
         // Return a proxy to the data set
@@ -428,6 +430,30 @@ class AuthenticatedState extends AbstractDssComponentState
                 + IDssServiceRpcGeneric.DSS_SERVICE_NAME + " interface.");
     }
 
+    /**
+     * The data store only stores the download url, get the data store url
+     */
+    // TODO 2010-06-02, CR, , -- Put this method in a better place
+    // Maybe on DataStore.
+    private String getDataStoreUrlFromDataStore(DataStore dataStore)
+    {
+        String datastoreUrl = dataStore.getDownloadUrl();
+        // The url objained form a DataStore object is the *download* url. Convert this to the
+        // datastore URL
+        if (datastoreUrl.endsWith(DATA_STORE_SERVER_WEB_APPLICATION_NAME))
+        {
+            datastoreUrl =
+                    datastoreUrl.substring(0, datastoreUrl.length()
+                            - DATA_STORE_SERVER_WEB_APPLICATION_NAME.length());
+        }
+        if (datastoreUrl.endsWith("/"))
+        {
+            datastoreUrl = datastoreUrl.substring(0, datastoreUrl.length() - 1);
+        }
+
+        return datastoreUrl;
+    }
+
     @Override
     public String getSessionToken()
     {
-- 
GitLab