Fix sorting of included groups

Change-Id: I41be5f33c94d3248e6a2c922ebb412f643277050
This commit is contained in:
Shawn Pearce
2013-01-10 20:54:17 -08:00
parent edfc960938
commit 3d217418d4
3 changed files with 29 additions and 25 deletions

View File

@@ -41,10 +41,14 @@ public class GroupInfo {
* *
* @param a the data store record holding the specific group details. * @param a the data store record holding the specific group details.
*/ */
public GroupInfo(final AccountGroup a) { public GroupInfo(GroupDescription.Basic a) {
uuid = a.getGroupUUID(); uuid = a.getGroupUUID();
name = a.getName(); name = a.getName();
description = a.getDescription();
if (a instanceof GroupDescription.Internal) {
AccountGroup group = ((GroupDescription.Internal) a).getAccountGroup();
description = group.getDescription();
}
} }
/** @return the unique local id of the group */ /** @return the unique local id of the group */

View File

@@ -136,23 +136,21 @@ public class GroupDetailFactory implements Callable<GroupDetail> {
Collections.sort(groups, new Comparator<AccountGroupIncludeByUuid>() { Collections.sort(groups, new Comparator<AccountGroupIncludeByUuid>() {
public int compare(final AccountGroupIncludeByUuid o1, public int compare(final AccountGroupIncludeByUuid o1,
final AccountGroupIncludeByUuid o2) { final AccountGroupIncludeByUuid o2) {
final AccountGroup a = gic.get(o1.getIncludeUUID()); GroupDescription.Basic a = gic.get(o1.getIncludeUUID());
final AccountGroup b = gic.get(o2.getIncludeUUID()); GroupDescription.Basic b = gic.get(o2.getIncludeUUID());
return n(a).compareTo(n(b)); return n(a).compareTo(n(b));
} }
private String n(final AccountGroup a) { private String n (GroupDescription.Basic a) {
if (a == null) {
return "";
}
String n = a.getName(); String n = a.getName();
if (n != null && n.length() > 0) { if (n != null && n.length() > 0) {
return n; return n;
} }
return a.getGroupUUID().get();
n = a.getDescription();
if (n != null && n.length() > 0) {
return n;
}
return a.getId().toString();
} }
}); });

View File

@@ -14,13 +14,14 @@
package com.google.gerrit.server.account; package com.google.gerrit.server.account;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gerrit.common.data.GroupDescription;
import com.google.gerrit.common.data.GroupInfo; import com.google.gerrit.common.data.GroupInfo;
import com.google.gerrit.common.data.GroupInfoCache; import com.google.gerrit.common.data.GroupInfoCache;
import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -30,13 +31,13 @@ public class GroupInfoCacheFactory {
GroupInfoCacheFactory create(); GroupInfoCacheFactory create();
} }
private final GroupCache groupCache; private final GroupBackend groupBackend;
private final Map<AccountGroup.UUID, AccountGroup> out; private final Map<AccountGroup.UUID, GroupDescription.Basic> out;
@Inject @Inject
GroupInfoCacheFactory(final GroupCache groupCache) { GroupInfoCacheFactory(GroupBackend groupBackend) {
this.groupCache = groupCache; this.groupBackend = groupBackend;
this.out = new HashMap<AccountGroup.UUID, AccountGroup>(); this.out = Maps.newHashMap();
} }
/** /**
@@ -46,7 +47,7 @@ public class GroupInfoCacheFactory {
*/ */
public void want(final AccountGroup.UUID uuid) { public void want(final AccountGroup.UUID uuid) {
if (uuid != null && !out.containsKey(uuid)) { if (uuid != null && !out.containsKey(uuid)) {
out.put(uuid, groupCache.get(uuid)); out.put(uuid, groupBackend.get(uuid));
} }
} }
@@ -57,7 +58,7 @@ public class GroupInfoCacheFactory {
} }
} }
public AccountGroup get(final AccountGroup.UUID uuid) { public GroupDescription.Basic get(final AccountGroup.UUID uuid) {
want(uuid); want(uuid);
return out.get(uuid); return out.get(uuid);
} }
@@ -66,11 +67,12 @@ public class GroupInfoCacheFactory {
* Create an GroupInfoCache with the currently loaded AccountGroup entities. * Create an GroupInfoCache with the currently loaded AccountGroup entities.
* */ * */
public GroupInfoCache create() { public GroupInfoCache create() {
final List<GroupInfo> r = new ArrayList<GroupInfo>(out.size()); List<GroupInfo> r = Lists.newArrayListWithCapacity(out.size());
for (final AccountGroup a : out.values()) { for (GroupDescription.Basic a : out.values()) {
if (a == null) continue; if (a != null) {
r.add(new GroupInfo(a)); r.add(new GroupInfo(a));
} }
}
return new GroupInfoCache(r); return new GroupInfoCache(r);
} }
} }