Migrate getCreatePrice() call to DomainPricingLogic

Swap all calls to TldSpecificLogicProxy.getCreatePrice() to the counterpart in
DomainPricingLogic. Also makes necessary changes for testing to work, including
fake implementations of DomainPricingCustomLogic and
DomainCreateLofwCustomLogic.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=140754334
This commit is contained in:
jianglai 2016-12-01 11:20:23 -08:00 committed by Ben McIlwain
parent f8b4c9eddb
commit 79a72387ee
15 changed files with 379 additions and 44 deletions

View file

@ -15,6 +15,7 @@
package google.registry.flows.custom;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.net.InternetDomainName;
import google.registry.flows.EppException;
import google.registry.flows.SessionMetadata;
@ -22,6 +23,8 @@ import google.registry.flows.domain.DomainCreateFlow;
import google.registry.model.ImmutableObject;
import google.registry.model.domain.DomainResource;
import google.registry.model.eppinput.EppInput;
import google.registry.model.eppoutput.EppResponse.ResponseData;
import google.registry.model.eppoutput.EppResponse.ResponseExtension;
import google.registry.model.reporting.HistoryEntry;
/**
@ -60,6 +63,21 @@ public class DomainCreateFlowCustomLogic extends BaseFlowCustomLogic {
return parameters.entityChanges();
}
/**
* A hook that runs before the response is returned.
*
* <p>This takes the {@link ResponseData} and {@link ResponseExtension}s as input and returns
* them, potentially with modifications.
*/
@SuppressWarnings("unused")
public BeforeResponseReturnData beforeResponse(BeforeResponseParameters parameters)
throws EppException {
return BeforeResponseReturnData.newBuilder()
.setResData(parameters.resData())
.setResponseExtensions(parameters.responseExtensions())
.build();
}
/** A class to encapsulate parameters for a call to {@link #afterValidation}. */
@AutoValue
public abstract static class AfterValidationParameters extends ImmutableObject {
@ -143,4 +161,56 @@ public class DomainCreateFlowCustomLogic extends BaseFlowCustomLogic {
public abstract BeforeSaveParameters build();
}
}
/** A class to encapsulate parameters for a call to {@link #beforeResponse}. */
@AutoValue
public abstract static class BeforeResponseParameters extends ImmutableObject {
public abstract ResponseData resData();
public abstract ImmutableList<? extends ResponseExtension> responseExtensions();
public static BeforeResponseParameters.Builder newBuilder() {
return new AutoValue_DomainCreateFlowCustomLogic_BeforeResponseParameters.Builder();
}
/** Builder for {@link DomainCreateFlowCustomLogic.BeforeResponseParameters}. */
@AutoValue.Builder
public abstract static class Builder {
public abstract BeforeResponseParameters.Builder setResData(ResponseData resData);
public abstract BeforeResponseParameters.Builder setResponseExtensions(
ImmutableList<? extends ResponseExtension> responseExtensions);
public abstract BeforeResponseParameters build();
}
}
/**
* A class to encapsulate parameters for the return values from a call to {@link #beforeResponse}.
*/
@AutoValue
public abstract static class BeforeResponseReturnData extends ImmutableObject {
public abstract ResponseData resData();
public abstract ImmutableList<? extends ResponseExtension> responseExtensions();
public static BeforeResponseReturnData.Builder newBuilder() {
return new AutoValue_DomainCreateFlowCustomLogic_BeforeResponseReturnData.Builder();
}
/** Builder for {@link DomainCreateFlowCustomLogic.BeforeResponseReturnData}. */
@AutoValue.Builder
public abstract static class Builder {
public abstract BeforeResponseReturnData.Builder setResData(ResponseData resData);
public abstract BeforeResponseReturnData.Builder setResponseExtensions(
ImmutableList<? extends ResponseExtension> responseExtensions);
public abstract BeforeResponseReturnData build();
}
}
}

View file

@ -52,7 +52,7 @@ import google.registry.flows.FlowModule.ClientId;
import google.registry.flows.FlowModule.Superuser;
import google.registry.flows.FlowModule.TargetId;
import google.registry.flows.TransactionalFlow;
import google.registry.flows.domain.TldSpecificLogicProxy.EppCommandOperations;
import google.registry.flows.domain.DomainPricingLogic.EppCommandOperations;
import google.registry.model.ImmutableObject;
import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.Flag;
@ -113,6 +113,7 @@ public class DomainAllocateFlow implements TransactionalFlow {
@Inject HistoryEntry.Builder historyBuilder;
@Inject EppInput eppInput;
@Inject EppResponse.Builder responseBuilder;
@Inject DomainPricingLogic pricingLogic;
@Inject DomainAllocateFlow() {}
@Override
@ -389,8 +390,8 @@ public class DomainAllocateFlow implements TransactionalFlow {
private ImmutableList<FeeTransformResponseExtension> createResponseExtensions(
DateTime now, Registry registry, int years) throws EppException {
EppCommandOperations commandOperations = TldSpecificLogicProxy.getCreatePrice(
registry, targetId, clientId, now, years, eppInput);
EppCommandOperations commandOperations =
pricingLogic.getCreatePrice(registry, targetId, now, years);
FeeCreateCommandExtension feeCreate =
eppInput.getSingleExtension(FeeCreateCommandExtension.class);
return (feeCreate == null)

View file

@ -64,7 +64,7 @@ import google.registry.flows.custom.DomainApplicationCreateFlowCustomLogic.After
import google.registry.flows.custom.DomainApplicationCreateFlowCustomLogic.BeforeResponseParameters;
import google.registry.flows.custom.DomainApplicationCreateFlowCustomLogic.BeforeResponseReturnData;
import google.registry.flows.custom.EntityChanges;
import google.registry.flows.domain.TldSpecificLogicProxy.EppCommandOperations;
import google.registry.flows.domain.DomainPricingLogic.EppCommandOperations;
import google.registry.model.ImmutableObject;
import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.DomainCommand.Create;
@ -174,6 +174,7 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
@Inject Trid trid;
@Inject EppResponse.Builder responseBuilder;
@Inject DomainApplicationCreateFlowCustomLogic customLogic;
@Inject DomainPricingLogic pricingLogic;
@Inject DomainApplicationCreateFlow() {}
@Override
@ -200,8 +201,8 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
String tld = domainName.parent().toString();
checkAllowedAccessToTld(clientId, tld);
Registry registry = Registry.get(tld);
EppCommandOperations commandOperations = TldSpecificLogicProxy.getCreatePrice(
registry, targetId, clientId, now, command.getPeriod().getValue(), eppInput);
EppCommandOperations commandOperations =
pricingLogic.getCreatePrice(registry, targetId, now, command.getPeriod().getValue());
// Superusers can create reserved domains, force creations on domains that require a claims
// notice without specifying a claims key, and override blocks on registering premium domains.
verifyUnitIsYears(command.getPeriod());

View file

@ -110,6 +110,7 @@ public final class DomainCheckFlow implements Flow {
@Inject Clock clock;
@Inject EppResponse.Builder responseBuilder;
@Inject DomainCheckFlowCustomLogic customLogic;
@Inject DomainPricingLogic pricingLogic;
@Inject DomainCheckFlow() {}
@Override
@ -208,7 +209,8 @@ public final class DomainCheckFlow implements Flow {
clientId,
feeCheck.getCurrency(),
now,
eppInput);
eppInput,
pricingLogic);
responseItems.add(builder.setDomainNameIfSupported(domainName).build());
}
}

View file

@ -43,7 +43,6 @@ import static google.registry.model.registry.label.ReservedList.matchesAnchorTen
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.leapSafeAddYears;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
@ -59,8 +58,10 @@ import google.registry.flows.FlowModule.Superuser;
import google.registry.flows.FlowModule.TargetId;
import google.registry.flows.TransactionalFlow;
import google.registry.flows.custom.DomainCreateFlowCustomLogic;
import google.registry.flows.custom.DomainCreateFlowCustomLogic.BeforeResponseParameters;
import google.registry.flows.custom.DomainCreateFlowCustomLogic.BeforeResponseReturnData;
import google.registry.flows.custom.EntityChanges;
import google.registry.flows.domain.TldSpecificLogicProxy.EppCommandOperations;
import google.registry.flows.domain.DomainPricingLogic.EppCommandOperations;
import google.registry.model.ImmutableObject;
import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.Flag;
@ -166,6 +167,7 @@ public class DomainCreateFlow implements TransactionalFlow {
@Inject HistoryEntry.Builder historyBuilder;
@Inject EppResponse.Builder responseBuilder;
@Inject DomainCreateFlowCustomLogic customLogic;
@Inject DomainPricingLogic pricingLogic;
@Inject DomainCreateFlow() {}
@Override
@ -211,8 +213,8 @@ public class DomainCreateFlow implements TransactionalFlow {
FeeCreateCommandExtension feeCreate =
eppInput.getSingleExtension(FeeCreateCommandExtension.class);
EppCommandOperations commandOperations = TldSpecificLogicProxy.getCreatePrice(
registry, targetId, clientId, now, years, eppInput);
EppCommandOperations commandOperations =
pricingLogic.getCreatePrice(registry, targetId, now, years);
validateFeeChallenge(
targetId, registry.getTldStr(), now, feeCreate, commandOperations.getTotalCost());
// Superusers can create reserved domains, force creations on domains that require a claims
@ -293,18 +295,6 @@ public class DomainCreateFlow implements TransactionalFlow {
}
enqueueTasks(hasSignedMarks, hasClaimsNotice, newDomain);
// TODO: Remove this section and only use the customLogic.
Optional<RegistryExtraFlowLogic> extraFlowLogic =
RegistryExtraFlowLogicProxy.newInstanceForTld(registry.getTldStr());
if (extraFlowLogic.isPresent()) {
extraFlowLogic.get().performAdditionalDomainCreateLogic(
newDomain,
clientId,
years,
eppInput,
historyEntry);
}
EntityChanges entityChanges =
customLogic.beforeSave(
DomainCreateFlowCustomLogic.BeforeSaveParameters.newBuilder()
@ -316,9 +306,15 @@ public class DomainCreateFlow implements TransactionalFlow {
.build());
persistEntityChanges(entityChanges);
BeforeResponseReturnData responseData =
customLogic.beforeResponse(
BeforeResponseParameters.newBuilder()
.setResData(DomainCreateData.create(targetId, now, registrationExpirationTime))
.setResponseExtensions(createResponseExtensions(feeCreate, commandOperations))
.build());
return responseBuilder
.setResData(DomainCreateData.create(targetId, now, registrationExpirationTime))
.setExtensions(createResponseExtensions(feeCreate, commandOperations))
.setResData(responseData.resData())
.setExtensions(responseData.responseExtensions())
.build();
}

View file

@ -56,7 +56,7 @@ import google.registry.flows.EppException.ParameterValueSyntaxErrorException;
import google.registry.flows.EppException.RequiredParameterMissingException;
import google.registry.flows.EppException.StatusProhibitsOperationException;
import google.registry.flows.EppException.UnimplementedOptionException;
import google.registry.flows.domain.TldSpecificLogicProxy.EppCommandOperations;
import google.registry.flows.domain.DomainPricingLogic.EppCommandOperations;
import google.registry.flows.exceptions.ResourceAlreadyExistsException;
import google.registry.flows.exceptions.ResourceHasClientUpdateProhibitedException;
import google.registry.model.EppResource;
@ -589,7 +589,9 @@ public class DomainFlowUtils {
String clientId,
@Nullable CurrencyUnit topLevelCurrency,
DateTime currentDate,
EppInput eppInput) throws EppException {
EppInput eppInput,
DomainPricingLogic pricingLogic)
throws EppException {
DateTime now = currentDate;
// Use the custom effective date specified in the fee check request, if there is one.
if (feeRequest.getEffectiveDate().isPresent()) {
@ -620,14 +622,13 @@ public class DomainFlowUtils {
ImmutableList<Fee> fees = ImmutableList.of();
switch (feeRequest.getCommandName()) {
case CREATE:
if (isReserved(domain, isSunrise)) { // Don't return a create price for reserved names.
builder.setClass("reserved"); // Override whatever class we've set above.
if (isReserved(domain, isSunrise)) { // Don't return a create price for reserved names.
builder.setClass("reserved"); // Override whatever class we've set above.
builder.setAvailIfSupported(false);
builder.setReasonIfSupported("reserved");
} else {
builder.setAvailIfSupported(true);
fees = TldSpecificLogicProxy.getCreatePrice(
registry, domainNameString, clientId, now, years, eppInput).getFees();
fees = pricingLogic.getCreatePrice(registry, domainNameString, now, years).getFees();
}
break;
case RENEW:

View file

@ -77,6 +77,7 @@ public final class DomainInfoFlow implements Flow {
@Inject Clock clock;
@Inject EppResponse.Builder responseBuilder;
@Inject DomainInfoFlowCustomLogic customLogic;
@Inject DomainPricingLogic pricingLogic;
@Inject
DomainInfoFlow() {}
@ -145,7 +146,14 @@ public final class DomainInfoFlow implements Flow {
if (feeInfo != null) { // Fee check was requested.
FeeInfoResponseExtensionV06.Builder builder = new FeeInfoResponseExtensionV06.Builder();
handleFeeRequest(
feeInfo, builder, InternetDomainName.from(targetId), clientId, null, now, eppInput);
feeInfo,
builder,
InternetDomainName.from(targetId),
clientId,
null,
now,
eppInput,
pricingLogic);
extensions.add(builder.build());
}
// If the TLD uses the flags extension, add it to the info response.

View file

@ -63,6 +63,18 @@ public abstract class CreateData implements ResponseData {
instance.expirationDate = expirationDate;
return instance;
}
public String name() {
return name;
}
public DateTime creationDate() {
return creationDate;
}
public DateTime expirationDate() {
return expirationDate;
}
}
/** An acknowledgment message indicating that a host was created. */