From 21a98b899c688cb059bb6dc60caac829be0d22f8 Mon Sep 17 00:00:00 2001 From: mcilwain Date: Thu, 22 Sep 2016 11:45:58 -0700 Subject: [PATCH] Replace loadByUniqueId() with methods that don't overload unique id It is replaced by loadByForeignKey(), which does the same thing that loadByUniqueId() did for contacts, hosts, and domains, and also loadDomainApplication(), which loads domain application by ROID. This eliminates the ugly mode-switching of attemping to load by other foreign key or ROID. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=133980156 --- .../ExpandRecurringBillingEventsAction.java | 4 +- .../google/registry/dns/RefreshDnsAction.java | 4 +- .../dns/writer/clouddns/CloudDnsWriter.java | 6 +- .../dns/writer/dnsupdate/DnsUpdateWriter.java | 6 +- .../registry/flows/ResourceFlowUtils.java | 8 +- .../registry/flows/SingleResourceFlow.java | 16 +++- .../flows/domain/BaseDomainCreateFlow.java | 4 +- .../flows/domain/DomainAllocateFlow.java | 4 +- .../domain/DomainApplicationInfoFlow.java | 9 +- .../flows/domain/TldSpecificLogicProxy.java | 6 +- .../registry/flows/host/HostFlowUtils.java | 4 +- .../registry/model/EppResourceUtils.java | 57 ++++++------ .../registry/rdap/RdapDomainAction.java | 5 +- .../registry/rdap/RdapDomainSearchAction.java | 6 +- .../registry/rdap/RdapNameserverAction.java | 5 +- .../rdap/RdapNameserverSearchAction.java | 8 +- .../registry/tools/GetEppResourceCommand.java | 16 ++-- .../tools/UniformRapidSuspensionCommand.java | 4 +- .../tools/UpdateApplicationStatusCommand.java | 5 +- .../tools/UpdateClaimsNoticeCommand.java | 5 +- .../registry/tools/UpdateSmdCommand.java | 5 +- .../tools/javascrap/LoadAndResaveCommand.java | 20 +++-- .../whois/DomainOrHostLookupCommand.java | 4 +- .../registry/flows/ResourceFlowTestCase.java | 17 ++-- .../DeleteContactResourceActionTest.java | 24 ++--- .../DeleteContactsAndHostsActionTest.java | 50 ++++++----- .../DeleteEppResourceActionTestCase.java | 4 +- .../async/DeleteHostResourceActionTest.java | 30 +++---- .../flows/contact/ContactCreateFlowTest.java | 4 +- .../flows/contact/ContactDeleteFlowTest.java | 4 +- .../ContactTransferApproveFlowTest.java | 2 +- .../ContactTransferCancelFlowTest.java | 2 +- .../contact/ContactTransferQueryFlowTest.java | 2 +- .../ContactTransferRejectFlowTest.java | 2 +- .../ContactTransferRequestFlowTest.java | 2 +- .../flows/contact/ContactUpdateFlowTest.java | 10 +-- .../flows/domain/DomainAllocateFlowTest.java | 15 ++-- .../DomainApplicationDeleteFlowTest.java | 12 +-- .../DomainApplicationUpdateFlowTest.java | 26 +++--- .../flows/domain/DomainCreateFlowTest.java | 16 ++-- .../flows/domain/DomainDeleteFlowTest.java | 37 ++++---- .../flows/domain/DomainRenewFlowTest.java | 16 ++-- .../domain/DomainRestoreRequestFlowTest.java | 2 +- .../domain/DomainTransferApproveFlowTest.java | 18 ++-- .../domain/DomainTransferCancelFlowTest.java | 2 +- .../domain/DomainTransferFlowTestCase.java | 9 +- .../domain/DomainTransferRejectFlowTest.java | 2 +- .../domain/DomainTransferRequestFlowTest.java | 4 +- .../flows/domain/DomainUpdateFlowTest.java | 90 +++++++++---------- .../flows/host/HostCreateFlowTest.java | 12 +-- .../flows/host/HostDeleteFlowTest.java | 4 +- .../flows/host/HostUpdateFlowTest.java | 43 ++++----- .../inputs/ChildEntityInputTest.java | 4 +- .../model/contact/ContactResourceTest.java | 4 +- .../model/domain/DomainApplicationTest.java | 8 +- .../model/domain/DomainResourceTest.java | 4 +- .../registry/model/host/HostResourceTest.java | 15 ++-- 57 files changed, 367 insertions(+), 340 deletions(-) diff --git a/java/google/registry/billing/ExpandRecurringBillingEventsAction.java b/java/google/registry/billing/ExpandRecurringBillingEventsAction.java index 78dcd8c0e..4a23890e6 100644 --- a/java/google/registry/billing/ExpandRecurringBillingEventsAction.java +++ b/java/google/registry/billing/ExpandRecurringBillingEventsAction.java @@ -18,7 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.Sets.difference; import static google.registry.mapreduce.MapreduceRunner.PARAM_DRY_RUN; import static google.registry.mapreduce.inputs.EppResourceInputs.createChildEntityInput; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.common.Cursor.CursorType.RECURRING_BILLING; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost; @@ -158,7 +158,7 @@ public class ExpandRecurringBillingEventsAction implements Runnable { Iterable oneTimesForDomain = ofy().load() .type(OneTime.class) - .ancestor(loadByUniqueId( + .ancestor(loadByForeignKey( DomainResource.class, recurring.getTargetId(), executeTime)); // Determine the billing times that already have OneTime events persisted. diff --git a/java/google/registry/dns/RefreshDnsAction.java b/java/google/registry/dns/RefreshDnsAction.java index d8d55f5cb..6db9e5e04 100644 --- a/java/google/registry/dns/RefreshDnsAction.java +++ b/java/google/registry/dns/RefreshDnsAction.java @@ -14,7 +14,7 @@ package google.registry.dns; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import google.registry.dns.DnsConstants.TargetType; import google.registry.model.EppResource; @@ -58,7 +58,7 @@ public final class RefreshDnsAction implements Runnable { throw new BadRequestException("Unsupported type: " + type); } - EppResource eppResource = loadByUniqueId(clazz, domainOrHostName, clock.nowUtc()); + EppResource eppResource = loadByForeignKey(clazz, domainOrHostName, clock.nowUtc()); if (eppResource == null) { throw new NotFoundException( String.format("%s %s not found", type, domainOrHostName)); diff --git a/java/google/registry/dns/writer/clouddns/CloudDnsWriter.java b/java/google/registry/dns/writer/clouddns/CloudDnsWriter.java index de0089ae4..2eef8f997 100644 --- a/java/google/registry/dns/writer/clouddns/CloudDnsWriter.java +++ b/java/google/registry/dns/writer/clouddns/CloudDnsWriter.java @@ -15,7 +15,7 @@ package google.registry.dns.writer.clouddns; import static com.google.common.base.Preconditions.checkArgument; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; import com.google.api.client.googleapis.json.GoogleJsonResponseException; @@ -110,7 +110,7 @@ class CloudDnsWriter implements DnsWriter { // Load the target domain. Note that it can be null if this domain was just deleted. Optional domainResource = - Optional.fromNullable(loadByUniqueId(DomainResource.class, domainName, clock.nowUtc())); + Optional.fromNullable(loadByForeignKey(DomainResource.class, domainName, clock.nowUtc())); // Return early if no DNS records should be published. // desiredRecordsBuilder is populated with an empty set to indicate that all existing records @@ -180,7 +180,7 @@ class CloudDnsWriter implements DnsWriter { // desiredRecords is populated with an empty set to indicate that all existing records // should be deleted. Optional host = - Optional.fromNullable(loadByUniqueId(HostResource.class, hostName, clock.nowUtc())); + Optional.fromNullable(loadByForeignKey(HostResource.class, hostName, clock.nowUtc())); // Return early if the host is deleted. if (!host.isPresent()) { diff --git a/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriter.java b/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriter.java index 831735115..f0c3c5b23 100644 --- a/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriter.java +++ b/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriter.java @@ -17,7 +17,7 @@ package google.registry.dns.writer.dnsupdate; import static com.google.common.base.Verify.verify; import static com.google.common.collect.Sets.intersection; import static com.google.common.collect.Sets.union; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import com.google.common.base.Joiner; import com.google.common.base.Optional; @@ -111,7 +111,7 @@ public class DnsUpdateWriter implements DnsWriter { * this domain refresh request */ private void publishDomain(String domainName, String requestingHostName) { - DomainResource domain = loadByUniqueId(DomainResource.class, domainName, clock.nowUtc()); + DomainResource domain = loadByForeignKey(DomainResource.class, domainName, clock.nowUtc()); try { Update update = new Update(toAbsoluteName(findTldFromName(domainName))); update.delete(toAbsoluteName(domainName), Type.ANY); @@ -202,7 +202,7 @@ public class DnsUpdateWriter implements DnsWriter { for (String hostName : intersection( domain.loadNameserverFullyQualifiedHostNames(), domain.getSubordinateHosts())) { - HostResource host = loadByUniqueId(HostResource.class, hostName, clock.nowUtc()); + HostResource host = loadByForeignKey(HostResource.class, hostName, clock.nowUtc()); update.add(makeAddressSet(host)); update.add(makeV6AddressSet(host)); } diff --git a/java/google/registry/flows/ResourceFlowUtils.java b/java/google/registry/flows/ResourceFlowUtils.java index baec63d4f..6ff99745d 100644 --- a/java/google/registry/flows/ResourceFlowUtils.java +++ b/java/google/registry/flows/ResourceFlowUtils.java @@ -15,7 +15,7 @@ package google.registry.flows; import static com.google.common.base.Preconditions.checkState; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.queryDomainsUsingResource; import static google.registry.model.domain.DomainResource.extendRegistrationWithCap; import static google.registry.model.ofy.ObjectifyService.ofy; @@ -287,7 +287,7 @@ public class ResourceFlowUtils { public static R loadResourceForQuery( Class clazz, String targetId, DateTime now) throws ResourceToQueryDoesNotExistException { - R resource = loadByUniqueId(clazz, targetId, now); + R resource = loadByForeignKey(clazz, targetId, now); if (resource == null) { throw new ResourceToQueryDoesNotExistException(clazz, targetId); } @@ -296,7 +296,7 @@ public class ResourceFlowUtils { public static R loadResourceToMutate( Class clazz, String targetId, DateTime now) throws ResourceToMutateDoesNotExistException { - R resource = loadByUniqueId(clazz, targetId, now); + R resource = loadByForeignKey(clazz, targetId, now); if (resource == null) { throw new ResourceToMutateDoesNotExistException(clazz, targetId); } @@ -305,7 +305,7 @@ public class ResourceFlowUtils { public static void verifyResourceDoesNotExist( Class clazz, String targetId, DateTime now) throws EppException { - if (loadByUniqueId(clazz, targetId, now) != null) { + if (loadByForeignKey(clazz, targetId, now) != null) { throw new ResourceAlreadyExistsException(targetId); } } diff --git a/java/google/registry/flows/SingleResourceFlow.java b/java/google/registry/flows/SingleResourceFlow.java index f098e44be..16309b71f 100644 --- a/java/google/registry/flows/SingleResourceFlow.java +++ b/java/google/registry/flows/SingleResourceFlow.java @@ -14,13 +14,15 @@ package google.registry.flows; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; +import static google.registry.model.EppResourceUtils.loadDomainApplication; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import google.registry.flows.EppException.StatusProhibitsOperationException; import google.registry.model.EppResource; +import google.registry.model.domain.DomainApplication; import google.registry.model.domain.launch.ApplicationIdTargetExtension; import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppinput.ResourceCommand.SingleResourceCommand; @@ -38,6 +40,7 @@ public abstract class SingleResourceFlow problems = Sets.intersection( existingResource.getStatusValues(), getDisallowedStatuses()); diff --git a/java/google/registry/flows/domain/BaseDomainCreateFlow.java b/java/google/registry/flows/domain/BaseDomainCreateFlow.java index 3b619a561..273e338f1 100644 --- a/java/google/registry/flows/domain/BaseDomainCreateFlow.java +++ b/java/google/registry/flows/domain/BaseDomainCreateFlow.java @@ -32,7 +32,7 @@ import static google.registry.flows.domain.DomainFlowUtils.verifyPremiumNameIsNo import static google.registry.flows.domain.DomainFlowUtils.verifySignedMarks; import static google.registry.flows.domain.DomainFlowUtils.verifyUnitIsYears; import static google.registry.model.EppResourceUtils.createDomainRoid; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.domain.fee.Fee.FEE_CREATE_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.registry.Registries.findTldForName; @@ -164,7 +164,7 @@ public abstract class BaseDomainCreateFlowLoading an {@link EppResource} by itself is not sufficient to know its current state since * it may have various expirable conditions and status values that might implicitly change its - * state as time progresses even if it has not been updated in the datastore. Rather, the - * resource must be combined with a timestamp to view its current state. We use a global last - * updated timestamp on the entire entity group (which is essentially free since all writes to - * the entity group must be serialized anyways) to guarantee monotonically increasing write - * times, so forwarding our projected time to the greater of "now", and this update timestamp - * guarantees that we're not projecting into the past. + * state as time progresses even if it has not been updated in the datastore. Rather, the resource + * must be combined with a timestamp to view its current state. We use a global last updated + * timestamp on the entire entity group (which is essentially free since all writes to the entity + * group must be serialized anyways) to guarantee monotonically increasing write times, so + * forwarding our projected time to the greater of "now", and this update timestamp guarantees + * that we're not projecting into the past. * * @param clazz the resource type to load * @param foreignKey id to match * @param now the current logical time to project resources at */ - public static T loadByUniqueId( + @Nullable + public static T loadByForeignKey( Class clazz, String foreignKey, DateTime now) { - // For regular foreign-keyed resources, get the key by loading the FKI; for domain applications, - // we can construct the key directly, since the provided foreignKey is just the repoId. - Key resourceKey = ForeignKeyedEppResource.class.isAssignableFrom(clazz) - ? loadAndGetKey(clazz, foreignKey, now) - : Key.create(null, clazz, foreignKey); + checkArgument( + ForeignKeyedEppResource.class.isAssignableFrom(clazz), + "loadByForeignKey may only be called for foreign keyed EPP resources"); + Key resourceKey = loadAndGetKey(clazz, foreignKey, now); if (resourceKey == null) { return null; } T resource = ofy().load().key(resourceKey).now(); - if (resource == null - // You'd think this couldn't happen, but it can. For polymorphic entities, a Key is of - // necessity a reference to the base type (since datastore doesn't have polymorphism and - // Objectify is faking it). In the non-foreign-key code path above where we directly create - // a Key, there is no way to know whether the Key points to an instance of the desired - // subclass without loading it. Due to type erasure, it gets stuffed into "resource" without - // causing a ClassCastException even if it's the wrong type until you actually try to use it - // as the wrong type, at which point it blows up somewhere else in the code. Concretely, - // this means that without this line bad things would happen if you tried to load a - // DomainApplication using the id of a DomainResource (but not vice versa). - || !clazz.isInstance(resource) - || isAtOrAfter(now, resource.getDeletionTime())) { + if (resource == null || isAtOrAfter(now, resource.getDeletionTime())) { return null; } // When setting status values based on a time, choose the greater of "now" and the resource's @@ -127,8 +117,23 @@ public final class EppResourceUtils { // fail when it tries to save anything via Ofy, since "now" is needed to be > the last update // time for writes. return cloneProjectedAtTime( - resource, - latestOf(now, resource.getUpdateAutoTimestamp().getTimestamp())); + resource, latestOf(now, resource.getUpdateAutoTimestamp().getTimestamp())); + } + + /** + * Returns the domain application with the given application id if it exists, or null if it does + * not or is soft-deleted as of the given time. + */ + @Nullable + public static DomainApplication loadDomainApplication(String applicationId, DateTime now) { + DomainApplication application = + ofy().load().key(Key.create(DomainApplication.class, applicationId)).now(); + if (application == null || isAtOrAfter(now, application.getDeletionTime())) { + return null; + } + // Applications don't have any speculative changes that become effective later, so no need to + // clone forward in time. + return application; } /** diff --git a/java/google/registry/rdap/RdapDomainAction.java b/java/google/registry/rdap/RdapDomainAction.java index f8e176dc5..63c2162ea 100644 --- a/java/google/registry/rdap/RdapDomainAction.java +++ b/java/google/registry/rdap/RdapDomainAction.java @@ -14,7 +14,7 @@ package google.registry.rdap; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.request.Action.Method.GET; import static google.registry.request.Action.Method.HEAD; @@ -55,8 +55,7 @@ public class RdapDomainAction extends RdapActionBase { pathSearchString = canonicalizeName(pathSearchString); validateDomainName(pathSearchString); // The query string is not used; the RDAP syntax is /rdap/domain/mydomain.com. - DomainResource domainResource = - loadByUniqueId(DomainResource.class, pathSearchString, now); + DomainResource domainResource = loadByForeignKey(DomainResource.class, pathSearchString, now); if (domainResource == null) { throw new NotFoundException(pathSearchString + " not found"); } diff --git a/java/google/registry/rdap/RdapDomainSearchAction.java b/java/google/registry/rdap/RdapDomainSearchAction.java index cc956b8de..5cdad874a 100644 --- a/java/google/registry/rdap/RdapDomainSearchAction.java +++ b/java/google/registry/rdap/RdapDomainSearchAction.java @@ -14,7 +14,7 @@ package google.registry.rdap; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.index.ForeignKeyIndex.loadAndGetKey; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.request.Action.Method.GET; @@ -136,7 +136,7 @@ public class RdapDomainSearchAction extends RdapActionBase { // Handle queries without a wildcard -- just load by foreign key. if (!partialStringQuery.getHasWildcard()) { DomainResource domainResource = - loadByUniqueId(DomainResource.class, partialStringQuery.getInitialString(), now); + loadByForeignKey(DomainResource.class, partialStringQuery.getInitialString(), now); if (domainResource == null) { return ImmutableList.of(); } @@ -222,7 +222,7 @@ public class RdapDomainSearchAction extends RdapActionBase { // differently. We use the suffix to look up the domain, then loop through the subordinate hosts // looking for matches. } else { - DomainResource domainResource = loadByUniqueId( + DomainResource domainResource = loadByForeignKey( DomainResource.class, partialStringQuery.getSuffix(), now); if (domainResource == null) { throw new NotFoundException("No domain found for specified nameserver suffix"); diff --git a/java/google/registry/rdap/RdapNameserverAction.java b/java/google/registry/rdap/RdapNameserverAction.java index 92870aa87..6dc9816d2 100644 --- a/java/google/registry/rdap/RdapNameserverAction.java +++ b/java/google/registry/rdap/RdapNameserverAction.java @@ -14,7 +14,7 @@ package google.registry.rdap; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.request.Action.Method.GET; import static google.registry.request.Action.Method.HEAD; @@ -55,8 +55,7 @@ public class RdapNameserverAction extends RdapActionBase { pathSearchString = canonicalizeName(pathSearchString); // The RDAP syntax is /rdap/nameserver/ns1.mydomain.com. validateDomainName(pathSearchString); - HostResource hostResource = - loadByUniqueId(HostResource.class, pathSearchString, now); + HostResource hostResource = loadByForeignKey(HostResource.class, pathSearchString, now); if (hostResource == null) { throw new NotFoundException(pathSearchString + " not found"); } diff --git a/java/google/registry/rdap/RdapNameserverSearchAction.java b/java/google/registry/rdap/RdapNameserverSearchAction.java index 263d13a47..0d6530098 100644 --- a/java/google/registry/rdap/RdapNameserverSearchAction.java +++ b/java/google/registry/rdap/RdapNameserverSearchAction.java @@ -14,7 +14,7 @@ package google.registry.rdap; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.request.Action.Method.GET; import static google.registry.request.Action.Method.HEAD; @@ -118,7 +118,7 @@ public class RdapNameserverSearchAction extends RdapActionBase { // Handle queries without a wildcard -- just load by foreign key. if (!partialStringQuery.getHasWildcard()) { HostResource hostResource = - loadByUniqueId(HostResource.class, partialStringQuery.getInitialString(), now); + loadByForeignKey(HostResource.class, partialStringQuery.getInitialString(), now); if (hostResource == null) { throw new NotFoundException("No nameservers found"); } @@ -141,7 +141,7 @@ public class RdapNameserverSearchAction extends RdapActionBase { // looking for matches. } else { DomainResource domainResource = - loadByUniqueId(DomainResource.class, partialStringQuery.getSuffix(), now); + loadByForeignKey(DomainResource.class, partialStringQuery.getSuffix(), now); if (domainResource == null) { throw new NotFoundException("No domain found for specified nameserver suffix"); } @@ -150,7 +150,7 @@ public class RdapNameserverSearchAction extends RdapActionBase { // We can't just check that the host name starts with the initial query string, because then // the query ns.exam*.example.com would match against nameserver ns.example.com. if (partialStringQuery.matches(fqhn)) { - HostResource hostResource = loadByUniqueId(HostResource.class, fqhn, now); + HostResource hostResource = loadByForeignKey(HostResource.class, fqhn, now); if (hostResource != null) { hostListBuilder.add(hostResource); } diff --git a/java/google/registry/tools/GetEppResourceCommand.java b/java/google/registry/tools/GetEppResourceCommand.java index ddb835631..ed4f240ee 100644 --- a/java/google/registry/tools/GetEppResourceCommand.java +++ b/java/google/registry/tools/GetEppResourceCommand.java @@ -15,13 +15,15 @@ package google.registry.tools; import static com.google.common.base.Preconditions.checkArgument; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; +import static google.registry.model.EppResourceUtils.loadDomainApplication; import static org.joda.time.DateTimeZone.UTC; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.googlecode.objectify.Key; import google.registry.model.EppResource; +import google.registry.model.domain.DomainApplication; import google.registry.tools.Command.RemoteApiCommand; import google.registry.util.TypeUtils.TypeInstantiator; import org.joda.time.DateTime; @@ -32,8 +34,7 @@ import org.joda.time.DateTime; * @param {@link EppResource} subclass. */ @Parameters(separators = " =") -abstract class GetEppResourceCommand - implements RemoteApiCommand { +abstract class GetEppResourceCommand implements RemoteApiCommand { private final DateTime now = DateTime.now(UTC); @@ -52,14 +53,17 @@ abstract class GetEppResourceCommand /** Resolve any parameters into ids for loadResource. */ abstract void processParameters(); - /** + /** * Load a resource by ID and output. Append the websafe key to the output for use in e.g. * manual mapreduce calls. */ void printResource(String uniqueId) { - R resource = loadByUniqueId(clazz, uniqueId, readTimestamp); + EppResource resource = + (clazz == DomainApplication.class) + ? loadDomainApplication(uniqueId, readTimestamp) + : loadByForeignKey(clazz, uniqueId, readTimestamp); System.out.println(resource != null - ? String.format("%s\n\nWebsafe key: %s", + ? String.format("%s\n\nWebsafe key: %s", expand ? resource.toHydratedString() : resource, Key.create(resource).getString()) : String.format( diff --git a/java/google/registry/tools/UniformRapidSuspensionCommand.java b/java/google/registry/tools/UniformRapidSuspensionCommand.java index c240fbafa..d7e193e79 100644 --- a/java/google/registry/tools/UniformRapidSuspensionCommand.java +++ b/java/google/registry/tools/UniformRapidSuspensionCommand.java @@ -18,7 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.collect.Sets.difference; import static google.registry.model.EppResourceUtils.checkResourcesExist; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.ofy.ObjectifyService.ofy; import static org.joda.time.DateTimeZone.UTC; @@ -120,7 +120,7 @@ final class UniformRapidSuspensionCommand extends MutatingEppToolCommand impleme } catch (ClassCastException | ParseException e) { throw new IllegalArgumentException("Invalid --dsdata JSON", e); } - DomainResource domain = loadByUniqueId(DomainResource.class, domainName, now); + DomainResource domain = loadByForeignKey(DomainResource.class, domainName, now); checkArgument(domain != null, "Domain '%s' does not exist", domainName); Set missingHosts = difference(newHostsSet, checkResourcesExist(HostResource.class, newHosts, now)); diff --git a/java/google/registry/tools/UpdateApplicationStatusCommand.java b/java/google/registry/tools/UpdateApplicationStatusCommand.java index dfb0eb617..551f3230f 100644 --- a/java/google/registry/tools/UpdateApplicationStatusCommand.java +++ b/java/google/registry/tools/UpdateApplicationStatusCommand.java @@ -16,7 +16,7 @@ package google.registry.tools; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadDomainApplication; import static google.registry.model.domain.launch.ApplicationStatus.ALLOCATED; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; @@ -89,8 +89,7 @@ final class UpdateApplicationStatusCommand extends MutatingCommand { DateTime now = ofy().getTransactionTime(); // Load the domain application. - DomainApplication domainApplication = - loadByUniqueId(DomainApplication.class, applicationId, now); + DomainApplication domainApplication = loadDomainApplication(applicationId, now); checkArgumentNotNull(domainApplication, "Domain application does not exist"); // It's not an error if the application already has the intended status. We want the method diff --git a/java/google/registry/tools/UpdateClaimsNoticeCommand.java b/java/google/registry/tools/UpdateClaimsNoticeCommand.java index 98a23c2e0..e6c2d8b37 100644 --- a/java/google/registry/tools/UpdateClaimsNoticeCommand.java +++ b/java/google/registry/tools/UpdateClaimsNoticeCommand.java @@ -15,7 +15,7 @@ package google.registry.tools; import static com.google.common.base.Preconditions.checkArgument; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadDomainApplication; import static google.registry.model.ofy.ObjectifyService.ofy; import com.beust.jcommander.Parameter; @@ -84,8 +84,7 @@ final class UpdateClaimsNoticeCommand implements RemoteApiCommand { DateTime now = ofy().getTransactionTime(); // Load the domain application. - DomainApplication domainApplication = - loadByUniqueId(DomainApplication.class, applicationId, now); + DomainApplication domainApplication = loadDomainApplication(applicationId, now); checkArgument(domainApplication != null, "Domain application does not exist"); // Make sure this isn't a sunrise application. diff --git a/java/google/registry/tools/UpdateSmdCommand.java b/java/google/registry/tools/UpdateSmdCommand.java index b05649815..f2b86d678 100644 --- a/java/google/registry/tools/UpdateSmdCommand.java +++ b/java/google/registry/tools/UpdateSmdCommand.java @@ -16,7 +16,7 @@ package google.registry.tools; import static com.google.common.base.Preconditions.checkArgument; import static google.registry.flows.domain.DomainFlowUtils.verifyEncodedSignedMark; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadDomainApplication; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.tmch.TmchData.readEncodedSignedMark; import static java.nio.charset.StandardCharsets.US_ASCII; @@ -81,8 +81,7 @@ final class UpdateSmdCommand implements RemoteApiCommand { DateTime now = ofy().getTransactionTime(); // Load the domain application. - DomainApplication domainApplication = - loadByUniqueId(DomainApplication.class, applicationId, now); + DomainApplication domainApplication = loadDomainApplication(applicationId, now); checkArgument(domainApplication != null, "Domain application does not exist"); // Make sure this is a sunrise application. diff --git a/java/google/registry/tools/javascrap/LoadAndResaveCommand.java b/java/google/registry/tools/javascrap/LoadAndResaveCommand.java index 368f5d14f..ef25d6c88 100644 --- a/java/google/registry/tools/javascrap/LoadAndResaveCommand.java +++ b/java/google/registry/tools/javascrap/LoadAndResaveCommand.java @@ -15,7 +15,8 @@ package google.registry.tools.javascrap; import static com.google.common.collect.Maps.uniqueIndex; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; +import static google.registry.model.EppResourceUtils.loadDomainApplication; import static google.registry.model.ofy.ObjectifyService.ofy; import static org.joda.time.DateTimeZone.UTC; @@ -32,7 +33,7 @@ import java.util.Arrays; import java.util.Map; import org.joda.time.DateTime; -/** Load and resave an object in the probers, to trigger @OnSave changes. */ +/** A command to load and resave an entity, which triggers @OnSave changes. */ @Parameters( separators = " =", commandDescription = "Load and resave an object, to trigger @OnSave changes") @@ -45,9 +46,9 @@ public final class LoadAndResaveCommand extends MutatingCommand { protected String type; @Parameter( - names = "--key", - description = "Foreign key of the resource. ") - protected String foreignKey; + names = "--id", + description = "Foreign key of the resource, or application ID of the domain application.") + protected String uniqueId; private static final Map> CLASSES_BY_NAME = uniqueIndex( @@ -64,12 +65,15 @@ public final class LoadAndResaveCommand extends MutatingCommand { @Override protected void init() throws Exception { + Class clazz = CLASSES_BY_NAME.get(type); + EppResource existing = + (clazz == DomainApplication.class) + ? loadDomainApplication(uniqueId, DateTime.now(UTC)) + : loadByForeignKey(clazz, uniqueId, DateTime.now(UTC)); // Find the resource by foreign key, and then reload it directly, bypassing loadByUniqueId(). // We need to do a reload because otherwise stageEntityChange() can fail due to the implicit // changes done when forwarding the resource to "now" in cloneProjectedAtTime(). - EppResource resource = ofy().load().entity( - loadByUniqueId(CLASSES_BY_NAME.get(type), foreignKey, DateTime.now(UTC))).now(); + EppResource resource = ofy().load().entity(existing).now(); stageEntityChange(resource, resource); } } - diff --git a/java/google/registry/whois/DomainOrHostLookupCommand.java b/java/google/registry/whois/DomainOrHostLookupCommand.java index 845151727..3f1def99a 100644 --- a/java/google/registry/whois/DomainOrHostLookupCommand.java +++ b/java/google/registry/whois/DomainOrHostLookupCommand.java @@ -15,7 +15,7 @@ package google.registry.whois; import static com.google.common.base.Preconditions.checkNotNull; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.registry.Registries.findTldForName; import static google.registry.model.registry.Registries.getTlds; import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND; @@ -52,7 +52,7 @@ abstract class DomainOrHostLookupCommand implements Whois } // Google Policy: Do not return records under TLDs for which we're not authoritative. if (tld.isPresent() && getTlds().contains(tld.get().toString())) { - T domainOrHost = loadByUniqueId( + T domainOrHost = loadByForeignKey( new TypeInstantiator(getClass()){}.getExactType(), domainOrHostName.toString(), now); diff --git a/javatests/google/registry/flows/ResourceFlowTestCase.java b/javatests/google/registry/flows/ResourceFlowTestCase.java index 960d8428d..32c7a51fc 100644 --- a/javatests/google/registry/flows/ResourceFlowTestCase.java +++ b/javatests/google/registry/flows/ResourceFlowTestCase.java @@ -15,7 +15,7 @@ package google.registry.flows; import static com.google.common.truth.Truth.assertThat; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.tmch.ClaimsListShardTest.createTestClaimsListShard; import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued; @@ -27,6 +27,8 @@ import com.google.common.collect.ImmutableMap; import com.googlecode.objectify.Key; import google.registry.flows.EppException.CommandUseErrorException; import google.registry.model.EppResource; +import google.registry.model.EppResourceUtils; +import google.registry.model.domain.DomainApplication; import google.registry.model.domain.launch.ApplicationIdTargetExtension; import google.registry.model.eppinput.EppInput.ResourceCommandWrapper; import google.registry.model.eppinput.ResourceCommand; @@ -54,19 +56,20 @@ public abstract class ResourceFlowTestCase T reloadResourceAndCloneAtTime(T resource, DateTime now) { diff --git a/javatests/google/registry/flows/async/DeleteContactResourceActionTest.java b/javatests/google/registry/flows/async/DeleteContactResourceActionTest.java index 170167a75..887231666 100644 --- a/javatests/google/registry/flows/async/DeleteContactResourceActionTest.java +++ b/javatests/google/registry/flows/async/DeleteContactResourceActionTest.java @@ -15,7 +15,7 @@ package google.registry.flows.async; import static com.google.common.truth.Truth.assertThat; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.ContactResourceSubject.assertAboutContacts; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; @@ -70,10 +70,10 @@ public class DeleteContactResourceActionTest .addStatusValue(StatusValue.PENDING_DELETE) .build()); runMapreduceWithKeyParam(Key.create(contactUsed).getString()); - contactUsed = loadByUniqueId(ContactResource.class, "blah1234", now); + contactUsed = loadByForeignKey(ContactResource.class, "blah1234", now); assertAboutContacts().that(contactUsed).doesNotHaveStatusValue(StatusValue.PENDING_DELETE) .and().hasDeletionTime(END_OF_TIME); - domain = loadByUniqueId(DomainResource.class, "example.tld", now); + domain = loadByForeignKey(DomainResource.class, "example.tld", now); assertThat(domain.getReferencedContacts()).contains(Key.create(contactUsed)); HistoryEntry historyEntry = getOnlyHistoryEntryOfType(contactUsed, HistoryEntry.Type.CONTACT_DELETE_FAILURE); @@ -113,7 +113,7 @@ public class DeleteContactResourceActionTest .and().hasNonNullFaxNumber(); Key key = Key.create(contactUnused); runMapreduceWithKeyParam(key.getString()); - assertThat(loadByUniqueId(ContactResource.class, "blah1235", now)).isNull(); + assertThat(loadByForeignKey(ContactResource.class, "blah1235", now)).isNull(); ContactResource contactAfterDeletion = ofy().load().key(key).now(); assertAboutContacts().that(contactAfterDeletion).hasDeletionTime(now) // Note that there will be another history entry of CONTACT_PENDING_DELETE, but this is @@ -140,10 +140,10 @@ public class DeleteContactResourceActionTest clock.nowUtc()); runMapreduceWithKeyParam(Key.create(contact).getString()); // Check that the contact is deleted as of now. - assertThat(loadByUniqueId(ContactResource.class, "sh8013", now)).isNull(); + assertThat(loadByForeignKey(ContactResource.class, "sh8013", now)).isNull(); // Check that it's still there (it wasn't deleted yesterday) and that it has history. assertAboutContacts() - .that(loadByUniqueId(ContactResource.class, "sh8013", now.minusDays(1))) + .that(loadByForeignKey(ContactResource.class, "sh8013", now.minusDays(1))) .hasOneHistoryEntryEachOfTypes( HistoryEntry.Type.CONTACT_TRANSFER_REQUEST, HistoryEntry.Type.CONTACT_DELETE); @@ -181,9 +181,9 @@ public class DeleteContactResourceActionTest .setDeletionTime(now.minusDays(3)) .build()); runMapreduceWithKeyParam(Key.create(contactUsed).getString()); - assertThat(loadByUniqueId(ContactResource.class, "blah1234", now)).isNull(); + assertThat(loadByForeignKey(ContactResource.class, "blah1234", now)).isNull(); ContactResource contactBeforeDeletion = - loadByUniqueId(ContactResource.class, "blah1234", now.minusDays(1)); + loadByForeignKey(ContactResource.class, "blah1234", now.minusDays(1)); assertAboutContacts().that(contactBeforeDeletion).hasDeletionTime(now) .and().hasExactlyStatusValues(StatusValue.OK) // Note that there will be another history entry of CONTACT_PENDING_DELETE, but this is @@ -199,7 +199,7 @@ public class DeleteContactResourceActionTest thrown.expect(IllegalStateException.class, "Resource blah1235 is not set as PENDING_DELETE"); runMapreduceWithKeyParam(Key.create(contactUnused).getString()); assertThat( - loadByUniqueId(ContactResource.class, "blah1235", now)).isEqualTo(contactUnused); + loadByForeignKey(ContactResource.class, "blah1235", now)).isEqualTo(contactUnused); } @Test @@ -210,10 +210,10 @@ public class DeleteContactResourceActionTest .build()); Key key = Key.create(contactUnused); runMapreduceWithParams(key.getString(), "OtherRegistrar", false); - contactUnused = loadByUniqueId(ContactResource.class, "blah1235", now); + contactUnused = loadByForeignKey(ContactResource.class, "blah1235", now); assertAboutContacts().that(contactUnused).doesNotHaveStatusValue(StatusValue.PENDING_DELETE) .and().hasDeletionTime(END_OF_TIME); - domain = loadByUniqueId(DomainResource.class, "example.tld", now); + domain = loadByForeignKey(DomainResource.class, "example.tld", now); HistoryEntry historyEntry = getOnlyHistoryEntryOfType(contactUnused, HistoryEntry.Type.CONTACT_DELETE_FAILURE); assertPollMessageFor( @@ -247,7 +247,7 @@ public class DeleteContactResourceActionTest .build()); Key key = Key.create(contactUnused); runMapreduceWithParams(key.getString(), "OtherRegistrar", true); - assertThat(loadByUniqueId(ContactResource.class, "blah1235", now)).isNull(); + assertThat(loadByForeignKey(ContactResource.class, "blah1235", now)).isNull(); ContactResource contactAfterDeletion = ofy().load().key(key).now(); assertAboutContacts().that(contactAfterDeletion).hasDeletionTime(now) // Note that there will be another history entry of CONTACT_PENDING_DELETE, but this is diff --git a/javatests/google/registry/flows/async/DeleteContactsAndHostsActionTest.java b/javatests/google/registry/flows/async/DeleteContactsAndHostsActionTest.java index 6b11abd8a..11c64e883 100644 --- a/javatests/google/registry/flows/async/DeleteContactsAndHostsActionTest.java +++ b/javatests/google/registry/flows/async/DeleteContactsAndHostsActionTest.java @@ -19,7 +19,7 @@ import static com.google.appengine.api.taskqueue.QueueFactory.getQueue; import static com.google.common.collect.Iterables.getOnlyElement; import static com.google.common.truth.Truth.assertThat; import static google.registry.flows.async.DeleteContactsAndHostsAction.QUEUE_ASYNC_DELETE; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.eppcommon.StatusValue.PENDING_DELETE; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.reporting.HistoryEntry.Type.CONTACT_DELETE; @@ -154,14 +154,14 @@ public class DeleteContactsAndHostsActionTest enqueuer.enqueueAsyncDelete(contact, "TheRegistrar", false); runMapreduce(); ContactResource contactUpdated = - loadByUniqueId(ContactResource.class, "blah8221", clock.nowUtc()); + loadByForeignKey(ContactResource.class, "blah8221", clock.nowUtc()); assertAboutContacts() .that(contactUpdated) .doesNotHaveStatusValue(PENDING_DELETE) .and() .hasDeletionTime(END_OF_TIME); DomainResource domainReloaded = - loadByUniqueId(DomainResource.class, "example.tld", clock.nowUtc()); + loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc()); assertThat(domainReloaded.getReferencedContacts()).contains(Key.create(contactUpdated)); HistoryEntry historyEntry = getOnlyHistoryEntryOfType(contactUpdated, HistoryEntry.Type.CONTACT_DELETE_FAILURE); @@ -176,7 +176,7 @@ public class DeleteContactsAndHostsActionTest ContactResource contact = persistContactWithPii("jim919"); enqueuer.enqueueAsyncDelete(contact, "TheRegistrar", false); runMapreduce(); - assertThat(loadByUniqueId(ContactResource.class, "jim919", clock.nowUtc())).isNull(); + assertThat(loadByForeignKey(ContactResource.class, "jim919", clock.nowUtc())).isNull(); ContactResource contactAfterDeletion = ofy().load().entity(contact).now(); assertAboutContacts() .that(contactAfterDeletion) @@ -213,10 +213,10 @@ public class DeleteContactsAndHostsActionTest enqueuer.enqueueAsyncDelete(contact, "TheRegistrar", false); runMapreduce(); // Check that the contact is deleted as of now. - assertThat(loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc())).isNull(); + assertThat(loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc())).isNull(); // Check that it's still there (it wasn't deleted yesterday) and that it has history. assertAboutContacts() - .that(loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc().minusDays(1))) + .that(loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc().minusDays(1))) .hasOneHistoryEntryEachOfTypes(CONTACT_TRANSFER_REQUEST, CONTACT_DELETE); assertNoBillingEvents(); PollMessage deletePollMessage = @@ -252,9 +252,9 @@ public class DeleteContactsAndHostsActionTest .build()); enqueuer.enqueueAsyncDelete(contactUsed, "TheRegistrar", false); runMapreduce(); - assertThat(loadByUniqueId(ContactResource.class, "blah1234", clock.nowUtc())).isNull(); + assertThat(loadByForeignKey(ContactResource.class, "blah1234", clock.nowUtc())).isNull(); ContactResource contactBeforeDeletion = - loadByUniqueId(ContactResource.class, "blah1234", clock.nowUtc().minusDays(1)); + loadByForeignKey(ContactResource.class, "blah1234", clock.nowUtc().minusDays(1)); assertAboutContacts() .that(contactBeforeDeletion) .isNotActiveAt(clock.nowUtc()) @@ -276,9 +276,9 @@ public class DeleteContactsAndHostsActionTest enqueuer.enqueueAsyncDelete(contact, "TheRegistrar", false); enqueuer.enqueueAsyncDelete(host, "TheRegistrar", false); runMapreduce(); - assertThat(loadByUniqueId(ContactResource.class, "blah2222", clock.nowUtc())) + assertThat(loadByForeignKey(ContactResource.class, "blah2222", clock.nowUtc())) .isEqualTo(contact); - assertThat(loadByUniqueId(HostResource.class, "rustles.your.jimmies", clock.nowUtc())) + assertThat(loadByForeignKey(HostResource.class, "rustles.your.jimmies", clock.nowUtc())) .isEqualTo(host); } @@ -288,7 +288,7 @@ public class DeleteContactsAndHostsActionTest enqueuer.enqueueAsyncDelete(contact, "OtherRegistrar", false); runMapreduce(); ContactResource contactAfter = - loadByUniqueId(ContactResource.class, "jane0991", clock.nowUtc()); + loadByForeignKey(ContactResource.class, "jane0991", clock.nowUtc()); assertAboutContacts() .that(contactAfter) .doesNotHaveStatusValue(PENDING_DELETE) @@ -306,7 +306,7 @@ public class DeleteContactsAndHostsActionTest ContactResource contact = persistContactWithPii("nate007"); enqueuer.enqueueAsyncDelete(contact, "OtherRegistrar", true); runMapreduce(); - assertThat(loadByUniqueId(ContactResource.class, "nate007", clock.nowUtc())).isNull(); + assertThat(loadByForeignKey(ContactResource.class, "nate007", clock.nowUtc())).isNull(); ContactResource contactAfterDeletion = ofy().load().entity(contact).now(); assertAboutContacts() .that(contactAfterDeletion) @@ -357,13 +357,14 @@ public class DeleteContactsAndHostsActionTest persistUsedDomain("example.tld", persistActiveContact("abc456"), host); enqueuer.enqueueAsyncDelete(host, "TheRegistrar", false); runMapreduce(); - HostResource hostAfter = loadByUniqueId(HostResource.class, "ns1.example.tld", clock.nowUtc()); + HostResource hostAfter = + loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc()); assertAboutHosts() .that(hostAfter) .doesNotHaveStatusValue(PENDING_DELETE) .and() .hasDeletionTime(END_OF_TIME); - DomainResource domain = loadByUniqueId(DomainResource.class, "example.tld", clock.nowUtc()); + DomainResource domain = loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc()); assertThat(domain.getNameservers()).contains(Key.create(hostAfter)); HistoryEntry historyEntry = getOnlyHistoryEntryOfType(hostAfter, HOST_DELETE_FAILURE); assertPollMessageFor( @@ -377,9 +378,9 @@ public class DeleteContactsAndHostsActionTest HostResource host = persistHostPendingDelete("ns2.example.tld"); enqueuer.enqueueAsyncDelete(host, "TheRegistrar", false); runMapreduce(); - assertThat(loadByUniqueId(HostResource.class, "ns2.example.tld", clock.nowUtc())).isNull(); + assertThat(loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc())).isNull(); HostResource hostBeforeDeletion = - loadByUniqueId(HostResource.class, "ns2.example.tld", clock.nowUtc().minusDays(1)); + loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc().minusDays(1)); assertAboutHosts() .that(hostBeforeDeletion) .isNotActiveAt(clock.nowUtc()) @@ -405,9 +406,9 @@ public class DeleteContactsAndHostsActionTest .build()); enqueuer.enqueueAsyncDelete(host, "TheRegistrar", false); runMapreduce(); - assertThat(loadByUniqueId(HostResource.class, "ns1.example.tld", clock.nowUtc())).isNull(); + assertThat(loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())).isNull(); HostResource hostBeforeDeletion = - loadByUniqueId(HostResource.class, "ns1.example.tld", clock.nowUtc().minusDays(1)); + loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc().minusDays(1)); assertAboutHosts() .that(hostBeforeDeletion) .isNotActiveAt(clock.nowUtc()) @@ -439,15 +440,15 @@ public class DeleteContactsAndHostsActionTest enqueuer.enqueueAsyncDelete(host, "TheRegistrar", false); runMapreduce(); // Check that the host is deleted as of now. - assertThat(loadByUniqueId(HostResource.class, "ns2.example.tld", clock.nowUtc())).isNull(); + assertThat(loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc())).isNull(); assertNoBillingEvents(); assertThat( - loadByUniqueId(DomainResource.class, "example.tld", clock.nowUtc()) + loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc()) .getSubordinateHosts()) .isEmpty(); assertDnsTasksEnqueued("ns2.example.tld"); HostResource hostBeforeDeletion = - loadByUniqueId(HostResource.class, "ns2.example.tld", clock.nowUtc().minusDays(1)); + loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc().minusDays(1)); assertAboutHosts() .that(hostBeforeDeletion) .isNotActiveAt(clock.nowUtc()) @@ -465,7 +466,8 @@ public class DeleteContactsAndHostsActionTest HostResource host = persistHostPendingDelete("ns2.example.tld"); enqueuer.enqueueAsyncDelete(host, "OtherRegistrar", false); runMapreduce(); - HostResource hostAfter = loadByUniqueId(HostResource.class, "ns2.example.tld", clock.nowUtc()); + HostResource hostAfter = + loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc()); assertAboutHosts() .that(hostAfter) .doesNotHaveStatusValue(PENDING_DELETE) @@ -483,9 +485,9 @@ public class DeleteContactsAndHostsActionTest HostResource host = persistHostPendingDelete("ns66.example.tld"); enqueuer.enqueueAsyncDelete(host, "OtherRegistrar", true); runMapreduce(); - assertThat(loadByUniqueId(HostResource.class, "ns66.example.tld", clock.nowUtc())).isNull(); + assertThat(loadByForeignKey(HostResource.class, "ns66.example.tld", clock.nowUtc())).isNull(); HostResource hostBeforeDeletion = - loadByUniqueId(HostResource.class, "ns66.example.tld", clock.nowUtc().minusDays(1)); + loadByForeignKey(HostResource.class, "ns66.example.tld", clock.nowUtc().minusDays(1)); assertAboutHosts() .that(hostBeforeDeletion) .isNotActiveAt(clock.nowUtc()) diff --git a/javatests/google/registry/flows/async/DeleteEppResourceActionTestCase.java b/javatests/google/registry/flows/async/DeleteEppResourceActionTestCase.java index b62c45a46..e89c890e0 100644 --- a/javatests/google/registry/flows/async/DeleteEppResourceActionTestCase.java +++ b/javatests/google/registry/flows/async/DeleteEppResourceActionTestCase.java @@ -15,7 +15,7 @@ package google.registry.flows.async; import static com.google.common.truth.Truth.assertThat; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.getOnlyPollMessageForHistoryEntry; @@ -127,7 +127,7 @@ public abstract class DeleteEppResourceActionTestCase key = Key.create(hostUnused); runMapreduceWithParams(key.getString(), "OtherRegistrar", false); - hostUnused = loadByUniqueId(HostResource.class, "ns2.example.tld", now); + hostUnused = loadByForeignKey(HostResource.class, "ns2.example.tld", now); assertAboutHosts().that(hostUnused).doesNotHaveStatusValue(StatusValue.PENDING_DELETE) .and().hasDeletionTime(END_OF_TIME); - domain = loadByUniqueId(DomainResource.class, "example.tld", now); + domain = loadByForeignKey(DomainResource.class, "example.tld", now); HistoryEntry historyEntry = getOnlyHistoryEntryOfType(hostUnused, HistoryEntry.Type.HOST_DELETE_FAILURE); assertPollMessageFor( @@ -183,9 +183,9 @@ public class DeleteHostResourceActionTest .build()); Key key = Key.create(hostUnused); runMapreduceWithParams(key.getString(), "OtherRegistrar", true); - assertThat(loadByUniqueId(HostResource.class, "ns2.example.tld", now)).isNull(); + assertThat(loadByForeignKey(HostResource.class, "ns2.example.tld", now)).isNull(); HostResource hostBeforeDeletion = - loadByUniqueId(HostResource.class, "ns2.example.tld", now.minusDays(1)); + loadByForeignKey(HostResource.class, "ns2.example.tld", now.minusDays(1)); assertAboutHosts().that(hostBeforeDeletion).hasDeletionTime(now) .and().hasExactlyStatusValues(StatusValue.OK) // Note that there will be another history entry of HOST_PENDING_DELETE, but this is diff --git a/javatests/google/registry/flows/contact/ContactCreateFlowTest.java b/javatests/google/registry/flows/contact/ContactCreateFlowTest.java index 26e1f0435..2fecdb486 100644 --- a/javatests/google/registry/flows/contact/ContactCreateFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactCreateFlowTest.java @@ -40,10 +40,10 @@ public class ContactCreateFlowTest assertTransactionalFlow(true); runFlowAssertResponse(readFile("contact_create_response.xml")); // Check that the contact was created and persisted with a history entry. - assertAboutContacts().that(reloadResourceByUniqueId()) + assertAboutContacts().that(reloadResourceByForeignKey()) .hasOnlyOneHistoryEntryWhich().hasNoXml(); assertNoBillingEvents(); - assertEppResourceIndexEntityFor(reloadResourceByUniqueId()); + assertEppResourceIndexEntityFor(reloadResourceByForeignKey()); } @Test diff --git a/javatests/google/registry/flows/contact/ContactDeleteFlowTest.java b/javatests/google/registry/flows/contact/ContactDeleteFlowTest.java index dba86026e..c121a54fd 100644 --- a/javatests/google/registry/flows/contact/ContactDeleteFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactDeleteFlowTest.java @@ -66,7 +66,7 @@ public class ContactDeleteFlowTest clock.advanceOneMilli(); assertTransactionalFlow(true); runFlowAssertResponse(readFile("contact_delete_response.xml")); - ContactResource deletedContact = reloadResourceByUniqueId(); + ContactResource deletedContact = reloadResourceByForeignKey(); assertAboutContacts().that(deletedContact).hasStatusValue(StatusValue.PENDING_DELETE); assertAsyncDeletionTaskEnqueued(deletedContact, "TheRegistrar", false); assertAboutContacts().that(deletedContact) @@ -125,7 +125,7 @@ public class ContactDeleteFlowTest clock.advanceOneMilli(); runFlowAssertResponse( CommitMode.LIVE, UserPrivileges.SUPERUSER, readFile("contact_delete_response.xml")); - ContactResource deletedContact = reloadResourceByUniqueId(); + ContactResource deletedContact = reloadResourceByForeignKey(); assertAboutContacts().that(deletedContact).hasStatusValue(StatusValue.PENDING_DELETE); assertAsyncDeletionTaskEnqueued(deletedContact, "NewRegistrar", true); assertAboutContacts().that(deletedContact) diff --git a/javatests/google/registry/flows/contact/ContactTransferApproveFlowTest.java b/javatests/google/registry/flows/contact/ContactTransferApproveFlowTest.java index 3582079c0..281dab8c2 100644 --- a/javatests/google/registry/flows/contact/ContactTransferApproveFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactTransferApproveFlowTest.java @@ -68,7 +68,7 @@ public class ContactTransferApproveFlowTest runFlowAssertResponse(readFile(expectedXmlFilename)); // Transfer should have succeeded. Verify correct fields were set. - contact = reloadResourceByUniqueId(); + contact = reloadResourceByForeignKey(); assertAboutContacts().that(contact) .hasCurrentSponsorClientId("NewRegistrar").and() .hasLastTransferTime(clock.nowUtc()).and() diff --git a/javatests/google/registry/flows/contact/ContactTransferCancelFlowTest.java b/javatests/google/registry/flows/contact/ContactTransferCancelFlowTest.java index 7e0e306b3..10c9cc6f3 100644 --- a/javatests/google/registry/flows/contact/ContactTransferCancelFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactTransferCancelFlowTest.java @@ -62,7 +62,7 @@ public class ContactTransferCancelFlowTest runFlowAssertResponse(readFile(expectedXmlFilename)); // Transfer should have been cancelled. Verify correct fields were set. - contact = reloadResourceByUniqueId(); + contact = reloadResourceByForeignKey(); assertAboutContacts().that(contact) .hasCurrentSponsorClientId("TheRegistrar").and() .hasLastTransferTimeNotEqualTo(clock.nowUtc()).and() diff --git a/javatests/google/registry/flows/contact/ContactTransferQueryFlowTest.java b/javatests/google/registry/flows/contact/ContactTransferQueryFlowTest.java index 5302aaf46..317eca7e9 100644 --- a/javatests/google/registry/flows/contact/ContactTransferQueryFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactTransferQueryFlowTest.java @@ -51,7 +51,7 @@ public class ContactTransferQueryFlowTest // Setup done; run the test. assertTransactionalFlow(false); runFlowAssertResponse(readFile(expectedXmlFilename)); - assertAboutContacts().that(reloadResourceByUniqueIdYesterday()) + assertAboutContacts().that(reloadResourceByForeignKey(clock.nowUtc().minusDays(1))) .hasOneHistoryEntryEachOfTypes(HistoryEntry.Type.CONTACT_TRANSFER_REQUEST); assertNoBillingEvents(); } diff --git a/javatests/google/registry/flows/contact/ContactTransferRejectFlowTest.java b/javatests/google/registry/flows/contact/ContactTransferRejectFlowTest.java index f483a2569..2e3b66296 100644 --- a/javatests/google/registry/flows/contact/ContactTransferRejectFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactTransferRejectFlowTest.java @@ -66,7 +66,7 @@ public class ContactTransferRejectFlowTest runFlowAssertResponse(readFile(expectedXmlFilename)); // Transfer should have failed. Verify correct fields were set. - contact = reloadResourceByUniqueId(); + contact = reloadResourceByForeignKey(); assertAboutContacts().that(contact) .hasCurrentSponsorClientId("TheRegistrar").and() .hasLastTransferTimeNotEqualTo(clock.nowUtc()).and() diff --git a/javatests/google/registry/flows/contact/ContactTransferRequestFlowTest.java b/javatests/google/registry/flows/contact/ContactTransferRequestFlowTest.java index ebcfd12b8..2a63ce156 100644 --- a/javatests/google/registry/flows/contact/ContactTransferRequestFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactTransferRequestFlowTest.java @@ -65,7 +65,7 @@ public class ContactTransferRequestFlowTest runFlowAssertResponse(readFile(expectedXmlFilename)); // Transfer should have been requested. Verify correct fields were set. - contact = reloadResourceByUniqueId(); + contact = reloadResourceByForeignKey(); assertAboutContacts().that(contact) .hasTransferStatus(TransferStatus.PENDING).and() .hasTransferGainingClientId("NewRegistrar").and() diff --git a/javatests/google/registry/flows/contact/ContactUpdateFlowTest.java b/javatests/google/registry/flows/contact/ContactUpdateFlowTest.java index 9cb937c92..590414fc0 100644 --- a/javatests/google/registry/flows/contact/ContactUpdateFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactUpdateFlowTest.java @@ -53,7 +53,7 @@ public class ContactUpdateFlowTest assertTransactionalFlow(true); runFlowAssertResponse(readFile("contact_update_response.xml")); // Check that the contact was updated. This value came from the xml. - assertAboutContacts().that(reloadResourceByUniqueId()) + assertAboutContacts().that(reloadResourceByForeignKey()) .hasAuthInfoPwd("2fooBAR").and() .hasOnlyOneHistoryEntryWhich() .hasNoXml(); @@ -79,7 +79,7 @@ public class ContactUpdateFlowTest .setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)) .build()); doSuccessfulTest(); - assertAboutContacts().that(reloadResourceByUniqueId()) + assertAboutContacts().that(reloadResourceByForeignKey()) .doesNotHaveStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED); } @@ -107,7 +107,7 @@ public class ContactUpdateFlowTest .hasInternationalizedPostalInfo(null); runFlowAssertResponse(readFile("contact_update_response.xml")); - assertAboutContacts().that(reloadResourceByUniqueId()) + assertAboutContacts().that(reloadResourceByForeignKey()) .hasLocalizedPostalInfo(null).and() .hasNonNullInternationalizedPostalInfo(); } @@ -133,7 +133,7 @@ public class ContactUpdateFlowTest clock.advanceOneMilli(); // The test xml updates the address of the postal info and should leave the name untouched. runFlowAssertResponse(readFile("contact_update_response.xml")); - assertAboutContacts().that(reloadResourceByUniqueId()).hasLocalizedPostalInfo( + assertAboutContacts().that(reloadResourceByForeignKey()).hasLocalizedPostalInfo( new PostalInfo.Builder() .setType(Type.LOCALIZED) .setName("A. Person") @@ -213,7 +213,7 @@ public class ContactUpdateFlowTest CommitMode.LIVE, UserPrivileges.SUPERUSER, readFile("contact_update_response.xml")); - assertAboutContacts().that(reloadResourceByUniqueId()) + assertAboutContacts().that(reloadResourceByForeignKey()) .hasStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED).and() .hasStatusValue(StatusValue.SERVER_DELETE_PROHIBITED); } diff --git a/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java b/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java index 9fc0505af..2e5ff4167 100644 --- a/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java @@ -16,7 +16,7 @@ package google.registry.flows.domain; import static com.google.common.io.BaseEncoding.base16; import static com.google.common.truth.Truth.assertThat; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadDomainApplication; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.assertBillingEvents; import static google.registry.testing.DatastoreHelper.createTld; @@ -132,7 +132,7 @@ public class DomainAllocateFlowTest UserPrivileges.SUPERUSER, readFile("domain_allocate_response.xml")); // Check that the domain was created and persisted with a history entry. - DomainResource domain = reloadResourceByUniqueId(); + DomainResource domain = reloadResourceByForeignKey(); assertAboutDomains().that(domain) .hasOnlyOneHistoryEntryWhich() .hasType(HistoryEntry.Type.DOMAIN_ALLOCATE); @@ -142,8 +142,7 @@ public class DomainAllocateFlowTest boolean sunrushAddGracePeriod = (nameservers == 0); // The application should be marked as allocated, with a new history entry. - DomainApplication application = - loadByUniqueId(DomainApplication.class, applicationId, clock.nowUtc()); + DomainApplication application = loadDomainApplication(applicationId, clock.nowUtc()); assertAboutApplications().that(application) .hasApplicationStatus(ApplicationStatus.ALLOCATED).and() .hasHistoryEntryAtIndex(1) @@ -284,7 +283,7 @@ public class DomainAllocateFlowTest setupDomainApplication("tld", TldState.QUIET_PERIOD); setEppInput("domain_allocate_dsdata.xml"); doSuccessfulTest(2); - assertAboutDomains().that(reloadResourceByUniqueId()) + assertAboutDomains().that(reloadResourceByForeignKey()) .hasExactlyDsData(DelegationSignerData.create( 12345, 3, 1, base16().decode("49FD46E6C4B45C55D4AC"))); } @@ -295,7 +294,7 @@ public class DomainAllocateFlowTest setEppInput("domain_allocate_dsdata_8_records.xml"); doSuccessfulTest(2); assertThat(getOnlyGlobalResource(DomainResource.class)).isNotNull(); - assertThat(reloadResourceByUniqueId().getDsData()).hasSize(8); + assertThat(reloadResourceByForeignKey().getDsData()).hasSize(8); } @Test @@ -326,7 +325,7 @@ public class DomainAllocateFlowTest String expectedCsv = String.format( "%s,example-one.tld,370d0b7c9223372036854775807,1," + "2010-09-16T10:00:00.000Z,2010-07-16T09:00:00.000Z,2010-08-16T10:00:00.000Z", - reloadResourceByUniqueId().getRepoId()); + reloadResourceByForeignKey().getRepoId()); assertTasksEnqueued( "lordn-claims", new TaskMatcher().payload(expectedCsv).tag("tld")); } @@ -339,7 +338,7 @@ public class DomainAllocateFlowTest String expectedCsv = String.format( "%s,example-one.tld,370d0b7c9223372036854775807,1," + "2011-08-17T09:00:00.000Z,2010-07-16T09:00:00.000Z,2010-08-16T10:00:00.000Z", - reloadResourceByUniqueId().getRepoId()); + reloadResourceByForeignKey().getRepoId()); assertTasksEnqueued("lordn-claims", new TaskMatcher().payload(expectedCsv).tag("tld")); } diff --git a/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java index 5d7d58ca1..c955c4f4c 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java @@ -15,7 +15,7 @@ package google.registry.flows.domain; import static com.google.common.truth.Truth.assertThat; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.newDomainApplication; @@ -65,7 +65,7 @@ public class DomainApplicationDeleteFlowTest clock.advanceOneMilli(); runFlowAssertResponse(readFile("domain_delete_response.xml")); // Check that the domain is fully deleted. - assertThat(reloadResourceByUniqueId()).isNull(); + assertThat(reloadDomainApplication()).isNull(); assertNoBillingEvents(); } @@ -86,15 +86,15 @@ public class DomainApplicationDeleteFlowTest .setRepoId("1-TLD") .setRegistrant( Key.create( - loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc()))) + loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()))) .setNameservers(ImmutableSet.of( Key.create( - loadByUniqueId(HostResource.class, "ns1.example.net", clock.nowUtc())))) + loadByForeignKey(HostResource.class, "ns1.example.net", clock.nowUtc())))) .build()); doSuccessfulTest(); for (EppResource resource : new EppResource[]{ - loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc()), - loadByUniqueId(HostResource.class, "ns1.example.net", clock.nowUtc()) }) { + loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()), + loadByForeignKey(HostResource.class, "ns1.example.net", clock.nowUtc()) }) { assertAboutEppResources().that(resource).doesNotHaveStatusValue(StatusValue.LINKED); } } diff --git a/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java index e268f79dd..d04298498 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java @@ -17,7 +17,7 @@ package google.registry.flows.domain; import static com.google.common.collect.Sets.union; import static com.google.common.io.BaseEncoding.base16; import static com.google.common.truth.Truth.assertThat; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.generateNewDomainRoid; @@ -107,7 +107,7 @@ public class DomainApplicationUpdateFlowTest DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)), DesignatedContact.create(Type.ADMIN, Key.create(unusedContact)))) .setNameservers(ImmutableSet.of(Key.create( - loadByUniqueId(HostResource.class, "ns1.example.tld", clock.nowUtc())))) + loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())))) .build()); } @@ -124,7 +124,7 @@ public class DomainApplicationUpdateFlowTest clock.advanceOneMilli(); runFlowAssertResponse(readFile("domain_update_response.xml")); // Check that the application was updated. These values came from the xml. - DomainApplication application = reloadResourceByUniqueId(); + DomainApplication application = reloadDomainApplication(); assertAboutApplications().that(application) .hasStatusValue(StatusValue.CLIENT_HOLD).and() .hasOnlyOneHistoryEntryWhich() @@ -168,7 +168,7 @@ public class DomainApplicationUpdateFlowTest public void testSuccess_registrantMovedToTechContact() throws Exception { setEppInput("domain_update_sunrise_registrant_to_tech.xml"); persistReferencedEntities(); - ContactResource sh8013 = loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc()); + ContactResource sh8013 = loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()); persistResource( newApplicationBuilder().setRegistrant(Key.create(sh8013)).build()); clock.advanceOneMilli(); @@ -179,7 +179,7 @@ public class DomainApplicationUpdateFlowTest public void testSuccess_multipleReferencesToSameContactRemoved() throws Exception { setEppInput("domain_update_sunrise_remove_multiple_contacts.xml"); persistReferencedEntities(); - ContactResource sh8013 = loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc()); + ContactResource sh8013 = loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()); Key sh8013Key = Key.create(sh8013); persistResource(newApplicationBuilder() .setRegistrant(sh8013Key) @@ -199,7 +199,7 @@ public class DomainApplicationUpdateFlowTest ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)).build()); clock.advanceOneMilli(); runFlow(); - assertAboutApplications().that(reloadResourceByUniqueId()) + assertAboutApplications().that(reloadDomainApplication()) .doesNotHaveStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED); } @@ -213,7 +213,7 @@ public class DomainApplicationUpdateFlowTest assertTransactionalFlow(true); clock.advanceOneMilli(); runFlowAssertResponse(readFile("domain_update_response.xml")); - assertAboutApplications().that(reloadResourceByUniqueId()) + assertAboutApplications().that(reloadDomainApplication()) .hasExactlyDsData(expectedDsData).and() .hasOnlyOneHistoryEntryWhich() .hasType(HistoryEntry.Type.DOMAIN_APPLICATION_UPDATE); @@ -372,11 +372,11 @@ public class DomainApplicationUpdateFlowTest 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(Key.create(loadByUniqueId( + nameservers.add(Key.create(loadByForeignKey( HostResource.class, String.format("ns%d.example.tld", i), clock.nowUtc()))); } } - persistResource(reloadResourceByUniqueId().asBuilder() + persistResource(reloadDomainApplication().asBuilder() .setNameservers(nameservers.build()) .build()); } @@ -491,9 +491,9 @@ public class DomainApplicationUpdateFlowTest persistNewApplication(); // 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( + persistResource(reloadDomainApplication().asBuilder().setContacts(ImmutableSet.of( DesignatedContact.create(Type.TECH, Key.create( - loadByUniqueId(ContactResource.class, "foo", clock.nowUtc()))))).build()); + loadByForeignKey(ContactResource.class, "foo", clock.nowUtc()))))).build()); runFlow(); } @@ -577,7 +577,7 @@ public class DomainApplicationUpdateFlowTest persistReferencedEntities(); persistResource(newApplicationBuilder() .setNameservers(ImmutableSet.of(Key.create( - loadByUniqueId(HostResource.class, "ns1.example.tld", clock.nowUtc())))) + loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())))) .build()); runFlow(); } @@ -591,7 +591,7 @@ public class DomainApplicationUpdateFlowTest .setContacts(ImmutableSet.of(DesignatedContact.create( Type.TECH, Key.create( - loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc()))))) + loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()))))) .build()); runFlow(); } diff --git a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java index 7c99b4c97..56a4e2a34 100644 --- a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java @@ -165,7 +165,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase substitutions) throws Exception { assertTransactionalFlow(true); - DateTime currentExpiration = reloadResourceByUniqueId().getRegistrationExpirationTime(); + DateTime currentExpiration = reloadResourceByForeignKey().getRegistrationExpirationTime(); DateTime newExpiration = currentExpiration.plusYears(renewalYears); runFlowAssertResponse(readFile(responseFilename, substitutions)); - DomainResource domain = reloadResourceByUniqueId(); + DomainResource domain = reloadResourceByForeignKey(); HistoryEntry historyEntryDomainRenew = getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RENEW); assertThat(ofy().load().key(domain.getAutorenewBillingEvent()).now().getEventTime()) @@ -351,12 +351,12 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase .setCreationClientId("TheRegistrar") .setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z")) .setRegistrationExpirationTime(REGISTRATION_EXPIRATION_TIME) - .setRegistrant(Key.create(loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc()))) + .setRegistrant( + Key.create(loadByForeignKey(ContactResource.class, "jd1234", clock.nowUtc()))) .setContacts(ImmutableSet.of( DesignatedContact.create( Type.ADMIN, - Key.create(loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc()))), + Key.create(loadByForeignKey(ContactResource.class, "jd1234", clock.nowUtc()))), DesignatedContact.create( Type.TECH, - Key.create(loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc()))))) + Key.create(loadByForeignKey(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/DomainTransferRejectFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferRejectFlowTest.java index 984b85f27..d151cf2c8 100644 --- a/javatests/google/registry/flows/domain/DomainTransferRejectFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferRejectFlowTest.java @@ -80,7 +80,7 @@ public class DomainTransferRejectFlowTest ImmutableSet originalGracePeriods = domain.getGracePeriods(); runFlowAssertResponse(readFile(expectedXmlFilename)); // Transfer should have been rejected. Verify correct fields were set. - domain = reloadResourceByUniqueId(); + domain = reloadResourceByForeignKey(); assertTransferFailed(domain, TransferStatus.CLIENT_REJECTED); assertTransferFailed( reloadResourceAndCloneAtTime(subordinateHost, clock.nowUtc()), diff --git a/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java index 90fe3953a..0f813b3fd 100644 --- a/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java @@ -147,7 +147,7 @@ public class DomainTransferRequestFlowTest assertTransactionalFlow(true); runFlowAssertResponse(readFile(expectedXmlFilename, substitutions)); // Transfer should have been requested. Verify correct fields were set. - domain = reloadResourceByUniqueId(); + domain = reloadResourceByForeignKey(); final HistoryEntry historyEntryTransferRequest = getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST); int registrationYears = domain.getTransferData().getExtendedRegistrationYears(); @@ -503,7 +503,7 @@ public class DomainTransferRequestFlowTest @Test public void testSuccess_autorenewBeforeAutomaticTransfer() throws Exception { - DomainResource oldResource = persistResource(reloadResourceByUniqueId().asBuilder() + DomainResource oldResource = persistResource(reloadResourceByForeignKey().asBuilder() .setRegistrationExpirationTime(clock.nowUtc().plusDays(1).plus(1)) .build()); clock.advanceOneMilli(); diff --git a/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java b/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java index d5e69601b..762770667 100644 --- a/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java @@ -17,7 +17,7 @@ package google.registry.flows.domain; import static com.google.common.collect.Sets.union; import static com.google.common.io.BaseEncoding.base16; import static com.google.common.truth.Truth.assertThat; -import static google.registry.model.EppResourceUtils.loadByUniqueId; +import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.assertBillingEvents; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; @@ -121,7 +121,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase> 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(Key.create(loadByUniqueId( + nameservers.add(Key.create(loadByForeignKey( HostResource.class, String.format("ns%d.example.foo", i), clock.nowUtc()))); } } persistResource( - reloadResourceByUniqueId().asBuilder() + reloadResourceByForeignKey().asBuilder() .setNameservers(nameservers.build()) .build()); clock.advanceOneMilli(); @@ -392,7 +392,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase contacts = contactsBuilder.build(); persistResource( - reloadResourceByUniqueId().asBuilder() + reloadResourceByForeignKey().asBuilder() .setNameservers(nameservers.build()) .setContacts(ImmutableSet.copyOf(contacts.subList(0, 3))) .setRegistrant(contacts.get(3).getContactKey()) @@ -400,7 +400,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase sh8013Key = Key.create(sh8013); persistResource( newDomainResource(getUniqueIdFromCommand()).asBuilder() @@ -516,7 +516,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase