mirror of
https://github.com/google/nomulus.git
synced 2025-05-29 00:40:09 +02:00
Support creation of EPP fee objects using custom descriptions
This is a reasonable thing that custom code might want to do (Donuts already has a use case). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=144216929
This commit is contained in:
parent
3ee98988c5
commit
a5d5c9e2fd
3 changed files with 32 additions and 16 deletions
|
@ -133,11 +133,6 @@ public abstract class BaseFee extends ImmutableObject {
|
||||||
return validDateRange;
|
return validDateRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void generateDescription(Object... args) {
|
|
||||||
checkState(type != null);
|
|
||||||
description = type.renderDescription(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasZeroCost() {
|
public boolean hasZeroCost() {
|
||||||
return cost.signum() == 0;
|
return cost.signum() == 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,17 +16,27 @@ package google.registry.model.domain.fee;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
/** A credit, in currency units specified elsewhere in the xml, and with an optional description. */
|
/** A credit, in currency units specified elsewhere in the xml, and with an optional description. */
|
||||||
public class Credit extends BaseFee {
|
public class Credit extends BaseFee {
|
||||||
|
|
||||||
|
/** Creates a Credit for the given amount and type with the default description. */
|
||||||
public static Credit create(BigDecimal cost, FeeType type, Object... descriptionArgs) {
|
public static Credit create(BigDecimal cost, FeeType type, Object... descriptionArgs) {
|
||||||
|
checkArgumentNotNull(type, "Must specify the type of the credit");
|
||||||
|
return createWithCustomDescription(cost, type, type.renderDescription(descriptionArgs));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates a Credit for the given amount and type with a custom description. */
|
||||||
|
public static Credit createWithCustomDescription(
|
||||||
|
BigDecimal cost, FeeType type, String description) {
|
||||||
Credit instance = new Credit();
|
Credit instance = new Credit();
|
||||||
instance.cost = checkNotNull(cost);
|
instance.cost = checkNotNull(cost);
|
||||||
checkArgument(instance.cost.signum() < 0);
|
checkArgument(instance.cost.signum() < 0);
|
||||||
instance.type = checkNotNull(type);
|
instance.type = checkNotNull(type);
|
||||||
instance.generateDescription(descriptionArgs);
|
instance.description = description;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ package google.registry.model.domain.fee;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Range;
|
import com.google.common.collect.Range;
|
||||||
|
@ -28,15 +29,14 @@ import org.joda.time.DateTime;
|
||||||
* description.
|
* description.
|
||||||
*/
|
*/
|
||||||
public class Fee extends BaseFee {
|
public class Fee extends BaseFee {
|
||||||
|
|
||||||
|
/** Creates a Fee for the given cost and type with the default description. */
|
||||||
public static Fee create(BigDecimal cost, FeeType type, Object... descriptionArgs) {
|
public static Fee create(BigDecimal cost, FeeType type, Object... descriptionArgs) {
|
||||||
Fee instance = new Fee();
|
checkArgumentNotNull(type, "Must specify the type of the fee");
|
||||||
instance.cost = checkNotNull(cost);
|
return createWithCustomDescription(cost, type, type.renderDescription(descriptionArgs));
|
||||||
checkArgument(instance.cost.signum() >= 0);
|
|
||||||
instance.type = checkNotNull(type);
|
|
||||||
instance.generateDescription(descriptionArgs);
|
|
||||||
return instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Creates a Fee for the given cost, type, and valid date range with the default description. */
|
||||||
public static Fee create(
|
public static Fee create(
|
||||||
BigDecimal cost, FeeType type, Range<DateTime> validDateRange, Object... descriptionArgs) {
|
BigDecimal cost, FeeType type, Range<DateTime> validDateRange, Object... descriptionArgs) {
|
||||||
Fee instance = create(cost, type, descriptionArgs);
|
Fee instance = create(cost, type, descriptionArgs);
|
||||||
|
@ -44,8 +44,19 @@ public class Fee extends BaseFee {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final ImmutableSet<String> FEE_EXTENSION_URIS = ImmutableSet.of(
|
/** Creates a Fee for the given cost and type with a custom description. */
|
||||||
ServiceExtension.FEE_0_12.getUri(),
|
public static Fee createWithCustomDescription(BigDecimal cost, FeeType type, String description) {
|
||||||
ServiceExtension.FEE_0_11.getUri(),
|
Fee instance = new Fee();
|
||||||
ServiceExtension.FEE_0_6.getUri());
|
instance.cost = checkNotNull(cost);
|
||||||
|
checkArgument(instance.cost.signum() >= 0);
|
||||||
|
instance.type = checkNotNull(type);
|
||||||
|
instance.description = description;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final ImmutableSet<String> FEE_EXTENSION_URIS =
|
||||||
|
ImmutableSet.of(
|
||||||
|
ServiceExtension.FEE_0_12.getUri(),
|
||||||
|
ServiceExtension.FEE_0_11.getUri(),
|
||||||
|
ServiceExtension.FEE_0_6.getUri());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue