Simplify the use of the fee extension a little

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=133149148
This commit is contained in:
cgoldfeder 2016-09-14 11:16:35 -07:00 committed by Ben McIlwain
parent 1ee02108ae
commit 01e2e0141d
11 changed files with 57 additions and 92 deletions

View file

@ -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.model.registry.label.ReservationType.UNRESERVED;
import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName; import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName;
import static google.registry.util.CollectionUtils.nullToEmpty; import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.DomainNameUtils.getTldFromDomainName;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
@ -49,7 +48,6 @@ import google.registry.model.registry.label.ReservationType;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
import org.joda.money.CurrencyUnit;
/** /**
* An EPP flow that checks whether a domain can be provisioned. * An EPP flow that checks whether a domain can be provisioned.
@ -160,7 +158,6 @@ public class DomainCheckFlow extends BaseDomainCheckFlow {
if (feeCheck == null) { if (feeCheck == null) {
return null; // No fee checks were requested. return null; // No fee checks were requested.
} }
CurrencyUnit topLevelCurrency = feeCheck.isCurrencySupported() ? feeCheck.getCurrency() : null;
ImmutableList.Builder<FeeCheckResponseExtensionItem> feeCheckResponseItemsBuilder = ImmutableList.Builder<FeeCheckResponseExtensionItem> feeCheckResponseItemsBuilder =
new ImmutableList.Builder<>(); new ImmutableList.Builder<>();
for (FeeCheckCommandExtensionItem feeCheckItem : feeCheck.getItems()) { for (FeeCheckCommandExtensionItem feeCheckItem : feeCheck.getItems()) {
@ -169,10 +166,9 @@ public class DomainCheckFlow extends BaseDomainCheckFlow {
handleFeeRequest( handleFeeRequest(
feeCheckItem, feeCheckItem,
builder, builder,
domainName, domainNames.get(domainName),
getTldFromDomainName(domainName),
getClientId(), getClientId(),
topLevelCurrency, feeCheck.getCurrency(),
now, now,
eppInput); eppInput);
feeCheckResponseItemsBuilder feeCheckResponseItemsBuilder

View file

@ -564,14 +564,13 @@ public class DomainFlowUtils {
static void handleFeeRequest( static void handleFeeRequest(
FeeQueryCommandExtensionItem feeRequest, FeeQueryCommandExtensionItem feeRequest,
FeeQueryResponseExtensionItem.Builder builder, FeeQueryResponseExtensionItem.Builder builder,
String domainName, InternetDomainName domain,
String tld,
String clientIdentifier, String clientIdentifier,
@Nullable CurrencyUnit topLevelCurrency, @Nullable CurrencyUnit topLevelCurrency,
DateTime now, DateTime now,
EppInput eppInput) throws EppException { EppInput eppInput) throws EppException {
InternetDomainName domain = InternetDomainName.from(domainName); String domainNameString = domain.toString();
Registry registry = Registry.get(tld); Registry registry = Registry.get(domain.parent().toString());
int years = verifyUnitIsYears(feeRequest.getPeriod()).getValue(); int years = verifyUnitIsYears(feeRequest.getPeriod()).getValue();
boolean isSunrise = registry.getTldState(now).equals(TldState.SUNRISE); boolean isSunrise = registry.getTldState(now).equals(TldState.SUNRISE);
@ -580,7 +579,7 @@ public class DomainFlowUtils {
} }
CurrencyUnit currency = CurrencyUnit currency =
feeRequest.isCurrencySupported() ? feeRequest.getCurrency() : topLevelCurrency; feeRequest.getCurrency() != null ? feeRequest.getCurrency() : topLevelCurrency;
if ((currency != null) && !currency.equals(registry.getCurrency())) { if ((currency != null) && !currency.equals(registry.getCurrency())) {
throw new CurrencyUnitMismatchException(); throw new CurrencyUnitMismatchException();
} }
@ -589,7 +588,7 @@ public class DomainFlowUtils {
.setCommand(feeRequest.getCommandName(), feeRequest.getPhase(), feeRequest.getSubphase()) .setCommand(feeRequest.getCommandName(), feeRequest.getPhase(), feeRequest.getSubphase())
.setCurrencyIfSupported(registry.getCurrency()) .setCurrencyIfSupported(registry.getCurrency())
.setPeriod(feeRequest.getPeriod()) .setPeriod(feeRequest.getPeriod())
.setClass(TldSpecificLogicProxy.getFeeClass(domainName, now).orNull()); .setClass(TldSpecificLogicProxy.getFeeClass(domainNameString, now).orNull());
switch (feeRequest.getCommandName()) { switch (feeRequest.getCommandName()) {
case CREATE: case CREATE:
@ -600,13 +599,13 @@ public class DomainFlowUtils {
} else { } else {
builder.setAvailIfSupported(true); builder.setAvailIfSupported(true);
builder.setFees(TldSpecificLogicProxy.getCreatePrice( builder.setFees(TldSpecificLogicProxy.getCreatePrice(
registry, domainName, clientIdentifier, now, years, eppInput).getFees()); registry, domainNameString, clientIdentifier, now, years, eppInput).getFees());
} }
break; break;
case RENEW: case RENEW:
builder.setAvailIfSupported(true); builder.setAvailIfSupported(true);
builder.setFees(TldSpecificLogicProxy.getRenewPrice( builder.setFees(TldSpecificLogicProxy.getRenewPrice(
registry, domainName, clientIdentifier, now, years, eppInput).getFees()); registry, domainNameString, clientIdentifier, now, years, eppInput).getFees());
break; break;
case RESTORE: case RESTORE:
if (years != 1) { if (years != 1) {
@ -614,17 +613,17 @@ public class DomainFlowUtils {
} }
builder.setAvailIfSupported(true); builder.setAvailIfSupported(true);
builder.setFees(TldSpecificLogicProxy.getRestorePrice( builder.setFees(TldSpecificLogicProxy.getRestorePrice(
registry, domainName, clientIdentifier, now, eppInput).getFees()); registry, domainNameString, clientIdentifier, now, eppInput).getFees());
break; break;
case TRANSFER: case TRANSFER:
builder.setAvailIfSupported(true); builder.setAvailIfSupported(true);
builder.setFees(TldSpecificLogicProxy.getTransferPrice( builder.setFees(TldSpecificLogicProxy.getTransferPrice(
registry, domainName, clientIdentifier, now, years, eppInput).getFees()); registry, domainNameString, clientIdentifier, now, years, eppInput).getFees());
break; break;
case UPDATE: case UPDATE:
builder.setAvailIfSupported(true); builder.setAvailIfSupported(true);
builder.setFees(TldSpecificLogicProxy.getUpdatePrice( builder.setFees(TldSpecificLogicProxy.getUpdatePrice(
registry, domainName, clientIdentifier, now, eppInput).getFees()); registry, domainNameString, clientIdentifier, now, eppInput).getFees());
break; break;
default: default:
throw new UnknownFeeCommandException(feeRequest.getUnparsedCommandName()); throw new UnknownFeeCommandException(feeRequest.getUnparsedCommandName());

View file

@ -19,6 +19,7 @@ import static google.registry.flows.domain.DomainFlowUtils.handleFeeRequest;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.net.InternetDomainName;
import google.registry.flows.EppException; import google.registry.flows.EppException;
import google.registry.model.domain.DomainResource; import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainResource.Builder; import google.registry.model.domain.DomainResource.Builder;
@ -97,8 +98,7 @@ public class DomainInfoFlow extends BaseDomainInfoFlow<DomainResource, Builder>
handleFeeRequest( handleFeeRequest(
feeInfo, feeInfo,
builder, builder,
getTargetId(), InternetDomainName.from(getTargetId()),
existingResource.getTld(),
getClientId(), getClientId(),
null, null,
now, now,

View file

@ -33,11 +33,12 @@ public interface FeeCheckCommandExtension<
R extends FeeCheckResponseExtension<?>> R extends FeeCheckResponseExtension<?>>
extends CommandExtension { 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.
*
/** Three-character currency code; throws an exception if currency is not supported. */ * <p>Returns null if this version of the fee extension doesn't specify currency at the top level.
public CurrencyUnit getCurrency() throws UnsupportedOperationException; */
public CurrencyUnit getCurrency();
public ImmutableSet<C> getItems(); public ImmutableSet<C> getItems();

View file

@ -35,11 +35,12 @@ public interface FeeQueryCommandExtensionItem {
UPDATE UPDATE
} }
/** True if this version of fee extension includes a currency in this type of query item. */ /**
public boolean isCurrencySupported(); * Three-character ISO4217 currency code.
*
/** A three-character ISO4217 currency code; throws an exception if currency is not supported. */ * <p>Returns null if this version of the fee extension doesn't specify currency at the top level.
public CurrencyUnit getCurrency() throws UnsupportedOperationException; */
public CurrencyUnit getCurrency();
/** The name of the command being checked. */ /** The name of the command being checked. */
public CommandName getCommandName(); public CommandName getCommandName();

View file

@ -40,11 +40,6 @@ public class FeeCheckCommandExtensionItemV06
return name; return name;
} }
@Override
public boolean isCurrencySupported() {
return true;
}
@Override @Override
public CurrencyUnit getCurrency() { public CurrencyUnit getCurrency() {
return currency; return currency;

View file

@ -36,14 +36,9 @@ public class FeeCheckCommandExtensionV06 extends ImmutableObject
@XmlElement(name = "domain") @XmlElement(name = "domain")
Set<FeeCheckCommandExtensionItemV06> items; Set<FeeCheckCommandExtensionItemV06> items;
@Override
public boolean isCurrencySupported() {
return false;
}
@Override @Override
public CurrencyUnit getCurrency() { 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 @Override

View file

@ -29,11 +29,6 @@ public class FeeInfoCommandExtensionV06
/** A three-character ISO4217 currency code. */ /** A three-character ISO4217 currency code. */
CurrencyUnit currency; CurrencyUnit currency;
@Override
public boolean isCurrencySupported() {
return true;
}
@Override @Override
public CurrencyUnit getCurrency() { public CurrencyUnit getCurrency() {
return currency; return currency;

View file

@ -60,14 +60,12 @@ public class FeeCheckCommandExtensionV11 extends ImmutableObject
@XmlElement(name = "class") @XmlElement(name = "class")
String feeClass; String feeClass;
@Override
public boolean isCurrencySupported() {
return false;
}
@Override @Override
public CurrencyUnit getCurrency() { 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 @Override
@ -130,11 +128,6 @@ public class FeeCheckCommandExtensionV11 extends ImmutableObject
throw new UnsupportedOperationException("Domain not supported"); throw new UnsupportedOperationException("Domain not supported");
} }
@Override
public boolean isCurrencySupported() {
return true;
}
@Override @Override
public CurrencyUnit getCurrency() { public CurrencyUnit getCurrency() {
return currency; return currency;

View file

@ -76,14 +76,9 @@ public class FeeCheckCommandExtensionItemV12
throw new UnsupportedOperationException("Domain not supported"); throw new UnsupportedOperationException("Domain not supported");
} }
@Override
public boolean isCurrencySupported() {
return false;
}
@Override @Override
public CurrencyUnit getCurrency() { public CurrencyUnit getCurrency() {
throw new UnsupportedOperationException("Currency not supported"); return null; // This version of the fee extension doesn't specify currency per-item.
} }
@Override @Override

View file

@ -37,11 +37,6 @@ public class FeeCheckCommandExtensionV12 extends ImmutableObject
CurrencyUnit currency; CurrencyUnit currency;
@Override
public boolean isCurrencySupported() {
return true;
}
@Override @Override
public CurrencyUnit getCurrency() { public CurrencyUnit getCurrency() {
return currency; return currency;