+
+ /**
+ * 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);
+
+ }