mirror of
https://github.com/google/nomulus.git
synced 2025-05-28 16:30:12 +02:00
Refactor Fee class to support EAP fee
Currently EapFee is a separate class that has no inheritance from either BaseFee and Fee. With this CL its functionality is merged into the Fee class and the type of the fee can be identified by the FeeType enum in the Fee class. Future custom fees can follow the same pattern. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=133627570
This commit is contained in:
parent
0518f63aad
commit
77571e2063
9 changed files with 121 additions and 131 deletions
|
@ -17,6 +17,7 @@ package google.registry.model.domain.fee;
|
|||
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.xml.PeriodAdapter;
|
||||
import java.math.BigDecimal;
|
||||
|
@ -25,6 +26,7 @@ import javax.xml.bind.annotation.XmlEnumValue;
|
|||
import javax.xml.bind.annotation.XmlTransient;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Period;
|
||||
|
||||
/** Base class for the fee and credit types. */
|
||||
|
@ -75,9 +77,12 @@ public abstract class BaseFee extends ImmutableObject {
|
|||
|
||||
@XmlValue
|
||||
BigDecimal cost;
|
||||
|
||||
|
||||
@XmlTransient
|
||||
FeeType type;
|
||||
|
||||
@XmlTransient
|
||||
Range<DateTime> validDateRange;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
|
@ -109,11 +114,19 @@ public abstract class BaseFee extends ImmutableObject {
|
|||
public FeeType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean hasValidDateRange() {
|
||||
return validDateRange != null;
|
||||
}
|
||||
|
||||
protected void generateDescription(Object... args) {
|
||||
checkState(type != null);
|
||||
description = type.renderDescription(args);
|
||||
}
|
||||
|
||||
public boolean hasZeroCost() {
|
||||
return cost.signum() == 0;
|
||||
}
|
||||
|
||||
public boolean hasDefaultAttributes() {
|
||||
return getGracePeriod().equals(Period.ZERO)
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model.domain.fee;
|
||||
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* An object representing an EAP fee (as a {@link Money}) along with the interval for which the
|
||||
* fee applies.
|
||||
*/
|
||||
public class EapFee {
|
||||
|
||||
/** The EAP fee (as applied on top of the domain registration cost). */
|
||||
Money cost;
|
||||
|
||||
/** The time period for which the fee applies. */
|
||||
Range<DateTime> period;
|
||||
|
||||
public Money getCost() {
|
||||
return cost;
|
||||
}
|
||||
|
||||
public Range<DateTime> getPeriod() {
|
||||
return period;
|
||||
}
|
||||
|
||||
public static EapFee create(Money cost, Range<DateTime> period) {
|
||||
EapFee instance = new EapFee();
|
||||
instance.cost = checkArgumentNotNull(cost, "EAP fee cost cannot be null.");
|
||||
instance.period = checkArgumentNotNull(period, "EAP fee period cannot be null.");
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Range;
|
||||
import google.registry.model.domain.fee06.FeeCheckCommandExtensionV06;
|
||||
import google.registry.model.domain.fee06.FeeCreateCommandExtensionV06;
|
||||
import google.registry.model.domain.fee06.FeeRenewCommandExtensionV06;
|
||||
|
@ -36,6 +37,7 @@ import google.registry.model.domain.fee12.FeeTransferCommandExtensionV12;
|
|||
import google.registry.model.domain.fee12.FeeUpdateCommandExtensionV12;
|
||||
import google.registry.model.eppcommon.ProtocolDefinition.ServiceExtension;
|
||||
import java.math.BigDecimal;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* A fee, in currency units specified elsewhere in the xml, with type of the fee an optional fee
|
||||
|
@ -51,6 +53,13 @@ public class Fee extends BaseFee {
|
|||
return instance;
|
||||
}
|
||||
|
||||
public static Fee create(
|
||||
BigDecimal cost, FeeType type, Range<DateTime> validDateRange, Object... descriptionArgs) {
|
||||
Fee instance = create(cost, type, descriptionArgs);
|
||||
instance.validDateRange = validDateRange;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static final ImmutableList<
|
||||
Class<? extends FeeCheckCommandExtension<
|
||||
? extends FeeCheckCommandExtensionItem, ? extends FeeCheckResponseExtension<?>>>>
|
||||
|
@ -91,10 +100,9 @@ public class Fee extends BaseFee {
|
|||
FeeUpdateCommandExtensionV11.class,
|
||||
FeeUpdateCommandExtensionV06.class);
|
||||
|
||||
public static final ImmutableSet<String>
|
||||
FEE_EXTENSION_URIS =
|
||||
ImmutableSet.<String>of(
|
||||
ServiceExtension.FEE_0_12.getUri(),
|
||||
ServiceExtension.FEE_0_11.getUri(),
|
||||
ServiceExtension.FEE_0_6.getUri());
|
||||
public static final ImmutableSet<String> FEE_EXTENSION_URIS =
|
||||
ImmutableSet.<String>of(
|
||||
ServiceExtension.FEE_0_12.getUri(),
|
||||
ServiceExtension.FEE_0_11.getUri(),
|
||||
ServiceExtension.FEE_0_6.getUri());
|
||||
}
|
||||
|
|
|
@ -56,7 +56,8 @@ import google.registry.model.ImmutableObject;
|
|||
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.domain.fee.BaseFee.FeeType;
|
||||
import google.registry.model.domain.fee.Fee;
|
||||
import google.registry.model.registry.label.PremiumList;
|
||||
import google.registry.model.registry.label.ReservedList;
|
||||
import google.registry.util.Idn;
|
||||
|
@ -518,15 +519,19 @@ public class Registry extends ImmutableObject implements Buildable {
|
|||
/**
|
||||
* Returns the EAP fee for the registry at the given time.
|
||||
*/
|
||||
public EapFee getEapFeeFor(DateTime now) {
|
||||
public Fee getEapFeeFor(DateTime now) {
|
||||
ImmutableSortedMap<DateTime, Money> valueMap = eapFeeSchedule.toValueMap();
|
||||
DateTime periodStart = valueMap.floorKey(now);
|
||||
DateTime periodEnd = valueMap.ceilingKey(now);
|
||||
return EapFee.create(
|
||||
eapFeeSchedule.getValueAtTime(now),
|
||||
Range.closedOpen(
|
||||
periodStart != null ? periodStart : START_OF_TIME,
|
||||
periodEnd != null ? periodEnd : END_OF_TIME));
|
||||
// NOTE: assuming END_OF_TIME would never be reached...
|
||||
Range<DateTime> validPeriod = Range.closedOpen(
|
||||
periodStart != null ? periodStart : START_OF_TIME,
|
||||
periodEnd != null ? periodEnd : END_OF_TIME);
|
||||
return Fee.create(
|
||||
eapFeeSchedule.getValueAtTime(now).getAmount(),
|
||||
FeeType.EAP,
|
||||
validPeriod,
|
||||
validPeriod.upperEndpoint());
|
||||
}
|
||||
|
||||
public String getLordnUsername() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue