Added two new classes. The first 'TestFolderSharing' handles the 'Sharing' option...
[pithos] / src / gr / ebs / gss / client / VersionsList.java
index 6eeadad..f76118c 100644 (file)
@@ -20,28 +20,34 @@ package gr.ebs.gss.client;
 
 import gr.ebs.gss.client.FilePropertiesDialog.Images;
 import gr.ebs.gss.client.rest.DeleteCommand;
 
 import gr.ebs.gss.client.FilePropertiesDialog.Images;
 import gr.ebs.gss.client.rest.DeleteCommand;
+import gr.ebs.gss.client.rest.GetCommand;
 import gr.ebs.gss.client.rest.PostCommand;
 import gr.ebs.gss.client.rest.RestCommand;
 import gr.ebs.gss.client.rest.RestException;
 import gr.ebs.gss.client.rest.resource.FileResource;
 import gr.ebs.gss.client.rest.PostCommand;
 import gr.ebs.gss.client.rest.RestCommand;
 import gr.ebs.gss.client.rest.RestException;
 import gr.ebs.gss.client.rest.resource.FileResource;
+import gr.ebs.gss.client.rest.resource.UserResource;
+import gr.ebs.gss.client.rest.resource.UserSearchResource;
 
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Date;
 import java.util.List;
 
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Date;
 import java.util.List;
 
+
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
 import com.google.gwt.http.client.URL;
 import com.google.gwt.i18n.client.DateTimeFormat;
 import com.google.gwt.user.client.DeferredCommand;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.http.client.URL;
 import com.google.gwt.i18n.client.DateTimeFormat;
 import com.google.gwt.user.client.DeferredCommand;
 import com.google.gwt.user.client.Window;
-import com.google.gwt.user.client.ui.ClickListener;
+import com.google.gwt.user.client.ui.AbstractImagePrototype;
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.FlexTable;
 import com.google.gwt.user.client.ui.HTML;
 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
 import com.google.gwt.user.client.ui.VerticalPanel;
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.FlexTable;
 import com.google.gwt.user.client.ui.HTML;
 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
 import com.google.gwt.user.client.ui.VerticalPanel;
-import com.google.gwt.user.client.ui.Widget;
 
 /**
  * @author kman
 
 /**
  * @author kman
@@ -70,6 +76,7 @@ public class VersionsList extends Composite {
                versions = theVersions;
                Collections.sort(theVersions, new Comparator<FileResource>(){
 
                versions = theVersions;
                Collections.sort(theVersions, new Comparator<FileResource>(){
 
+                       @Override
                        public int compare(FileResource o1, FileResource o2) {
                                return o1.getVersion().compareTo(o2.getVersion());
                        }
                        public int compare(FileResource o1, FileResource o2) {
                                return o1.getVersion().compareTo(o2.getVersion());
                        }
@@ -91,45 +98,47 @@ public class VersionsList extends Composite {
                permTable.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
                permTable.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
                permPanel.add(permTable);
                permTable.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
                permTable.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
                permPanel.add(permTable);
-               permPanel.addStyleName("gwt-TabPanelBottom");
+               permPanel.addStyleName("gss-TabPanelBottom");
                permTable.addStyleName("gss-permList");
                initWidget(permPanel);
                updateTable();
        }
 
        public void updateTable() {
                permTable.addStyleName("gss-permList");
                initWidget(permPanel);
                updateTable();
        }
 
        public void updateTable() {
+               copyListAndContinue(versions);          
+       }
+       
+       public void showVersionsTable(){
                int i = 1;
                if (toRemove != null) {
                        versions.remove(toRemove);
                        toRemove = null;
                }
                for (final FileResource dto : versions) {
                int i = 1;
                if (toRemove != null) {
                        versions.remove(toRemove);
                        toRemove = null;
                }
                for (final FileResource dto : versions) {
-                       HTML restoreVersion = new HTML("<a href='#' class='hidden-link info'><span>"+images.restore().getHTML()+"</span><div>Restore this Version</div></a>");
-                       restoreVersion.addClickListener( new ClickListener() {
-
-                               public void onClick(Widget sender) {
+                       HTML restoreVersion = new HTML("<a href='#' class='hidden-link info'><span>"+AbstractImagePrototype.create(images.restore()).getHTML()+"</span><div>Restore this Version</div></a>");
+                       restoreVersion.addClickHandler(new ClickHandler() {
+                               @Override
+                               public void onClick(ClickEvent event) {
                                        restoreVersion(dto);
                                }
                        });
 
                        permTable.setHTML(i, 0, "<span>" + dto.getVersion() + "</span>");
                                        restoreVersion(dto);
                                }
                        });
 
                        permTable.setHTML(i, 0, "<span>" + dto.getVersion() + "</span>");
-                       permTable.setHTML(i, 1, "<span>" + formatDate(dto.getCreationDate()) + "</span>");
-                       permTable.setHTML(i, 2, "<span>" + formatDate(dto.getModificationDate()) + "</span>");
+                       permTable.setHTML(i, 1, "<span>" + formatDate(dto.getCreationDate()) + " by " + GSS.get().findUserFullName(dto.getCreatedBy()) + "</span>");
+                       permTable.setHTML(i, 2, "<span>" + formatDate(dto.getModificationDate()) + " by " + GSS.get().findUserFullName(dto.getModifiedBy()) + "</span>");
                        permTable.setHTML(i, 3, "<span>" + dto.getFileSizeAsString() + "</span>");
                        permTable.setHTML(i, 3, "<span>" + dto.getFileSizeAsString() + "</span>");
-                       HTML downloadHtml = new HTML("<a class='hidden-link info' href='#'><span>"+images.download().getHTML()+"</span><div>View this Version</div></a>");
-                       downloadHtml.addClickListener(new ClickListener(){
-
-                               public void onClick(Widget arg0) {
+                       HTML downloadHtml = new HTML("<a class='hidden-link info' href='#'><span>"+AbstractImagePrototype.create(images.download()).getHTML()+"</span><div>View this Version</div></a>");
+                       downloadHtml.addClickHandler(new ClickHandler() {
+                               @Override
+                               public void onClick(ClickEvent event) {
                                        GSS app = GSS.get();
                                        String dateString = RestCommand.getDate();
                                        String resource = dto.getUri().substring(app.getApiPath().length()-1, dto.getUri().length());
                                        String sig = app.getCurrentUserResource().getUsername()+" "+RestCommand.calculateSig("GET", dateString, resource, RestCommand.base64decode(app.getToken()));
                                        GSS app = GSS.get();
                                        String dateString = RestCommand.getDate();
                                        String resource = dto.getUri().substring(app.getApiPath().length()-1, dto.getUri().length());
                                        String sig = app.getCurrentUserResource().getUsername()+" "+RestCommand.calculateSig("GET", dateString, resource, RestCommand.base64decode(app.getToken()));
-                                       String fileUrl = dto.getUri() + "&Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString);
+                                       String fileUrl = dto.getUri() + "?version=" + dto.getVersion() + "&Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString);
                                        Window.open(fileUrl, "_BLANK", "");
                                        Window.open(fileUrl, "_BLANK", "");
-
                                }
                        });
                                }
                        });
-                       GWT.log("images:"+images.download().getHTML(), null);
                        permTable.setWidget(i, 4, downloadHtml);
                        permTable.setWidget(i, 5, restoreVersion);
                        permTable.getFlexCellFormatter().setStyleName(i, 0, "props-labels");
                        permTable.setWidget(i, 4, downloadHtml);
                        permTable.setWidget(i, 5, restoreVersion);
                        permTable.getFlexCellFormatter().setStyleName(i, 0, "props-labels");
@@ -144,7 +153,6 @@ public class VersionsList extends Composite {
                        permTable.removeRow(i);
        }
 
                        permTable.removeRow(i);
        }
 
-
        void removeVersion(final FileResource version) {
                DeleteCommand df = new DeleteCommand(version.getUri()){
 
        void removeVersion(final FileResource version) {
                DeleteCommand df = new DeleteCommand(version.getUri()){
 
@@ -203,5 +211,88 @@ public class VersionsList extends Composite {
                DateTimeFormat format = DateTimeFormat.getFormat("dd/MM/yyyy : HH:mm");
                return format.format(date);
        }
                DateTimeFormat format = DateTimeFormat.getFormat("dd/MM/yyyy : HH:mm");
                return format.format(date);
        }
+       
+       /**
+        * Copies the input List to a new List
+        * @param input
+        */
+       private void copyListAndContinue(List<FileResource> input){
+               List<FileResource> copiedInput = new ArrayList<FileResource>();         
+               for(FileResource dto : input) {
+                       copiedInput.add(dto);
+               }
+               handleFullNames(copiedInput);
+       }
+       
+       /**
+        * Examines whether or not the user's full name exists in the 
+        * userFullNameMap in the GSS.java for every element of the input list.
+        * If the user's full name does not exist in the map then a request is being made
+        * for the specific username.  
+        * 
+        * @param input
+        */
+       private void handleFullNames(List<FileResource> input){         
+               if(input.isEmpty()){
+                       showVersionsTable();
+                       return;
+               }
+               
+               if(GSS.get().findUserFullName(input.get(0).getOwner()) == null){
+                       findFullNameAndUpdate(input);           
+                       return;
+               }
+                               
+               if(input.size() >= 1){
+                       input.remove(input.get(0));
+                       if(input.isEmpty()){
+                               showVersionsTable();                    
+                       }else{
+                               handleFullNames(input);
+                       }
+               }                                       
+       }
+       
+       /**
+        * Makes a request to search for full name from a given username
+        * and continues checking the next element of the List.
+        *  
+        * @param input
+        */
+
+       private void findFullNameAndUpdate(final List<FileResource> input){                             
+               final String aUserName = input.get(0).getOwner();
+               String path = GSS.get().getApiPath() + "users/" + aUserName; 
+
+               GetCommand<UserSearchResource> gg = new GetCommand<UserSearchResource>(UserSearchResource.class, path, false,null) {
+                       @Override
+                       public void onComplete() {
+                               final UserSearchResource result = getResult();
+                               for (UserResource user : result.getUsers()){
+                                       String username = user.getUsername();
+                                       String userFullName = user.getName();
+                                       GSS.get().putUserToMap(username, userFullName);
+                                       if(input.size() >= 1){
+                                               input.remove(input.get(0));                                             
+                                               if(input.isEmpty()){
+                                                       showVersionsTable();
+                                                       return;
+                                               }
+                                               handleFullNames(input);                                                                         
+                                       }                                                                       
+                               }
+                       }
+                       @Override
+                       public void onError(Throwable t) {                              
+                               GSS.get().displayError("Unable to fetch user's full name from the given username " + aUserName);
+                               if(input.size() >= 1){
+                                       input.remove(input.get(0));
+                                       handleFullNames(input);                                 
+                               }
+                       }
+               };
+               DeferredCommand.addCommand(gg);
+       
+       }
 
 }
 
 }