Record transaction for domain adds, renews and allocates

This is the second of many cls adding explicit logging in all our domain
mutation flows to facilitate transaction reporting.

Adds and renews each result in a +1 counter for the NET_ADDS/RENEWS_#_YR field,
which I've added simple (# of years, add or renew) -> Enum functions to get.
Allocates are just a special case of adds, and are counted in a similar manner.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=165963249
This commit is contained in:
larryruili 2017-08-21 12:57:01 -07:00 committed by Ben McIlwain
parent cb854f1b8b
commit c40dc67c5b
8 changed files with 170 additions and 24 deletions

View file

@ -14,6 +14,7 @@
package google.registry.model.reporting;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import com.google.common.collect.ImmutableSet;
@ -118,7 +119,28 @@ public class DomainTransactionRecord extends ImmutableObject implements Buildabl
TRANSFER_LOSING_NACKED,
DELETED_DOMAINS_GRACE,
DELETED_DOMAINS_NOGRACE,
RESTORED_DOMAINS
RESTORED_DOMAINS;
/** Boilerplate to simplify getting the NET_ADDS_#_YR enum from a number of years. */
public static TransactionReportField netAddsFieldFromYears(int years) {
return nameToField("NET_ADDS_%d_YR", years);
}
/** Boilerplate to simplify getting the NET_RENEWS_#_YR enum from a number of years. */
public static TransactionReportField netRenewsFieldFromYears(int years) {
return nameToField("NET_RENEWS_%d_YR", years);
}
private static TransactionReportField nameToField(String enumTemplate, int years) {
checkArgument(
years >= 1 && years <= 10, "domain add and renew years must be between 1 and 10");
try {
return TransactionReportField.valueOf(String.format(enumTemplate, years));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(
"Unexpected error converting add/renew years to enum TransactionReportField", e);
}
}
}
}
@ -134,6 +156,19 @@ public class DomainTransactionRecord extends ImmutableObject implements Buildabl
return transactionFieldAmounts;
}
/** An alternative construction method when the builder is not necessary. */
public static DomainTransactionRecord create(
String tld,
DateTime reportingTime,
TransactionFieldAmount... transactionFieldAmounts) {
return new DomainTransactionRecord.Builder()
.setTld(tld)
// We report this event when the grace period ends, if applicable
.setReportingTime(reportingTime)
.setTransactionFieldAmounts(ImmutableSet.copyOf(transactionFieldAmounts))
.build();
}
@Override
public Builder asBuilder() {
return new Builder(clone(this));