diff --git a/java/google/registry/model/domain/DomainResource.java b/java/google/registry/model/domain/DomainResource.java index 58b7173fe..cda8e6006 100644 --- a/java/google/registry/model/domain/DomainResource.java +++ b/java/google/registry/model/domain/DomainResource.java @@ -213,35 +213,15 @@ public class DomainResource extends DomainBase return ImmutableSet.copyOf(gracePeriodStatuses); } - /** - * Returns the Registry Grace Period expiration date for the specified type of grace period for - * this domain, or null if there is no grace period of the specified type. - */ - public Optional getGracePeriodExpirationTime(GracePeriodStatus gracePeriodType) { + /** Returns the subset of grace periods having the specified type. */ + public ImmutableSet getGracePeriodsOfType(GracePeriodStatus gracePeriodType) { + ImmutableSet.Builder builder = new ImmutableSet.Builder<>(); for (GracePeriod gracePeriod : getGracePeriods()) { if (gracePeriod.getType() == gracePeriodType) { - return Optional.of(gracePeriod.getExpirationTime()); + builder.add(gracePeriod); } } - return Optional.absent(); - } - - /** - * Checks to see if the domain is in a particular type of grace period at the specified time. We - * only check the expiration time, because grace periods are always assumed to start at the - * beginning of time. This could be confusing if asOfDate is in the past. For instance, the Add - * Grace Period will appear to last from the beginning of time until 5 days after the domain is - * created. - */ - public boolean doesAnyGracePeriodOfTypeExpireAfter( - GracePeriodStatus gracePeriodType, DateTime asOfDate) { - for (GracePeriod gracePeriod : getGracePeriods()) { - if ((gracePeriod.getType() == gracePeriodType) - && gracePeriod.getExpirationTime().isAfter(asOfDate)) { - return true; - } - } - return false; + return builder.build(); } /** diff --git a/javatests/google/registry/model/domain/DomainResourceTest.java b/javatests/google/registry/model/domain/DomainResourceTest.java index 132e80c43..7f9bf9653 100644 --- a/javatests/google/registry/model/domain/DomainResourceTest.java +++ b/javatests/google/registry/model/domain/DomainResourceTest.java @@ -26,6 +26,7 @@ import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.util.DateTimeUtils.START_OF_TIME; import static org.joda.money.CurrencyUnit.USD; +import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; @@ -51,7 +52,6 @@ import google.registry.model.transfer.TransferData; import google.registry.model.transfer.TransferData.TransferServerApproveEntity; import google.registry.model.transfer.TransferStatus; import google.registry.testing.ExceptionRule; -import java.util.List; import org.joda.money.Money; import org.joda.time.DateTime; import org.junit.Before; @@ -346,7 +346,7 @@ public class DomainResourceTest extends EntityTestCase { @Test public void testStackedGracePeriods() { - List gracePeriods = ImmutableList.of( + ImmutableList gracePeriods = ImmutableList.of( GracePeriod.create(GracePeriodStatus.ADD, clock.nowUtc().plusDays(3), "foo", null), GracePeriod.create(GracePeriodStatus.ADD, clock.nowUtc().plusDays(2), "bar", null), GracePeriod.create(GracePeriodStatus.ADD, clock.nowUtc().plusDays(1), "baz", null)); @@ -357,6 +357,22 @@ public class DomainResourceTest extends EntityTestCase { } } + @Test + public void testGracePeriodsByType() { + ImmutableSet addGracePeriods = ImmutableSet.of( + GracePeriod.create(GracePeriodStatus.ADD, clock.nowUtc().plusDays(3), "foo", null), + GracePeriod.create(GracePeriodStatus.ADD, clock.nowUtc().plusDays(1), "baz", null)); + ImmutableSet renewGracePeriods = ImmutableSet.of( + GracePeriod.create(GracePeriodStatus.RENEW, clock.nowUtc().plusDays(3), "foo", null), + GracePeriod.create(GracePeriodStatus.RENEW, clock.nowUtc().plusDays(1), "baz", null)); + domain = domain.asBuilder() + .setGracePeriods(FluentIterable.from(addGracePeriods).append(renewGracePeriods).toSet()) + .build(); + assertThat(domain.getGracePeriodsOfType(GracePeriodStatus.ADD)).isEqualTo(addGracePeriods); + assertThat(domain.getGracePeriodsOfType(GracePeriodStatus.RENEW)).isEqualTo(renewGracePeriods); + assertThat(domain.getGracePeriodsOfType(GracePeriodStatus.TRANSFER)).isEmpty(); + } + @Test public void testRenewalsHappenAtExpiration() { DomainResource renewed =