mirror of
https://github.com/google/nomulus.git
synced 2025-05-12 22:38:16 +02:00
Flatten the domain transfer flows
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=133906420
This commit is contained in:
parent
2d46c7c27c
commit
1b34f1e326
19 changed files with 848 additions and 351 deletions
|
@ -14,13 +14,23 @@
|
|||
|
||||
package google.registry.flows.domain;
|
||||
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static com.google.common.collect.Sets.union;
|
||||
import static google.registry.flows.ResourceFlowUtils.loadResourceToMutate;
|
||||
import static google.registry.flows.ResourceFlowUtils.verifyNoDisallowedStatuses;
|
||||
import static google.registry.flows.ResourceFlowUtils.verifyRequiredAuthInfoForResourceTransfer;
|
||||
import static google.registry.flows.domain.DomainFlowUtils.checkAllowedAccessToTld;
|
||||
import static google.registry.flows.domain.DomainFlowUtils.createGainingTransferPollMessage;
|
||||
import static google.registry.flows.domain.DomainFlowUtils.createLosingTransferPollMessage;
|
||||
import static google.registry.flows.domain.DomainFlowUtils.createTransferResponse;
|
||||
import static google.registry.flows.domain.DomainFlowUtils.updateAutorenewRecurrenceEndTime;
|
||||
import static google.registry.flows.domain.DomainFlowUtils.validateFeeChallenge;
|
||||
import static google.registry.flows.domain.DomainFlowUtils.verifyPremiumNameIsNotBlocked;
|
||||
import static google.registry.flows.domain.DomainFlowUtils.verifyUnitIsYears;
|
||||
import static google.registry.model.domain.DomainResource.extendRegistrationWithCap;
|
||||
import static google.registry.model.domain.fee.Fee.FEE_TRANSFER_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER;
|
||||
import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_ACTION_PENDING;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
|
@ -30,7 +40,13 @@ import com.google.common.collect.ImmutableList;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.flows.EppException;
|
||||
import google.registry.flows.ResourceTransferRequestFlow;
|
||||
import google.registry.flows.FlowModule.ClientId;
|
||||
import google.registry.flows.FlowModule.TargetId;
|
||||
import google.registry.flows.LoggedInFlow;
|
||||
import google.registry.flows.TransactionalFlow;
|
||||
import google.registry.flows.exceptions.AlreadyPendingTransferException;
|
||||
import google.registry.flows.exceptions.ObjectAlreadySponsoredException;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.billing.BillingEvent;
|
||||
import google.registry.model.billing.BillingEvent.Flag;
|
||||
import google.registry.model.billing.BillingEvent.Reason;
|
||||
|
@ -40,230 +56,371 @@ import google.registry.model.domain.Period;
|
|||
import google.registry.model.domain.fee.BaseFee.FeeType;
|
||||
import google.registry.model.domain.fee.Fee;
|
||||
import google.registry.model.domain.fee.FeeTransformCommandExtension;
|
||||
import google.registry.model.domain.fee.FeeTransformResponseExtension;
|
||||
import google.registry.model.domain.flags.FlagsTransferCommandExtension;
|
||||
import google.registry.model.eppoutput.EppResponse.ResponseExtension;
|
||||
import google.registry.model.domain.metadata.MetadataExtension;
|
||||
import google.registry.model.eppcommon.AuthInfo;
|
||||
import google.registry.model.eppcommon.StatusValue;
|
||||
import google.registry.model.eppinput.ResourceCommand;
|
||||
import google.registry.model.eppoutput.EppOutput;
|
||||
import google.registry.model.poll.PollMessage;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.model.transfer.TransferData;
|
||||
import google.registry.model.transfer.TransferData.Builder;
|
||||
import google.registry.model.transfer.TransferData.TransferServerApproveEntity;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import google.registry.model.transfer.TransferResponse.DomainTransferResponse;
|
||||
import google.registry.model.transfer.TransferStatus;
|
||||
import javax.inject.Inject;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
|
||||
/**
|
||||
* An EPP flow that requests a transfer on a {@link DomainResource}.
|
||||
*
|
||||
* @error {@link google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException}
|
||||
* <p>The "gaining" registrar requests a transfer from the "losing" (aka current) registrar. The
|
||||
* losing registrar has a "transfer" time period to respond (by default five days) after which the
|
||||
* transfer is automatically approved. Within that window, the transfer might be approved explicitly
|
||||
* by the losing registrar or rejected, and the gaining registrar can also cancel the transfer
|
||||
* request.
|
||||
*
|
||||
* <p>When a transfer is requested, poll messages and billing events are saved to Datastore with
|
||||
* timestamps such that they only become active when the server-approval period passes. Keys to
|
||||
* these speculative objects are saved in the domain's transfer data, and on explicit approval,
|
||||
* rejection or cancellation of the request, they will be deleted (and in the approval case,
|
||||
* replaced with new ones with the correct approval time).
|
||||
*
|
||||
* @error {@link google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException}
|
||||
* @error {@link google.registry.flows.ResourceMutateFlow.ResourceToMutateDoesNotExistException}
|
||||
* @error {@link google.registry.flows.ResourceTransferRequestFlow.AlreadyPendingTransferException}
|
||||
* @error {@link google.registry.flows.ResourceTransferRequestFlow.MissingTransferRequestAuthInfoException}
|
||||
* @error {@link google.registry.flows.ResourceTransferRequestFlow.ObjectAlreadySponsoredException}
|
||||
* @error {@link google.registry.flows.SingleResourceFlow.ResourceStatusProhibitsOperationException}
|
||||
* @error {@link google.registry.flows.exceptions.AlreadyPendingTransferException}
|
||||
* @error {@link google.registry.flows.exceptions.MissingTransferRequestAuthInfoException}
|
||||
* @error {@link google.registry.flows.exceptions.ObjectAlreadySponsoredException}
|
||||
* @error {@link google.registry.flows.exceptions.ResourceStatusProhibitsOperationException}
|
||||
* @error {@link google.registry.flows.exceptions.ResourceToMutateDoesNotExistException}
|
||||
* @error {@link DomainFlowUtils.BadPeriodUnitException}
|
||||
* @error {@link DomainFlowUtils.CurrencyUnitMismatchException}
|
||||
* @error {@link DomainFlowUtils.CurrencyValueScaleException}
|
||||
* @error {@link DomainFlowUtils.FeesMismatchException}
|
||||
* @error {@link DomainFlowUtils.FeesRequiredForPremiumNameException}
|
||||
* @error {@link DomainFlowUtils.NotAuthorizedForTldException}
|
||||
* @error {@link DomainFlowUtils.PremiumNameBlockedException}
|
||||
* @error {@link DomainFlowUtils.UnsupportedFeeAttributeException}
|
||||
*/
|
||||
public class DomainTransferRequestFlow
|
||||
extends ResourceTransferRequestFlow<DomainResource, Transfer> {
|
||||
public final class DomainTransferRequestFlow extends LoggedInFlow implements TransactionalFlow {
|
||||
|
||||
/** The time when the transfer will be server approved if no other action happens first. */
|
||||
private DateTime automaticTransferTime;
|
||||
|
||||
/** A new one-time billing event for the renewal packaged as part of this transfer. */
|
||||
private BillingEvent.OneTime transferBillingEvent;
|
||||
|
||||
/** A new autorenew billing event starting at the transfer time. */
|
||||
private BillingEvent.Recurring gainingClientAutorenewEvent;
|
||||
|
||||
/** A new autorenew poll message starting at the transfer time. */
|
||||
private PollMessage.Autorenew gainingClientAutorenewPollMessage;
|
||||
|
||||
/** The amount that this transfer will cost due to the implied renew. */
|
||||
private Money renewCost;
|
||||
|
||||
/** Extra flow logic instance. */
|
||||
protected Optional<RegistryExtraFlowLogic> extraFlowLogic;
|
||||
|
||||
/**
|
||||
* An optional extension from the client specifying how much they think the transfer should cost.
|
||||
*/
|
||||
private FeeTransformCommandExtension feeTransfer;
|
||||
private static final ImmutableSet<StatusValue> DISALLOWED_STATUSES = ImmutableSet.of(
|
||||
StatusValue.CLIENT_TRANSFER_PROHIBITED,
|
||||
StatusValue.PENDING_DELETE,
|
||||
StatusValue.SERVER_TRANSFER_PROHIBITED);
|
||||
|
||||
@Inject ResourceCommand resourceCommand;
|
||||
@Inject Optional<AuthInfo> authInfo;
|
||||
@Inject @ClientId String gainingClientId;
|
||||
@Inject @TargetId String targetId;
|
||||
@Inject HistoryEntry.Builder historyBuilder;
|
||||
@Inject DomainTransferRequestFlow() {}
|
||||
|
||||
@Override
|
||||
protected Duration getAutomaticTransferLength() {
|
||||
return Registry.get(existingResource.getTld()).getAutomaticTransferLength();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void initResourceTransferRequestFlow() throws EppException {
|
||||
registerExtensions(FlagsTransferCommandExtension.class);
|
||||
protected final void initLoggedInFlow() throws EppException {
|
||||
registerExtensions(MetadataExtension.class, FlagsTransferCommandExtension.class);
|
||||
registerExtensions(FEE_TRANSFER_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER);
|
||||
feeTransfer = eppInput.getFirstExtensionOfClasses(
|
||||
}
|
||||
|
||||
@Override
|
||||
public final EppOutput run() throws EppException {
|
||||
Period period = ((Transfer) resourceCommand).getPeriod();
|
||||
int years = period.getValue();
|
||||
DomainResource existingDomain = loadResourceToMutate(DomainResource.class, targetId, now);
|
||||
verifyTransferAllowed(existingDomain, period);
|
||||
String tld = existingDomain.getTld();
|
||||
Registry registry = Registry.get(tld);
|
||||
// The cost of the renewal implied by a transfer.
|
||||
Money renewCost = getDomainRenewCost(targetId, now, years);
|
||||
// An optional extension from the client specifying what they think the transfer should cost.
|
||||
FeeTransformCommandExtension feeTransfer = eppInput.getFirstExtensionOfClasses(
|
||||
FEE_TRANSFER_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER);
|
||||
// The "existingResource" field is loaded before this function is called, but it may be null if
|
||||
// the domain name specified is invalid or doesn't exist. If that's the case, simply exit
|
||||
// early, and ResourceMutateFlow will later throw ResourceToMutateDoesNotExistException.
|
||||
if (existingResource == null) {
|
||||
return;
|
||||
}
|
||||
Registry registry = Registry.get(existingResource.getTld());
|
||||
automaticTransferTime = now.plus(registry.getAutomaticTransferLength());
|
||||
// Note that the gaining registrar is used to calculate the cost of the renewal.
|
||||
renewCost = getDomainRenewCost(targetId, now, command.getPeriod().getValue());
|
||||
transferBillingEvent = new BillingEvent.OneTime.Builder()
|
||||
.setReason(Reason.TRANSFER)
|
||||
.setTargetId(targetId)
|
||||
.setClientId(getClientId())
|
||||
.setCost(renewCost)
|
||||
.setPeriodYears(command.getPeriod().getValue())
|
||||
.setEventTime(automaticTransferTime)
|
||||
.setBillingTime(automaticTransferTime.plus(registry.getTransferGracePeriodLength()))
|
||||
.setParent(historyEntry)
|
||||
.build();
|
||||
DateTime newExpirationTime = extendRegistrationWithCap(
|
||||
validateFeeChallenge(targetId, tld, now, feeTransfer, renewCost);
|
||||
ImmutableSet.Builder<ImmutableObject> entitiesToSave = new ImmutableSet.Builder<>();
|
||||
HistoryEntry historyEntry = buildHistory(period, existingDomain);
|
||||
entitiesToSave.add(historyEntry);
|
||||
DateTime automaticTransferTime = now.plus(registry.getAutomaticTransferLength());
|
||||
// The new expiration time if there is a server approval.
|
||||
DateTime serverApproveNewExpirationTime = extendRegistrationWithCap(
|
||||
automaticTransferTime, existingDomain.getRegistrationExpirationTime(), years);
|
||||
ImmutableSet<BillingEvent> billingEvents = createBillingEvents(
|
||||
renewCost,
|
||||
registry,
|
||||
existingDomain,
|
||||
historyEntry,
|
||||
automaticTransferTime,
|
||||
existingResource.getRegistrationExpirationTime(),
|
||||
command.getPeriod().getValue());
|
||||
gainingClientAutorenewEvent = new BillingEvent.Recurring.Builder()
|
||||
.setReason(Reason.RENEW)
|
||||
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
|
||||
.setTargetId(targetId)
|
||||
.setClientId(gainingClient.getId())
|
||||
.setEventTime(newExpirationTime)
|
||||
.setRecurrenceEndTime(END_OF_TIME)
|
||||
.setParent(historyEntry)
|
||||
serverApproveNewExpirationTime,
|
||||
years);
|
||||
entitiesToSave.addAll(billingEvents);
|
||||
ImmutableSet<PollMessage> pollMessages = createPollMessages(
|
||||
existingDomain,
|
||||
historyEntry,
|
||||
automaticTransferTime,
|
||||
serverApproveNewExpirationTime,
|
||||
years);
|
||||
entitiesToSave.addAll(pollMessages);
|
||||
ImmutableSet.Builder<Key<? extends TransferServerApproveEntity>> serverApproveEntities =
|
||||
new ImmutableSet.Builder<>();
|
||||
for (TransferServerApproveEntity entity : union(billingEvents, pollMessages)) {
|
||||
serverApproveEntities.add(Key.create(entity));
|
||||
}
|
||||
// Create the transfer data that represents the pending transfer.
|
||||
TransferData pendingTransferData = createTransferDataBuilder()
|
||||
.setTransferStatus(TransferStatus.PENDING)
|
||||
.setLosingClientId(existingDomain.getCurrentSponsorClientId())
|
||||
.setPendingTransferExpirationTime(automaticTransferTime)
|
||||
.setExtendedRegistrationYears(years)
|
||||
.setServerApproveBillingEvent(Key.create(
|
||||
getOnlyElement(filter(billingEvents, BillingEvent.OneTime.class))))
|
||||
.setServerApproveAutorenewEvent(Key.create(
|
||||
getOnlyElement(filter(billingEvents, BillingEvent.Recurring.class))))
|
||||
.setServerApproveAutorenewPollMessage(Key.create(
|
||||
getOnlyElement(filter(pollMessages, PollMessage.Autorenew.class))))
|
||||
.setServerApproveEntities(serverApproveEntities.build())
|
||||
.build();
|
||||
gainingClientAutorenewPollMessage = new PollMessage.Autorenew.Builder()
|
||||
.setTargetId(targetId)
|
||||
.setClientId(gainingClient.getId())
|
||||
.setEventTime(newExpirationTime)
|
||||
.setAutorenewEndTime(END_OF_TIME)
|
||||
.setMsg("Domain was auto-renewed.")
|
||||
.setParent(historyEntry)
|
||||
// When a transfer is requested, a poll message is created to notify the losing registrar.
|
||||
PollMessage requestPollMessage = createLosingTransferPollMessage(
|
||||
targetId, pendingTransferData, serverApproveNewExpirationTime, historyEntry)
|
||||
.asBuilder().setEventTime(now).build();
|
||||
entitiesToSave.add(requestPollMessage);
|
||||
// End the old autorenew event and poll message at the implicit transfer time. This may delete
|
||||
// the poll message if it has no events left. Note that this is still left on the domain as the
|
||||
// autorenewBillingEvent because it is still the current autorenew event until the transfer
|
||||
// happens. If you read the domain after the transfer occurs, then cloneProjectedAtTime() will
|
||||
// move the serverApproveAutoRenewEvent into the autoRenewEvent field.
|
||||
updateAutorenewRecurrenceEndTime(existingDomain, automaticTransferTime);
|
||||
handleExtraFlowLogic(years, existingDomain, historyEntry);
|
||||
DomainResource newDomain = existingDomain.asBuilder()
|
||||
.setTransferData(pendingTransferData)
|
||||
.addStatusValue(StatusValue.PENDING_TRANSFER)
|
||||
.build();
|
||||
extraFlowLogic = RegistryExtraFlowLogicProxy.newInstanceForDomain(existingResource);
|
||||
ofy().save().entities(entitiesToSave.add(newDomain).build());
|
||||
return createOutput(
|
||||
SUCCESS_WITH_ACTION_PENDING,
|
||||
createResponse(period, existingDomain, newDomain),
|
||||
createResponseExtensions(renewCost, feeTransfer));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void verifyTransferRequestIsAllowed() throws EppException {
|
||||
verifyUnitIsYears(command.getPeriod());
|
||||
private void verifyTransferAllowed(DomainResource existingDomain, Period period)
|
||||
throws EppException {
|
||||
verifyNoDisallowedStatuses(existingDomain, DISALLOWED_STATUSES);
|
||||
verifyRequiredAuthInfoForResourceTransfer(authInfo, existingDomain);
|
||||
// Verify that the resource does not already have a pending transfer.
|
||||
if (TransferStatus.PENDING.equals(existingDomain.getTransferData().getTransferStatus())) {
|
||||
throw new AlreadyPendingTransferException(targetId);
|
||||
}
|
||||
// Verify that this client doesn't already sponsor this resource.
|
||||
if (gainingClientId.equals(existingDomain.getCurrentSponsorClientId())) {
|
||||
throw new ObjectAlreadySponsoredException();
|
||||
}
|
||||
checkAllowedAccessToTld(getAllowedTlds(), existingDomain.getTld());
|
||||
verifyUnitIsYears(period);
|
||||
if (!isSuperuser) {
|
||||
verifyPremiumNameIsNotBlocked(targetId, now, getClientId());
|
||||
}
|
||||
validateFeeChallenge(
|
||||
targetId, existingResource.getTld(), now, feeTransfer, renewCost);
|
||||
checkAllowedAccessToTld(getAllowedTlds(), existingResource.getTld());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImmutableList<? extends ResponseExtension> getTransferResponseExtensions() {
|
||||
if (feeTransfer != null) {
|
||||
return ImmutableList.of(
|
||||
feeTransfer
|
||||
.createResponseBuilder()
|
||||
.setCurrency(renewCost.getCurrencyUnit())
|
||||
.setFees(ImmutableList.of(Fee.create(renewCost.getAmount(), FeeType.RENEW)))
|
||||
.build());
|
||||
} else {
|
||||
return null;
|
||||
verifyPremiumNameIsNotBlocked(targetId, now, gainingClientId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setTransferDataProperties(TransferData.Builder builder) throws EppException {
|
||||
builder
|
||||
.setServerApproveBillingEvent(Key.create(transferBillingEvent))
|
||||
.setServerApproveAutorenewEvent(Key.create(gainingClientAutorenewEvent))
|
||||
.setServerApproveAutorenewPollMessage(Key.create(gainingClientAutorenewPollMessage))
|
||||
.setExtendedRegistrationYears(command.getPeriod().getValue());
|
||||
|
||||
// Handle extra flow logic, if any.
|
||||
if (extraFlowLogic.isPresent()) {
|
||||
extraFlowLogic.get().performAdditionalDomainTransferLogic(
|
||||
existingResource,
|
||||
getClientId(),
|
||||
now,
|
||||
command.getPeriod().getValue(),
|
||||
eppInput,
|
||||
historyEntry);
|
||||
}
|
||||
private HistoryEntry buildHistory(Period period, DomainResource existingResource) {
|
||||
return historyBuilder
|
||||
.setType(HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST)
|
||||
.setPeriod(period)
|
||||
.setModificationTime(now)
|
||||
.setParent(Key.create(existingResource))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* When a transfer is requested, schedule a billing event and poll message for the automatic
|
||||
* approval case.
|
||||
*
|
||||
* <p>Note that the action time is AUTOMATIC_TRANSFER_DAYS in the future, matching the server
|
||||
* policy on automated approval of transfers. There is no equivalent grace period added; if the
|
||||
* transfer is implicitly approved, the resource will project a grace period on itself.
|
||||
*/
|
||||
@Override
|
||||
protected Set<Key<? extends TransferServerApproveEntity>> getTransferServerApproveEntities() {
|
||||
ofy().save().<Object>entities(
|
||||
transferBillingEvent, gainingClientAutorenewEvent, gainingClientAutorenewPollMessage);
|
||||
private ImmutableSet<BillingEvent> createBillingEvents(
|
||||
Money renewCost,
|
||||
Registry registry,
|
||||
DomainResource existingDomain,
|
||||
HistoryEntry historyEntry,
|
||||
DateTime automaticTransferTime,
|
||||
DateTime serverApproveNewExpirationTime,
|
||||
int years) {
|
||||
ImmutableSet.Builder<BillingEvent> billingEvents = new ImmutableSet.Builder<>();
|
||||
BillingEvent.OneTime transferBillingEvent =
|
||||
createTransferBillingEvent(years, renewCost, registry, historyEntry);
|
||||
BillingEvent.Recurring gainingClientAutorenewEvent = createGainingClientAutorenewEvent(
|
||||
historyEntry, serverApproveNewExpirationTime);
|
||||
billingEvents.add(transferBillingEvent, gainingClientAutorenewEvent);
|
||||
// If there will be an autorenew between now and the automatic transfer time, and if the
|
||||
// autorenew grace period length is long enough that the domain will still be within it at the
|
||||
// automatic transfer time, then the transfer will subsume the autorenew so we need to write out
|
||||
// a cancellation for it.
|
||||
Set<Key<? extends TransferServerApproveEntity>> serverApproveEntities = new HashSet<>();
|
||||
DateTime expirationTime = existingResource.getRegistrationExpirationTime();
|
||||
Registry registry = Registry.get(existingResource.getTld());
|
||||
if (automaticTransferTime.isAfter(expirationTime) && automaticTransferTime.isBefore(
|
||||
expirationTime.plus(registry.getAutoRenewGracePeriodLength()))) {
|
||||
BillingEvent.Cancellation autorenewCancellation = new BillingEvent.Cancellation.Builder()
|
||||
.setReason(Reason.RENEW)
|
||||
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
|
||||
.setTargetId(targetId)
|
||||
.setClientId(existingResource.getCurrentSponsorClientId())
|
||||
.setEventTime(automaticTransferTime)
|
||||
.setBillingTime(expirationTime.plus(registry.getAutoRenewGracePeriodLength()))
|
||||
.setRecurringEventKey(existingResource.getAutorenewBillingEvent())
|
||||
.setParent(historyEntry)
|
||||
.build();
|
||||
ofy().save().entity(autorenewCancellation);
|
||||
serverApproveEntities.add(Key.create(autorenewCancellation));
|
||||
DateTime oldExpirationTime = existingDomain.getRegistrationExpirationTime();
|
||||
if (automaticTransferTime.isAfter(oldExpirationTime) && automaticTransferTime.isBefore(
|
||||
oldExpirationTime.plus(registry.getAutoRenewGracePeriodLength()))) {
|
||||
BillingEvent.Cancellation autorenewCancellation =
|
||||
createAutorenewCancellation(
|
||||
existingDomain, historyEntry, automaticTransferTime, registry);
|
||||
billingEvents.add(autorenewCancellation);
|
||||
}
|
||||
serverApproveEntities.add(Key.create(transferBillingEvent));
|
||||
serverApproveEntities.add(Key.create(gainingClientAutorenewEvent));
|
||||
serverApproveEntities.add(Key.create(gainingClientAutorenewPollMessage));
|
||||
return serverApproveEntities;
|
||||
return billingEvents.build();
|
||||
}
|
||||
|
||||
/** Close the old autorenew billing event and save a new one. */
|
||||
@Override
|
||||
protected final void modifyRelatedResources() throws EppException {
|
||||
// End the old autorenew event and poll message at the implicit transfer time. This may delete
|
||||
// the poll message if it has no events left.
|
||||
//
|
||||
// Note that this is still left on the domain as the autorenewBillingEvent because it is still
|
||||
// the current autorenew event until the transfer happens. If you read the domain after the
|
||||
// transfer occurs, then the logic in cloneProjectedAtTime() will move the
|
||||
// serverApproveAutoRenewEvent into the autoRenewEvent field.
|
||||
updateAutorenewRecurrenceEndTime(existingResource, automaticTransferTime);
|
||||
private BillingEvent.OneTime createTransferBillingEvent(
|
||||
int years, Money renewCost, Registry registry, HistoryEntry historyEntry) {
|
||||
DateTime automaticTransferTime = now.plus(registry.getAutomaticTransferLength());
|
||||
return new BillingEvent.OneTime.Builder()
|
||||
.setReason(Reason.TRANSFER)
|
||||
.setTargetId(targetId)
|
||||
.setClientId(gainingClientId)
|
||||
.setCost(renewCost)
|
||||
.setPeriodYears(years)
|
||||
.setEventTime(automaticTransferTime)
|
||||
.setBillingTime(automaticTransferTime.plus(registry.getTransferGracePeriodLength()))
|
||||
.setParent(historyEntry)
|
||||
.build();
|
||||
}
|
||||
|
||||
private BillingEvent.Recurring createGainingClientAutorenewEvent(
|
||||
HistoryEntry historyEntry, DateTime serverApproveNewExpirationTime) {
|
||||
return new BillingEvent.Recurring.Builder()
|
||||
.setReason(Reason.RENEW)
|
||||
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
|
||||
.setTargetId(targetId)
|
||||
.setClientId(gainingClientId)
|
||||
.setEventTime(serverApproveNewExpirationTime)
|
||||
.setRecurrenceEndTime(END_OF_TIME)
|
||||
.setParent(historyEntry)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an autorenew cancellation.
|
||||
*
|
||||
* <p>If there will be an autorenew between now and the automatic transfer time, and if the
|
||||
* autorenew grace period length is long enough that the domain will still be within it at the
|
||||
* automatic transfer time, then the transfer will subsume the autorenew and we need to write out
|
||||
* a cancellation for it.
|
||||
*/
|
||||
private BillingEvent.Cancellation createAutorenewCancellation(
|
||||
DomainResource existingDomain,
|
||||
HistoryEntry historyEntry,
|
||||
DateTime automaticTransferTime,
|
||||
Registry registry) {
|
||||
return new BillingEvent.Cancellation.Builder()
|
||||
.setReason(Reason.RENEW)
|
||||
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
|
||||
.setTargetId(targetId)
|
||||
.setClientId(existingDomain.getCurrentSponsorClientId())
|
||||
.setEventTime(automaticTransferTime)
|
||||
.setBillingTime(existingDomain.getRegistrationExpirationTime()
|
||||
.plus(registry.getAutoRenewGracePeriodLength()))
|
||||
.setRecurringEventKey(existingDomain.getAutorenewBillingEvent())
|
||||
.setParent(historyEntry)
|
||||
.build();
|
||||
}
|
||||
|
||||
/** Create the message that will be sent to the gaining registrar on server approval. */
|
||||
private PollMessage createServerApproveGainingPollMessage(
|
||||
DomainResource existingDomain,
|
||||
HistoryEntry historyEntry,
|
||||
DateTime automaticTransferTime,
|
||||
DateTime serverApproveNewExpirationTime,
|
||||
int years) {
|
||||
return createGainingTransferPollMessage(
|
||||
targetId,
|
||||
createTransferDataBuilder()
|
||||
.setTransferStatus(TransferStatus.SERVER_APPROVED)
|
||||
.setLosingClientId(existingDomain.getCurrentSponsorClientId())
|
||||
.setPendingTransferExpirationTime(automaticTransferTime)
|
||||
.setExtendedRegistrationYears(years)
|
||||
.build(),
|
||||
serverApproveNewExpirationTime,
|
||||
historyEntry);
|
||||
}
|
||||
|
||||
private ImmutableSet<PollMessage> createPollMessages(
|
||||
DomainResource existingDomain,
|
||||
HistoryEntry historyEntry,
|
||||
DateTime automaticTransferTime,
|
||||
DateTime serverApproveNewExpirationTime,
|
||||
int years) {
|
||||
PollMessage.Autorenew gainingClientAutorenewPollMessage =
|
||||
createGainingClientAutorenewPollMessage(historyEntry, serverApproveNewExpirationTime);
|
||||
PollMessage serverApproveGainingPollMessage = createServerApproveGainingPollMessage(
|
||||
existingDomain, historyEntry, automaticTransferTime, serverApproveNewExpirationTime, years);
|
||||
PollMessage serverApproveLosingPollMessage = createServerApproveLosingPollMessage(
|
||||
existingDomain, historyEntry, automaticTransferTime, serverApproveNewExpirationTime, years);
|
||||
return ImmutableSet.of(
|
||||
gainingClientAutorenewPollMessage,
|
||||
serverApproveGainingPollMessage,
|
||||
serverApproveLosingPollMessage);
|
||||
}
|
||||
|
||||
private PollMessage.Autorenew createGainingClientAutorenewPollMessage(
|
||||
HistoryEntry historyEntry, DateTime serverApproveNewExpirationTime) {
|
||||
return new PollMessage.Autorenew.Builder()
|
||||
.setTargetId(targetId)
|
||||
.setClientId(gainingClientId)
|
||||
.setEventTime(serverApproveNewExpirationTime)
|
||||
.setAutorenewEndTime(END_OF_TIME)
|
||||
.setMsg("Domain was auto-renewed.")
|
||||
.setParent(historyEntry)
|
||||
.build();
|
||||
}
|
||||
|
||||
/** Create the message that will be sent to the losing registrar on server approval. */
|
||||
private PollMessage createServerApproveLosingPollMessage(
|
||||
DomainResource existingDomain,
|
||||
HistoryEntry historyEntry,
|
||||
DateTime automaticTransferTime,
|
||||
DateTime serverApproveNewExpirationTime,
|
||||
int years) {
|
||||
return createLosingTransferPollMessage(
|
||||
targetId,
|
||||
createTransferDataBuilder()
|
||||
.setTransferStatus(TransferStatus.SERVER_APPROVED)
|
||||
.setLosingClientId(existingDomain.getCurrentSponsorClientId())
|
||||
.setPendingTransferExpirationTime(automaticTransferTime)
|
||||
.setExtendedRegistrationYears(years)
|
||||
.build(),
|
||||
serverApproveNewExpirationTime,
|
||||
historyEntry);
|
||||
}
|
||||
|
||||
private Builder createTransferDataBuilder() {
|
||||
return new TransferData.Builder()
|
||||
.setTransferRequestTime(now)
|
||||
.setGainingClientId(gainingClientId)
|
||||
.setTransferRequestTrid(trid);
|
||||
}
|
||||
|
||||
private void handleExtraFlowLogic(
|
||||
int years, DomainResource existingDomain, HistoryEntry historyEntry) throws EppException {
|
||||
Optional<RegistryExtraFlowLogic> extraFlowLogic =
|
||||
RegistryExtraFlowLogicProxy.newInstanceForDomain(existingDomain);
|
||||
if (extraFlowLogic.isPresent()) {
|
||||
extraFlowLogic.get().performAdditionalDomainTransferLogic(
|
||||
existingDomain, gainingClientId, now, years, eppInput, historyEntry);
|
||||
extraFlowLogic.get().commitAdditionalLogicChanges();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final HistoryEntry.Type getHistoryEntryType() {
|
||||
return HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST;
|
||||
private DomainTransferResponse createResponse(
|
||||
Period period, DomainResource existingDomain, DomainResource newDomain) {
|
||||
// If the registration were approved this instant, this is what the new expiration would be,
|
||||
// because we cap at 10 years from the moment of approval. This is different than the server
|
||||
// approval new expiration time, which is capped at 10 years from the server approve time.
|
||||
DateTime approveNowExtendedRegistrationTime = extendRegistrationWithCap(
|
||||
now,
|
||||
existingDomain.getRegistrationExpirationTime(),
|
||||
period.getValue());
|
||||
return createTransferResponse(
|
||||
targetId, newDomain.getTransferData(), approveNowExtendedRegistrationTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final Period getCommandPeriod() {
|
||||
return command.getPeriod();
|
||||
private ImmutableList<FeeTransformResponseExtension> createResponseExtensions(Money renewCost,
|
||||
FeeTransformCommandExtension feeTransfer) {
|
||||
return feeTransfer == null
|
||||
? null
|
||||
: ImmutableList.of(feeTransfer.createResponseBuilder()
|
||||
.setCurrency(renewCost.getCurrencyUnit())
|
||||
.setFees(ImmutableList.of(Fee.create(renewCost.getAmount(), FeeType.RENEW)))
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue