Revision 3ee27ba6 src/gr/ebs/gss/client/FileList.java

b/src/gr/ebs/gss/client/FileList.java
30 30
import gr.ebs.gss.client.rest.resource.SharedResource;
31 31
import gr.ebs.gss.client.rest.resource.TrashResource;
32 32
import gr.ebs.gss.client.rest.resource.UserResource;
33
import gr.ebs.gss.client.rest.resource.UserSearchResource;
33 34

  
34 35
import java.util.ArrayList;
35 36
import java.util.Collections;
......
297 298
		celltable.addColumn(new TextColumn<FileResource>() {
298 299
			@Override
299 300
			public String getValue(FileResource object) {
300
				// TODO Auto-generated method stub
301
				return object.getOwner();
301
				return GSS.get().findUserFullName(object.getOwner());
302 302
			}			
303 303
		},aheader = new SortableHeader("Owner"));
304 304
		allHeaders.add(aheader);
......
457 457
			max = count;
458 458
		folderTotalSize = 0;
459 459
		
460
		celltable.setRowCount(files.size());
461
		celltable.setRowData(0,files);
462
		celltable.redrawHeaders();
460
		copyListAndContinue(files);
461
		
463 462
		if (folderFileCount == 0) {
464 463
			showingStats = "no files";
465 464
		} else if (folderFileCount < GSS.VISIBLE_FILE_COUNT) {
......
944 943
		}
945 944
		
946 945
	}
946
	/**
947
	 * Creates a new ArrayList<FileResources> from the given files ArrayList 
948
	 * in order that the input files remain untouched 
949
	 * and continues to find user's full names of each FileResource element
950
	 * in the new ArrayList
951
	 *    
952
	 * @param filesInput
953
	 */
954
	private void copyListAndContinue(List<FileResource> filesInput){
955
		List<FileResource> copiedFiles = new ArrayList<FileResource>();		
956
		for(FileResource file : filesInput) {
957
			copiedFiles.add(file);
958
		}
959
		handleFullNames(copiedFiles);
960
	}
961
	
962
	/**
963
	 * Examines whether or not the user's full name exists in the 
964
	 * userFullNameMap in the GSS.java for every element of the input list.
965
	 * If the user's full name does not exist in the map then a command is being made.  
966
	 * 
967
	 * @param filesInput
968
	 */
969
	private void handleFullNames(List<FileResource> filesInput){		
970
		if(filesInput.size() == 0){
971
			showCellTable();
972
			return;
973
		}		
974

  
975
		if(GSS.get().findUserFullName(filesInput.get(0).getOwner()) == null){
976
			findFullNameAndUpdate(filesInput);		
977
			return;
978
		}
979
				
980
		if(filesInput.size() >= 1){
981
			filesInput.remove(filesInput.get(0));
982
			if(filesInput.isEmpty()){
983
				showCellTable();				
984
			}else{
985
				handleFullNames(filesInput);
986
			}
987
		}		
988
	}
989
	
990
	/**
991
	 * Makes a command to search for full name from a given username. 
992
	 * Only after the completion of the command the celltable is shown
993
	 * or the search for the next full name continues.
994
	 *  
995
	 * @param filesInput
996
	 */
997
	private void findFullNameAndUpdate(final List<FileResource> filesInput){		
998
		String aUserName = filesInput.get(0).getOwner();
999
		String path = GSS.get().getApiPath() + "users/" + aUserName; 
1000

  
1001
		GetCommand<UserSearchResource> gg = new GetCommand<UserSearchResource>(UserSearchResource.class, path, false,null) {
1002
			@Override
1003
			public void onComplete() {
1004
				final UserSearchResource result = getResult();
1005
				for (UserResource user : result.getUsers()){
1006
					String username = user.getUsername();
1007
					String userFullName = user.getName();
1008
					GSS.get().putUserToMap(username, userFullName);
1009
					if(filesInput.size() >= 1){
1010
						filesInput.remove(filesInput.get(0));
1011
						if(filesInput.isEmpty()){
1012
							showCellTable();
1013
						}else{
1014
							handleFullNames(filesInput);
1015
						}												
1016
					}									
1017
				}
1018
			}
1019
			@Override
1020
			public void onError(Throwable t) {
1021
				GWT.log("", t);
1022
				GSS.get().displayError("Unable to fetch user's full name from the given username " + filesInput.get(0).getOwner());
1023
				if(filesInput.size() >= 1){
1024
					filesInput.remove(filesInput.get(0));
1025
					handleFullNames(filesInput);					
1026
				}
1027
			}
1028
		};
1029
		DeferredCommand.addCommand(gg);
1030
	
1031
	}
1032
	/**
1033
	 * Shows the files in the cellTable 
1034
	 */
1035

  
1036
	private void showCellTable(){
1037
		celltable.setRowCount(files.size());
1038
		celltable.setRowData(0,files);
1039
		celltable.redrawHeaders();		
1040
	}
1041

  
1042
	
947 1043
}

Also available in: Unified diff