Simplify the fee extensions.

I added shared base classes to all of the Fee extension types that
make it possible to fully ignore the version in the flows. (You
ask for a FeeCreateCommandExtension, for example, and you get one
without having to worry about which). This is an improvement over
the old code that asked you to provide a list of possible fee
extensions and then ask for the first one in preference order.

As part of this I was able to make the Fee implementation a bit
simpler as well.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=137992390
This commit is contained in:
cgoldfeder 2016-11-02 14:18:47 -07:00 committed by Ben McIlwain
parent 2dd703ef3a
commit 8256120b3a
66 changed files with 786 additions and 954 deletions

View file

@ -17,7 +17,6 @@ package google.registry.model.eppinput;
import static google.registry.util.CollectionUtils.nullSafeImmutableCopy;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
import com.google.common.base.Optional;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@ -111,34 +110,6 @@ public class EppInput extends ImmutableObject {
return FluentIterable.from(getCommandWrapper().getExtensions()).filter(clazz).first().orNull();
}
/** Get the extension based on type, or null, chosen from a list of possible extension classes.
* If there are extensions matching multiple classes, the first class listed is chosen. If there
* are multiple extensions of the same class, the first extension of that class is chosen
* (assuming that an extension matching a preceding class was not already chosen). This method is
* used to support multiple versions of an extension. Specify all supported versions, starting
* with the latest. The first-occurring extension of the latest version will be chosen, or failing
* that the first-occurring extension of the previous version, and so on.
*/
@Nullable
public <E extends CommandExtension>
E getFirstExtensionOfClasses(ImmutableList<Class<? extends E>> classes) {
for (Class<? extends E> clazz : classes) {
Optional<? extends E> extension = FluentIterable.from(
getCommandWrapper().getExtensions()).filter(clazz).first();
if (extension.isPresent()) {
return extension.get();
}
}
return null;
}
@SafeVarargs
@Nullable
public final <E extends CommandExtension>
E getFirstExtensionOfClasses(Class<? extends E>... classes) {
return getFirstExtensionOfClasses(ImmutableList.copyOf(classes));
}
/** A tag that goes inside of an EPP {@literal <command>}. */
public static class InnerCommand extends ImmutableObject {}