diff --git a/java/google/registry/flows/FlowModule.java b/java/google/registry/flows/FlowModule.java index 740e5eb5f..ac16c18fe 100644 --- a/java/google/registry/flows/FlowModule.java +++ b/java/google/registry/flows/FlowModule.java @@ -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 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() - .setTrid(trid) - .setXmlBytes(inputXmlBytes) - .setBySuperuser(isSuperuser) - .setClientId(clientId); - MetadataExtension metadataExtension = eppInput.getSingleExtension(MetadataExtension.class); - if (metadataExtension != null) { + HistoryEntry.Builder historyBuilder = + new HistoryEntry.Builder() + .setTrid(trid) + .setXmlBytes(inputXmlBytes) + .setBySuperuser(isSuperuser) + .setClientId(clientId); + Optional 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; } diff --git a/java/google/registry/flows/domain/DomainAllocateFlow.java b/java/google/registry/flows/domain/DomainAllocateFlow.java index 5f38ca562..e44b6e2d9 100644 --- a/java/google/registry/flows/domain/DomainAllocateFlow.java +++ b/java/google/registry/flows/domain/DomainAllocateFlow.java @@ -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 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,31 +167,37 @@ 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() - .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))) - .setApplicationTime(allocateCreate.getApplicationTime()) - .setApplication(Key.create(application)) - .setSmdId(allocateCreate.getSmdId()) - .setLaunchNotice(allocateCreate.getNotice()) - .setDsData(secDnsCreate == null ? application.getDsData() : secDnsCreate.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) - ? ImmutableSet.of(StatusValue.SERVER_HOLD) - : ImmutableSet.of()) - .setRegistrant(command.getRegistrant()) - .setAuthInfo(command.getAuthInfo()) - .setFullyQualifiedDomainName(targetId) - .setNameservers(command.getNameservers()) - .setContacts(command.getContacts()) - .build(); + 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))) + .setApplicationTime(allocateCreate.getApplicationTime()) + .setApplication(Key.create(application)) + .setSmdId(allocateCreate.getSmdId()) + .setLaunchNotice(allocateCreate.getNotice()) + .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) + ? ImmutableSet.of(StatusValue.SERVER_HOLD) + : ImmutableSet.of()) + .setRegistrant(command.getRegistrant()) + .setAuthInfo(command.getAuthInfo()) + .setFullyQualifiedDomainName(targetId) + .setNameservers(command.getNameservers()) + .setContacts(command.getContacts()) + .build(); entitiesToSave.add( newDomain, buildApplicationHistory(application, now), @@ -402,11 +409,11 @@ public class DomainAllocateFlow implements TransactionalFlow { private ImmutableList createResponseExtensions( DateTime now, Registry registry, int years) throws EppException { FeesAndCredits feesAndCredits = pricingLogic.getCreatePrice(registry, targetId, now, years); - FeeCreateCommandExtension feeCreate = + Optional 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. */ diff --git a/java/google/registry/flows/domain/DomainApplicationCreateFlow.java b/java/google/registry/flows/domain/DomainApplicationCreateFlow.java index 858822694..3acdfb240 100644 --- a/java/google/registry/flows/domain/DomainApplicationCreateFlow.java +++ b/java/google/registry/flows/domain/DomainApplicationCreateFlow.java @@ -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) { - validateLaunchCreateExtension(launchCreate, registry, domainName, now); - } + 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 feeCreate = eppInput.getSingleExtension(FeeCreateCommandExtension.class); validateFeeChallenge(targetId, tld, now, feeCreate, feesAndCredits); - SecDnsCreateExtension secDnsCreate = + Optional 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 createResponseExtensions( String applicationId, LaunchPhase launchPhase, - FeeTransformCommandExtension feeCreate, + Optional feeCreate, FeesAndCredits feesAndCredits) { ImmutableList.Builder 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(); } diff --git a/java/google/registry/flows/domain/DomainApplicationDeleteFlow.java b/java/google/registry/flows/domain/DomainApplicationDeleteFlow.java index 9e0c91e1d..8ceb81209 100644 --- a/java/google/registry/flows/domain/DomainApplicationDeleteFlow.java +++ b/java/google/registry/flows/domain/DomainApplicationDeleteFlow.java @@ -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) diff --git a/java/google/registry/flows/domain/DomainApplicationInfoFlow.java b/java/google/registry/flows/domain/DomainApplicationInfoFlow.java index bc48d0c7f..841a0156e 100644 --- a/java/google/registry/flows/domain/DomainApplicationInfoFlow.java +++ b/java/google/registry/flows/domain/DomainApplicationInfoFlow.java @@ -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(); } diff --git a/java/google/registry/flows/domain/DomainApplicationUpdateFlow.java b/java/google/registry/flows/domain/DomainApplicationUpdateFlow.java index f2e7e220b..a321b7cd4 100644 --- a/java/google/registry/flows/domain/DomainApplicationUpdateFlow.java +++ b/java/google/registry/flows/domain/DomainApplicationUpdateFlow.java @@ -189,12 +189,12 @@ public class DomainApplicationUpdateFlow implements TransactionalFlow { Registry registry = Registry.get(tld); FeesAndCredits feesAndCredits = pricingLogic.getApplicationUpdatePrice(registry, existingApplication, now); - FeeUpdateCommandExtension feeUpdate = + Optional 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 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) diff --git a/java/google/registry/flows/domain/DomainCheckFlow.java b/java/google/registry/flows/domain/DomainCheckFlow.java index f0e18881a..1647c8f38 100644 --- a/java/google/registry/flows/domain/DomainCheckFlow.java +++ b/java/google/registry/flows/domain/DomainCheckFlow.java @@ -151,13 +151,13 @@ public final class DomainCheckFlow implements Flow { .setAsOfDate(now) .build()); Set existingIds = checkResourcesExist(DomainResource.class, targetIds, now); - AllocationTokenExtension allocationTokenExtension = + Optional allocationTokenExtension = eppInput.getSingleExtension(AllocationTokenExtension.class); ImmutableMap tokenCheckResults = - (allocationTokenExtension == null) - ? ImmutableMap.of() - : checkDomainsWithToken( - targetIds, allocationTokenExtension.getAllocationToken(), clientId); + allocationTokenExtension.isPresent() + ? checkDomainsWithToken( + targetIds, allocationTokenExtension.get().getAllocationToken(), clientId) + : ImmutableMap.of(); ImmutableList.Builder checks = new ImmutableList.Builder<>(); for (String targetId : targetIds) { Optional 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 getResponseExtensions( ImmutableMap domainNames, DateTime now) throws EppException { - FeeCheckCommandExtension feeCheck = + Optional 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 responseItems = new ImmutableList.Builder<>(); for (FeeCheckCommandExtensionItem feeCheckItem : feeCheck.getItems()) { diff --git a/java/google/registry/flows/domain/DomainClaimsCheckFlow.java b/java/google/registry/flows/domain/DomainClaimsCheckFlow.java index 171dc07d2..959290033 100644 --- a/java/google/registry/flows/domain/DomainClaimsCheckFlow.java +++ b/java/google/registry/flows/domain/DomainClaimsCheckFlow.java @@ -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 targetIds = ((Check) resourceCommand).getTargetIds(); diff --git a/java/google/registry/flows/domain/DomainCreateFlow.java b/java/google/registry/flows/domain/DomainCreateFlow.java index 9c4a74c14..90f281702 100644 --- a/java/google/registry/flows/domain/DomainCreateFlow.java +++ b/java/google/registry/flows/domain/DomainCreateFlow.java @@ -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 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 = @@ -264,11 +268,11 @@ public class DomainCreateFlow implements TransactionalFlow { .setYears(years) .setSignedMarkId(Optional.ofNullable(signedMarkId)) .build()); - FeeCreateCommandExtension feeCreate = + Optional feeCreate = eppInput.getSingleExtension(FeeCreateCommandExtension.class); FeesAndCredits feesAndCredits = pricingLogic.getCreatePrice(registry, targetId, now, years); validateFeeChallenge(targetId, registry.getTldStr(), now, feeCreate, feesAndCredits); - SecDnsCreateExtension secDnsCreate = + Optional 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 = + 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 verifyAllocationTokenIfPresent( InternetDomainName domainName, Registry registry, String clientId) throws EppException { - AllocationTokenExtension ext = eppInput.getSingleExtension(AllocationTokenExtension.class); + Optional 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 createResponseExtensions( - FeeCreateCommandExtension feeCreate, FeesAndCredits feesAndCredits) { - return (feeCreate == null) - ? ImmutableList.of() - : ImmutableList.of(createFeeCreateResponse(feeCreate, feesAndCredits)); + Optional feeCreate, FeesAndCredits feesAndCredits) { + return feeCreate.isPresent() + ? ImmutableList.of(createFeeCreateResponse(feeCreate.get(), feesAndCredits)) + : ImmutableList.of(); } /** There is an open application for this domain. */ diff --git a/java/google/registry/flows/domain/DomainDeleteFlow.java b/java/google/registry/flows/domain/DomainDeleteFlow.java index 659989aa7..1de464048 100644 --- a/java/google/registry/flows/domain/DomainDeleteFlow.java +++ b/java/google/registry/flows/domain/DomainDeleteFlow.java @@ -155,13 +155,14 @@ public final class DomainDeleteFlow implements TransactionalFlow { } Duration redemptionGracePeriodLength = registry.getRedemptionGracePeriodLength(); Duration pendingDeleteLength = registry.getPendingDeleteLength(); - DomainDeleteSuperuserExtension domainDeleteSuperuserExtension = + Optional 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); diff --git a/java/google/registry/flows/domain/DomainFlowUtils.java b/java/google/registry/flows/domain/DomainFlowUtils.java index 67b1077f1..6a0113f27 100644 --- a/java/google/registry/flows/domain/DomainFlowUtils.java +++ b/java/google/registry/flows/domain/DomainFlowUtils.java @@ -617,20 +617,20 @@ public class DomainFlowUtils { String domainName, String tld, DateTime priceTime, - final FeeTransformCommandExtension feeCommand, + final Optional 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 fees = feeCommand.getFees(); + List 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 validateSecDnsExtension( + Optional 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; } diff --git a/java/google/registry/flows/domain/DomainInfoFlow.java b/java/google/registry/flows/domain/DomainInfoFlow.java index 5fcdfbeac..03450898d 100644 --- a/java/google/registry/flows/domain/DomainInfoFlow.java +++ b/java/google/registry/flows/domain/DomainInfoFlow.java @@ -151,12 +151,12 @@ public final class DomainInfoFlow implements Flow { if (!gracePeriodStatuses.isEmpty()) { extensions.add(RgpInfoExtension.create(gracePeriodStatuses)); } - FeeInfoCommandExtensionV06 feeInfo = + Optional 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, diff --git a/java/google/registry/flows/domain/DomainRenewFlow.java b/java/google/registry/flows/domain/DomainRenewFlow.java index b7fdfee20..d692a94c1 100644 --- a/java/google/registry/flows/domain/DomainRenewFlow.java +++ b/java/google/registry/flows/domain/DomainRenewFlow.java @@ -142,7 +142,7 @@ public final class DomainRenewFlow implements TransactionalFlow { DateTime newExpirationTime = leapSafeAddYears(existingDomain.getRegistrationExpirationTime(), years); // Uncapped validateRegistrationPeriod(now, newExpirationTime); - FeeRenewCommandExtension feeRenew = + Optional 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 createResponseExtensions( - Money renewCost, FeeRenewCommandExtension feeRenew) { - return (feeRenew == null) - ? ImmutableList.of() - : ImmutableList.of(feeRenew.createResponseBuilder() - .setCurrency(renewCost.getCurrencyUnit()) - .setFees(ImmutableList.of(Fee.create(renewCost.getAmount(), FeeType.RENEW))) - .build()); + Money renewCost, Optional feeRenew) { + return feeRenew.isPresent() + ? ImmutableList.of( + feeRenew + .get() + .createResponseBuilder() + .setCurrency(renewCost.getCurrencyUnit()) + .setFees(ImmutableList.of(Fee.create(renewCost.getAmount(), FeeType.RENEW))) + .build()) + : ImmutableList.of(); } /** The current expiration date is incorrect. */ diff --git a/java/google/registry/flows/domain/DomainRestoreRequestFlow.java b/java/google/registry/flows/domain/DomainRestoreRequestFlow.java index a815c4882..4b240ee6d 100644 --- a/java/google/registry/flows/domain/DomainRestoreRequestFlow.java +++ b/java/google/registry/flows/domain/DomainRestoreRequestFlow.java @@ -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 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 feeUpdate, FeesAndCredits feesAndCredits, DateTime now) throws EppException { verifyOptionalAuthInfo(authInfo, existingDomain); @@ -261,15 +261,19 @@ public final class DomainRestoreRequestFlow implements TransactionalFlow { } private static ImmutableList createResponseExtensions( - Money restoreCost, Money renewCost, FeeUpdateCommandExtension feeUpdate) { - return (feeUpdate == null) - ? ImmutableList.of() - : ImmutableList.of(feeUpdate.createResponseBuilder() - .setCurrency(restoreCost.getCurrencyUnit()) - .setFees(ImmutableList.of( - Fee.create(restoreCost.getAmount(), FeeType.RESTORE), - Fee.create(renewCost.getAmount(), FeeType.RENEW))) - .build()); + Money restoreCost, Money renewCost, Optional feeUpdate) { + return feeUpdate.isPresent() + ? ImmutableList.of( + feeUpdate + .get() + .createResponseBuilder() + .setCurrency(restoreCost.getCurrencyUnit()) + .setFees( + ImmutableList.of( + Fee.create(restoreCost.getAmount(), FeeType.RESTORE), + Fee.create(renewCost.getAmount(), FeeType.RENEW))) + .build()) + : ImmutableList.of(); } /** Restore command cannot have other changes specified. */ diff --git a/java/google/registry/flows/domain/DomainTransferRequestFlow.java b/java/google/registry/flows/domain/DomainTransferRequestFlow.java index 389df2e7e..0293f825f 100644 --- a/java/google/registry/flows/domain/DomainTransferRequestFlow.java +++ b/java/google/registry/flows/domain/DomainTransferRequestFlow.java @@ -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 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 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 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 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 createResponseExtensions( - Optional feesAndCredits, FeeTransferCommandExtension feeTransfer) { - return (feeTransfer == null || !feesAndCredits.isPresent()) - ? ImmutableList.of() - : ImmutableList.of(feeTransfer.createResponseBuilder() - .setFees(feesAndCredits.get().getFees()) - .setCredits(feesAndCredits.get().getCredits()) - .setCurrency(feesAndCredits.get().getCurrency()) - .build()); + Optional feesAndCredits, Optional feeTransfer) { + return (feeTransfer.isPresent() && feesAndCredits.isPresent()) + ? ImmutableList.of( + feeTransfer + .get() + .createResponseBuilder() + .setFees(feesAndCredits.get().getFees()) + .setCredits(feesAndCredits.get().getCredits()) + .setCurrency(feesAndCredits.get().getCurrency()) + .build()) + : ImmutableList.of(); } } diff --git a/java/google/registry/flows/domain/DomainUpdateFlow.java b/java/google/registry/flows/domain/DomainUpdateFlow.java index 3e418a8fd..092e3e812 100644 --- a/java/google/registry/flows/domain/DomainUpdateFlow.java +++ b/java/google/registry/flows/domain/DomainUpdateFlow.java @@ -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 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 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 = + eppInput.getSingleExtension(MetadataExtension.class); + if (metadataExtension.isPresent() && metadataExtension.get().getRequestedByRegistrar()) { for (StatusValue statusValue : symmetricDifference(existingDomain.getStatusValues(), newDomain.getStatusValues())) { if (statusValue.isChargedStatus()) { diff --git a/java/google/registry/flows/picker/FlowPicker.java b/java/google/registry/flows/picker/FlowPicker.java index bd5fa3059..b52a70de6 100644 --- a/java/google/registry/flows/picker/FlowPicker.java +++ b/java/google/registry/flows/picker/FlowPicker.java @@ -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 = + 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() { - @Override - Class 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. - return DomainCheckFlow.class; - } - if (CheckType.CLAIMS.equals(extension.getCheckType()) - && LaunchPhase.CLAIMS.equals(extension.getPhase())) { - return DomainClaimsCheckFlow.class; - } - return null; - }}; + private static final FlowProvider DOMAIN_CHECK_FLOW_PROVIDER = + new FlowProvider() { + @Override + Class get( + EppInput eppInput, InnerCommand innerCommand, ResourceCommand resourceCommand) { + if (!(resourceCommand instanceof DomainCommand.Check)) { + return null; + } + Optional 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(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() { - @Override - Class get( - EppInput eppInput, InnerCommand innerCommand, ResourceCommand resourceCommand) { - return (resourceCommand instanceof DomainCommand.Create - && eppInput.getSingleExtension(AllocateCreateExtension.class) != null) - ? DomainAllocateFlow.class : null; - }}; + private static final FlowProvider ALLOCATE_FLOW_PROVIDER = + new FlowProvider() { + @Override + Class get( + EppInput eppInput, InnerCommand innerCommand, ResourceCommand resourceCommand) { + return (resourceCommand instanceof DomainCommand.Create + && 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> 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 Map, Class> + 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 launchPhases = ImmutableSet.of( - LaunchPhase.SUNRISE, LaunchPhase.SUNRUSH, LaunchPhase.LANDRUSH); + private final Set launchPhases = + ImmutableSet.of(LaunchPhase.SUNRISE, LaunchPhase.SUNRUSH, LaunchPhase.LANDRUSH); - @Override - Class get( - EppInput eppInput, InnerCommand innerCommand, ResourceCommand resourceCommand) { - if (eppInput.getSingleExtension(ApplicationIdTargetExtension.class) != null) { - return applicationFlows.get(resourceCommand.getClass()); - } - 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))) { - return applicationFlows.get(resourceCommand.getClass()); + @Override + Class get( + EppInput eppInput, InnerCommand innerCommand, ResourceCommand resourceCommand) { + if (eppInput.getSingleExtension(ApplicationIdTargetExtension.class).isPresent()) { + return applicationFlows.get(resourceCommand.getClass()); + } + Optional 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.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; } - } - return null; - }}; + }; /** Transfer flows have an {@link InnerCommand} of type {@link Transfer}. */ private static final FlowProvider TRANSFER_FLOW_PROVIDER = new FlowProvider() { diff --git a/java/google/registry/model/eppinput/EppInput.java b/java/google/registry/model/eppinput/EppInput.java index db7fcf504..d1ccd15cf 100644 --- a/java/google/registry/model/eppinput/EppInput.java +++ b/java/google/registry/model/eppinput/EppInput.java @@ -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 getSingleExtension(Class clazz) { - return getCommandWrapper() - .getExtensions() - .stream() - .filter(clazz::isInstance) - .map(clazz::cast) - .findFirst() - .orElse(null); + public Optional getSingleExtension(Class clazz) { + return Optional.ofNullable( + getCommandWrapper() + .getExtensions() + .stream() + .filter(clazz::isInstance) + .map(clazz::cast) + .findFirst() + .orElse(null)); } /** A tag that goes inside of an EPP {@literal }. */ diff --git a/java/google/registry/tools/server/VerifyOteAction.java b/java/google/registry/tools/server/VerifyOteAction.java index ab36d5c40..5f3eaac0f 100644 --- a/java/google/registry/tools/server/VerifyOteAction.java +++ b/java/google/registry/tools/server/VerifyOteAction.java @@ -105,20 +105,20 @@ public class VerifyOteAction implements Runnable, JsonAction { private static final Predicate HAS_CLAIMS_NOTICE = eppInput -> { - LaunchCreateExtension launchCreate = + Optional launchCreate = eppInput.getSingleExtension(LaunchCreateExtension.class); - return launchCreate != null && launchCreate.getNotice() != null; + return launchCreate.isPresent() && launchCreate.get().getNotice() != null; }; private static final Predicate 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 IS_SUNRISE = eppInput -> { - LaunchCreateExtension launchCreate = + Optional launchCreate = eppInput.getSingleExtension(LaunchCreateExtension.class); - return launchCreate != null && !isNullOrEmpty(launchCreate.getSignedMarks()); + return launchCreate.isPresent() && !isNullOrEmpty(launchCreate.get().getSignedMarks()); }; private static final Predicate 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)), diff --git a/javatests/google/registry/flows/ResourceFlowTestCase.java b/javatests/google/registry/flows/ResourceFlowTestCase.java index 8f9207900..f68e70fb7 100644 --- a/javatests/google/registry/flows/ResourceFlowTestCase.java +++ b/javatests/google/registry/flows/ResourceFlowTestCase.java @@ -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 extension = eppLoader.getEpp().getSingleExtension(ApplicationIdTargetExtension.class); - return extension == null ? getResourceCommand().getTargetId() : extension.getApplicationId(); + return extension.isPresent() + ? extension.get().getApplicationId() + : getResourceCommand().getTargetId(); } protected Class getResourceClass() { diff --git a/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java index bb5c2d9f8..8c2118c1e 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java @@ -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)