From 64bfbea324342ed5976d31552b3dfd32dc4d48c2 Mon Sep 17 00:00:00 2001 From: mcilwain Date: Mon, 27 Feb 2017 09:35:33 -0800 Subject: [PATCH] Remove duplicate version of lookupSuperordinateDomain() function ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=148657943 --- .../registry/flows/host/HostCreateFlow.java | 4 +-- .../registry/flows/host/HostFlowUtils.java | 6 ++-- .../registry/flows/host/HostUpdateFlow.java | 2 +- .../rde/imports/RdeHostLinkAction.java | 29 +------------------ 4 files changed, 7 insertions(+), 34 deletions(-) diff --git a/java/google/registry/flows/host/HostCreateFlow.java b/java/google/registry/flows/host/HostCreateFlow.java index 291f18c2d..b33392cea 100644 --- a/java/google/registry/flows/host/HostCreateFlow.java +++ b/java/google/registry/flows/host/HostCreateFlow.java @@ -96,8 +96,8 @@ public final class HostCreateFlow implements TransactionalFlow { // The superordinate domain of the host object if creating an in-bailiwick host, or null if // creating an external host. This is looked up before we actually create the Host object so // we can detect error conditions earlier. - Optional superordinateDomain = Optional.fromNullable( - lookupSuperordinateDomain(validateHostName(targetId), now)); + Optional superordinateDomain = + lookupSuperordinateDomain(validateHostName(targetId), now); verifyDomainIsSameRegistrar(superordinateDomain.orNull(), clientId); boolean willBeSubordinate = superordinateDomain.isPresent(); boolean hasIpAddresses = !isNullOrEmpty(command.getInetAddresses()); diff --git a/java/google/registry/flows/host/HostFlowUtils.java b/java/google/registry/flows/host/HostFlowUtils.java index 0f8208f95..06243b9a0 100644 --- a/java/google/registry/flows/host/HostFlowUtils.java +++ b/java/google/registry/flows/host/HostFlowUtils.java @@ -86,12 +86,12 @@ public class HostFlowUtils { } /** Return the {@link DomainResource} this host is subordinate to, or null for external hosts. */ - static DomainResource lookupSuperordinateDomain( + public static Optional lookupSuperordinateDomain( InternetDomainName hostName, DateTime now) throws EppException { Optional tld = findTldForName(hostName); if (!tld.isPresent()) { // This is an host on a TLD we don't run, therefore obviously external, so we are done. - return null; + return Optional.absent(); } // This is a subordinate host String domainName = Joiner.on('.').join(Iterables.skip( @@ -100,7 +100,7 @@ public class HostFlowUtils { if (superordinateDomain == null || !isActive(superordinateDomain, now)) { throw new SuperordinateDomainDoesNotExistException(domainName); } - return superordinateDomain; + return Optional.of(superordinateDomain); } /** Superordinate domain for this hostname does not exist. */ diff --git a/java/google/registry/flows/host/HostUpdateFlow.java b/java/google/registry/flows/host/HostUpdateFlow.java index 15352b619..bac86100e 100644 --- a/java/google/registry/flows/host/HostUpdateFlow.java +++ b/java/google/registry/flows/host/HostUpdateFlow.java @@ -130,7 +130,7 @@ public final class HostUpdateFlow implements TransactionalFlow { String newHostName = firstNonNull(suppliedNewHostName, oldHostName); // Note that lookupSuperordinateDomain calls cloneProjectedAtTime on the domain for us. Optional newSuperordinateDomain = - Optional.fromNullable(lookupSuperordinateDomain(validateHostName(newHostName), now)); + lookupSuperordinateDomain(validateHostName(newHostName), now); verifyUpdateAllowed(command, existingHost, newSuperordinateDomain.orNull()); if (isHostRename && loadAndGetKey(HostResource.class, newHostName, now) != null) { throw new HostAlreadyExistsException(newHostName); diff --git a/java/google/registry/rde/imports/RdeHostLinkAction.java b/java/google/registry/rde/imports/RdeHostLinkAction.java index b02e6a75d..5093358fb 100644 --- a/java/google/registry/rde/imports/RdeHostLinkAction.java +++ b/java/google/registry/rde/imports/RdeHostLinkAction.java @@ -14,18 +14,14 @@ package google.registry.rde.imports; -import static com.google.common.base.Preconditions.checkState; +import static google.registry.flows.host.HostFlowUtils.lookupSuperordinateDomain; import static google.registry.mapreduce.MapreduceRunner.PARAM_MAP_SHARDS; -import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.ofy.ObjectifyService.ofy; -import static google.registry.model.registry.Registries.findTldForName; import static google.registry.util.PipelineUtils.createJobPath; import com.google.appengine.tools.mapreduce.Mapper; -import com.google.common.base.Joiner; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; import com.google.common.net.InternetDomainName; import com.googlecode.objectify.Key; import com.googlecode.objectify.VoidWork; @@ -135,29 +131,6 @@ public class RdeHostLinkAction implements Runnable { throw new HostLinkException(xjcHost.getName(), xjcHost.toString(), e); } } - - /** - * Return the {@link DomainResource} this host is subordinate to, or absent for out of zone - * hosts. - * - * @throws IllegalStateException for hosts without superordinate domains - */ - private static Optional lookupSuperordinateDomain( - InternetDomainName hostName, DateTime now) { - Optional tld = findTldForName(hostName); - // out of zone hosts cannot be linked - if (!tld.isPresent()) { - return Optional.absent(); - } - // This is a subordinate host - String domainName = Joiner.on('.').join(Iterables.skip( - hostName.parts(), hostName.parts().size() - (tld.get().parts().size() + 1))); - DomainResource superordinateDomain = loadByForeignKey(DomainResource.class, domainName, now); - // Hosts can't be linked if domains import hasn't been run - checkState( - superordinateDomain != null, "Superordinate domain does not exist: %s", domainName); - return Optional.of(superordinateDomain); - } } private static class HostLinkException extends RuntimeException {