mirror of
https://github.com/google/nomulus.git
synced 2025-07-23 19:20:44 +02:00
Rename PricingEngine to PremiumPricingEngine
This properly reflects the fact that other, separate things will now be responsible both for EAP and for per-TLD custom pricing. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=124558165
This commit is contained in:
parent
366c5a344d
commit
6ba1d5e6df
11 changed files with 45 additions and 52 deletions
|
@ -16,7 +16,7 @@ package google.registry.pricing;
|
|||
|
||||
import dagger.Component;
|
||||
|
||||
import google.registry.model.pricing.PricingEngine;
|
||||
import google.registry.model.pricing.PremiumPricingEngine;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -32,5 +32,5 @@ import javax.inject.Singleton;
|
|||
@Singleton
|
||||
@Component(modules = {PricingModule.class})
|
||||
interface PricingComponent {
|
||||
Map<Class<? extends PricingEngine>, PricingEngine> pricingEngines();
|
||||
Map<Class<? extends PremiumPricingEngine>, PremiumPricingEngine> premiumPricingEngines();
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ import com.google.common.base.Function;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import google.registry.model.pricing.PricingEngine;
|
||||
import google.registry.model.pricing.PricingEngine.DomainPrices;
|
||||
import google.registry.model.pricing.PremiumPricingEngine;
|
||||
import google.registry.model.pricing.PremiumPricingEngine.DomainPrices;
|
||||
import google.registry.model.registry.Registry;
|
||||
|
||||
import org.joda.money.Money;
|
||||
|
@ -33,22 +33,22 @@ import java.util.Map;
|
|||
|
||||
/**
|
||||
* A global proxy providing static methods for getting premium prices that dispatches requests
|
||||
* correctly to the relevant {@link PricingEngine} implementation per TLD.
|
||||
* correctly to the relevant {@link PremiumPricingEngine} implementation per TLD.
|
||||
*/
|
||||
public final class PricingEngineProxy {
|
||||
|
||||
private static final Map<Class<? extends PricingEngine>, PricingEngine> pricingEngineClasses =
|
||||
DaggerPricingComponent.create().pricingEngines();
|
||||
private static final Map<Class<? extends PremiumPricingEngine>, PremiumPricingEngine>
|
||||
premiumPricingEngineClasses = DaggerPricingComponent.create().premiumPricingEngines();
|
||||
|
||||
// Dagger map keys have to be provided with constant values that are known at compile time, so it
|
||||
// can't be done using clazz.getCanonicalName(). So we construct the map by canonical name here,
|
||||
// at runtime.
|
||||
private static final ImmutableMap<String, PricingEngine> pricingEngines =
|
||||
private static final ImmutableMap<String, PremiumPricingEngine> premiumPricingEngines =
|
||||
Maps.uniqueIndex(
|
||||
pricingEngineClasses.values(),
|
||||
new Function<PricingEngine, String>() {
|
||||
premiumPricingEngineClasses.values(),
|
||||
new Function<PremiumPricingEngine, String>() {
|
||||
@Override
|
||||
public String apply(PricingEngine pricingEngine) {
|
||||
public String apply(PremiumPricingEngine pricingEngine) {
|
||||
return pricingEngine.getClass().getCanonicalName();
|
||||
}});
|
||||
|
||||
|
@ -66,13 +66,13 @@ public final class PricingEngineProxy {
|
|||
|
||||
/**
|
||||
* 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.
|
||||
* appropriate {@link PremiumPricingEngine} based on what is configured for the TLD that the
|
||||
* domain is under.
|
||||
*/
|
||||
public static DomainPrices getPricesForDomainName(String domainName, DateTime priceTime) {
|
||||
String tld = getTldFromDomainName(domainName);
|
||||
String clazz = Registry.get(tld).getPricingEngineClassName();
|
||||
PricingEngine engine = pricingEngines.get(clazz);
|
||||
String clazz = Registry.get(tld).getPremiumPricingEngineClassName();
|
||||
PremiumPricingEngine engine = premiumPricingEngines.get(clazz);
|
||||
checkState(engine != null, "Could not load pricing engine %s for TLD %s", clazz, tld);
|
||||
return engine.getDomainPrices(domainName, priceTime);
|
||||
}
|
||||
|
|
|
@ -19,29 +19,29 @@ import dagger.Module;
|
|||
import dagger.Provides;
|
||||
import dagger.multibindings.IntoMap;
|
||||
|
||||
import google.registry.model.pricing.PricingEngine;
|
||||
import google.registry.model.pricing.PremiumPricingEngine;
|
||||
import google.registry.model.pricing.StaticPremiumListPricingEngine;
|
||||
|
||||
/**
|
||||
* Dagger module for injecting pricing engines.
|
||||
*
|
||||
* <p>To add a new pricing engine, create a new class that implements {@link PricingEngine}, and add
|
||||
* a module that provides an instance of PricingEngine with a <code>PricingEngineClassKey</code>
|
||||
* annotation with the class of the implementation and also <code>@Provides @IntoMap</code>
|
||||
* annotations.
|
||||
* <p>To add a new pricing engine, create a new class that implements {@link PremiumPricingEngine},
|
||||
* and add a module that provides an instance of PricingEngine with a
|
||||
* <code>PricingEngineClassKey</code> annotation with the class of the implementation and also
|
||||
* <code>@Provides @IntoMap</code> annotations.
|
||||
*/
|
||||
@Module
|
||||
public class PricingModule {
|
||||
|
||||
/** The annotation used for PricingEngine implementation keys. */
|
||||
@MapKey
|
||||
@interface PricingEngineClassKey {
|
||||
Class<? extends PricingEngine> value();
|
||||
@interface PremiumPricingEngineClassKey {
|
||||
Class<? extends PremiumPricingEngine> value();
|
||||
}
|
||||
|
||||
@Provides @IntoMap
|
||||
@PricingEngineClassKey(StaticPremiumListPricingEngine.class)
|
||||
static PricingEngine provideStaticPremiumList(StaticPremiumListPricingEngine engine) {
|
||||
@PremiumPricingEngineClassKey(StaticPremiumListPricingEngine.class)
|
||||
static PremiumPricingEngine provideStaticPremiumList(StaticPremiumListPricingEngine engine) {
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue