Configurable service URLs via the otherProperties JS mechanism
authorChristos KK Loverdos <loverdos@gmail.com>
Fri, 31 May 2013 09:29:59 +0000 (12:29 +0300)
committerChristos KK Loverdos <loverdos@gmail.com>
Fri, 31 May 2013 09:29:59 +0000 (12:29 +0300)
I have implemented the following:

* Key STORAGE_API_URL represents the Pithos API
  URL and it is search for in otherProperties.
* Key USER_CATALOGS_API_URL represents the
  /user_catalogs API URL and it is searched for
  in otherProperties.
* If STORAGE_API_URL is found then we use that
  as the API URL otherwise we fall back to the
  previous mechanism.
* If USER_CATALOGS_API_URL is found then we use
  that as the /user_catalogs API URL otherwise
  we fall back to the previous mechanism (which
  is really ad-hoc anyway)

Refs #3884

25 files changed:
src/gr/grnet/pithos/web/client/AddUserDialog.java
src/gr/grnet/pithos/web/client/DeleteFileDialog.java
src/gr/grnet/pithos/web/client/FileContextMenu.java
src/gr/grnet/pithos/web/client/FileList.java
src/gr/grnet/pithos/web/client/FilePermissionsDialog.java
src/gr/grnet/pithos/web/client/FilePropertiesDialog.java
src/gr/grnet/pithos/web/client/FileShareDialog.java
src/gr/grnet/pithos/web/client/FileUploadDialog.java
src/gr/grnet/pithos/web/client/FileVersionsDialog.java
src/gr/grnet/pithos/web/client/FolderPermissionsDialog.java
src/gr/grnet/pithos/web/client/FolderPropertiesDialog.java
src/gr/grnet/pithos/web/client/Pithos.java
src/gr/grnet/pithos/web/client/ToolsMenu.java
src/gr/grnet/pithos/web/client/VersionsList.java
src/gr/grnet/pithos/web/client/catalog/GetUserCatalogs.java
src/gr/grnet/pithos/web/client/catalog/UpdateUserCatalogs.java
src/gr/grnet/pithos/web/client/commands/DeleteGroupCommand.java
src/gr/grnet/pithos/web/client/commands/PasteCommand.java
src/gr/grnet/pithos/web/client/commands/RemoveUserCommand.java
src/gr/grnet/pithos/web/client/commands/RestoreTrashCommand.java
src/gr/grnet/pithos/web/client/commands/ToTrashCommand.java
src/gr/grnet/pithos/web/client/foldertree/FolderTreeViewModel.java
src/gr/grnet/pithos/web/client/mysharedtree/MysharedTreeViewModel.java
src/gr/grnet/pithos/web/client/othersharedtree/OtherSharedTreeViewModel.java
src/gr/grnet/pithos/web/client/tagtree/TagTreeViewModel.java

index 759039f..62552c4 100644 (file)
@@ -173,7 +173,7 @@ public class AddUserDialog extends DialogBox {
         final String userID = app.getIDForUserDisplayName(userDisplayName);\r
         group.addMemberID(userID);\r
         String path = "?update=";\r
-        PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUserID(), path) {\r
+        PostRequest updateGroup = new PostRequest(Pithos.getStorageAPIURL(), app.getUserID(), path) {\r
 \r
             @Override\r
             public void onSuccess(Resource result) {\r
index d53a546..fd6fb98 100644 (file)
@@ -135,7 +135,7 @@ public class DeleteFileDialog extends DialogBox {
         if (iter.hasNext()) {\r
             File f = iter.next();\r
             String path = f.getUri();\r
-            DeleteRequest deleteFile = new DeleteRequest(app.getApiPath(), f.getOwnerID(), URL.encode(path)) {\r
+            DeleteRequest deleteFile = new DeleteRequest(Pithos.getStorageAPIURL(), f.getOwnerID(), URL.encode(path)) {\r
                 @Override\r
                 public void onSuccess(Resource result) {\r
                     deleteFile(iter);\r
index 4dff687..c1f331e 100644 (file)
@@ -41,7 +41,6 @@ import gr.grnet.pithos.web.client.commands.PasteCommand;
 import gr.grnet.pithos.web.client.commands.PropertiesCommand;
 import gr.grnet.pithos.web.client.commands.RestoreTrashCommand;
 import gr.grnet.pithos.web.client.commands.ToTrashCommand;
-import gr.grnet.pithos.web.client.commands.UploadFileCommand;
 import gr.grnet.pithos.web.client.foldertree.File;
 import gr.grnet.pithos.web.client.foldertree.Folder;
 
@@ -250,7 +249,7 @@ public class FileContextMenu extends PopupPanel {
                        @Override
                        public void execute() {
                                for (File f : selectedFiles)
-                                       Window.open(app.getApiPath() + f.getOwnerID() + f.getUri(), "_blank", "");
+                                       Window.open(Pithos.getStorageAPIURL() + f.getOwnerID() + f.getUri(), "_blank", "");
                        }
                }));
 
index cdafa27..4398321 100644 (file)
@@ -288,7 +288,7 @@ public class FileList extends Composite {
                                sb.append(Templates.INSTANCE.filenameSpan(object.getName()));
                                if (object.getContentType() != null && (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg"))) {
                                sb.appendHtmlConstant("&nbsp;")
-                      .append(Templates.INSTANCE.viewLink(app.getApiPath() + object.getOwnerID() + object.getUri(), object.getName()));
+                      .append(Templates.INSTANCE.viewLink(Pithos.getStorageAPIURL() + object.getOwnerID() + object.getUri(), object.getName()));
                                }
                                
                                return sb.toSafeHtml();
@@ -415,7 +415,7 @@ public class FileList extends Composite {
                if (DOM.eventGetType(event) == Event.ONDBLCLICK)
                        if (getSelectedFiles().size() == 1) {
                                File file = getSelectedFiles().get(0);
-                               Window.open(app.getApiPath() + file.getOwnerID() + file.getUri(), "_blank", "");
+                               Window.open(Pithos.getStorageAPIURL() + file.getOwnerID() + file.getUri(), "_blank", "");
                                event.preventDefault();
                                return;
                        }
@@ -647,7 +647,7 @@ public class FileList extends Composite {
                int i = 0;
                boolean scrolled = false;
                for (File f : files) {
-                       if (selectedUrls.contains(app.getApiPath() + f.getOwnerID() + f.getUri())) {
+                       if (selectedUrls.contains(Pithos.getStorageAPIURL() + f.getOwnerID() + f.getUri())) {
                                selectionModel.setSelected(f, true);
                                if (!scrolled) {
                                        celltable.getRowElement(i).getCells().getItem(0).scrollIntoView();
index 1a6183d..bdd3dac 100644 (file)
@@ -240,7 +240,7 @@ public class FilePermissionsDialog extends AbstractPropertiesDialog {
     void showLinkIfShared() {\r
                if (file.isShared()) {\r
                        UrlBuilder b = Window.Location.createUrlBuilder();\r
-                       b.setPath(app.getApiPath() + file.getOwnerID() + file.getUri());\r
+                       b.setPath(Pithos.getStorageAPIURL() + file.getOwnerID() + file.getUri());\r
                        String href = Window.Location.getHref();\r
                        boolean hasParameters = href.contains(Const.QUESTION_MARK);\r
                        path.setText(href + (hasParameters ? Const.AMPERSAND : Const.QUESTION_MARK) + Const.GOTO_EQ + b.buildString());\r
@@ -257,7 +257,7 @@ public class FilePermissionsDialog extends AbstractPropertiesDialog {
        @Override\r
        protected boolean accept() {\r
         updateMetaData(\r
-            app.getApiPath(),\r
+            Pithos.getStorageAPIURL(),\r
             app.getUserID(),\r
             file.getUri() + Const.QUESTION_MARK_UPDATE_EQ,\r
             permList.getPermissions()\r
@@ -270,7 +270,7 @@ public class FilePermissionsDialog extends AbstractPropertiesDialog {
             PostRequest updateFile = new PostRequest(api, owner, path) {\r
                 @Override\r
                 public void onSuccess(Resource result) {\r
-                       HeadRequest<File> headFile = new HeadRequest<File>(File.class, app.getApiPath(), file.getOwnerID(), path, file) {\r
+                       HeadRequest<File> headFile = new HeadRequest<File>(File.class, Pithos.getStorageAPIURL(), file.getOwnerID(), path, file) {\r
 \r
                                                @Override\r
                                                public void onSuccess(File _result) {\r
index d33cd27..75f8378 100644 (file)
@@ -261,10 +261,10 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog {
 \r
         if (newFilename != null) {\r
             final String path = file.getParent().getUri() + "/" + newFilename;\r
-            PutRequest updateFile = new PutRequest(app.getApiPath(), app.getUserID(), path) {\r
+            PutRequest updateFile = new PutRequest(Pithos.getStorageAPIURL(), app.getUserID(), path) {\r
                 @Override\r
                 public void onSuccess(Resource result) {\r
-                    updateMetaData(app.getApiPath(), file.getOwnerID(), path, newMeta);\r
+                    updateMetaData(Pithos.getStorageAPIURL(), file.getOwnerID(), path, newMeta);\r
                 }\r
 \r
                 @Override\r
@@ -313,7 +313,7 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog {
             Scheduler.get().scheduleDeferred(updateFile);\r
         }\r
         else\r
-            updateMetaData(app.getApiPath(), app.getUserID(), file.getUri(), newMeta);\r
+            updateMetaData(Pithos.getStorageAPIURL(), app.getUserID(), file.getUri(), newMeta);\r
         return true;\r
        }\r
 \r
index b57aac5..e02204b 100644 (file)
@@ -436,7 +436,7 @@ public class FileShareDialog extends AbstractPropertiesDialog {
     private void showLinkForPrivateSharing() {
         if (isFilePrivatelyShared()) {
             UrlBuilder b = Window.Location.createUrlBuilder();
-            b.setPath(app.getApiPath() + file.getOwnerID() + file.getUri());
+            b.setPath(Pithos.getStorageAPIURL() + file.getOwnerID() + file.getUri());
             String href = Window.Location.getHref();
             boolean hasParameters = href.contains(Const.QUESTION_MARK);
             privatePathText.setText(href + (hasParameters ? Const.AMPERSAND : Const.QUESTION_MARK) + Const.GOTO_EQ + b.buildString());
@@ -452,7 +452,7 @@ public class FileShareDialog extends AbstractPropertiesDialog {
             PostRequest updateFile = new PostRequest(api, owner, path) {
                 @Override
                 public void onSuccess(Resource result) {
-                       HeadRequest<File> headFile = new HeadRequest<File>(File.class, app.getApiPath(), file.getOwnerID(), path, file) {
+                       HeadRequest<File> headFile = new HeadRequest<File>(File.class, Pithos.getStorageAPIURL(), file.getOwnerID(), path, file) {
 
                                                @Override
                                                public void onSuccess(File _result) {
@@ -515,7 +515,7 @@ public class FileShareDialog extends AbstractPropertiesDialog {
     }
     protected void updateMetaDataForPublicSharing(Boolean published) {
         updateMetaDataForPublicSharing(
-            app.getApiPath(),
+            Pithos.getStorageAPIURL(),
             app.getUserID(),
             file.getUri() + Const.QUESTION_MARK_UPDATE_EQ,
             published
@@ -527,7 +527,7 @@ public class FileShareDialog extends AbstractPropertiesDialog {
             PostRequest updateFile = new PostRequest(api, owner, path) {
                 @Override
                 public void onSuccess(Resource result) {
-                    HeadRequest<File> headFile = new HeadRequest<File>(File.class, app.getApiPath(), file.getOwnerID(), path, file) {
+                    HeadRequest<File> headFile = new HeadRequest<File>(File.class, Pithos.getStorageAPIURL(), file.getOwnerID(), path, file) {
 
                         @Override
                         public void onSuccess(File _result) {
@@ -621,7 +621,7 @@ public class FileShareDialog extends AbstractPropertiesDialog {
     }
     protected void updateMetaDataForPrivateSharing() {
         updateMetaDataForPrivateSharing(
-            app.getApiPath(),
+            Pithos.getStorageAPIURL(),
             app.getUserID(),
             file.getUri() + Const.QUESTION_MARK_UPDATE_EQ,
             permList.getPermissions()
index 04071ef..4ac971e 100644 (file)
@@ -198,7 +198,7 @@ public class FileUploadDialog extends DialogBox {
                                
                                init: {
                                        FilesAdded: function(up, files) {
-                                               var api = app.@gr.grnet.pithos.web.client.Pithos::getApiPath()();
+                                               var api = @gr.grnet.pithos.web.client.Pithos::getStorageAPIURL()();
                                                var folder = app.@gr.grnet.pithos.web.client.Pithos::getUploadFolder()();
                                                var owner = folder.@gr.grnet.pithos.web.client.foldertree.Folder::getOwnerID()();
                                                var uri = folder.@gr.grnet.pithos.web.client.foldertree.Folder::getUri()();
index 43afb5d..0e4e5e8 100644 (file)
@@ -146,7 +146,7 @@ public class FileVersionsDialog extends AbstractPropertiesDialog {
 \r
     protected void fetchVersions() {\r
        String path = file.getUri() + "?format=json&version=list";\r
-       GetRequest<FileVersions> getVersions = new GetRequest<FileVersions>(FileVersions.class, app.getApiPath(), file.getOwnerID(), path) {\r
+       GetRequest<FileVersions> getVersions = new GetRequest<FileVersions>(FileVersions.class, Pithos.getStorageAPIURL(), file.getOwnerID(), path) {\r
 \r
                        @Override\r
                        public void onSuccess(FileVersions _result) {\r
index ecb5765..2f98360 100644 (file)
@@ -214,7 +214,7 @@ public class FolderPermissionsDialog extends DialogBox {
 \r
     private void updateMetadataForPrivateSharing(final String path, final Map<String, Boolean[]> newPermissions) {\r
         if(newPermissions != null) {\r
-            PostRequest updateFolder = new PostRequest(app.getApiPath(), folder.getOwnerID(), path) {\r
+            PostRequest updateFolder = new PostRequest(Pithos.getStorageAPIURL(), folder.getOwnerID(), path) {\r
                 @Override\r
                 public void onSuccess(Resource result) {\r
                     app.updateFolder(folder.getParent(), false, new Command() {\r
@@ -231,7 +231,7 @@ public class FolderPermissionsDialog extends DialogBox {
                     if(t instanceof RestException) {\r
                         if(((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) { //Probably a virtual folder\r
                             final String path1 = folder.getUri();\r
-                            PutRequest newFolder = new PutRequest(app.getApiPath(), folder.getOwnerID(), path1) {\r
+                            PutRequest newFolder = new PutRequest(Pithos.getStorageAPIURL(), folder.getOwnerID(), path1) {\r
                                 @Override\r
                                 public void onSuccess(Resource result) {\r
                                     updateMetadataForPrivateSharing(path, newPermissions);\r
index 9531dcf..e218818 100644 (file)
@@ -249,7 +249,7 @@ public class FolderPropertiesDialog extends DialogBox {
             return;\r
         }\r
         String path = folder.getUri() + "/" + name;\r
-        PutRequest createFolder = new PutRequest(app.getApiPath(), folder.getOwnerID(), path) {\r
+        PutRequest createFolder = new PutRequest(Pithos.getStorageAPIURL(), folder.getOwnerID(), path) {\r
             @Override\r
             public void onSuccess(Resource result) {\r
                 app.updateFolder(folder, true, new Command() {\r
index 2ce488e..f3e6f4b 100644 (file)
@@ -78,7 +78,7 @@ import java.util.*;
  * Entry point classes define <code>onModuleLoad()</code>.
  */
 public class Pithos implements EntryPoint, ResizeHandler {
-    private static final boolean IsLOGEnabled = false;
+    private static final boolean IsLOGEnabled = true;
     public static final boolean IsDetailedHTTPLOGEnabled = true;
     public static final boolean IsFullResponseBodyLOGEnabled = true;
 
@@ -93,6 +93,61 @@ public class Pithos implements EntryPoint, ResizeHandler {
     }
 
     public static final Configuration config = GWT.create(Configuration.class);
+    public static final String CONFIG_API_PATH = config.apiPath();
+    static {
+        LOG("CONFIG_API_PATH = ", CONFIG_API_PATH);
+    }
+
+    public static final Dictionary otherProperties = Dictionary.getDictionary(Const.OTHER_PROPERTIES);
+    public static String getFromOtherPropertiesOrNull(String key) {
+        try {
+            return otherProperties.get(key);
+        }
+        catch(Exception e) {
+            LOGError(e);
+            return null;
+        }
+    }
+    public static final String OTHERPROPS_STORAGE_API_URL = getFromOtherPropertiesOrNull("STORAGE_API_URL");
+    public static final String OTHERPROPS_USER_CATALOGS_API_URL = getFromOtherPropertiesOrNull("USER_CATALOGS_API_URL");
+    static {
+        LOG("STORAGE_API_URL = ", OTHERPROPS_STORAGE_API_URL);
+        LOG("USER_CATALOGS_API_URL = ", OTHERPROPS_USER_CATALOGS_API_URL);
+    }
+
+    public static final String STORAGE_API_URL;
+    static {
+        if(OTHERPROPS_STORAGE_API_URL != null) {
+            STORAGE_API_URL = OTHERPROPS_STORAGE_API_URL;
+        }
+        else if(CONFIG_API_PATH != null) {
+            STORAGE_API_URL = CONFIG_API_PATH;
+        }
+        else {
+            throw new RuntimeException("Unknown STORAGE_API_URL");
+        }
+    }
+    public static final String USER_CATALOGS_API_URL;
+    static {
+        if(OTHERPROPS_USER_CATALOGS_API_URL != null) {
+            USER_CATALOGS_API_URL = OTHERPROPS_USER_CATALOGS_API_URL;
+        }
+        else if(OTHERPROPS_STORAGE_API_URL != null) {
+            throw new RuntimeException("STORAGE_API_URL is defined but USER_CATALOGS_API_URL is not");
+        }
+        else {
+            // https://server.com/v1/ --> https://server.com
+            String url = CONFIG_API_PATH;
+            url = Helpers.stripTrailing(url, "/");
+            url = Helpers.upToIncludingLastPart(url, "/");
+            url = Helpers.stripTrailing(url, "/");
+            url = url + "/user_catalogs";
+
+            USER_CATALOGS_API_URL = url;
+
+            LOG("USER_CATALOGS_API_URL = ", USER_CATALOGS_API_URL);
+        }
+    }
 
     public interface Style extends CssResource {
         String commandAnchor();
@@ -616,7 +671,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                     return true;
                 }
 
-                HeadRequest<Folder> head = new HeadRequest<Folder>(Folder.class, getApiPath(), f.getOwnerID(), "/" + f.getContainer()) {
+                HeadRequest<Folder> head = new HeadRequest<Folder>(Folder.class, getStorageAPIURL(), f.getOwnerID(), "/" + f.getContainer()) {
 
                     @Override
                     public void onSuccess(Folder _result) {
@@ -734,9 +789,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
      * Parse and store the user credentials to the appropriate fields.
      */
     private boolean parseUserCredentials() {
-        Configuration conf = (Configuration) GWT.create(Configuration.class);
-        Dictionary otherProperties = Dictionary.getDictionary(Const.OTHER_PROPERTIES);
-        String cookie = otherProperties.get(Const.AUTH_COOKIE);
+        final String cookie = otherProperties.get(Const.AUTH_COOKIE);
         String auth = Cookies.getCookie(cookie);
         if(auth == null) {
             authenticateUser();
@@ -748,13 +801,13 @@ public class Pithos implements EntryPoint, ResizeHandler {
         if(auth.endsWith("\"")) {
             auth = auth.substring(0, auth.length() - 1);
         }
-        String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2);
+        String[] authSplit = auth.split("\\" + config.cookieSeparator(), 2);
         if(authSplit.length != 2) {
             authenticateUser();
             return false;
         }
-        userID = authSplit[0];
-        userToken = authSplit[1];
+        this.userID = authSplit[0];
+        this.userToken = authSplit[1];
 
         String gotoUrl = Window.Location.getParameter("goto");
         if(gotoUrl != null && gotoUrl.length() > 0) {
@@ -775,7 +828,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
     public void fetchAccount(final Command callback) {
         String path = "?format=json";
 
-        GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, getApiPath(), userID, path) {
+        GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, getStorageAPIURL(), userID, path) {
             @Override
             public void onSuccess(AccountResource accountResource) {
                 account = accountResource;
@@ -818,7 +871,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
     }
 
     public void updateStatistics() {
-        HeadRequest<AccountResource> headAccount = new HeadRequest<AccountResource>(AccountResource.class, getApiPath(), userID, "", account) {
+        HeadRequest<AccountResource> headAccount = new HeadRequest<AccountResource>(AccountResource.class, getStorageAPIURL(), userID, "", account) {
 
             @Override
             public void onSuccess(AccountResource _result) {
@@ -848,7 +901,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
     protected void createHomeContainer(final AccountResource _account, final Command callback) {
         String path = "/" + Const.HOME_CONTAINER;
-        PutRequest createPithos = new PutRequest(getApiPath(), getUserID(), path) {
+        PutRequest createPithos = new PutRequest(getStorageAPIURL(), getUserID(), path) {
             @Override
             public void onSuccess(Resource result) {
                 if(!_account.hasTrashContainer()) {
@@ -882,7 +935,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
     protected void createTrashContainer(final Command callback) {
         String path = "/" + Const.TRASH_CONTAINER;
-        PutRequest createPithos = new PutRequest(getApiPath(), getUserID(), path) {
+        PutRequest createPithos = new PutRequest(getStorageAPIURL(), getUserID(), path) {
             @Override
             public void onSuccess(Resource result) {
                 fetchAccount(callback);
@@ -1023,12 +1076,12 @@ public class Pithos implements EntryPoint, ResizeHandler {
         $doc.body.onselectstart = null;
     }-*/;
 
-    /**
-     * @return the absolute path of the API root URL
-     */
-    public String getApiPath() {
-        Configuration conf = (Configuration) GWT.create(Configuration.class);
-        return conf.apiPath();
+    public static String getStorageAPIURL() {
+        return STORAGE_API_URL;
+    }
+
+    public static String getUserCatalogsURL() {
+        return USER_CATALOGS_API_URL;
     }
 
     /**
@@ -1049,7 +1102,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
         final PleaseWaitPopup pwp = new PleaseWaitPopup();
         pwp.center();
         String path = "/" + folder.getContainer() + "/" + folder.getPrefix() + "?delimiter=/" + "&t=" + System.currentTimeMillis();
-        DeleteRequest deleteFolder = new DeleteRequest(getApiPath(), folder.getOwnerID(), path) {
+        DeleteRequest deleteFolder = new DeleteRequest(getStorageAPIURL(), folder.getOwnerID(), path) {
 
             @Override
             protected void onUnauthorized(Response response) {
@@ -1103,7 +1156,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
         if(iter.hasNext()) {
             File file = iter.next();
             String path = targetUri + "/" + file.getName();
-            PutRequest copyFile = new PutRequest(getApiPath(), targetUsername, path) {
+            PutRequest copyFile = new PutRequest(getStorageAPIURL(), targetUsername, path) {
                 @Override
                 public void onSuccess(Resource result) {
                     copyFiles(iter, targetUsername, targetUri, callback);
@@ -1141,7 +1194,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
     public void copyFolder(final Folder f, final String targetUsername, final String targetUri, boolean move, final Command callback) {
         String path = targetUri + "?delimiter=/";
-        PutRequest copyFolder = new PutRequest(getApiPath(), targetUsername, path) {
+        PutRequest copyFolder = new PutRequest(getStorageAPIURL(), targetUsername, path) {
             @Override
             public void onSuccess(Resource result) {
                 if(callback != null) {
@@ -1380,7 +1433,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
             }
         }
         else {
-            HeadRequest<Folder> headFolder = new HeadRequest<Folder>(Folder.class, getApiPath(), folder.getOwnerID(), folder.getUri(), folder) {
+            HeadRequest<Folder> headFolder = new HeadRequest<Folder>(Folder.class, getStorageAPIURL(), folder.getOwnerID(), folder.getUri(), folder) {
 
                 @Override
                 public void onSuccess(Folder _result) {
@@ -1394,7 +1447,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                     if(t instanceof RestException) {
                         if(((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) {
                             final String path = folder.getUri();
-                            PutRequest newFolder = new PutRequest(getApiPath(), folder.getOwnerID(), path) {
+                            PutRequest newFolder = new PutRequest(getStorageAPIURL(), folder.getOwnerID(), path) {
                                 @Override
                                 public void onSuccess(Resource _result) {
                                     scheduleFolderHeadCommand(folder, callback);
@@ -1448,7 +1501,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
     }
 
     public void scheduleFileHeadCommand(File f, final Command callback) {
-        HeadRequest<File> headFile = new HeadRequest<File>(File.class, getApiPath(), f.getOwnerID(), f.getUri(), f) {
+        HeadRequest<File> headFile = new HeadRequest<File>(File.class, getStorageAPIURL(), f.getOwnerID(), f.getUri(), f) {
 
             @Override
             public void onSuccess(File _result) {
@@ -1562,7 +1615,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
     public void purgeContainer(final Folder container) {
         String path = "/" + container.getName() + "?delimiter=/";
-        DeleteRequest delete = new DeleteRequest(getApiPath(), getUserID(), path) {
+        DeleteRequest delete = new DeleteRequest(getStorageAPIURL(), getUserID(), path) {
 
             @Override
             protected void onUnauthorized(Response response) {
index f96e546..47ec2cc 100644 (file)
@@ -172,7 +172,7 @@ public class ToolsMenu extends PopupPanel {
                                                        @Override
                                                        public void execute() {
                                                        for (File f: files)
-                                                               Window.open(app.getApiPath() + f.getOwnerID() + f.getUri(), "_blank", "");
+                                                               Window.open(Pithos.getStorageAPIURL() + f.getOwnerID() + f.getUri(), "_blank", "");
                                                        }
                                                }));
                                        empty = false;
index b5cee94..246b68b 100644 (file)
@@ -116,7 +116,7 @@ public class VersionsList extends Composite {
                        downloadHtml.addClickHandler(new ClickHandler() {
                                @Override
                                public void onClick(ClickEvent event) {
-                                       String fileUrl = app.getApiPath() + file.getOwnerID() + file.getUri() + "?version=" + v.getVersion();
+                                       String fileUrl = Pithos.getStorageAPIURL() + file.getOwnerID() + file.getUri() + "?version=" + v.getVersion();
                                        Window.open(fileUrl, "_BLANK", "");
                                }
                        });
@@ -132,7 +132,7 @@ public class VersionsList extends Composite {
 
        void restoreVersion(int version) {
                String path = file.getUri() + "?update=";
-               PostRequest restoreVersion = new PostRequest(app.getApiPath(), file.getOwnerID(), path) {
+               PostRequest restoreVersion = new PostRequest(Pithos.getStorageAPIURL(), file.getOwnerID(), path) {
                        
                        @Override
                        public void onSuccess(Resource result) {
index 6b53c56..9fd49cb 100644 (file)
@@ -35,7 +35,6 @@
 
 package gr.grnet.pithos.web.client.catalog;
 
-import com.google.gwt.core.client.GWT;
 import com.google.gwt.core.client.Scheduler;
 import com.google.gwt.http.client.*;
 import com.google.gwt.json.client.JSONArray;
@@ -52,49 +51,22 @@ import java.util.List;
  * The request via which we obtain user catalog info.
  */
 public class GetUserCatalogs implements Scheduler.ScheduledCommand {
-    private final Pithos app;
     private final String url;
     private final String userToken;
     private final List<String> ids;
     private final List<String> names;
 
     public static final int SuccessCode = 200;
-    public static final String CallEndPoint = "/user_catalogs";
     public static final String RequestField_uuids = "uuids";
     public static final String RequestField_displaynames = "displaynames";
     public static final String ResponseField_displayname_catalog = "displayname_catalog";
     public static final String ResponseField_uuid_catalog = "uuid_catalog";
 
-    public GetUserCatalogs(Pithos app) {
-        this(app, null, null);
-    }
-
-    public GetUserCatalogs(Pithos app, String userID) {
-        this(app, Helpers.toList(userID), null);
-    }
-
-    public GetUserCatalogs(Pithos app, List<String> ids) {
-        this(app, ids, null);
-    }
-
-    public GetUserCatalogs(Pithos app, List<String> ids, List<String> names) {
-        assert app != null;
-
-        this.app = app;
-
-        // FIXME: Probably use Window.Location.getHost()
-        // https://server.com/v1/ --> https://server.com
-        String path = app.getApiPath();
-        path = Helpers.stripTrailing(path, "/");
-        path = Helpers.upToIncludingLastPart(path, "/");
-        path = Helpers.stripTrailing(path, "/");
-
-        // https://server.com/user_catalogs
-        this.url = path + CallEndPoint;
-
+    public GetUserCatalogs(String userToken, List<String> ids, List<String> names) {
+        this.url = Pithos.getUserCatalogsURL();
+        this.userToken = userToken;
         this.ids = Helpers.safeList(ids);
         this.names = Helpers.safeList(names);
-        this.userToken = app.getUserToken();
     }
 
     public String getURL() {
@@ -137,7 +109,7 @@ public class GetUserCatalogs implements Scheduler.ScheduledCommand {
     }
 
     public void onError(Request request, Throwable t) {
-        app.LOG("GetUserCatalogs", t);
+        Pithos.LOG("GetUserCatalogs", t);
     }
 
     @Override
@@ -145,7 +117,7 @@ public class GetUserCatalogs implements Scheduler.ScheduledCommand {
         final RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, getURL());
         rb.setHeader(Const.X_AUTH_TOKEN, userToken);
         final String requestData = makeRequestData().toString();
-        app.LOG("GetUserCatalogs => ", requestData);
+        Pithos.LOG("GetUserCatalogs => ", requestData);
         Pithos.LOG("POST ", getURL());
 
         try {
@@ -155,14 +127,14 @@ public class GetUserCatalogs implements Scheduler.ScheduledCommand {
                     final int statusCode = response.getStatusCode();
 
                     if(statusCode != SuccessCode) {
-                        app.LOG("GetUserCatalogs <= [", statusCode, " ", response.getStatusText(), "]");
+                        Pithos.LOG("GetUserCatalogs <= [", statusCode, " ", response.getStatusText(), "]");
                         GetUserCatalogs.this.onBadStatusCode(request, response);
                         return;
                     }
 
                     final String responseText = response.getText();
                     final JSONValue jsonValue = JSONParser.parseStrict(responseText);
-                    app.LOG("GetUserCatalogs <= ", jsonValue.toString());
+                    Pithos.LOG("GetUserCatalogs <= ", jsonValue.toString());
                     final JSONObject result = jsonValue.isObject();
 
                     if(result == null) {
@@ -182,7 +154,7 @@ public class GetUserCatalogs implements Scheduler.ScheduledCommand {
             });
         }
         catch(Exception e) {
-            app.LOG("GetUserCatalogs", e);
+            Pithos.LOG("GetUserCatalogs", e);
         }
     }
 
index 175e4ee..5e46912 100644 (file)
@@ -42,7 +42,6 @@ import com.google.gwt.json.client.JSONObject;
 import gr.grnet.pithos.web.client.Helpers;
 import gr.grnet.pithos.web.client.Pithos;
 
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -78,7 +77,7 @@ public class UpdateUserCatalogs implements Scheduler.ScheduledCommand {
 
     public UpdateUserCatalogs(Pithos app, List<String> ids, List<String> names) {
         this.app = app;
-        this.getUserCatalogs = new GetUserCatalogs(app, ids, names) {
+        this.getUserCatalogs = new GetUserCatalogs(app.getUserToken(), ids, names) {
             @Override
             public void onSuccess(Request request, Response response, JSONObject result, UserCatalogs userCatalogs) {
                 UpdateUserCatalogs.this.app.getUserCatalogs().updateFrom(userCatalogs);
index 0d979ba..023ba9e 100644 (file)
@@ -75,7 +75,7 @@ public class DeleteGroupCommand implements Command {
                containerPanel.hide();
         if (Window.confirm("Are you sure you want to delete group " + group.getName())) {
                String path = "?update=";
-               PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUserID(), path) {
+               PostRequest updateGroup = new PostRequest(Pithos.getStorageAPIURL(), app.getUserID(), path) {
                                
                                @Override
                                public void onSuccess(Resource result) {
index 6261090..853f205 100644 (file)
@@ -137,7 +137,7 @@ public class PasteCommand implements Command {
         if (iter.hasNext()) {
             File file = iter.next();
             String path = folder.getUri() + "/" + file.getName();
-            PutRequest copyFile = new PutRequest(app.getApiPath(), folder.getOwnerID(), path) {
+            PutRequest copyFile = new PutRequest(Pithos.getStorageAPIURL(), folder.getOwnerID(), path) {
                 @Override
                 public void onSuccess(Resource result) {
                     moveFiles(iter, callback);
index 9fba21e..d522228 100644 (file)
@@ -78,7 +78,7 @@ public class RemoveUserCommand implements Command {
                return;
        group.removeMemberID(user.getUserID());
        String path = "?update=";
-       PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUserID(), path) {
+       PostRequest updateGroup = new PostRequest(Pithos.getStorageAPIURL(), app.getUserID(), path) {
                        
                        @Override
                        public void onSuccess(Resource result) {
index 8778236..38354a6 100644 (file)
@@ -117,7 +117,7 @@ public class RestoreTrashCommand implements Command {
         if (iter.hasNext()) {
             File file = iter.next();
             String path = "/" + Const.HOME_CONTAINER + "/" + file.getPath();
-            PutRequest untrashFile = new PutRequest(app.getApiPath(), app.getUserID(), path) {
+            PutRequest untrashFile = new PutRequest(Pithos.getStorageAPIURL(), app.getUserID(), path) {
                 @Override
                 public void onSuccess(Resource result) {
                     untrashFiles(iter, callback);
index 2e257cd..58d21b2 100644 (file)
@@ -127,7 +127,7 @@ public class ToTrashCommand implements Command{
         if (iter.hasNext()) {
             File file = iter.next();
             String path = "/" + Const.TRASH_CONTAINER + "/" + file.getPath();
-            PutRequest trashFile = new PutRequest(app.getApiPath(), app.getUserID(), path) {
+            PutRequest trashFile = new PutRequest(Pithos.getStorageAPIURL(), app.getUserID(), path) {
                 @Override
                 public void onSuccess(Resource result) {
                     trashFiles(iter, callback);
index 2163c4e..1d38e4f 100644 (file)
@@ -152,7 +152,7 @@ public class FolderTreeViewModel implements TreeViewModel {
             final Folder f = iter.next();
 
             String path = "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix());
-            GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), f.getOwnerID(), path, f) {
+            GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, Pithos.getStorageAPIURL(), f.getOwnerID(), path, f) {
                 @Override
                 public void onSuccess(Folder _result) {
                     fetchFolder(iter, callback);
@@ -236,7 +236,7 @@ public class FolderTreeViewModel implements TreeViewModel {
 
     public void fetchFolder(final Folder f, final ListDataProvider<Folder> dataProvider, final boolean showfiles, final Command callback) {
         String path = "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix());
-        GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), f.getOwnerID(), path, f) {
+        GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, Pithos.getStorageAPIURL(), f.getOwnerID(), path, f) {
             @Override
             public void onSuccess(final Folder _result) {
                 if (showfiles)
index 9598c87..d1bf9c6 100644 (file)
@@ -121,7 +121,7 @@ public class MysharedTreeViewModel implements TreeViewModel {
        private void fetchSharedContainers(final Command callback) {
         app.LOG("MysharedTreeViewModel::fetchSharedContainers(), callback=", callback);
         String path = "?format=json&shared=&public=";
-        GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, app.getApiPath(), app.getUserID(), path) {
+        GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, Pithos.getStorageAPIURL(), app.getUserID(), path) {
             @Override
             public void onSuccess(final AccountResource _result) {
                                firstLevelDataProvider.getList().clear();
@@ -171,7 +171,7 @@ public class MysharedTreeViewModel implements TreeViewModel {
             final Folder f = iter.next();
 
             String path = "/" + f.getContainer() + "?format=json&shared=&public=&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix());
-            GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), f.getOwnerID(), path, f) {
+            GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, Pithos.getStorageAPIURL(), f.getOwnerID(), path, f) {
                 @Override
                 public void onSuccess(Folder _result) {
                     fetchFolder(iter, callback);
@@ -211,7 +211,7 @@ public class MysharedTreeViewModel implements TreeViewModel {
     public void fetchFolder(final Folder f, final boolean showfiles, final Command callback) {
         app.LOG("MysharedTreeViewModel::fetchFolder(), folder=", f, ", showfiles=", showfiles, ", callback=", callback);
         String path = "/" + f.getContainer() + "?format=json&shared=&public=" + URL.encodeQueryString(f.getPrefix());
-        GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), f.getOwnerID(), path, f) {
+        GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, Pithos.getStorageAPIURL(), f.getOwnerID(), path, f) {
             @Override
             public void onSuccess(final Folder _result) {
                for (File file : _result.getFiles()) {
index fedb1c2..53b68c3 100644 (file)
@@ -171,7 +171,7 @@ public class OtherSharedTreeViewModel implements TreeViewModel {
 
     private void fetchSharingUsers(final Command callback) {
         app.LOG("OtherSharedTreeViewModel::fetchSharingUsers() callback=", callback);
-        GetRequest<SharingUsers> getSharingUsers = new GetRequest<SharingUsers>(SharingUsers.class, app.getApiPath(), "", "?format=json") {
+        GetRequest<SharingUsers> getSharingUsers = new GetRequest<SharingUsers>(SharingUsers.class, Pithos.getStorageAPIURL(), "", "?format=json") {
             @Override
             public void onSuccess(final SharingUsers _result) {
                 userLevelDataProviderForIDs.getList().clear();
@@ -282,7 +282,7 @@ public class OtherSharedTreeViewModel implements TreeViewModel {
 
     private void fetchSharedContainers(final String userID, final ListDataProvider<Folder> dataProvider, final Command callback) {
         app.LOG("OtherSharedTreeViewModel::fetchSharedContainers(), userID=", userID, ", callback=", callback);
-        GetRequest<AccountResource> getUserSharedContainers = new GetRequest<AccountResource>(AccountResource.class, app.getApiPath(), userID, "?format=json") {
+        GetRequest<AccountResource> getUserSharedContainers = new GetRequest<AccountResource>(AccountResource.class, Pithos.getStorageAPIURL(), userID, "?format=json") {
 
             @Override
             public void onSuccess(AccountResource _result) {
@@ -328,7 +328,7 @@ public class OtherSharedTreeViewModel implements TreeViewModel {
             final Folder f = folderIterator.next();
 
             String path = "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix());
-            GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), userID, path, f) {
+            GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, Pithos.getStorageAPIURL(), userID, path, f) {
                 @Override
                 public void onSuccess(Folder _result) {
                     dataProvider.getList().add(_result);
@@ -376,7 +376,7 @@ public class OtherSharedTreeViewModel implements TreeViewModel {
     public void fetchFolder(final Folder f, final ListDataProvider<Folder> dataProvider, final boolean showfiles, final Command callback) {
         app.LOG("OtherSharedTreeViewModel::fetchFolder(), folder=", f, ", showfiles=", showfiles, ", callback=", callback);
         String path = "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix());
-        GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), f.getOwnerID(), path, f) {
+        GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, Pithos.getStorageAPIURL(), f.getOwnerID(), path, f) {
             @Override
             public void onSuccess(final Folder _result) {
                 if(showfiles) {
index 653db23..9fd2a94 100644 (file)
@@ -147,7 +147,7 @@ public class TagTreeViewModel implements TreeViewModel {
         if (iter.hasNext()) {
             Folder f = iter.next();
             String path = f.getUri() + "?format=json&meta=" + t.getName();
-            GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), app.getUserID(), path) {
+            GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, Pithos.getStorageAPIURL(), app.getUserID(), path) {
                 @Override
                 public void onSuccess(Folder _result) {
                     files.addAll(_result.getFiles());