Make EAP fee description check more flexible

Currently we determine fee type from the fee extension description by checking if the format string of the FeeType contains the description we received. The formatting string for EAP is "Early Access Period, fee expires: %s", so the fee description generated by a domain check command, like "Early Access Period, fee expires: 2022-03-01T00:00:00.000Z", is not recognized as EAP.

This CL adds the ability to add arbitrary extra description strings to the FeeType for a description to match against. It also changes the match to "the given description contains any of the strings from the list of format string plus extra description strings".

For EAP, we added an extra description string "Early Access Period", so any fee description that contains "Early Access Period" will be matched to EAP FeeType, including the specific description (that contains the expiry time) that we send in a domain check.

Also improved error message on multiple fee type matching.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=194149162
This commit is contained in:
jianglai 2018-04-24 14:46:52 -07:00
parent 4d3065c7ab
commit 82ded21b9e
3 changed files with 50 additions and 9 deletions

View file

@ -49,7 +49,7 @@ public abstract class BaseFee extends ImmutableObject {
/** Enum for the type of the fee. */
public enum FeeType {
CREATE("create"),
EAP("Early Access Period, fee expires: %s"),
EAP("Early Access Period, fee expires: %s", "Early Access Period"),
RENEW("renew"),
RESTORE("restore"),
/**
@ -65,8 +65,11 @@ public abstract class BaseFee extends ImmutableObject {
private final String formatString;
FeeType(String formatString) {
private final ImmutableList<String> extraAcceptableDescriptions;
FeeType(String formatString, String... extraAcceptableDescriptions) {
this.formatString = formatString;
this.extraAcceptableDescriptions = ImmutableList.copyOf(extraAcceptableDescriptions);
}
String renderDescription(Object... args) {
@ -74,7 +77,14 @@ public abstract class BaseFee extends ImmutableObject {
}
boolean matchFormatString(String description) {
return Ascii.toLowerCase(formatString).contains(Ascii.toLowerCase(description));
return new ImmutableList.Builder<String>()
.add(formatString)
.addAll(extraAcceptableDescriptions)
.build()
.stream()
.anyMatch(
expectedDescription ->
Ascii.toLowerCase(description).contains(Ascii.toLowerCase(expectedDescription)));
}
}