Add extra flow logic hooks for info and update

This CL adds the hooks necessary to implement TLD-specific flow info and update flow logic. Usage of the hooks follows in a separate CL.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=130108832
This commit is contained in:
mountford 2016-08-12 09:41:48 -07:00 committed by Ben McIlwain
parent e55ed209c5
commit 0066a03709
18 changed files with 397 additions and 16 deletions

View file

@ -27,8 +27,8 @@ import static google.registry.flows.domain.DomainFlowUtils.validateRegistrantAll
import static google.registry.flows.domain.DomainFlowUtils.validateRequiredContactsPresent;
import static google.registry.flows.domain.DomainFlowUtils.verifyNotInPendingDelete;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
import google.registry.flows.EppException;
import google.registry.flows.EppException.ParameterValuePolicyErrorException;
import google.registry.flows.EppException.RequiredParameterMissingException;
@ -41,7 +41,6 @@ import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.domain.secdns.SecDnsUpdateExtension;
import google.registry.model.domain.secdns.SecDnsUpdateExtension.Add;
import google.registry.model.domain.secdns.SecDnsUpdateExtension.Remove;
import java.util.Set;
/**
@ -53,10 +52,18 @@ import java.util.Set;
public abstract class BaseDomainUpdateFlow<R extends DomainBase, B extends Builder<R, B>>
extends ResourceUpdateFlow<R, B, Update> {
protected Optional<RegistryExtraFlowLogic> extraFlowLogic;
@Override
public final void initResourceCreateOrMutateFlow() throws EppException {
command = cloneAndLinkReferences(command, now);
initDomainUpdateFlow();
// In certain conditions (for instance, errors), there is no existing resource.
if (existingResource == null) {
extraFlowLogic = Optional.absent();
} else {
extraFlowLogic = RegistryExtraFlowLogicProxy.newInstanceForTld(existingResource.getTld());
}
}
@SuppressWarnings("unused")
@ -98,8 +105,13 @@ public abstract class BaseDomainUpdateFlow<R extends DomainBase, B extends Build
return setDomainUpdateProperties(builder);
}
/** Subclasses can override this to do set more specific properties. */
protected B setDomainUpdateProperties(B builder) {
/**
* Subclasses can override this to do set more specific properties.
*
* @throws EppException if the overriding method encounters an error that should be returned to
* the user as an EPP response
*/
protected B setDomainUpdateProperties(B builder) throws EppException {
return builder;
}

View file

@ -324,7 +324,7 @@ public class DomainFlowUtils {
throws RegistrantNotAllowedException {
ImmutableSet<String> whitelist = Registry.get(tld).getAllowedRegistrantContactIds();
// Empty whitelist or null registrantContactId are ignored.
if (registrantContactId != null && !whitelist.isEmpty()
if (registrantContactId != null && !whitelist.isEmpty()
&& !whitelist.contains(registrantContactId)) {
throw new RegistrantNotAllowedException(registrantContactId);
}
@ -576,7 +576,7 @@ public class DomainFlowUtils {
if (feeRequest.getPhase() != null || feeRequest.getSubphase() != null) {
throw new FeeChecksDontSupportPhasesException();
}
CurrencyUnit currency =
feeRequest.isCurrencySupported() ? feeRequest.getCurrency() : topLevelCurrency;
if ((currency != null) && !currency.equals(registry.getCurrency())) {
@ -620,7 +620,7 @@ public class DomainFlowUtils {
}
}
static void validateFeeChallenge(
public static void validateFeeChallenge(
String domainName,
String tld,
DateTime priceTime,
@ -664,7 +664,7 @@ public class DomainFlowUtils {
throw new CurrencyUnitMismatchException();
}
if (!feeTotal.equals(costTotal)) {
throw new FeesMismatchException();
throw new FeesMismatchException(costTotal);
}
}
@ -988,10 +988,16 @@ public class DomainFlowUtils {
}
/** The fees passed in the transform command do not match the fees that will be charged. */
static class FeesMismatchException extends ParameterValueRangeErrorException {
public static class FeesMismatchException extends ParameterValueRangeErrorException {
public FeesMismatchException() {
super("The fees passed in the transform command do not match the fees that will be charged");
}
public FeesMismatchException(Money correctFee) {
super(String.format(
"The fees passed in the transform command do not match the expected total of %s",
correctFee));
}
}
/** Registrar is not authorized to access this TLD. */

View file

@ -16,6 +16,7 @@ package google.registry.flows.domain;
import static google.registry.flows.domain.DomainFlowUtils.handleFeeRequest;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import google.registry.flows.EppException;
@ -23,9 +24,11 @@ import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainResource.Builder;
import google.registry.model.domain.fee06.FeeInfoCommandExtensionV06;
import google.registry.model.domain.fee06.FeeInfoResponseExtensionV06;
import google.registry.model.domain.flags.FlagsInfoResponseExtension;
import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.rgp.RgpInfoExtension;
import google.registry.model.eppoutput.EppResponse.ResponseExtension;
import java.util.List;
import javax.inject.Inject;
/**
@ -100,6 +103,17 @@ public class DomainInfoFlow extends BaseDomainInfoFlow<DomainResource, Builder>
now);
extensions.add(builder.build());
}
// If the TLD uses the flags extension, add it to the info response.
Optional<RegistryExtraFlowLogic> extraLogicManager =
RegistryExtraFlowLogicProxy.newInstanceForTld(existingResource.getTld());
if (extraLogicManager.isPresent()) {
List<String> flags = extraLogicManager.get().getFlags(
existingResource, this.getClientId(), now); // As-of date is always now for info commands.
if (!flags.isEmpty()) {
extensions.add(FlagsInfoResponseExtension.create(flags));
}
}
return extensions.build();
}
}

View file

@ -22,11 +22,13 @@ import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import google.registry.dns.DnsQueue;
import google.registry.flows.EppException;
import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.DomainResource.Builder;
import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.flags.FlagsUpdateCommandExtension;
import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.secdns.SecDnsUpdateExtension;
import google.registry.model.eppcommon.StatusValue;
@ -70,11 +72,11 @@ public class DomainUpdateFlow extends BaseDomainUpdateFlow<DomainResource, Build
@Override
protected void initDomainUpdateFlow() {
registerExtensions(SecDnsUpdateExtension.class);
registerExtensions(SecDnsUpdateExtension.class, FlagsUpdateCommandExtension.class);
}
@Override
protected Builder setDomainUpdateProperties(Builder builder) {
protected Builder setDomainUpdateProperties(Builder builder) throws EppException {
// Check if the domain is currently in the sunrush add grace period.
Optional<GracePeriod> sunrushAddGracePeriod = Iterables.tryFind(
existingResource.getGracePeriods(),
@ -127,6 +129,11 @@ public class DomainUpdateFlow extends BaseDomainUpdateFlow<DomainResource, Build
ofy().save().entities(billingEvent, billingEventCancellation);
}
// Handle extra flow logic, if any.
if (extraFlowLogic.isPresent()) {
extraFlowLogic.get().performAdditionalDomainUpdateLogic(
existingResource, getClientId(), now, eppInput);
}
return builder;
}
@ -154,6 +161,10 @@ public class DomainUpdateFlow extends BaseDomainUpdateFlow<DomainResource, Build
ofy().save().entity(billingEvent);
}
}
if (extraFlowLogic.isPresent()) {
extraFlowLogic.get().commitAdditionalDomainUpdates();
}
}
@Override

View file

@ -0,0 +1,45 @@
// 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.flows.domain;
import google.registry.flows.EppException;
import google.registry.model.domain.DomainResource;
import google.registry.model.eppinput.EppInput;
import java.util.List;
import org.joda.time.DateTime;
/**
* Interface for classes which provide extra registry logic for things like TLD-specific rules and
* discounts.
*/
public interface RegistryExtraFlowLogic {
/** Get the flags to be passed to the client in the EPP flags extension. */
public List<String> getFlags(
DomainResource domainResource, String clientIdentifier, DateTime asOfDate);
/**
* Add and remove flags passed via the EPP flags extension. Any changes should not be persisted to
* Datastore until commitAdditionalDomainUpdates is called. Name suggested by Benjamin McIlwain.
*/
public void performAdditionalDomainUpdateLogic(
DomainResource domainResource,
String clientIdentifier,
DateTime asOfDate,
EppInput eppInput) throws EppException;
/** Commit any changes made as a result of a call to performAdditionalDomainUpdateLogic(). */
public void commitAdditionalDomainUpdates();
}

View file

@ -0,0 +1,49 @@
// 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.flows.domain;
import com.google.common.base.Optional;
import google.registry.model.registry.Registry;
import java.util.HashMap;
/**
* Static class to return the correct {@link RegistryExtraFlowLogic} for a particular TLD.
* Eventually, this will probably be replaced with dependency injection, barring unforeseen
* complications.
*/
public class RegistryExtraFlowLogicProxy {
private static final HashMap<String, Class<? extends RegistryExtraFlowLogic>>
extraLogicOverrideMap = new HashMap<>();
public static void setOverride(
String tld, Class<? extends RegistryExtraFlowLogic> extraLogicClass) {
if (Registry.get(tld) == null) {
throw new IllegalArgumentException(tld + " does not exist");
}
extraLogicOverrideMap.put(tld, extraLogicClass);
}
public static Optional<RegistryExtraFlowLogic> newInstanceForTld(String tld) {
if (extraLogicOverrideMap.containsKey(tld)) {
try {
return Optional.<RegistryExtraFlowLogic>of(extraLogicOverrideMap.get(tld).newInstance());
} catch (InstantiationException | IllegalAccessException e) {
return Optional.absent();
}
}
return Optional.absent();
}
}

View file

@ -30,4 +30,10 @@ import javax.xml.bind.annotation.XmlRootElement;
public class FlagsInfoResponseExtension implements ResponseExtension {
@XmlElement(name = "flag")
List<String> flags;
public static FlagsInfoResponseExtension create(List<String> flags) {
FlagsInfoResponseExtension extension = new FlagsInfoResponseExtension();
extension.flags = flags;
return extension;
}
}

View file

@ -24,4 +24,8 @@ import javax.xml.bind.annotation.XmlElement;
public class FlagsList {
@XmlElement(name = "flag")
List<String> flags;
public List<String> getFlags() {
return flags;
}
}

View file

@ -30,4 +30,12 @@ import javax.xml.bind.annotation.XmlType;
public class FlagsUpdateCommandExtension implements CommandExtension {
FlagsList add; // list of flags to be added (turned on)
FlagsList rem; // list of flags to be removed (turned off)
public FlagsList getAddFlags() {
return add;
}
public FlagsList getRemoveFlags() {
return rem;
}
}