Remove nearly all uses of ReferenceUnion

ReferenceUnion is a hack to work around the mismatch between how
we store references (by roid) and how they are represented in EPP
(by foreign key). If it ever needed to exist (not entirely clear...)
it should have remained tightly scoped within the domain commands
and resources. Instead it has leaked everywhere in the project,
causing lots of boilerplate. This CL hides all of that behind
standard Refs, and should be followed by work to remove ReferenceUnion
completely.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=122424416
This commit is contained in:
cgoldfeder 2016-05-16 08:55:54 -07:00 committed by Justine Tunney
parent 56c8bb0f2a
commit 9a2afc7a9b
59 changed files with 448 additions and 454 deletions

View file

@ -30,6 +30,8 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Ref;
import google.registry.flows.EppException.UnimplementedExtensionException;
import google.registry.flows.FlowRunner.CommitMode;
import google.registry.flows.FlowRunner.UserPrivileges;
@ -50,7 +52,7 @@ import google.registry.flows.domain.DomainFlowUtils.LinkedResourceDoesNotExistEx
import google.registry.flows.domain.DomainFlowUtils.MissingAdminContactException;
import google.registry.flows.domain.DomainFlowUtils.MissingContactTypeException;
import google.registry.flows.domain.DomainFlowUtils.MissingTechnicalContactException;
import google.registry.flows.domain.DomainFlowUtils.NameserverNotAllowedException;
import google.registry.flows.domain.DomainFlowUtils.NameserversNotAllowedException;
import google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException;
import google.registry.flows.domain.DomainFlowUtils.RegistrantNotAllowedException;
import google.registry.flows.domain.DomainFlowUtils.TooManyDsRecordsException;
@ -60,7 +62,6 @@ import google.registry.model.domain.DesignatedContact;
import google.registry.model.domain.DesignatedContact.Type;
import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.DomainApplication.Builder;
import google.registry.model.domain.ReferenceUnion;
import google.registry.model.domain.launch.ApplicationStatus;
import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.eppcommon.StatusValue;
@ -108,9 +109,9 @@ public class DomainApplicationUpdateFlowTest
private DomainApplication persistApplication() throws Exception {
return persistResource(newApplicationBuilder()
.setContacts(ImmutableSet.of(
DesignatedContact.create(Type.TECH, ReferenceUnion.create(sh8013Contact)),
DesignatedContact.create(Type.ADMIN, ReferenceUnion.create(unusedContact))))
.setNameservers(ImmutableSet.of(ReferenceUnion.create(
DesignatedContact.create(Type.TECH, Ref.create(sh8013Contact)),
DesignatedContact.create(Type.ADMIN, Ref.create(unusedContact))))
.setNameservers(ImmutableSet.of(Ref.create(
loadByUniqueId(HostResource.class, "ns1.example.tld", clock.nowUtc()))))
.build());
}
@ -174,7 +175,7 @@ public class DomainApplicationUpdateFlowTest
persistReferencedEntities();
ContactResource sh8013 = loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc());
persistResource(
newApplicationBuilder().setRegistrant(ReferenceUnion.create(sh8013)).build());
newApplicationBuilder().setRegistrant(Ref.create(sh8013)).build());
clock.advanceOneMilli();
runFlowAssertResponse(readFile("domain_update_response.xml"));
}
@ -184,13 +185,13 @@ public class DomainApplicationUpdateFlowTest
setEppInput("domain_update_sunrise_remove_multiple_contacts.xml");
persistReferencedEntities();
ContactResource sh8013 = loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc());
ReferenceUnion<ContactResource> sh8013ReferenceUnion = ReferenceUnion.create(sh8013);
Ref<ContactResource> sh8013Ref = Ref.create(sh8013);
persistResource(newApplicationBuilder()
.setRegistrant(sh8013ReferenceUnion)
.setRegistrant(sh8013Ref)
.setContacts(ImmutableSet.of(
DesignatedContact.create(Type.ADMIN, sh8013ReferenceUnion),
DesignatedContact.create(Type.BILLING, sh8013ReferenceUnion),
DesignatedContact.create(Type.TECH, sh8013ReferenceUnion)))
DesignatedContact.create(Type.ADMIN, sh8013Ref),
DesignatedContact.create(Type.BILLING, sh8013Ref),
DesignatedContact.create(Type.TECH, sh8013Ref)))
.build());
clock.advanceOneMilli();
runFlowAssertResponse(readFile("domain_update_response.xml"));
@ -373,10 +374,10 @@ public class DomainApplicationUpdateFlowTest
}
private void modifyApplicationToHave13Nameservers() throws Exception {
ImmutableSet.Builder<ReferenceUnion<HostResource>> nameservers = new ImmutableSet.Builder<>();
ImmutableSet.Builder<Ref<HostResource>> nameservers = new ImmutableSet.Builder<>();
for (int i = 1; i < 15; i++) {
if (i != 2) { // Skip 2 since that's the one that the tests will add.
nameservers.add(ReferenceUnion.create(loadByUniqueId(
nameservers.add(Ref.create(loadByUniqueId(
HostResource.class, String.format("ns%d.example.tld", i), clock.nowUtc())));
}
}
@ -496,7 +497,7 @@ public class DomainApplicationUpdateFlowTest
// Add a tech contact to the persisted entity, which should cause the flow to fail when it tries
// to add "mak21" as a second tech contact.
persistResource(reloadResourceByUniqueId().asBuilder().setContacts(ImmutableSet.of(
DesignatedContact.create(Type.TECH, ReferenceUnion.create(
DesignatedContact.create(Type.TECH, Ref.create(
loadByUniqueId(ContactResource.class, "foo", clock.nowUtc()))))).build());
runFlow();
}
@ -581,7 +582,7 @@ public class DomainApplicationUpdateFlowTest
setEppInput("domain_update_sunrise_add_remove_same_host.xml");
persistReferencedEntities();
persistResource(newApplicationBuilder()
.setNameservers(ImmutableSet.of(ReferenceUnion.create(
.setNameservers(ImmutableSet.of(Ref.create(
loadByUniqueId(HostResource.class, "ns1.example.tld", clock.nowUtc()))))
.build());
runFlow();
@ -595,7 +596,7 @@ public class DomainApplicationUpdateFlowTest
persistResource(newApplicationBuilder()
.setContacts(ImmutableSet.of(DesignatedContact.create(
Type.TECH,
ReferenceUnion.create(
Ref.create(
loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc())))))
.build());
runFlow();
@ -608,8 +609,8 @@ public class DomainApplicationUpdateFlowTest
persistReferencedEntities();
persistResource(newApplicationBuilder()
.setContacts(ImmutableSet.of(
DesignatedContact.create(Type.ADMIN, ReferenceUnion.create(sh8013Contact)),
DesignatedContact.create(Type.TECH, ReferenceUnion.create(sh8013Contact))))
DesignatedContact.create(Type.ADMIN, Ref.create(sh8013Contact)),
DesignatedContact.create(Type.TECH, Ref.create(sh8013Contact))))
.build());
runFlow();
}
@ -621,8 +622,8 @@ public class DomainApplicationUpdateFlowTest
persistReferencedEntities();
persistResource(newApplicationBuilder()
.setContacts(ImmutableSet.of(
DesignatedContact.create(Type.ADMIN, ReferenceUnion.create(sh8013Contact)),
DesignatedContact.create(Type.TECH, ReferenceUnion.create(sh8013Contact))))
DesignatedContact.create(Type.ADMIN, Ref.create(sh8013Contact)),
DesignatedContact.create(Type.TECH, Ref.create(sh8013Contact))))
.build());
runFlow();
}
@ -649,7 +650,7 @@ public class DomainApplicationUpdateFlowTest
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo"))
.build());
clock.advanceOneMilli();
thrown.expect(NameserverNotAllowedException.class);
thrown.expect(NameserversNotAllowedException.class);
runFlow();
}