Automated merge with https://gss.googlecode.com/hg/
[pithos] / src / gr / ebs / gss / client / rest / resource / FolderResource.java
index 3ee8683..59e25c3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009 Electronic Business Systems Ltd.
+ * Copyright 2009, 2010 Electronic Business Systems Ltd.
  *
  * This file is part of GSS.
  *
@@ -19,6 +19,8 @@
 
 package gr.ebs.gss.client.rest.resource;
 
+import gr.ebs.gss.client.DisplayHelper;
+import gr.ebs.gss.client.GSS;
 import gr.ebs.gss.client.rest.MultipleGetCommand;
 import gr.ebs.gss.client.rest.MultipleGetCommand.Cached;
 
@@ -34,6 +36,7 @@ import com.google.gwt.http.client.URL;
 import com.google.gwt.json.client.JSONArray;
 import com.google.gwt.json.client.JSONObject;
 import com.google.gwt.json.client.JSONParser;
+import com.google.gwt.user.client.ui.TreeItem;
 
 /**
  * @author kman
@@ -76,6 +79,30 @@ public class FolderResource extends RestResource {
 
        private boolean filesExpanded=false;
 
+       boolean readForAll;
+       
+       Boolean shared;
+       
+       
+       /**
+        * Retrieve the shared.
+        *
+        * @return the shared
+        */
+       public Boolean getShared() {
+               return shared;
+       }
+       
+       
+       /**
+        * Modify the shared.
+        *
+        * @param shared the shared to set
+        */
+       public void setShared(Boolean shared) {
+               this.shared = shared;
+       }
+
        /**
         * Modify the parentName.
         *
@@ -90,6 +117,7 @@ public class FolderResource extends RestResource {
         *
         * @return the name
         */
+       @Override
        public String getName() {
                return name;
        }
@@ -333,7 +361,11 @@ public class FolderResource extends RestResource {
                JSONObject json = (JSONObject) JSONParser.parse(text);
                name = unmarshallString(json, "name");
                owner = unmarshallString(json, "owner");
+               createdBy = unmarshallString(json, "createdBy");
+               modifiedBy = unmarshallString(json, "modifiedBy");
                deleted = unmarshallBoolean(json, "deleted");
+               shared = unmarshallBoolean(json, "shared");
+               readForAll = unmarshallBoolean(json, "readForAll");
                if (deleted)
                        GWT.log("FOUND A DELETED FOLDER:" + name, null);
 
@@ -341,8 +373,6 @@ public class FolderResource extends RestResource {
                        JSONObject parent = json.get("parent").isObject();
                        parentURI = unmarshallString(parent, "uri");
                        parentName = unmarshallString(parent, "name");
-                       if(parentName != null)
-                               parentName = URL.decodeComponent(parentName);
                }
 
                if (json.get("permissions") != null) {
@@ -376,6 +406,8 @@ public class FolderResource extends RestResource {
                                                                subUri = subUri + "/";
                                                        FolderResource sub = new FolderResource(subUri);
                                                        sub.setName(subName);
+                                                       sub.setParentURI(uri);
+                                                       sub.setParentName(name);
                                                        sub.setNeedsExpanding(true);
                                                        folders.add(sub);
                                                        subfolderPaths.add(subUri);
@@ -393,6 +425,7 @@ public class FolderResource extends RestResource {
                                                String fowner = unmarshallString(fo, "owner");
                                                String fcontent = unmarshallString(fo, "content");
                                                String fpath = unmarshallString(fo, "path");
+                                               Boolean fshared = unmarshallBoolean(fo, "shared");
                                                fpath = URL.decodeComponent(fpath);
                                                Integer fversion = null;
                                                if (fo.get("version") != null)
@@ -416,6 +449,7 @@ public class FolderResource extends RestResource {
                                                fs.setVersion(fversion);
                                                fs.setContentLength(fsize);
                                                fs.setDeleted(fdeleted);
+                                               fs.setShared(fshared);
                                                fs.setCreationDate(fcreationDate);
                                                fs.setModificationDate(fmodificationDate);
                                                fs.setContentType(fcontent);
@@ -506,4 +540,94 @@ public class FolderResource extends RestResource {
        public void setFilesExpanded(boolean newFilesExpanded) {
                filesExpanded = newFilesExpanded;
        }
+       /**
+        * this method constructs the partial path of a given TreeItem using it's text
+        *
+        * @param selectedItem the selectedItem to check
+        */
+       private String constructPartialPath(TreeItem selectedItem){
+          String result = DisplayHelper.trim(selectedItem.getText());
+          TreeItem parent = selectedItem.getParentItem();
+          while (!(DisplayHelper.trim(parent.getText()).equals("My Shared") || DisplayHelper.trim(parent.getText()).equals("Other's Shared")||DisplayHelper.trim(parent.getText()).equals("Trash"))){
+             result = DisplayHelper.trim(parent.getText()) + "/" + result;
+             if(result.equals("My Shared")||result.equals("Other's Shared")) return result;
+             parent = parent.getParentItem();
+          }
+
+          return result;
+       }
+       /**
+        * examine whether a folder name like "Trash", "My Shared", "Other's Shared" is inside path
+        *
+        * @param selectedItem the selectedTreeItem to check
+        */
+
+       private boolean containsFolder(TreeItem selectedItem, String folderName){
+               TreeItem parent = selectedItem.getParentItem();
+               while (parent != null){
+                       String parentItemText = parent.getText();
+                       String parentItemTextTr = DisplayHelper.trim(parentItemText);
+                       if(parentItemTextTr.equals(folderName)) return true;
+                       parent = parent.getParentItem();
+                       }
+               return false;
+       }
+       @Override
+       public String constructUri(TreeItem treeItem, String path){
+               String constructedUri = "";
+               if(containsFolder(treeItem, "My Shared")){
+                       //case: selected folders below My Shared folder
+                       String partialUri = constructPartialPath(treeItem);
+                       constructedUri = constructedUri + "Files/shared/" + partialUri;
+                       return constructedUri;
+               }else if(containsFolder(treeItem, "Other's Shared")){
+                       //case: selected folders below Other's Shared folder
+                       String partialPath = constructPartialPath(treeItem);
+                       constructedUri = constructedUri + "Files/others/"+ partialPath;
+                       return constructedUri;
+               }
+               else if(getParentURI()==null){
+                       if(containsFolder(treeItem, "Trash")){
+                               //case: selected folders below Trash folder
+                               String partialUri = constructPartialPath(treeItem);
+                               constructedUri = constructedUri + "Files/trash/" + partialUri;
+                               return constructedUri;
+                       }
+                       //case: home folder is selected
+                       constructedUri = constructedUri + "Files/files/" + getName();
+                       return constructedUri;
+               }
+               else if(treeItem.getParentItem() == null){
+                       //this is the case when the user uses the browser's forward arrow to navigate through other's
+                       //shared folders and item.getParentItem is null only inside other's shared folder
+                       String apiPath = GSS.get().getApiPath();
+                       String newPath = getParentURI().substring(apiPath.lastIndexOf("/"));
+                       constructedUri = constructedUri + "Files"+ newPath + getName();
+                       return constructedUri;
+               }
+               else{
+                       String finalUri = getParentURI().substring(path.lastIndexOf("/")) + getName();
+                       constructedUri = constructedUri + "Files"+ finalUri;
+                       return constructedUri;
+               }
+
+       }
+
+       /**
+        * Retrieve the readForAll.
+        *
+        * @return the readForAll
+        */
+       public boolean isReadForAll() {
+               return readForAll;
+       }
+       /**
+        * Modify the readForAll.
+        *
+        * @param newReadForAll the readForAll to set
+        */
+       public void setReadForAll(boolean newReadForAll) {
+               readForAll = newReadForAll;
+       }
+
 }