Add additional return values to PricingEngine interface

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=123658519
This commit is contained in:
mcilwain 2016-05-31 10:47:02 -07:00 committed by Ben McIlwain
parent ca585dd0b5
commit 91f6c7006e
21 changed files with 191 additions and 191 deletions

View file

@ -16,16 +16,14 @@ package google.registry.pricing;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static google.registry.model.registry.Registries.assertTldExists;
import static google.registry.util.DomainNameUtils.getTldFromDomainName;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.net.InternetDomainName;
import google.registry.model.pricing.PricingEngine;
import google.registry.model.pricing.PricingEngine.DomainPrices;
import google.registry.model.registry.Registry;
import org.joda.money.Money;
@ -54,53 +52,29 @@ public final class PricingEngineProxy {
return pricingEngine.getClass().getCanonicalName();
}});
/** Returns true if the given domain name is on the premium price list. */
public static boolean isPremiumName(
String domainName, DateTime priceTime, String clientIdentifier) {
return isPremiumName(InternetDomainName.from(domainName), priceTime, clientIdentifier);
}
/** Returns true if the given domain name is on the premium price list. */
public static boolean isPremiumName(
InternetDomainName domainName, DateTime priceTime, String clientIdentifier) {
return getPremiumPriceForDomainName(domainName, priceTime, clientIdentifier).isPresent();
}
/** Returns the billing cost for registering the specified domain name for this many years. */
public static Money getDomainCreateCost(
String domainName, DateTime priceTime, String clientIdentifier, int years) {
public static Money getDomainCreateCost(String domainName, DateTime priceTime, int years) {
checkArgument(years > 0, "Number of years must be positive");
Optional<Money> annualCost =
getPremiumPriceForDomainName(
InternetDomainName.from(domainName), priceTime, clientIdentifier);
return annualCost
.or(Registry.get(getTldFromDomainName(domainName)).getStandardCreateCost())
.multipliedBy(years);
return getPricesForDomainName(domainName, priceTime).getCreateCost().multipliedBy(years);
}
/** Returns the billing cost for renewing the specified domain name for this many years. */
public static Money getDomainRenewCost(
String domainName, DateTime priceTime, String clientIdentifier, int years) {
public static Money getDomainRenewCost(String domainName, DateTime priceTime, int years) {
checkArgument(years > 0, "Number of years must be positive");
Optional<Money> annualCost =
getPremiumPriceForDomainName(
InternetDomainName.from(domainName), priceTime, clientIdentifier);
return annualCost
.or(Registry.get(getTldFromDomainName(domainName)).getStandardRenewCost(priceTime))
.multipliedBy(years);
return getPricesForDomainName(domainName, priceTime).getRenewCost().multipliedBy(years);
}
/**
* Returns whether the given domain name is premium by dispatching to the appropriate
* {@link PricingEngine} based on what is configured for the TLD that the domain is under.
* Returns the full {@link DomainPrices} details for the given domain name by dispatching to the
* appropriate {@link PricingEngine} based on what is configured for the TLD that the domain is
* under.
*/
private static Optional<Money> getPremiumPriceForDomainName(
InternetDomainName domainName, DateTime priceTime, String clientIdentifier) {
String tld = assertTldExists(getTldFromDomainName(domainName));
public static DomainPrices getPricesForDomainName(String domainName, DateTime priceTime) {
String tld = getTldFromDomainName(domainName);
String clazz = Registry.get(tld).getPricingEngineClassName();
PricingEngine engine = pricingEngines.get(clazz);
checkState(engine != null, "Could not load pricing engine %s for TLD %s", clazz, tld);
return engine.getPremiumPrice(domainName.toString(), priceTime, clientIdentifier);
return engine.getDomainPrices(domainName, priceTime);
}
private PricingEngineProxy() {}