Rename DomainNameUtils method to getTldFromSld

This is broken out from []
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=121599268
This commit is contained in:
mcilwain 2016-05-05 11:35:58 -07:00 committed by Justine Tunney
parent 3ec6aebe44
commit 4a9be60e0b
8 changed files with 37 additions and 26 deletions

View file

@ -21,7 +21,7 @@ import static google.registry.dns.DnsConstants.DNS_TARGET_NAME_PARAM;
import static google.registry.dns.DnsConstants.DNS_TARGET_TYPE_PARAM;
import static google.registry.model.registry.Registries.assertTldExists;
import static google.registry.request.RequestParameters.PARAM_TLD;
import static google.registry.util.DomainNameUtils.getTldFromDomainName;
import static google.registry.util.DomainNameUtils.getTldFromSld;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import com.google.appengine.api.taskqueue.Queue;
@ -91,7 +91,7 @@ public class DnsQueue {
return addToQueue(
TargetType.DOMAIN,
fullyQualifiedDomainName,
assertTldExists(getTldFromDomainName(fullyQualifiedDomainName)));
assertTldExists(getTldFromSld(fullyQualifiedDomainName)));
}
/** Adds a task to the queue to refresh the DNS information for the specified zone. */

View file

@ -19,7 +19,7 @@ import static google.registry.flows.domain.DomainFlowUtils.handleFeeRequest;
import static google.registry.model.EppResourceUtils.checkResourcesExist;
import static google.registry.model.registry.label.ReservationType.UNRESERVED;
import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.DomainNameUtils.getTldFromDomainName;
import static google.registry.util.DomainNameUtils.getTldFromSld;
import com.google.common.collect.ImmutableList;
import com.google.common.net.InternetDomainName;
@ -114,7 +114,7 @@ public class DomainCheckFlow extends BaseDomainCheckFlow {
throw new OnlyCheckedNamesCanBeFeeCheckedException();
}
FeeCheck.Builder builder = new FeeCheck.Builder();
handleFeeRequest(domainCheck, builder, domainName, getTldFromDomainName(domainName), now);
handleFeeRequest(domainCheck, builder, domainName, getTldFromSld(domainName), now);
feeChecksBuilder.add(builder.setName(domainName).build());
}
return ImmutableList.of(FeeCheckResponseExtension.create(feeChecksBuilder.build()));

View file

@ -22,7 +22,7 @@ import static google.registry.model.domain.DesignatedContact.Type.REGISTRANT;
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.getTldFromDomainName;
import static google.registry.util.DomainNameUtils.getTldFromSld;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
@ -228,7 +228,7 @@ public abstract class DomainBase extends EppResource {
T instance = getInstance();
checkState(
!isNullOrEmpty(instance.fullyQualifiedDomainName), "Missing fullyQualifiedDomainName");
instance.tld = getTldFromDomainName(instance.fullyQualifiedDomainName);
instance.tld = getTldFromSld(instance.fullyQualifiedDomainName);
instance.allContacts = instance.registrant == null ? instance.contacts : union(
instance.getContacts(), DesignatedContact.create(REGISTRANT, instance.registrant));
return super.build();

View file

@ -92,7 +92,7 @@ public final class Registries {
*
* <p><b>Note:</b> This routine will only work on names under TLDs for which this registry is
* authoritative. To extract TLDs from domains (not hosts) that other registries control, use
* {@link google.registry.util.DomainNameUtils#getTldFromDomainName(String)
* {@link google.registry.util.DomainNameUtils#getTldFromSld(String)
* DomainNameUtils#getTldFromDomainName}.
*
* @param domainName domain name or host name (but not TLD) under an authoritative TLD

View file

@ -20,7 +20,7 @@ import static com.google.common.net.HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN;
import static google.registry.model.eppcommon.ProtocolDefinition.ServiceExtension.FEE_0_6;
import static google.registry.ui.server.SoyTemplateUtils.createTofuSupplier;
import static google.registry.util.DomainNameUtils.canonicalizeDomainName;
import static google.registry.util.DomainNameUtils.getTldFromDomainName;
import static google.registry.util.DomainNameUtils.getTldFromSld;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.json.simple.JSONValue.toJSONString;
@ -89,7 +89,7 @@ public class CheckApiServlet extends HttpServlet {
try {
domainString = canonicalizeDomainName(nullToEmpty(domainString));
// Validate the TLD.
getTldFromDomainName(domainString);
getTldFromSld(domainString);
} catch (IllegalStateException | IllegalArgumentException e) {
return fail("Must supply a valid second level domain name");
}

View file

@ -15,6 +15,7 @@
package google.registry.util;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import com.google.common.base.Ascii;
import com.google.common.base.Strings;
@ -42,8 +43,8 @@ public final class DomainNameUtils {
}
/**
* Returns the canonicalized TLD part of a valid domain name (just an SLD, no subdomains) by
* stripping off the leftmost part.
* Returns the canonicalized TLD part of a valid second level domain name by stripping off the
* leftmost part.
*
* <p>This function is compatible with multi-part tlds, e.g. {@code co.uk}. This function will
* also work on domains for which the registry is not authoritative. If you are certain that the
@ -51,16 +52,26 @@ public final class DomainNameUtils {
* {@link google.registry.model.registry.Registries#findTldForName(InternetDomainName)
* Registries#findTldForName}, which will work on hostnames in addition to domains.
*
* @param fullyQualifiedDomainName must be a punycode SLD (not a host or unicode)
* @param sld must be a punycode SLD (not a host or unicode)
* @throws IllegalArgumentException if there is no TLD
*/
public static String getTldFromDomainName(String fullyQualifiedDomainName) {
checkArgument(
!Strings.isNullOrEmpty(fullyQualifiedDomainName),
"fullyQualifiedDomainName cannot be null or empty");
InternetDomainName domainName = InternetDomainName.from(fullyQualifiedDomainName);
checkArgument(domainName.hasParent(), "fullyQualifiedDomainName does not have a TLD");
return domainName.parent().toString();
public static String getTldFromSld(String sld) {
checkArgument(!Strings.isNullOrEmpty(sld), "secondLevelDomainName cannot be null or empty");
return getTldFromSld(InternetDomainName.from(sld));
}
/**
* Returns the canonicalized TLD part of a valid second level domain name by stripping off the
* leftmost part.
*
* <p>This function is compatible with multi-part tlds.
*
* @throws IllegalArgumentException if there is no TLD
*/
public static String getTldFromSld(InternetDomainName sld) {
checkArgumentNotNull(sld);
checkArgument(sld.hasParent(), "secondLevelDomainName does not have a TLD");
return sld.parent().toString();
}
private DomainNameUtils() {}

View file

@ -30,7 +30,7 @@ import static google.registry.util.CollectionUtils.union;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.DomainNameUtils.ACE_PREFIX_REGEX;
import static google.registry.util.DomainNameUtils.getTldFromDomainName;
import static google.registry.util.DomainNameUtils.getTldFromSld;
import static google.registry.util.ResourceUtils.readResourceUtf8;
import static java.util.Arrays.asList;
import static org.joda.money.CurrencyUnit.USD;
@ -119,13 +119,13 @@ public class DatastoreHelper {
}
public static DomainResource newDomainResource(String domainName) {
String repoId = generateNewDomainRoid(getTldFromDomainName(domainName));
String repoId = generateNewDomainRoid(getTldFromSld(domainName));
return newDomainResource(domainName, repoId, persistActiveContact("contact1234"));
}
public static DomainResource newDomainResource(String domainName, ContactResource contact) {
return newDomainResource(
domainName, generateNewDomainRoid(getTldFromDomainName(domainName)), contact);
domainName, generateNewDomainRoid(getTldFromSld(domainName)), contact);
}
public static DomainResource newDomainResource(
@ -150,7 +150,7 @@ public class DatastoreHelper {
// contact does, which is usually the applicationId 1.
return newDomainApplication(
domainName,
generateNewDomainRoid(getTldFromDomainName(domainName)),
generateNewDomainRoid(getTldFromSld(domainName)),
persistActiveContact("contact1234"),
LaunchPhase.SUNRISE);
}
@ -163,7 +163,7 @@ public class DatastoreHelper {
String domainName, ContactResource contact, LaunchPhase phase) {
return newDomainApplication(
domainName,
generateNewDomainRoid(getTldFromDomainName(domainName)),
generateNewDomainRoid(getTldFromSld(domainName)),
contact,
phase);
}

View file

@ -17,7 +17,7 @@ package google.registry.testing;
import static google.registry.testing.DatastoreHelper.generateNewContactHostRoid;
import static google.registry.testing.DatastoreHelper.generateNewDomainRoid;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.util.DomainNameUtils.getTldFromDomainName;
import static google.registry.util.DomainNameUtils.getTldFromSld;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.collect.ImmutableList;
@ -220,7 +220,7 @@ public final class FullFieldsTestEntityHelper {
Registrar registrar) {
DomainResource.Builder builder = new DomainResource.Builder()
.setFullyQualifiedDomainName(Idn.toASCII(domain))
.setRepoId(generateNewDomainRoid(getTldFromDomainName(Idn.toASCII(domain))))
.setRepoId(generateNewDomainRoid(getTldFromSld(Idn.toASCII(domain))))
.setLastEppUpdateTime(DateTime.parse("2009-05-29T20:13:00Z"))
.setCreationTimeForTest(DateTime.parse("2000-10-08T00:45:00Z"))
.setRegistrationExpirationTime(DateTime.parse("2110-10-08T00:44:59Z"))