// Path: ali-plugin-main/src/main/java/com/hp/alm/ali/idea/model/User.java
// public class User {
// 
//     private String username;
//     private String fullName;
// 
//     public User(String username, String fullName) {
//         this.username = username;
//         this.fullName = fullName;
//     }
// 
//     public String getUsername() {
//         return username;
//     }
// 
//     public String getFullName() {
//         return fullName;
//     }
// }
// 
// Path: ali-plugin-main/src/main/java/com/hp/alm/ali/idea/services/ProjectUserService.java
// public class ProjectUserService extends AbstractCachingService<Integer, UserList, AbstractCachingService.Callback<UserList>> {
//     private RestService restService;
// 
//     public ProjectUserService(Project project) {
//         super(project);
// 
//         restService = project.getComponent(RestService.class);
//     }
// 
//     public void loadUsersAsync(Callback<UserList> callback) {
//         getValueAsync(1, callback);
//     }
// 
//     public User tryGetUser(String username) {
//         UserList users = getCachedValue(1);
//         if(users != null) {
//             User user = users.getUser(username);
//             if(user == null) {
//                 // avoid infinite loop if users loaded but username not found
//                 return new User(username, username);
//             }
//             return user;
//         } else {
//             return null;
//         }
//     }
// 
//     public void loadUserAsync(final String username, final Callback<User> callback) {
//         loadUsersAsync(translate(callback, new Transform<UserList, User>() {
//             @Override
//             public User transform(UserList users) {
//                 User user = users.getUser(username);
//                 if(user == null) {
//                     return new User(username, username);
//                 } else {
//                     return user;
//                 }
//             }
//         }));
//     }
// 
//     public UserList getUserList() {
//         return getValue(1);
//     }
// 
//     public User getUser(String username) {
//         for(User user: getUserList()) {
//             if(user.getUsername().equals(username)) {
//                 return user;
//             }
//         }
//         return null;
//     }
// 
//     public String getUserFullName(String username) {
//         User user = getUser(username);
//         if(user != null) {
//             return user.getFullName();
//         } else {
//             return null;
//         }
//     }
// 
//     @Override
//     protected UserList doGetValue(Integer key) {
//         InputStream is = restService.getForStream("customization/users");
//         return UserList.create(is);
//     }
// }


import java.util.List;
import com.hp.alm.ali.idea.filter.MultipleItemsChooserFactory;
import com.hp.alm.ali.idea.model.ItemsProvider;
import com.hp.alm.ali.idea.model.User;
import com.hp.alm.ali.idea.translate.filter.MultipleItemsTranslatedResolver;
import com.hp.alm.ali.idea.translate.Translator;
import com.hp.alm.ali.idea.translate.ValueCallback;
import com.hp.alm.ali.idea.services.AbstractCachingService;
import com.hp.alm.ali.idea.services.ProjectUserService;
import com.hp.alm.ali.idea.filter.FilterFactory;
import com.hp.alm.ali.idea.translate.filter.FilterResolver;
import com.hp.alm.ali.idea.ui.ComboItem;
import com.intellij.openapi.project.Project;
import java.util.ArrayList;
    @Override
    public String translate(String value, final ValueCallback onValue) {
        User user = projectUserService.tryGetUser(value);
        if(user == null) {
            projectUserService.loadUserAsync(value, new AbstractCachingService.Callback<User>() {
                @Override
                public void loaded(User user) {
                    onValue.value(userName(user, false));
                }
            });
            return null;
        } else {
            return userName(user, false);
        }
    }

    private String userName(User user, boolean longName) {
        String fullName = user.getFullName();
        if(fullName.isEmpty()) {
            return user.getUsername();
        } else if(longName) {
            return fullName + " (" + user.getUsername() + ")";
        } else {
            return fullName;
        }
    }

    @Override
    public String resolveDisplayValue(String value, final ValueCallback onValue) {
        onValue.value(value);
// Path: ali-plugin-main/src/main/java/com/hp/alm/ali/idea/model/User.java
// public class User {
// 
//     private String username;
//     private String fullName;
// 
//     public User(String username, String fullName) {
//         this.username = username;
//         this.fullName = fullName;
//     }
// 
//     public String getUsername() {
//         return username;
//     }
// 
//     public String getFullName() {
//         return fullName;
//     }
// }
// 
// Path: ali-plugin-main/src/main/java/com/hp/alm/ali/idea/services/ProjectUserService.java
// public class ProjectUserService extends AbstractCachingService<Integer, UserList, AbstractCachingService.Callback<UserList>> {
//     private RestService restService;
// 
//     public ProjectUserService(Project project) {
//         super(project);
// 
//         restService = project.getComponent(RestService.class);
//     }
// 
//     public void loadUsersAsync(Callback<UserList> callback) {
//         getValueAsync(1, callback);
//     }
// 
//     public User tryGetUser(String username) {
//         UserList users = getCachedValue(1);
//         if(users != null) {
//             User user = users.getUser(username);
//             if(user == null) {
//                 // avoid infinite loop if users loaded but username not found
//                 return new User(username, username);
//             }
//             return user;
//         } else {
//             return null;
//         }
//     }
// 
//     public void loadUserAsync(final String username, final Callback<User> callback) {
//         loadUsersAsync(translate(callback, new Transform<UserList, User>() {
//             @Override
//             public User transform(UserList users) {
//                 User user = users.getUser(username);
//                 if(user == null) {
//                     return new User(username, username);
//                 } else {
//                     return user;
//                 }
//             }
//         }));
//     }
// 
//     public UserList getUserList() {
//         return getValue(1);
//     }
// 
//     public User getUser(String username) {
//         for(User user: getUserList()) {
//             if(user.getUsername().equals(username)) {
//                 return user;
//             }
//         }
//         return null;
//     }
// 
//     public String getUserFullName(String username) {
//         User user = getUser(username);
//         if(user != null) {
//             return user.getFullName();
//         } else {
//             return null;
//         }
//     }
// 
//     @Override
//     protected UserList doGetValue(Integer key) {
//         InputStream is = restService.getForStream("customization/users");
//         return UserList.create(is);
//     }
// }


// Path: ali-plugin-main/src/main/java/com/hp/alm/ali/idea/model/type/UserType.java
import java.util.List;
import com.hp.alm.ali.idea.filter.MultipleItemsChooserFactory;
import com.hp.alm.ali.idea.model.ItemsProvider;
import com.hp.alm.ali.idea.model.User;
import com.hp.alm.ali.idea.translate.filter.MultipleItemsTranslatedResolver;
import com.hp.alm.ali.idea.translate.Translator;
import com.hp.alm.ali.idea.translate.ValueCallback;
import com.hp.alm.ali.idea.services.AbstractCachingService;
import com.hp.alm.ali.idea.services.ProjectUserService;
import com.hp.alm.ali.idea.filter.FilterFactory;
import com.hp.alm.ali.idea.translate.filter.FilterResolver;
import com.hp.alm.ali.idea.ui.ComboItem;
import com.intellij.openapi.project.Project;
import java.util.ArrayList;

    @Override
    public String translate(String value, final ValueCallback onValue) {
        User user = projectUserService.tryGetUser(value);
        if(user == null) {
            projectUserService.loadUserAsync(value, new AbstractCachingService.Callback<User>() {
                @Override
                public void loaded(User user) {
                    onValue.value(userName(user, false));
                }
            });
            return null;
        } else {
            return userName(user, false);
        }
    }

    private String userName(User user, boolean longName) {
        String fullName = user.getFullName();
        if(fullName.isEmpty()) {
            return user.getUsername();
        } else if(longName) {
            return fullName + " (" + user.getUsername() + ")";
        } else {
            return fullName;
        }
    }

    @Override
    public String resolveDisplayValue(String value, final ValueCallback onValue) {
        onValue.value(value);
        projectUserService.loadUserAsync(value, new AbstractCachingService.Callback<User>() {