Replace use of AccountGroup by an interface for various classes

Previously, GroupDescription.Internal served only as a marker for
internal groups and simply delegated to AccountGroup. By converting
GroupDescription.Internal to a real interface, we gain a lot of
flexibility. For instance, we are free to use another class to
represent internal groups (which will be necessary for the migration
of groups to NoteDb).

Change-Id: If7397898d8508184a2ccdc7c371ed60ada7d6f3e
This commit is contained in:
Alice Kober-Sotzek
2017-08-16 17:41:38 +02:00
parent 6da54a4009
commit 3a68432798
28 changed files with 154 additions and 146 deletions

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.common.data;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.reviewdb.client.AccountGroup;
import java.sql.Timestamp;
/** Group methods exposed by the GroupBackend. */
public class GroupDescription {
@@ -42,10 +43,18 @@ public class GroupDescription {
String getUrl();
}
/** The extended information exposed by internal groups backed by an AccountGroup. */
/** The extended information exposed by internal groups. */
public interface Internal extends Basic {
/** @return the backing AccountGroup. */
AccountGroup getAccountGroup();
AccountGroup.Id getId();
String getDescription();
AccountGroup.UUID getOwnerGroupUUID();
boolean isVisibleToAll();
Timestamp getCreatedOn();
}
private GroupDescription() {}

View File

@@ -17,18 +17,11 @@ package com.google.gerrit.common.data;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.reviewdb.client.AccountGroup;
import java.sql.Timestamp;
/** Utility class for building GroupDescription objects. */
public class GroupDescriptions {
@Nullable
public static AccountGroup toAccountGroup(GroupDescription.Basic group) {
if (group instanceof GroupDescription.Internal) {
return ((GroupDescription.Internal) group).getAccountGroup();
}
return null;
}
public static GroupDescription.Internal forAccountGroup(AccountGroup group) {
return new GroupDescription.Internal() {
@Override
@@ -41,11 +34,6 @@ public class GroupDescriptions {
return group.getName();
}
@Override
public AccountGroup getAccountGroup() {
return group;
}
@Override
@Nullable
public String getEmailAddress() {
@@ -53,10 +41,34 @@ public class GroupDescriptions {
}
@Override
@Nullable
public String getUrl() {
return "#" + PageLinks.toGroup(getGroupUUID());
}
@Override
public AccountGroup.Id getId() {
return group.getId();
}
@Override
public String getDescription() {
return group.getDescription();
}
@Override
public AccountGroup.UUID getOwnerGroupUUID() {
return group.getOwnerGroupUUID();
}
@Override
public boolean isVisibleToAll() {
return group.isVisibleToAll();
}
@Override
public Timestamp getCreatedOn() {
return group.getCreatedOn();
}
};
}

View File

@@ -46,8 +46,7 @@ public class GroupInfo {
url = a.getUrl();
if (a instanceof GroupDescription.Internal) {
AccountGroup group = ((GroupDescription.Internal) a).getAccountGroup();
description = group.getDescription();
description = ((GroupDescription.Internal) a).getDescription();
}
}