mirror of
https://github.com/google/nomulus.git
synced 2025-05-03 13:37:51 +02:00
Switch over to non-ReferenceUnion fields on DomainBase
This is the second phase of a three phase migration to remove ReferenceUnions. As of the end of this phase, ReferenceUnions are no longer read from in any active code paths, but are still written to in case a rollback to the previous version is necessary. The third and final phase will remove the ReferenceUnions entirely. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=136388057
This commit is contained in:
parent
d9dbf2ec1a
commit
361a53a3c9
6 changed files with 25 additions and 34 deletions
|
@ -347,12 +347,10 @@ public final class EppResourceUtils {
|
|||
public static List<Key<DomainBase>> queryDomainsUsingResource(
|
||||
Class<? extends EppResource> clazz, Key<? extends EppResource> key, DateTime now, int limit) {
|
||||
checkArgument(ContactResource.class.equals(clazz) || HostResource.class.equals(clazz));
|
||||
return ofy().load().type(DomainBase.class)
|
||||
.filter(
|
||||
clazz.equals(ContactResource.class)
|
||||
? "allContacts.contactId.linked"
|
||||
: "nameservers.linked",
|
||||
key)
|
||||
return ofy()
|
||||
.load()
|
||||
.type(DomainBase.class)
|
||||
.filter(clazz.equals(ContactResource.class) ? "allContacts.contact" : "nsHosts", key)
|
||||
.filter("deletionTime >", now)
|
||||
.limit(limit)
|
||||
.keys()
|
||||
|
|
|
@ -72,6 +72,6 @@ public class DesignatedContact extends ImmutableObject {
|
|||
}
|
||||
|
||||
public Key<ContactResource> getContactKey() {
|
||||
return contactId.getLinked();
|
||||
return contact;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -183,11 +183,7 @@ public abstract class DomainBase extends EppResource {
|
|||
}
|
||||
|
||||
public ImmutableSet<Key<HostResource>> getNameservers() {
|
||||
ImmutableSet.Builder<Key<HostResource>> builder = new ImmutableSet.Builder<>();
|
||||
for (ReferenceUnion<HostResource> union : nullToEmptyImmutableCopy(nameservers)) {
|
||||
builder.add(union.getLinked());
|
||||
}
|
||||
return builder.build();
|
||||
return nullToEmptyImmutableCopy(nsHosts);
|
||||
}
|
||||
|
||||
/** Loads and returns the fully qualified host names of all linked nameservers. */
|
||||
|
@ -242,13 +238,13 @@ public abstract class DomainBase extends EppResource {
|
|||
@OnSave
|
||||
void dualSaveReferenceUnions() {
|
||||
for (DesignatedContact contact : nullToEmptyImmutableCopy(allContacts)) {
|
||||
contact.contact = contact.contactId.getLinked();
|
||||
contact.contactId = ReferenceUnion.create(contact.contact);
|
||||
}
|
||||
ImmutableSet.Builder<Key<HostResource>> hostKeys = new ImmutableSet.Builder<>();
|
||||
for (ReferenceUnion<HostResource> refUnion : nullToEmptyImmutableCopy(nameservers)) {
|
||||
hostKeys.add(refUnion.getLinked());
|
||||
ImmutableSet.Builder<ReferenceUnion<HostResource>> hosts = new ImmutableSet.Builder<>();
|
||||
for (Key<HostResource> hostKey : nullToEmptyImmutableCopy(nsHosts)) {
|
||||
hosts.add(ReferenceUnion.create(hostKey));
|
||||
}
|
||||
nsHosts = hostKeys.build();
|
||||
nameservers = hosts.build();
|
||||
}
|
||||
|
||||
/** Predicate to determine if a given {@link DesignatedContact} is the registrant. */
|
||||
|
@ -307,11 +303,7 @@ public abstract class DomainBase extends EppResource {
|
|||
}
|
||||
|
||||
public B setNameservers(ImmutableSet<Key<HostResource>> nameservers) {
|
||||
ImmutableSet.Builder<ReferenceUnion<HostResource>> builder = new ImmutableSet.Builder<>();
|
||||
for (Key<HostResource> key : nullToEmpty(nameservers)) {
|
||||
builder.add(ReferenceUnion.create(key));
|
||||
}
|
||||
getInstance().nameservers = builder.build();
|
||||
getInstance().nsHosts = nameservers;
|
||||
return thisCastToDerived();
|
||||
}
|
||||
|
||||
|
|
|
@ -269,7 +269,7 @@ public class RdapDomainSearchAction extends RdapActionBase {
|
|||
for (List<Key<HostResource>> chunk : Iterables.partition(hostKeys, 30)) {
|
||||
for (DomainResource domain : ofy().load()
|
||||
.type(DomainResource.class)
|
||||
.filter("nameservers.linked in", chunk)
|
||||
.filter("nsHosts in", chunk)
|
||||
.filter("deletionTime >", now)
|
||||
.limit(rdapResultSetMaxSize + 1)) {
|
||||
if (!domains.contains(domain)) {
|
||||
|
|
|
@ -145,16 +145,16 @@ public class DomainApplicationTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testEmptySetsAndArraysBecomeNull() {
|
||||
assertThat(emptyBuilder().setNameservers(null).build().nameservers).isNull();
|
||||
assertThat(emptyBuilder().setNameservers(null).build().nsHosts).isNull();
|
||||
assertThat(emptyBuilder()
|
||||
.setNameservers(ImmutableSet.<Key<HostResource>>of())
|
||||
.build()
|
||||
.nameservers)
|
||||
.nsHosts)
|
||||
.isNull();
|
||||
assertThat(emptyBuilder()
|
||||
.setNameservers(ImmutableSet.of(Key.create(newHostResource("foo.example.tld"))))
|
||||
.build()
|
||||
.nameservers)
|
||||
.nsHosts)
|
||||
.isNotNull();
|
||||
// This behavior should also hold true for ImmutableObjects nested in collections.
|
||||
assertThat(emptyBuilder()
|
||||
|
|
|
@ -207,13 +207,13 @@ public class DomainResourceTest extends EntityTestCase {
|
|||
@Test
|
||||
public void testEmptySetsAndArraysBecomeNull() {
|
||||
assertThat(newDomainResource("example.com").asBuilder()
|
||||
.setNameservers(null).build().nameservers).isNull();
|
||||
.setNameservers(null).build().nsHosts).isNull();
|
||||
assertThat(newDomainResource("example.com").asBuilder()
|
||||
.setNameservers(ImmutableSet.<Key<HostResource>>of()).build().nameservers)
|
||||
.setNameservers(ImmutableSet.<Key<HostResource>>of()).build().nsHosts)
|
||||
.isNull();
|
||||
assertThat(newDomainResource("example.com").asBuilder()
|
||||
.setNameservers(ImmutableSet.of(Key.create(newHostResource("foo.example.tld"))))
|
||||
.build().nameservers)
|
||||
.build().nsHosts)
|
||||
.isNotNull();
|
||||
// This behavior should also hold true for ImmutableObjects nested in collections.
|
||||
assertThat(newDomainResource("example.com").asBuilder()
|
||||
|
@ -462,21 +462,22 @@ public class DomainResourceTest extends EntityTestCase {
|
|||
public void testDualSavingOfDesignatedContact() {
|
||||
ContactResource contact = persistActiveContact("time1006");
|
||||
DesignatedContact designatedContact = new DesignatedContact();
|
||||
designatedContact.contactId = ReferenceUnion.create(Key.create(contact));
|
||||
designatedContact.contact = Key.create(contact);
|
||||
designatedContact.type = Type.ADMIN;
|
||||
DomainResource domainWithContact =
|
||||
domain.asBuilder().setContacts(ImmutableSet.of(designatedContact)).build();
|
||||
assertThat(getOnlyElement(domainWithContact.getContacts()).contact).isNull();
|
||||
assertThat(getOnlyElement(domainWithContact.getContacts()).contactId).isNull();
|
||||
DomainResource reloadedDomain = persistResource(domainWithContact);
|
||||
assertThat(getOnlyElement(reloadedDomain.getContacts()).contact).isEqualTo(Key.create(contact));
|
||||
assertThat(getOnlyElement(reloadedDomain.getContacts()).contactId)
|
||||
.isEqualTo(ReferenceUnion.create(Key.create(contact)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDualSavingOfNameservers() {
|
||||
HostResource host = persistActiveHost("zzz.xxx.yyy");
|
||||
DomainResource domain = newDomainResource("python-django-unchained.com", host);
|
||||
assertThat(domain.nsHosts).isNull();
|
||||
assertThat(domain.nameservers).isNull();
|
||||
DomainResource djangoReloaded = persistResource(domain);
|
||||
assertThat(djangoReloaded.nsHosts).containsExactly(Key.create(host));
|
||||
assertThat(djangoReloaded.nameservers).containsExactly(ReferenceUnion.create(Key.create(host)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue