killbill-memoizeit
Changes
analytics/src/test/java/com/ning/billing/analytics/TestBusinessSubscriptionTransitionRecorder.java 2(+1 -1)
invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultInvoiceAdjustmentEvent.java 20(+6 -14)
junction/src/main/java/com/ning/billing/junction/plumbing/billing/BillCycleDayCalculator.java 10(+5 -5)
junction/src/main/java/com/ning/billing/junction/plumbing/billing/DefaultInternalBillingApi.java 2(+1 -1)
junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestBillCycleDayCalculator.java 2(+1 -1)
Details
diff --git a/analytics/src/main/java/com/ning/billing/analytics/BusinessSubscriptionTransitionDao.java b/analytics/src/main/java/com/ning/billing/analytics/BusinessSubscriptionTransitionDao.java
index 6a5c0e6..05581aa 100644
--- a/analytics/src/main/java/com/ning/billing/analytics/BusinessSubscriptionTransitionDao.java
+++ b/analytics/src/main/java/com/ning/billing/analytics/BusinessSubscriptionTransitionDao.java
@@ -98,7 +98,8 @@ public class BusinessSubscriptionTransitionDao {
final ArrayList<BusinessSubscriptionTransition> transitions = new ArrayList<BusinessSubscriptionTransition>();
for (final Subscription subscription : subscriptions) {
- for (final EffectiveSubscriptionInternalEvent event : entitlementApi.getAllTransitions(subscription)) {
+ // TODO remove API call from within transaction, although this is NOT a real issue as this call wil not hit the DB
+ for (final EffectiveSubscriptionInternalEvent event : entitlementApi.getAllTransitions(subscription, context)) {
final BusinessSubscriptionEvent businessEvent = getBusinessSubscriptionFromEvent(event);
if (businessEvent == null) {
continue;
diff --git a/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java b/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java
index 9a6241c..afe306c 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java
@@ -235,10 +235,10 @@ public class TestAnalyticsService extends AnalyticsTestSuiteWithEmbeddedDB {
// It doesn't really matter what the events contain - the listener will go back to the db
invoiceCreationNotification = new DefaultInvoiceCreationEvent(invoice.getId(), account.getId(),
- INVOICE_AMOUNT, ACCOUNT_CURRENCY, null);
+ INVOICE_AMOUNT, ACCOUNT_CURRENCY, null, 1L, 1L);
paymentInfoNotification = new DefaultPaymentInfoEvent(account.getId(), invoices.get(0).getId(), null, invoices.get(0).getBalance(), -1,
- PaymentStatus.UNKNOWN, null, null, null, clock.getUTCNow());
+ PaymentStatus.UNKNOWN, null, null, null, clock.getUTCNow(), 1L, 1L);
final PaymentModelDao paymentInfo = new PaymentModelDao(account.getId(), invoice.getId(), account.getPaymentMethodId(),
BigDecimal.ONE, Currency.USD, clock.getUTCNow(), PaymentStatus.SUCCESS);
diff --git a/analytics/src/test/java/com/ning/billing/analytics/TestBusinessSubscriptionTransitionRecorder.java b/analytics/src/test/java/com/ning/billing/analytics/TestBusinessSubscriptionTransitionRecorder.java
index 0e39638..78dbe98 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/TestBusinessSubscriptionTransitionRecorder.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/TestBusinessSubscriptionTransitionRecorder.java
@@ -84,7 +84,7 @@ public class TestBusinessSubscriptionTransitionRecorder extends AnalyticsTestSui
final Subscription subscription = Mockito.mock(Subscription.class);
Mockito.when(subscription.getId()).thenReturn(subscriptionId);
- Mockito.when(entitlementApi.getAllTransitions(subscription)).thenReturn(ImmutableList.<EffectiveSubscriptionInternalEvent>of(eventEffective));
+ Mockito.when(entitlementApi.getAllTransitions(subscription, internalCallContext)).thenReturn(ImmutableList.<EffectiveSubscriptionInternalEvent>of(eventEffective));
Mockito.when(entitlementApi.getSubscriptionsForBundle(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(ImmutableList.<Subscription>of(subscription));
diff --git a/invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultInvoiceAdjustmentEvent.java b/invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultInvoiceAdjustmentEvent.java
index 10d1656..64913da 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultInvoiceAdjustmentEvent.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultInvoiceAdjustmentEvent.java
@@ -18,25 +18,27 @@ package com.ning.billing.invoice.api.user;
import java.util.UUID;
+import com.ning.billing.util.events.DefaultBusInternalEvent;
import com.ning.billing.util.events.InvoiceAdjustmentInternalEvent;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
-public class DefaultInvoiceAdjustmentEvent implements InvoiceAdjustmentInternalEvent {
+public class DefaultInvoiceAdjustmentEvent extends DefaultBusInternalEvent implements InvoiceAdjustmentInternalEvent {
private final UUID invoiceId;
private final UUID accountId;
- private final UUID userToken;
@JsonCreator
public DefaultInvoiceAdjustmentEvent(@JsonProperty("invoiceId") final UUID invoiceId,
@JsonProperty("accountId") final UUID accountId,
- @JsonProperty("userToken") final UUID userToken) {
+ @JsonProperty("userToken") final UUID userToken,
+ @JsonProperty("accountRecordId") final Long accountRecordId,
+ @JsonProperty("tenantRecordId") final Long tenantRecordId) {
+ super(userToken, accountRecordId, tenantRecordId);
this.invoiceId = invoiceId;
this.accountId = accountId;
- this.userToken = userToken;
}
@Override
@@ -55,10 +57,6 @@ public class DefaultInvoiceAdjustmentEvent implements InvoiceAdjustmentInternalE
return BusEventType.INVOICE_ADJUSTMENT;
}
- @Override
- public UUID getUserToken() {
- return userToken;
- }
@Override
public String toString() {
@@ -66,7 +64,6 @@ public class DefaultInvoiceAdjustmentEvent implements InvoiceAdjustmentInternalE
sb.append("DefaultInvoiceAdjustmentEvent");
sb.append("{invoiceId=").append(invoiceId);
sb.append(", accountId=").append(accountId);
- sb.append(", userToken=").append(userToken);
sb.append('}');
return sb.toString();
}
@@ -88,10 +85,6 @@ public class DefaultInvoiceAdjustmentEvent implements InvoiceAdjustmentInternalE
if (invoiceId != null ? !invoiceId.equals(that.invoiceId) : that.invoiceId != null) {
return false;
}
- if (userToken != null ? !userToken.equals(that.userToken) : that.userToken != null) {
- return false;
- }
-
return true;
}
@@ -99,7 +92,6 @@ public class DefaultInvoiceAdjustmentEvent implements InvoiceAdjustmentInternalE
public int hashCode() {
int result = invoiceId != null ? invoiceId.hashCode() : 0;
result = 31 * result + (accountId != null ? accountId.hashCode() : 0);
- result = 31 * result + (userToken != null ? userToken.hashCode() : 0);
return result;
}
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultInvoiceCreationEvent.java b/invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultInvoiceCreationEvent.java
index 0b2d9ad..0e5c678 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultInvoiceCreationEvent.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultInvoiceCreationEvent.java
@@ -20,31 +20,33 @@ import java.math.BigDecimal;
import java.util.UUID;
import com.ning.billing.catalog.api.Currency;
+import com.ning.billing.util.events.DefaultBusInternalEvent;
import com.ning.billing.util.events.InvoiceCreationInternalEvent;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
-public class DefaultInvoiceCreationEvent implements InvoiceCreationInternalEvent {
+public class DefaultInvoiceCreationEvent extends DefaultBusInternalEvent implements InvoiceCreationInternalEvent {
private final UUID invoiceId;
private final UUID accountId;
private final BigDecimal amountOwed;
private final Currency currency;
- private final UUID userToken;
@JsonCreator
public DefaultInvoiceCreationEvent(@JsonProperty("invoiceId") final UUID invoiceId,
@JsonProperty("accountId") final UUID accountId,
@JsonProperty("amountOwed") final BigDecimal amountOwed,
@JsonProperty("currency") final Currency currency,
- @JsonProperty("userToken") final UUID userToken) {
+ @JsonProperty("userToken") final UUID userToken,
+ @JsonProperty("accountRecordId") final Long accountRecordId,
+ @JsonProperty("tenantRecordId") final Long tenantRecordId) {
+ super(userToken, accountRecordId, tenantRecordId);
this.invoiceId = invoiceId;
this.accountId = accountId;
this.amountOwed = amountOwed;
this.currency = currency;
- this.userToken = userToken;
}
@JsonIgnore
@@ -53,10 +55,6 @@ public class DefaultInvoiceCreationEvent implements InvoiceCreationInternalEvent
return BusEventType.INVOICE_CREATION;
}
- @Override
- public UUID getUserToken() {
- return userToken;
- }
@Override
public UUID getInvoiceId() {
@@ -94,8 +92,6 @@ public class DefaultInvoiceCreationEvent implements InvoiceCreationInternalEvent
if (amountOwed != null ? !amountOwed.equals(that.amountOwed) : that.amountOwed != null) return false;
if (currency != that.currency) return false;
if (invoiceId != null ? !invoiceId.equals(that.invoiceId) : that.invoiceId != null) return false;
- if (userToken != null ? !userToken.equals(that.userToken) : that.userToken != null) return false;
-
return true;
}
@@ -105,7 +101,6 @@ public class DefaultInvoiceCreationEvent implements InvoiceCreationInternalEvent
result = 31 * result + (accountId != null ? accountId.hashCode() : 0);
result = 31 * result + (amountOwed != null ? amountOwed.hashCode() : 0);
result = 31 * result + (currency != null ? currency.hashCode() : 0);
- result = 31 * result + (userToken != null ? userToken.hashCode() : 0);
return result;
}
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultInvoiceUserApi.java b/invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultInvoiceUserApi.java
index 49facb4..b1fe43b 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultInvoiceUserApi.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultInvoiceUserApi.java
@@ -285,7 +285,7 @@ public class DefaultInvoiceUserApi implements InvoiceUserApi {
private void notifyBusOfInvoiceAdjustment(final UUID invoiceId, final UUID accountId, final UUID userToken, final InternalCallContext context) {
try {
- eventBus.post(new DefaultInvoiceAdjustmentEvent(invoiceId, accountId, userToken), context);
+ eventBus.post(new DefaultInvoiceAdjustmentEvent(invoiceId, accountId, context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId()), context);
} catch (EventBusException e) {
log.warn("Failed to post adjustment event for invoice " + invoiceId, e);
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultNullInvoiceEvent.java b/invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultNullInvoiceEvent.java
index ceabe8e..7cf9b09 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultNullInvoiceEvent.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/api/user/DefaultNullInvoiceEvent.java
@@ -20,26 +20,27 @@ import java.util.UUID;
import org.joda.time.LocalDate;
+import com.ning.billing.util.events.DefaultBusInternalEvent;
import com.ning.billing.util.events.NullInvoiceInternalEvent;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
-public class DefaultNullInvoiceEvent implements NullInvoiceInternalEvent {
+public class DefaultNullInvoiceEvent extends DefaultBusInternalEvent implements NullInvoiceInternalEvent {
private final UUID accountId;
private final LocalDate processingDate;
- private final UUID userToken;
@JsonCreator
public DefaultNullInvoiceEvent(@JsonProperty("accountId") final UUID accountId,
@JsonProperty("processingDate") final LocalDate processingDate,
- @JsonProperty("userToken") final UUID userToken) {
- super();
+ @JsonProperty("userToken") final UUID userToken,
+ @JsonProperty("accountRecordId") final Long accountRecordId,
+ @JsonProperty("tenantRecordId") final Long tenantRecordId) {
+ super(userToken, accountRecordId, tenantRecordId);
this.accountId = accountId;
this.processingDate = processingDate;
- this.userToken = userToken;
}
@JsonIgnore
@@ -48,10 +49,6 @@ public class DefaultNullInvoiceEvent implements NullInvoiceInternalEvent {
return BusEventType.INVOICE_EMPTY;
}
- @Override
- public UUID getUserToken() {
- return userToken;
- }
@Override
public UUID getAccountId() {
@@ -68,7 +65,6 @@ public class DefaultNullInvoiceEvent implements NullInvoiceInternalEvent {
sb.append("DefaultNullInvoiceEvent");
sb.append("{accountId=").append(accountId);
sb.append(", processingDate=").append(processingDate);
- sb.append(", userToken=").append(userToken);
sb.append('}');
return sb.toString();
}
@@ -81,8 +77,6 @@ public class DefaultNullInvoiceEvent implements NullInvoiceInternalEvent {
+ ((accountId == null) ? 0 : accountId.hashCode());
result = prime * result
+ ((processingDate == null) ? 0 : processingDate.hashCode());
- result = prime * result
- + ((userToken == null) ? 0 : userToken.hashCode());
return result;
}
@@ -112,13 +106,6 @@ public class DefaultNullInvoiceEvent implements NullInvoiceInternalEvent {
} else if (processingDate.compareTo(other.processingDate) != 0) {
return false;
}
- if (userToken == null) {
- if (other.userToken != null) {
- return false;
- }
- } else if (!userToken.equals(other.userToken)) {
- return false;
- }
return true;
}
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/dao/AuditedInvoiceDao.java b/invoice/src/main/java/com/ning/billing/invoice/dao/AuditedInvoiceDao.java
index ec27c0c..b1789e0 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/dao/AuditedInvoiceDao.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/dao/AuditedInvoiceDao.java
@@ -967,7 +967,8 @@ public class AuditedInvoiceDao implements InvoiceDao {
private void notifyBusOfInvoiceAdjustment(final Transmogrifier transactional, final UUID invoiceId, final UUID accountId,
final UUID userToken, final InternalCallContext context) {
try {
- eventBus.postFromTransaction(new DefaultInvoiceAdjustmentEvent(invoiceId, accountId, userToken), transactional, context);
+ eventBus.postFromTransaction(new DefaultInvoiceAdjustmentEvent(invoiceId, accountId, userToken, context.getAccountRecordId(), context.getTenantRecordId()),
+ transactional, context);
} catch (EventBusException e) {
log.warn("Failed to post adjustment event for invoice " + invoiceId, e);
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/InvoiceDispatcher.java b/invoice/src/main/java/com/ning/billing/invoice/InvoiceDispatcher.java
index 182168b..d9f2afd 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/InvoiceDispatcher.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/InvoiceDispatcher.java
@@ -171,7 +171,8 @@ public class InvoiceDispatcher {
if (invoice == null) {
log.info("Generated null invoice.");
if (!dryRun) {
- final BusInternalEvent event = new DefaultNullInvoiceEvent(accountId, clock.getUTCToday(), context.getUserToken());
+ final BusInternalEvent event = new DefaultNullInvoiceEvent(accountId, clock.getUTCToday(), context.getUserToken(),
+ internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId());
postEvent(event, accountId, internalCallContext);
}
} else {
@@ -193,7 +194,9 @@ public class InvoiceDispatcher {
final InvoiceCreationInternalEvent event = new DefaultInvoiceCreationEvent(invoice.getId(), invoice.getAccountId(),
invoice.getBalance(), invoice.getCurrency(),
- context.getUserToken());
+ context.getUserToken(),
+ internalCallContext.getAccountRecordId(),
+ internalCallContext.getTenantRecordId());
if (isRealInvoiceWithItems) {
postEvent(event, accountId, internalCallContext);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/api/user/TestEventJson.java b/invoice/src/test/java/com/ning/billing/invoice/api/user/TestEventJson.java
index efee08f..240fb0a 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/api/user/TestEventJson.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/api/user/TestEventJson.java
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2010-2011 Ning, Inc.
*
* Ning licenses this file to you under the Apache License, version 2.0
@@ -35,7 +35,7 @@ public class TestEventJson extends InvoiceTestSuite {
@Test(groups = "fast")
public void testInvoiceCreationEvent() throws Exception {
- final InvoiceCreationInternalEvent e = new DefaultInvoiceCreationEvent(UUID.randomUUID(), UUID.randomUUID(), new BigDecimal(12.0), Currency.USD, UUID.randomUUID());
+ final InvoiceCreationInternalEvent e = new DefaultInvoiceCreationEvent(UUID.randomUUID(), UUID.randomUUID(), new BigDecimal(12.0), Currency.USD, UUID.randomUUID(), 1L, 1L);
final String json = mapper.writeValueAsString(e);
final Object obj = mapper.readValue(json, DefaultInvoiceCreationEvent.class);
@@ -44,7 +44,7 @@ public class TestEventJson extends InvoiceTestSuite {
@Test(groups = "fast")
public void testEmptyInvoiceEvent() throws Exception {
- final NullInvoiceInternalEvent e = new DefaultNullInvoiceEvent(UUID.randomUUID(), new LocalDate(), UUID.randomUUID());
+ final NullInvoiceInternalEvent e = new DefaultNullInvoiceEvent(UUID.randomUUID(), new LocalDate(), UUID.randomUUID(), 1L, 1L);
final String json = mapper.writeValueAsString(e);
final Object obj = mapper.readValue(json, DefaultNullInvoiceEvent.class);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/dao/MockInvoiceDao.java b/invoice/src/test/java/com/ning/billing/invoice/dao/MockInvoiceDao.java
index c689a21..6c47c67 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/dao/MockInvoiceDao.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/dao/MockInvoiceDao.java
@@ -34,9 +34,9 @@ import com.ning.billing.invoice.api.InvoiceApiException;
import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.api.InvoicePayment;
import com.ning.billing.invoice.api.user.DefaultInvoiceCreationEvent;
-import com.ning.billing.util.svcsapi.bus.Bus;
import com.ning.billing.util.callcontext.InternalCallContext;
import com.ning.billing.util.callcontext.InternalTenantContext;
+import com.ning.billing.util.svcsapi.bus.Bus;
import com.google.inject.Inject;
@@ -59,7 +59,7 @@ public class MockInvoiceDao implements InvoiceDao {
try {
eventBus.post(new DefaultInvoiceCreationEvent(invoice.getId(), invoice.getAccountId(),
invoice.getBalance(), invoice.getCurrency(),
- null), context);
+ null, 1L, 1L), context);
} catch (Bus.EventBusException ex) {
throw new RuntimeException(ex);
}
diff --git a/junction/src/main/java/com/ning/billing/junction/plumbing/api/BlockingSubscription.java b/junction/src/main/java/com/ning/billing/junction/plumbing/api/BlockingSubscription.java
index 1d22293..2344062 100644
--- a/junction/src/main/java/com/ning/billing/junction/plumbing/api/BlockingSubscription.java
+++ b/junction/src/main/java/com/ning/billing/junction/plumbing/api/BlockingSubscription.java
@@ -16,7 +16,6 @@
package com.ning.billing.junction.plumbing.api;
-import java.util.List;
import java.util.UUID;
import org.joda.time.DateTime;
@@ -28,7 +27,6 @@ import com.ning.billing.catalog.api.PlanPhase;
import com.ning.billing.catalog.api.PlanPhaseSpecifier;
import com.ning.billing.catalog.api.PriceList;
import com.ning.billing.catalog.api.ProductCategory;
-import com.ning.billing.entitlement.api.user.EffectiveSubscriptionEvent;
import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.entitlement.api.user.Subscription;
import com.ning.billing.junction.api.BlockingApiException;
@@ -184,26 +182,6 @@ public class BlockingSubscription implements Subscription {
}
@Override
- public EffectiveSubscriptionEvent getPendingTransition() {
- return subscription.getPendingTransition();
- }
-
- @Override
- public EffectiveSubscriptionEvent getPreviousTransition() {
- return subscription.getPreviousTransition();
- }
-
- @Override
- public List<EffectiveSubscriptionEvent> getBillingTransitions() {
- return subscription.getBillingTransitions();
- }
-
- @Override
- public List<EffectiveSubscriptionEvent> getAllTransitions() {
- return subscription.getAllTransitions();
- }
-
- @Override
public BlockingState getBlockingState() {
if (blockingState == null) {
blockingState = blockingApi.getBlockingStateFor(this, context);
diff --git a/junction/src/main/java/com/ning/billing/junction/plumbing/billing/BillCycleDayCalculator.java b/junction/src/main/java/com/ning/billing/junction/plumbing/billing/BillCycleDayCalculator.java
index 93b31b7..465b707 100644
--- a/junction/src/main/java/com/ning/billing/junction/plumbing/billing/BillCycleDayCalculator.java
+++ b/junction/src/main/java/com/ning/billing/junction/plumbing/billing/BillCycleDayCalculator.java
@@ -95,7 +95,7 @@ public class BillCycleDayCalculator {
case ACCOUNT:
result = account.getBillCycleDay();
if (result == null || result.getDayOfMonthUTC() == 0) {
- result = calculateBcdFromSubscription(subscription, plan, account, catalog);
+ result = calculateBcdFromSubscription(subscription, plan, account, catalog, context);
}
break;
case BUNDLE:
@@ -105,10 +105,10 @@ public class BillCycleDayCalculator {
// The BP has been cancelled
basePlan = baseSub.getLastActivePlan();
}
- result = calculateBcdFromSubscription(baseSub, basePlan, account, catalog);
+ result = calculateBcdFromSubscription(baseSub, basePlan, account, catalog, context);
break;
case SUBSCRIPTION:
- result = calculateBcdFromSubscription(subscription, plan, account, catalog);
+ result = calculateBcdFromSubscription(subscription, plan, account, catalog, context);
break;
}
@@ -120,12 +120,12 @@ public class BillCycleDayCalculator {
}
@VisibleForTesting
- BillCycleDay calculateBcdFromSubscription(final Subscription subscription, final Plan plan, final Account account, final Catalog catalog)
+ BillCycleDay calculateBcdFromSubscription(final Subscription subscription, final Plan plan, final Account account, final Catalog catalog, final InternalCallContext context)
throws AccountApiException, CatalogApiException {
// Retrieve the initial phase type for that subscription
// TODO - this should be extracted somewhere, along with this code above
final PhaseType initialPhaseType;
- final List<EffectiveSubscriptionInternalEvent> transitions = entitlementApi.getAllTransitions(subscription);
+ final List<EffectiveSubscriptionInternalEvent> transitions = entitlementApi.getAllTransitions(subscription, context);
if (transitions.size() == 0) {
initialPhaseType = null;
} else {
diff --git a/junction/src/main/java/com/ning/billing/junction/plumbing/billing/DefaultInternalBillingApi.java b/junction/src/main/java/com/ning/billing/junction/plumbing/billing/DefaultInternalBillingApi.java
index 2ca82f9..bd541e8 100644
--- a/junction/src/main/java/com/ning/billing/junction/plumbing/billing/DefaultInternalBillingApi.java
+++ b/junction/src/main/java/com/ning/billing/junction/plumbing/billing/DefaultInternalBillingApi.java
@@ -137,7 +137,7 @@ public class DefaultInternalBillingApi implements BillingInternalApi {
private void addBillingEventsForSubscription(final List<Subscription> subscriptions, final SubscriptionBundle bundle, final Account account, final InternalCallContext context, final DefaultBillingEventSet result) {
for (final Subscription subscription : subscriptions) {
- for (final EffectiveSubscriptionInternalEvent transition : entitlementApi.getBillingTransitions(subscription)) {
+ for (final EffectiveSubscriptionInternalEvent transition : entitlementApi.getBillingTransitions(subscription, context)) {
try {
final BillCycleDay bcd = bcdCalculator.calculateBcd(bundle, subscription, transition, account, context);
diff --git a/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestBillCycleDayCalculator.java b/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestBillCycleDayCalculator.java
index d707114..af9951b 100644
--- a/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestBillCycleDayCalculator.java
+++ b/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestBillCycleDayCalculator.java
@@ -145,7 +145,7 @@ public class TestBillCycleDayCalculator extends JunctionTestSuite {
final Account account = Mockito.mock(Account.class);
Mockito.when(account.getTimeZone()).thenReturn(accountTimeZone);
- final BillCycleDay bcd = billCycleDayCalculator.calculateBcdFromSubscription(subscription, plan, account, Mockito.mock(Catalog.class));
+ final BillCycleDay bcd = billCycleDayCalculator.calculateBcdFromSubscription(subscription, plan, account, Mockito.mock(Catalog.class), internalCallContext);
Assert.assertEquals(bcd.getDayOfMonthUTC(), bcdUTC);
Assert.assertEquals(bcd.getDayOfMonthLocal(), bcdLocal);
}
diff --git a/overdue/src/main/java/com/ning/billing/overdue/applicator/DefaultOverdueChangeEvent.java b/overdue/src/main/java/com/ning/billing/overdue/applicator/DefaultOverdueChangeEvent.java
index 6add492..fac42a4 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/applicator/DefaultOverdueChangeEvent.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/applicator/DefaultOverdueChangeEvent.java
@@ -18,20 +18,20 @@ package com.ning.billing.overdue.applicator;
import java.util.UUID;
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.junction.api.Blockable.Type;
+import com.ning.billing.util.events.DefaultBusInternalEvent;
import com.ning.billing.util.events.OverdueChangeInternalEvent;
-public class DefaultOverdueChangeEvent implements OverdueChangeInternalEvent {
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class DefaultOverdueChangeEvent extends DefaultBusInternalEvent implements OverdueChangeInternalEvent {
private final UUID overdueObjectId;
private final Blockable.Type overdueObjectType;
private final String previousOverdueStateName;
private final String nextOverdueStateName;
- private final UUID userToken;
@JsonCreator
@@ -39,14 +39,16 @@ public class DefaultOverdueChangeEvent implements OverdueChangeInternalEvent {
@JsonProperty("overdueObjectType") final Blockable.Type overdueObjectType,
@JsonProperty("previousOverdueStateName") final String previousOverdueStateName,
@JsonProperty("nextOverdueStateName") final String nextOverdueStateName,
- @JsonProperty("userToken") final UUID userToken) {
+ @JsonProperty("userToken") final UUID userToken,
+ @JsonProperty("accountRecordId") final Long accountRecordId,
+ @JsonProperty("tenantRecordId") final Long tenantRecordId) {
+ super(userToken, accountRecordId, tenantRecordId);
this.overdueObjectId = overdueObjectId;
this.overdueObjectType = overdueObjectType;
this.previousOverdueStateName = previousOverdueStateName;
this.nextOverdueStateName = nextOverdueStateName;
- this.userToken = userToken;
}
-
+
@JsonIgnore
@Override
public BusEventType getBusEventType() {
@@ -54,10 +56,6 @@ public class DefaultOverdueChangeEvent implements OverdueChangeInternalEvent {
}
@Override
- public UUID getUserToken() {
- return userToken;
- }
- @Override
public String getPreviousOverdueStateName() {
return previousOverdueStateName;
}
diff --git a/overdue/src/main/java/com/ning/billing/overdue/applicator/OverdueStateApplicator.java b/overdue/src/main/java/com/ning/billing/overdue/applicator/OverdueStateApplicator.java
index e5a6745..da3ff18 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/applicator/OverdueStateApplicator.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/applicator/OverdueStateApplicator.java
@@ -129,14 +129,14 @@ public class OverdueStateApplicator<T extends Blockable> {
}
try {
- bus.post(createOverdueEvent(overdueable, previousOverdueStateName, nextOverdueState.getName()), context);
+ bus.post(createOverdueEvent(overdueable, previousOverdueStateName, nextOverdueState.getName(), context), context);
} catch (Exception e) {
log.error("Error posting overdue change event to bus", e);
}
}
- private OverdueChangeInternalEvent createOverdueEvent(final T overdueable, final String previousOverdueStateName, final String nextOverdueStateName) throws BlockingApiException {
- return new DefaultOverdueChangeEvent(overdueable.getId(), Blockable.Type.get(overdueable), previousOverdueStateName, nextOverdueStateName, null);
+ private OverdueChangeInternalEvent createOverdueEvent(final T overdueable, final String previousOverdueStateName, final String nextOverdueStateName, final InternalCallContext context) throws BlockingApiException {
+ return new DefaultOverdueChangeEvent(overdueable.getId(), Blockable.Type.get(overdueable), previousOverdueStateName, nextOverdueStateName, context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId());
}
protected void storeNewState(final T blockable, final OverdueState<T> nextOverdueState, final InternalCallContext context) throws OverdueException {
diff --git a/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentErrorEvent.java b/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentErrorEvent.java
index a8d7baf..9c88a36 100644
--- a/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentErrorEvent.java
+++ b/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentErrorEvent.java
@@ -18,42 +18,45 @@ package com.ning.billing.payment.api;
import java.util.UUID;
+import com.ning.billing.util.events.DefaultBusInternalEvent;
+import com.ning.billing.util.events.PaymentErrorInternalEvent;
+
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.ning.billing.util.entity.EntityBase;
-import com.ning.billing.util.events.PaymentErrorInternalEvent;
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "error")
-public class DefaultPaymentErrorEvent extends EntityBase implements PaymentErrorInternalEvent {
+public class DefaultPaymentErrorEvent extends DefaultBusInternalEvent implements PaymentErrorInternalEvent {
+ private final UUID id;
private final String message;
private final UUID accountId;
private final UUID invoiceId;
private final UUID paymentId;
- private final UUID userToken;
@JsonCreator
- public DefaultPaymentErrorEvent(@JsonProperty("id") final UUID id,
+ public DefaultPaymentErrorEvent(@JsonProperty("id") final UUID id, /* not used */
@JsonProperty("accountId") final UUID accountId,
@JsonProperty("invoiceId") final UUID invoiceId,
@JsonProperty("paymentId") final UUID paymentId,
@JsonProperty("message") final String message,
- @JsonProperty("userToken") final UUID userToken) {
- super(id);
+ @JsonProperty("userToken") final UUID userToken,
+ @JsonProperty("accountRecordId") final Long accountRecordId,
+ @JsonProperty("tenantRecordId") final Long tenantRecordId) {
+ super(userToken, accountRecordId, tenantRecordId);
+ this.id = id;
this.message = message;
this.accountId = accountId;
this.invoiceId = invoiceId;
this.paymentId = paymentId;
- this.userToken = userToken;
}
public DefaultPaymentErrorEvent(final UUID accountId,
- final UUID invoiceId, final UUID paymentId, final String message, final UUID userToken) {
- this(UUID.randomUUID(), accountId, invoiceId, paymentId, message, userToken);
+ final UUID invoiceId, final UUID paymentId, final String message, final UUID userToken, final Long accountRecordId, final Long tenantRecordId) {
+ this(UUID.randomUUID(), accountId, invoiceId, paymentId, message, userToken, accountRecordId, tenantRecordId);
}
@@ -63,10 +66,6 @@ public class DefaultPaymentErrorEvent extends EntityBase implements PaymentError
return BusEventType.PAYMENT_ERROR;
}
- @Override
- public UUID getUserToken() {
- return userToken;
- }
@Override
public String getMessage() {
@@ -100,8 +99,6 @@ public class DefaultPaymentErrorEvent extends EntityBase implements PaymentError
result = prime * result + ((message == null) ? 0 : message.hashCode());
result = prime * result
+ ((paymentId == null) ? 0 : paymentId.hashCode());
- result = prime * result
- + ((userToken == null) ? 0 : userToken.hashCode());
return result;
}
@@ -146,13 +143,6 @@ public class DefaultPaymentErrorEvent extends EntityBase implements PaymentError
} else if (!paymentId.equals(other.paymentId)) {
return false;
}
- if (userToken == null) {
- if (other.userToken != null) {
- return false;
- }
- } else if (!userToken.equals(other.userToken)) {
- return false;
- }
return true;
}
@@ -161,6 +151,6 @@ public class DefaultPaymentErrorEvent extends EntityBase implements PaymentError
public String toString() {
return "DefaultPaymentErrorEvent [message=" + message + ", accountId="
+ accountId + ", invoiceId=" + invoiceId + ", paymentId="
- + paymentId + ", userToken=" + userToken + "]";
+ + paymentId + ", userToken=" + getUserToken() + "]";
}
}
diff --git a/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentInfoEvent.java b/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentInfoEvent.java
index a64a63c..eb8ea64 100644
--- a/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentInfoEvent.java
+++ b/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentInfoEvent.java
@@ -21,13 +21,14 @@ import java.util.UUID;
import org.joda.time.DateTime;
+import com.ning.billing.util.events.DefaultBusInternalEvent;
+import com.ning.billing.util.events.PaymentInfoInternalEvent;
+
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.ning.billing.util.entity.EntityBase;
-import com.ning.billing.util.events.PaymentInfoInternalEvent;
-public class DefaultPaymentInfoEvent extends EntityBase implements PaymentInfoInternalEvent {
+public class DefaultPaymentInfoEvent extends DefaultBusInternalEvent implements PaymentInfoInternalEvent {
private final UUID accountId;
private final UUID invoiceId;
@@ -41,7 +42,7 @@ public class DefaultPaymentInfoEvent extends EntityBase implements PaymentInfoIn
private final String extSecondPaymentRefId;
@JsonCreator
- public DefaultPaymentInfoEvent(@JsonProperty("id") final UUID id,
+ public DefaultPaymentInfoEvent(@JsonProperty("id") final UUID id, /* not used */
@JsonProperty("accountId") final UUID accountId,
@JsonProperty("invoiceId") final UUID invoiceId,
@JsonProperty("paymentId") final UUID paymentId,
@@ -51,8 +52,10 @@ public class DefaultPaymentInfoEvent extends EntityBase implements PaymentInfoIn
@JsonProperty("extFirstPaymentRefId") final String extFirstPaymentRefId,
@JsonProperty("extSecondPaymentRefId") final String extSecondPaymentRefId,
@JsonProperty("userToken") final UUID userToken,
- @JsonProperty("effectiveDate") final DateTime effectiveDate) {
- super(id);
+ @JsonProperty("effectiveDate") final DateTime effectiveDate,
+ @JsonProperty("accountRecordId") final Long accountRecordId,
+ @JsonProperty("tenantRecordId") final Long tenantRecordId) {
+ super(userToken, accountRecordId, tenantRecordId);
this.accountId = accountId;
this.invoiceId = invoiceId;
this.paymentId = paymentId;
@@ -68,12 +71,14 @@ public class DefaultPaymentInfoEvent extends EntityBase implements PaymentInfoIn
public DefaultPaymentInfoEvent(final UUID accountId, final UUID invoiceId,
final UUID paymentId, final BigDecimal amount, final Integer paymentNumber,
- final PaymentStatus status, final String extFirstPaymentRefId, final String extSecondPaymentRefId, final UUID userToken, final DateTime effectiveDate) {
- this(UUID.randomUUID(), accountId, invoiceId, paymentId, amount, paymentNumber, status, extFirstPaymentRefId, extSecondPaymentRefId, userToken, effectiveDate);
+ final PaymentStatus status, final String extFirstPaymentRefId, final String extSecondPaymentRefId, final UUID userToken,
+ final DateTime effectiveDatefinal, Long accountRecordId, final Long tenantRecordId) {
+ this(UUID.randomUUID(), accountId, invoiceId, paymentId, amount, paymentNumber, status, extFirstPaymentRefId, extSecondPaymentRefId, userToken,
+ effectiveDatefinal, accountRecordId, tenantRecordId);
}
public DefaultPaymentInfoEvent(final DefaultPaymentInfoEvent src) {
- this(src.id,
+ this(UUID.randomUUID(),
src.accountId,
src.invoiceId,
src.paymentId,
@@ -83,7 +88,9 @@ public class DefaultPaymentInfoEvent extends EntityBase implements PaymentInfoIn
src.extFirstPaymentRefId,
src.extSecondPaymentRefId,
src.userToken,
- src.effectiveDate);
+ src.effectiveDate,
+ src.getAccountRecordId(),
+ src.getTenantRecordId());
}
@@ -98,12 +105,6 @@ public class DefaultPaymentInfoEvent extends EntityBase implements PaymentInfoIn
return userToken;
}
-
- @Override
- public UUID getId() {
- return id;
- }
-
@Override
public UUID getAccountId() {
return accountId;
diff --git a/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java b/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
index 414afe8..5c59ffd 100644
--- a/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
+++ b/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
@@ -213,7 +213,8 @@ public class PaymentProcessor extends ProcessorBase {
// Note that at this point, we don't know the exact invoice balance (see getAndValidatePaymentAmount() below).
// This means that events will be posted for null and zero dollar invoices (e.g. trials).
final PaymentErrorInternalEvent event = new DefaultPaymentErrorEvent(account.getId(), invoiceId, null,
- ErrorCode.PAYMENT_NO_DEFAULT_PAYMENT_METHOD.toString(), context.getUserToken());
+ ErrorCode.PAYMENT_NO_DEFAULT_PAYMENT_METHOD.toString(), context.getUserToken(),
+ context.getAccountRecordId(), context.getTenantRecordId());
postPaymentEvent(event, account.getId(), context);
throw e;
}
@@ -443,7 +444,8 @@ public class PaymentProcessor extends ProcessorBase {
// Create Bus event
event = new DefaultPaymentInfoEvent(account.getId(),
invoice.getId(), payment.getId(), payment.getAmount(), payment.getPaymentNumber(), paymentStatus,
- paymentPluginInfo.getExtFirstReferenceId(), paymentPluginInfo.getExtSecondReferenceId(), context.getUserToken(), payment.getEffectiveDate());
+ paymentPluginInfo.getExtFirstReferenceId(), paymentPluginInfo.getExtSecondReferenceId(), context.getUserToken(), payment.getEffectiveDate(),
+ context.getAccountRecordId(), context.getTenantRecordId());
break;
case ERROR:
@@ -460,7 +462,8 @@ public class PaymentProcessor extends ProcessorBase {
log.info(String.format("Could not process payment for account %s, invoice %s, error = %s",
account.getId(), invoice.getId(), paymentPluginInfo.getGatewayError()));
- event = new DefaultPaymentErrorEvent(account.getId(), invoice.getId(), paymentInput.getId(), paymentPluginInfo.getGatewayError(), context.getUserToken());
+ event = new DefaultPaymentErrorEvent(account.getId(), invoice.getId(), paymentInput.getId(), paymentPluginInfo.getGatewayError(), context.getUserToken(),
+ context.getAccountRecordId(), context.getTenantRecordId());
throw new PaymentApiException(ErrorCode.PAYMENT_CREATE_PAYMENT, account.getId(), paymentPluginInfo.getGatewayError());
default:
diff --git a/payment/src/test/java/com/ning/billing/payment/api/TestEventJson.java b/payment/src/test/java/com/ning/billing/payment/api/TestEventJson.java
index 997c6dd..1fde26e 100644
--- a/payment/src/test/java/com/ning/billing/payment/api/TestEventJson.java
+++ b/payment/src/test/java/com/ning/billing/payment/api/TestEventJson.java
@@ -33,7 +33,7 @@ public class TestEventJson extends PaymentTestSuite {
@Test(groups = "fast")
public void testPaymentErrorEvent() throws Exception {
- final PaymentErrorInternalEvent e = new DefaultPaymentErrorEvent(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), "no message", UUID.randomUUID());
+ final PaymentErrorInternalEvent e = new DefaultPaymentErrorEvent(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), "no message", UUID.randomUUID(), 1L, 1L);
final String json = mapper.writeValueAsString(e);
final Class<?> claz = Class.forName(DefaultPaymentErrorEvent.class.getName());
@@ -43,7 +43,8 @@ public class TestEventJson extends PaymentTestSuite {
@Test(groups = "fast")
public void testPaymentInfoEvent() throws Exception {
- final PaymentInfoInternalEvent e = new DefaultPaymentInfoEvent(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), new BigDecimal(12.9), new Integer(13), PaymentStatus.SUCCESS, "ext-ref1-12345", "ext-ref2-12345", UUID.randomUUID(), new DateTime());
+ final PaymentInfoInternalEvent e = new DefaultPaymentInfoEvent(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), new BigDecimal(12.9), new Integer(13), PaymentStatus.SUCCESS, "ext-ref1-12345", "ext-ref2-12345",
+ UUID.randomUUID(), new DateTime(), 1L, 1L);
final String json = mapper.writeValueAsString(e);
final Class<?> clazz = Class.forName(DefaultPaymentInfoEvent.class.getName());
diff --git a/payment/src/test/java/com/ning/billing/payment/MockInvoiceCreationEvent.java b/payment/src/test/java/com/ning/billing/payment/MockInvoiceCreationEvent.java
index ec9e7e3..4590ed2 100644
--- a/payment/src/test/java/com/ning/billing/payment/MockInvoiceCreationEvent.java
+++ b/payment/src/test/java/com/ning/billing/payment/MockInvoiceCreationEvent.java
@@ -21,11 +21,12 @@ import java.util.UUID;
import org.joda.time.LocalDate;
+import com.ning.billing.catalog.api.Currency;
+import com.ning.billing.util.events.InvoiceCreationInternalEvent;
+
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.ning.billing.catalog.api.Currency;
-import com.ning.billing.util.events.InvoiceCreationInternalEvent;
public class MockInvoiceCreationEvent implements InvoiceCreationInternalEvent {
@@ -161,5 +162,13 @@ public class MockInvoiceCreationEvent implements InvoiceCreationInternalEvent {
return true;
}
+ @Override
+ public Long getTenantRecordId() {
+ return 1L;
+ }
+ @Override
+ public Long getAccountRecordId() {
+ return 1L;
+ }
}
diff --git a/util/src/main/java/com/ning/billing/util/events/PaymentInfoInternalEvent.java b/util/src/main/java/com/ning/billing/util/events/PaymentInfoInternalEvent.java
index d02421b..33f4f6f 100644
--- a/util/src/main/java/com/ning/billing/util/events/PaymentInfoInternalEvent.java
+++ b/util/src/main/java/com/ning/billing/util/events/PaymentInfoInternalEvent.java
@@ -21,9 +21,8 @@ import java.util.UUID;
import org.joda.time.DateTime;
import com.ning.billing.payment.api.PaymentStatus;
-import com.ning.billing.util.entity.Entity;
-public interface PaymentInfoInternalEvent extends Entity, BusInternalEvent {
+public interface PaymentInfoInternalEvent extends BusInternalEvent {
public UUID getPaymentId();