diff --git a/java/google/registry/flows/domain/DomainCheckFlow.java b/java/google/registry/flows/domain/DomainCheckFlow.java index 7047226d9..46fab25af 100644 --- a/java/google/registry/flows/domain/DomainCheckFlow.java +++ b/java/google/registry/flows/domain/DomainCheckFlow.java @@ -23,7 +23,6 @@ import static google.registry.model.index.DomainApplicationIndex.loadActiveAppli import static google.registry.model.registry.label.ReservationType.UNRESERVED; import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName; import static google.registry.util.CollectionUtils.nullToEmpty; -import static google.registry.util.DomainNameUtils.getTldFromDomainName; import com.google.common.base.Predicate; import com.google.common.collect.FluentIterable; @@ -49,7 +48,6 @@ import google.registry.model.registry.label.ReservationType; import java.util.Collections; import java.util.Set; import javax.inject.Inject; -import org.joda.money.CurrencyUnit; /** * An EPP flow that checks whether a domain can be provisioned. @@ -148,7 +146,7 @@ public class DomainCheckFlow extends BaseDomainCheckFlow { // If this version of the fee extension is nameless, use the full list of domains. return domainNames.keySet(); } - } + } /** Handle the fee check extension. */ @Override @@ -160,7 +158,6 @@ public class DomainCheckFlow extends BaseDomainCheckFlow { if (feeCheck == null) { return null; // No fee checks were requested. } - CurrencyUnit topLevelCurrency = feeCheck.isCurrencySupported() ? feeCheck.getCurrency() : null; ImmutableList.Builder feeCheckResponseItemsBuilder = new ImmutableList.Builder<>(); for (FeeCheckCommandExtensionItem feeCheckItem : feeCheck.getItems()) { @@ -169,10 +166,9 @@ public class DomainCheckFlow extends BaseDomainCheckFlow { handleFeeRequest( feeCheckItem, builder, - domainName, - getTldFromDomainName(domainName), + domainNames.get(domainName), getClientId(), - topLevelCurrency, + feeCheck.getCurrency(), now, eppInput); feeCheckResponseItemsBuilder @@ -182,7 +178,7 @@ public class DomainCheckFlow extends BaseDomainCheckFlow { return ImmutableList.of( feeCheck.createResponse(feeCheckResponseItemsBuilder.build())); } - + /** By server policy, fee check names must be listed in the availability check. */ static class OnlyCheckedNamesCanBeFeeCheckedException extends ParameterValuePolicyErrorException { OnlyCheckedNamesCanBeFeeCheckedException() { diff --git a/java/google/registry/flows/domain/DomainFlowUtils.java b/java/google/registry/flows/domain/DomainFlowUtils.java index 495404818..ef0f4b8dd 100644 --- a/java/google/registry/flows/domain/DomainFlowUtils.java +++ b/java/google/registry/flows/domain/DomainFlowUtils.java @@ -564,14 +564,13 @@ public class DomainFlowUtils { static void handleFeeRequest( FeeQueryCommandExtensionItem feeRequest, FeeQueryResponseExtensionItem.Builder builder, - String domainName, - String tld, + InternetDomainName domain, String clientIdentifier, @Nullable CurrencyUnit topLevelCurrency, DateTime now, EppInput eppInput) throws EppException { - InternetDomainName domain = InternetDomainName.from(domainName); - Registry registry = Registry.get(tld); + String domainNameString = domain.toString(); + Registry registry = Registry.get(domain.parent().toString()); int years = verifyUnitIsYears(feeRequest.getPeriod()).getValue(); boolean isSunrise = registry.getTldState(now).equals(TldState.SUNRISE); @@ -580,7 +579,7 @@ public class DomainFlowUtils { } CurrencyUnit currency = - feeRequest.isCurrencySupported() ? feeRequest.getCurrency() : topLevelCurrency; + feeRequest.getCurrency() != null ? feeRequest.getCurrency() : topLevelCurrency; if ((currency != null) && !currency.equals(registry.getCurrency())) { throw new CurrencyUnitMismatchException(); } @@ -589,7 +588,7 @@ public class DomainFlowUtils { .setCommand(feeRequest.getCommandName(), feeRequest.getPhase(), feeRequest.getSubphase()) .setCurrencyIfSupported(registry.getCurrency()) .setPeriod(feeRequest.getPeriod()) - .setClass(TldSpecificLogicProxy.getFeeClass(domainName, now).orNull()); + .setClass(TldSpecificLogicProxy.getFeeClass(domainNameString, now).orNull()); switch (feeRequest.getCommandName()) { case CREATE: @@ -600,13 +599,13 @@ public class DomainFlowUtils { } else { builder.setAvailIfSupported(true); builder.setFees(TldSpecificLogicProxy.getCreatePrice( - registry, domainName, clientIdentifier, now, years, eppInput).getFees()); + registry, domainNameString, clientIdentifier, now, years, eppInput).getFees()); } break; case RENEW: builder.setAvailIfSupported(true); builder.setFees(TldSpecificLogicProxy.getRenewPrice( - registry, domainName, clientIdentifier, now, years, eppInput).getFees()); + registry, domainNameString, clientIdentifier, now, years, eppInput).getFees()); break; case RESTORE: if (years != 1) { @@ -614,17 +613,17 @@ public class DomainFlowUtils { } builder.setAvailIfSupported(true); builder.setFees(TldSpecificLogicProxy.getRestorePrice( - registry, domainName, clientIdentifier, now, eppInput).getFees()); + registry, domainNameString, clientIdentifier, now, eppInput).getFees()); break; case TRANSFER: builder.setAvailIfSupported(true); builder.setFees(TldSpecificLogicProxy.getTransferPrice( - registry, domainName, clientIdentifier, now, years, eppInput).getFees()); + registry, domainNameString, clientIdentifier, now, years, eppInput).getFees()); break; case UPDATE: builder.setAvailIfSupported(true); builder.setFees(TldSpecificLogicProxy.getUpdatePrice( - registry, domainName, clientIdentifier, now, eppInput).getFees()); + registry, domainNameString, clientIdentifier, now, eppInput).getFees()); break; default: throw new UnknownFeeCommandException(feeRequest.getUnparsedCommandName()); diff --git a/java/google/registry/flows/domain/DomainInfoFlow.java b/java/google/registry/flows/domain/DomainInfoFlow.java index 06c38296a..c9043e0d1 100644 --- a/java/google/registry/flows/domain/DomainInfoFlow.java +++ b/java/google/registry/flows/domain/DomainInfoFlow.java @@ -19,6 +19,7 @@ import static google.registry.flows.domain.DomainFlowUtils.handleFeeRequest; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.common.net.InternetDomainName; import google.registry.flows.EppException; import google.registry.model.domain.DomainResource; import google.registry.model.domain.DomainResource.Builder; @@ -97,8 +98,7 @@ public class DomainInfoFlow extends BaseDomainInfoFlow handleFeeRequest( feeInfo, builder, - getTargetId(), - existingResource.getTld(), + InternetDomainName.from(getTargetId()), getClientId(), null, now, diff --git a/java/google/registry/model/domain/fee/FeeCheckCommandExtension.java b/java/google/registry/model/domain/fee/FeeCheckCommandExtension.java index e8b662720..160ec6718 100644 --- a/java/google/registry/model/domain/fee/FeeCheckCommandExtension.java +++ b/java/google/registry/model/domain/fee/FeeCheckCommandExtension.java @@ -24,7 +24,7 @@ import org.joda.money.CurrencyUnit; * of items requesting the fees for particular commands and domains. For some versions of the fee * extension, the currency is also specified here; for other versions it is contained in the * individual items. - * + * * @type C the type of extension item used by this command (e.g. v6 items for a v6 extension) * @type R the type of response returned for for this command (e.g. v6 responses for a v6 extension) */ @@ -33,13 +33,14 @@ public interface FeeCheckCommandExtension< R extends FeeCheckResponseExtension> extends CommandExtension { - /** True if this version of the fee extension specifies the currency at the top level. */ - public boolean isCurrencySupported(); + /** + * Three-character ISO4217 currency code. + * + *

Returns null if this version of the fee extension doesn't specify currency at the top level. + */ + public CurrencyUnit getCurrency(); - /** Three-character currency code; throws an exception if currency is not supported. */ - public CurrencyUnit getCurrency() throws UnsupportedOperationException; - public ImmutableSet getItems(); - + public R createResponse(ImmutableList items); } diff --git a/java/google/registry/model/domain/fee/FeeQueryCommandExtensionItem.java b/java/google/registry/model/domain/fee/FeeQueryCommandExtensionItem.java index eb91a7604..fc0e2cc6b 100644 --- a/java/google/registry/model/domain/fee/FeeQueryCommandExtensionItem.java +++ b/java/google/registry/model/domain/fee/FeeQueryCommandExtensionItem.java @@ -35,18 +35,19 @@ public interface FeeQueryCommandExtensionItem { UPDATE } - /** True if this version of fee extension includes a currency in this type of query item. */ - public boolean isCurrencySupported(); - - /** A three-character ISO4217 currency code; throws an exception if currency is not supported. */ - public CurrencyUnit getCurrency() throws UnsupportedOperationException; + /** + * Three-character ISO4217 currency code. + * + *

Returns null if this version of the fee extension doesn't specify currency at the top level. + */ + public CurrencyUnit getCurrency(); /** The name of the command being checked. */ public CommandName getCommandName(); - + /** The unparse name of the command being checked, for use in error strings. */ public String getUnparsedCommandName(); - + /** The phase of the command being checked. */ public String getPhase(); diff --git a/java/google/registry/model/domain/fee06/FeeCheckCommandExtensionItemV06.java b/java/google/registry/model/domain/fee06/FeeCheckCommandExtensionItemV06.java index 238017e6f..7b1c977d1 100644 --- a/java/google/registry/model/domain/fee06/FeeCheckCommandExtensionItemV06.java +++ b/java/google/registry/model/domain/fee06/FeeCheckCommandExtensionItemV06.java @@ -29,7 +29,7 @@ public class FeeCheckCommandExtensionItemV06 String name; CurrencyUnit currency; - + @Override public boolean isDomainNameSupported() { return true; @@ -40,11 +40,6 @@ public class FeeCheckCommandExtensionItemV06 return name; } - @Override - public boolean isCurrencySupported() { - return true; - } - @Override public CurrencyUnit getCurrency() { return currency; diff --git a/java/google/registry/model/domain/fee06/FeeCheckCommandExtensionV06.java b/java/google/registry/model/domain/fee06/FeeCheckCommandExtensionV06.java index 45590b087..afe88d242 100644 --- a/java/google/registry/model/domain/fee06/FeeCheckCommandExtensionV06.java +++ b/java/google/registry/model/domain/fee06/FeeCheckCommandExtensionV06.java @@ -32,18 +32,13 @@ public class FeeCheckCommandExtensionV06 extends ImmutableObject implements FeeCheckCommandExtension< FeeCheckCommandExtensionItemV06, FeeCheckResponseExtensionV06> { - + @XmlElement(name = "domain") Set items; - @Override - public boolean isCurrencySupported() { - return false; - } - @Override public CurrencyUnit getCurrency() { - throw new UnsupportedOperationException("Currency not supported"); + return null; // This version of the fee extension doesn't specify a top-level currency. } @Override diff --git a/java/google/registry/model/domain/fee06/FeeInfoCommandExtensionV06.java b/java/google/registry/model/domain/fee06/FeeInfoCommandExtensionV06.java index 56c905c88..6ce0a4dda 100644 --- a/java/google/registry/model/domain/fee06/FeeInfoCommandExtensionV06.java +++ b/java/google/registry/model/domain/fee06/FeeInfoCommandExtensionV06.java @@ -25,15 +25,10 @@ import org.joda.money.CurrencyUnit; @XmlType(propOrder = {"currency", "command", "period"}) public class FeeInfoCommandExtensionV06 extends FeeQueryCommandExtensionItemImpl implements CommandExtension { - + /** A three-character ISO4217 currency code. */ CurrencyUnit currency; - @Override - public boolean isCurrencySupported() { - return true; - } - @Override public CurrencyUnit getCurrency() { return currency; diff --git a/java/google/registry/model/domain/fee11/FeeCheckCommandExtensionV11.java b/java/google/registry/model/domain/fee11/FeeCheckCommandExtensionV11.java index 57c6b4718..ceb8791f8 100644 --- a/java/google/registry/model/domain/fee11/FeeCheckCommandExtensionV11.java +++ b/java/google/registry/model/domain/fee11/FeeCheckCommandExtensionV11.java @@ -52,22 +52,20 @@ public class FeeCheckCommandExtensionV11 extends ImmutableObject /** Three-letter currency code in which results should be returned. */ CurrencyUnit currency; - + /** The period to check. */ Period period; /** The class to check. */ @XmlElement(name = "class") String feeClass; - - @Override - public boolean isCurrencySupported() { - return false; - } - + @Override public CurrencyUnit getCurrency() { - throw new UnsupportedOperationException("Currency not supported"); + // This version of the fee extension does not have any items, and although the currency is + // specified at the top level we've modeled it as a single fake item with the currency inside, + // so there's no top level currency to return here. + return null; } @Override @@ -96,13 +94,13 @@ public class FeeCheckCommandExtensionV11 extends ImmutableObject public CommandName getCommandName() { return command.getCommand(); } - + /** The command name before being parsed into an enum, for use in error strings. */ @Override public String getUnparsedCommandName() { return command.getUnparsedCommandName(); } - + /** The phase of the command being checked. */ @Override public String getPhase() { @@ -119,22 +117,17 @@ public class FeeCheckCommandExtensionV11 extends ImmutableObject public Period getPeriod() { return Optional.fromNullable(period).or(DEFAULT_PERIOD); } - + @Override public boolean isDomainNameSupported() { return false; } - + @Override public String getDomainName() { throw new UnsupportedOperationException("Domain not supported"); } - @Override - public boolean isCurrencySupported() { - return true; - } - @Override public CurrencyUnit getCurrency() { return currency; diff --git a/java/google/registry/model/domain/fee12/FeeCheckCommandExtensionItemV12.java b/java/google/registry/model/domain/fee12/FeeCheckCommandExtensionItemV12.java index 78782efbe..329667d17 100644 --- a/java/google/registry/model/domain/fee12/FeeCheckCommandExtensionItemV12.java +++ b/java/google/registry/model/domain/fee12/FeeCheckCommandExtensionItemV12.java @@ -30,13 +30,13 @@ import org.joda.time.DateTime; /** * An individual price check item in version 0.12 of the fee extension on domain check commands. * Items look like: - * + * * * 1 * premium * 2017-05-17T13:22:21.0Z * - * + * * In a change from previous versions of the extension, items do not contain domain names; instead, * the names from the non-extension check element are used. */ @@ -49,7 +49,7 @@ public class FeeCheckCommandExtensionItemV12 @XmlAttribute(name = "name") String commandName; - + @XmlAttribute String phase; @@ -58,10 +58,10 @@ public class FeeCheckCommandExtensionItemV12 @XmlElement Period period; - + @XmlElement(name = "class") String feeClass; - + @XmlElement(name = "date") DateTime feeDate; @@ -75,22 +75,17 @@ public class FeeCheckCommandExtensionItemV12 public String getDomainName() { throw new UnsupportedOperationException("Domain not supported"); } - - @Override - public boolean isCurrencySupported() { - return false; - } - + @Override public CurrencyUnit getCurrency() { - throw new UnsupportedOperationException("Currency not supported"); + return null; // This version of the fee extension doesn't specify currency per-item. } - + @Override public String getUnparsedCommandName() { return commandName; } - + @Override public CommandName getCommandName() { // Require the xml string to be lowercase. @@ -108,7 +103,7 @@ public class FeeCheckCommandExtensionItemV12 public String getPhase() { return phase; } - + @Override public String getSubphase() { return subphase; diff --git a/java/google/registry/model/domain/fee12/FeeCheckCommandExtensionV12.java b/java/google/registry/model/domain/fee12/FeeCheckCommandExtensionV12.java index 309d86239..0bd94185a 100644 --- a/java/google/registry/model/domain/fee12/FeeCheckCommandExtensionV12.java +++ b/java/google/registry/model/domain/fee12/FeeCheckCommandExtensionV12.java @@ -36,17 +36,12 @@ public class FeeCheckCommandExtensionV12 extends ImmutableObject FeeCheckResponseExtensionV12> { CurrencyUnit currency; - - @Override - public boolean isCurrencySupported() { - return true; - } @Override public CurrencyUnit getCurrency() { return currency; } - + @XmlElement(name = "command") Set items;