map.put("", configs.get(""));
for (RepositoryModel model : repositoryManager.getRepositoryModels(user)) {
String rootPath = StringUtils.getRootPath(model.name).toLowerCase();
if (!map.containsKey(rootPath)) {
ProjectModel project;
if (configs.containsKey(rootPath)) {
// clone the project model because it's repository list will
// be tailored for the requesting user
project = DeepCopier.copy(configs.get(rootPath));
} else {
project = new ProjectModel(rootPath);
}
map.put(rootPath, project);
}
map.get(rootPath).addRepository(model);
}
// sort projects, root project first
List<ProjectModel> projects;
if (includeUsers) {
// all projects
projects = new ArrayList<ProjectModel>(map.values());
Collections.sort(projects);
projects.remove(map.get(""));
projects.add(0, map.get(""));
} else {
// all non-user projects
projects = new ArrayList<ProjectModel>();
ProjectModel root = map.remove("");
for (ProjectModel model : map.values()) {
if (!model.isUserProject()) {
projects.add(model);
}
}