mirror of
https://github.com/google/nomulus.git
synced 2025-06-26 22:34:55 +02:00
Add extensible custom logic to the domain delete flow
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=140534389
This commit is contained in:
parent
6373784858
commit
b35ac10b7e
4 changed files with 235 additions and 6 deletions
|
@ -15,6 +15,7 @@
|
|||
package google.registry.flows.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static google.registry.flows.FlowUtils.persistEntityChanges;
|
||||
import static google.registry.flows.FlowUtils.validateClientIsLoggedIn;
|
||||
import static google.registry.flows.ResourceFlowUtils.handlePendingTransferOnDelete;
|
||||
import static google.registry.flows.ResourceFlowUtils.loadAndVerifyExistence;
|
||||
|
@ -45,6 +46,12 @@ import google.registry.flows.FlowModule.TargetId;
|
|||
import google.registry.flows.ResourceFlowUtils;
|
||||
import google.registry.flows.SessionMetadata;
|
||||
import google.registry.flows.TransactionalFlow;
|
||||
import google.registry.flows.custom.DomainDeleteFlowCustomLogic;
|
||||
import google.registry.flows.custom.DomainDeleteFlowCustomLogic.AfterValidationParameters;
|
||||
import google.registry.flows.custom.DomainDeleteFlowCustomLogic.BeforeResponseParameters;
|
||||
import google.registry.flows.custom.DomainDeleteFlowCustomLogic.BeforeResponseReturnData;
|
||||
import google.registry.flows.custom.DomainDeleteFlowCustomLogic.BeforeSaveParameters;
|
||||
import google.registry.flows.custom.EntityChanges;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.billing.BillingEvent;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
|
@ -106,11 +113,13 @@ public final class DomainDeleteFlow implements TransactionalFlow {
|
|||
@Inject DnsQueue dnsQueue;
|
||||
@Inject Trid trid;
|
||||
@Inject EppResponse.Builder responseBuilder;
|
||||
@Inject DomainDeleteFlowCustomLogic customLogic;
|
||||
@Inject DomainDeleteFlow() {}
|
||||
|
||||
@Override
|
||||
public final EppResponse run() throws EppException {
|
||||
extensionManager.register(MetadataExtension.class, SecDnsCreateExtension.class);
|
||||
customLogic.beforeValidation();
|
||||
extensionManager.validate();
|
||||
validateClientIsLoggedIn(clientId);
|
||||
DateTime now = ofy().getTransactionTime();
|
||||
|
@ -118,6 +127,9 @@ public final class DomainDeleteFlow implements TransactionalFlow {
|
|||
DomainResource existingDomain = loadAndVerifyExistence(DomainResource.class, targetId, now);
|
||||
Registry registry = Registry.get(existingDomain.getTld());
|
||||
verifyDeleteAllowed(existingDomain, registry, now);
|
||||
customLogic.afterValidation(
|
||||
AfterValidationParameters.newBuilder().setExistingDomain(existingDomain).build());
|
||||
ImmutableSet.Builder<ImmutableObject> entitiesToSave = new ImmutableSet.Builder<>();
|
||||
HistoryEntry historyEntry = buildHistoryEntry(existingDomain, now);
|
||||
Builder builder =
|
||||
ResourceFlowUtils.<DomainResource, DomainResource.Builder>resolvePendingTransfer(
|
||||
|
@ -132,7 +144,7 @@ public final class DomainDeleteFlow implements TransactionalFlow {
|
|||
.plus(registry.getPendingDeleteLength());
|
||||
PollMessage.OneTime deletePollMessage =
|
||||
createDeletePollMessage(existingDomain, historyEntry, deletionTime);
|
||||
ofy().save().entity(deletePollMessage);
|
||||
entitiesToSave.add(deletePollMessage);
|
||||
builder.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
|
||||
.setDeletionTime(deletionTime)
|
||||
// Clear out all old grace periods and add REDEMPTION, which does not include a key to a
|
||||
|
@ -157,15 +169,31 @@ public final class DomainDeleteFlow implements TransactionalFlow {
|
|||
for (GracePeriod gracePeriod : existingDomain.getGracePeriods()) {
|
||||
// No cancellation is written if the grace period was not for a billable event.
|
||||
if (gracePeriod.hasBillingEvent()) {
|
||||
ofy().save().entity(
|
||||
entitiesToSave.add(
|
||||
BillingEvent.Cancellation.forGracePeriod(gracePeriod, historyEntry, targetId));
|
||||
}
|
||||
}
|
||||
ofy().save().<ImmutableObject>entities(newDomain, historyEntry);
|
||||
entitiesToSave.add(newDomain, historyEntry);
|
||||
EntityChanges entityChanges = customLogic.beforeSave(
|
||||
BeforeSaveParameters.newBuilder()
|
||||
.setExistingDomain(existingDomain)
|
||||
.setNewDomain(newDomain)
|
||||
.setHistoryEntry(historyEntry)
|
||||
.setEntityChanges(EntityChanges.newBuilder().setSaves(entitiesToSave.build()).build())
|
||||
.build());
|
||||
persistEntityChanges(entityChanges);
|
||||
BeforeResponseReturnData responseData =
|
||||
customLogic.beforeResponse(
|
||||
BeforeResponseParameters.newBuilder()
|
||||
.setResultCode(
|
||||
newDomain.getDeletionTime().isAfter(now)
|
||||
? SUCCESS_WITH_ACTION_PENDING
|
||||
: SUCCESS)
|
||||
.setResponseExtensions(getResponseExtensions(existingDomain, now))
|
||||
.build());
|
||||
return responseBuilder
|
||||
.setResultFromCode(
|
||||
newDomain.getDeletionTime().isAfter(now) ? SUCCESS_WITH_ACTION_PENDING : SUCCESS)
|
||||
.setExtensions(getResponseExtensions(existingDomain, now))
|
||||
.setResultFromCode(responseData.resultCode())
|
||||
.setExtensions(responseData.responseExtensions())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue