mirror of
https://github.com/google/nomulus.git
synced 2025-05-11 01:08:21 +02:00
This CL enhances various domain flows (check, create, delete, renew, restore, transfer, update) so that they invoke the appropriate methods on the object implementing the TLD's RegistryExtraFlowLogic (if any). TldSpecificLogicProxy is also updated to invoke RegistryExtraFlowLogic proxy (if any) to fetch the appropriate price. The tests use a made-up extra flow logic object which can be attached to a test TLD to make sure that the proper routines are being invoked. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=132486734
123 lines
3.3 KiB
Java
123 lines
3.3 KiB
Java
// 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 com.google.common.base.MoreObjects.firstNonNull;
|
|
import static com.google.common.base.Preconditions.checkState;
|
|
|
|
import google.registry.model.ImmutableObject;
|
|
import google.registry.xml.PeriodAdapter;
|
|
import java.math.BigDecimal;
|
|
import javax.xml.bind.annotation.XmlAttribute;
|
|
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.Period;
|
|
|
|
/** Base class for the fee and credit types. */
|
|
@XmlTransient
|
|
public abstract class BaseFee extends ImmutableObject {
|
|
|
|
/** Enum for when a fee is applied. */
|
|
public enum AppliedType {
|
|
@XmlEnumValue("immediate")
|
|
IMMEDIATE,
|
|
|
|
@XmlEnumValue("delayed")
|
|
DELAYED
|
|
}
|
|
|
|
/** Enum for the type of the fee. */
|
|
public enum FeeType {
|
|
CREATE("create"),
|
|
EAP("Early Access Period, fee expires: %s"),
|
|
RENEW("renew"),
|
|
RESTORE("restore"),
|
|
UPDATE("update"),
|
|
CREDIT("%s credit");
|
|
|
|
private final String formatString;
|
|
|
|
FeeType(String formatString) {
|
|
this.formatString = formatString;
|
|
}
|
|
|
|
String renderDescription(Object... args) {
|
|
return String.format(formatString, args);
|
|
}
|
|
}
|
|
|
|
@XmlAttribute
|
|
String description;
|
|
|
|
@XmlAttribute
|
|
AppliedType applied;
|
|
|
|
@XmlAttribute(name = "grace-period")
|
|
@XmlJavaTypeAdapter(PeriodAdapter.class)
|
|
Period gracePeriod;
|
|
|
|
@XmlAttribute
|
|
Boolean refundable;
|
|
|
|
@XmlValue
|
|
BigDecimal cost;
|
|
|
|
@XmlTransient
|
|
FeeType type;
|
|
|
|
public String getDescription() {
|
|
return description;
|
|
}
|
|
|
|
public AppliedType getApplied() {
|
|
return firstNonNull(applied, AppliedType.IMMEDIATE);
|
|
}
|
|
|
|
public Period getGracePeriod() {
|
|
return firstNonNull(gracePeriod, Period.ZERO);
|
|
}
|
|
|
|
public Boolean getRefundable() {
|
|
return firstNonNull(refundable, true);
|
|
}
|
|
|
|
/**
|
|
* According to the fee extension specification, a fee must always be non-negative, while a credit
|
|
* must always be negative. Essentially, they are the same thing, just with different sign.
|
|
* However, we need them to be separate classes for proper JAXB handling.
|
|
*
|
|
* @see "https://tools.ietf.org/html/draft-brown-epp-fees-03#section-2.4"
|
|
*/
|
|
public BigDecimal getCost() {
|
|
return cost;
|
|
}
|
|
|
|
public FeeType getType() {
|
|
return type;
|
|
}
|
|
|
|
protected void generateDescription(Object... args) {
|
|
checkState(type != null);
|
|
description = type.renderDescription(args);
|
|
}
|
|
|
|
public boolean hasDefaultAttributes() {
|
|
return getGracePeriod().equals(Period.ZERO)
|
|
&& getApplied().equals(AppliedType.IMMEDIATE)
|
|
&& getRefundable();
|
|
}
|
|
}
|