Make use of GetUserCommand in the PropertiesCommand
authorNatasa Kapravelou <akapravelou@gmail.com>
Fri, 21 Jan 2011 13:05:57 +0000 (15:05 +0200)
committerNatasa Kapravelou <akapravelou@gmail.com>
Fri, 21 Jan 2011 13:05:57 +0000 (15:05 +0200)
src/gr/ebs/gss/client/commands/GetUserCommand.java
src/gr/ebs/gss/client/commands/PropertiesCommand.java

index dcfe6a4..9eb2173 100644 (file)
@@ -43,21 +43,13 @@ public class GetUserCommand implements Command{
         */
        private String userName;
 
-       /**
-        * User's full name e.g 'John Doe'
-        */
-
-
        public GetUserCommand(String _userName){
                userName = _userName;
        }
 
        @Override
        public void execute() {
-               //this generates a java.lang.StringIndexOutOfBoundsException: String index out of range: -1
-               String nameOfUserName = userName.substring(0,userName.indexOf("@"));
-               String path = GSS.get().getApiPath() + "users/" + URL.encodeComponent(nameOfUserName);
-
+               String path = GSS.get().getApiPath() + "users/" + userName; 
                GetCommand<UserSearchResource> gg = new GetCommand<UserSearchResource>(UserSearchResource.class,
                                        path, false ,null) {
                        @Override
index 6b7653d..2981878 100644 (file)
@@ -283,39 +283,12 @@ public class PropertiesCommand implements Command {
                        FileResource fileResource = (FileResource) GSS.get().getCurrentSelection();
                        userName = fileResource.getOwner();
                        if(GSS.get().findUserFullName(userName) == null){
-                               findFullNameAndUpdate(userName);
+                               GetUserCommand gu = new GetUserCommand(userName);
+                               gu.execute();
                        }
 
                }
        }
-       /**
-        * Makes a command to search for full name from a given username. 
-        * 
-        * @param filesInput
-        */
-       private void findFullNameAndUpdate(final String aUserName){             
-               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);
-                                       }
-                       }
-                       
-                       @Override
-                       public void onError(Throwable t) {
-                               GWT.log("", t);
-                               GSS.get().displayError("Unable to fetch user's full name from the given username " + aUserName);
-                               
-                       }
-               };
-               DeferredCommand.addCommand(gg);
-       
-       }
 
 }