diff --git a/java/google/registry/model/domain/DomainBase.java b/java/google/registry/model/domain/DomainBase.java index 0ceea074f..11b24ee8d 100644 --- a/java/google/registry/model/domain/DomainBase.java +++ b/java/google/registry/model/domain/DomainBase.java @@ -14,8 +14,7 @@ package google.registry.model.domain; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Strings.isNullOrEmpty; +import static com.google.common.base.Strings.emptyToNull; 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; @@ -25,6 +24,7 @@ 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 static google.registry.util.PreconditionsUtils.checkArgumentNotNull; import com.google.common.base.Function; import com.google.common.collect.FluentIterable; @@ -176,11 +176,7 @@ public abstract class DomainBase extends EppResource { } public Ref getRegistrant() { - return registrant == null ? null : registrant.getLinked(); - } - - public ContactResource loadRegistrant() { - return getRegistrant().get(); + return registrant.getLinked(); } public ImmutableSet getContacts() { @@ -238,12 +234,11 @@ public abstract class DomainBase extends EppResource { @Override public T build() { T instance = getInstance(); - checkState( - !isNullOrEmpty(instance.fullyQualifiedDomainName), "Missing fullyQualifiedDomainName"); + checkArgumentNotNull( + emptyToNull(instance.fullyQualifiedDomainName), "Missing fullyQualifiedDomainName"); + checkArgumentNotNull(instance.registrant, "Missing registrant"); instance.tld = getTldFromSld(instance.fullyQualifiedDomainName); - instance.allContacts = instance.registrant == null - ? instance.contacts - : union( + instance.allContacts = union( instance.getContacts(), DesignatedContact.create(REGISTRANT, instance.registrant.getLinked())); return super.build(); diff --git a/java/google/registry/rdap/RdapJsonFormatter.java b/java/google/registry/rdap/RdapJsonFormatter.java index f22fc203f..8e7e81cbd 100644 --- a/java/google/registry/rdap/RdapJsonFormatter.java +++ b/java/google/registry/rdap/RdapJsonFormatter.java @@ -30,7 +30,6 @@ import com.google.common.collect.Ordering; import com.google.common.net.InetAddresses; import com.googlecode.objectify.Key; -import com.googlecode.objectify.Ref; import google.registry.model.EppResource; import google.registry.model.contact.ContactPhoneNumber; @@ -54,12 +53,8 @@ import java.net.Inet4Address; import java.net.Inet6Address; import java.net.InetAddress; import java.net.URI; -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Set; import javax.annotation.Nullable; @@ -400,16 +395,9 @@ public class RdapJsonFormatter { Map, HostResource> loadedHosts = ofy().load().refs(domainResource.getNameservers()); // And the registrant and other contacts. - List allContacts = new ArrayList<>(); - if (domainResource.getRegistrant() != null) { - allContacts.add(DesignatedContact.create(Type.REGISTRANT, domainResource.getRegistrant())); - } - allContacts.addAll(domainResource.getContacts()); - Set> contactRefs = new LinkedHashSet<>(); - for (DesignatedContact designatedContact : allContacts) { - contactRefs.add(designatedContact.getContactRef()); - } - Map, ContactResource> loadedContacts = ofy().load().refs(contactRefs); + Map, ContactResource> loadedContacts = + ofy().load().refs(domainResource.getReferencedContacts()); + // Now, assemble the results, using the loaded objects as needed. ImmutableMap.Builder builder = new ImmutableMap.Builder<>(); builder.put("objectClassName", "domain"); @@ -438,8 +426,9 @@ public class RdapJsonFormatter { } // Contacts ImmutableList.Builder entitiesBuilder = new ImmutableList.Builder<>(); - for (DesignatedContact designatedContact - : DESIGNATED_CONTACT_ORDERING.immutableSortedCopy(allContacts)) { + for (DesignatedContact designatedContact : FluentIterable.from(domainResource.getContacts()) + .append(DesignatedContact.create(Type.REGISTRANT, domainResource.getRegistrant())) + .toSortedList(DESIGNATED_CONTACT_ORDERING)) { ContactResource loadedContact = loadedContacts.get(designatedContact.getContactRef().key()); entitiesBuilder.add(makeRdapJsonForContact( diff --git a/java/google/registry/tools/AllocateDomainCommand.java b/java/google/registry/tools/AllocateDomainCommand.java index 6dbe8bdb1..34eb50859 100644 --- a/java/google/registry/tools/AllocateDomainCommand.java +++ b/java/google/registry/tools/AllocateDomainCommand.java @@ -146,7 +146,7 @@ final class AllocateDomainCommand extends MutatingEppToolCommand { "name", application.getFullyQualifiedDomainName(), "period", period.getValue(), "nameservers", application.loadNameserverFullyQualifiedHostNames(), - "registrant", application.loadRegistrant().getForeignKey(), + "registrant", application.getRegistrant().get().getForeignKey(), "contacts", contactsMapBuilder.build(), "authInfo", application.getAuthInfo().getPw().getValue(), "smdId", application.getEncodedSignedMarks().isEmpty() diff --git a/java/google/registry/tools/AuctionStatusCommand.java b/java/google/registry/tools/AuctionStatusCommand.java index 73a883967..b69c4f3bf 100644 --- a/java/google/registry/tools/AuctionStatusCommand.java +++ b/java/google/registry/tools/AuctionStatusCommand.java @@ -104,7 +104,7 @@ final class AuctionStatusCommand implements RemoteApiCommand, GtechCommand { new Function() { @Override public String apply(DomainApplication app) { - ContactResource registrant = checkNotNull(app.loadRegistrant()); + ContactResource registrant = checkNotNull(app.getRegistrant().get()); Object[] keysAndValues = new Object[] { "Domain", app.getFullyQualifiedDomainName(), "Type", app.getEncodedSignedMarks().isEmpty() ? "Landrush" : "Sunrise", diff --git a/java/google/registry/tools/GenerateApplicationsReportCommand.java b/java/google/registry/tools/GenerateApplicationsReportCommand.java index 1da998ef1..d494f1b9c 100644 --- a/java/google/registry/tools/GenerateApplicationsReportCommand.java +++ b/java/google/registry/tools/GenerateApplicationsReportCommand.java @@ -177,7 +177,7 @@ final class GenerateApplicationsReportCommand implements RemoteApiCommand, Gtech domainApplication.getEncodedSignedMarks().isEmpty() ? "landrush" : "sunrise", domainApplication.getApplicationStatus(), domainApplication.getCurrentSponsorClientId(), - domainApplication.loadRegistrant().getEmailAddress(), + domainApplication.getRegistrant().get().getEmailAddress(), validityMessage); } } diff --git a/java/google/registry/tools/GenerateAuctionDataCommand.java b/java/google/registry/tools/GenerateAuctionDataCommand.java index 8a65cb89b..d630bc1ae 100644 --- a/java/google/registry/tools/GenerateAuctionDataCommand.java +++ b/java/google/registry/tools/GenerateAuctionDataCommand.java @@ -118,7 +118,7 @@ final class GenerateAuctionDataCommand implements RemoteApiCommand, GtechCommand + "Can't process contending applications for %s because some applications " + "are not yet validated.", domainName); - ContactResource registrant = checkNotNull(domainApplication.loadRegistrant()); + ContactResource registrant = checkNotNull(domainApplication.getRegistrant().get()); result.add(emitApplication(domainApplication, registrant)); // Ensure the registrant's email address is unique across the contending applications. diff --git a/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java index 9638fdaf8..30e16024b 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java @@ -278,6 +278,7 @@ public class DomainApplicationInfoFlowTest .setRepoId("123-COM") .setFullyQualifiedDomainName("timber.com") .setDeletionTime(DateTime.now().minusDays(1)) + .setRegistrant(Ref.create(persistActiveContact("jd1234"))) .build()); runFlow(); } @@ -298,6 +299,7 @@ public class DomainApplicationInfoFlowTest persistResource(new DomainApplication.Builder() .setRepoId("123-TLD") .setFullyQualifiedDomainName("invalid.tld") + .setRegistrant(Ref.create(persistActiveContact("jd1234"))) .setPhase(LaunchPhase.SUNRUSH) .build()); runFlow(); diff --git a/javatests/google/registry/rdap/RdapJsonFormatterTest.java b/javatests/google/registry/rdap/RdapJsonFormatterTest.java index 874ff5d9a..099f851d8 100644 --- a/javatests/google/registry/rdap/RdapJsonFormatterTest.java +++ b/javatests/google/registry/rdap/RdapJsonFormatterTest.java @@ -68,8 +68,6 @@ public class RdapJsonFormatterTest { private Registrar registrar; private DomainResource domainResourceFull; - private DomainResource domainResourceNoRegistrant; - private DomainResource domainResourceNoContacts; private DomainResource domainResourceNoNameservers; private HostResource hostResourceIpv4; private HostResource hostResourceIpv6; @@ -131,24 +129,6 @@ public class RdapJsonFormatterTest { hostResourceIpv4, hostResourceIpv6, registrar)); - domainResourceNoRegistrant = persistResource( - makeDomainResource( - "dog.みんな", - null, - contactResourceAdmin, - contactResourceTech, - hostResourceBoth, - hostResourceNoAddresses, - registrar)); - domainResourceNoContacts = persistResource( - makeDomainResource( - "bird.みんな", - null, - null, - null, - hostResourceIpv4, - hostResourceIpv6, - registrar)); domainResourceNoNameservers = persistResource( makeDomainResource( "fish.みんな", @@ -167,20 +147,6 @@ public class RdapJsonFormatterTest { Period.create(1, Period.Unit.YEARS), "created", clock.nowUtc())); - persistResource( - makeHistoryEntry( - domainResourceNoRegistrant, - HistoryEntry.Type.DOMAIN_CREATE, - Period.create(1, Period.Unit.YEARS), - "created", - clock.nowUtc())); - persistResource( - makeHistoryEntry( - domainResourceNoContacts, - HistoryEntry.Type.DOMAIN_CREATE, - Period.create(1, Period.Unit.YEARS), - "created", - clock.nowUtc())); persistResource( makeHistoryEntry( domainResourceNoNameservers, @@ -339,22 +305,6 @@ public class RdapJsonFormatterTest { .isEqualTo(loadJson("rdapjson_domain_full.json")); } - @Test - public void testDomain_noRegistrant() throws Exception { - assertThat( - RdapJsonFormatter.makeRdapJsonForDomain( - domainResourceNoRegistrant, false, LINK_BASE, WHOIS_SERVER)) - .isEqualTo(loadJson("rdapjson_domain_no_registrant.json")); - } - - @Test - public void testDomain_noContacts() throws Exception { - assertThat( - RdapJsonFormatter.makeRdapJsonForDomain( - domainResourceNoContacts, false, LINK_BASE, WHOIS_SERVER)) - .isEqualTo(loadJson("rdapjson_domain_no_contacts.json")); - } - @Test public void testDomain_noNameservers() throws Exception { assertThat( diff --git a/javatests/google/registry/rdap/testdata/rdapjson_domain_no_contacts.json b/javatests/google/registry/rdap/testdata/rdapjson_domain_no_contacts.json deleted file mode 100644 index 583010cfd..000000000 --- a/javatests/google/registry/rdap/testdata/rdapjson_domain_no_contacts.json +++ /dev/null @@ -1,95 +0,0 @@ -{ - "objectClassName" : "domain", - "handle" : "12-Q9JYB4C", - "ldhName" : "bird.xn--q9jyb4c", - "unicodeName" : "bird.みんな", - "status" : - [ - "delete prohibited", - "renew prohibited", - "transfer prohibited", - "update prohibited" - ], - "links" : - [ - { - "value" : "http://myserver.google.com/domain/bird.xn--q9jyb4c", - "rel" : "self", - "href" : "http://myserver.google.com/domain/bird.xn--q9jyb4c", - "type" : "application/rdap+json" - } - ], - "events": [ - { - "eventAction": "registration", - "eventActor": "foo", - "eventDate": "2000-01-01T00:00:00.000Z" - }, - { - "eventAction": "expiration", - "eventDate": "2110-10-08T00:44:59.000Z" - }, - { - "eventAction": "last changed", - "eventDate": "2009-05-29T20:13:00.000Z" - } - ], - "nameservers" : - [ - { - "objectClassName" : "nameserver", - "handle" : "8-ROID", - "ldhName" : "ns1.cat.xn--q9jyb4c", - "unicodeName" : "ns1.cat.みんな", - "status" : ["active"], - "links" : - [ - { - "value" : "http://myserver.google.com/nameserver/ns1.cat.xn--q9jyb4c", - "rel" : "self", - "href" : "http://myserver.google.com/nameserver/ns1.cat.xn--q9jyb4c", - "type" : "application/rdap+json" - } - ], - "events": [ - { - "eventAction": "registration", - "eventActor": "foo", - "eventDate": "1999-01-01T00:00:00.000Z" - } - ], - "ipAddresses" : - { - "v4" : ["1.2.3.4"] - } - }, - { - "objectClassName" : "nameserver", - "handle" : "A-ROID", - "ldhName" : "ns2.cat.xn--q9jyb4c", - "unicodeName" : "ns2.cat.みんな", - "status" : ["active"], - "links" : - [ - { - "value" : "http://myserver.google.com/nameserver/ns2.cat.xn--q9jyb4c", - "rel" : "self", - "href" : "http://myserver.google.com/nameserver/ns2.cat.xn--q9jyb4c", - "type" : "application/rdap+json" - } - ], - "events": [ - { - "eventAction": "registration", - "eventActor": "foo", - "eventDate": "1998-01-01T00:00:00.000Z" - } - ], - "ipAddresses" : - { - "v6" : ["bad:f00d:cafe::15:beef"] - } - } - ], - "port43": "whois.google.com" -} diff --git a/javatests/google/registry/rdap/testdata/rdapjson_domain_no_nameservers.json b/javatests/google/registry/rdap/testdata/rdapjson_domain_no_nameservers.json index afb8a12db..49469ca72 100644 --- a/javatests/google/registry/rdap/testdata/rdapjson_domain_no_nameservers.json +++ b/javatests/google/registry/rdap/testdata/rdapjson_domain_no_nameservers.json @@ -1,6 +1,6 @@ { "objectClassName" : "domain", - "handle" : "13-Q9JYB4C", + "handle" : "11-Q9JYB4C", "ldhName" : "fish.xn--q9jyb4c", "unicodeName" : "fish.みんな", "status" : diff --git a/javatests/google/registry/rdap/testdata/rdapjson_domain_no_registrant.json b/javatests/google/registry/rdap/testdata/rdapjson_domain_no_registrant.json deleted file mode 100644 index 4ccfb4870..000000000 --- a/javatests/google/registry/rdap/testdata/rdapjson_domain_no_registrant.json +++ /dev/null @@ -1,185 +0,0 @@ -{ - "objectClassName" : "domain", - "handle" : "11-Q9JYB4C", - "ldhName" : "dog.xn--q9jyb4c", - "unicodeName" : "dog.みんな", - "status" : - [ - "delete prohibited", - "renew prohibited", - "transfer prohibited", - "update prohibited" - ], - "links" : - [ - { - "value" : "http://myserver.google.com/domain/dog.xn--q9jyb4c", - "rel" : "self", - "href" : "http://myserver.google.com/domain/dog.xn--q9jyb4c", - "type" : "application/rdap+json" - } - ], - "events": [ - { - "eventAction": "registration", - "eventActor": "foo", - "eventDate": "2000-01-01T00:00:00.000Z" - }, - { - "eventAction": "expiration", - "eventDate": "2110-10-08T00:44:59.000Z" - }, - { - "eventAction": "last changed", - "eventDate": "2009-05-29T20:13:00.000Z" - } - ], - "nameservers" : - [ - { - "objectClassName" : "nameserver", - "handle" : "C-ROID", - "ldhName" : "ns3.cat.xn--q9jyb4c", - "unicodeName" : "ns3.cat.みんな", - "status" : ["active"], - "links" : - [ - { - "value" : "http://myserver.google.com/nameserver/ns3.cat.xn--q9jyb4c", - "rel" : "self", - "href" : "http://myserver.google.com/nameserver/ns3.cat.xn--q9jyb4c", - "type" : "application/rdap+json" - } - ], - "events": [ - { - "eventAction": "registration", - "eventActor": "foo", - "eventDate": "1997-01-01T00:00:00.000Z" - } - ], - "ipAddresses" : - { - "v4" : ["1.2.3.4"] - "v6" : ["bad:f00d:cafe::15:beef"] - } - }, - { - "objectClassName" : "nameserver", - "handle" : "E-ROID", - "ldhName" : "ns4.cat.xn--q9jyb4c", - "unicodeName" : "ns4.cat.みんな", - "status" : ["active"], - "events": [ - { - "eventAction": "registration", - "eventActor": "foo", - "eventDate": "1996-01-01T00:00:00.000Z" - } - ], - "links" : - [ - { - "value" : "http://myserver.google.com/nameserver/ns4.cat.xn--q9jyb4c", - "rel" : "self", - "href" : "http://myserver.google.com/nameserver/ns4.cat.xn--q9jyb4c", - "type" : "application/rdap+json" - } - ] - } - ], - "entities" : - [ - { - "objectClassName" : "entity", - "handle" : "4-ROID", - "status" : ["active"], - "roles" : ["administrative"], - "links" : - [ - { - "value" : "http://myserver.google.com/entity/4-ROID", - "rel" : "self", - "href" : "http://myserver.google.com/entity/4-ROID", - "type" : "application/rdap+json" - } - ], - "events": [ - { - "eventAction": "registration", - "eventActor": "foo", - "eventDate": "1998-01-01T00:00:00.000Z" - } - ], - "vcardArray" : - [ - "vcard", - [ - ["version", {}, "text", "4.0"], - ["fn", {}, "text", "Santa Claus"], - ["org", {}, "text", "GOOGLE INCORPORATED