mirror of
https://github.com/google/nomulus.git
synced 2025-06-27 14:54:51 +02:00
Minor cleanups in host flows
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=133760258
This commit is contained in:
parent
2dcac3ca68
commit
df70da48a2
5 changed files with 45 additions and 40 deletions
|
@ -15,6 +15,7 @@
|
|||
package google.registry.flows;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static google.registry.model.EppResourceUtils.loadByUniqueId;
|
||||
import static google.registry.model.EppResourceUtils.queryDomainsUsingResource;
|
||||
import static google.registry.model.domain.DomainResource.extendRegistrationWithCap;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
|
@ -30,9 +31,11 @@ import com.googlecode.objectify.Key;
|
|||
import com.googlecode.objectify.Work;
|
||||
import google.registry.flows.EppException.AuthorizationErrorException;
|
||||
import google.registry.flows.EppException.InvalidAuthorizationInformationErrorException;
|
||||
import google.registry.flows.exceptions.ResourceAlreadyExistsException;
|
||||
import google.registry.flows.exceptions.ResourceStatusProhibitsOperationException;
|
||||
import google.registry.flows.exceptions.ResourceToDeleteIsReferencedException;
|
||||
import google.registry.flows.exceptions.ResourceToMutateDoesNotExistException;
|
||||
import google.registry.flows.exceptions.ResourceToQueryDoesNotExistException;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.EppResource.Builder;
|
||||
import google.registry.model.EppResource.ForeignKeyedEppResource;
|
||||
|
@ -271,6 +274,31 @@ public class ResourceFlowUtils {
|
|||
return resolvePendingTransfer(resource, transferStatus, now).build();
|
||||
}
|
||||
|
||||
public static <R extends EppResource> R loadResourceForQuery(
|
||||
Class<R> clazz, String targetId, DateTime now) throws ResourceToQueryDoesNotExistException {
|
||||
R existingResource = loadByUniqueId(clazz, targetId, now);
|
||||
if (existingResource == null) {
|
||||
throw new ResourceToQueryDoesNotExistException(clazz, targetId);
|
||||
}
|
||||
return existingResource;
|
||||
}
|
||||
|
||||
public static <R extends EppResource> R loadResourceToMutate(
|
||||
Class<R> clazz, String targetId, DateTime now) throws ResourceToMutateDoesNotExistException {
|
||||
R existingResource = loadByUniqueId(clazz, targetId, now);
|
||||
if (existingResource == null) {
|
||||
throw new ResourceToMutateDoesNotExistException(clazz, targetId);
|
||||
}
|
||||
return existingResource;
|
||||
}
|
||||
|
||||
public static <R extends EppResource> void verifyResourceDoesNotExist(
|
||||
Class<R> clazz, String targetId, DateTime now) throws EppException {
|
||||
if (loadByUniqueId(clazz, targetId, now) != null) {
|
||||
throw new ResourceAlreadyExistsException(targetId);
|
||||
}
|
||||
}
|
||||
|
||||
/** The specified resource belongs to another client. */
|
||||
public static class ResourceNotOwnedException extends AuthorizationErrorException {
|
||||
public ResourceNotOwnedException() {
|
||||
|
|
|
@ -14,11 +14,11 @@
|
|||
|
||||
package google.registry.flows.host;
|
||||
|
||||
import static google.registry.flows.ResourceFlowUtils.verifyResourceDoesNotExist;
|
||||
import static google.registry.flows.host.HostFlowUtils.lookupSuperordinateDomain;
|
||||
import static google.registry.flows.host.HostFlowUtils.validateHostName;
|
||||
import static google.registry.flows.host.HostFlowUtils.verifyDomainIsSameRegistrar;
|
||||
import static google.registry.model.EppResourceUtils.createContactHostRoid;
|
||||
import static google.registry.model.EppResourceUtils.loadByUniqueId;
|
||||
import static google.registry.model.eppoutput.Result.Code.SUCCESS;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.util.CollectionUtils.isNullOrEmpty;
|
||||
|
@ -32,9 +32,9 @@ import google.registry.flows.EppException;
|
|||
import google.registry.flows.EppException.ParameterValueRangeErrorException;
|
||||
import google.registry.flows.EppException.RequiredParameterMissingException;
|
||||
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.ResourceAlreadyExistsException;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
import google.registry.model.domain.metadata.MetadataExtension;
|
||||
|
@ -66,6 +66,7 @@ public class HostCreateFlow extends LoggedInFlow implements TransactionalFlow {
|
|||
|
||||
@Inject ResourceCommand resourceCommand;
|
||||
@Inject @ClientId String clientId;
|
||||
@Inject @TargetId String targetId;
|
||||
@Inject HistoryEntry.Builder historyBuilder;
|
||||
@Inject HostCreateFlow() {}
|
||||
|
||||
|
@ -78,16 +79,12 @@ public class HostCreateFlow extends LoggedInFlow implements TransactionalFlow {
|
|||
@Override
|
||||
protected final EppOutput run() throws EppException {
|
||||
Create command = (Create) resourceCommand;
|
||||
String targetId = command.getTargetId();
|
||||
HostResource existingResource = loadByUniqueId(HostResource.class, targetId, now);
|
||||
if (existingResource != null) {
|
||||
throw new ResourceAlreadyExistsException(targetId);
|
||||
}
|
||||
verifyResourceDoesNotExist(HostResource.class, targetId, now);
|
||||
// The superordinate domain of the host object if creating an in-bailiwick host, or null if
|
||||
// creating an external host. This is looked up before we actually create the Host object so
|
||||
// we can detect error conditions earlier.
|
||||
Optional<DomainResource> superordinateDomain = Optional.fromNullable(
|
||||
lookupSuperordinateDomain(validateHostName(command.getFullyQualifiedHostName()), now));
|
||||
lookupSuperordinateDomain(validateHostName(targetId), now));
|
||||
verifyDomainIsSameRegistrar(superordinateDomain.orNull(), clientId);
|
||||
boolean willBeSubordinate = superordinateDomain.isPresent();
|
||||
boolean hasIpAddresses = !isNullOrEmpty(command.getInetAddresses());
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
package google.registry.flows.host;
|
||||
|
||||
import static google.registry.flows.ResourceFlowUtils.failfastForAsyncDelete;
|
||||
import static google.registry.flows.ResourceFlowUtils.loadResourceToMutate;
|
||||
import static google.registry.flows.ResourceFlowUtils.verifyNoDisallowedStatuses;
|
||||
import static google.registry.flows.ResourceFlowUtils.verifyOptionalAuthInfoForResource;
|
||||
import static google.registry.flows.ResourceFlowUtils.verifyResourceOwnership;
|
||||
import static google.registry.model.EppResourceUtils.loadByUniqueId;
|
||||
import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_ACTION_PENDING;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
|
||||
|
@ -26,24 +26,20 @@ import com.google.common.base.Function;
|
|||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.config.ConfigModule.Config;
|
||||
import google.registry.flows.EppException;
|
||||
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.async.AsyncFlowEnqueuer;
|
||||
import google.registry.flows.exceptions.ResourceToMutateDoesNotExistException;
|
||||
import google.registry.model.domain.DomainBase;
|
||||
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.host.HostCommand.Delete;
|
||||
import google.registry.model.host.HostResource;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import javax.inject.Inject;
|
||||
import org.joda.time.Duration;
|
||||
|
||||
/**
|
||||
* An EPP flow that deletes a host resource.
|
||||
|
@ -69,10 +65,9 @@ public class HostDeleteFlow extends LoggedInFlow implements TransactionalFlow {
|
|||
}};
|
||||
|
||||
@Inject AsyncFlowEnqueuer asyncFlowEnqueuer;
|
||||
@Inject ResourceCommand resourceCommand;
|
||||
@Inject Optional<AuthInfo> authInfo;
|
||||
@Inject @ClientId String clientId;
|
||||
@Inject @Config("asyncDeleteFlowMapreduceDelay") Duration mapreduceDelay;
|
||||
@Inject @TargetId String targetId;
|
||||
@Inject HistoryEntry.Builder historyBuilder;
|
||||
@Inject HostDeleteFlow() {}
|
||||
|
||||
|
@ -83,13 +78,8 @@ public class HostDeleteFlow extends LoggedInFlow implements TransactionalFlow {
|
|||
|
||||
@Override
|
||||
public final EppOutput run() throws EppException {
|
||||
Delete command = (Delete) resourceCommand;
|
||||
String targetId = command.getTargetId();
|
||||
failfastForAsyncDelete(targetId, now, HostResource.class, GET_NAMESERVERS);
|
||||
HostResource existingResource = loadByUniqueId(HostResource.class, targetId, now);
|
||||
if (existingResource == null) {
|
||||
throw new ResourceToMutateDoesNotExistException(HostResource.class, targetId);
|
||||
}
|
||||
HostResource existingResource = loadResourceToMutate(HostResource.class, targetId, now);
|
||||
verifyNoDisallowedStatuses(existingResource, DISALLOWED_STATUSES);
|
||||
verifyOptionalAuthInfoForResource(authInfo, existingResource);
|
||||
if (!isSuperuser) {
|
||||
|
|
|
@ -14,19 +14,17 @@
|
|||
|
||||
package google.registry.flows.host;
|
||||
|
||||
import static google.registry.flows.ResourceFlowUtils.loadResourceForQuery;
|
||||
import static google.registry.flows.ResourceFlowUtils.verifyOptionalAuthInfoForResource;
|
||||
import static google.registry.model.EppResourceUtils.cloneResourceWithLinkedStatus;
|
||||
import static google.registry.model.EppResourceUtils.loadByUniqueId;
|
||||
import static google.registry.model.eppoutput.Result.Code.SUCCESS;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import google.registry.flows.EppException;
|
||||
import google.registry.flows.FlowModule.TargetId;
|
||||
import google.registry.flows.LoggedInFlow;
|
||||
import google.registry.flows.exceptions.ResourceToQueryDoesNotExistException;
|
||||
import google.registry.model.eppcommon.AuthInfo;
|
||||
import google.registry.model.eppinput.ResourceCommand;
|
||||
import google.registry.model.eppoutput.EppOutput;
|
||||
import google.registry.model.host.HostCommand.Info;
|
||||
import google.registry.model.host.HostResource;
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -37,18 +35,13 @@ import javax.inject.Inject;
|
|||
*/
|
||||
public class HostInfoFlow extends LoggedInFlow {
|
||||
|
||||
@Inject ResourceCommand resourceCommand;
|
||||
@Inject @TargetId String targetId;
|
||||
@Inject Optional<AuthInfo> authInfo;
|
||||
@Inject HostInfoFlow() {}
|
||||
|
||||
@Override
|
||||
public EppOutput run() throws EppException {
|
||||
Info command = (Info) resourceCommand;
|
||||
String targetId = command.getTargetId();
|
||||
HostResource existingResource = loadByUniqueId(HostResource.class, targetId, now);
|
||||
if (existingResource == null) {
|
||||
throw new ResourceToQueryDoesNotExistException(HostResource.class, targetId);
|
||||
}
|
||||
HostResource existingResource = loadResourceForQuery(HostResource.class, targetId, now);
|
||||
verifyOptionalAuthInfoForResource(authInfo, existingResource);
|
||||
return createOutput(SUCCESS, cloneResourceWithLinkedStatus(existingResource, now));
|
||||
}
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
package google.registry.flows.host;
|
||||
|
||||
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||
import static google.registry.flows.ResourceFlowUtils.loadResourceToMutate;
|
||||
import static google.registry.flows.ResourceFlowUtils.verifyNoDisallowedStatuses;
|
||||
import static google.registry.flows.ResourceFlowUtils.verifyOptionalAuthInfoForResource;
|
||||
import static google.registry.flows.ResourceFlowUtils.verifyResourceOwnership;
|
||||
import static google.registry.flows.host.HostFlowUtils.lookupSuperordinateDomain;
|
||||
import static google.registry.flows.host.HostFlowUtils.validateHostName;
|
||||
import static google.registry.flows.host.HostFlowUtils.verifyDomainIsSameRegistrar;
|
||||
import static google.registry.model.EppResourceUtils.loadByUniqueId;
|
||||
import static google.registry.model.eppoutput.Result.Code.SUCCESS;
|
||||
import static google.registry.model.index.ForeignKeyIndex.loadAndGetKey;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
|
@ -38,12 +38,12 @@ import google.registry.flows.EppException.ParameterValueRangeErrorException;
|
|||
import google.registry.flows.EppException.RequiredParameterMissingException;
|
||||
import google.registry.flows.EppException.StatusProhibitsOperationException;
|
||||
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.async.AsyncFlowEnqueuer;
|
||||
import google.registry.flows.exceptions.AddRemoveSameValueEppException;
|
||||
import google.registry.flows.exceptions.ResourceHasClientUpdateProhibitedException;
|
||||
import google.registry.flows.exceptions.ResourceToMutateDoesNotExistException;
|
||||
import google.registry.flows.exceptions.StatusNotClientSettableException;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
|
@ -92,6 +92,7 @@ public class HostUpdateFlow extends LoggedInFlow implements TransactionalFlow {
|
|||
@Inject ResourceCommand resourceCommand;
|
||||
@Inject Optional<AuthInfo> authInfo;
|
||||
@Inject @ClientId String clientId;
|
||||
@Inject @TargetId String targetId;
|
||||
@Inject HistoryEntry.Builder historyBuilder;
|
||||
@Inject AsyncFlowEnqueuer asyncFlowEnqueuer;
|
||||
@Inject HostUpdateFlow() {}
|
||||
|
@ -105,11 +106,7 @@ public class HostUpdateFlow extends LoggedInFlow implements TransactionalFlow {
|
|||
public final EppOutput run() throws EppException {
|
||||
Update command = (Update) resourceCommand;
|
||||
String suppliedNewHostName = command.getInnerChange().getFullyQualifiedHostName();
|
||||
String targetId = command.getTargetId();
|
||||
HostResource existingResource = loadByUniqueId(HostResource.class, targetId, now);
|
||||
if (existingResource == null) {
|
||||
throw new ResourceToMutateDoesNotExistException(HostResource.class, targetId);
|
||||
}
|
||||
HostResource existingResource = loadResourceToMutate(HostResource.class, targetId, now);
|
||||
boolean isHostRename = suppliedNewHostName != null;
|
||||
String oldHostName = targetId;
|
||||
String newHostName = firstNonNull(suppliedNewHostName, oldHostName);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue