Flatten group audit keys into containing types

The keys were used as primary keys in ReviewDb; this is no longer
required, and the key abstraction is serving no purpose. Within
AuditLogReader there is a need to build maps containing audit records
keyed by something, but AuditLogReader has its own key types for that,
since they don't match the audit record keys.

Change-Id: I2632cbf709cab020a0d9a44d177ad6e326e21bcf
This commit is contained in:
Dave Borowitz
2019-05-01 10:56:00 -07:00
parent c6b037b2ab
commit df200270c8
5 changed files with 38 additions and 62 deletions

View File

@@ -21,29 +21,20 @@ import java.util.Optional;
/** Inclusion of an {@link AccountGroup} in another {@link AccountGroup}. */ /** Inclusion of an {@link AccountGroup} in another {@link AccountGroup}. */
@AutoValue @AutoValue
public abstract class AccountGroupByIdAudit { public abstract class AccountGroupByIdAudit {
public static Key key(AccountGroup.Id groupId, AccountGroup.UUID includeUuid, Timestamp addedOn) {
return new AutoValue_AccountGroupByIdAudit_Key(groupId, includeUuid, addedOn);
}
@AutoValue
public abstract static class Key {
public abstract AccountGroup.Id groupId();
public abstract AccountGroup.UUID includeUuid();
public abstract Timestamp addedOn();
}
public static Builder builder() { public static Builder builder() {
return new AutoValue_AccountGroupByIdAudit.Builder(); return new AutoValue_AccountGroupByIdAudit.Builder();
} }
@AutoValue.Builder @AutoValue.Builder
public abstract static class Builder { public abstract static class Builder {
public abstract Builder key(Key key); public abstract Builder groupId(AccountGroup.Id groupId);
public abstract Builder includeUuid(AccountGroup.UUID includeUuid);
public abstract Builder addedBy(Account.Id addedBy); public abstract Builder addedBy(Account.Id addedBy);
public abstract Builder addedOn(Timestamp addedOn);
abstract Builder removedBy(Account.Id removedBy); abstract Builder removedBy(Account.Id removedBy);
abstract Builder removedOn(Timestamp removedOn); abstract Builder removedOn(Timestamp removedOn);
@@ -55,28 +46,20 @@ public abstract class AccountGroupByIdAudit {
public abstract AccountGroupByIdAudit build(); public abstract AccountGroupByIdAudit build();
} }
public abstract AccountGroupByIdAudit.Key key(); public abstract AccountGroup.Id groupId();
public abstract AccountGroup.UUID includeUuid();
public abstract Account.Id addedBy(); public abstract Account.Id addedBy();
public abstract Timestamp addedOn();
public abstract Optional<Account.Id> removedBy(); public abstract Optional<Account.Id> removedBy();
public abstract Optional<Timestamp> removedOn(); public abstract Optional<Timestamp> removedOn();
public abstract Builder toBuilder(); public abstract Builder toBuilder();
public AccountGroup.Id groupId() {
return key().groupId();
}
public Timestamp getAddedOn() {
return key().addedOn();
}
public AccountGroup.UUID includeUuid() {
return key().includeUuid();
}
public boolean isActive() { public boolean isActive() {
return !removedOn().isPresent(); return !removedOn().isPresent();
} }

View File

@@ -21,33 +21,24 @@ import java.util.Optional;
/** Membership of an {@link Account} in an {@link AccountGroup}. */ /** Membership of an {@link Account} in an {@link AccountGroup}. */
@AutoValue @AutoValue
public abstract class AccountGroupMemberAudit { public abstract class AccountGroupMemberAudit {
public static Key key(Account.Id accountId, AccountGroup.Id groupId, Timestamp addedOn) {
return new AutoValue_AccountGroupMemberAudit_Key(accountId, groupId, addedOn);
}
@AutoValue
public abstract static class Key {
public abstract Account.Id accountId();
public abstract AccountGroup.Id groupId();
public abstract Timestamp addedOn();
}
public static Builder builder() { public static Builder builder() {
return new AutoValue_AccountGroupMemberAudit.Builder(); return new AutoValue_AccountGroupMemberAudit.Builder();
} }
@AutoValue.Builder @AutoValue.Builder
public abstract static class Builder { public abstract static class Builder {
public abstract Builder key(Key key); public abstract Builder groupId(AccountGroup.Id groupId);
abstract Key key(); public abstract Builder memberId(Account.Id accountId);
public abstract Builder addedBy(Account.Id addedBy); public abstract Builder addedBy(Account.Id addedBy);
abstract Account.Id addedBy(); abstract Account.Id addedBy();
public abstract Builder addedOn(Timestamp addedOn);
abstract Timestamp addedOn();
abstract Builder removedBy(Account.Id removedBy); abstract Builder removedBy(Account.Id removedBy);
abstract Builder removedOn(Timestamp removedOn); abstract Builder removedOn(Timestamp removedOn);
@@ -57,34 +48,26 @@ public abstract class AccountGroupMemberAudit {
} }
public Builder removedLegacy() { public Builder removedLegacy() {
return removed(addedBy(), key().addedOn()); return removed(addedBy(), addedOn());
} }
public abstract AccountGroupMemberAudit build(); public abstract AccountGroupMemberAudit build();
} }
public abstract AccountGroupMemberAudit.Key key(); public abstract AccountGroup.Id groupId();
public abstract Account.Id memberId();
public abstract Account.Id addedBy(); public abstract Account.Id addedBy();
public abstract Timestamp addedOn();
public abstract Optional<Account.Id> removedBy(); public abstract Optional<Account.Id> removedBy();
public abstract Optional<Timestamp> removedOn(); public abstract Optional<Timestamp> removedOn();
public abstract Builder toBuilder(); public abstract Builder toBuilder();
public AccountGroup.Id groupId() {
return key().groupId();
}
public Account.Id memberId() {
return key().accountId();
}
public Timestamp addedOn() {
return key().addedOn();
}
public boolean isActive() { public boolean isActive() {
return !removedOn().isPresent(); return !removedOn().isPresent();
} }

View File

@@ -79,7 +79,9 @@ public class AuditLogReader {
MemberKey key = MemberKey.create(groupId, id); MemberKey key = MemberKey.create(groupId, id);
AccountGroupMemberAudit.Builder audit = AccountGroupMemberAudit.Builder audit =
AccountGroupMemberAudit.builder() AccountGroupMemberAudit.builder()
.key(AccountGroupMemberAudit.key(id, groupId, pc.when())) .memberId(id)
.groupId(groupId)
.addedOn(pc.when())
.addedBy(pc.authorId()); .addedBy(pc.authorId());
audits.put(key, audit); audits.put(key, audit);
result.add(audit); result.add(audit);
@@ -93,7 +95,9 @@ public class AuditLogReader {
// Match old behavior of DbGroupAuditListener and add a "legacy" add/remove pair. // Match old behavior of DbGroupAuditListener and add a "legacy" add/remove pair.
AccountGroupMemberAudit.Builder audit = AccountGroupMemberAudit.Builder audit =
AccountGroupMemberAudit.builder() AccountGroupMemberAudit.builder()
.key(AccountGroupMemberAudit.key(id, groupId, pc.when())) .groupId(groupId)
.memberId(id)
.addedOn(pc.when())
.addedBy(pc.authorId()) .addedBy(pc.authorId())
.removedLegacy(); .removedLegacy();
result.add(audit); result.add(audit);
@@ -118,7 +122,9 @@ public class AuditLogReader {
SubgroupKey key = SubgroupKey.create(groupId, uuid); SubgroupKey key = SubgroupKey.create(groupId, uuid);
AccountGroupByIdAudit.Builder audit = AccountGroupByIdAudit.Builder audit =
AccountGroupByIdAudit.builder() AccountGroupByIdAudit.builder()
.key(AccountGroupByIdAudit.key(groupId, uuid, pc.when())) .groupId(groupId)
.includeUuid(uuid)
.addedOn(pc.when())
.addedBy(pc.authorId()); .addedBy(pc.authorId());
audits.put(key, audit); audits.put(key, audit);
result.add(audit); result.add(audit);

View File

@@ -123,7 +123,7 @@ public class GetAuditLog implements RestReadView<GroupResource> {
auditEvents.add( auditEvents.add(
GroupAuditEventInfo.createAddGroupEvent( GroupAuditEventInfo.createAddGroupEvent(
accountLoader.get(auditEvent.addedBy()), auditEvent.key().addedOn(), member)); accountLoader.get(auditEvent.addedBy()), auditEvent.addedOn(), member));
if (!auditEvent.isActive()) { if (!auditEvent.isActive()) {
auditEvents.add( auditEvents.add(

View File

@@ -304,7 +304,9 @@ public final class AuditLogReaderTest extends AbstractGroupTest {
private static AccountGroupMemberAudit createExpMemberAudit( private static AccountGroupMemberAudit createExpMemberAudit(
AccountGroup.Id groupId, Account.Id id, Account.Id addedBy, Timestamp addedOn) { AccountGroup.Id groupId, Account.Id id, Account.Id addedBy, Timestamp addedOn) {
return AccountGroupMemberAudit.builder() return AccountGroupMemberAudit.builder()
.key(AccountGroupMemberAudit.key(id, groupId, addedOn)) .groupId(groupId)
.memberId(id)
.addedOn(addedOn)
.addedBy(addedBy) .addedBy(addedBy)
.build(); .build();
} }
@@ -312,7 +314,9 @@ public final class AuditLogReaderTest extends AbstractGroupTest {
private static AccountGroupByIdAudit createExpGroupAudit( private static AccountGroupByIdAudit createExpGroupAudit(
AccountGroup.Id groupId, AccountGroup.UUID uuid, Account.Id addedBy, Timestamp addedOn) { AccountGroup.Id groupId, AccountGroup.UUID uuid, Account.Id addedBy, Timestamp addedOn) {
return AccountGroupByIdAudit.builder() return AccountGroupByIdAudit.builder()
.key(AccountGroupByIdAudit.key(groupId, uuid, addedOn)) .groupId(groupId)
.includeUuid(uuid)
.addedOn(addedOn)
.addedBy(addedBy) .addedBy(addedBy)
.build(); .build();
} }