Skip to content

Commit

Permalink
entitlement: prevent transfers in the future
Browse files Browse the repository at this point in the history
The entitlement code always assumes that the first event for a
subscription is in the past. This means we don't support transfers
happening in the future - make sure to reject the transfer in that case.

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
  • Loading branch information
Pierre-Alexandre Meyer committed Oct 22, 2012
1 parent 896aef2 commit 752be1d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/src/main/java/com/ning/billing/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public enum ErrorCode {
ENT_BUNDLE_IS_OVERDUE_BLOCKED(1090, "Changes to this bundle are blocked by overdue enforcement (%s : %s)"),
ENT_ACCOUNT_IS_OVERDUE_BLOCKED(1091, "Changes to this account are blocked by overdue enforcement (%s)"),

/* Transfer */
ENT_TRANSFER_INVALID_EFF_DATE(1106, "Invalid effective date for transfer: %s"),

/*
*
* Range 2000 : CATALOG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ public SubscriptionBundle transferBundle(final UUID sourceAccountId, final UUID

try {
final DateTime effectiveTransferDate = transferDate == null ? clock.getUTCNow() : transferDate;
if (effectiveTransferDate.isAfter(clock.getUTCNow())) {
// The transfer event for the migrated bundle will be the first one, which cannot be in the future
// (entitlement always expects the first event to be in the past)
throw new EntitlementTransferApiException(ErrorCode.ENT_TRANSFER_INVALID_EFF_DATE, effectiveTransferDate);
}

final SubscriptionBundle bundle = dao.getSubscriptionBundleFromAccountAndKey(sourceAccountId, bundleKey, internalCallContext);
if (bundle == null) {
Expand Down

0 comments on commit 752be1d

Please sign in to comment.