Add new DomainResource.getGracePeriodsOfType() method

This adds a new method which will be used in an upcoming CL affecting domain
transfer logic.  It also removes two older methods that are unused (they were
originally going to be used for TLD-specific logic which is now obsolete).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=148928965
This commit is contained in:
nickfelt 2017-03-01 14:07:14 -08:00 committed by Ben McIlwain
parent 13249db5cf
commit c56959b62b
2 changed files with 23 additions and 27 deletions

View file

@ -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<DateTime> getGracePeriodExpirationTime(GracePeriodStatus gracePeriodType) {
/** Returns the subset of grace periods having the specified type. */
public ImmutableSet<GracePeriod> getGracePeriodsOfType(GracePeriodStatus gracePeriodType) {
ImmutableSet.Builder<GracePeriod> 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();
}
/**

View file

@ -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<GracePeriod> gracePeriods = ImmutableList.of(
ImmutableList<GracePeriod> 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<GracePeriod> addGracePeriods = ImmutableSet.of(
GracePeriod.create(GracePeriodStatus.ADD, clock.nowUtc().plusDays(3), "foo", null),
GracePeriod.create(GracePeriodStatus.ADD, clock.nowUtc().plusDays(1), "baz", null));
ImmutableSet<GracePeriod> 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 =