Add syntheticCreationTime to BillingEvent.OneTime

In order to clean up potentially bad BillingEvent.Recurring expansions, we'll need to be able to trace synthetic billing events back to particular runs of the []. This field will be set to the cursor time at the start of the MR (all expansions in one MR job will have the same timestamp).
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=121999938
This commit is contained in:
ctingue 2016-05-10 16:16:04 -07:00 committed by Justine Tunney
parent d62da7bb19
commit 51362722cd
4 changed files with 76 additions and 18 deletions

View file

@ -216,6 +216,15 @@ public abstract class BillingEvent extends ImmutableObject
@IgnoreSave(IfNull.class)
Integer periodYears = null;
/**
* For {@link Flag#SYNTHETIC} events, when this event was persisted to datastore (i.e. the
* cursor position at the time the recurrence expansion job was last run). In the event a job
* needs to be undone, a query on this field will return the complete set of potentially bad
* events.
*/
@Index
DateTime syntheticCreationTime;
public Money getCost() {
return cost;
}
@ -228,6 +237,10 @@ public abstract class BillingEvent extends ImmutableObject
return periodYears;
}
public DateTime getSyntheticCreationTime() {
return syntheticCreationTime;
}
@Override
public Builder asBuilder() {
return new Builder(clone(this));
@ -259,6 +272,11 @@ public abstract class BillingEvent extends ImmutableObject
return this;
}
public Builder setSyntheticCreationTime(DateTime syntheticCreationTime) {
getInstance().syntheticCreationTime = syntheticCreationTime;
return this;
}
@Override
public OneTime build() {
OneTime instance = getInstance();
@ -270,6 +288,10 @@ public abstract class BillingEvent extends ImmutableObject
checkState(
reasonsWithPeriods.contains(instance.reason) == (instance.periodYears != null),
"Period years must be set if and only if reason is CREATE, RENEW, or TRANSFER.");
checkState(
instance.getFlags().contains(Flag.SYNTHETIC)
== (instance.syntheticCreationTime != null),
"Billing events with SYNTHETIC flag set must have a synthetic creation time.");
return super.build();
}
}