Remove all non-static functionality from AccountGroup
This had no remaining callers; the group APIs all use InternalGroup directly where applicable. Change-Id: Ic0b918af51b27929b16323d7aa5a46d2661d578f
This commit is contained in:
		
				
					committed by
					
						
						David Pursehouse
					
				
			
			
				
	
			
			
			
						parent
						
							0e345d7121
						
					
				
				
					commit
					b14fae8996
				
			@@ -15,23 +15,8 @@
 | 
			
		||||
package com.google.gerrit.entities;
 | 
			
		||||
 | 
			
		||||
import com.google.auto.value.AutoValue;
 | 
			
		||||
import com.google.gerrit.common.Nullable;
 | 
			
		||||
import java.sql.Timestamp;
 | 
			
		||||
import java.time.Instant;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
 | 
			
		||||
/** Named group of one or more accounts, typically used for access controls. */
 | 
			
		||||
public final class AccountGroup {
 | 
			
		||||
  /**
 | 
			
		||||
   * Time when the audit subsystem was implemented, used as the default value for {@link #createdOn}
 | 
			
		||||
   * when one couldn't be determined from the audit log.
 | 
			
		||||
   */
 | 
			
		||||
  private static final Instant AUDIT_CREATION_INSTANT_MS = Instant.ofEpochMilli(1244489460000L);
 | 
			
		||||
 | 
			
		||||
  public static Timestamp auditCreationInstantTs() {
 | 
			
		||||
    return Timestamp.from(AUDIT_CREATION_INSTANT_MS);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public static NameKey nameKey(String n) {
 | 
			
		||||
    return new AutoValue_AccountGroup_NameKey(n);
 | 
			
		||||
  }
 | 
			
		||||
@@ -135,158 +120,4 @@ public final class AccountGroup {
 | 
			
		||||
      return Integer.toString(get());
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /** Unique name of this group within the system. */
 | 
			
		||||
  protected NameKey name;
 | 
			
		||||
 | 
			
		||||
  /** Unique identity, to link entities as {@link #name} can change. */
 | 
			
		||||
  protected Id groupId;
 | 
			
		||||
 | 
			
		||||
  // DELETED: id = 3 (ownerGroupId)
 | 
			
		||||
 | 
			
		||||
  /** A textual description of the group's purpose. */
 | 
			
		||||
  @Nullable protected String description;
 | 
			
		||||
 | 
			
		||||
  // DELETED: id = 5 (groupType)
 | 
			
		||||
  // DELETED: id = 6 (externalName)
 | 
			
		||||
 | 
			
		||||
  protected boolean visibleToAll;
 | 
			
		||||
 | 
			
		||||
  // DELETED: id = 8 (emailOnlyAuthors)
 | 
			
		||||
 | 
			
		||||
  /** Globally unique identifier name for this group. */
 | 
			
		||||
  protected UUID groupUUID;
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Identity of the group whose members can manage this group.
 | 
			
		||||
   *
 | 
			
		||||
   * <p>This can be a self-reference to indicate the group's members manage itself.
 | 
			
		||||
   */
 | 
			
		||||
  protected UUID ownerGroupUUID;
 | 
			
		||||
 | 
			
		||||
  @Nullable protected Timestamp createdOn;
 | 
			
		||||
 | 
			
		||||
  protected AccountGroup() {}
 | 
			
		||||
 | 
			
		||||
  public AccountGroup(
 | 
			
		||||
      AccountGroup.NameKey newName,
 | 
			
		||||
      AccountGroup.Id newId,
 | 
			
		||||
      AccountGroup.UUID uuid,
 | 
			
		||||
      Timestamp createdOn) {
 | 
			
		||||
    name = newName;
 | 
			
		||||
    groupId = newId;
 | 
			
		||||
    visibleToAll = false;
 | 
			
		||||
    groupUUID = uuid;
 | 
			
		||||
    ownerGroupUUID = groupUUID;
 | 
			
		||||
    this.createdOn = createdOn;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public AccountGroup(AccountGroup other) {
 | 
			
		||||
    name = other.name;
 | 
			
		||||
    groupId = other.groupId;
 | 
			
		||||
    description = other.description;
 | 
			
		||||
    visibleToAll = other.visibleToAll;
 | 
			
		||||
    groupUUID = other.groupUUID;
 | 
			
		||||
    ownerGroupUUID = other.ownerGroupUUID;
 | 
			
		||||
    createdOn = other.createdOn;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public AccountGroup.Id getId() {
 | 
			
		||||
    return groupId;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public String getName() {
 | 
			
		||||
    return name.get();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public AccountGroup.NameKey getNameKey() {
 | 
			
		||||
    return name;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setNameKey(AccountGroup.NameKey nameKey) {
 | 
			
		||||
    name = nameKey;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public String getDescription() {
 | 
			
		||||
    return description;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setDescription(String d) {
 | 
			
		||||
    description = d;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public AccountGroup.UUID getOwnerGroupUUID() {
 | 
			
		||||
    return ownerGroupUUID;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setOwnerGroupUUID(AccountGroup.UUID uuid) {
 | 
			
		||||
    ownerGroupUUID = uuid;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setVisibleToAll(boolean visibleToAll) {
 | 
			
		||||
    this.visibleToAll = visibleToAll;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public boolean isVisibleToAll() {
 | 
			
		||||
    return visibleToAll;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public AccountGroup.UUID getGroupUUID() {
 | 
			
		||||
    return groupUUID;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setGroupUUID(AccountGroup.UUID uuid) {
 | 
			
		||||
    groupUUID = uuid;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public Timestamp getCreatedOn() {
 | 
			
		||||
    return createdOn != null ? createdOn : auditCreationInstantTs();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setCreatedOn(Timestamp createdOn) {
 | 
			
		||||
    this.createdOn = createdOn;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public boolean equals(Object o) {
 | 
			
		||||
    if (!(o instanceof AccountGroup)) {
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
    AccountGroup g = (AccountGroup) o;
 | 
			
		||||
    return Objects.equals(name, g.name)
 | 
			
		||||
        && Objects.equals(groupId, g.groupId)
 | 
			
		||||
        && Objects.equals(description, g.description)
 | 
			
		||||
        && visibleToAll == g.visibleToAll
 | 
			
		||||
        && Objects.equals(groupUUID, g.groupUUID)
 | 
			
		||||
        && Objects.equals(ownerGroupUUID, g.ownerGroupUUID)
 | 
			
		||||
        // Treat created on epoch identical regardless if underlying value is null.
 | 
			
		||||
        && getCreatedOn().equals(g.getCreatedOn());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public int hashCode() {
 | 
			
		||||
    return Objects.hash(
 | 
			
		||||
        name, groupId, description, visibleToAll, groupUUID, ownerGroupUUID, createdOn);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public String toString() {
 | 
			
		||||
    return getClass().getSimpleName()
 | 
			
		||||
        + "{"
 | 
			
		||||
        + "name="
 | 
			
		||||
        + name
 | 
			
		||||
        + ", groupId="
 | 
			
		||||
        + groupId
 | 
			
		||||
        + ", description="
 | 
			
		||||
        + description
 | 
			
		||||
        + ", visibleToAll="
 | 
			
		||||
        + visibleToAll
 | 
			
		||||
        + ", groupUUID="
 | 
			
		||||
        + groupUUID
 | 
			
		||||
        + ", ownerGroupUUID="
 | 
			
		||||
        + ownerGroupUUID
 | 
			
		||||
        + ", createdOn="
 | 
			
		||||
        + createdOn
 | 
			
		||||
        + "}";
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -19,23 +19,12 @@ import static com.google.gerrit.entities.AccountGroup.UUID.fromRef;
 | 
			
		||||
import static com.google.gerrit.entities.AccountGroup.UUID.fromRefPart;
 | 
			
		||||
import static com.google.gerrit.entities.AccountGroup.uuid;
 | 
			
		||||
 | 
			
		||||
import java.sql.Timestamp;
 | 
			
		||||
import java.time.Instant;
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
import java.time.Month;
 | 
			
		||||
import java.time.ZoneOffset;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
 | 
			
		||||
public class AccountGroupTest {
 | 
			
		||||
  private static final String TEST_UUID = "ccab3195282a8ce4f5014efa391e82d10f884c64";
 | 
			
		||||
  private static final String TEST_SHARDED_UUID = TEST_UUID.substring(0, 2) + "/" + TEST_UUID;
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void auditCreationInstant() {
 | 
			
		||||
    Instant instant = LocalDateTime.of(2009, Month.JUNE, 8, 19, 31).toInstant(ZoneOffset.UTC);
 | 
			
		||||
    assertThat(AccountGroup.auditCreationInstantTs()).isEqualTo(Timestamp.from(instant));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void parseRefName() {
 | 
			
		||||
    assertThat(fromRef("refs/groups/" + TEST_SHARDED_UUID)).isEqualTo(uuid(TEST_UUID));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user