diff --git a/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriter.java b/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriter.java index 2d1e8f897..8b4319eeb 100644 --- a/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriter.java +++ b/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriter.java @@ -16,6 +16,7 @@ package google.registry.dns.writer.dnsupdate; import static com.google.common.base.Verify.verify; import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.ofy.ObjectifyService.ofy; import com.google.common.net.InternetDomainName; @@ -102,7 +103,8 @@ public class DnsUpdateWriter implements DnsWriter { Update update = new Update(toAbsoluteName(findTldFromName(domainName))); update.delete(toAbsoluteName(domainName), Type.ANY); if (domain != null && domain.shouldPublishToDns()) { - update.add(makeNameServerSet(domainName, domain.loadNameservers())); + update.add(makeNameServerSet( + domainName, ofy().load().refs(domain.getNameservers()).values())); update.add(makeDelegationSignerSet(domainName, domain.getDsData())); } diff --git a/java/google/registry/model/EppResourceUtils.java b/java/google/registry/model/EppResourceUtils.java index f3eff50c7..5f7b8774e 100644 --- a/java/google/registry/model/EppResourceUtils.java +++ b/java/google/registry/model/EppResourceUtils.java @@ -24,7 +24,6 @@ import static google.registry.util.DateTimeUtils.isBeforeOrAt; import static google.registry.util.DateTimeUtils.latestOf; import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; import com.googlecode.objectify.Ref; @@ -138,29 +137,6 @@ public final class EppResourceUtils { latestOf(now, resource.getUpdateAutoTimestamp().getTimestamp())); } - /** Loads and returns the hosts specified by the given reference. */ - public static ImmutableSet loadReferencedNameservers( - Set> hostRefs) { - ImmutableSet.Builder builder = new ImmutableSet.Builder<>(); - for (Ref hostRef : hostRefs) { - HostResource host = hostRef.get(); - if (host != null) { - builder.add(host); - } - } - return builder.build(); - } - - /** Loads and returns the contacts specified by the given references. */ - public static ImmutableSet loadReferencedContacts( - Set> contactRefs) { - ImmutableSet.Builder builder = new ImmutableSet.Builder<>(); - for (Ref contactRef : contactRefs) { - builder.add(contactRef.get()); - } - return builder.build(); - } - /** * Checks multiple {@link EppResource} objects from the datastore by unique ids. *

diff --git a/java/google/registry/model/domain/DomainBase.java b/java/google/registry/model/domain/DomainBase.java index 6cf47f713..6cb05b519 100644 --- a/java/google/registry/model/domain/DomainBase.java +++ b/java/google/registry/model/domain/DomainBase.java @@ -19,12 +19,15 @@ 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.model.ofy.ObjectifyService.ofy; 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; import static google.registry.util.DomainNameUtils.getTldFromSld; +import com.google.common.base.Function; +import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; @@ -37,7 +40,6 @@ import com.googlecode.objectify.annotation.OnLoad; import com.googlecode.objectify.condition.IfNull; import google.registry.model.EppResource; -import google.registry.model.EppResourceUtils; import google.registry.model.contact.ContactResource; import google.registry.model.domain.launch.LaunchNotice; import google.registry.model.domain.secdns.DelegationSignerData; @@ -161,9 +163,16 @@ public abstract class DomainBase extends EppResource { return builder.build(); } - /** Loads and returns all linked nameservers. */ - public ImmutableSet loadNameservers() { - return EppResourceUtils.loadReferencedNameservers(getNameservers()); + /** Loads and returns the fully qualified host names of all linked nameservers. */ + public ImmutableSet loadNameserverFullyQualifiedHostNames() { + return FluentIterable.from(ofy().load().refs(getNameservers()).values()) + .transform( + new Function() { + @Override + public String apply(HostResource host) { + return host.getFullyQualifiedHostName(); + }}) + .toSet(); } public Ref getRegistrant() { @@ -192,11 +201,6 @@ public abstract class DomainBase extends EppResource { return contactsBuilder.build(); } - /** Loads and returns all referenced contacts from this domain or application. */ - public ImmutableSet loadReferencedContacts() { - return EppResourceUtils.loadReferencedContacts(getReferencedContacts()); - } - public String getTld() { return tld; } diff --git a/java/google/registry/rdap/RdapJsonFormatter.java b/java/google/registry/rdap/RdapJsonFormatter.java index a983d27c0..f22fc203f 100644 --- a/java/google/registry/rdap/RdapJsonFormatter.java +++ b/java/google/registry/rdap/RdapJsonFormatter.java @@ -397,7 +397,8 @@ public class RdapJsonFormatter { @Nullable String linkBase, @Nullable String whoisServer) { // Kick off the database loads of the nameservers that we will need. - ImmutableSet loadedHosts = domainResource.loadNameservers(); + Map, HostResource> loadedHosts = + ofy().load().refs(domainResource.getNameservers()); // And the registrant and other contacts. List allContacts = new ArrayList<>(); if (domainResource.getRegistrant() != null) { @@ -427,7 +428,8 @@ public class RdapJsonFormatter { } // Nameservers ImmutableList.Builder nsBuilder = new ImmutableList.Builder<>(); - for (HostResource hostResource : HOST_RESOURCE_ORDERING.immutableSortedCopy(loadedHosts)) { + for (HostResource hostResource + : HOST_RESOURCE_ORDERING.immutableSortedCopy(loadedHosts.values())) { nsBuilder.add(makeRdapJsonForHost(hostResource, false, linkBase, null)); } ImmutableList ns = nsBuilder.build(); diff --git a/java/google/registry/rde/DomainResourceToXjcConverter.java b/java/google/registry/rde/DomainResourceToXjcConverter.java index 1ee593aa9..331b98eb6 100644 --- a/java/google/registry/rde/DomainResourceToXjcConverter.java +++ b/java/google/registry/rde/DomainResourceToXjcConverter.java @@ -25,7 +25,6 @@ import google.registry.model.domain.DomainResource; import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.eppcommon.StatusValue; -import google.registry.model.host.HostResource; import google.registry.model.rde.RdeMode; import google.registry.model.transfer.TransferData; import google.registry.model.transfer.TransferStatus; @@ -141,11 +140,11 @@ final class DomainResourceToXjcConverter { // it is that with host attributes, you inline the nameserver data // on each domain; with host objects, you normalize the nameserver // data to a separate EPP object. - ImmutableSet linkedNameservers = model.loadNameservers(); - if (!linkedNameservers.isEmpty()) { + ImmutableSet linkedNameserverHostNames = model.loadNameserverFullyQualifiedHostNames(); + if (!linkedNameserverHostNames.isEmpty()) { XjcDomainNsType nameservers = new XjcDomainNsType(); - for (HostResource host : linkedNameservers) { - nameservers.getHostObjs().add(host.getFullyQualifiedHostName()); + for (String hostName : linkedNameserverHostNames) { + nameservers.getHostObjs().add(hostName); } bean.setNs(nameservers); } diff --git a/java/google/registry/tools/AllocateDomainCommand.java b/java/google/registry/tools/AllocateDomainCommand.java index a9ef9209a..6dbe8bdb1 100644 --- a/java/google/registry/tools/AllocateDomainCommand.java +++ b/java/google/registry/tools/AllocateDomainCommand.java @@ -48,7 +48,6 @@ import google.registry.model.domain.launch.LaunchNotice; import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.eppinput.EppInput; import google.registry.model.eppinput.EppInput.ResourceCommandWrapper; -import google.registry.model.host.HostResource; import google.registry.model.reporting.HistoryEntry; import google.registry.model.smd.SignedMark; import google.registry.tools.soy.DomainAllocateSoyInfo; @@ -146,13 +145,7 @@ final class AllocateDomainCommand extends MutatingEppToolCommand { addSoyRecord(application.getCurrentSponsorClientId(), new SoyMapData( "name", application.getFullyQualifiedDomainName(), "period", period.getValue(), - "nameservers", FluentIterable.from(application.loadNameservers()) - .transform(new Function() { - @Override - public String apply(HostResource host) { - return host.getForeignKey(); - }}) - .toList(), + "nameservers", application.loadNameserverFullyQualifiedHostNames(), "registrant", application.loadRegistrant().getForeignKey(), "contacts", contactsMapBuilder.build(), "authInfo", application.getAuthInfo().getPw().getValue(), diff --git a/java/google/registry/tools/GenerateDnsReportCommand.java b/java/google/registry/tools/GenerateDnsReportCommand.java index fa92713a6..4bc2e960f 100644 --- a/java/google/registry/tools/GenerateDnsReportCommand.java +++ b/java/google/registry/tools/GenerateDnsReportCommand.java @@ -104,12 +104,8 @@ final class GenerateDnsReportCommand implements RemoteApiCommand, GtechCommand { } private void write(DomainResource domain) { - ImmutableList nameservers = FluentIterable.from(domain.loadNameservers()) - .transform(new Function() { - @Override - public String apply(HostResource host) { - return host.getForeignKey(); - }}) + ImmutableList nameservers = FluentIterable + .from(domain.loadNameserverFullyQualifiedHostNames()) .toSortedList(Ordering.natural()); ImmutableList> dsData = FluentIterable.from(domain.getDsData()) .transform(new Function>() { diff --git a/java/google/registry/whois/DomainWhoisResponse.java b/java/google/registry/whois/DomainWhoisResponse.java index a89b740ad..e881a3ef6 100644 --- a/java/google/registry/whois/DomainWhoisResponse.java +++ b/java/google/registry/whois/DomainWhoisResponse.java @@ -34,7 +34,6 @@ import google.registry.model.domain.DesignatedContact.Type; import google.registry.model.domain.DomainResource; import google.registry.model.domain.GracePeriod; import google.registry.model.eppcommon.StatusValue; -import google.registry.model.host.HostResource; import google.registry.model.registrar.Registrar; import google.registry.model.translators.EnumToAttributeAdapter.EppEnum; import google.registry.util.FormattingLogger; @@ -89,11 +88,11 @@ final class DomainWhoisResponse extends WhoisResponseImpl { .emitContact("Billing", getContactReference(Type.BILLING), preferUnicode) .emitSet( "Name Server", - domain.loadNameservers(), - new Function() { + domain.loadNameserverFullyQualifiedHostNames(), + new Function() { @Override - public String apply(HostResource host) { - return maybeFormatHostname(host.getFullyQualifiedHostName(), preferUnicode); + public String apply(String hostName) { + return maybeFormatHostname(hostName, preferUnicode); }}) .emitField("DNSSEC", isNullOrEmpty(domain.getDsData()) ? "unsigned" : "signedDelegation") .emitLastUpdated(getTimestamp())