Create container pithos if no containers exist
authorChristos Stathis <chstath@ebs.gr>
Fri, 22 Jul 2011 11:13:30 +0000 (14:13 +0300)
committerChristos Stathis <chstath@ebs.gr>
Fri, 22 Jul 2011 11:13:30 +0000 (14:13 +0300)
src/gr/grnet/pithos/web/client/Pithos.java

index 7d93af1..f420b4d 100644 (file)
@@ -483,8 +483,11 @@ public class Pithos implements EntryPoint, ResizeHandler {
             public void onSuccess(AccountResource result) {
                 account = result;
                 statusPanel.displayStats(account);
-                folderTreeViewModel.initialize(account);
                 inner.selectTab(0);
+                if (account.getContainers().isEmpty())
+                    createHomeContainers();
+                else
+                    folderTreeViewModel.initialize(account);
             }
 
             @Override
@@ -500,6 +503,27 @@ public class Pithos implements EntryPoint, ResizeHandler {
         Scheduler.get().scheduleDeferred(getAccount);
     }
 
+    private void createHomeContainers() {
+        String path = getApiPath() + getUsername() + "/pithos";
+        PutRequest createPithos = new PutRequest(path) {
+            @Override
+            public void onSuccess(Resource result) {
+                fetchAccount();
+            }
+
+            @Override
+            public void onError(Throwable t) {
+                GWT.log("Error creating pithos", t);
+                if (t instanceof RestException)
+                    Pithos.get().displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
+                else
+                    Pithos.get().displayError("System error Error creating pithos: " + t.getMessage());
+            }
+        };
+        createPithos.setHeader("X-Auth-Token", getToken());
+        Scheduler.get().scheduleDeferred(createPithos);
+    }
+
        /**
         * Clear the cookie and redirect the user to the logout page.
         */