mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 08:27:14 +02:00
Certain flows need to launch batched jobs. Logically this would mean that flows depend on batch. However, the current state of dependency was the other way around, and the reason for that was ResourceFlowUtils.java that had in it some utility functions that weren't used in the flows and were needed in the batch jobs. This CL removes these utility functions from the /flows/ directory, letting us reverse the dependency edge between flows/ and batch/ Part of this was moving the flows/async/ code into batch/ - which also makes sense because flows/async/ just "enqueued" tasks that would then be run by actions in batch/ It makes sense that the code that enqueues the tasks and the code that dequeues the tasks sit in the same library. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=228698761
125 lines
6.1 KiB
Java
125 lines
6.1 KiB
Java
// Copyright 2017 The Nomulus 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 static google.registry.flows.FlowUtils.validateClientIsLoggedIn;
|
|
import static google.registry.flows.ResourceFlowUtils.verifyExistence;
|
|
import static google.registry.flows.ResourceFlowUtils.verifyOptionalAuthInfo;
|
|
import static google.registry.flows.ResourceFlowUtils.verifyResourceOwnership;
|
|
import static google.registry.flows.domain.DomainFlowUtils.checkAllowedAccessToTld;
|
|
import static google.registry.flows.domain.DomainFlowUtils.verifyApplicationDomainMatchesTargetId;
|
|
import static google.registry.flows.domain.DomainFlowUtils.verifyLaunchPhaseMatchesRegistryPhase;
|
|
import static google.registry.flows.domain.DomainFlowUtils.verifyRegistryStateAllowsApplicationFlows;
|
|
import static google.registry.model.EppResourceUtils.loadDomainApplication;
|
|
import static google.registry.model.ResourceTransferUtils.updateForeignKeyIndexDeletionTime;
|
|
import static google.registry.model.ofy.ObjectifyService.ofy;
|
|
|
|
import com.googlecode.objectify.Key;
|
|
import google.registry.flows.EppException;
|
|
import google.registry.flows.EppException.StatusProhibitsOperationException;
|
|
import google.registry.flows.ExtensionManager;
|
|
import google.registry.flows.FlowModule.ApplicationId;
|
|
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.annotations.ReportingSpec;
|
|
import google.registry.model.domain.DomainApplication;
|
|
import google.registry.model.domain.launch.LaunchDeleteExtension;
|
|
import google.registry.model.domain.launch.LaunchPhase;
|
|
import google.registry.model.domain.metadata.MetadataExtension;
|
|
import google.registry.model.eppcommon.AuthInfo;
|
|
import google.registry.model.eppinput.EppInput;
|
|
import google.registry.model.eppoutput.EppResponse;
|
|
import google.registry.model.registry.Registry;
|
|
import google.registry.model.registry.Registry.TldState;
|
|
import google.registry.model.reporting.HistoryEntry;
|
|
import google.registry.model.reporting.IcannReportingTypes.ActivityReportField;
|
|
import java.util.Optional;
|
|
import javax.inject.Inject;
|
|
import org.joda.time.DateTime;
|
|
|
|
/**
|
|
* An EPP flow that deletes a domain application.
|
|
*
|
|
* @error {@link google.registry.flows.EppException.UnimplementedExtensionException}
|
|
* @error {@link google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException}
|
|
* @error {@link google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException}
|
|
* @error {@link DomainApplicationDeleteFlow.SunriseApplicationCannotBeDeletedInLandrushException}
|
|
* @error {@link DomainFlowUtils.ApplicationDomainNameMismatchException}
|
|
* @error {@link DomainFlowUtils.BadCommandForRegistryPhaseException}
|
|
* @error {@link DomainFlowUtils.LaunchPhaseMismatchException}
|
|
* @error {@link DomainFlowUtils.NotAuthorizedForTldException}
|
|
*/
|
|
@ReportingSpec(ActivityReportField.DOMAIN_DELETE) // Applications are technically domains in EPP.
|
|
public final class DomainApplicationDeleteFlow implements TransactionalFlow {
|
|
|
|
@Inject ExtensionManager extensionManager;
|
|
@Inject EppInput eppInput;
|
|
@Inject Optional<AuthInfo> authInfo;
|
|
@Inject @ClientId String clientId;
|
|
@Inject @TargetId String targetId;
|
|
@Inject @ApplicationId String applicationId;
|
|
@Inject @Superuser boolean isSuperuser;
|
|
@Inject HistoryEntry.Builder historyBuilder;
|
|
@Inject EppResponse.Builder responseBuilder;
|
|
@Inject DomainApplicationDeleteFlow() {}
|
|
|
|
@Override
|
|
public final EppResponse run() throws EppException {
|
|
extensionManager.register(MetadataExtension.class, LaunchDeleteExtension.class);
|
|
extensionManager.validate();
|
|
validateClientIsLoggedIn(clientId);
|
|
DateTime now = ofy().getTransactionTime();
|
|
DomainApplication existingApplication = verifyExistence(
|
|
DomainApplication.class, applicationId, loadDomainApplication(applicationId, now));
|
|
verifyApplicationDomainMatchesTargetId(existingApplication, targetId);
|
|
verifyOptionalAuthInfo(authInfo, existingApplication);
|
|
String tld = existingApplication.getTld();
|
|
if (!isSuperuser) {
|
|
checkAllowedAccessToTld(clientId, tld);
|
|
Registry registry = Registry.get(tld);
|
|
verifyRegistryStateAllowsApplicationFlows(registry, now);
|
|
verifyLaunchPhaseMatchesRegistryPhase(
|
|
registry, eppInput.getSingleExtension(LaunchDeleteExtension.class).get(), now);
|
|
verifyResourceOwnership(clientId, existingApplication);
|
|
// Don't allow deleting a sunrise application during landrush.
|
|
if (existingApplication.getPhase().equals(LaunchPhase.SUNRISE)
|
|
&& registry.getTldState(now).equals(TldState.LANDRUSH)) {
|
|
throw new SunriseApplicationCannotBeDeletedInLandrushException();
|
|
}
|
|
}
|
|
DomainApplication newApplication = existingApplication.asBuilder()
|
|
.setDeletionTime(now)
|
|
.setStatusValues(null)
|
|
.build();
|
|
HistoryEntry historyEntry = historyBuilder
|
|
.setType(HistoryEntry.Type.DOMAIN_APPLICATION_DELETE)
|
|
.setModificationTime(now)
|
|
.setParent(Key.create(existingApplication))
|
|
.build();
|
|
updateForeignKeyIndexDeletionTime(newApplication);
|
|
ofy().save().<Object>entities(newApplication, historyEntry);
|
|
return responseBuilder.build();
|
|
}
|
|
|
|
/** A sunrise application cannot be deleted during landrush. */
|
|
static class SunriseApplicationCannotBeDeletedInLandrushException
|
|
extends StatusProhibitsOperationException {
|
|
public SunriseApplicationCannotBeDeletedInLandrushException() {
|
|
super("A sunrise application cannot be deleted during landrush");
|
|
}
|
|
}
|
|
}
|