mirror of
https://github.com/google/nomulus.git
synced 2025-05-28 15:11:26 +02:00
Replace loadByUniqueId() with methods that don't overload unique id
It is replaced by loadByForeignKey(), which does the same thing that loadByUniqueId() did for contacts, hosts, and domains, and also loadDomainApplication(), which loads domain application by ROID. This eliminates the ugly mode-switching of attemping to load by other foreign key or ROID. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=133980156
This commit is contained in:
parent
025a4ae012
commit
21a98b899c
57 changed files with 367 additions and 340 deletions
|
@ -15,7 +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.loadByForeignKey;
|
||||
import static google.registry.model.EppResourceUtils.queryDomainsUsingResource;
|
||||
import static google.registry.model.domain.DomainResource.extendRegistrationWithCap;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
|
@ -287,7 +287,7 @@ public class ResourceFlowUtils {
|
|||
|
||||
public static <R extends EppResource> R loadResourceForQuery(
|
||||
Class<R> clazz, String targetId, DateTime now) throws ResourceToQueryDoesNotExistException {
|
||||
R resource = loadByUniqueId(clazz, targetId, now);
|
||||
R resource = loadByForeignKey(clazz, targetId, now);
|
||||
if (resource == null) {
|
||||
throw new ResourceToQueryDoesNotExistException(clazz, targetId);
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ public class ResourceFlowUtils {
|
|||
|
||||
public static <R extends EppResource> R loadResourceToMutate(
|
||||
Class<R> clazz, String targetId, DateTime now) throws ResourceToMutateDoesNotExistException {
|
||||
R resource = loadByUniqueId(clazz, targetId, now);
|
||||
R resource = loadByForeignKey(clazz, targetId, now);
|
||||
if (resource == null) {
|
||||
throw new ResourceToMutateDoesNotExistException(clazz, targetId);
|
||||
}
|
||||
|
@ -305,7 +305,7 @@ public class ResourceFlowUtils {
|
|||
|
||||
public static <R extends EppResource> void verifyResourceDoesNotExist(
|
||||
Class<R> clazz, String targetId, DateTime now) throws EppException {
|
||||
if (loadByUniqueId(clazz, targetId, now) != null) {
|
||||
if (loadByForeignKey(clazz, targetId, now) != null) {
|
||||
throw new ResourceAlreadyExistsException(targetId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,13 +14,15 @@
|
|||
|
||||
package google.registry.flows;
|
||||
|
||||
import static google.registry.model.EppResourceUtils.loadByUniqueId;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.EppResourceUtils.loadDomainApplication;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import google.registry.flows.EppException.StatusProhibitsOperationException;
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.domain.DomainApplication;
|
||||
import google.registry.model.domain.launch.ApplicationIdTargetExtension;
|
||||
import google.registry.model.eppcommon.StatusValue;
|
||||
import google.registry.model.eppinput.ResourceCommand.SingleResourceCommand;
|
||||
|
@ -38,6 +40,7 @@ public abstract class SingleResourceFlow<R extends EppResource, C extends Single
|
|||
protected R existingResource;
|
||||
protected String targetId;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected final void initResourceFlow() throws EppException {
|
||||
targetId = getTargetId();
|
||||
|
@ -48,9 +51,14 @@ public abstract class SingleResourceFlow<R extends EppResource, C extends Single
|
|||
// Some flows such as DomainApplicationInfoFlow have the id marked as optional in the schema.
|
||||
// We require it by policy in the relevant flow, but here we need to make sure not to NPE when
|
||||
// initializing the (obviously nonexistent) existing resource.
|
||||
existingResource = (targetId == null || !tryToLoadExisting())
|
||||
? null
|
||||
: loadByUniqueId(resourceClass, targetId, now);
|
||||
if (targetId != null && tryToLoadExisting()) {
|
||||
// This ugliness goes away once domain application flows are flattened.
|
||||
if (resourceClass == DomainApplication.class) {
|
||||
existingResource = (R) loadDomainApplication(targetId, now);
|
||||
} else {
|
||||
existingResource = loadByForeignKey(resourceClass, targetId, now);
|
||||
}
|
||||
}
|
||||
if (existingResource != null) {
|
||||
Set<StatusValue> problems = Sets.intersection(
|
||||
existingResource.getStatusValues(), getDisallowedStatuses());
|
||||
|
|
|
@ -32,7 +32,7 @@ import static google.registry.flows.domain.DomainFlowUtils.verifyPremiumNameIsNo
|
|||
import static google.registry.flows.domain.DomainFlowUtils.verifySignedMarks;
|
||||
import static google.registry.flows.domain.DomainFlowUtils.verifyUnitIsYears;
|
||||
import static google.registry.model.EppResourceUtils.createDomainRoid;
|
||||
import static google.registry.model.EppResourceUtils.loadByUniqueId;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.domain.fee.Fee.FEE_CREATE_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.model.registry.Registries.findTldForName;
|
||||
|
@ -164,7 +164,7 @@ public abstract class BaseDomainCreateFlow<R extends DomainBase, B extends Build
|
|||
@Override
|
||||
public DomainResource run() {
|
||||
// This is cacheable because we are outside of a transaction.
|
||||
return loadByUniqueId(DomainResource.class, targetId, now);
|
||||
return loadByForeignKey(DomainResource.class, targetId, now);
|
||||
}});
|
||||
// If the domain exists already and isn't in the ADD grace period then there is no way it will
|
||||
// be suddenly deleted and therefore the create must fail.
|
||||
|
|
|
@ -16,7 +16,7 @@ package google.registry.flows.domain;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static google.registry.flows.domain.DomainFlowUtils.getReservationType;
|
||||
import static google.registry.model.EppResourceUtils.loadByUniqueId;
|
||||
import static google.registry.model.EppResourceUtils.loadDomainApplication;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.pricing.PricingEngineProxy.getDomainCreateCost;
|
||||
import static google.registry.util.CollectionUtils.isNullOrEmpty;
|
||||
|
@ -75,7 +75,7 @@ public class DomainAllocateFlow extends DomainCreateOrAllocateFlow {
|
|||
throw new OnlySuperuserCanAllocateException();
|
||||
}
|
||||
String applicationRoid = allocateCreate.getApplicationRoid();
|
||||
application = loadByUniqueId(DomainApplication.class, applicationRoid, now);
|
||||
application = loadDomainApplication(applicationRoid, now);
|
||||
if (application == null) {
|
||||
throw new MissingApplicationException(applicationRoid);
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
package google.registry.flows.domain;
|
||||
|
||||
import static google.registry.flows.EppXmlTransformer.unmarshal;
|
||||
import static google.registry.flows.ResourceFlowUtils.loadResourceForQuery;
|
||||
import static google.registry.flows.ResourceFlowUtils.verifyOptionalAuthInfoForResource;
|
||||
import static google.registry.flows.ResourceFlowUtils.verifyResourceOwnership;
|
||||
import static google.registry.flows.domain.DomainFlowUtils.addSecDnsExtensionIfPresent;
|
||||
import static google.registry.flows.domain.DomainFlowUtils.verifyApplicationDomainMatchesTargetId;
|
||||
import static google.registry.model.EppResourceUtils.loadDomainApplication;
|
||||
import static google.registry.model.eppoutput.Result.Code.SUCCESS;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
@ -31,6 +31,7 @@ import google.registry.flows.FlowModule.ApplicationId;
|
|||
import google.registry.flows.FlowModule.ClientId;
|
||||
import google.registry.flows.FlowModule.TargetId;
|
||||
import google.registry.flows.LoggedInFlow;
|
||||
import google.registry.flows.exceptions.ResourceToQueryDoesNotExistException;
|
||||
import google.registry.model.domain.DomainApplication;
|
||||
import google.registry.model.domain.DomainCommand.Info;
|
||||
import google.registry.model.domain.launch.LaunchInfoExtension;
|
||||
|
@ -75,8 +76,10 @@ public final class DomainApplicationInfoFlow extends LoggedInFlow {
|
|||
if (applicationId.isEmpty()) {
|
||||
throw new MissingApplicationIdException();
|
||||
}
|
||||
DomainApplication application =
|
||||
loadResourceForQuery(DomainApplication.class, applicationId, now);
|
||||
DomainApplication application = loadDomainApplication(applicationId, now);
|
||||
if (application == null) {
|
||||
throw new ResourceToQueryDoesNotExistException(DomainApplication.class, applicationId);
|
||||
}
|
||||
verifyApplicationDomainMatchesTargetId(application, targetId);
|
||||
verifyOptionalAuthInfoForResource(authInfo, application);
|
||||
LaunchInfoExtension launchInfo = eppInput.getSingleExtension(LaunchInfoExtension.class);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
package google.registry.flows.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static google.registry.model.EppResourceUtils.loadByUniqueId;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName;
|
||||
import static google.registry.util.CollectionUtils.nullToEmpty;
|
||||
|
@ -181,7 +181,7 @@ public final class TldSpecificLogicProxy {
|
|||
RegistryExtraFlowLogicProxy.newInstanceForTld(registry.getTldStr());
|
||||
if (extraFlowLogic.isPresent()) {
|
||||
// TODO: Consider changing the method definition to have the domain passed in to begin with.
|
||||
DomainResource domain = loadByUniqueId(DomainResource.class, domainName, date);
|
||||
DomainResource domain = loadByForeignKey(DomainResource.class, domainName, date);
|
||||
if (domain == null) {
|
||||
throw new ResourceToMutateDoesNotExistException(DomainResource.class, domainName);
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ public final class TldSpecificLogicProxy {
|
|||
RegistryExtraFlowLogicProxy.newInstanceForTld(registry.getTldStr());
|
||||
if (extraFlowLogic.isPresent()) {
|
||||
// TODO: Consider changing the method definition to have the domain passed in to begin with.
|
||||
DomainResource domain = loadByUniqueId(DomainResource.class, domainName, date);
|
||||
DomainResource domain = loadByForeignKey(DomainResource.class, domainName, date);
|
||||
if (domain == null) {
|
||||
throw new ResourceToMutateDoesNotExistException(DomainResource.class, domainName);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
package google.registry.flows.host;
|
||||
|
||||
import static google.registry.model.EppResourceUtils.isActive;
|
||||
import static google.registry.model.EppResourceUtils.loadByUniqueId;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.registry.Registries.findTldForName;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
|
@ -84,7 +84,7 @@ public class HostFlowUtils {
|
|||
// This is a subordinate host
|
||||
String domainName = Joiner.on('.').join(Iterables.skip(
|
||||
hostName.parts(), hostName.parts().size() - (tld.get().parts().size() + 1)));
|
||||
DomainResource superordinateDomain = loadByUniqueId(DomainResource.class, domainName, now);
|
||||
DomainResource superordinateDomain = loadByForeignKey(DomainResource.class, domainName, now);
|
||||
if (superordinateDomain == null || !isActive(superordinateDomain, now)) {
|
||||
throw new SuperordinateDomainDoesNotExistException(domainName);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue