Use string keys for the multimap of pricing engines for TLDs

This is better than the previous way of using the canonical name of the class,
because the previous way did not allow for refactoring, and also required the
PremiumPricingEngine to live in the model package lest there be circular
dependencies, which does not seem ideal.

Note that, for reasons of backwards compatibility with existing persisted data,
the name of the static premium pricing engine has been set to its canonical
class name, but the class can now be refactored going forward so long as this
string remains unchanged, and any new pricing engine implementations can use
whatever string key they want (it doesn't have to be a canonical class name).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=129215185
This commit is contained in:
mcilwain 2016-08-03 08:08:27 -07:00 committed by Ben McIlwain
parent 7cc7dc4af2
commit ea24f6ca31
9 changed files with 26 additions and 48 deletions

View file

@ -34,6 +34,9 @@ import org.joda.time.DateTime;
/** A premium list pricing engine that stores static pricing information in Datastore entities. */
public final class StaticPremiumListPricingEngine implements PremiumPricingEngine {
/** The name of the pricing engine, as used in {@code Registry.pricingEngineClassName}. */
public static final String NAME = "google.registry.model.pricing.StaticPremiumListPricingEngine";
@Inject StaticPremiumListPricingEngine() {}
@Override

View file

@ -58,7 +58,6 @@ import google.registry.model.common.EntityGroupRoot;
import google.registry.model.common.TimedTransitionProperty;
import google.registry.model.common.TimedTransitionProperty.TimedTransition;
import google.registry.model.domain.fee.EapFee;
import google.registry.model.pricing.PremiumPricingEngine;
import google.registry.model.pricing.StaticPremiumListPricingEngine;
import google.registry.model.registry.label.PremiumList;
import google.registry.model.registry.label.ReservedList;
@ -252,15 +251,18 @@ public class Registry extends ImmutableObject implements Buildable {
@OnLoad
void backfillPricingEngine() {
if (pricingEngineClassName == null) {
pricingEngineClassName = StaticPremiumListPricingEngine.class.getCanonicalName();
pricingEngineClassName = StaticPremiumListPricingEngine.NAME;
}
}
/**
* The fully qualified canonical classname of the pricing engine that this TLD uses.
* The name of the pricing engine that this TLD uses.
*
* <p>This must be a valid key for the map of pricing engines injected by
* <code>@Inject Map<String, PricingEngine></code>
* {@code @Inject Map<String, PricingEngine>}.
*
* <p>Note that it used to be the canonical class name, hence the name of this field, but this
* restriction has since been relaxed and it may now be any unique string.
*/
String pricingEngineClassName;
@ -609,10 +611,8 @@ public class Registry extends ImmutableObject implements Buildable {
return this;
}
public Builder setPremiumPricingEngineClass(
Class<? extends PremiumPricingEngine> pricingEngineClass) {
getInstance().pricingEngineClassName =
checkArgumentNotNull(pricingEngineClass).getCanonicalName();
public Builder setPremiumPricingEngine(String pricingEngineClass) {
getInstance().pricingEngineClassName = checkArgumentNotNull(pricingEngineClass);
return this;
}