diff --git a/java/google/registry/flows/ResourceAsyncDeleteFlow.java b/java/google/registry/flows/ResourceAsyncDeleteFlow.java index aaba301fd..d18f28f49 100644 --- a/java/google/registry/flows/ResourceAsyncDeleteFlow.java +++ b/java/google/registry/flows/ResourceAsyncDeleteFlow.java @@ -17,12 +17,12 @@ package google.registry.flows; import static google.registry.model.eppoutput.Result.Code.SuccessWithActionPending; import static google.registry.model.ofy.ObjectifyService.ofy; +import com.googlecode.objectify.Ref; import com.googlecode.objectify.Work; import google.registry.flows.EppException.AssociationProhibitsOperationException; import google.registry.model.EppResource; import google.registry.model.EppResource.Builder; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppinput.ResourceCommand.SingleResourceCommand; import google.registry.model.eppoutput.Result.Code; @@ -51,7 +51,7 @@ public abstract class ResourceAsyncDeleteFlow // that would be hard to reason about, and there's no real gain in doing so. return false; } - return isLinkedForFailfast(ReferenceUnion.create(fki.getReference())); + return isLinkedForFailfast(fki.getReference()); } }); if (isLinked) { @@ -60,7 +60,7 @@ public abstract class ResourceAsyncDeleteFlow } /** Subclasses must override this to check if the supplied reference has incoming links. */ - protected abstract boolean isLinkedForFailfast(ReferenceUnion ref); + protected abstract boolean isLinkedForFailfast(Ref ref); @Override protected final R createOrMutateResource() { diff --git a/java/google/registry/flows/async/DeleteContactResourceAction.java b/java/google/registry/flows/async/DeleteContactResourceAction.java index 731320029..812e21c3d 100644 --- a/java/google/registry/flows/async/DeleteContactResourceAction.java +++ b/java/google/registry/flows/async/DeleteContactResourceAction.java @@ -16,9 +16,10 @@ package google.registry.flows.async; import static google.registry.flows.ResourceFlowUtils.handlePendingTransferOnDelete; +import com.googlecode.objectify.Ref; + import google.registry.model.contact.ContactResource; import google.registry.model.domain.DomainBase; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.reporting.HistoryEntry; import google.registry.model.reporting.HistoryEntry.Type; import google.registry.request.Action; @@ -48,7 +49,7 @@ public class DeleteContactResourceAction extends DeleteEppResourceAction targetResourceRef) { + DomainBase domain, Ref targetResourceRef) { return domain.getReferencedContacts().contains(targetResourceRef); } } diff --git a/java/google/registry/flows/async/DeleteEppResourceAction.java b/java/google/registry/flows/async/DeleteEppResourceAction.java index 26a1a05c1..737746caa 100644 --- a/java/google/registry/flows/async/DeleteEppResourceAction.java +++ b/java/google/registry/flows/async/DeleteEppResourceAction.java @@ -41,7 +41,6 @@ import google.registry.mapreduce.inputs.NullInput; import google.registry.model.EppResource; import google.registry.model.annotations.ExternalMessagingName; import google.registry.model.domain.DomainBase; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.eppcommon.StatusValue; import google.registry.model.poll.PollMessage; import google.registry.model.reporting.HistoryEntry; @@ -110,7 +109,7 @@ public abstract class DeleteEppResourceAction implements "Resource %s is already deleted.", resource.getForeignKey()); checkState( resource.getStatusValues().contains(StatusValue.PENDING_DELETE), - "Resource %s is not set as PENDING_DELETE", resource.getForeignKey()); + "Resource %s is not set as PENDING_DELETE", resource.getForeignKey()); mapper.setTargetResource(resourceKey); reducer.setClient(requestingClientId, isSuperuser); logger.infofmt("Executing Delete EPP resource mapreduce for %s", resourceKey); @@ -147,7 +146,7 @@ public abstract class DeleteEppResourceAction implements } /** Determine whether the target resource is a linked resource on the domain. */ - protected abstract boolean isLinked(DomainBase domain, ReferenceUnion targetResourceRef); + protected abstract boolean isLinked(DomainBase domain, Ref targetResourceRef); @Override public void map(DomainBase domain) { @@ -159,12 +158,12 @@ public abstract class DeleteEppResourceAction implements emit(targetEppResourceKey, false); return; } - // The ReferenceUnion can't be a field on the Mapper, because when a Ref is serialized - // (required for each MapShardTask), it uses the DeadRef version, which contains the Ref's - // value, which isn't serializable. Thankfully, this isn't expensive. + // The Ref can't be a field on the Mapper, because when a Ref is serialized (required for + // each MapShardTask), it uses the DeadRef version, which contains the Ref's value, which + // isn't serializable. Thankfully, this isn't expensive. // See: https://github.com/objectify/objectify/blob/master/src/main/java/com/googlecode/objectify/impl/ref/DeadRef.java if (isActive(domain, targetResourceUpdateTimestamp) - && isLinked(domain, ReferenceUnion.create(Ref.create(targetEppResourceKey)))) { + && isLinked(domain, Ref.create(targetEppResourceKey))) { emit(targetEppResourceKey, true); } } diff --git a/java/google/registry/flows/async/DeleteHostResourceAction.java b/java/google/registry/flows/async/DeleteHostResourceAction.java index 3100a2eee..4414402f1 100644 --- a/java/google/registry/flows/async/DeleteHostResourceAction.java +++ b/java/google/registry/flows/async/DeleteHostResourceAction.java @@ -16,9 +16,10 @@ package google.registry.flows.async; import static google.registry.model.ofy.ObjectifyService.ofy; +import com.googlecode.objectify.Ref; + import google.registry.dns.DnsQueue; import google.registry.model.domain.DomainBase; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.host.HostResource; import google.registry.model.reporting.HistoryEntry; import google.registry.model.reporting.HistoryEntry.Type; @@ -48,8 +49,7 @@ public class DeleteHostResourceAction extends DeleteEppResourceAction targetResourceRef) { + protected boolean isLinked(DomainBase domain, Ref targetResourceRef) { return domain.getNameservers().contains(targetResourceRef); } } diff --git a/java/google/registry/flows/async/DnsRefreshForHostRenameAction.java b/java/google/registry/flows/async/DnsRefreshForHostRenameAction.java index b14f62be2..97c5a406b 100644 --- a/java/google/registry/flows/async/DnsRefreshForHostRenameAction.java +++ b/java/google/registry/flows/async/DnsRefreshForHostRenameAction.java @@ -30,7 +30,6 @@ import google.registry.mapreduce.MapreduceAction; import google.registry.mapreduce.MapreduceRunner; import google.registry.mapreduce.inputs.EppResourceInputs; import google.registry.model.domain.DomainResource; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.host.HostResource; import google.registry.request.Action; import google.registry.request.HttpException.BadRequestException; @@ -98,7 +97,7 @@ public class DnsRefreshForHostRenameAction implements MapreduceAction { @Override public final void map(DomainResource domain) { if (isActive(domain, hostUpdateTime) - && domain.getNameservers().contains(ReferenceUnion.create(Ref.create(targetHostKey)))) { + && domain.getNameservers().contains(Ref.create(targetHostKey))) { try { dnsQueue.addDomainRefreshTask(domain.getFullyQualifiedDomainName()); logger.infofmt("Enqueued refresh for domain %s", domain.getFullyQualifiedDomainName()); diff --git a/java/google/registry/flows/contact/ContactDeleteFlow.java b/java/google/registry/flows/contact/ContactDeleteFlow.java index 606e85bfc..9918fb9d5 100644 --- a/java/google/registry/flows/contact/ContactDeleteFlow.java +++ b/java/google/registry/flows/contact/ContactDeleteFlow.java @@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.googlecode.objectify.Key; +import com.googlecode.objectify.Ref; import google.registry.config.RegistryEnvironment; import google.registry.flows.EppException; @@ -33,7 +34,6 @@ import google.registry.model.contact.ContactCommand.Delete; import google.registry.model.contact.ContactResource; import google.registry.model.contact.ContactResource.Builder; import google.registry.model.domain.DomainBase; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.reporting.HistoryEntry; /** @@ -50,7 +50,7 @@ public class ContactDeleteFlow extends ResourceAsyncDeleteFlow ref) { + protected boolean isLinkedForFailfast(final Ref ref) { // Query for the first few linked domains, and if found, actually load them. The query is // eventually consistent and so might be very stale, but the direct load will not be stale, // just non-transactional. If we find at least one actual reference then we can reliably @@ -58,7 +58,7 @@ public class ContactDeleteFlow extends ResourceAsyncDeleteFlow() { @Override public boolean apply(DomainBase domain) { diff --git a/java/google/registry/flows/domain/BaseDomainCreateFlow.java b/java/google/registry/flows/domain/BaseDomainCreateFlow.java index dc5535cb8..2eac62cc8 100644 --- a/java/google/registry/flows/domain/BaseDomainCreateFlow.java +++ b/java/google/registry/flows/domain/BaseDomainCreateFlow.java @@ -20,7 +20,8 @@ import static google.registry.flows.domain.DomainFlowUtils.validateContactsHaveT import static google.registry.flows.domain.DomainFlowUtils.validateDomainName; import static google.registry.flows.domain.DomainFlowUtils.validateDomainNameWithIdnTables; import static google.registry.flows.domain.DomainFlowUtils.validateDsData; -import static google.registry.flows.domain.DomainFlowUtils.validateNameservers; +import static google.registry.flows.domain.DomainFlowUtils.validateNameserversAllowedOnTld; +import static google.registry.flows.domain.DomainFlowUtils.validateNameserversCount; import static google.registry.flows.domain.DomainFlowUtils.validateNoDuplicateContacts; import static google.registry.flows.domain.DomainFlowUtils.validateRegistrantAllowedOnTld; import static google.registry.flows.domain.DomainFlowUtils.validateRequiredContactsPresent; @@ -36,6 +37,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.registry.Registries.findTldForName; import static google.registry.model.registry.label.ReservedList.matchesAnchorTenantReservation; import static google.registry.pricing.PricingEngineProxy.getDomainCreateCost; +import static google.registry.util.CollectionUtils.nullToEmpty; import com.google.common.base.Optional; import com.google.common.net.InternetDomainName; @@ -67,6 +69,8 @@ import google.registry.model.tmch.ClaimsListShard; import org.joda.money.Money; +import java.util.Set; + import javax.annotation.Nullable; /** @@ -210,10 +214,13 @@ public abstract class BaseDomainCreateFlow fullyQualifiedHostNames = + nullToEmpty(command.getNameserverFullyQualifiedHostNames()); + validateNameserversCount(fullyQualifiedHostNames.size()); + validateNameserversAllowedOnTld(tld, fullyQualifiedHostNames); validateLaunchCreateExtension(); // If a signed mark was provided, then it must match the desired domain label. // We do this after validating the launch create extension so that flows which don't allow any diff --git a/java/google/registry/flows/domain/BaseDomainUpdateFlow.java b/java/google/registry/flows/domain/BaseDomainUpdateFlow.java index 9af81be68..98a72d8ad 100644 --- a/java/google/registry/flows/domain/BaseDomainUpdateFlow.java +++ b/java/google/registry/flows/domain/BaseDomainUpdateFlow.java @@ -20,7 +20,8 @@ import static google.registry.flows.domain.DomainFlowUtils.checkAllowedAccessToT import static google.registry.flows.domain.DomainFlowUtils.cloneAndLinkReferences; import static google.registry.flows.domain.DomainFlowUtils.validateContactsHaveTypes; import static google.registry.flows.domain.DomainFlowUtils.validateDsData; -import static google.registry.flows.domain.DomainFlowUtils.validateNameservers; +import static google.registry.flows.domain.DomainFlowUtils.validateNameserversAllowedOnTld; +import static google.registry.flows.domain.DomainFlowUtils.validateNameserversCount; import static google.registry.flows.domain.DomainFlowUtils.validateNoDuplicateContacts; import static google.registry.flows.domain.DomainFlowUtils.validateRegistrantAllowedOnTld; import static google.registry.flows.domain.DomainFlowUtils.validateRequiredContactsPresent; @@ -112,6 +113,10 @@ public abstract class BaseDomainUpdateFlow contacts, - ReferenceUnion registrant, - Set> nameservers) throws EppException { + Ref registrant, + Set> nameservers) throws EppException { for (DesignatedContact contact : nullToEmpty(contacts)) { - verifyNotInPendingDelete(contact.getContactId()); + verifyNotInPendingDelete(contact.getContactRef()); } if (registrant != null) { verifyNotInPendingDelete(registrant); } - for (ReferenceUnion host : nullToEmpty(nameservers)) { + for (Ref host : nullToEmpty(nameservers)) { verifyNotInPendingDelete(host); } } private static void verifyNotInPendingDelete( - ReferenceUnion resourceRef) throws EppException { + Ref resourceRef) throws EppException { - EppResource resource = resourceRef.getLinked().get(); + EppResource resource = resourceRef.get(); if (resource.getStatusValues().contains(StatusValue.PENDING_DELETE)) { throw new LinkedResourceInPendingDeleteProhibitsOperationException(resource.getForeignKey()); } @@ -280,28 +281,12 @@ public class DomainFlowUtils { } } - /** Return a foreign key for a {@link ReferenceUnion} from memory or datastore as needed. */ - private static String resolveForeignKey(ReferenceUnion ref) { - return ref.getForeignKey() != null - ? ref.getForeignKey() - : ref.getLinked().get().getForeignKey(); - } + static void validateNameserversCount(int count) throws EppException { + if (count > MAX_NAMESERVERS_PER_DOMAIN) { + throw new TooManyNameserversException(String.format( + "Only %d nameservers are allowed per domain", MAX_NAMESERVERS_PER_DOMAIN)); + } - static void validateNameservers(String tld, Set> nameservers) - throws EppException { - if (nameservers != null && nameservers.size() > MAX_NAMESERVERS_PER_DOMAIN) { - throw new TooManyNameserversException(String.format( - "Only %d nameservers are allowed per domain", MAX_NAMESERVERS_PER_DOMAIN)); - } - ImmutableSet whitelist = Registry.get(tld).getAllowedFullyQualifiedHostNames(); - if (!whitelist.isEmpty()) { // Empty whitelists are ignored. - for (ReferenceUnion nameserver : nullToEmpty(nameservers)) { - String foreignKey = resolveForeignKey(nameserver); - if (!whitelist.contains(foreignKey)) { - throw new NameserverNotAllowedException(foreignKey); - } - } - } } static void validateNoDuplicateContacts(Set contacts) @@ -315,8 +300,8 @@ public class DomainFlowUtils { } static void validateRequiredContactsPresent( - ReferenceUnion registrant, Set contacts) - throws RequiredParameterMissingException { + Ref registrant, Set contacts) + throws RequiredParameterMissingException { if (registrant == null) { throw new MissingRegistrantException(); } @@ -333,12 +318,24 @@ public class DomainFlowUtils { } } - static void validateRegistrantAllowedOnTld(String tld, ReferenceUnion registrant) + static void validateRegistrantAllowedOnTld(String tld, String registrantContactId) throws RegistrantNotAllowedException { ImmutableSet whitelist = Registry.get(tld).getAllowedRegistrantContactIds(); // Empty whitelists are ignored. - if (!whitelist.isEmpty() && !whitelist.contains(resolveForeignKey(registrant))) { - throw new RegistrantNotAllowedException(resolveForeignKey(registrant)); + if (!whitelist.isEmpty() && !whitelist.contains(registrantContactId)) { + throw new RegistrantNotAllowedException(registrantContactId); + } + } + + static void validateNameserversAllowedOnTld(String tld, Set fullyQualifiedHostNames) + throws EppException { + ImmutableSet whitelist = Registry.get(tld).getAllowedFullyQualifiedHostNames(); + if (whitelist.isEmpty()) { // Empty whitelists are ignored. + return; + } + Set disallowedNameservers = difference(nullToEmpty(fullyQualifiedHostNames), whitelist); + if (!disallowedNameservers.isEmpty()) { + throw new NameserversNotAllowedException(disallowedNameservers); } } @@ -1015,10 +1012,13 @@ public class DomainFlowUtils { } } - /** Nameserver is not whitelisted for this TLD. */ - public static class NameserverNotAllowedException extends StatusProhibitsOperationException { - public NameserverNotAllowedException(String fullyQualifiedHostName) { - super(String.format("Nameserver %s is not whitelisted for this TLD", fullyQualifiedHostName)); + /** Nameserver are not whitelisted for this TLD. */ + public static class NameserversNotAllowedException extends StatusProhibitsOperationException { + public NameserversNotAllowedException(Set fullyQualifiedHostNames) { + super(String.format( + "Nameservers '%s' are not whitelisted for this TLD", + Joiner.on(',').join(fullyQualifiedHostNames))); } } } + diff --git a/java/google/registry/flows/domain/DomainUpdateFlow.java b/java/google/registry/flows/domain/DomainUpdateFlow.java index 03c3a4890..d399c5441 100644 --- a/java/google/registry/flows/domain/DomainUpdateFlow.java +++ b/java/google/registry/flows/domain/DomainUpdateFlow.java @@ -61,7 +61,7 @@ import java.util.Set; * @error {@link DomainFlowUtils.MissingAdminContactException} * @error {@link DomainFlowUtils.MissingContactTypeException} * @error {@link DomainFlowUtils.MissingTechnicalContactException} - * @error {@link DomainFlowUtils.NameserverNotAllowedException} + * @error {@link DomainFlowUtils.NameserversNotAllowedException} * @error {@link DomainFlowUtils.RegistrantNotAllowedException} * @error {@link DomainFlowUtils.TooManyDsRecordsException} * @error {@link DomainFlowUtils.TooManyNameserversException} diff --git a/java/google/registry/flows/host/HostDeleteFlow.java b/java/google/registry/flows/host/HostDeleteFlow.java index fef0cb04e..586dae915 100644 --- a/java/google/registry/flows/host/HostDeleteFlow.java +++ b/java/google/registry/flows/host/HostDeleteFlow.java @@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.googlecode.objectify.Key; +import com.googlecode.objectify.Ref; import google.registry.config.RegistryEnvironment; import google.registry.flows.EppException; @@ -30,7 +31,6 @@ import google.registry.flows.async.AsyncFlowUtils; import google.registry.flows.async.DeleteEppResourceAction; import google.registry.flows.async.DeleteHostResourceAction; import google.registry.model.domain.DomainBase; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.host.HostCommand.Delete; import google.registry.model.host.HostResource; import google.registry.model.host.HostResource.Builder; @@ -50,7 +50,7 @@ public class HostDeleteFlow extends ResourceAsyncDeleteFlow ref) { + protected boolean isLinkedForFailfast(final Ref ref) { // Query for the first few linked domains, and if found, actually load them. The query is // eventually consistent and so might be very stale, but the direct load will not be stale, // just non-transactional. If we find at least one actual reference then we can reliably @@ -58,7 +58,7 @@ public class HostDeleteFlow extends ResourceAsyncDeleteFlow() { @Override public boolean apply(DomainBase domain) { diff --git a/java/google/registry/model/EppResourceUtils.java b/java/google/registry/model/EppResourceUtils.java index 314ac7722..f3eff50c7 100644 --- a/java/google/registry/model/EppResourceUtils.java +++ b/java/google/registry/model/EppResourceUtils.java @@ -36,7 +36,6 @@ import google.registry.model.EppResource.Builder; import google.registry.model.EppResource.ForeignKeyedEppResource; import google.registry.model.contact.ContactResource; import google.registry.model.domain.DomainBase; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.eppcommon.StatusValue; import google.registry.model.host.HostResource; import google.registry.model.index.ForeignKeyIndex; @@ -139,12 +138,12 @@ public final class EppResourceUtils { latestOf(now, resource.getUpdateAutoTimestamp().getTimestamp())); } - /** Loads returns the hosts specified by the given ReferenceUnions. */ + /** Loads and returns the hosts specified by the given reference. */ public static ImmutableSet loadReferencedNameservers( - Set> hostRefs) { + Set> hostRefs) { ImmutableSet.Builder builder = new ImmutableSet.Builder<>(); - for (ReferenceUnion hostRef : hostRefs) { - HostResource host = hostRef.getLinked().get(); + for (Ref hostRef : hostRefs) { + HostResource host = hostRef.get(); if (host != null) { builder.add(host); } @@ -152,12 +151,12 @@ public final class EppResourceUtils { return builder.build(); } - /** Loads and returns the contacts specified by the given ReferenceUnions. */ + /** Loads and returns the contacts specified by the given references. */ public static ImmutableSet loadReferencedContacts( - Set> contactRefs) { + Set> contactRefs) { ImmutableSet.Builder builder = new ImmutableSet.Builder<>(); - for (ReferenceUnion contactRef : contactRefs) { - builder.add(contactRef.getLinked().get()); + for (Ref contactRef : contactRefs) { + builder.add(contactRef.get()); } return builder.build(); } diff --git a/java/google/registry/model/domain/DesignatedContact.java b/java/google/registry/model/domain/DesignatedContact.java index 782ac025c..c53f15665 100644 --- a/java/google/registry/model/domain/DesignatedContact.java +++ b/java/google/registry/model/domain/DesignatedContact.java @@ -16,6 +16,7 @@ package google.registry.model.domain; import com.google.common.annotations.VisibleForTesting; +import com.googlecode.objectify.Ref; import com.googlecode.objectify.annotation.Embed; import com.googlecode.objectify.annotation.Index; @@ -50,10 +51,10 @@ public class DesignatedContact extends ImmutableObject { } @VisibleForTesting - public static DesignatedContact create(Type type, ReferenceUnion contact) { + public static DesignatedContact create(Type type, Ref contact) { DesignatedContact instance = new DesignatedContact(); instance.type = type; - instance.contactId = contact; + instance.contactId = ReferenceUnion.create(contact); return instance; } @@ -62,13 +63,14 @@ public class DesignatedContact extends ImmutableObject { @Index @XmlValue + //TODO(b/28713909): Make this a Ref. ReferenceUnion contactId; public Type getType() { return type; } - public ReferenceUnion getContactId() { - return contactId; + public Ref getContactRef() { + return contactId.getLinked(); } } diff --git a/java/google/registry/model/domain/DomainAuthInfo.java b/java/google/registry/model/domain/DomainAuthInfo.java index 35b40f1e7..5923a0abc 100644 --- a/java/google/registry/model/domain/DomainAuthInfo.java +++ b/java/google/registry/model/domain/DomainAuthInfo.java @@ -16,6 +16,7 @@ package google.registry.model.domain; import static com.google.common.base.Preconditions.checkNotNull; +import com.googlecode.objectify.Ref; import com.googlecode.objectify.annotation.Embed; import google.registry.model.EppResource; @@ -38,9 +39,9 @@ public class DomainAuthInfo extends AuthInfo { checkNotNull(getPw()); if (getRepoId() != null) { // Make sure the repo id matches one of the contacts on the domain. - ReferenceUnion foundContact = null; - for (ReferenceUnion contact : domain.getReferencedContacts()) { - String contactRepoId = contact.getLinked().getKey().getName(); + Ref foundContact = null; + for (Ref contact : domain.getReferencedContacts()) { + String contactRepoId = contact.getKey().getName(); if (getRepoId().equals(contactRepoId)) { foundContact = contact; break; @@ -50,7 +51,7 @@ public class DomainAuthInfo extends AuthInfo { throw new BadAuthInfoException(); } // Check if the password provided matches the password on the referenced contact. - if (!foundContact.getLinked().get().getAuthInfo().getPw().getValue().equals( + if (!foundContact.get().getAuthInfo().getPw().getValue().equals( getPw().getValue())) { throw new BadAuthInfoException(); } diff --git a/java/google/registry/model/domain/DomainBase.java b/java/google/registry/model/domain/DomainBase.java index d06f292cf..6cf47f713 100644 --- a/java/google/registry/model/domain/DomainBase.java +++ b/java/google/registry/model/domain/DomainBase.java @@ -19,6 +19,7 @@ import static com.google.common.base.Strings.isNullOrEmpty; import static com.google.common.collect.Sets.difference; import static com.google.common.collect.Sets.union; import static google.registry.model.domain.DesignatedContact.Type.REGISTRANT; +import static google.registry.util.CollectionUtils.nullToEmpty; import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy; import static google.registry.util.CollectionUtils.nullToEmptyImmutableSortedCopy; import static google.registry.util.CollectionUtils.union; @@ -27,6 +28,7 @@ import static google.registry.util.DomainNameUtils.getTldFromSld; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; +import com.googlecode.objectify.Ref; import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Ignore; import com.googlecode.objectify.annotation.IgnoreSave; @@ -74,6 +76,7 @@ public abstract class DomainBase extends EppResource { /** References to hosts that are the nameservers for the domain. */ @XmlElementWrapper(name = "ns") @XmlElement(name = "hostObj") + //TODO(b/28713909): Make this a Set>. Set> nameservers; /** @@ -102,6 +105,7 @@ public abstract class DomainBase extends EppResource { * both stored in {@link DomainBase#allContacts} to allow for more efficient queries. */ @Ignore + //TODO(b/28713909): Make this a Ref. ReferenceUnion registrant; /** Authorization info (aka transfer secret) of the domain. */ @@ -149,8 +153,12 @@ public abstract class DomainBase extends EppResource { return idnTableName; } - public ImmutableSet> getNameservers() { - return nullToEmptyImmutableCopy(nameservers); + public ImmutableSet> getNameservers() { + ImmutableSet.Builder> builder = new ImmutableSet.Builder<>(); + for (ReferenceUnion union : nullToEmptyImmutableCopy(nameservers)) { + builder.add(union.getLinked()); + } + return builder.build(); } /** Loads and returns all linked nameservers. */ @@ -158,12 +166,12 @@ public abstract class DomainBase extends EppResource { return EppResourceUtils.loadReferencedNameservers(getNameservers()); } - public ReferenceUnion getRegistrant() { - return registrant; + public Ref getRegistrant() { + return registrant == null ? null : registrant.getLinked(); } public ContactResource loadRegistrant() { - return registrant.getLinked().get(); + return getRegistrant().get(); } public ImmutableSet getContacts() { @@ -175,11 +183,11 @@ public abstract class DomainBase extends EppResource { } /** Returns all referenced contacts from this domain or application. */ - public ImmutableSet> getReferencedContacts() { - ImmutableSet.Builder> contactsBuilder = + public ImmutableSet> getReferencedContacts() { + ImmutableSet.Builder> contactsBuilder = new ImmutableSet.Builder<>(); for (DesignatedContact designated : nullToEmptyImmutableCopy(allContacts)) { - contactsBuilder.add(designated.getContactId()); + contactsBuilder.add(designated.getContactRef()); } return contactsBuilder.build(); } @@ -202,7 +210,7 @@ public abstract class DomainBase extends EppResource { ImmutableSet.Builder contactsBuilder = new ImmutableSet.Builder<>(); for (DesignatedContact contact : nullToEmptyImmutableCopy(allContacts)) { if (REGISTRANT.equals(contact.getType())){ - registrant = contact.getContactId(); + registrant = ReferenceUnion.create(contact.getContactRef()); } else { contactsBuilder.add(contact); } @@ -229,8 +237,11 @@ public abstract class DomainBase extends EppResource { checkState( !isNullOrEmpty(instance.fullyQualifiedDomainName), "Missing fullyQualifiedDomainName"); instance.tld = getTldFromSld(instance.fullyQualifiedDomainName); - instance.allContacts = instance.registrant == null ? instance.contacts : union( - instance.getContacts(), DesignatedContact.create(REGISTRANT, instance.registrant)); + instance.allContacts = instance.registrant == null + ? instance.contacts + : union( + instance.getContacts(), + DesignatedContact.create(REGISTRANT, instance.registrant.getLinked())); return super.build(); } @@ -244,8 +255,8 @@ public abstract class DomainBase extends EppResource { return thisCastToDerived(); } - public B setRegistrant(ReferenceUnion registrant) { - getInstance().registrant = registrant; + public B setRegistrant(Ref registrant) { + getInstance().registrant = ReferenceUnion.create(registrant); return thisCastToDerived(); } @@ -254,17 +265,21 @@ public abstract class DomainBase extends EppResource { return thisCastToDerived(); } - public B setNameservers(ImmutableSet> nameservers) { - getInstance().nameservers = nameservers; + public B setNameservers(ImmutableSet> nameservers) { + ImmutableSet.Builder> builder = new ImmutableSet.Builder<>(); + for (Ref ref : nullToEmpty(nameservers)) { + builder.add(ReferenceUnion.create(ref)); + } + getInstance().nameservers = builder.build(); return thisCastToDerived(); } - public B addNameservers(ImmutableSet> nameservers) { + public B addNameservers(ImmutableSet> nameservers) { return setNameservers( ImmutableSet.copyOf(union(getInstance().getNameservers(), nameservers))); } - public B removeNameservers(ImmutableSet> nameservers) { + public B removeNameservers(ImmutableSet> nameservers) { return setNameservers( ImmutableSet.copyOf(difference(getInstance().getNameservers(), nameservers))); } diff --git a/java/google/registry/model/domain/DomainCommand.java b/java/google/registry/model/domain/DomainCommand.java index 172ce537d..07af484a5 100644 --- a/java/google/registry/model/domain/DomainCommand.java +++ b/java/google/registry/model/domain/DomainCommand.java @@ -74,12 +74,25 @@ public class DomainCommand { public static class DomainCreateOrChange> extends ImmutableObject implements ResourceCreateOrChange { - /** A reference to the registrant who registered this domain. */ - ReferenceUnion registrant; + /** The contactId of the registrant who registered this domain. */ + @XmlElement(name = "registrant") + String registrantContactId; + + /** A resolved reference to the registrant who registered this domain. */ + @XmlTransient + Ref registrant; /** Authorization info (aka transfer secret) of the domain. */ DomainAuthInfo authInfo; + public String getRegistrantContactId() { + return registrantContactId; + } + + public Ref getRegistrant() { + return registrant; + } + @Override public void applyTo(B builder) { if (registrant != null) { @@ -97,7 +110,12 @@ public class DomainCommand { */ @XmlRootElement @XmlType(propOrder = { - "fullyQualifiedDomainName", "period", "nameservers", "registrant", "contacts", "authInfo" }) + "fullyQualifiedDomainName", + "period", + "nameserverFullyQualifiedHostNames", + "registrantContactId", + "foreignKeyedDesignatedContacts", + "authInfo"}) public static class Create extends DomainCreateOrChange> implements CreateOrUpdate { @@ -106,13 +124,21 @@ public class DomainCommand { @XmlElement(name = "name") String fullyQualifiedDomainName; - /** References to hosts that are the nameservers for the domain. */ + /** Fully qualified host names of the hosts that are the nameservers for the domain. */ @XmlElementWrapper(name = "ns") @XmlElement(name = "hostObj") - Set> nameservers; + Set nameserverFullyQualifiedHostNames; - /** Associated contacts for the domain (other than registrant). */ + /** Resolved references to hosts that are the nameservers for the domain. */ + @XmlTransient + Set> nameservers; + + /** Foreign keyed associated contacts for the domain (other than registrant). */ @XmlElement(name = "contact") + Set foreignKeyedDesignatedContacts; + + /** Resolved references to associated contacts for the domain (other than registrant). */ + @XmlTransient Set contacts; /** The period that this domain's state was set to last for (e.g. 1-10 years). */ @@ -131,7 +157,11 @@ public class DomainCommand { return fullyQualifiedDomainName; } - public ImmutableSet> getNameservers() { + public ImmutableSet getNameserverFullyQualifiedHostNames() { + return nullSafeImmutableCopy(nameserverFullyQualifiedHostNames); + } + + public ImmutableSet> getNameservers() { return nullSafeImmutableCopy(nameservers); } @@ -139,11 +169,7 @@ public class DomainCommand { return nullSafeImmutableCopy(contacts); } - public ReferenceUnion getRegistrant() { - return registrant; - } - - @Override + @Override public AuthInfo getAuthInfo() { return authInfo; } @@ -166,10 +192,10 @@ public class DomainCommand { @Override public Create cloneAndLinkReferences(DateTime now) throws InvalidReferenceException { Create clone = clone(this); - clone.nameservers = linkHosts(clone.nameservers, now); - clone.contacts = linkContacts(clone.contacts, now); - clone.registrant = clone.registrant == null - ? null : linkReference(clone.registrant, ContactResource.class, now); + clone.nameservers = linkHosts(clone.nameserverFullyQualifiedHostNames, now); + clone.contacts = linkContacts(clone.foreignKeyedDesignatedContacts, now); + clone.registrant = clone.registrantContactId == null + ? null : loadReference(clone.registrantContactId, ContactResource.class, now); return clone; } } @@ -317,18 +343,33 @@ public class DomainCommand { } /** The inner change type on a domain update command. */ - @XmlType(propOrder = {"nameservers", "contacts", "statusValues"}) + @XmlType(propOrder = { + "nameserverFullyQualifiedHostNames", + "foreignKeyedDesignatedContacts", + "statusValues"}) public static class AddRemove extends ResourceUpdate.AddRemove { - /** References to hosts that are the nameservers for the domain. */ + /** Fully qualified host names of the hosts that are the nameservers for the domain. */ @XmlElementWrapper(name = "ns") @XmlElement(name = "hostObj") - Set> nameservers; + Set nameserverFullyQualifiedHostNames; - /** Associated contacts for the domain. */ + /** Resolved references to hosts that are the nameservers for the domain. */ + @XmlTransient + Set> nameservers; + + /** Foreign keyed associated contacts for the domain (other than registrant). */ @XmlElement(name = "contact") + Set foreignKeyedDesignatedContacts; + + /** Resolved references to associated contacts for the domain (other than registrant). */ + @XmlTransient Set contacts; - public ImmutableSet> getNameservers() { + public ImmutableSet getNameserverFullyQualifiedHostNames() { + return nullSafeImmutableCopy(nameserverFullyQualifiedHostNames); + } + + public ImmutableSet> getNameservers() { return nullToEmptyImmutableCopy(nameservers); } @@ -339,25 +380,20 @@ public class DomainCommand { /** Creates a copy of this {@link AddRemove} with hard links to hosts and contacts. */ private AddRemove cloneAndLinkReferences(DateTime now) throws InvalidReferenceException { AddRemove clone = clone(this); - clone.nameservers = linkHosts(clone.nameservers, now); - clone.contacts = linkContacts(clone.contacts, now); + clone.nameservers = linkHosts(clone.nameserverFullyQualifiedHostNames, now); + clone.contacts = linkContacts(clone.foreignKeyedDesignatedContacts, now); return clone; } } /** The inner change type on a domain update command. */ - @XmlType(propOrder = {"registrant", "authInfo"}) + @XmlType(propOrder = {"registrantContactId", "authInfo"}) public static class Change extends DomainCreateOrChange> { - - public ReferenceUnion getRegistrant() { - return registrant; - } - /** Creates a copy of this {@link Change} with hard links to hosts and contacts. */ Change cloneAndLinkReferences(DateTime now) throws InvalidReferenceException { Change clone = clone(this); - clone.registrant = clone.registrant == null - ? null : linkReference(clone.registrant, ContactResource.class, now); + clone.registrant = clone.registrantContactId == null + ? null : loadReference(clone.registrantContactId, ContactResource.class, now); return clone; } } @@ -396,50 +432,59 @@ public class DomainCommand { } } - private static Set> linkHosts( - Set> hosts, - DateTime now) throws InvalidReferenceException { - if (hosts == null) { + private static Set> linkHosts( + Set fullyQualifiedHostNames, DateTime now) throws InvalidReferenceException { + if (fullyQualifiedHostNames == null) { return null; } - ImmutableSet.Builder> linked = new ImmutableSet.Builder<>(); - for (ReferenceUnion host : hosts) { - linked.add(linkReference(host, HostResource.class, now)); + ImmutableSet.Builder> linked = new ImmutableSet.Builder<>(); + for (String fullyQualifiedHostName : fullyQualifiedHostNames) { + linked.add(loadReference(fullyQualifiedHostName, HostResource.class, now)); } return linked.build(); } private static Set linkContacts( - Set contacts, DateTime now) throws InvalidReferenceException { + Set contacts, DateTime now) throws InvalidReferenceException { if (contacts == null) { return null; } ImmutableSet.Builder linkedContacts = new ImmutableSet.Builder<>(); - for (DesignatedContact contact : contacts) { + for (ForeignKeyedDesignatedContact contact : contacts) { linkedContacts.add(DesignatedContact.create( - contact.getType(), - linkReference(contact.getContactId(), ContactResource.class, now))); + contact.type, loadReference(contact.contactId, ContactResource.class, now))); } return linkedContacts.build(); } - /** Turn a foreign-keyed {@link ReferenceUnion} into a linked one. */ - private static ReferenceUnion linkReference( - final ReferenceUnion reference, final Class clazz, final DateTime now) + /** Load a reference to a resource by its foreign key. */ + private static Ref loadReference( + final String foreignKey, final Class clazz, final DateTime now) throws InvalidReferenceException { - if (reference.getForeignKey() == null) { - return reference; - } Ref ref = ofy().doTransactionless(new Work>() { @Override public Ref run() { - return loadAndGetReference(clazz, reference.getForeignKey(), now); + return loadAndGetReference(clazz, foreignKey, now); } }); if (ref == null) { - throw new InvalidReferenceException(clazz, reference.getForeignKey()); + throw new InvalidReferenceException(clazz, foreignKey); } - return ReferenceUnion.create(ref); + return ref; + } + + /** + * EPP-inputable version of XML type for contact identifiers associated with a domain, which can + * be converted to a storable (and EPP-outputable) {@link DesignatedContact}. + * + * @see "http://tools.ietf.org/html/rfc5731#section-2.2" + */ + static class ForeignKeyedDesignatedContact extends ImmutableObject { + @XmlAttribute(required = true) + DesignatedContact.Type type; + + @XmlValue + String contactId; } /** Exception to throw when a referenced object does not exist. */ diff --git a/java/google/registry/model/domain/ReferenceUnion.java b/java/google/registry/model/domain/ReferenceUnion.java index 50caed2e0..336489d1d 100644 --- a/java/google/registry/model/domain/ReferenceUnion.java +++ b/java/google/registry/model/domain/ReferenceUnion.java @@ -16,7 +16,6 @@ package google.registry.model.domain; import com.googlecode.objectify.Ref; import com.googlecode.objectify.annotation.Embed; -import com.googlecode.objectify.annotation.Ignore; import com.googlecode.objectify.annotation.Index; import google.registry.model.EppResource; @@ -24,81 +23,50 @@ import google.registry.model.ImmutableObject; import google.registry.model.contact.ContactResource; import google.registry.model.host.HostResource; -import java.io.Serializable; - import javax.xml.bind.annotation.adapters.XmlAdapter; /** - * A "union" type to represent referenced objects as either a foreign key or as a link to another - * object in the datastore. + * Legacy shell of a "union" type to represent referenced objects as either a foreign key or as a + * link to another object in the datastore. In its current form it merely wraps a {@link Ref}. *

- * This type always marshals as the "foreign key". When it is explicitly storing a foreign key it - * gets the value from its own string field. When it is linked to another object, it gets the value - * from the other object. - *

- * When a {@link ReferenceUnion} comes in from Epp, either in an update or a delete, it fills in the - * "foreign key" string field, but as soon as the relevant Flow runs it deletes that field and - * replaces it with a linked {@link Ref} to the object named by that string. We can't do this in a - * {@code XmlJavaTypeAdapter} because failing a lookup is a business logic error, not a failure to - * parse the XML. + * This type always marshals as the "foreign key". We no longer use this type for unmarshalling. * * @param the type being referenced */ @Embed -public class ReferenceUnion extends ImmutableObject implements Serializable { +public class ReferenceUnion extends ImmutableObject { @Index Ref linked; - /** This is never persisted, and only ever populated to marshal or unmarshal to or from XML. */ - @Ignore - String foreignKey; - public Ref getLinked() { return linked; } - public String getForeignKey() { - return foreignKey; - } - - /** An adapter that is aware of the union inside {@link ReferenceUnion}. */ + /** An adapter that marshals the linked {@link Ref} as its loaded foreign key. */ public static class Adapter extends XmlAdapter> { @Override public ReferenceUnion unmarshal(String foreignKey) throws Exception { - return ReferenceUnion.create(foreignKey); + throw new UnsupportedOperationException(); } @Override public String marshal(ReferenceUnion reference) throws Exception { - return reference.getForeignKey() == null - ? reference.getLinked().get().getForeignKey() - : reference.getForeignKey(); + return reference.getLinked().get().getForeignKey(); } } /** An adapter for references to contacts. */ - static class ContactReferenceUnionAdapter extends ReferenceUnion.Adapter{} + static class ContactReferenceUnionAdapter extends Adapter{} /** An adapter for references to hosts. */ - static class HostReferenceUnionAdapter extends ReferenceUnion.Adapter{} - - public static ReferenceUnion create(String foreignKey) { - ReferenceUnion instance = new ReferenceUnion<>(); - instance.foreignKey = foreignKey; - return instance; - } + static class HostReferenceUnionAdapter extends Adapter{} public static ReferenceUnion create(Ref linked) { ReferenceUnion instance = new ReferenceUnion<>(); instance.linked = linked; return instance; } - - /** Convenience method. */ - public static ReferenceUnion create(T resource) { - return create(Ref.create(resource)); - } } diff --git a/java/google/registry/monitoring/whitebox/VerifyEntityIntegrityAction.java b/java/google/registry/monitoring/whitebox/VerifyEntityIntegrityAction.java index 65baf7681..d92b5b678 100644 --- a/java/google/registry/monitoring/whitebox/VerifyEntityIntegrityAction.java +++ b/java/google/registry/monitoring/whitebox/VerifyEntityIntegrityAction.java @@ -50,7 +50,6 @@ import google.registry.model.domain.DomainApplication; import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainResource; import google.registry.model.domain.GracePeriod; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.host.HostResource; import google.registry.model.index.DomainApplicationIndex; import google.registry.model.index.EppResourceIndex; @@ -246,8 +245,8 @@ public class VerifyEntityIntegrityAction implements Runnable { if (resource instanceof DomainBase) { DomainBase domainBase = (DomainBase) resource; Key key = Key.create(domainBase); - verifyExistence(key, bustUnions(domainBase.getReferencedContacts())); - verifyExistence(key, bustUnions(domainBase.getNameservers())); + verifyExistence(key, refsToKeys(domainBase.getReferencedContacts())); + verifyExistence(key, refsToKeys(domainBase.getNameservers())); verifyExistence(key, domainBase.getTransferData().getServerApproveAutorenewEvent()); verifyExistence(key, domainBase.getTransferData().getServerApproveAutorenewPollMessage()); verifyExistence(key, domainBase.getTransferData().getServerApproveBillingEvent()); @@ -386,14 +385,13 @@ public class VerifyEntityIntegrityAction implements Runnable { return entity; } - private static Set> bustUnions( - Iterable> unions) { + private static ImmutableSet> refsToKeys(Iterable> refs) { return FluentIterable - .from(unions) - .transform(new Function, Key>() { + .from(refs) + .transform(new Function, Key>() { @Override - public Key apply(ReferenceUnion union) { - return union.getLinked().getKey(); + public Key apply(Ref ref) { + return ref.getKey(); }}) .toSet(); } diff --git a/java/google/registry/rdap/RdapJsonFormatter.java b/java/google/registry/rdap/RdapJsonFormatter.java index cfe7db3ed..a983d27c0 100644 --- a/java/google/registry/rdap/RdapJsonFormatter.java +++ b/java/google/registry/rdap/RdapJsonFormatter.java @@ -39,7 +39,6 @@ import google.registry.model.contact.PostalInfo; import google.registry.model.domain.DesignatedContact; import google.registry.model.domain.DesignatedContact.Type; import google.registry.model.domain.DomainResource; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.eppcommon.Address; import google.registry.model.eppcommon.StatusValue; import google.registry.model.host.HostResource; @@ -398,11 +397,7 @@ public class RdapJsonFormatter { @Nullable String linkBase, @Nullable String whoisServer) { // Kick off the database loads of the nameservers that we will need. - Set> hostRefs = new LinkedHashSet<>(); - for (ReferenceUnion hostReference : domainResource.getNameservers()) { - hostRefs.add(hostReference.getLinked()); - } - Map, HostResource> loadedHosts = ofy().load().refs(hostRefs); + ImmutableSet loadedHosts = domainResource.loadNameservers(); // And the registrant and other contacts. List allContacts = new ArrayList<>(); if (domainResource.getRegistrant() != null) { @@ -411,7 +406,7 @@ public class RdapJsonFormatter { allContacts.addAll(domainResource.getContacts()); Set> contactRefs = new LinkedHashSet<>(); for (DesignatedContact designatedContact : allContacts) { - contactRefs.add(designatedContact.getContactId().getLinked()); + contactRefs.add(designatedContact.getContactRef()); } Map, ContactResource> loadedContacts = ofy().load().refs(contactRefs); // Now, assemble the results, using the loaded objects as needed. @@ -432,8 +427,7 @@ public class RdapJsonFormatter { } // Nameservers ImmutableList.Builder nsBuilder = new ImmutableList.Builder<>(); - for (HostResource hostResource - : HOST_RESOURCE_ORDERING.immutableSortedCopy(loadedHosts.values())) { + for (HostResource hostResource : HOST_RESOURCE_ORDERING.immutableSortedCopy(loadedHosts)) { nsBuilder.add(makeRdapJsonForHost(hostResource, false, linkBase, null)); } ImmutableList ns = nsBuilder.build(); @@ -445,7 +439,7 @@ public class RdapJsonFormatter { for (DesignatedContact designatedContact : DESIGNATED_CONTACT_ORDERING.immutableSortedCopy(allContacts)) { ContactResource loadedContact = - loadedContacts.get(designatedContact.getContactId().getLinked().key()); + loadedContacts.get(designatedContact.getContactRef().key()); entitiesBuilder.add(makeRdapJsonForContact( loadedContact, false, Optional.of(designatedContact.getType()), linkBase, null)); } diff --git a/java/google/registry/rde/DomainResourceToXjcConverter.java b/java/google/registry/rde/DomainResourceToXjcConverter.java index 314c76942..1ee593aa9 100644 --- a/java/google/registry/rde/DomainResourceToXjcConverter.java +++ b/java/google/registry/rde/DomainResourceToXjcConverter.java @@ -17,10 +17,11 @@ package google.registry.rde; import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; +import com.googlecode.objectify.Ref; + import google.registry.model.contact.ContactResource; import google.registry.model.domain.DesignatedContact; import google.registry.model.domain.DomainResource; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.eppcommon.StatusValue; @@ -163,9 +164,9 @@ final class DomainResourceToXjcConverter { // o An OPTIONAL element that contain the identifier for // the human or organizational social information object associated // as the holder of the domain name object. - ReferenceUnion registrant = model.getRegistrant(); + Ref registrant = model.getRegistrant(); if (registrant != null) { - bean.setRegistrant(registrant.getLinked().get().getContactId()); + bean.setRegistrant(registrant.get().getContactId()); } // o Zero or more OPTIONAL elements that contain identifiers @@ -282,7 +283,7 @@ final class DomainResourceToXjcConverter { /** Converts {@link DesignatedContact} to {@link XjcDomainContactType}. */ private static XjcDomainContactType convertDesignatedContact(DesignatedContact model) { XjcDomainContactType bean = new XjcDomainContactType(); - ContactResource contact = model.getContactId().getLinked().get(); + ContactResource contact = model.getContactRef().get(); bean.setType(XjcDomainContactAttrType.fromValue(model.getType().toString().toLowerCase())); bean.setValue(contact.getContactId()); return bean; diff --git a/java/google/registry/tools/AllocateDomainCommand.java b/java/google/registry/tools/AllocateDomainCommand.java index dc0356359..a9ef9209a 100644 --- a/java/google/registry/tools/AllocateDomainCommand.java +++ b/java/google/registry/tools/AllocateDomainCommand.java @@ -140,7 +140,7 @@ final class AllocateDomainCommand extends MutatingEppToolCommand { for (DesignatedContact contact : application.getContacts()) { contactsMapBuilder.put( contact.getType().toString().toLowerCase(), - contact.getContactId().getLinked().get().getForeignKey()); + contact.getContactRef().get().getForeignKey()); } LaunchNotice launchNotice = application.getLaunchNotice(); addSoyRecord(application.getCurrentSponsorClientId(), new SoyMapData( diff --git a/java/google/registry/tools/UniformRapidSuspensionCommand.java b/java/google/registry/tools/UniformRapidSuspensionCommand.java index aafe094cc..27577435e 100644 --- a/java/google/registry/tools/UniformRapidSuspensionCommand.java +++ b/java/google/registry/tools/UniformRapidSuspensionCommand.java @@ -27,9 +27,9 @@ import com.google.template.soy.data.SoyMapData; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; +import com.googlecode.objectify.Ref; import google.registry.model.domain.DomainResource; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.eppcommon.StatusValue; import google.registry.model.host.HostResource; import google.registry.tools.Command.GtechCommand; @@ -113,8 +113,8 @@ final class UniformRapidSuspensionCommand extends MutatingEppToolCommand impleme private ImmutableSortedSet getExistingNameservers(DomainResource domain) { ImmutableSortedSet.Builder nameservers = ImmutableSortedSet.naturalOrder(); - for (ReferenceUnion nameserverRef : domain.getNameservers()) { - nameservers.add(nameserverRef.getLinked().get().getForeignKey()); + for (Ref nameserverRef : domain.getNameservers()) { + nameservers.add(nameserverRef.get().getForeignKey()); } return nameservers.build(); } diff --git a/java/google/registry/tools/server/GenerateZoneFilesAction.java b/java/google/registry/tools/server/GenerateZoneFilesAction.java index 0861675e1..da4996cb6 100644 --- a/java/google/registry/tools/server/GenerateZoneFilesAction.java +++ b/java/google/registry/tools/server/GenerateZoneFilesAction.java @@ -16,7 +16,6 @@ package google.registry.tools.server; import static com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService; import static com.google.common.base.Predicates.notNull; -import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Iterators.filter; import static com.google.common.io.BaseEncoding.base16; import static google.registry.mapreduce.inputs.EppResourceInputs.createEntityInput; @@ -38,15 +37,12 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.googlecode.objectify.Ref; - import google.registry.config.ConfigModule.Config; import google.registry.gcs.GcsUtils; import google.registry.mapreduce.MapreduceRunner; import google.registry.mapreduce.inputs.NullInput; import google.registry.model.EppResource; import google.registry.model.domain.DomainResource; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.host.HostResource; import google.registry.request.Action; @@ -280,14 +276,7 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA */ private static String domainStanza(DomainResource domain, DateTime exportTime) { StringBuilder result = new StringBuilder(); - for (HostResource nameserver : ofy().load().refs( - transform( - domain.getNameservers(), - new Function, Ref>() { - @Override - public Ref apply(ReferenceUnion referenceUnion) { - return referenceUnion.getLinked(); - }})).values()) { + for (HostResource nameserver : ofy().load().refs(domain.getNameservers()).values()) { result.append(String.format( NS_FORMAT, domain.getFullyQualifiedDomainName(), diff --git a/java/google/registry/whois/DomainWhoisResponse.java b/java/google/registry/whois/DomainWhoisResponse.java index 09cd553b3..a89b740ad 100644 --- a/java/google/registry/whois/DomainWhoisResponse.java +++ b/java/google/registry/whois/DomainWhoisResponse.java @@ -24,6 +24,8 @@ import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; +import com.googlecode.objectify.Ref; + import google.registry.model.contact.ContactPhoneNumber; import google.registry.model.contact.ContactResource; import google.registry.model.contact.PostalInfo; @@ -31,7 +33,6 @@ import google.registry.model.domain.DesignatedContact; import google.registry.model.domain.DesignatedContact.Type; import google.registry.model.domain.DomainResource; import google.registry.model.domain.GracePeriod; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.eppcommon.StatusValue; import google.registry.model.host.HostResource; import google.registry.model.registrar.Registrar; @@ -103,14 +104,14 @@ final class DomainWhoisResponse extends WhoisResponseImpl { /** Returns the contact of the given type, or null if it does not exist. */ @Nullable - private ReferenceUnion getContactReference(final Type type) { + private Ref getContactReference(final Type type) { Optional contactOfType = tryFind(domain.getContacts(), new Predicate() { @Override public boolean apply(DesignatedContact d) { return d.getType() == type; }}); - return contactOfType.isPresent() ? contactOfType.get().getContactId() : null; + return contactOfType.isPresent() ? contactOfType.get().getContactRef() : null; } /** Output emitter with logic for domains. */ @@ -126,7 +127,7 @@ final class DomainWhoisResponse extends WhoisResponseImpl { /** Emit the contact entry of the given type. */ DomainEmitter emitContact( String contactType, - @Nullable ReferenceUnion contact, + @Nullable Ref contact, boolean preferUnicode) { if (contact == null) { return this; @@ -134,10 +135,10 @@ final class DomainWhoisResponse extends WhoisResponseImpl { // If we refer to a contact that doesn't exist, that's a bug. It means referential integrity // has somehow been broken. We skip the rest of this contact, but log it to hopefully bring it // someone's attention. - ContactResource contactResource = contact.getLinked().get(); + ContactResource contactResource = contact.get(); if (contactResource == null) { logger.severefmt("(BUG) Broken reference found from domain %s to contact %s", - domain.getFullyQualifiedDomainName(), contact.getLinked()); + domain.getFullyQualifiedDomainName(), contact); return this; } emitField(contactType, "ID", contactResource.getContactId()); diff --git a/javatests/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java b/javatests/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java index 2a2fc121b..8feb11760 100644 --- a/javatests/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java +++ b/javatests/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java @@ -32,8 +32,9 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.net.InetAddresses; +import com.googlecode.objectify.Ref; + import google.registry.model.domain.DomainResource; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.eppcommon.StatusValue; import google.registry.model.host.HostResource; @@ -109,8 +110,7 @@ public class DnsUpdateWriterTest { DomainResource domain = persistActiveDomain("example.tld") .asBuilder() - .setNameservers( - ImmutableSet.of(ReferenceUnion.create(host1), ReferenceUnion.create(host2))) + .setNameservers(ImmutableSet.of(Ref.create(host1), Ref.create(host2))) .build(); persistResource(domain); @@ -129,8 +129,7 @@ public class DnsUpdateWriterTest { DomainResource domain = persistActiveDomain("example.tld") .asBuilder() - .setNameservers( - ImmutableSet.of(ReferenceUnion.create(persistActiveHost("ns1.example.tld")))) + .setNameservers(ImmutableSet.of(Ref.create(persistActiveHost("ns1.example.tld")))) .setDsData( ImmutableSet.of( DelegationSignerData.create(1, 3, 1, base16().decode("0123456789ABCDEF")))) @@ -154,8 +153,7 @@ public class DnsUpdateWriterTest { persistActiveDomain("example.tld") .asBuilder() .addStatusValue(StatusValue.SERVER_HOLD) - .setNameservers( - ImmutableSet.of(ReferenceUnion.create(persistActiveHost("ns1.example.tld")))) + .setNameservers(ImmutableSet.of(Ref.create(persistActiveHost("ns1.example.tld")))) .build(); persistResource(domain); @@ -223,8 +221,7 @@ public class DnsUpdateWriterTest { DomainResource domain = persistActiveDomain("example.tld") .asBuilder() - .setNameservers( - ImmutableSet.of(ReferenceUnion.create(persistActiveHost("ns1.example.tld")))) + .setNameservers(ImmutableSet.of(Ref.create(persistActiveHost("ns1.example.tld")))) .build(); persistResource(domain); when(mockResolver.send(any(Message.class))).thenReturn(messageWithResponseCode(Rcode.SERVFAIL)); diff --git a/javatests/google/registry/flows/async/DeleteContactResourceActionTest.java b/javatests/google/registry/flows/async/DeleteContactResourceActionTest.java index d1f6f89d3..b076f15cb 100644 --- a/javatests/google/registry/flows/async/DeleteContactResourceActionTest.java +++ b/javatests/google/registry/flows/async/DeleteContactResourceActionTest.java @@ -40,7 +40,6 @@ import google.registry.model.contact.ContactPhoneNumber; import google.registry.model.contact.ContactResource; import google.registry.model.contact.PostalInfo; import google.registry.model.domain.DomainResource; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppcommon.Trid; import google.registry.model.poll.PendingActionNotificationResponse; @@ -79,8 +78,7 @@ public class DeleteContactResourceActionTest assertAboutContacts().that(contactUsed).doesNotHaveStatusValue(StatusValue.PENDING_DELETE) .and().hasDeletionTime(END_OF_TIME); domain = loadByUniqueId(DomainResource.class, "example.tld", now); - assertThat(domain.getReferencedContacts()) - .contains(ReferenceUnion.create(Ref.create(contactUsed))); + assertThat(domain.getReferencedContacts()).contains(Ref.create(contactUsed)); HistoryEntry historyEntry = getOnlyHistoryEntryOfType(contactUsed, HistoryEntry.Type.CONTACT_DELETE_FAILURE); assertPollMessageFor( diff --git a/javatests/google/registry/flows/async/DeleteEppResourceActionTestCase.java b/javatests/google/registry/flows/async/DeleteEppResourceActionTestCase.java index c15f33364..71f1c1f03 100644 --- a/javatests/google/registry/flows/async/DeleteEppResourceActionTestCase.java +++ b/javatests/google/registry/flows/async/DeleteEppResourceActionTestCase.java @@ -29,11 +29,11 @@ import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; +import com.googlecode.objectify.Ref; import google.registry.mapreduce.MapreduceRunner; import google.registry.model.contact.ContactResource; import google.registry.model.domain.DomainResource; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.host.HostResource; import google.registry.model.ofy.Ofy; import google.registry.model.poll.PollMessage; @@ -84,7 +84,7 @@ public abstract class DeleteEppResourceActionTestCasecreate(Ref.create(hostUsed))); + assertThat(domain.getNameservers()).contains(Ref.create(hostUsed)); HistoryEntry historyEntry = getOnlyHistoryEntryOfType(hostUsed, HistoryEntry.Type.HOST_DELETE_FAILURE); assertPollMessageFor( diff --git a/javatests/google/registry/flows/async/DnsRefreshForHostRenameActionTest.java b/javatests/google/registry/flows/async/DnsRefreshForHostRenameActionTest.java index ed52f57f3..49f9b4014 100644 --- a/javatests/google/registry/flows/async/DnsRefreshForHostRenameActionTest.java +++ b/javatests/google/registry/flows/async/DnsRefreshForHostRenameActionTest.java @@ -30,10 +30,10 @@ import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; +import com.googlecode.objectify.Ref; import google.registry.dns.DnsQueue; import google.registry.mapreduce.MapreduceRunner; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.host.HostResource; import google.registry.request.HttpException.BadRequestException; import google.registry.testing.ExceptionRule; @@ -77,21 +77,21 @@ public class DnsRefreshForHostRenameActionTest @Test public void testSuccess_dnsUpdateEnqueued() throws Exception { createTld("tld"); - HostResource renamedHost = persistActiveHost("ns1.example.tld"); - HostResource otherHost = persistActiveHost("ns2.example.tld"); + Ref renamedHostRef = Ref.create(persistActiveHost("ns1.example.tld")); + Ref otherHostRef = Ref.create(persistActiveHost("ns2.example.tld")); persistResource(newDomainApplication("notadomain.tld").asBuilder() - .setNameservers(ImmutableSet.of(ReferenceUnion.create(renamedHost))) + .setNameservers(ImmutableSet.of(renamedHostRef)) .build()); persistResource(newDomainResource("example.tld").asBuilder() - .setNameservers(ImmutableSet.of(ReferenceUnion.create(renamedHost))) + .setNameservers(ImmutableSet.of(renamedHostRef)) .build()); persistResource(newDomainResource("otherexample.tld").asBuilder() - .setNameservers(ImmutableSet.of(ReferenceUnion.create(renamedHost))) + .setNameservers(ImmutableSet.of(renamedHostRef)) .build()); persistResource(newDomainResource("untouched.tld").asBuilder() - .setNameservers(ImmutableSet.of(ReferenceUnion.create(otherHost))) + .setNameservers(ImmutableSet.of(otherHostRef)) .build()); - runMapreduce(Key.create(renamedHost).getString()); + runMapreduce(renamedHostRef.getKey().getString()); verify(dnsQueue).addDomainRefreshTask("example.tld"); verify(dnsQueue).addDomainRefreshTask("otherexample.tld"); verifyNoMoreInteractions(dnsQueue); @@ -100,12 +100,12 @@ public class DnsRefreshForHostRenameActionTest @Test public void testSuccess_noDnsTasksForDeletedDomain() throws Exception { createTld("tld"); - HostResource renamedHost = persistActiveHost("ns1.example.tld"); + Ref renamedHostRef = Ref.create(persistActiveHost("ns1.example.tld")); persistResource(newDomainResource("example.tld").asBuilder() - .setNameservers(ImmutableSet.of(ReferenceUnion.create(renamedHost))) + .setNameservers(ImmutableSet.of(renamedHostRef)) .setDeletionTime(START_OF_TIME) .build()); - runMapreduce(Key.create(renamedHost).getString()); + runMapreduce(renamedHostRef.getKey().getString()); verifyZeroInteractions(dnsQueue); } diff --git a/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java index 4d218ed4b..d7de23697 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java @@ -79,7 +79,7 @@ import google.registry.flows.domain.DomainFlowUtils.LaunchPhaseMismatchException import google.registry.flows.domain.DomainFlowUtils.LeadingDashException; import google.registry.flows.domain.DomainFlowUtils.LinkedResourceDoesNotExistException; import google.registry.flows.domain.DomainFlowUtils.MissingContactTypeException; -import google.registry.flows.domain.DomainFlowUtils.NameserverNotAllowedException; +import google.registry.flows.domain.DomainFlowUtils.NameserversNotAllowedException; import google.registry.flows.domain.DomainFlowUtils.NoMarksFoundMatchingDomainException; import google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException; import google.registry.flows.domain.DomainFlowUtils.PremiumNameBlockedException; @@ -1191,7 +1191,7 @@ public class DomainApplicationCreateFlowTest persistResource(Registry.get("tld").asBuilder() .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.net")) .build()); - thrown.expect(NameserverNotAllowedException.class, "ns1.example.net"); + thrown.expect(NameserversNotAllowedException.class, "ns1.example.net"); runFlow(); } diff --git a/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java index 51370b11d..c9f2cfb85 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java @@ -27,6 +27,8 @@ import static google.registry.testing.GenericEppResourceSubject.assertAboutEppRe 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; @@ -41,7 +43,6 @@ import google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException import google.registry.model.EppResource; import google.registry.model.contact.ContactResource; import google.registry.model.domain.DomainApplication; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.domain.launch.LaunchPhase; import google.registry.model.eppcommon.StatusValue; import google.registry.model.host.HostResource; @@ -89,10 +90,10 @@ public class DomainApplicationDeleteFlowTest persistResource(newDomainApplication("example.tld").asBuilder() .setRepoId("1-TLD") .setRegistrant( - ReferenceUnion.create( + Ref.create( loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc()))) .setNameservers(ImmutableSet.of( - ReferenceUnion.create( + Ref.create( loadByUniqueId(HostResource.class, "ns1.example.net", clock.nowUtc())))) .build()); doSuccessfulTest(); diff --git a/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java index a104f0999..9638fdaf8 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java @@ -26,6 +26,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.googlecode.objectify.Ref; + import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException; import google.registry.flows.ResourceQueryFlow.ResourceToQueryDoesNotExistException; @@ -37,7 +39,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.DomainAuthInfo; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.domain.launch.ApplicationStatus; import google.registry.model.domain.launch.LaunchCreateExtension; import google.registry.model.domain.launch.LaunchPhase; @@ -89,12 +90,12 @@ public class DomainApplicationInfoFlowTest .setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z")) .setLastEppUpdateTime(DateTime.parse("1999-12-03T09:00:00.0Z")) .setLastTransferTime(DateTime.parse("2000-04-08T09:00:00.0Z")) - .setRegistrant(ReferenceUnion.create(registrant)) + .setRegistrant(Ref.create(registrant)) .setContacts(ImmutableSet.of( - DesignatedContact.create(Type.ADMIN, ReferenceUnion.create(contact)), - DesignatedContact.create(Type.TECH, ReferenceUnion.create(contact)))) + DesignatedContact.create(Type.ADMIN, Ref.create(contact)), + DesignatedContact.create(Type.TECH, Ref.create(contact)))) .setNameservers(hostsState.equals(HostsState.HOSTS_EXIST) ? ImmutableSet.of( - ReferenceUnion.create(host1), ReferenceUnion.create(host2)) : null) + Ref.create(host1), Ref.create(host2)) : null) .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("2fooBAR"))) .addStatusValue(StatusValue.PENDING_CREATE) .setApplicationStatus(ApplicationStatus.PENDING_VALIDATION) @@ -244,7 +245,7 @@ public class DomainApplicationInfoFlowTest .setDsData(ImmutableSet.of(DelegationSignerData.create( 12345, 3, 1, base16().decode("49FD46E6C4B45C55D4AC")))) .setNameservers(ImmutableSet.of( - ReferenceUnion.create(host1), ReferenceUnion.create(host2))) + Ref.create(host1), Ref.create(host2))) .build()); doSuccessfulTest("domain_info_sunrise_response_dsdata.xml", HostsState.NO_HOSTS_EXIST); } diff --git a/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java index ac7bb487d..a85249196 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java @@ -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 sh8013ReferenceUnion = ReferenceUnion.create(sh8013); + Ref 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> nameservers = new ImmutableSet.Builder<>(); + ImmutableSet.Builder> 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(); } diff --git a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java index bff51fc6e..28c88cff8 100644 --- a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java @@ -89,7 +89,7 @@ import google.registry.flows.domain.DomainFlowUtils.MissingAdminContactException import google.registry.flows.domain.DomainFlowUtils.MissingContactTypeException; import google.registry.flows.domain.DomainFlowUtils.MissingRegistrantException; 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.PremiumNameBlockedException; import google.registry.flows.domain.DomainFlowUtils.RegistrantNotAllowedException; @@ -1251,7 +1251,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase .setCreationClientId("TheRegistrar") .setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z")) .setRegistrationExpirationTime(REGISTRATION_EXPIRATION_TIME) - .setRegistrant( - ReferenceUnion.create(loadByUniqueId( - ContactResource.class, "jd1234", clock.nowUtc()))) + .setRegistrant(Ref.create(loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc()))) .setContacts(ImmutableSet.of( DesignatedContact.create( Type.ADMIN, - ReferenceUnion.create( - loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc()))), + Ref.create(loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc()))), DesignatedContact.create( Type.TECH, - ReferenceUnion.create( - loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc()))))) + Ref.create(loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc()))))) .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("fooBAR"))) .addGracePeriod(GracePeriod.create( GracePeriodStatus.ADD, clock.nowUtc().plusDays(10), "foo", null)) diff --git a/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java b/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java index 6e920be3f..e6d05f20b 100644 --- a/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java @@ -62,7 +62,7 @@ import google.registry.flows.domain.DomainFlowUtils.LinkedResourceInPendingDelet 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; @@ -74,7 +74,6 @@ import google.registry.model.domain.DesignatedContact; import google.registry.model.domain.DesignatedContact.Type; import google.registry.model.domain.DomainResource; import google.registry.model.domain.GracePeriod; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.eppcommon.StatusValue; @@ -123,9 +122,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase> nameservers = new ImmutableSet.Builder<>(); + ImmutableSet.Builder> 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.foo", i), clock.nowUtc()))); } } @@ -374,11 +373,11 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase> nameservers = new ImmutableSet.Builder<>(); + ImmutableSet.Builder> nameservers = new ImmutableSet.Builder<>(); for (int i = 0; i < 26; i++) { HostResource host = persistActiveHost(String.format("max_test_%d.example.tld", i)); if (i < 13) { - nameservers.add(ReferenceUnion.create(host)); + nameservers.add(Ref.create(host)); } } ImmutableSet.Builder contacts = new ImmutableSet.Builder<>(); @@ -388,7 +387,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase sh8013ReferenceUnion = ReferenceUnion.create(sh8013); + Ref sh8013Ref = Ref.create(sh8013); persistResource( newDomainResource(getUniqueIdFromCommand()).asBuilder() - .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")); @@ -891,7 +890,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCasecreate(persistHostResource(true)))) + ImmutableSet.of(Ref.create(persistHostResource(true)))) .build()); assertTransactionalFlow(false); // Check that the persisted host info was returned. diff --git a/javatests/google/registry/flows/host/HostUpdateFlowTest.java b/javatests/google/registry/flows/host/HostUpdateFlowTest.java index 304abd7cb..1610b16bd 100644 --- a/javatests/google/registry/flows/host/HostUpdateFlowTest.java +++ b/javatests/google/registry/flows/host/HostUpdateFlowTest.java @@ -58,7 +58,6 @@ import google.registry.flows.host.HostUpdateFlow.HostAlreadyExistsException; import google.registry.flows.host.HostUpdateFlow.RenameHostToExternalRemoveIpException; import google.registry.flows.host.HostUpdateFlow.RenameHostToSubordinateRequiresIpException; import google.registry.model.domain.DomainResource; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.eppcommon.StatusValue; import google.registry.model.host.HostResource; import google.registry.model.index.ForeignKeyIndex; @@ -162,7 +161,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase>of()) + .setNameservers(ImmutableSet.>of()) .build() .nameservers) .isNull(); assertThat(emptyBuilder() - .setNameservers(ImmutableSet.of(ReferenceUnion.create("foo"))) + .setNameservers(ImmutableSet.of(Ref.create(newHostResource("foo.example.tld")))) .build() .nameservers) .isNotNull(); diff --git a/javatests/google/registry/model/domain/DomainResourceTest.java b/javatests/google/registry/model/domain/DomainResourceTest.java index 03bbb5010..84920634e 100644 --- a/javatests/google/registry/model/domain/DomainResourceTest.java +++ b/javatests/google/registry/model/domain/DomainResourceTest.java @@ -20,6 +20,7 @@ import static google.registry.model.EppResourceUtils.loadByUniqueId; import static google.registry.testing.DatastoreHelper.cloneAndSetAutoTimestamps; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.newDomainResource; +import static google.registry.testing.DatastoreHelper.newHostResource; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.util.DateTimeUtils.START_OF_TIME; @@ -103,11 +104,11 @@ public class DomainResourceTest extends EntityTestCase { StatusValue.SERVER_UPDATE_PROHIBITED, StatusValue.SERVER_RENEW_PROHIBITED, StatusValue.SERVER_HOLD)) - .setRegistrant(ReferenceUnion.create(contactResource1)) + .setRegistrant(Ref.create(contactResource1)) .setContacts(ImmutableSet.of(DesignatedContact.create( DesignatedContact.Type.ADMIN, - ReferenceUnion.create(contactResource2)))) - .setNameservers(ImmutableSet.of(ReferenceUnion.create(hostResource))) + Ref.create(contactResource2)))) + .setNameservers(ImmutableSet.of(Ref.create(hostResource))) .setSubordinateHosts(ImmutableSet.of("ns1.example.com")) .setCurrentSponsorClientId("a third registrar") .setRegistrationExpirationTime(clock.nowUtc().plusYears(1)) @@ -190,10 +191,10 @@ public class DomainResourceTest extends EntityTestCase { assertThat(newDomainResource("example.com").asBuilder() .setNameservers(null).build().nameservers).isNull(); assertThat(newDomainResource("example.com").asBuilder() - .setNameservers(ImmutableSet.>of()).build().nameservers) + .setNameservers(ImmutableSet.>of()).build().nameservers) .isNull(); assertThat(newDomainResource("example.com").asBuilder() - .setNameservers(ImmutableSet.of(ReferenceUnion.create("foo"))) + .setNameservers(ImmutableSet.of(Ref.create(newHostResource("foo.example.tld")))) .build().nameservers) .isNotNull(); // This behavior should also hold true for ImmutableObjects nested in collections. @@ -222,8 +223,8 @@ public class DomainResourceTest extends EntityTestCase { @Test public void testImplicitStatusValues() { - ImmutableSet> nameservers = - ImmutableSet.of(ReferenceUnion.create("foo")); + ImmutableSet> nameservers = + ImmutableSet.of(Ref.create(newHostResource("foo.example.tld"))); StatusValue[] statuses = {StatusValue.OK}; // OK is implicit if there's no other statuses but there are nameservers. assertAboutDomains() diff --git a/javatests/google/registry/monitoring/whitebox/VerifyEntityIntegrityActionTest.java b/javatests/google/registry/monitoring/whitebox/VerifyEntityIntegrityActionTest.java index 7b1dca249..85de09f16 100644 --- a/javatests/google/registry/monitoring/whitebox/VerifyEntityIntegrityActionTest.java +++ b/javatests/google/registry/monitoring/whitebox/VerifyEntityIntegrityActionTest.java @@ -49,7 +49,6 @@ import google.registry.config.RegistryEnvironment; import google.registry.mapreduce.MapreduceRunner; import google.registry.model.contact.ContactResource; import google.registry.model.domain.DomainResource; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.host.HostResource; import google.registry.model.index.EppResourceIndex; import google.registry.model.index.ForeignKeyIndex; @@ -192,9 +191,9 @@ public class VerifyEntityIntegrityActionTest .asBuilder() .setNameservers( ImmutableSet.of( - ReferenceUnion.create(Ref.create(missingHost1)), - ReferenceUnion.create(Ref.create(missingHost2)), - ReferenceUnion.create(Ref.create(missingHost3)))) + Ref.create(missingHost1), + Ref.create(missingHost2), + Ref.create(missingHost3))) .build()); String source = Key.create(domain).toString(); runMapreduce(); diff --git a/javatests/google/registry/pricing/PricingEngineProxyTest.java b/javatests/google/registry/pricing/PricingEngineProxyTest.java index 3dbdf5b75..4b3a91b22 100644 --- a/javatests/google/registry/pricing/PricingEngineProxyTest.java +++ b/javatests/google/registry/pricing/PricingEngineProxyTest.java @@ -25,6 +25,7 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME; import static org.joda.money.CurrencyUnit.USD; import com.google.common.collect.ImmutableSortedMap; + import google.registry.model.registry.Registry; import google.registry.model.registry.label.PremiumList; import google.registry.testing.AppEngineRule; diff --git a/javatests/google/registry/rde/DomainResourceToXjcConverterTest.java b/javatests/google/registry/rde/DomainResourceToXjcConverterTest.java index 08429a0fc..ae6364b67 100644 --- a/javatests/google/registry/rde/DomainResourceToXjcConverterTest.java +++ b/javatests/google/registry/rde/DomainResourceToXjcConverterTest.java @@ -46,7 +46,6 @@ import google.registry.model.domain.DesignatedContact; import google.registry.model.domain.DomainAuthInfo; import google.registry.model.domain.DomainResource; import google.registry.model.domain.GracePeriod; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.eppcommon.AuthInfo.PasswordAuth; @@ -264,10 +263,10 @@ public class DomainResourceToXjcConverterTest { domain = domain.asBuilder() .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("secret"))) .setContacts(ImmutableSet.of( - DesignatedContact.create(DesignatedContact.Type.ADMIN, ReferenceUnion.create( + DesignatedContact.create(DesignatedContact.Type.ADMIN, Ref.create( makeContactResource(clock, "10-Q9JYB4C", "5372808-IRL", "be that word our sign in parting", "BOFH@cat.みんな"))), - DesignatedContact.create(DesignatedContact.Type.TECH, ReferenceUnion.create( + DesignatedContact.create(DesignatedContact.Type.TECH, Ref.create( makeContactResource(clock, "11-Q9JYB4C", "5372808-TRL", "bird or fiend!? i shrieked upstarting", "bog@cat.みんな"))))) .setCreationClientId("LawyerCat") @@ -280,11 +279,11 @@ public class DomainResourceToXjcConverterTest { .setLastEppUpdateClientId("IntoTheTempest") .setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z")) .setNameservers(ImmutableSet.of( - ReferenceUnion.create( + Ref.create( makeHostResource(clock, "3-Q9JYB4C", "bird.or.devil.みんな", "1.2.3.4")), - ReferenceUnion.create( + Ref.create( makeHostResource(clock, "4-Q9JYB4C", "ns2.cat.みんな", "bad:f00d:cafe::15:beef")))) - .setRegistrant(ReferenceUnion.create(makeContactResource( + .setRegistrant(Ref.create(makeContactResource( clock, "12-Q9JYB4C", "5372808-ERL", "(◕‿◕) nevermore", "prophet@evil.みんな"))) .setRegistrationExpirationTime(DateTime.parse("1930-01-01T00:00:00Z")) .setGracePeriods(ImmutableSet.of( diff --git a/javatests/google/registry/rde/RdeFixtures.java b/javatests/google/registry/rde/RdeFixtures.java index 75708f94e..d37177b4a 100644 --- a/javatests/google/registry/rde/RdeFixtures.java +++ b/javatests/google/registry/rde/RdeFixtures.java @@ -41,7 +41,6 @@ import google.registry.model.domain.DesignatedContact; import google.registry.model.domain.DomainAuthInfo; import google.registry.model.domain.DomainResource; import google.registry.model.domain.GracePeriod; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.eppcommon.AuthInfo.PasswordAuth; @@ -85,10 +84,10 @@ final class RdeFixtures { domain = domain.asBuilder() .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("secret"))) .setContacts(ImmutableSet.of( - DesignatedContact.create(DesignatedContact.Type.ADMIN, ReferenceUnion.create( + DesignatedContact.create(DesignatedContact.Type.ADMIN, Ref.create( makeContactResource(clock, "5372808-IRL", "be that word our sign in parting", "BOFH@cat.みんな"))), - DesignatedContact.create(DesignatedContact.Type.TECH, ReferenceUnion.create( + DesignatedContact.create(DesignatedContact.Type.TECH, Ref.create( makeContactResource(clock, "5372808-TRL", "bird or fiend!? i shrieked upstarting", "bog@cat.みんな"))))) .setCreationClientId("TheRegistrar") @@ -102,12 +101,12 @@ final class RdeFixtures { .setLastEppUpdateTime(clock.nowUtc()) .setIdnTableName("extended_latin") .setNameservers(ImmutableSet.of( - ReferenceUnion.create( + Ref.create( makeHostResource(clock, "bird.or.devil.みんな", "1.2.3.4")), - ReferenceUnion.create( + Ref.create( makeHostResource( clock, "ns2.cat.みんな", "bad:f00d:cafe::15:beef")))) - .setRegistrant(ReferenceUnion.create( + .setRegistrant(Ref.create( makeContactResource(clock, "5372808-ERL", "(◕‿◕) nevermore", "prophet@evil.みんな"))) .setRegistrationExpirationTime(DateTime.parse("1930-01-01T00:00:00Z")) diff --git a/javatests/google/registry/server/BUILD b/javatests/google/registry/server/BUILD index 8f2f1b2c7..d0dc5d80c 100644 --- a/javatests/google/registry/server/BUILD +++ b/javatests/google/registry/server/BUILD @@ -38,6 +38,7 @@ java_library( "//java/com/google/common/collect", "//third_party/java/appengine:appengine-api", "//third_party/java/joda_time", + "//third_party/java/objectify:objectify-v4_1", "//java/google/registry/model", "//javatests/google/registry/testing", ], diff --git a/javatests/google/registry/server/Fixture.java b/javatests/google/registry/server/Fixture.java index 3b3b0bf9f..32efcc458 100644 --- a/javatests/google/registry/server/Fixture.java +++ b/javatests/google/registry/server/Fixture.java @@ -26,11 +26,12 @@ import static google.registry.testing.DatastoreHelper.persistResource; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.googlecode.objectify.Ref; + import google.registry.model.contact.ContactAddress; import google.registry.model.contact.ContactResource; import google.registry.model.contact.PostalInfo; import google.registry.model.domain.DesignatedContact; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.ofy.Ofy; import google.registry.model.registrar.Registrar; import google.registry.testing.FakeClock; @@ -114,28 +115,26 @@ public enum Fixture { persistResource( newDomainResource("love.xn--q9jyb4c", justine).asBuilder() .setContacts(ImmutableSet.of( - DesignatedContact.create(ADMIN, ReferenceUnion.create(robert)), - DesignatedContact.create(BILLING, ReferenceUnion.create(google)), - DesignatedContact.create(TECH, ReferenceUnion.create(justine)))) + DesignatedContact.create(ADMIN, Ref.create(robert)), + DesignatedContact.create(BILLING, Ref.create(google)), + DesignatedContact.create(TECH, Ref.create(justine)))) .setNameservers(ImmutableSet.of( - ReferenceUnion.create( - persistActiveHost("ns1.love.xn--q9jyb4c")), - ReferenceUnion.create( - persistActiveHost("ns2.love.xn--q9jyb4c")))) + Ref.create(persistActiveHost("ns1.love.xn--q9jyb4c")), + Ref.create(persistActiveHost("ns2.love.xn--q9jyb4c")))) .build()); persistResource( newDomainResource("moogle.example", justine).asBuilder() .setContacts(ImmutableSet.of( - DesignatedContact.create(ADMIN, ReferenceUnion.create(robert)), - DesignatedContact.create(BILLING, ReferenceUnion.create(google)), - DesignatedContact.create(TECH, ReferenceUnion.create(justine)))) + DesignatedContact.create(ADMIN, Ref.create(robert)), + DesignatedContact.create(BILLING, Ref.create(google)), + DesignatedContact.create(TECH, Ref.create(justine)))) .setNameservers(ImmutableSet.of( - ReferenceUnion.create(persistActiveHost("ns1.linode.com")), - ReferenceUnion.create(persistActiveHost("ns2.linode.com")), - ReferenceUnion.create(persistActiveHost("ns3.linode.com")), - ReferenceUnion.create(persistActiveHost("ns4.linode.com")), - ReferenceUnion.create(persistActiveHost("ns5.linode.com")))) + Ref.create(persistActiveHost("ns1.linode.com")), + Ref.create(persistActiveHost("ns2.linode.com")), + Ref.create(persistActiveHost("ns3.linode.com")), + Ref.create(persistActiveHost("ns4.linode.com")), + Ref.create(persistActiveHost("ns5.linode.com")))) .build()); persistResource( diff --git a/javatests/google/registry/testing/DatastoreHelper.java b/javatests/google/registry/testing/DatastoreHelper.java index 8b5e1c64d..b925da744 100644 --- a/javatests/google/registry/testing/DatastoreHelper.java +++ b/javatests/google/registry/testing/DatastoreHelper.java @@ -68,7 +68,6 @@ import google.registry.model.domain.DesignatedContact.Type; import google.registry.model.domain.DomainApplication; import google.registry.model.domain.DomainAuthInfo; import google.registry.model.domain.DomainResource; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.domain.launch.LaunchPhase; import google.registry.model.eppcommon.AuthInfo.PasswordAuth; import google.registry.model.eppcommon.StatusValue; @@ -132,6 +131,7 @@ public class DatastoreHelper { public static DomainResource newDomainResource( String domainName, String repoId, ContactResource contact) { + Ref contactRef = Ref.create(contact); return new DomainResource.Builder() .setRepoId(repoId) .setFullyQualifiedDomainName(domainName) @@ -139,10 +139,10 @@ public class DatastoreHelper { .setCurrentSponsorClientId("TheRegistrar") .setCreationTimeForTest(START_OF_TIME) .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("2fooBAR"))) - .setRegistrant(ReferenceUnion.create(contact)) + .setRegistrant(contactRef) .setContacts(ImmutableSet.of( - DesignatedContact.create(Type.ADMIN, ReferenceUnion.create(contact)), - DesignatedContact.create(Type.TECH, ReferenceUnion.create(contact)))) + DesignatedContact.create(Type.ADMIN, contactRef), + DesignatedContact.create(Type.TECH, contactRef))) .setRegistrationExpirationTime(END_OF_TIME) .build(); } @@ -172,15 +172,16 @@ public class DatastoreHelper { public static DomainApplication newDomainApplication( String domainName, String repoId, ContactResource contact, LaunchPhase phase) { + Ref contactRef = Ref.create(contact); return new DomainApplication.Builder() .setRepoId(repoId) .setFullyQualifiedDomainName(domainName) .setCurrentSponsorClientId("TheRegistrar") .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("2fooBAR"))) - .setRegistrant(ReferenceUnion.create(contact)) + .setRegistrant(contactRef) .setContacts(ImmutableSet.of( - DesignatedContact.create(Type.ADMIN, ReferenceUnion.create(contact)), - DesignatedContact.create(Type.TECH, ReferenceUnion.create(contact)))) + DesignatedContact.create(Type.ADMIN, contactRef), + DesignatedContact.create(Type.TECH, contactRef))) .setPhase(phase) .setApplicationStatus(VALIDATED) .addStatusValue(StatusValue.PENDING_CREATE) diff --git a/javatests/google/registry/testing/FullFieldsTestEntityHelper.java b/javatests/google/registry/testing/FullFieldsTestEntityHelper.java index 645517f40..e1d9c62a4 100644 --- a/javatests/google/registry/testing/FullFieldsTestEntityHelper.java +++ b/javatests/google/registry/testing/FullFieldsTestEntityHelper.java @@ -24,6 +24,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.net.InetAddresses; +import com.googlecode.objectify.Ref; + import google.registry.model.EppResource; import google.registry.model.contact.ContactAddress; import google.registry.model.contact.ContactPhoneNumber; @@ -32,7 +34,6 @@ import google.registry.model.contact.PostalInfo; import google.registry.model.domain.DesignatedContact; import google.registry.model.domain.DomainResource; import google.registry.model.domain.Period; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppcommon.Trid; @@ -232,27 +233,27 @@ public final class FullFieldsTestEntityHelper { StatusValue.SERVER_UPDATE_PROHIBITED)) .setDsData(ImmutableSet.of(new DelegationSignerData())); if (registrant != null) { - builder.setRegistrant(ReferenceUnion.create(registrant)); + builder.setRegistrant(Ref.create(registrant)); } if ((admin != null) || (tech != null)) { ImmutableSet.Builder contactsBuilder = new ImmutableSet.Builder<>(); if (admin != null) { contactsBuilder.add(DesignatedContact.create( - DesignatedContact.Type.ADMIN, ReferenceUnion.create(admin))); + DesignatedContact.Type.ADMIN, Ref.create(admin))); } if (tech != null) { contactsBuilder.add(DesignatedContact.create( - DesignatedContact.Type.TECH, ReferenceUnion.create(tech))); + DesignatedContact.Type.TECH, Ref.create(tech))); } builder.setContacts(contactsBuilder.build()); } if ((ns1 != null) || (ns2 != null)) { - ImmutableSet.Builder> nsBuilder = new ImmutableSet.Builder<>(); + ImmutableSet.Builder> nsBuilder = new ImmutableSet.Builder<>(); if (ns1 != null) { - nsBuilder.add(ReferenceUnion.create(ns1)); + nsBuilder.add(Ref.create(ns1)); } if (ns2 != null) { - nsBuilder.add(ReferenceUnion.create(ns2)); + nsBuilder.add(Ref.create(ns2)); } builder.setNameservers(nsBuilder.build()); } diff --git a/javatests/google/registry/tools/AllocateDomainCommandTest.java b/javatests/google/registry/tools/AllocateDomainCommandTest.java index 94db29e83..5ce17c7d0 100644 --- a/javatests/google/registry/tools/AllocateDomainCommandTest.java +++ b/javatests/google/registry/tools/AllocateDomainCommandTest.java @@ -42,12 +42,12 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.beust.jcommander.ParameterException; +import com.googlecode.objectify.Ref; import google.registry.flows.EppXmlTransformer; import google.registry.flows.domain.DomainAllocateFlow; import google.registry.model.domain.DesignatedContact; import google.registry.model.domain.DomainApplication; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.domain.launch.LaunchNotice; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.eppcommon.Trid; @@ -93,20 +93,20 @@ public class AllocateDomainCommandTest extends CommandTestCase> hostRefs = new ImmutableSet.Builder<>(); + ImmutableSet.Builder> hostRefs = new ImmutableSet.Builder<>(); for (HostResource host : hosts) { - hostRefs.add(ReferenceUnion.create(Ref.create(host))); + hostRefs.add(Ref.create(host)); } persistResource(newDomainResource("evil.tld").asBuilder() .setNameservers(hostRefs.build()) diff --git a/javatests/google/registry/tools/server/GenerateZoneFilesActionTest.java b/javatests/google/registry/tools/server/GenerateZoneFilesActionTest.java index 8dad00d6c..e81058454 100644 --- a/javatests/google/registry/tools/server/GenerateZoneFilesActionTest.java +++ b/javatests/google/registry/tools/server/GenerateZoneFilesActionTest.java @@ -37,8 +37,9 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.googlecode.objectify.Ref; + import google.registry.mapreduce.MapreduceRunner; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.host.HostResource; import google.registry.testing.FakeClock; @@ -73,10 +74,8 @@ public class GenerateZoneFilesActionTest extends MapreduceTestCase> nameservers = - ImmutableSet.of( - ReferenceUnion.create(host1), - ReferenceUnion.create(host2)); + ImmutableSet> nameservers = + ImmutableSet.of(Ref.create(host1), Ref.create(host2)); persistResource(newDomainResource("ns-and-ds.tld").asBuilder() .addNameservers(nameservers) .setDsData(ImmutableSet.of(DelegationSignerData.create(1, 2, 3, new byte[] {0, 1, 2}))) diff --git a/javatests/google/registry/whois/DomainWhoisResponseTest.java b/javatests/google/registry/whois/DomainWhoisResponseTest.java index 97d255a69..32e5acd22 100644 --- a/javatests/google/registry/whois/DomainWhoisResponseTest.java +++ b/javatests/google/registry/whois/DomainWhoisResponseTest.java @@ -32,7 +32,6 @@ import google.registry.model.contact.PostalInfo; import google.registry.model.domain.DesignatedContact; import google.registry.model.domain.DomainResource; import google.registry.model.domain.GracePeriod; -import google.registry.model.domain.ReferenceUnion; import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.eppcommon.StatusValue; @@ -227,17 +226,11 @@ public class DomainWhoisResponseTest { StatusValue.CLIENT_RENEW_PROHIBITED, StatusValue.CLIENT_TRANSFER_PROHIBITED, StatusValue.SERVER_UPDATE_PROHIBITED)) - .setRegistrant(ReferenceUnion.create(registrantResourceRef)) + .setRegistrant(registrantResourceRef) .setContacts(ImmutableSet.of( - DesignatedContact.create( - DesignatedContact.Type.ADMIN, - ReferenceUnion.create(adminResourceRef)), - DesignatedContact.create( - DesignatedContact.Type.TECH, - ReferenceUnion.create(techResourceRef)))) - .setNameservers(ImmutableSet.of( - ReferenceUnion.create(hostResource1Ref), - ReferenceUnion.create(hostResource2Ref))) + DesignatedContact.create(DesignatedContact.Type.ADMIN, adminResourceRef), + DesignatedContact.create(DesignatedContact.Type.TECH, techResourceRef))) + .setNameservers(ImmutableSet.of(hostResource1Ref, hostResource2Ref)) .setDsData(ImmutableSet.of(new DelegationSignerData())) .setGracePeriods(ImmutableSet.of( GracePeriod.create(GracePeriodStatus.ADD, END_OF_TIME, "", null),