mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
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:
parent
13249db5cf
commit
c56959b62b
2 changed files with 23 additions and 27 deletions
|
@ -213,35 +213,15 @@ public class DomainResource extends DomainBase
|
||||||
return ImmutableSet.copyOf(gracePeriodStatuses);
|
return ImmutableSet.copyOf(gracePeriodStatuses);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Returns the subset of grace periods having the specified type. */
|
||||||
* Returns the Registry Grace Period expiration date for the specified type of grace period for
|
public ImmutableSet<GracePeriod> getGracePeriodsOfType(GracePeriodStatus gracePeriodType) {
|
||||||
* this domain, or null if there is no grace period of the specified type.
|
ImmutableSet.Builder<GracePeriod> builder = new ImmutableSet.Builder<>();
|
||||||
*/
|
|
||||||
public Optional<DateTime> getGracePeriodExpirationTime(GracePeriodStatus gracePeriodType) {
|
|
||||||
for (GracePeriod gracePeriod : getGracePeriods()) {
|
for (GracePeriod gracePeriod : getGracePeriods()) {
|
||||||
if (gracePeriod.getType() == gracePeriodType) {
|
if (gracePeriod.getType() == gracePeriodType) {
|
||||||
return Optional.of(gracePeriod.getExpirationTime());
|
builder.add(gracePeriod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Optional.absent();
|
return builder.build();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,6 +26,7 @@ import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
|
||||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||||
import static org.joda.money.CurrencyUnit.USD;
|
import static org.joda.money.CurrencyUnit.USD;
|
||||||
|
|
||||||
|
import com.google.common.collect.FluentIterable;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.ImmutableSortedMap;
|
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.TransferData.TransferServerApproveEntity;
|
||||||
import google.registry.model.transfer.TransferStatus;
|
import google.registry.model.transfer.TransferStatus;
|
||||||
import google.registry.testing.ExceptionRule;
|
import google.registry.testing.ExceptionRule;
|
||||||
import java.util.List;
|
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -346,7 +346,7 @@ public class DomainResourceTest extends EntityTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStackedGracePeriods() {
|
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(3), "foo", null),
|
||||||
GracePeriod.create(GracePeriodStatus.ADD, clock.nowUtc().plusDays(2), "bar", null),
|
GracePeriod.create(GracePeriodStatus.ADD, clock.nowUtc().plusDays(2), "bar", null),
|
||||||
GracePeriod.create(GracePeriodStatus.ADD, clock.nowUtc().plusDays(1), "baz", 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
|
@Test
|
||||||
public void testRenewalsHappenAtExpiration() {
|
public void testRenewalsHappenAtExpiration() {
|
||||||
DomainResource renewed =
|
DomainResource renewed =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue