diff --git a/core/src/main/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java b/core/src/main/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java index 54a74368d..b04a1331e 100644 --- a/core/src/main/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java +++ b/core/src/main/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java @@ -152,7 +152,7 @@ public class AllocationTokenFlowUtils { } maybeTokenEntity = - tm().transact(() -> tm().loadByKeyIfPresent(VKey.create(AllocationToken.class, token))); + tm().transact(() -> tm().loadByKeyIfPresent(VKey.createSql(AllocationToken.class, token))); if (!maybeTokenEntity.isPresent()) { throw new InvalidAllocationTokenException(); diff --git a/core/src/main/java/google/registry/model/EntityClasses.java b/core/src/main/java/google/registry/model/EntityClasses.java index c6fbfe785..90fb5c0b8 100644 --- a/core/src/main/java/google/registry/model/EntityClasses.java +++ b/core/src/main/java/google/registry/model/EntityClasses.java @@ -22,7 +22,6 @@ import google.registry.model.contact.Contact; import google.registry.model.contact.ContactHistory; import google.registry.model.domain.Domain; import google.registry.model.domain.DomainHistory; -import google.registry.model.domain.token.AllocationToken; import google.registry.model.host.Host; import google.registry.model.host.HostHistory; import google.registry.model.index.EppResourceIndex; @@ -40,7 +39,6 @@ public final class EntityClasses { /** Set of entity classes. */ public static final ImmutableSet> ALL_CLASSES = ImmutableSet.of( - AllocationToken.class, Contact.class, ContactHistory.class, Domain.class, diff --git a/core/src/main/java/google/registry/model/domain/DomainBase.java b/core/src/main/java/google/registry/model/domain/DomainBase.java index 6a14e2077..488191ffc 100644 --- a/core/src/main/java/google/registry/model/domain/DomainBase.java +++ b/core/src/main/java/google/registry/model/domain/DomainBase.java @@ -277,7 +277,7 @@ public class DomainBase extends EppResource @Ignore DateTime dnsRefreshRequestTime; /** The {@link AllocationToken} for the package this domain is currently a part of. */ - @Nullable VKey currentPackageToken; + @Ignore @Nullable VKey currentPackageToken; /** * Returns the DNS refresh request time iff this domain's DNS needs refreshing, otherwise absent. diff --git a/core/src/main/java/google/registry/model/domain/token/AllocationToken.java b/core/src/main/java/google/registry/model/domain/token/AllocationToken.java index 9f0bcd94e..bc60dd0eb 100644 --- a/core/src/main/java/google/registry/model/domain/token/AllocationToken.java +++ b/core/src/main/java/google/registry/model/domain/token/AllocationToken.java @@ -31,18 +31,11 @@ import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Range; -import com.googlecode.objectify.Key; -import com.googlecode.objectify.annotation.Entity; -import com.googlecode.objectify.annotation.Id; -import com.googlecode.objectify.annotation.Ignore; -import com.googlecode.objectify.annotation.Index; -import com.googlecode.objectify.annotation.OnLoad; import google.registry.flows.EppException; import google.registry.flows.domain.DomainFlowUtils; import google.registry.model.BackupGroupRoot; import google.registry.model.Buildable; import google.registry.model.CreateAutoTimestamp; -import google.registry.model.annotations.ReportedOn; import google.registry.model.billing.BillingEvent.RenewalPriceBehavior; import google.registry.model.common.TimedTransitionProperty; import google.registry.model.reporting.HistoryEntry; @@ -55,27 +48,23 @@ import javax.annotation.Nullable; import javax.persistence.AttributeOverride; import javax.persistence.AttributeOverrides; import javax.persistence.Column; +import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; +import javax.persistence.Id; +import javax.persistence.Index; import javax.persistence.Table; import org.joda.time.DateTime; /** An entity representing an allocation token. */ -@ReportedOn @Entity -@WithStringVKey -@javax.persistence.Entity +@WithStringVKey(compositeKey = true) @Table( indexes = { - @javax.persistence.Index( - columnList = "token", - name = "allocation_token_token_idx", - unique = true), - @javax.persistence.Index( - columnList = "domainName", - name = "allocation_token_domain_name_idx"), - @javax.persistence.Index(columnList = "tokenType"), - @javax.persistence.Index(columnList = "redemption_domain_repo_id") + @Index(columnList = "token", name = "allocation_token_token_idx", unique = true), + @Index(columnList = "domainName", name = "allocation_token_domain_name_idx"), + @Index(columnList = "tokenType"), + @Index(columnList = "redemption_domain_repo_id") }) public class AllocationToken extends BackupGroupRoot implements Buildable { @@ -157,11 +146,10 @@ public class AllocationToken extends BackupGroupRoot implements Buildable { } /** The allocation token string. */ - @javax.persistence.Id @Id String token; + @Id String token; /** The key of the history entry for which the token was used. Null if not yet used. */ @Nullable - @Index @AttributeOverrides({ @AttributeOverride(name = "repoId", column = @Column(name = "redemption_domain_repo_id")), @AttributeOverride( @@ -171,10 +159,10 @@ public class AllocationToken extends BackupGroupRoot implements Buildable { DomainHistoryVKey redemptionHistoryEntry; /** The fully-qualified domain name that this token is limited to, if any. */ - @Nullable @Index String domainName; + @Nullable String domainName; /** When this token was created. */ - @Ignore CreateAutoTimestamp creationTime = CreateAutoTimestamp.create(null); + CreateAutoTimestamp creationTime = CreateAutoTimestamp.create(null); /** Allowed registrar client IDs for this token, or null if all registrars are allowed. */ @Column(name = "allowedRegistrarIds") @@ -203,21 +191,12 @@ public class AllocationToken extends BackupGroupRoot implements Buildable { @Enumerated(EnumType.STRING) @Column(name = "renewalPriceBehavior", nullable = false) - @Ignore RenewalPriceBehavior renewalPriceBehavior = RenewalPriceBehavior.DEFAULT; @Enumerated(EnumType.STRING) @Column(nullable = false) RegistrationBehavior registrationBehavior = RegistrationBehavior.DEFAULT; - // TODO: Remove onLoad once all allocation tokens are migrated to have a discountYears of 1. - @OnLoad - void onLoad() { - if (discountYears == 0) { - discountYears = 1; - } - } - /** * Promotional token validity periods. * @@ -296,7 +275,7 @@ public class AllocationToken extends BackupGroupRoot implements Buildable { throw new IllegalArgumentException( String.format("%s tokens are not stored in the database", getTokenBehavior())); } - return VKey.create(AllocationToken.class, getToken(), Key.create(this)); + return VKey.createSql(AllocationToken.class, getToken()); } @Override @@ -330,7 +309,8 @@ public class AllocationToken extends BackupGroupRoot implements Buildable { "Redemption history entry can only be specified for SINGLE_USE tokens"); checkArgument( getInstance().tokenType != TokenType.PACKAGE - || getInstance().allowedClientIds.size() == 1, + || (getInstance().allowedClientIds != null + && getInstance().allowedClientIds.size() == 1), "PACKAGE tokens must have exactly one allowed client registrar"); checkArgument( getInstance().discountFraction > 0 || !getInstance().discountPremiums, diff --git a/core/src/main/java/google/registry/tools/GenerateAllocationTokensCommand.java b/core/src/main/java/google/registry/tools/GenerateAllocationTokensCommand.java index 2c2fe66e2..da643ee7b 100644 --- a/core/src/main/java/google/registry/tools/GenerateAllocationTokensCommand.java +++ b/core/src/main/java/google/registry/tools/GenerateAllocationTokensCommand.java @@ -314,7 +314,7 @@ class GenerateAllocationTokensCommand implements CommandWithRemoteApi { private ImmutableSet getExistingTokenStrings(ImmutableSet candidates) { ImmutableSet> existingTokenKeys = candidates.stream() - .map(input -> VKey.create(AllocationToken.class, input)) + .map(input -> VKey.createSql(AllocationToken.class, input)) .collect(toImmutableSet()); return tm().transact( () -> diff --git a/core/src/main/java/google/registry/tools/GetAllocationTokenCommand.java b/core/src/main/java/google/registry/tools/GetAllocationTokenCommand.java index e28b3278a..bfd5ccafa 100644 --- a/core/src/main/java/google/registry/tools/GetAllocationTokenCommand.java +++ b/core/src/main/java/google/registry/tools/GetAllocationTokenCommand.java @@ -47,7 +47,7 @@ final class GetAllocationTokenCommand implements CommandWithRemoteApi { for (List tokens : Lists.partition(mainParameters, BATCH_SIZE)) { ImmutableList> tokenKeys = tokens.stream() - .map(t -> VKey.create(AllocationToken.class, t)) + .map(t -> VKey.createSql(AllocationToken.class, t)) .collect(toImmutableList()); tm().transact( () -> diff --git a/core/src/main/java/google/registry/tools/UpdateOrDeleteAllocationTokensCommand.java b/core/src/main/java/google/registry/tools/UpdateOrDeleteAllocationTokensCommand.java index acb9310fc..9bb2f786e 100644 --- a/core/src/main/java/google/registry/tools/UpdateOrDeleteAllocationTokensCommand.java +++ b/core/src/main/java/google/registry/tools/UpdateOrDeleteAllocationTokensCommand.java @@ -55,7 +55,7 @@ abstract class UpdateOrDeleteAllocationTokensCommand extends ConfirmingCommand if (tokens != null) { ImmutableSet> keys = tokens.stream() - .map(token -> VKey.create(AllocationToken.class, token)) + .map(token -> VKey.createSql(AllocationToken.class, token)) .collect(toImmutableSet()); ImmutableSet> nonexistentKeys = tm().transact( diff --git a/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java index 98ec4df5f..9a5ca7d50 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java @@ -1352,7 +1352,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase tm().loadByKey(VKey.create(AllocationToken.class, token))); + tm().transact(() -> tm().loadByKey(VKey.createSql(AllocationToken.class, token))); assertThat(reloadedToken.isRedeemed()).isTrue(); assertThat(reloadedToken.getRedemptionHistoryEntry()) .hasValue( @@ -1362,7 +1362,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase tm().loadByKey(VKey.create(AllocationToken.class, token))); + tm().transact(() -> tm().loadByKey(VKey.createSql(AllocationToken.class, token))); assertThat(reloadedToken.isRedeemed()).isFalse(); } diff --git a/core/src/test/java/google/registry/flows/domain/DomainRenewFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainRenewFlowTest.java index b842d101f..48e2a2c81 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainRenewFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainRenewFlowTest.java @@ -332,7 +332,7 @@ class DomainRenewFlowTest extends ResourceFlowTestCase @Test private void assertAllocationTokenWasNotRedeemed(String token) { AllocationToken reloadedToken = - tm().transact(() -> tm().loadByKey(VKey.create(AllocationToken.class, token))); + tm().transact(() -> tm().loadByKey(VKey.createSql(AllocationToken.class, token))); assertThat(reloadedToken.isRedeemed()).isFalse(); } diff --git a/core/src/test/java/google/registry/model/common/ClassPathManagerTest.java b/core/src/test/java/google/registry/model/common/ClassPathManagerTest.java index e747b446a..659bc1857 100644 --- a/core/src/test/java/google/registry/model/common/ClassPathManagerTest.java +++ b/core/src/test/java/google/registry/model/common/ClassPathManagerTest.java @@ -20,7 +20,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import google.registry.model.contact.Contact; import google.registry.model.domain.Domain; import google.registry.model.domain.DomainHistory; -import google.registry.model.domain.token.AllocationToken; import google.registry.model.host.Host; import google.registry.model.index.EppResourceIndex; import google.registry.model.index.EppResourceIndexBucket; @@ -49,7 +48,6 @@ public class ClassPathManagerTest { */ assertThat(ClassPathManager.getClass("ForeignKeyContactIndex")) .isEqualTo(ForeignKeyContactIndex.class); - assertThat(ClassPathManager.getClass("AllocationToken")).isEqualTo(AllocationToken.class); assertThat(ClassPathManager.getClass("Host")).isEqualTo(Host.class); assertThat(ClassPathManager.getClass("Registrar")).isEqualTo(Registrar.class); assertThat(ClassPathManager.getClass("Contact")).isEqualTo(Contact.class); @@ -100,7 +98,6 @@ public class ClassPathManagerTest { */ assertThat(ClassPathManager.getClassName(ForeignKeyContactIndex.class)) .isEqualTo("ForeignKeyContactIndex"); - assertThat(ClassPathManager.getClassName(AllocationToken.class)).isEqualTo("AllocationToken"); assertThat(ClassPathManager.getClassName(Host.class)).isEqualTo("Host"); assertThat(ClassPathManager.getClassName(Registrar.class)).isEqualTo("Registrar"); assertThat(ClassPathManager.getClassName(Contact.class)).isEqualTo("Contact"); diff --git a/core/src/test/java/google/registry/model/domain/token/AllocationTokenTest.java b/core/src/test/java/google/registry/model/domain/token/AllocationTokenTest.java index 93f7da570..d89d89a7b 100644 --- a/core/src/test/java/google/registry/model/domain/token/AllocationTokenTest.java +++ b/core/src/test/java/google/registry/model/domain/token/AllocationTokenTest.java @@ -222,8 +222,7 @@ public class AllocationTokenTest extends EntityTestCase { .setToken("abc123") .setTokenType(TokenType.PACKAGE) .setRenewalPriceBehavior(RenewalPriceBehavior.DEFAULT); - IllegalArgumentException thrown = - assertThrows(IllegalArgumentException.class, () -> builder.build()); + IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build); assertThat(thrown) .hasMessageThat() .isEqualTo("Package tokens must have renewalPriceBehavior set to SPECIFIED"); @@ -280,7 +279,7 @@ public class AllocationTokenTest extends EntityTestCase { @Test void testBuild_onlyOneClientInPackage() { - Buildable.Builder builder = + Buildable.Builder builder = new AllocationToken.Builder() .setToken("foobar") .setTokenType(PACKAGE) @@ -531,7 +530,7 @@ public class AllocationTokenTest extends EntityTestCase { } private void assertTerminal(TokenStatus status) { - // The "terminal" message is slightly different so it must be tested separately + // The "terminal" message is slightly different, so it must be tested separately IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, diff --git a/core/src/test/resources/google/registry/model/schema.txt b/core/src/test/resources/google/registry/model/schema.txt index b84de6540..2743a1437 100644 --- a/core/src/test/resources/google/registry/model/schema.txt +++ b/core/src/test/resources/google/registry/model/schema.txt @@ -89,7 +89,6 @@ class google.registry.model.domain.Domain { google.registry.persistence.VKey billingContact; google.registry.persistence.VKey registrantContact; google.registry.persistence.VKey techContact; - google.registry.persistence.VKey currentPackageToken; google.registry.persistence.VKey autorenewPollMessage; google.registry.persistence.VKey deletePollMessage; java.lang.String creationClientId; @@ -122,7 +121,6 @@ class google.registry.model.domain.DomainBase { google.registry.persistence.VKey billingContact; google.registry.persistence.VKey registrantContact; google.registry.persistence.VKey techContact; - google.registry.persistence.VKey currentPackageToken; google.registry.persistence.VKey autorenewPollMessage; google.registry.persistence.VKey deletePollMessage; java.lang.String creationClientId; @@ -216,35 +214,6 @@ class google.registry.model.domain.secdns.DomainDsDataHistory { java.lang.Long domainHistoryRevisionId; java.lang.Long dsDataHistoryRevisionId; } -class google.registry.model.domain.token.AllocationToken { - @Id java.lang.String token; - boolean discountPremiums; - double discountFraction; - google.registry.model.common.TimedTransitionProperty tokenStatusTransitions; - google.registry.model.domain.token.AllocationToken$RegistrationBehavior registrationBehavior; - google.registry.model.domain.token.AllocationToken$TokenType tokenType; - google.registry.persistence.DomainHistoryVKey redemptionHistoryEntry; - int discountYears; - java.lang.String domainName; - java.util.Set allowedClientIds; - java.util.Set allowedTlds; -} -enum google.registry.model.domain.token.AllocationToken$RegistrationBehavior { - ANCHOR_TENANT; - BYPASS_TLD_STATE; - DEFAULT; -} -enum google.registry.model.domain.token.AllocationToken$TokenStatus { - CANCELLED; - ENDED; - NOT_STARTED; - VALID; -} -enum google.registry.model.domain.token.AllocationToken$TokenType { - PACKAGE; - SINGLE_USE; - UNLIMITED_USE; -} class google.registry.model.eppcommon.AuthInfo$PasswordAuth { java.lang.String repoId; java.lang.String value; @@ -509,7 +478,3 @@ enum google.registry.model.transfer.TransferStatus { SERVER_APPROVED; SERVER_CANCELLED; } -class google.registry.persistence.DomainHistoryVKey { - java.lang.Long historyRevisionId; - java.lang.String repoId; -}