mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +02:00
Make EppInput.getSingleExtension() return Optional, not @Nullable
This makes it harder to use it incorrectly by accident. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=181795813
This commit is contained in:
parent
fbdb148540
commit
315e6d57bf
21 changed files with 290 additions and 239 deletions
|
@ -209,8 +209,12 @@ public class FlowModule {
|
|||
@ApplicationId
|
||||
static String provideApplicationId(EppInput eppInput) {
|
||||
// Treat a missing application id as empty so we can always inject a non-null value.
|
||||
return nullToEmpty(
|
||||
eppInput.getSingleExtension(ApplicationIdTargetExtension.class).getApplicationId());
|
||||
Optional<ApplicationIdTargetExtension> extension =
|
||||
eppInput.getSingleExtension(ApplicationIdTargetExtension.class);
|
||||
checkState(
|
||||
extension.isPresent(),
|
||||
"ApplicationIdTargetExtension must be used to provide the application ID");
|
||||
return nullToEmpty(extension.get().getApplicationId());
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -233,16 +237,18 @@ public class FlowModule {
|
|||
@Superuser boolean isSuperuser,
|
||||
@ClientId String clientId,
|
||||
EppInput eppInput) {
|
||||
HistoryEntry.Builder historyBuilder = new HistoryEntry.Builder()
|
||||
HistoryEntry.Builder historyBuilder =
|
||||
new HistoryEntry.Builder()
|
||||
.setTrid(trid)
|
||||
.setXmlBytes(inputXmlBytes)
|
||||
.setBySuperuser(isSuperuser)
|
||||
.setClientId(clientId);
|
||||
MetadataExtension metadataExtension = eppInput.getSingleExtension(MetadataExtension.class);
|
||||
if (metadataExtension != null) {
|
||||
Optional<MetadataExtension> metadataExtension =
|
||||
eppInput.getSingleExtension(MetadataExtension.class);
|
||||
if (metadataExtension.isPresent()) {
|
||||
historyBuilder
|
||||
.setReason(metadataExtension.getReason())
|
||||
.setRequestedByRegistrar(metadataExtension.getRequestedByRegistrar());
|
||||
.setReason(metadataExtension.get().getReason())
|
||||
.setRequestedByRegistrar(metadataExtension.get().getRequestedByRegistrar());
|
||||
}
|
||||
return historyBuilder;
|
||||
}
|
||||
|
|
|
@ -90,6 +90,7 @@ import google.registry.model.reporting.DomainTransactionRecord.TransactionReport
|
|||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.model.reporting.IcannReportingTypes.ActivityReportField;
|
||||
import google.registry.tmch.LordnTask;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
import org.joda.time.DateTime;
|
||||
|
@ -150,11 +151,11 @@ public class DomainAllocateFlow implements TransactionalFlow {
|
|||
int years = period.getValue();
|
||||
validateRegistrationPeriod(years);
|
||||
validateCreateCommandContactsAndNameservers(command, registry, domainName);
|
||||
SecDnsCreateExtension secDnsCreate =
|
||||
Optional<SecDnsCreateExtension> secDnsCreate =
|
||||
validateSecDnsExtension(eppInput.getSingleExtension(SecDnsCreateExtension.class));
|
||||
boolean isSunrushAddGracePeriod = isNullOrEmpty(command.getNameservers());
|
||||
AllocateCreateExtension allocateCreate =
|
||||
eppInput.getSingleExtension(AllocateCreateExtension.class);
|
||||
eppInput.getSingleExtension(AllocateCreateExtension.class).get();
|
||||
DomainApplication application =
|
||||
loadAndValidateApplication(allocateCreate.getApplicationRoid(), now);
|
||||
String repoId = createDomainRepoId(ObjectifyService.allocateId(), registry.getTldStr());
|
||||
|
@ -166,23 +167,29 @@ public class DomainAllocateFlow implements TransactionalFlow {
|
|||
domainName, application, historyEntry, isSunrushAddGracePeriod, registry, now, years);
|
||||
entitiesToSave.addAll(billsAndPolls);
|
||||
DateTime registrationExpirationTime = leapSafeAddYears(now, years);
|
||||
DomainResource newDomain = new DomainResource.Builder()
|
||||
DomainResource newDomain =
|
||||
new DomainResource.Builder()
|
||||
.setCreationClientId(clientId)
|
||||
.setPersistedCurrentSponsorClientId(clientId)
|
||||
.setRepoId(repoId)
|
||||
.setIdnTableName(validateDomainNameWithIdnTables(domainName))
|
||||
.setRegistrationExpirationTime(registrationExpirationTime)
|
||||
.setAutorenewBillingEvent(Key.create(getOnly(billsAndPolls, BillingEvent.Recurring.class)))
|
||||
.setAutorenewPollMessage(Key.create(getOnly(billsAndPolls, PollMessage.Autorenew.class)))
|
||||
.setAutorenewBillingEvent(
|
||||
Key.create(getOnly(billsAndPolls, BillingEvent.Recurring.class)))
|
||||
.setAutorenewPollMessage(
|
||||
Key.create(getOnly(billsAndPolls, PollMessage.Autorenew.class)))
|
||||
.setApplicationTime(allocateCreate.getApplicationTime())
|
||||
.setApplication(Key.create(application))
|
||||
.setSmdId(allocateCreate.getSmdId())
|
||||
.setLaunchNotice(allocateCreate.getNotice())
|
||||
.setDsData(secDnsCreate == null ? application.getDsData() : secDnsCreate.getDsData())
|
||||
.addGracePeriod(createGracePeriod(
|
||||
.setDsData(
|
||||
secDnsCreate.isPresent() ? secDnsCreate.get().getDsData() : application.getDsData())
|
||||
.addGracePeriod(
|
||||
createGracePeriod(
|
||||
isSunrushAddGracePeriod, getOnly(billsAndPolls, BillingEvent.OneTime.class)))
|
||||
// Names on the collision list will not be delegated. Set server hold.
|
||||
.setStatusValues(getReservationTypes(domainName).contains(ReservationType.NAME_COLLISION)
|
||||
.setStatusValues(
|
||||
getReservationTypes(domainName).contains(ReservationType.NAME_COLLISION)
|
||||
? ImmutableSet.of(StatusValue.SERVER_HOLD)
|
||||
: ImmutableSet.of())
|
||||
.setRegistrant(command.getRegistrant())
|
||||
|
@ -402,11 +409,11 @@ public class DomainAllocateFlow implements TransactionalFlow {
|
|||
private ImmutableList<FeeTransformResponseExtension> createResponseExtensions(
|
||||
DateTime now, Registry registry, int years) throws EppException {
|
||||
FeesAndCredits feesAndCredits = pricingLogic.getCreatePrice(registry, targetId, now, years);
|
||||
FeeCreateCommandExtension feeCreate =
|
||||
Optional<FeeCreateCommandExtension> feeCreate =
|
||||
eppInput.getSingleExtension(FeeCreateCommandExtension.class);
|
||||
return (feeCreate == null)
|
||||
? ImmutableList.of()
|
||||
: ImmutableList.of(createFeeCreateResponse(feeCreate, feesAndCredits));
|
||||
return feeCreate.isPresent()
|
||||
? ImmutableList.of(createFeeCreateResponse(feeCreate.get(), feesAndCredits))
|
||||
: ImmutableList.of();
|
||||
}
|
||||
|
||||
/** Domain application with specific ROID does not exist. */
|
||||
|
|
|
@ -94,6 +94,7 @@ import google.registry.model.registry.Registry.TldState;
|
|||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.model.reporting.IcannReportingTypes.ActivityReportField;
|
||||
import google.registry.model.smd.EncodedSignedMark;
|
||||
import java.util.Optional;
|
||||
import javax.inject.Inject;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
|
@ -216,10 +217,9 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
|
|||
int years = command.getPeriod().getValue();
|
||||
validateRegistrationPeriod(years);
|
||||
validateCreateCommandContactsAndNameservers(command, registry, domainName);
|
||||
LaunchCreateExtension launchCreate = eppInput.getSingleExtension(LaunchCreateExtension.class);
|
||||
if (launchCreate != null) {
|
||||
LaunchCreateExtension launchCreate =
|
||||
eppInput.getSingleExtension(LaunchCreateExtension.class).get();
|
||||
validateLaunchCreateExtension(launchCreate, registry, domainName, now);
|
||||
}
|
||||
boolean isAnchorTenant =
|
||||
matchesAnchorTenantReservation(domainName, authInfo.getPw().getValue());
|
||||
// Superusers can create reserved domains, force creations on domains that require a claims
|
||||
|
@ -232,10 +232,10 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
|
|||
verifyNotReserved(domainName, isSunriseApplication);
|
||||
}
|
||||
}
|
||||
FeeCreateCommandExtension feeCreate =
|
||||
Optional<FeeCreateCommandExtension> feeCreate =
|
||||
eppInput.getSingleExtension(FeeCreateCommandExtension.class);
|
||||
validateFeeChallenge(targetId, tld, now, feeCreate, feesAndCredits);
|
||||
SecDnsCreateExtension secDnsCreate =
|
||||
Optional<SecDnsCreateExtension> secDnsCreate =
|
||||
validateSecDnsExtension(eppInput.getSingleExtension(SecDnsCreateExtension.class));
|
||||
customLogic.afterValidation(
|
||||
AfterValidationParameters.newBuilder()
|
||||
|
@ -254,7 +254,7 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
|
|||
.setPeriod(command.getPeriod())
|
||||
.setApplicationStatus(ApplicationStatus.VALIDATED)
|
||||
.addStatusValue(StatusValue.PENDING_CREATE)
|
||||
.setDsData(secDnsCreate == null ? null : secDnsCreate.getDsData())
|
||||
.setDsData(secDnsCreate.isPresent() ? secDnsCreate.get().getDsData() : null)
|
||||
.setRegistrant(command.getRegistrant())
|
||||
.setAuthInfo(command.getAuthInfo())
|
||||
.setFullyQualifiedDomainName(targetId)
|
||||
|
@ -377,7 +377,7 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
|
|||
private static ImmutableList<ResponseExtension> createResponseExtensions(
|
||||
String applicationId,
|
||||
LaunchPhase launchPhase,
|
||||
FeeTransformCommandExtension feeCreate,
|
||||
Optional<? extends FeeTransformCommandExtension> feeCreate,
|
||||
FeesAndCredits feesAndCredits) {
|
||||
ImmutableList.Builder<ResponseExtension> responseExtensionsBuilder =
|
||||
new ImmutableList.Builder<>();
|
||||
|
@ -385,8 +385,8 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
|
|||
.setPhase(launchPhase)
|
||||
.setApplicationId(applicationId)
|
||||
.build());
|
||||
if (feeCreate != null) {
|
||||
responseExtensionsBuilder.add(createFeeCreateResponse(feeCreate, feesAndCredits));
|
||||
if (feeCreate.isPresent()) {
|
||||
responseExtensionsBuilder.add(createFeeCreateResponse(feeCreate.get(), feesAndCredits));
|
||||
}
|
||||
return responseExtensionsBuilder.build();
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ public final class DomainApplicationDeleteFlow implements TransactionalFlow {
|
|||
Registry registry = Registry.get(tld);
|
||||
verifyRegistryStateAllowsLaunchFlows(registry, now);
|
||||
verifyLaunchPhaseMatchesRegistryPhase(
|
||||
registry, eppInput.getSingleExtension(LaunchDeleteExtension.class), now);
|
||||
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)
|
||||
|
|
|
@ -98,7 +98,7 @@ public final class DomainApplicationInfoFlow implements Flow {
|
|||
: null);
|
||||
verifyApplicationDomainMatchesTargetId(application, targetId);
|
||||
verifyOptionalAuthInfo(authInfo, application);
|
||||
LaunchInfoExtension launchInfo = eppInput.getSingleExtension(LaunchInfoExtension.class);
|
||||
LaunchInfoExtension launchInfo = eppInput.getSingleExtension(LaunchInfoExtension.class).get();
|
||||
if (!application.getPhase().equals(launchInfo.getPhase())) {
|
||||
throw new ApplicationLaunchPhaseMismatchException();
|
||||
}
|
||||
|
|
|
@ -189,12 +189,12 @@ public class DomainApplicationUpdateFlow implements TransactionalFlow {
|
|||
Registry registry = Registry.get(tld);
|
||||
FeesAndCredits feesAndCredits =
|
||||
pricingLogic.getApplicationUpdatePrice(registry, existingApplication, now);
|
||||
FeeUpdateCommandExtension feeUpdate =
|
||||
Optional<FeeUpdateCommandExtension> feeUpdate =
|
||||
eppInput.getSingleExtension(FeeUpdateCommandExtension.class);
|
||||
// If the fee extension is present, validate it (even if the cost is zero, to check for price
|
||||
// mismatches). Don't rely on the the validateFeeChallenge check for feeUpdate nullness, because
|
||||
// it throws an error if the name is premium, and we don't want to do that here.
|
||||
if (feeUpdate != null) {
|
||||
if (feeUpdate.isPresent()) {
|
||||
validateFeeChallenge(targetId, tld, now, feeUpdate, feesAndCredits);
|
||||
} else if (!feesAndCredits.getTotalCost().isZero()) {
|
||||
// If it's not present but the cost is not zero, throw an exception.
|
||||
|
@ -231,11 +231,12 @@ public class DomainApplicationUpdateFlow implements TransactionalFlow {
|
|||
checkSameValuesNotAddedAndRemoved(add.getContacts(), remove.getContacts());
|
||||
checkSameValuesNotAddedAndRemoved(add.getStatusValues(), remove.getStatusValues());
|
||||
Change change = command.getInnerChange();
|
||||
SecDnsUpdateExtension secDnsUpdate = eppInput.getSingleExtension(SecDnsUpdateExtension.class);
|
||||
Optional<SecDnsUpdateExtension> secDnsUpdate =
|
||||
eppInput.getSingleExtension(SecDnsUpdateExtension.class);
|
||||
return application.asBuilder()
|
||||
// Handle the secDNS extension.
|
||||
.setDsData(secDnsUpdate != null
|
||||
? updateDsData(application.getDsData(), secDnsUpdate)
|
||||
.setDsData(secDnsUpdate.isPresent()
|
||||
? updateDsData(application.getDsData(), secDnsUpdate.get())
|
||||
: application.getDsData())
|
||||
.setLastEppUpdateTime(now)
|
||||
.setLastEppUpdateClientId(clientId)
|
||||
|
|
|
@ -151,13 +151,13 @@ public final class DomainCheckFlow implements Flow {
|
|||
.setAsOfDate(now)
|
||||
.build());
|
||||
Set<String> existingIds = checkResourcesExist(DomainResource.class, targetIds, now);
|
||||
AllocationTokenExtension allocationTokenExtension =
|
||||
Optional<AllocationTokenExtension> allocationTokenExtension =
|
||||
eppInput.getSingleExtension(AllocationTokenExtension.class);
|
||||
ImmutableMap<String, String> tokenCheckResults =
|
||||
(allocationTokenExtension == null)
|
||||
? ImmutableMap.of()
|
||||
: checkDomainsWithToken(
|
||||
targetIds, allocationTokenExtension.getAllocationToken(), clientId);
|
||||
allocationTokenExtension.isPresent()
|
||||
? checkDomainsWithToken(
|
||||
targetIds, allocationTokenExtension.get().getAllocationToken(), clientId)
|
||||
: ImmutableMap.of();
|
||||
ImmutableList.Builder<DomainCheck> checks = new ImmutableList.Builder<>();
|
||||
for (String targetId : targetIds) {
|
||||
Optional<String> message =
|
||||
|
@ -196,7 +196,7 @@ public final class DomainCheckFlow implements Flow {
|
|||
if (reservationTypes.isEmpty()
|
||||
&& isDomainPremium(domainName.toString(), now)
|
||||
&& registry.getPremiumPriceAckRequired()
|
||||
&& eppInput.getSingleExtension(FeeCheckCommandExtension.class) == null) {
|
||||
&& !eppInput.getSingleExtension(FeeCheckCommandExtension.class).isPresent()) {
|
||||
return Optional.of("Premium names require EPP ext.");
|
||||
}
|
||||
if (!reservationTypes.isEmpty()) {
|
||||
|
@ -210,11 +210,12 @@ public final class DomainCheckFlow implements Flow {
|
|||
/** Handle the fee check extension. */
|
||||
private ImmutableList<? extends ResponseExtension> getResponseExtensions(
|
||||
ImmutableMap<String, InternetDomainName> domainNames, DateTime now) throws EppException {
|
||||
FeeCheckCommandExtension<?, ?> feeCheck =
|
||||
Optional<FeeCheckCommandExtension> feeCheckOpt =
|
||||
eppInput.getSingleExtension(FeeCheckCommandExtension.class);
|
||||
if (feeCheck == null) {
|
||||
if (!feeCheckOpt.isPresent()) {
|
||||
return ImmutableList.of(); // No fee checks were requested.
|
||||
}
|
||||
FeeCheckCommandExtension<?, ?> feeCheck = feeCheckOpt.get();
|
||||
ImmutableList.Builder<FeeCheckResponseExtensionItem> responseItems =
|
||||
new ImmutableList.Builder<>();
|
||||
for (FeeCheckCommandExtensionItem feeCheckItem : feeCheck.getItems()) {
|
||||
|
|
|
@ -85,7 +85,7 @@ public final class DomainClaimsCheckFlow implements Flow {
|
|||
extensionManager.register(LaunchCheckExtension.class, AllocationTokenExtension.class);
|
||||
extensionManager.validate();
|
||||
validateClientIsLoggedIn(clientId);
|
||||
if (eppInput.getSingleExtension(AllocationTokenExtension.class) != null) {
|
||||
if (eppInput.getSingleExtension(AllocationTokenExtension.class).isPresent()) {
|
||||
throw new DomainClaimsCheckNotAllowedWithAllocationTokens();
|
||||
}
|
||||
List<String> targetIds = ((Check) resourceCommand).getTargetIds();
|
||||
|
|
|
@ -220,12 +220,14 @@ public class DomainCreateFlow implements TransactionalFlow {
|
|||
}
|
||||
TldState tldState = registry.getTldState(now);
|
||||
boolean isAnchorTenant = isAnchorTenant(domainName);
|
||||
LaunchCreateExtension launchCreate = eppInput.getSingleExtension(LaunchCreateExtension.class);
|
||||
boolean hasSignedMarks = launchCreate != null && !launchCreate.getSignedMarks().isEmpty();
|
||||
boolean hasClaimsNotice = launchCreate != null && launchCreate.getNotice() != null;
|
||||
if (launchCreate != null) {
|
||||
verifyNoCodeMarks(launchCreate);
|
||||
validateLaunchCreateNotice(launchCreate.getNotice(), domainLabel, isSuperuser, now);
|
||||
Optional<LaunchCreateExtension> launchCreate =
|
||||
eppInput.getSingleExtension(LaunchCreateExtension.class);
|
||||
boolean hasSignedMarks =
|
||||
launchCreate.isPresent() && !launchCreate.get().getSignedMarks().isEmpty();
|
||||
boolean hasClaimsNotice = launchCreate.isPresent() && launchCreate.get().getNotice() != null;
|
||||
if (launchCreate.isPresent()) {
|
||||
verifyNoCodeMarks(launchCreate.get());
|
||||
validateLaunchCreateNotice(launchCreate.get().getNotice(), domainLabel, isSuperuser, now);
|
||||
}
|
||||
boolean isSunriseCreate = hasSignedMarks && SUNRISE_STATES.contains(tldState);
|
||||
String signedMarkId = null;
|
||||
|
@ -234,8 +236,8 @@ public class DomainCreateFlow implements TransactionalFlow {
|
|||
// registering premium domains.
|
||||
if (!isSuperuser) {
|
||||
checkAllowedAccessToTld(clientId, registry.getTldStr());
|
||||
if (launchCreate != null) {
|
||||
verifyLaunchPhaseMatchesRegistryPhase(registry, launchCreate, now);
|
||||
if (launchCreate.isPresent()) {
|
||||
verifyLaunchPhaseMatchesRegistryPhase(registry, launchCreate.get(), now);
|
||||
}
|
||||
if (!isAnchorTenant) {
|
||||
verifyNotReserved(domainName, isSunriseCreate);
|
||||
|
@ -253,7 +255,9 @@ public class DomainCreateFlow implements TransactionalFlow {
|
|||
// If a signed mark was provided, then it must match the desired domain label. Get the mark
|
||||
// at this point so that we can verify it before the "after validation" extension point.
|
||||
signedMarkId =
|
||||
tmchUtils.verifySignedMarks(launchCreate.getSignedMarks(), domainLabel, now).getId();
|
||||
tmchUtils
|
||||
.verifySignedMarks(launchCreate.get().getSignedMarks(), domainLabel, now)
|
||||
.getId();
|
||||
}
|
||||
}
|
||||
Optional<AllocationToken> allocationToken =
|
||||
|
@ -264,11 +268,11 @@ public class DomainCreateFlow implements TransactionalFlow {
|
|||
.setYears(years)
|
||||
.setSignedMarkId(Optional.ofNullable(signedMarkId))
|
||||
.build());
|
||||
FeeCreateCommandExtension feeCreate =
|
||||
Optional<FeeCreateCommandExtension> feeCreate =
|
||||
eppInput.getSingleExtension(FeeCreateCommandExtension.class);
|
||||
FeesAndCredits feesAndCredits = pricingLogic.getCreatePrice(registry, targetId, now, years);
|
||||
validateFeeChallenge(targetId, registry.getTldStr(), now, feeCreate, feesAndCredits);
|
||||
SecDnsCreateExtension secDnsCreate =
|
||||
Optional<SecDnsCreateExtension> secDnsCreate =
|
||||
validateSecDnsExtension(eppInput.getSingleExtension(SecDnsCreateExtension.class));
|
||||
String repoId = createDomainRepoId(ObjectifyService.allocateId(), registry.getTldStr());
|
||||
DateTime registrationExpirationTime = leapSafeAddYears(now, years);
|
||||
|
@ -302,9 +306,9 @@ public class DomainCreateFlow implements TransactionalFlow {
|
|||
.setRegistrationExpirationTime(registrationExpirationTime)
|
||||
.setAutorenewBillingEvent(Key.create(autorenewBillingEvent))
|
||||
.setAutorenewPollMessage(Key.create(autorenewPollMessage))
|
||||
.setLaunchNotice(hasClaimsNotice ? launchCreate.getNotice() : null)
|
||||
.setLaunchNotice(hasClaimsNotice ? launchCreate.get().getNotice() : null)
|
||||
.setSmdId(signedMarkId)
|
||||
.setDsData(secDnsCreate == null ? null : secDnsCreate.getDsData())
|
||||
.setDsData(secDnsCreate.isPresent() ? secDnsCreate.get().getDsData() : null)
|
||||
.setRegistrant(command.getRegistrant())
|
||||
.setAuthInfo(command.getAuthInfo())
|
||||
.setFullyQualifiedDomainName(targetId)
|
||||
|
@ -354,9 +358,10 @@ public class DomainCreateFlow implements TransactionalFlow {
|
|||
}
|
||||
|
||||
private boolean isAnchorTenant(InternetDomainName domainName) {
|
||||
MetadataExtension metadataExtension = eppInput.getSingleExtension(MetadataExtension.class);
|
||||
Optional<MetadataExtension> metadataExtension =
|
||||
eppInput.getSingleExtension(MetadataExtension.class);
|
||||
return matchesAnchorTenantReservation(domainName, authInfo.getPw().getValue())
|
||||
|| (metadataExtension != null && metadataExtension.getIsAnchorTenant());
|
||||
|| (metadataExtension.isPresent() && metadataExtension.get().getIsAnchorTenant());
|
||||
}
|
||||
|
||||
/** Prohibit creating a domain if there is an open application for the same name. */
|
||||
|
@ -380,11 +385,12 @@ public class DomainCreateFlow implements TransactionalFlow {
|
|||
private Optional<AllocationToken> verifyAllocationTokenIfPresent(
|
||||
InternetDomainName domainName, Registry registry, String clientId)
|
||||
throws EppException {
|
||||
AllocationTokenExtension ext = eppInput.getSingleExtension(AllocationTokenExtension.class);
|
||||
Optional<AllocationTokenExtension> extension =
|
||||
eppInput.getSingleExtension(AllocationTokenExtension.class);
|
||||
return Optional.ofNullable(
|
||||
(ext == null)
|
||||
? null
|
||||
: verifyToken(domainName, ext.getAllocationToken(), registry, clientId));
|
||||
extension.isPresent()
|
||||
? verifyToken(domainName, extension.get().getAllocationToken(), registry, clientId)
|
||||
: null);
|
||||
}
|
||||
|
||||
private HistoryEntry buildHistoryEntry(
|
||||
|
@ -488,10 +494,10 @@ public class DomainCreateFlow implements TransactionalFlow {
|
|||
}
|
||||
|
||||
private static ImmutableList<FeeTransformResponseExtension> createResponseExtensions(
|
||||
FeeCreateCommandExtension feeCreate, FeesAndCredits feesAndCredits) {
|
||||
return (feeCreate == null)
|
||||
? ImmutableList.of()
|
||||
: ImmutableList.of(createFeeCreateResponse(feeCreate, feesAndCredits));
|
||||
Optional<FeeCreateCommandExtension> feeCreate, FeesAndCredits feesAndCredits) {
|
||||
return feeCreate.isPresent()
|
||||
? ImmutableList.of(createFeeCreateResponse(feeCreate.get(), feesAndCredits))
|
||||
: ImmutableList.of();
|
||||
}
|
||||
|
||||
/** There is an open application for this domain. */
|
||||
|
|
|
@ -155,13 +155,14 @@ public final class DomainDeleteFlow implements TransactionalFlow {
|
|||
}
|
||||
Duration redemptionGracePeriodLength = registry.getRedemptionGracePeriodLength();
|
||||
Duration pendingDeleteLength = registry.getPendingDeleteLength();
|
||||
DomainDeleteSuperuserExtension domainDeleteSuperuserExtension =
|
||||
Optional<DomainDeleteSuperuserExtension> domainDeleteSuperuserExtension =
|
||||
eppInput.getSingleExtension(DomainDeleteSuperuserExtension.class);
|
||||
if (domainDeleteSuperuserExtension != null) {
|
||||
if (domainDeleteSuperuserExtension.isPresent()) {
|
||||
redemptionGracePeriodLength =
|
||||
Duration.standardDays(domainDeleteSuperuserExtension.getRedemptionGracePeriodDays());
|
||||
Duration.standardDays(
|
||||
domainDeleteSuperuserExtension.get().getRedemptionGracePeriodDays());
|
||||
pendingDeleteLength =
|
||||
Duration.standardDays(domainDeleteSuperuserExtension.getPendingDeleteDays());
|
||||
Duration.standardDays(domainDeleteSuperuserExtension.get().getPendingDeleteDays());
|
||||
}
|
||||
boolean inAddGracePeriod =
|
||||
existingDomain.getGracePeriodStatuses().contains(GracePeriodStatus.ADD);
|
||||
|
|
|
@ -617,20 +617,20 @@ public class DomainFlowUtils {
|
|||
String domainName,
|
||||
String tld,
|
||||
DateTime priceTime,
|
||||
final FeeTransformCommandExtension feeCommand,
|
||||
final Optional<? extends FeeTransformCommandExtension> feeCommand,
|
||||
FeesAndCredits feesAndCredits)
|
||||
throws EppException {
|
||||
Registry registry = Registry.get(tld);
|
||||
if (registry.getPremiumPriceAckRequired()
|
||||
&& isDomainPremium(domainName, priceTime)
|
||||
&& feeCommand == null) {
|
||||
&& !feeCommand.isPresent()) {
|
||||
throw new FeesRequiredForPremiumNameException();
|
||||
}
|
||||
|
||||
// Check for the case where a fee command extension was required but not provided.
|
||||
// This only happens when the total fees are non-zero and include custom fees requiring the
|
||||
// extension.
|
||||
if (feeCommand == null) {
|
||||
if (!feeCommand.isPresent()) {
|
||||
if (!feesAndCredits.getEapCost().isZero()) {
|
||||
throw new FeesRequiredDuringEarlyAccessProgramException(feesAndCredits.getEapCost());
|
||||
}
|
||||
|
@ -640,7 +640,7 @@ public class DomainFlowUtils {
|
|||
throw new FeesRequiredForNonFreeOperationException(feesAndCredits.getTotalCost());
|
||||
}
|
||||
|
||||
List<Fee> fees = feeCommand.getFees();
|
||||
List<Fee> fees = feeCommand.get().getFees();
|
||||
// The schema guarantees that at least one fee will be present.
|
||||
checkState(!fees.isEmpty());
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
|
@ -650,7 +650,7 @@ public class DomainFlowUtils {
|
|||
}
|
||||
total = total.add(fee.getCost());
|
||||
}
|
||||
for (Credit credit : feeCommand.getCredits()) {
|
||||
for (Credit credit : feeCommand.get().getCredits()) {
|
||||
if (!credit.hasDefaultAttributes()) {
|
||||
throw new UnsupportedFeeAttributeException();
|
||||
}
|
||||
|
@ -659,7 +659,7 @@ public class DomainFlowUtils {
|
|||
|
||||
Money feeTotal = null;
|
||||
try {
|
||||
feeTotal = Money.of(feeCommand.getCurrency(), total);
|
||||
feeTotal = Money.of(feeCommand.get().getCurrency(), total);
|
||||
} catch (ArithmeticException e) {
|
||||
throw new CurrencyValueScaleException();
|
||||
}
|
||||
|
@ -801,18 +801,18 @@ public class DomainFlowUtils {
|
|||
}
|
||||
|
||||
/** Validate the secDNS extension, if present. */
|
||||
static SecDnsCreateExtension validateSecDnsExtension(SecDnsCreateExtension secDnsCreate)
|
||||
throws EppException {
|
||||
if (secDnsCreate == null) {
|
||||
return null;
|
||||
static Optional<SecDnsCreateExtension> validateSecDnsExtension(
|
||||
Optional<SecDnsCreateExtension> secDnsCreate) throws EppException {
|
||||
if (!secDnsCreate.isPresent()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (secDnsCreate.getDsData() == null) {
|
||||
if (secDnsCreate.get().getDsData() == null) {
|
||||
throw new DsDataRequiredException();
|
||||
}
|
||||
if (secDnsCreate.getMaxSigLife() != null) {
|
||||
if (secDnsCreate.get().getMaxSigLife() != null) {
|
||||
throw new MaxSigLifeNotSupportedException();
|
||||
}
|
||||
validateDsData(secDnsCreate.getDsData());
|
||||
validateDsData(secDnsCreate.get().getDsData());
|
||||
return secDnsCreate;
|
||||
}
|
||||
|
||||
|
|
|
@ -151,12 +151,12 @@ public final class DomainInfoFlow implements Flow {
|
|||
if (!gracePeriodStatuses.isEmpty()) {
|
||||
extensions.add(RgpInfoExtension.create(gracePeriodStatuses));
|
||||
}
|
||||
FeeInfoCommandExtensionV06 feeInfo =
|
||||
Optional<FeeInfoCommandExtensionV06> feeInfo =
|
||||
eppInput.getSingleExtension(FeeInfoCommandExtensionV06.class);
|
||||
if (feeInfo != null) { // Fee check was requested.
|
||||
if (feeInfo.isPresent()) { // Fee check was requested.
|
||||
FeeInfoResponseExtensionV06.Builder builder = new FeeInfoResponseExtensionV06.Builder();
|
||||
handleFeeRequest(
|
||||
feeInfo,
|
||||
feeInfo.get(),
|
||||
builder,
|
||||
InternetDomainName.from(targetId),
|
||||
null,
|
||||
|
|
|
@ -142,7 +142,7 @@ public final class DomainRenewFlow implements TransactionalFlow {
|
|||
DateTime newExpirationTime =
|
||||
leapSafeAddYears(existingDomain.getRegistrationExpirationTime(), years); // Uncapped
|
||||
validateRegistrationPeriod(now, newExpirationTime);
|
||||
FeeRenewCommandExtension feeRenew =
|
||||
Optional<FeeRenewCommandExtension> feeRenew =
|
||||
eppInput.getSingleExtension(FeeRenewCommandExtension.class);
|
||||
FeesAndCredits feesAndCredits =
|
||||
pricingLogic.getRenewPrice(Registry.get(existingDomain.getTld()), targetId, now, years);
|
||||
|
@ -261,13 +261,16 @@ public final class DomainRenewFlow implements TransactionalFlow {
|
|||
}
|
||||
|
||||
private ImmutableList<FeeTransformResponseExtension> createResponseExtensions(
|
||||
Money renewCost, FeeRenewCommandExtension feeRenew) {
|
||||
return (feeRenew == null)
|
||||
? ImmutableList.of()
|
||||
: ImmutableList.of(feeRenew.createResponseBuilder()
|
||||
Money renewCost, Optional<FeeRenewCommandExtension> feeRenew) {
|
||||
return feeRenew.isPresent()
|
||||
? ImmutableList.of(
|
||||
feeRenew
|
||||
.get()
|
||||
.createResponseBuilder()
|
||||
.setCurrency(renewCost.getCurrencyUnit())
|
||||
.setFees(ImmutableList.of(Fee.create(renewCost.getAmount(), FeeType.RENEW)))
|
||||
.build());
|
||||
.build())
|
||||
: ImmutableList.of();
|
||||
}
|
||||
|
||||
/** The current expiration date is incorrect. */
|
||||
|
|
|
@ -134,7 +134,7 @@ public final class DomainRestoreRequestFlow implements TransactionalFlow {
|
|||
DomainResource existingDomain = loadAndVerifyExistence(DomainResource.class, targetId, now);
|
||||
FeesAndCredits feesAndCredits =
|
||||
pricingLogic.getRestorePrice(Registry.get(existingDomain.getTld()), targetId, now);
|
||||
FeeUpdateCommandExtension feeUpdate =
|
||||
Optional<FeeUpdateCommandExtension> feeUpdate =
|
||||
eppInput.getSingleExtension(FeeUpdateCommandExtension.class);
|
||||
verifyRestoreAllowed(command, existingDomain, feeUpdate, feesAndCredits, now);
|
||||
HistoryEntry historyEntry = buildHistoryEntry(existingDomain, now);
|
||||
|
@ -186,7 +186,7 @@ public final class DomainRestoreRequestFlow implements TransactionalFlow {
|
|||
private void verifyRestoreAllowed(
|
||||
Update command,
|
||||
DomainResource existingDomain,
|
||||
FeeUpdateCommandExtension feeUpdate,
|
||||
Optional<FeeUpdateCommandExtension> feeUpdate,
|
||||
FeesAndCredits feesAndCredits,
|
||||
DateTime now) throws EppException {
|
||||
verifyOptionalAuthInfo(authInfo, existingDomain);
|
||||
|
@ -261,15 +261,19 @@ public final class DomainRestoreRequestFlow implements TransactionalFlow {
|
|||
}
|
||||
|
||||
private static ImmutableList<FeeTransformResponseExtension> createResponseExtensions(
|
||||
Money restoreCost, Money renewCost, FeeUpdateCommandExtension feeUpdate) {
|
||||
return (feeUpdate == null)
|
||||
? ImmutableList.of()
|
||||
: ImmutableList.of(feeUpdate.createResponseBuilder()
|
||||
Money restoreCost, Money renewCost, Optional<FeeUpdateCommandExtension> feeUpdate) {
|
||||
return feeUpdate.isPresent()
|
||||
? ImmutableList.of(
|
||||
feeUpdate
|
||||
.get()
|
||||
.createResponseBuilder()
|
||||
.setCurrency(restoreCost.getCurrencyUnit())
|
||||
.setFees(ImmutableList.of(
|
||||
.setFees(
|
||||
ImmutableList.of(
|
||||
Fee.create(restoreCost.getAmount(), FeeType.RESTORE),
|
||||
Fee.create(renewCost.getAmount(), FeeType.RENEW)))
|
||||
.build());
|
||||
.build())
|
||||
: ImmutableList.of();
|
||||
}
|
||||
|
||||
/** Restore command cannot have other changes specified. */
|
||||
|
|
|
@ -139,19 +139,19 @@ public final class DomainTransferRequestFlow implements TransactionalFlow {
|
|||
validateClientIsLoggedIn(gainingClientId);
|
||||
DateTime now = ofy().getTransactionTime();
|
||||
DomainResource existingDomain = loadAndVerifyExistence(DomainResource.class, targetId, now);
|
||||
DomainTransferRequestSuperuserExtension superuserExtension =
|
||||
Optional<DomainTransferRequestSuperuserExtension> superuserExtension =
|
||||
eppInput.getSingleExtension(DomainTransferRequestSuperuserExtension.class);
|
||||
Period period =
|
||||
(superuserExtension == null)
|
||||
? ((Transfer) resourceCommand).getPeriod()
|
||||
: superuserExtension.getRenewalPeriod();
|
||||
superuserExtension.isPresent()
|
||||
? superuserExtension.get().getRenewalPeriod()
|
||||
: ((Transfer) resourceCommand).getPeriod();
|
||||
verifyTransferAllowed(existingDomain, period, now, superuserExtension);
|
||||
String tld = existingDomain.getTld();
|
||||
Registry registry = Registry.get(tld);
|
||||
// An optional extension from the client specifying what they think the transfer should cost.
|
||||
FeeTransferCommandExtension feeTransfer =
|
||||
Optional<FeeTransferCommandExtension> feeTransfer =
|
||||
eppInput.getSingleExtension(FeeTransferCommandExtension.class);
|
||||
if (period.getValue() == 0 && feeTransfer != null) {
|
||||
if (period.getValue() == 0 && feeTransfer.isPresent()) {
|
||||
// If the period is zero, then there is no transfer billing event, so using the fee transfer
|
||||
// extension does not make sense.
|
||||
throw new TransferPeriodZeroAndFeeTransferExtensionException();
|
||||
|
@ -166,9 +166,9 @@ public final class DomainTransferRequestFlow implements TransactionalFlow {
|
|||
}
|
||||
HistoryEntry historyEntry = buildHistoryEntry(existingDomain, registry, now, period);
|
||||
DateTime automaticTransferTime =
|
||||
(superuserExtension == null)
|
||||
? now.plus(registry.getAutomaticTransferLength())
|
||||
: now.plusDays(superuserExtension.getAutomaticTransferLength());
|
||||
superuserExtension.isPresent()
|
||||
? now.plusDays(superuserExtension.get().getAutomaticTransferLength())
|
||||
: now.plus(registry.getAutomaticTransferLength());
|
||||
// If the domain will be in the auto-renew grace period at the moment of transfer, the transfer
|
||||
// will subsume the autorenew, so we don't add the normal extra year from the transfer.
|
||||
// The gaining registrar is still billed for the extra year; the losing registrar will get a
|
||||
|
@ -241,7 +241,7 @@ public final class DomainTransferRequestFlow implements TransactionalFlow {
|
|||
DomainResource existingDomain,
|
||||
Period period,
|
||||
DateTime now,
|
||||
final DomainTransferRequestSuperuserExtension superuserExtension)
|
||||
Optional<DomainTransferRequestSuperuserExtension> superuserExtension)
|
||||
throws EppException {
|
||||
verifyNoDisallowedStatuses(existingDomain, DISALLOWED_STATUSES);
|
||||
verifyAuthInfoPresentForResourceTransfer(authInfo);
|
||||
|
@ -283,19 +283,19 @@ public final class DomainTransferRequestFlow implements TransactionalFlow {
|
|||
* will simply default to one year.
|
||||
*/
|
||||
private static void verifyTransferPeriod(
|
||||
Period period, DomainTransferRequestSuperuserExtension superuserExtension)
|
||||
Period period, Optional<DomainTransferRequestSuperuserExtension> superuserExtension)
|
||||
throws EppException {
|
||||
verifyUnitIsYears(period);
|
||||
if (superuserExtension == null) {
|
||||
// If the superuser extension is not being used, then the period can only be one.
|
||||
if (period.getValue() != 1) {
|
||||
throw new TransferPeriodMustBeOneYearException();
|
||||
}
|
||||
} else {
|
||||
if (superuserExtension.isPresent()) {
|
||||
// If the superuser extension is being used, then the period can be one or zero.
|
||||
if (period.getValue() != 1 && period.getValue() != 0) {
|
||||
throw new InvalidTransferPeriodValueException();
|
||||
}
|
||||
} else {
|
||||
// If the superuser extension is not being used, then the period can only be one.
|
||||
if (period.getValue() != 1) {
|
||||
throw new TransferPeriodMustBeOneYearException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,13 +332,16 @@ public final class DomainTransferRequestFlow implements TransactionalFlow {
|
|||
}
|
||||
|
||||
private static ImmutableList<FeeTransformResponseExtension> createResponseExtensions(
|
||||
Optional<FeesAndCredits> feesAndCredits, FeeTransferCommandExtension feeTransfer) {
|
||||
return (feeTransfer == null || !feesAndCredits.isPresent())
|
||||
? ImmutableList.of()
|
||||
: ImmutableList.of(feeTransfer.createResponseBuilder()
|
||||
Optional<FeesAndCredits> feesAndCredits, Optional<FeeTransferCommandExtension> feeTransfer) {
|
||||
return (feeTransfer.isPresent() && feesAndCredits.isPresent())
|
||||
? ImmutableList.of(
|
||||
feeTransfer
|
||||
.get()
|
||||
.createResponseBuilder()
|
||||
.setFees(feesAndCredits.get().getFees())
|
||||
.setCredits(feesAndCredits.get().getCredits())
|
||||
.setCurrency(feesAndCredits.get().getCurrency())
|
||||
.build());
|
||||
.build())
|
||||
: ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,6 @@ import google.registry.model.domain.DomainCommand.Update.AddRemove;
|
|||
import google.registry.model.domain.DomainCommand.Update.Change;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
import google.registry.model.domain.GracePeriod;
|
||||
import google.registry.model.domain.fee.FeeTransformCommandExtension;
|
||||
import google.registry.model.domain.fee.FeeUpdateCommandExtension;
|
||||
import google.registry.model.domain.metadata.MetadataExtension;
|
||||
import google.registry.model.domain.rgp.GracePeriodStatus;
|
||||
|
@ -222,13 +221,13 @@ public final class DomainUpdateFlow implements TransactionalFlow {
|
|||
checkAllowedAccessToTld(clientId, tld);
|
||||
}
|
||||
Registry registry = Registry.get(tld);
|
||||
FeeTransformCommandExtension feeUpdate =
|
||||
Optional<FeeUpdateCommandExtension> feeUpdate =
|
||||
eppInput.getSingleExtension(FeeUpdateCommandExtension.class);
|
||||
// If the fee extension is present, validate it (even if the cost is zero, to check for price
|
||||
// mismatches). Don't rely on the the validateFeeChallenge check for feeUpdate nullness, because
|
||||
// it throws an error if the name is premium, and we don't want to do that here.
|
||||
FeesAndCredits feesAndCredits = pricingLogic.getUpdatePrice(registry, targetId, now);
|
||||
if (feeUpdate != null) {
|
||||
if (feeUpdate.isPresent()) {
|
||||
validateFeeChallenge(targetId, existingDomain.getTld(), now, feeUpdate, feesAndCredits);
|
||||
} else if (!feesAndCredits.getTotalCost().isZero()) {
|
||||
// If it's not present but the cost is not zero, throw an exception.
|
||||
|
@ -268,14 +267,15 @@ public final class DomainUpdateFlow implements TransactionalFlow {
|
|||
checkSameValuesNotAddedAndRemoved(add.getContacts(), remove.getContacts());
|
||||
checkSameValuesNotAddedAndRemoved(add.getStatusValues(), remove.getStatusValues());
|
||||
Change change = command.getInnerChange();
|
||||
SecDnsUpdateExtension secDnsUpdate = eppInput.getSingleExtension(SecDnsUpdateExtension.class);
|
||||
Optional<SecDnsUpdateExtension> secDnsUpdate =
|
||||
eppInput.getSingleExtension(SecDnsUpdateExtension.class);
|
||||
DomainResource.Builder domainBuilder =
|
||||
domain
|
||||
.asBuilder()
|
||||
// Handle the secDNS extension.
|
||||
.setDsData(
|
||||
secDnsUpdate != null
|
||||
? updateDsData(domain.getDsData(), secDnsUpdate)
|
||||
secDnsUpdate.isPresent()
|
||||
? updateDsData(domain.getDsData(), secDnsUpdate.get())
|
||||
: domain.getDsData())
|
||||
.setLastEppUpdateTime(now)
|
||||
.setLastEppUpdateClientId(clientId)
|
||||
|
@ -355,8 +355,9 @@ public final class DomainUpdateFlow implements TransactionalFlow {
|
|||
DomainResource newDomain,
|
||||
HistoryEntry historyEntry,
|
||||
DateTime now) {
|
||||
MetadataExtension metadataExtension = eppInput.getSingleExtension(MetadataExtension.class);
|
||||
if (metadataExtension != null && metadataExtension.getRequestedByRegistrar()) {
|
||||
Optional<MetadataExtension> metadataExtension =
|
||||
eppInput.getSingleExtension(MetadataExtension.class);
|
||||
if (metadataExtension.isPresent() && metadataExtension.get().getRequestedByRegistrar()) {
|
||||
for (StatusValue statusValue
|
||||
: symmetricDifference(existingDomain.getStatusValues(), newDomain.getStatusValues())) {
|
||||
if (statusValue.isChargedStatus()) {
|
||||
|
|
|
@ -85,6 +85,7 @@ import google.registry.model.eppinput.EppInput.Transfer.TransferOp;
|
|||
import google.registry.model.eppinput.ResourceCommand;
|
||||
import google.registry.model.host.HostCommand;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/** Class that picks a flow to handle a given EPP command. */
|
||||
|
@ -163,12 +164,13 @@ public class FlowPicker {
|
|||
if (!(resourceCommand instanceof DomainCommand.Update)) {
|
||||
return null;
|
||||
}
|
||||
RgpUpdateExtension rgpUpdateExtension = eppInput.getSingleExtension(RgpUpdateExtension.class);
|
||||
if (rgpUpdateExtension == null) {
|
||||
Optional<RgpUpdateExtension> rgpUpdateExtension =
|
||||
eppInput.getSingleExtension(RgpUpdateExtension.class);
|
||||
if (!rgpUpdateExtension.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
// Restore command with an op of "report" is not currently supported.
|
||||
return (rgpUpdateExtension.getRestoreCommand().getRestoreOp() == RestoreOp.REQUEST)
|
||||
return (rgpUpdateExtension.get().getRestoreCommand().getRestoreOp() == RestoreOp.REQUEST)
|
||||
? DomainRestoreRequestFlow.class
|
||||
: UnimplementedFlow.class;
|
||||
}};
|
||||
|
@ -177,24 +179,29 @@ public class FlowPicker {
|
|||
* The claims check flow is keyed on the type of the {@link ResourceCommand} and on having the
|
||||
* correct extension with a specific phase value.
|
||||
*/
|
||||
private static final FlowProvider DOMAIN_CHECK_FLOW_PROVIDER = new FlowProvider() {
|
||||
private static final FlowProvider DOMAIN_CHECK_FLOW_PROVIDER =
|
||||
new FlowProvider() {
|
||||
@Override
|
||||
Class<? extends Flow> get(
|
||||
EppInput eppInput, InnerCommand innerCommand, ResourceCommand resourceCommand) {
|
||||
if (!(resourceCommand instanceof DomainCommand.Check)) {
|
||||
return null;
|
||||
}
|
||||
LaunchCheckExtension extension = eppInput.getSingleExtension(LaunchCheckExtension.class);
|
||||
if (extension == null || CheckType.AVAILABILITY.equals(extension.getCheckType())) {
|
||||
// We don't distinguish between registry phases for "avail", so don't bother checking phase.
|
||||
Optional<LaunchCheckExtension> launchCheck =
|
||||
eppInput.getSingleExtension(LaunchCheckExtension.class);
|
||||
if (!launchCheck.isPresent()
|
||||
|| CheckType.AVAILABILITY.equals(launchCheck.get().getCheckType())) {
|
||||
// We don't distinguish between registry phases for "avail", so don't bother checking
|
||||
// phase.
|
||||
return DomainCheckFlow.class;
|
||||
}
|
||||
if (CheckType.CLAIMS.equals(extension.getCheckType())
|
||||
&& LaunchPhase.CLAIMS.equals(extension.getPhase())) {
|
||||
if (CheckType.CLAIMS.equals(launchCheck.get().getCheckType())
|
||||
&& LaunchPhase.CLAIMS.equals(launchCheck.get().getPhase())) {
|
||||
return DomainClaimsCheckFlow.class;
|
||||
}
|
||||
return null;
|
||||
}};
|
||||
}
|
||||
};
|
||||
|
||||
/** General resource CRUD flows are keyed on the type of their {@link ResourceCommand}. */
|
||||
private static final FlowProvider RESOURCE_CRUD_FLOW_PROVIDER = new FlowProvider() {
|
||||
|
@ -224,50 +231,57 @@ public class FlowPicker {
|
|||
}};
|
||||
|
||||
/** The domain allocate flow has a specific extension. */
|
||||
private static final FlowProvider ALLOCATE_FLOW_PROVIDER = new FlowProvider() {
|
||||
private static final FlowProvider ALLOCATE_FLOW_PROVIDER =
|
||||
new FlowProvider() {
|
||||
@Override
|
||||
Class<? extends Flow> get(
|
||||
EppInput eppInput, InnerCommand innerCommand, ResourceCommand resourceCommand) {
|
||||
return (resourceCommand instanceof DomainCommand.Create
|
||||
&& eppInput.getSingleExtension(AllocateCreateExtension.class) != null)
|
||||
? DomainAllocateFlow.class : null;
|
||||
}};
|
||||
&& eppInput.getSingleExtension(AllocateCreateExtension.class).isPresent())
|
||||
? DomainAllocateFlow.class
|
||||
: null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Application CRUD flows have an extension and are keyed on the type of their
|
||||
* {@link ResourceCommand}.
|
||||
* Application CRUD flows have an extension and are keyed on the type of their {@link
|
||||
* ResourceCommand}.
|
||||
*/
|
||||
private static final FlowProvider APPLICATION_CRUD_FLOW_PROVIDER = new FlowProvider() {
|
||||
private static final FlowProvider APPLICATION_CRUD_FLOW_PROVIDER =
|
||||
new FlowProvider() {
|
||||
|
||||
private final Map<Class<? extends ResourceCommand>, Class<? extends Flow>> applicationFlows =
|
||||
private final Map<Class<? extends ResourceCommand>, Class<? extends Flow>>
|
||||
applicationFlows =
|
||||
ImmutableMap.of(
|
||||
DomainCommand.Create.class, DomainApplicationCreateFlow.class,
|
||||
DomainCommand.Delete.class, DomainApplicationDeleteFlow.class,
|
||||
DomainCommand.Info.class, DomainApplicationInfoFlow.class,
|
||||
DomainCommand.Update.class, DomainApplicationUpdateFlow.class);
|
||||
|
||||
private final Set<LaunchPhase> launchPhases = ImmutableSet.of(
|
||||
LaunchPhase.SUNRISE, LaunchPhase.SUNRUSH, LaunchPhase.LANDRUSH);
|
||||
private final Set<LaunchPhase> launchPhases =
|
||||
ImmutableSet.of(LaunchPhase.SUNRISE, LaunchPhase.SUNRUSH, LaunchPhase.LANDRUSH);
|
||||
|
||||
@Override
|
||||
Class<? extends Flow> get(
|
||||
EppInput eppInput, InnerCommand innerCommand, ResourceCommand resourceCommand) {
|
||||
if (eppInput.getSingleExtension(ApplicationIdTargetExtension.class) != null) {
|
||||
if (eppInput.getSingleExtension(ApplicationIdTargetExtension.class).isPresent()) {
|
||||
return applicationFlows.get(resourceCommand.getClass());
|
||||
}
|
||||
LaunchCreateExtension createExtension =
|
||||
Optional<LaunchCreateExtension> createExtension =
|
||||
eppInput.getSingleExtension(LaunchCreateExtension.class);
|
||||
// Return a flow if the type is APPLICATION, or if it's null and we are in a launch phase.
|
||||
// If the type is specified as REGISTRATION, return null.
|
||||
if (createExtension != null) {
|
||||
LaunchPhase launchPhase = createExtension.getPhase();
|
||||
if (APPLICATION.equals(createExtension.getCreateType())
|
||||
|| (createExtension.getCreateType() == null && launchPhases.contains(launchPhase))) {
|
||||
if (createExtension.isPresent()) {
|
||||
LaunchPhase launchPhase = createExtension.get().getPhase();
|
||||
if (APPLICATION.equals(createExtension.get().getCreateType())
|
||||
|| (createExtension.get().getCreateType() == null
|
||||
&& launchPhases.contains(launchPhase))) {
|
||||
return applicationFlows.get(resourceCommand.getClass());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}};
|
||||
}
|
||||
};
|
||||
|
||||
/** Transfer flows have an {@link InnerCommand} of type {@link Transfer}. */
|
||||
private static final FlowProvider TRANSFER_FLOW_PROVIDER = new FlowProvider() {
|
||||
|
|
|
@ -151,15 +151,15 @@ public class EppInput extends ImmutableObject {
|
|||
}
|
||||
|
||||
/** Get the extension based on type, or null. If there are multiple, it chooses the first. */
|
||||
@Nullable
|
||||
public <E extends CommandExtension> E getSingleExtension(Class<E> clazz) {
|
||||
return getCommandWrapper()
|
||||
public <E extends CommandExtension> Optional<E> getSingleExtension(Class<E> clazz) {
|
||||
return Optional.ofNullable(
|
||||
getCommandWrapper()
|
||||
.getExtensions()
|
||||
.stream()
|
||||
.filter(clazz::isInstance)
|
||||
.map(clazz::cast)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
.orElse(null));
|
||||
}
|
||||
|
||||
/** A tag that goes inside of an EPP {@literal <command>}. */
|
||||
|
|
|
@ -105,20 +105,20 @@ public class VerifyOteAction implements Runnable, JsonAction {
|
|||
|
||||
private static final Predicate<EppInput> HAS_CLAIMS_NOTICE =
|
||||
eppInput -> {
|
||||
LaunchCreateExtension launchCreate =
|
||||
Optional<LaunchCreateExtension> launchCreate =
|
||||
eppInput.getSingleExtension(LaunchCreateExtension.class);
|
||||
return launchCreate != null && launchCreate.getNotice() != null;
|
||||
return launchCreate.isPresent() && launchCreate.get().getNotice() != null;
|
||||
};
|
||||
|
||||
private static final Predicate<EppInput> HAS_SEC_DNS =
|
||||
eppInput ->
|
||||
(eppInput.getSingleExtension(SecDnsCreateExtension.class) != null)
|
||||
|| (eppInput.getSingleExtension(SecDnsUpdateExtension.class) != null);
|
||||
(eppInput.getSingleExtension(SecDnsCreateExtension.class).isPresent())
|
||||
|| (eppInput.getSingleExtension(SecDnsUpdateExtension.class).isPresent());
|
||||
private static final Predicate<EppInput> IS_SUNRISE =
|
||||
eppInput -> {
|
||||
LaunchCreateExtension launchCreate =
|
||||
Optional<LaunchCreateExtension> launchCreate =
|
||||
eppInput.getSingleExtension(LaunchCreateExtension.class);
|
||||
return launchCreate != null && !isNullOrEmpty(launchCreate.getSignedMarks());
|
||||
return launchCreate.isPresent() && !isNullOrEmpty(launchCreate.get().getSignedMarks());
|
||||
};
|
||||
|
||||
private static final Predicate<EppInput> IS_IDN =
|
||||
|
@ -158,7 +158,7 @@ public class VerifyOteAction implements Runnable, JsonAction {
|
|||
DOMAIN_CREATES_WITH_FEE(
|
||||
1,
|
||||
equalTo(Type.DOMAIN_CREATE),
|
||||
eppInput -> eppInput.getSingleExtension(FeeCreateCommandExtension.class) != null),
|
||||
eppInput -> eppInput.getSingleExtension(FeeCreateCommandExtension.class).isPresent()),
|
||||
DOMAIN_CREATES_WITH_SEC_DNS(1, equalTo(Type.DOMAIN_CREATE), HAS_SEC_DNS),
|
||||
DOMAIN_CREATES_WITHOUT_SEC_DNS(0, equalTo(Type.DOMAIN_CREATE), HAS_SEC_DNS.negate()),
|
||||
DOMAIN_DELETES(2, equalTo(Type.DOMAIN_DELETE)),
|
||||
|
|
|
@ -43,6 +43,7 @@ import google.registry.model.tmch.ClaimsListShard.ClaimsListRevision;
|
|||
import google.registry.model.tmch.ClaimsListShard.ClaimsListSingleton;
|
||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||
import google.registry.util.TypeUtils.TypeInstantiator;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.joda.time.DateTime;
|
||||
|
@ -106,9 +107,11 @@ public abstract class ResourceFlowTestCase<F extends Flow, R extends EppResource
|
|||
* the test code rather than the production code.
|
||||
*/
|
||||
protected String getUniqueIdFromCommand() throws Exception {
|
||||
ApplicationIdTargetExtension extension =
|
||||
Optional<ApplicationIdTargetExtension> extension =
|
||||
eppLoader.getEpp().getSingleExtension(ApplicationIdTargetExtension.class);
|
||||
return extension == null ? getResourceCommand().getTargetId() : extension.getApplicationId();
|
||||
return extension.isPresent()
|
||||
? extension.get().getApplicationId()
|
||||
: getResourceCommand().getTargetId();
|
||||
}
|
||||
|
||||
protected Class<R> getResourceClass() {
|
||||
|
|
|
@ -122,6 +122,7 @@ public class DomainApplicationInfoFlowTest
|
|||
new EppLoader(this, "domain_create_sunrise_encoded_signed_mark.xml")
|
||||
.getEpp()
|
||||
.getSingleExtension(LaunchCreateExtension.class)
|
||||
.get()
|
||||
.getSignedMarks()
|
||||
.get(0))
|
||||
: null)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue