Add additional specific PricingEngineProxy methods

We already had methods to return just the create or just the renew price. I added more to return just the premium flag or just the fee class.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=136833071
This commit is contained in:
mountford 2016-10-21 08:10:33 -07:00 committed by Ben McIlwain
parent fad0aa4ffa
commit aecca10989
7 changed files with 29 additions and 19 deletions

View file

@ -27,7 +27,7 @@ import static google.registry.model.domain.fee.Fee.FEE_EXTENSION_URIS;
import static google.registry.model.eppoutput.Result.Code.SUCCESS; import static google.registry.model.eppoutput.Result.Code.SUCCESS;
import static google.registry.model.index.DomainApplicationIndex.loadActiveApplicationsByDomainName; import static google.registry.model.index.DomainApplicationIndex.loadActiveApplicationsByDomainName;
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.isDomainPremium;
import static google.registry.util.CollectionUtils.nullToEmpty; import static google.registry.util.CollectionUtils.nullToEmpty;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -158,7 +158,7 @@ public final class DomainCheckFlow extends LoggedInFlow {
} }
ReservationType reservationType = getReservationType(domainName); ReservationType reservationType = getReservationType(domainName);
if (reservationType == UNRESERVED if (reservationType == UNRESERVED
&& getPricesForDomainName(domainName.toString(), now).isPremium() && isDomainPremium(domainName.toString(), now)
&& registry.getPremiumPriceAckRequired() && registry.getPremiumPriceAckRequired()
&& Collections.disjoint( && Collections.disjoint(
nullToEmpty(sessionMetadata.getServiceExtensionUris()), nullToEmpty(sessionMetadata.getServiceExtensionUris()),

View file

@ -27,7 +27,7 @@ import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.Registries.findTldForName; import static google.registry.model.registry.Registries.findTldForName;
import static google.registry.model.registry.label.ReservedList.getReservation; import static google.registry.model.registry.label.ReservedList.getReservation;
import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName; import static google.registry.pricing.PricingEngineProxy.isDomainPremium;
import static google.registry.tldconfig.idn.IdnLabelValidator.findValidIdnTableForTld; import static google.registry.tldconfig.idn.IdnLabelValidator.findValidIdnTableForTld;
import static google.registry.util.CollectionUtils.nullToEmpty; import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.END_OF_TIME;
@ -413,7 +413,7 @@ public class DomainFlowUtils {
*/ */
static void verifyPremiumNameIsNotBlocked( static void verifyPremiumNameIsNotBlocked(
String domainName, DateTime priceTime, String clientId) throws EppException { String domainName, DateTime priceTime, String clientId) throws EppException {
if (getPricesForDomainName(domainName, priceTime).isPremium()) { if (isDomainPremium(domainName, priceTime)) {
// NB: The load of the Registar object is transactionless, which means that it should hit // NB: The load of the Registar object is transactionless, which means that it should hit
// memcache most of the time. // memcache most of the time.
if (Registrar.loadByClientId(clientId).getBlockPremiumNames()) { if (Registrar.loadByClientId(clientId).getBlockPremiumNames()) {
@ -686,7 +686,7 @@ public class DomainFlowUtils {
throws EppException { throws EppException {
Registry registry = Registry.get(tld); Registry registry = Registry.get(tld);
if (registry.getPremiumPriceAckRequired() if (registry.getPremiumPriceAckRequired()
&& getPricesForDomainName(domainName, priceTime).isPremium() && isDomainPremium(domainName, priceTime)
&& feeCommand == null) { && feeCommand == null) {
throw new FeesRequiredForPremiumNameException(); throw new FeesRequiredForPremiumNameException();
} }

View file

@ -17,7 +17,9 @@ package google.registry.flows.domain;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName; import static google.registry.pricing.PricingEngineProxy.getDomainCreateCost;
import static google.registry.pricing.PricingEngineProxy.getDomainFeeClass;
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
import static google.registry.util.CollectionUtils.nullToEmpty; import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
@ -35,7 +37,6 @@ import google.registry.model.domain.fee.BaseFee.FeeType;
import google.registry.model.domain.fee.Credit; import google.registry.model.domain.fee.Credit;
import google.registry.model.domain.fee.Fee; import google.registry.model.domain.fee.Fee;
import google.registry.model.eppinput.EppInput; import google.registry.model.eppinput.EppInput;
import google.registry.model.pricing.PremiumPricingEngine.DomainPrices;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import java.util.List; import java.util.List;
import org.joda.money.CurrencyUnit; import org.joda.money.CurrencyUnit;
@ -152,9 +153,8 @@ public final class TldSpecificLogicProxy {
createFeeOrCredit = extraFlowLogic.get() createFeeOrCredit = extraFlowLogic.get()
.getCreateFeeOrCredit(domainName, clientId, date, years, eppInput); .getCreateFeeOrCredit(domainName, clientId, date, years, eppInput);
} else { } else {
DomainPrices prices = getPricesForDomainName(domainName, date);
createFeeOrCredit = createFeeOrCredit =
Fee.create(prices.getCreateCost().multipliedBy(years).getAmount(), FeeType.CREATE); Fee.create(getDomainCreateCost(domainName, date, years).getAmount(), FeeType.CREATE);
} }
// Create fees for the cost and the EAP fee, if any. // Create fees for the cost and the EAP fee, if any.
@ -188,8 +188,7 @@ public final class TldSpecificLogicProxy {
return return
extraFlowLogic.get().getRenewFeeOrCredit(domain, clientId, date, years, eppInput); extraFlowLogic.get().getRenewFeeOrCredit(domain, clientId, date, years, eppInput);
} else { } else {
DomainPrices prices = getPricesForDomainName(domainName, date); return Fee.create(getDomainRenewCost(domainName, date, years).getAmount(), FeeType.RENEW);
return Fee.create(prices.getRenewCost().multipliedBy(years).getAmount(), FeeType.RENEW);
} }
} }
@ -262,7 +261,7 @@ public final class TldSpecificLogicProxy {
/** Returns the fee class for a given domain and date. */ /** Returns the fee class for a given domain and date. */
public static Optional<String> getFeeClass(String domainName, DateTime date) { public static Optional<String> getFeeClass(String domainName, DateTime date) {
return getPricesForDomainName(domainName, date).getFeeClass(); return getDomainFeeClass(domainName, date);
} }
/** /**

View file

@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static google.registry.util.DomainNameUtils.getTldFromDomainName; import static google.registry.util.DomainNameUtils.getTldFromDomainName;
import com.google.common.base.Optional;
import google.registry.model.pricing.PremiumPricingEngine; import google.registry.model.pricing.PremiumPricingEngine;
import google.registry.model.pricing.PremiumPricingEngine.DomainPrices; import google.registry.model.pricing.PremiumPricingEngine.DomainPrices;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
@ -46,6 +47,16 @@ public final class PricingEngineProxy {
return getPricesForDomainName(domainName, priceTime).getRenewCost().multipliedBy(years); return getPricesForDomainName(domainName, priceTime).getRenewCost().multipliedBy(years);
} }
/** Returns true if the specified domain name is premium. */
public static boolean isDomainPremium(String domainName, DateTime priceTime) {
return getPricesForDomainName(domainName, priceTime).isPremium();
}
/** Returns the fee class of the specified domain name. */
public static Optional<String> getDomainFeeClass(String domainName, DateTime priceTime) {
return getPricesForDomainName(domainName, priceTime).getFeeClass();
}
/** /**
* Returns the full {@link DomainPrices} details for the given domain name by dispatching to the * Returns the full {@link DomainPrices} details for the given domain name by dispatching to the
* appropriate {@link PremiumPricingEngine} based on what is configured for the TLD that the * appropriate {@link PremiumPricingEngine} based on what is configured for the TLD that the

View file

@ -18,7 +18,7 @@ import static com.google.common.io.BaseEncoding.base16;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.domain.fee.Fee.FEE_EXTENSION_URIS; import static google.registry.model.domain.fee.Fee.FEE_EXTENSION_URIS;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName; import static google.registry.pricing.PricingEngineProxy.isDomainPremium;
import static google.registry.testing.DatastoreHelper.assertBillingEvents; import static google.registry.testing.DatastoreHelper.assertBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.createTlds; import static google.registry.testing.DatastoreHelper.createTlds;
@ -173,7 +173,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
DomainResource domain = reloadResourceByForeignKey(); DomainResource domain = reloadResourceByForeignKey();
// Calculate the total cost. // Calculate the total cost.
Money cost = getPricesForDomainName(getUniqueIdFromCommand(), clock.nowUtc()).isPremium() Money cost = isDomainPremium(getUniqueIdFromCommand(), clock.nowUtc())
? Money.of(USD, 200) ? Money.of(USD, 200)
: Money.of(USD, 26); : Money.of(USD, 26);
Money eapFee = Money.of(Registry.get(domainTld).getCurrency(), Money eapFee = Money.of(Registry.get(domainTld).getCurrency(),

View file

@ -84,7 +84,7 @@ public class TldSpecificLogicProxyTest extends ShardableTestCase {
b, Money.of(USD, 50))) b, Money.of(USD, 50)))
.build()); .build());
basicCreateCost = basicCreateCost =
PricingEngineProxy.getPricesForDomainName("example.tld", clock.nowUtc()).getCreateCost(); PricingEngineProxy.getDomainCreateCost("example.tld", clock.nowUtc(), 1);
} }
@Test @Test

View file

@ -17,7 +17,7 @@ package google.registry.pricing;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.pricing.PricingEngineProxy.getDomainCreateCost; import static google.registry.pricing.PricingEngineProxy.getDomainCreateCost;
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost; import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName; import static google.registry.pricing.PricingEngineProxy.isDomainPremium;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistPremiumList; import static google.registry.testing.DatastoreHelper.persistPremiumList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
@ -91,9 +91,9 @@ public class PricingEngineProxyTest {
@Test @Test
public void testIsPremiumDomain() throws Exception { public void testIsPremiumDomain() throws Exception {
createTld("example"); createTld("example");
assertThat(getPricesForDomainName("poor.example", clock.nowUtc()).isPremium()).isFalse(); assertThat(isDomainPremium("poor.example", clock.nowUtc())).isFalse();
assertThat(getPricesForDomainName("rich.example", clock.nowUtc()).isPremium()).isTrue(); assertThat(isDomainPremium("rich.example", clock.nowUtc())).isTrue();
assertThat(getPricesForDomainName("richer.example", clock.nowUtc()).isPremium()).isTrue(); assertThat(isDomainPremium("richer.example", clock.nowUtc())).isTrue();
} }
@Test @Test