killbill-memoizeit
Changes
beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java 250(+126 -124)
entitlement/src/main/java/com/ning/billing/entitlement/api/timeline/DefaultEntitlementTimelineApi.java 2(+1 -1)
invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDateNotifier.java 18(+6 -12)
junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestDefaultEntitlementBillingApi.java 6(+3 -3)
overdue/pom.xml 13(+6 -7)
overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java 15(+4 -11)
Details
diff --git a/analytics/src/main/java/com/ning/billing/analytics/dao/BusinessAccountBinder.java b/analytics/src/main/java/com/ning/billing/analytics/dao/BusinessAccountBinder.java
index 6478536..b9da3fa 100644
--- a/analytics/src/main/java/com/ning/billing/analytics/dao/BusinessAccountBinder.java
+++ b/analytics/src/main/java/com/ning/billing/analytics/dao/BusinessAccountBinder.java
@@ -50,12 +50,12 @@ public @interface BusinessAccountBinder
final DateTime dateTimeNow = new DateTime(DateTimeZone.UTC);
if (account.getCreatedDt() != null) {
- q.bind("created_dt", account.getCreatedDt().getMillis());
+ q.bind("created_date", account.getCreatedDt().getMillis());
}
else {
- q.bind("created_dt", dateTimeNow.getMillis());
+ q.bind("created_date", dateTimeNow.getMillis());
}
- q.bind("updated_dt", dateTimeNow.getMillis());
+ q.bind("updated_date", dateTimeNow.getMillis());
q.bind("account_key", account.getKey());
q.bind("balance", account.getRoundedBalance());
diff --git a/analytics/src/main/resources/com/ning/billing/analytics/dao/BusinessAccountDao.sql.stg b/analytics/src/main/resources/com/ning/billing/analytics/dao/BusinessAccountDao.sql.stg
index 55f03e8..10f27b8 100644
--- a/analytics/src/main/resources/com/ning/billing/analytics/dao/BusinessAccountDao.sql.stg
+++ b/analytics/src/main/resources/com/ning/billing/analytics/dao/BusinessAccountDao.sql.stg
@@ -3,8 +3,8 @@ group BusinessAccount;
getAccount(account_key) ::= <<
select
account_key
- , created_dt
- , updated_dt
+ , created_date
+ , updated_date
, balance
, tags
, last_invoice_date
@@ -22,8 +22,8 @@ getAccount(account_key) ::= <<
createAccount() ::= <<
insert into bac(
account_key
- , created_dt
- , updated_dt
+ , created_date
+ , updated_date
, balance
, tags
, last_invoice_date
@@ -34,8 +34,8 @@ createAccount() ::= <<
, billing_address_country
) values (
:account_key
- , :created_dt
- , :updated_dt
+ , :created_date
+ , :updated_date
, :balance
, :tags
, :last_invoice_date
@@ -49,7 +49,7 @@ createAccount() ::= <<
saveAccount() ::= <<
update bac set
- updated_dt=:updated_dt
+ updated_date=:updated_date
, balance=:balance
, tags=:tags
, last_invoice_date=:last_invoice_date
diff --git a/analytics/src/main/resources/com/ning/billing/analytics/ddl.sql b/analytics/src/main/resources/com/ning/billing/analytics/ddl.sql
index 6489b12..7240236 100644
--- a/analytics/src/main/resources/com/ning/billing/analytics/ddl.sql
+++ b/analytics/src/main/resources/com/ning/billing/analytics/ddl.sql
@@ -40,8 +40,8 @@ create index bst_key_index on bst (event_key, requested_timestamp asc);
drop table if exists bac;
create table bac (
account_key varchar(50) not null
-, created_dt bigint not null
-, updated_dt bigint not null
+, created_date bigint not null
+, updated_date bigint not null
, balance numeric(10, 4) default 0
, tags varchar(500) default null
, last_invoice_date bigint default null
diff --git a/api/src/main/java/com/ning/billing/BillingExceptionBase.java b/api/src/main/java/com/ning/billing/BillingExceptionBase.java
index 3a458fc..a4ff3cd 100644
--- a/api/src/main/java/com/ning/billing/BillingExceptionBase.java
+++ b/api/src/main/java/com/ning/billing/BillingExceptionBase.java
@@ -35,6 +35,13 @@ public class BillingExceptionBase extends Exception {
this.code = code;
this.cause = cause;
}
+
+ public BillingExceptionBase(BillingExceptionBase cause) {
+ this.formattedMsg = cause.getMessage();
+ this.code = cause.getCode();
+ this.cause = cause;
+ }
+
public BillingExceptionBase(Throwable cause, ErrorCode code, final Object... args) {
String tmp = null;
diff --git a/api/src/main/java/com/ning/billing/config/EntitlementConfig.java b/api/src/main/java/com/ning/billing/config/EntitlementConfig.java
index c73530f..12418c6 100644
--- a/api/src/main/java/com/ning/billing/config/EntitlementConfig.java
+++ b/api/src/main/java/com/ning/billing/config/EntitlementConfig.java
@@ -24,19 +24,9 @@ import com.google.common.annotations.VisibleForTesting;
public interface EntitlementConfig extends NotificationConfig, KillbillConfig {
@Override
- @Config("killbill.entitlement.dao.claim.time")
- @Default("60000")
- public long getDaoClaimTimeMs();
-
- @Override
- @Config("killbill.entitlement.dao.ready.max")
- @Default("10")
- public int getDaoMaxReadyEvents();
-
- @Override
@Config("killbill.entitlement.engine.notifications.sleep")
@Default("500")
- public long getNotificationSleepTimeMs();
+ public long getSleepTimeMs();
@Override
@Config("killbill.notifications.off")
diff --git a/api/src/main/java/com/ning/billing/config/InvoiceConfig.java b/api/src/main/java/com/ning/billing/config/InvoiceConfig.java
index 18972eb..407f4d3 100644
--- a/api/src/main/java/com/ning/billing/config/InvoiceConfig.java
+++ b/api/src/main/java/com/ning/billing/config/InvoiceConfig.java
@@ -21,22 +21,12 @@ import org.skife.config.Default;
public interface InvoiceConfig extends NotificationConfig, KillbillConfig {
- @Override
- @Config("killbill.invoice.dao.claim.time")
- @Default("60000")
- public long getDaoClaimTimeMs();
-
- @Override
- @Config("killbill.invoice.dao.ready.max")
- @Default("10")
- public int getDaoMaxReadyEvents();
-
- @Override
+ @Override
@Config("killbill.invoice.engine.notifications.sleep")
@Default("500")
- public long getNotificationSleepTimeMs();
+ public long getSleepTimeMs();
- @Override
+ @Override
@Config("killbill.notifications.off")
@Default("false")
public boolean isNotificationProcessingOff();
diff --git a/api/src/main/java/com/ning/billing/config/NotificationConfig.java b/api/src/main/java/com/ning/billing/config/NotificationConfig.java
index 82f68b6..630a2d6 100644
--- a/api/src/main/java/com/ning/billing/config/NotificationConfig.java
+++ b/api/src/main/java/com/ning/billing/config/NotificationConfig.java
@@ -17,13 +17,6 @@
package com.ning.billing.config;
-public interface NotificationConfig {
-
- public long getDaoClaimTimeMs();
-
- public int getDaoMaxReadyEvents();
-
- public long getNotificationSleepTimeMs();
-
+public interface NotificationConfig extends PersistentQueueConfig {
public boolean isNotificationProcessingOff();
}
diff --git a/api/src/main/java/com/ning/billing/config/PaymentConfig.java b/api/src/main/java/com/ning/billing/config/PaymentConfig.java
index 599232c..f606039 100644
--- a/api/src/main/java/com/ning/billing/config/PaymentConfig.java
+++ b/api/src/main/java/com/ning/billing/config/PaymentConfig.java
@@ -35,19 +35,9 @@ public interface PaymentConfig extends NotificationConfig, KillbillConfig {
public List<Integer> getPaymentRetryDays();
@Override
- @Config("killbill.payment.dao.claim.time")
- @Default("60000")
- public long getDaoClaimTimeMs();
-
- @Override
- @Config("killbill.payment.dao.ready.max")
- @Default("10")
- public int getDaoMaxReadyEvents();
-
- @Override
@Config("killbill.payment.engine.notifications.sleep")
@Default("500")
- public long getNotificationSleepTimeMs();
+ public long getSleepTimeMs();
@Override
@Config("killbill.payment.engine.events.off")
diff --git a/api/src/main/java/com/ning/billing/ErrorCode.java b/api/src/main/java/com/ning/billing/ErrorCode.java
index 3aa190b..860ae6c 100644
--- a/api/src/main/java/com/ning/billing/ErrorCode.java
+++ b/api/src/main/java/com/ning/billing/ErrorCode.java
@@ -193,6 +193,7 @@ public enum ErrorCode {
*/
OVERDUE_CAT_ERROR_ENCOUNTERED(5001,"Catalog error encountered on Overdueable: id='%s', type='%s'"),
OVERDUE_TYPE_NOT_SUPPORTED(5002,"Overdue of this type is not supported: id='%s', type='%s'"),
+ OVERDUE_NO_REEVALUATION_INTERVAL(5003,"No valid reevaluation interval for state (name: %s)"),
/*
*
* Range 6000: Blocking system
diff --git a/api/src/main/java/com/ning/billing/junction/api/BlockingApi.java b/api/src/main/java/com/ning/billing/junction/api/BlockingApi.java
index 18c6799..d7fc678 100644
--- a/api/src/main/java/com/ning/billing/junction/api/BlockingApi.java
+++ b/api/src/main/java/com/ning/billing/junction/api/BlockingApi.java
@@ -25,11 +25,11 @@ public interface BlockingApi {
public BlockingState getBlockingStateFor(Blockable overdueable);
- public BlockingState getBlockingStateFor(UUID overdueableId, Blockable.Type type);
+ public BlockingState getBlockingStateFor(UUID overdueableId);
public SortedSet<BlockingState> getBlockingHistory(Blockable overdueable);
- public SortedSet<BlockingState> getBlockingHistory(UUID overdueableId, Blockable.Type type);
+ public SortedSet<BlockingState> getBlockingHistory(UUID overdueableId);
public <T extends Blockable> void setBlockingState(BlockingState state);
diff --git a/api/src/main/java/com/ning/billing/junction/api/BlockingState.java b/api/src/main/java/com/ning/billing/junction/api/BlockingState.java
index fcb38fc..08202a2 100644
--- a/api/src/main/java/com/ning/billing/junction/api/BlockingState.java
+++ b/api/src/main/java/com/ning/billing/junction/api/BlockingState.java
@@ -21,6 +21,8 @@ import org.joda.time.DateTime;
public interface BlockingState extends Comparable<BlockingState> {
public abstract String getStateName();
+
+ public abstract Blockable.Type getType();
public abstract DateTime getTimestamp();
diff --git a/api/src/main/java/com/ning/billing/junction/api/DefaultBlockingState.java b/api/src/main/java/com/ning/billing/junction/api/DefaultBlockingState.java
index f2e632d..332cb85 100644
--- a/api/src/main/java/com/ning/billing/junction/api/DefaultBlockingState.java
+++ b/api/src/main/java/com/ning/billing/junction/api/DefaultBlockingState.java
@@ -23,8 +23,6 @@ import org.joda.time.DateTime;
public class DefaultBlockingState implements BlockingState{
- private static final String CLEAR_STATE = "clear";
-
private static BlockingState clearState= null;
private final UUID blockingId;
@@ -38,7 +36,7 @@ public class DefaultBlockingState implements BlockingState{
public static BlockingState getClearState() {
if(clearState == null) {
- clearState = new DefaultBlockingState(null, CLEAR_STATE, null, null, false, false, false);
+ clearState = new DefaultBlockingState(null, BlockingApi.CLEAR_STATE_NAME, null, null, false, false, false);
}
return clearState;
}
@@ -92,6 +90,7 @@ public class DefaultBlockingState implements BlockingState{
return stateName;
}
+ @Override
public Blockable.Type getType() {
return type;
}
diff --git a/api/src/main/java/com/ning/billing/overdue/config/api/OverdueError.java b/api/src/main/java/com/ning/billing/overdue/config/api/OverdueError.java
index b71b299..78f62c6 100644
--- a/api/src/main/java/com/ning/billing/overdue/config/api/OverdueError.java
+++ b/api/src/main/java/com/ning/billing/overdue/config/api/OverdueError.java
@@ -20,6 +20,15 @@ import com.ning.billing.BillingExceptionBase;
import com.ning.billing.ErrorCode;
public class OverdueError extends BillingExceptionBase {
+
+ public OverdueError(BillingExceptionBase cause) {
+ super(cause);
+ }
+
+ public OverdueError(Throwable cause, int code, String msg) {
+ super(cause, code, msg);
+ }
+
private static final long serialVersionUID = 1L;
public OverdueError(Throwable cause, ErrorCode code, Object... args) {
diff --git a/api/src/main/java/com/ning/billing/overdue/config/api/OverdueStateSet.java b/api/src/main/java/com/ning/billing/overdue/config/api/OverdueStateSet.java
index 796e482..693fa8f 100644
--- a/api/src/main/java/com/ning/billing/overdue/config/api/OverdueStateSet.java
+++ b/api/src/main/java/com/ning/billing/overdue/config/api/OverdueStateSet.java
@@ -18,18 +18,15 @@ package com.ning.billing.overdue.config.api;
import org.joda.time.DateTime;
-import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.junction.api.Blockable;
+import com.ning.billing.overdue.OverdueApiException;
import com.ning.billing.overdue.OverdueState;
public interface OverdueStateSet<T extends Blockable> {
- public abstract OverdueState<T> findClearState() throws CatalogApiException;
+ public abstract OverdueState<T> findClearState() throws OverdueApiException;
- public abstract OverdueState<T> findState(String stateName) throws CatalogApiException;
-
- public abstract OverdueState<T> calculateOverdueState(BillingState<T> billingState, DateTime now) throws CatalogApiException;
-
- public abstract DateTime dateOfNextCheck(BillingState<T> billingState, DateTime now);
+ public abstract OverdueState<T> findState(String stateName) throws OverdueApiException;
+ public abstract OverdueState<T> calculateOverdueState(BillingState<T> billingState, DateTime now) throws OverdueApiException;
}
\ No newline at end of file
diff --git a/api/src/main/java/com/ning/billing/overdue/OverdueState.java b/api/src/main/java/com/ning/billing/overdue/OverdueState.java
index 0679416..3de2c94 100644
--- a/api/src/main/java/com/ning/billing/overdue/OverdueState.java
+++ b/api/src/main/java/com/ning/billing/overdue/OverdueState.java
@@ -16,6 +16,8 @@
package com.ning.billing.overdue;
+import org.joda.time.Period;
+
import com.ning.billing.junction.api.Blockable;
@@ -33,4 +35,6 @@ public interface OverdueState<T extends Blockable> {
public boolean blockChanges();
public boolean isClearState();
+
+ public Period getReevaluationInterval() throws OverdueApiException;
}
\ No newline at end of file
diff --git a/api/src/main/java/com/ning/billing/overdue/OverdueUserApi.java b/api/src/main/java/com/ning/billing/overdue/OverdueUserApi.java
index 74764b3..3101c10 100644
--- a/api/src/main/java/com/ning/billing/overdue/OverdueUserApi.java
+++ b/api/src/main/java/com/ning/billing/overdue/OverdueUserApi.java
@@ -16,15 +16,13 @@
package com.ning.billing.overdue;
-import com.ning.billing.catalog.api.CatalogApiException;
-import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.overdue.config.api.BillingState;
import com.ning.billing.overdue.config.api.OverdueError;
public interface OverdueUserApi {
- public <T extends Blockable> OverdueState<T> refreshOverdueStateFor(T overdueable) throws OverdueError, CatalogApiException, EntitlementUserApiException;
+ public <T extends Blockable> OverdueState<T> refreshOverdueStateFor(T overdueable) throws OverdueError, OverdueApiException;
public <T extends Blockable> void setOverrideBillingStateForAccount(T overdueable, BillingState<T> state) throws OverdueError;
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java
index 2dfe2ee..edc9ec1 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java
@@ -14,127 +14,129 @@
* under the License.
*/
-//package com.ning.billing.beatrix.integration.overdue;
-//
-//import static org.testng.Assert.assertNotNull;
-//
-//import java.io.ByteArrayInputStream;
-//import java.io.InputStream;
-//
-//import org.joda.time.DateTime;
-//import org.joda.time.Interval;
-//
-//import com.google.inject.Inject;
-//import com.ning.billing.account.api.Account;
-//import com.ning.billing.beatrix.integration.TestIntegrationBase;
-//import com.ning.billing.catalog.api.BillingPeriod;
-//import com.ning.billing.catalog.api.Duration;
-//import com.ning.billing.catalog.api.PlanPhaseSpecifier;
-//import com.ning.billing.catalog.api.PriceListSet;
-//import com.ning.billing.catalog.api.ProductCategory;
-//import com.ning.billing.entitlement.api.user.SubscriptionBundle;
-//import com.ning.billing.entitlement.api.user.SubscriptionData;
-//import com.ning.billing.junction.api.BlockingApi;
-//import com.ning.billing.overdue.config.OverdueConfig;
-//import com.ning.billing.payment.provider.MockPaymentProviderPlugin;
-//import com.ning.billing.util.clock.ClockMock;
-//import com.ning.billing.util.config.XMLLoader;
-//
-//public class TestOverdueIntegration extends TestIntegrationBase {
-// private final String configXml =
-// "<overdueConfig>" +
-// " <bundleOverdueStates>" +
-// " <state name=\"OD1\">" +
-// " <condition>" +
-// " <timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
-// " <unit>MONTHS</unit><number>1</number>" +
-// " </timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
-// " </condition>" +
-// " <externalMessage>Reached OD1</externalMessage>" +
-// " <blockChanges>true</blockChanges>" +
-// " <disableEntitlementAndChangesBlocked>false</disableEntitlementAndChangesBlocked>" +
-// " </state>" +
-// " <state name=\"OD2\">" +
-// " <condition>" +
-// " <timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
-// " <unit>MONTHS</unit><number>2</number>" +
-// " </timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
-// " </condition>" +
-// " <externalMessage>Reached OD1</externalMessage>" +
-// " <blockChanges>true</blockChanges>" +
-// " <disableEntitlementAndChangesBlocked>true</disableEntitlementAndChangesBlocked>" +
-// " </state>" +
-// " </bundleOverdueStates>" +
-// "</overdueConfig>";
-// private OverdueConfig config;
-//
-// @Inject
-// private ClockMock clock;
-//
-// @Inject
-// private MockPaymentProviderPlugin paymentPlugin;
-//
-// @Inject
-// private BlockingApi blockingApi;
-//
-// private Account account;
-// private SubscriptionBundle bundle;
-// private String productName;
-// private BillingPeriod term;
-// private String planSetName;
-//
-// long twoWeeks = new Interval(clock.getUTCNow(), clock.getUTCNow().plusWeeks(2)).toDurationMillis();
-// long fourWeeks = new Interval(clock.getUTCNow(), clock.getUTCNow().plusWeeks(4)).toDurationMillis();
-//
-// //@BeforeMethod
-// public void setup() throws Exception {
-// InputStream is = new ByteArrayInputStream(configXml.getBytes());
-// config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class);
-// Account account = accountUserApi.createAccount(getAccountData(25), null, null, context);
-// assertNotNull(account);
-//
-// bundle = entitlementUserApi.createBundleForAccount(account.getId(), "whatever", context);
-//
-// productName = "Shotgun";
-// term = BillingPeriod.MONTHLY;
-// planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
-//
-// // create account
-// // set mock payments to fail
-// // reset clock
-// // configure basic OD state rules for 2 states OD1 1-2month, OD2 2-3 month
-// }
-//
-// //@AfterMethod
-// public void cleanup(){
-// // Clear databases
-// }
-//
-// public void testBasicOverdueState() throws Exception {
-// DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
-// clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
-//
-//
-// // set next invoice to fail and create network
-// paymentPlugin.makeNextInvoiceFail();
-// SubscriptionData baseSubscription = subscriptionDataFromSubscription(entitlementUserApi.createSubscription(bundle.getId(),
-// new PlanPhaseSpecifier(productName, ProductCategory.BASE, term, planSetName, null), null, context));
-// assertNotNull(baseSubscription);
-//
-//
-// // advance time 2weeks
-// clock.addDeltaFromReality(twoWeeks);
-//
-// // should still be in clear state
-// blockingApi.getBlockingStateFor(bundle);
-//
-// // set next invoice to fail and advance time 1 month
-// clock.addDeltaFromReality(fourWeeks);
-//
-// // should now be in OD1 state
-// // set next invoice to fail and advance time 1 month
-// // should now be in OD2 state
-//
-//
-// }
-//}
+package com.ning.billing.beatrix.integration.overdue;
+
+import static org.testng.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.joda.time.DateTime;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Guice;
+import org.testng.annotations.Test;
+
+import com.google.inject.Inject;
+import com.ning.billing.account.api.Account;
+import com.ning.billing.beatrix.integration.MockModule;
+import com.ning.billing.beatrix.integration.TestIntegrationBase;
+import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.PlanPhaseSpecifier;
+import com.ning.billing.catalog.api.PriceListSet;
+import com.ning.billing.catalog.api.ProductCategory;
+import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.entitlement.api.user.SubscriptionData;
+import com.ning.billing.junction.api.BlockingApi;
+import com.ning.billing.junction.api.BlockingState;
+import com.ning.billing.overdue.config.OverdueConfig;
+import com.ning.billing.payment.provider.MockPaymentProviderPlugin;
+import com.ning.billing.util.clock.ClockMock;
+import com.ning.billing.util.config.XMLLoader;
+
+@Test(groups = "slow")
+@Guice(modules = {MockModule.class})
+public class TestOverdueIntegration extends TestIntegrationBase {
+ private final String configXml =
+ "<overdueConfig>" +
+ " <bundleOverdueStates>" +
+ " <state name=\"OD1\">" +
+ " <condition>" +
+ " <timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
+ " <unit>MONTHS</unit><number>1</number>" +
+ " </timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
+ " </condition>" +
+ " <externalMessage>Reached OD1</externalMessage>" +
+ " <blockChanges>true</blockChanges>" +
+ " <disableEntitlementAndChangesBlocked>false</disableEntitlementAndChangesBlocked>" +
+ " </state>" +
+ " <state name=\"OD2\">" +
+ " <condition>" +
+ " <timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
+ " <unit>MONTHS</unit><number>2</number>" +
+ " </timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
+ " </condition>" +
+ " <externalMessage>Reached OD1</externalMessage>" +
+ " <blockChanges>true</blockChanges>" +
+ " <disableEntitlementAndChangesBlocked>true</disableEntitlementAndChangesBlocked>" +
+ " </state>" +
+ " </bundleOverdueStates>" +
+ "</overdueConfig>";
+ private OverdueConfig config;
+
+ @Inject
+ private ClockMock clock;
+
+ @Inject
+ private MockPaymentProviderPlugin paymentPlugin;
+
+ @Inject
+ private BlockingApi blockingApi;
+
+ private Account account;
+ private SubscriptionBundle bundle;
+ private String productName;
+ private BillingPeriod term;
+ private String planSetName;
+
+ @BeforeMethod(groups = {"slow"})
+ public void setupOverdue() throws Exception {
+ InputStream is = new ByteArrayInputStream(configXml.getBytes());
+ config = XMLLoader.getObjectFromStreamNoValidation(is, OverdueConfig.class);
+ Account account = accountUserApi.createAccount(getAccountData(25), null, null, context);
+ assertNotNull(account);
+
+ bundle = entitlementUserApi.createBundleForAccount(account.getId(), "whatever", context);
+
+ productName = "Shotgun";
+ term = BillingPeriod.MONTHLY;
+ planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
+
+ // create account
+ // set mock payments to fail
+ // reset clock
+ // configure basic OD state rules for 2 states OD1 1-2month, OD2 2-3 month
+ }
+
+ @AfterMethod
+ public void cleanup(){
+ // Clear databases
+ }
+
+ @Test(groups={"slow"}, enabled = true)
+ public void testBasicOverdueState() throws Exception {
+ clock.setTime(new DateTime(2012, 5, 1, 0, 3, 42, 0));
+
+ // set next invoice to fail and create network
+ paymentPlugin.makeNextInvoiceFail();
+ SubscriptionData baseSubscription = subscriptionDataFromSubscription(entitlementUserApi.createSubscription(bundle.getId(),
+ new PlanPhaseSpecifier(productName, ProductCategory.BASE, term, planSetName, null), null, context));
+ assertNotNull(baseSubscription);
+
+ // advance time 2weeks
+ clock.addWeeks(2);
+
+ // should still be in clear state
+ BlockingState state = blockingApi.getBlockingStateFor(bundle);
+ Assert.assertEquals(state.getStateName(), BlockingApi.CLEAR_STATE_NAME);
+ // set next invoice to fail and advance time 1 month
+ clock.addWeeks(4);
+
+ // should now be in OD1 state
+ // set next invoice to fail and advance time 1 month
+ // should now be in OD2 state
+ clock.addWeeks(4);
+
+ }
+}
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java
index 579f47c..a408755 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java
@@ -85,7 +85,8 @@ public class TestIntegrationBase implements TestListenerStatus {
protected static final Logger log = LoggerFactory.getLogger(TestIntegration.class);
protected static long AT_LEAST_ONE_MONTH_MS = 31L * 24L * 3600L * 1000L;
- protected static final long DELAY = 10000;
+
+ protected static final long DELAY = 5000;
@Inject
protected IDBI dbi;
diff --git a/beatrix/src/test/resources/resource.properties b/beatrix/src/test/resources/resource.properties
index d63334b..a2c4ec1 100644
--- a/beatrix/src/test/resources/resource.properties
+++ b/beatrix/src/test/resources/resource.properties
@@ -1,7 +1,11 @@
killbill.catalog.uri=file:src/test/resources/catalogSample.xml
killbill.entitlement.dao.claim.time=60000
killbill.entitlement.dao.ready.max=1
-killbill.entitlement.engine.notifications.sleep=500
+killbill.payment.engine.notifications.sleep=100
+killbill.invoice.engine.notifications.sleep=100
+killbill.entitlement.engine.notifications.sleep=100
+killbill.billing.util.persistent.bus.sleep=100
+killbill.billing.util.persistent.bus.nbThreads=1
user.timezone=UTC
diff --git a/catalog/src/test/java/com/ning/billing/catalog/TestPlanPhase.java b/catalog/src/test/java/com/ning/billing/catalog/TestPlanPhase.java
index e25ac82..bee4e3d 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/TestPlanPhase.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/TestPlanPhase.java
@@ -58,23 +58,23 @@ public class TestPlanPhase {
DefaultPlanPhase ppDiscount = MockPlanPhase.create1USDMonthlyEvergreen().setPhaseType(PhaseType.DISCOUNT).setPlan(p);
DefaultPlanPhase ppTrial = MockPlanPhase.create30DayTrial().setPhaseType(PhaseType.TRIAL).setPlan(p);
DefaultPlanPhase ppEvergreen = MockPlanPhase.create1USDMonthlyEvergreen().setPhaseType(PhaseType.EVERGREEN).setPlan(p);
- DefaultPlanPhase ppFixedterm = MockPlanPhase.create1USDMonthlyEvergreen().setPhaseType(PhaseType.FIXEDTERM).setPlan(p);
+ DefaultPlanPhase ppFixedTerm = MockPlanPhase.create1USDMonthlyEvergreen().setPhaseType(PhaseType.FIXEDTERM).setPlan(p);
String ppnDiscount = DefaultPlanPhase.phaseName(p.getName(), ppDiscount.getPhaseType());
String ppnTrial = DefaultPlanPhase.phaseName(p.getName(), ppTrial.getPhaseType());
String ppnEvergreen = DefaultPlanPhase.phaseName(p.getName(), ppEvergreen.getPhaseType());
- String ppnFixedterm = DefaultPlanPhase.phaseName(p.getName(), ppFixedterm.getPhaseType());
+ String ppnFixedTerm = DefaultPlanPhase.phaseName(p.getName(), ppFixedTerm.getPhaseType());
Assert.assertEquals(ppnTrial, planNameExt + "trial");
Assert.assertEquals(ppnEvergreen, planNameExt + "evergreen");
- Assert.assertEquals(ppnFixedterm, planNameExt + "fixedterm");
+ Assert.assertEquals(ppnFixedTerm, planNameExt + "fixedterm");
Assert.assertEquals(ppnDiscount, planNameExt + "discount");
Assert.assertEquals(DefaultPlanPhase.planName(ppnDiscount),planName);
Assert.assertEquals(DefaultPlanPhase.planName(ppnTrial),planName);
Assert.assertEquals(DefaultPlanPhase.planName(ppnEvergreen), planName);
- Assert.assertEquals(DefaultPlanPhase.planName(ppnFixedterm), planName);
+ Assert.assertEquals(DefaultPlanPhase.planName(ppnFixedTerm), planName);
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/api/timeline/DefaultEntitlementTimelineApi.java b/entitlement/src/main/java/com/ning/billing/entitlement/api/timeline/DefaultEntitlementTimelineApi.java
index cf9db7c..9f73725 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/api/timeline/DefaultEntitlementTimelineApi.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/api/timeline/DefaultEntitlementTimelineApi.java
@@ -393,7 +393,7 @@ public class DefaultEntitlementTimelineApi implements EntitlementTimelineApi {
}
@Override
public String getExternalKey() {
- return null;
+ return externalKey;
}
};
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/engine/core/Engine.java b/entitlement/src/main/java/com/ning/billing/entitlement/engine/core/Engine.java
index accb829..344f47e 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/engine/core/Engine.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/engine/core/Engine.java
@@ -133,21 +133,15 @@ public class Engine implements EventListener, EntitlementService {
}
},
new NotificationConfig() {
+
@Override
- public boolean isNotificationProcessingOff() {
- return config.isNotificationProcessingOff();
- }
- @Override
- public long getNotificationSleepTimeMs() {
- return config.getNotificationSleepTimeMs();
- }
- @Override
- public int getDaoMaxReadyEvents() {
- return config.getDaoMaxReadyEvents();
+ public long getSleepTimeMs() {
+ return config.getSleepTimeMs();
}
+
@Override
- public long getDaoClaimTimeMs() {
- return config.getDaoClaimTimeMs();
+ public boolean isNotificationProcessingOff() {
+ return config.isNotificationProcessingOff();
}
});
} catch (NotificationQueueAlreadyExists e) {
diff --git a/entitlement/src/test/resources/entitlement.properties b/entitlement/src/test/resources/entitlement.properties
index af1c3fc..58f4f95 100644
--- a/entitlement/src/test/resources/entitlement.properties
+++ b/entitlement/src/test/resources/entitlement.properties
@@ -1,6 +1,8 @@
killbill.catalog.uri=file:src/test/resources/testInput.xml
killbill.entitlement.dao.claim.time=60000
killbill.entitlement.dao.ready.max=1
-killbill.entitlement.engine.notifications.sleep=500
+killbill.entitlement.engine.notifications.sleep=100
+killbill.billing.util.persistent.bus.sleep=100
+killbill.billing.util.persistent.bus.nbThreads=1
user.timezone=UTC
diff --git a/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDateNotifier.java b/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDateNotifier.java
index 28d15a8..d61e206 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDateNotifier.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDateNotifier.java
@@ -86,21 +86,15 @@ public class DefaultNextBillingDateNotifier implements NextBillingDateNotifier
}
},
new NotificationConfig() {
+
@Override
- public boolean isNotificationProcessingOff() {
- return config.isNotificationProcessingOff();
- }
- @Override
- public long getNotificationSleepTimeMs() {
- return config.getNotificationSleepTimeMs();
+ public long getSleepTimeMs() {
+ return config.getSleepTimeMs();
}
+
@Override
- public int getDaoMaxReadyEvents() {
- return config.getDaoMaxReadyEvents();
- }
- @Override
- public long getDaoClaimTimeMs() {
- return config.getDaoClaimTimeMs();
+ public boolean isNotificationProcessingOff() {
+ return config.isNotificationProcessingOff();
}
});
} catch (NotificationQueueAlreadyExists e) {
diff --git a/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTestBase.java b/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTestBase.java
index 08354db..91dbf7d 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTestBase.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTestBase.java
@@ -55,11 +55,7 @@ public abstract class InvoiceDaoTestBase extends InvoicingTestBase {
private final InvoiceConfig invoiceConfig = new InvoiceConfig() {
@Override
- public long getDaoClaimTimeMs() {throw new UnsupportedOperationException();}
- @Override
- public int getDaoMaxReadyEvents() {throw new UnsupportedOperationException();}
- @Override
- public long getNotificationSleepTimeMs() {throw new UnsupportedOperationException();}
+ public long getSleepTimeMs() {throw new UnsupportedOperationException();}
@Override
public boolean isNotificationProcessingOff() {throw new UnsupportedOperationException();}
@Override
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/DefaultInvoiceGeneratorTests.java b/invoice/src/test/java/com/ning/billing/invoice/tests/DefaultInvoiceGeneratorTests.java
index 1aaab2d..6c3dd65 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/DefaultInvoiceGeneratorTests.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/DefaultInvoiceGeneratorTests.java
@@ -68,17 +68,7 @@ public class DefaultInvoiceGeneratorTests extends InvoicingTestBase {
Clock clock = new DefaultClock();
InvoiceConfig invoiceConfig = new InvoiceConfig() {
@Override
- public long getDaoClaimTimeMs() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int getDaoMaxReadyEvents() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public long getNotificationSleepTimeMs() {
+ public long getSleepTimeMs() {
throw new UnsupportedOperationException();
}
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountJson.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountJson.java
index 2b7e409..82645a5 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountJson.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountJson.java
@@ -191,14 +191,14 @@ public class AccountJson extends AccountJsonSimple {
}
@JsonCreator
- public AccountJson(@JsonProperty("account_id") String acountId,
+ public AccountJson(@JsonProperty("accountId") String accountId,
@JsonProperty("name") String name,
- @JsonProperty("first_name_length") Integer length,
+ @JsonProperty("firstNameLength") Integer length,
@JsonProperty("external_key") String externalKey,
@JsonProperty("email") String email,
- @JsonProperty("billing_day") Integer billCycleDay,
+ @JsonProperty("billingDay") Integer billCycleDay,
@JsonProperty("currency") String currency,
- @JsonProperty("payment_provider") String paymentProvider,
+ @JsonProperty("paymentProvider") String paymentProvider,
@JsonProperty("timezone") String timeZone,
@JsonProperty("address1") String address1,
@JsonProperty("address2") String address2,
@@ -206,7 +206,7 @@ public class AccountJson extends AccountJsonSimple {
@JsonProperty("state") String state,
@JsonProperty("country") String country,
@JsonProperty("phone") String phone) {
- super(acountId, externalKey);
+ super(accountId, externalKey);
this.name = name;
this.length = length;
this.email = email;
@@ -279,7 +279,7 @@ public class AccountJson extends AccountJsonSimple {
final int prime = 31;
int result = 1;
result = prime * result
- + ((acountId == null) ? 0 : acountId.hashCode());
+ + ((accountId == null) ? 0 : accountId.hashCode());
result = prime * result
+ ((address1 == null) ? 0 : address1.hashCode());
result = prime * result
@@ -392,10 +392,10 @@ public class AccountJson extends AccountJsonSimple {
return false;
} else {
AccountJson other = (AccountJson) obj;
- if (acountId == null) {
- if (other.acountId != null)
+ if (accountId == null) {
+ if (other.accountId != null)
return false;
- } else if (!acountId.equals(other.acountId))
+ } else if (!accountId.equals(other.accountId))
return false;
}
return true;
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountJsonSimple.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountJsonSimple.java
index 548635e..d7e1b2d 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountJsonSimple.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountJsonSimple.java
@@ -22,25 +22,25 @@ import org.codehaus.jackson.map.annotate.JsonView;
public class AccountJsonSimple {
@JsonView(BundleTimelineViews.Base.class)
- protected final String acountId;
+ protected final String accountId;
@JsonView(BundleTimelineViews.Base.class)
protected final String externalKey;
public AccountJsonSimple() {
- this.acountId = null;
+ this.accountId = null;
this.externalKey = null;
}
@JsonCreator
- public AccountJsonSimple(@JsonProperty("account_id") String acountId,
- @JsonProperty("external_key") String externalKey) {
- this.acountId = acountId;
+ public AccountJsonSimple(@JsonProperty("accountId") String accountId,
+ @JsonProperty("externalKey") String externalKey) {
+ this.accountId = accountId;
this.externalKey = externalKey;
}
- public String getAcountId() {
- return acountId;
+ public String getAccountId() {
+ return accountId;
}
public String getExternalKey() {
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountTimelineJson.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountTimelineJson.java
index 8c242d0..881745a 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountTimelineJson.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountTimelineJson.java
@@ -16,8 +16,11 @@
package com.ning.billing.jaxrs.json;
import java.math.BigDecimal;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.Set;
+import java.util.UUID;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonProperty;
@@ -26,15 +29,16 @@ import org.codehaus.jackson.map.annotate.JsonView;
import com.ning.billing.account.api.Account;
import com.ning.billing.entitlement.api.timeline.BundleTimeline;
import com.ning.billing.invoice.api.Invoice;
+import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.payment.api.PaymentAttempt;
public class AccountTimelineJson {
@JsonView(BundleTimelineViews.ReadTimeline.class)
- private final List<PaymentJson> payments;
+ private final List<PaymentJsonWithBundleKeys> payments;
@JsonView(BundleTimelineViews.ReadTimeline.class)
- private final List<InvoiceJson> invoices;
+ private final List<InvoiceJsonWithBundleKeys> invoices;
@JsonView(BundleTimelineViews.ReadTimeline.class)
private final AccountJsonSimple account;
@@ -45,31 +49,67 @@ public class AccountTimelineJson {
@JsonCreator
public AccountTimelineJson(@JsonProperty("account") AccountJsonSimple account,
@JsonProperty("bundles") List<BundleJsonWithSubscriptions> bundles,
- @JsonProperty("invoices") List<InvoiceJson> invoices,
- @JsonProperty("payments") List<PaymentJson> payments) {
+ @JsonProperty("invoices") List<InvoiceJsonWithBundleKeys> invoices,
+ @JsonProperty("payments") List<PaymentJsonWithBundleKeys> payments) {
this.account = account;
this.bundles = bundles;
this.invoices = invoices;
this.payments = payments;
}
+ private String getBundleExternalKey(UUID invoiceId, List<Invoice> invoices, List<BundleTimeline> bundles) {
+ for (Invoice cur : invoices) {
+ if (cur.getId().equals(invoiceId)) {
+ return getBundleExternalKey(cur, bundles);
+ }
+ }
+ return null;
+ }
+
+ private String getBundleExternalKey(Invoice invoice, List<BundleTimeline> bundles) {
+ Set<UUID> b = new HashSet<UUID>();
+ for (final InvoiceItem cur : invoice.getInvoiceItems()) {
+ b.add(cur.getBundleId());
+ }
+ boolean first = true;
+ StringBuilder tmp = new StringBuilder();
+ for (final UUID cur : b) {
+ for (final BundleTimeline bt : bundles) {
+ if (bt.getBundleId().equals(cur)) {
+ if (!first) {
+ tmp.append(",");
+ }
+ tmp.append(bt.getExternalKey());
+ first = false;
+ break;
+ }
+ }
+ }
+ return tmp.toString();
+ }
+
public AccountTimelineJson(Account account, List<Invoice> invoices, List<PaymentAttempt> payments, List<BundleTimeline> bundles) {
this.account = new AccountJsonSimple(account.getId().toString(), account.getExternalKey());
this.bundles = new LinkedList<BundleJsonWithSubscriptions>();
for (BundleTimeline cur : bundles) {
this.bundles.add(new BundleJsonWithSubscriptions(account.getId(), cur));
}
- this.invoices = new LinkedList<InvoiceJson>();
+ this.invoices = new LinkedList<InvoiceJsonWithBundleKeys>();
for (Invoice cur : invoices) {
- this.invoices.add(new InvoiceJson(cur.getTotalAmount(), cur.getId().toString(), cur.getInvoiceDate(), Integer.toString(cur.getInvoiceNumber()), cur.getBalance()));
+ this.invoices.add(new InvoiceJsonWithBundleKeys(cur.getTotalAmount(), cur.getId().toString(), cur.getInvoiceDate(), cur.getTargetDate(),
+ Integer.toString(cur.getInvoiceNumber()), cur.getBalance(),
+ getBundleExternalKey(cur, bundles)));
}
- this.payments = new LinkedList<PaymentJson>();
+ this.payments = new LinkedList<PaymentJsonWithBundleKeys>();
for (PaymentAttempt cur : payments) {
+
+
String status = cur.getPaymentId() != null ? "Success" : "Failed";
BigDecimal paidAmount = cur.getPaymentId() != null ? cur.getAmount() : BigDecimal.ZERO;
- this.payments.add(new PaymentJson(cur.getAmount(), paidAmount, cur.getInvoiceId(), cur.getPaymentId(), cur.getCreatedDate(), cur.getUpdatedDate(),
- cur.getRetryCount(), cur.getCurrency().toString(), status));
+ this.payments.add(new PaymentJsonWithBundleKeys(cur.getAmount(), paidAmount, cur.getInvoiceId(), cur.getPaymentId(), cur.getCreatedDate(), cur.getUpdatedDate(),
+ cur.getRetryCount(), cur.getCurrency().toString(), status,
+ getBundleExternalKey(cur.getInvoiceId(), invoices, bundles)));
}
}
@@ -80,11 +120,11 @@ public class AccountTimelineJson {
this.payments = null;
}
- public List<PaymentJson> getPayments() {
+ public List<PaymentJsonWithBundleKeys> getPayments() {
return payments;
}
- public List<InvoiceJson> getInvoices() {
+ public List<InvoiceJsonWithBundleKeys> getInvoices() {
return invoices;
}
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/BundleJsonNoSubsciptions.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/BundleJsonNoSubsciptions.java
index 753688b..c1221b8 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/BundleJsonNoSubsciptions.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/BundleJsonNoSubsciptions.java
@@ -31,9 +31,9 @@ public class BundleJsonNoSubsciptions extends BundleJsonSimple {
@JsonCreator
- public BundleJsonNoSubsciptions(@JsonProperty("bundle_id") String bundleId,
- @JsonProperty("account_id") String accountId,
- @JsonProperty("external_key") String externalKey,
+ public BundleJsonNoSubsciptions(@JsonProperty("bundleId") String bundleId,
+ @JsonProperty("accountId") String accountId,
+ @JsonProperty("externalKey") String externalKey,
@JsonProperty("subscriptions") List<SubscriptionJsonWithEvents> subscriptions) {
super(bundleId, externalKey);
this.accountId = accountId;
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/BundleJsonSimple.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/BundleJsonSimple.java
index 3053f0d..8c2d836 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/BundleJsonSimple.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/BundleJsonSimple.java
@@ -16,6 +16,7 @@
package com.ning.billing.jaxrs.json;
import org.codehaus.jackson.annotate.JsonCreator;
+import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonView;
public class BundleJsonSimple {
@@ -27,7 +28,8 @@ public class BundleJsonSimple {
protected final String externalKey;
@JsonCreator
- public BundleJsonSimple(String bundleId, String externalKey) {
+ public BundleJsonSimple(@JsonProperty("bundleId") String bundleId,
+ @JsonProperty("externalKey") String externalKey) {
super();
this.bundleId = bundleId;
this.externalKey = externalKey;
@@ -38,10 +40,12 @@ public class BundleJsonSimple {
this.externalKey = null;
}
+ @JsonProperty("bundleId")
public String getBundleId() {
return bundleId;
}
+ @JsonProperty("externalKey")
public String getExternalKey() {
return externalKey;
}
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/BundleJsonWithSubscriptions.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/BundleJsonWithSubscriptions.java
index a51e09e..fa45cdd 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/BundleJsonWithSubscriptions.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/BundleJsonWithSubscriptions.java
@@ -33,13 +33,14 @@ public class BundleJsonWithSubscriptions extends BundleJsonSimple {
private final List<SubscriptionJsonWithEvents> subscriptions;
@JsonCreator
- public BundleJsonWithSubscriptions(@JsonProperty("bundle_id") String bundleId,
- @JsonProperty("external_key") String externalKey,
+ public BundleJsonWithSubscriptions(@JsonProperty("bundleId") String bundleId,
+ @JsonProperty("externalKey") String externalKey,
@JsonProperty("subscriptions") List<SubscriptionJsonWithEvents> subscriptions) {
super(bundleId, externalKey);
this.subscriptions = subscriptions;
}
+ @JsonProperty("subscriptions")
public List<SubscriptionJsonWithEvents> getSubscriptions() {
return subscriptions;
}
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/BundleTimelineJson.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/BundleTimelineJson.java
index 64a416c..099d837 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/BundleTimelineJson.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/BundleTimelineJson.java
@@ -31,20 +31,20 @@ public class BundleTimelineJson {
private final BundleJsonWithSubscriptions bundle;
@JsonView(BundleTimelineViews.ReadTimeline.class)
- private final List<PaymentJson> payments;
+ private final List<PaymentJsonSimple> payments;
@JsonView(BundleTimelineViews.ReadTimeline.class)
- private final List<InvoiceJson> invoices;
+ private final List<InvoiceJsonSimple> invoices;
@JsonView(BundleTimelineViews.WriteTimeline.class)
private final String resonForChange;
@JsonCreator
- public BundleTimelineJson(@JsonProperty("view_id") String viewId,
+ public BundleTimelineJson(@JsonProperty("viewId") String viewId,
@JsonProperty("bundle") BundleJsonWithSubscriptions bundle,
- @JsonProperty("payments") List<PaymentJson> payments,
- @JsonProperty("invoices") List<InvoiceJson> invoices,
- @JsonProperty("reason_for_change") String reason) {
+ @JsonProperty("payments") List<PaymentJsonSimple> payments,
+ @JsonProperty("invoices") List<InvoiceJsonSimple> invoices,
+ @JsonProperty("reasonForChange") String reason) {
this.viewId = viewId;
this.bundle = bundle;
this.payments = payments;
@@ -60,11 +60,11 @@ public class BundleTimelineJson {
return bundle;
}
- public List<PaymentJson> getPayments() {
+ public List<PaymentJsonSimple> getPayments() {
return payments;
}
- public List<InvoiceJson> getInvoices() {
+ public List<InvoiceJsonSimple> getInvoices() {
return invoices;
}
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/InvoiceJsonWithBundleKeys.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/InvoiceJsonWithBundleKeys.java
new file mode 100644
index 0000000..cc15072
--- /dev/null
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/InvoiceJsonWithBundleKeys.java
@@ -0,0 +1,57 @@
+package com.ning.billing.jaxrs.json;
+import java.math.BigDecimal;
+
+import org.codehaus.jackson.annotate.JsonCreator;
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.joda.time.DateTime;
+
+import com.ning.billing.invoice.api.Invoice;
+
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+public class InvoiceJsonWithBundleKeys extends InvoiceJsonSimple {
+
+
+ private final String bundleKeys;
+
+
+ public InvoiceJsonWithBundleKeys() {
+ super();
+ this.bundleKeys = null;
+ }
+
+ @JsonCreator
+ public InvoiceJsonWithBundleKeys(@JsonProperty("amount") BigDecimal amount,
+ @JsonProperty("invoiceId") String invoiceId,
+ @JsonProperty("invoiceDate") DateTime invoiceDate,
+ @JsonProperty("targetDate") DateTime targetDate,
+ @JsonProperty("invoiceNumber") String invoiceNumber,
+ @JsonProperty("balance") BigDecimal balance,
+ @JsonProperty("externalBundleKeys") String bundleKeys) {
+ super(amount, invoiceId, invoiceDate, targetDate, invoiceNumber, balance);
+ this.bundleKeys = bundleKeys;
+ }
+
+ public InvoiceJsonWithBundleKeys(Invoice input, String bundleKeys) {
+ super(input);
+ this.bundleKeys = bundleKeys;
+ }
+
+ public String getBundleKeys() {
+ return bundleKeys;
+ }
+}
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/PaymentJsonWithBundleKeys.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/PaymentJsonWithBundleKeys.java
new file mode 100644
index 0000000..e322a59
--- /dev/null
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/PaymentJsonWithBundleKeys.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.jaxrs.json;
+
+import java.math.BigDecimal;
+import java.util.UUID;
+
+import org.codehaus.jackson.annotate.JsonCreator;
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.joda.time.DateTime;
+
+public class PaymentJsonWithBundleKeys extends PaymentJsonSimple {
+
+ private final String bundleKeys;
+
+ public PaymentJsonWithBundleKeys() {
+ super();
+ this.bundleKeys = null;
+ }
+
+ @JsonCreator
+ public PaymentJsonWithBundleKeys(@JsonProperty("amount") BigDecimal amount,
+ @JsonProperty("paidAmount") BigDecimal paidAmount,
+ @JsonProperty("invoiceId") UUID invoiceId,
+ @JsonProperty("paymentId") UUID paymentId,
+ @JsonProperty("requestedDt") DateTime requestedDate,
+ @JsonProperty("effectiveDt") DateTime effectiveDate,
+ @JsonProperty("retryCount") Integer retryCount,
+ @JsonProperty("currency") String currency,
+ @JsonProperty("status") String status,
+ @JsonProperty("externalBundleKeys") String bundleKeys) {
+ super(amount, paidAmount, invoiceId, paymentId, requestedDate, effectiveDate, retryCount, currency, status);
+ this.bundleKeys = bundleKeys;
+ }
+
+ public String getBundleKeys() {
+ return bundleKeys;
+ }
+}
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonNoEvents.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonNoEvents.java
index 2ec1c44..95a5e09 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonNoEvents.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonNoEvents.java
@@ -57,14 +57,14 @@ public class SubscriptionJsonNoEvents extends SubscriptionJsonSimple {
@JsonCreator
- public SubscriptionJsonNoEvents(@JsonProperty("subscription_id") String subscriptionId,
- @JsonProperty("bundle_id") String bundleId,
- @JsonProperty("start_date") DateTime startDate,
- @JsonProperty("product_name") String productName,
- @JsonProperty("product_category") String productCategory,
- @JsonProperty("billing_period") String billingPeriod,
- @JsonProperty("price_list") String priceList,
- @JsonProperty("charged_through_date") DateTime chargedThroughDate) {
+ public SubscriptionJsonNoEvents(@JsonProperty("subscriptionId") String subscriptionId,
+ @JsonProperty("bundleId") String bundleId,
+ @JsonProperty("startDate") DateTime startDate,
+ @JsonProperty("productName") String productName,
+ @JsonProperty("productCategory") String productCategory,
+ @JsonProperty("billingPeriod") String billingPeriod,
+ @JsonProperty("priceList") String priceList,
+ @JsonProperty("chargedThroughDate") DateTime chargedThroughDate) {
super(subscriptionId);
this.bundleId = bundleId;
this.startDate = startDate;
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonSimple.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonSimple.java
index ebb86e4..5fb782e 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonSimple.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonSimple.java
@@ -29,7 +29,7 @@ public class SubscriptionJsonSimple {
}
@JsonCreator
- public SubscriptionJsonSimple(@JsonProperty("subscription_id") String subscriptionId) {
+ public SubscriptionJsonSimple(@JsonProperty("subscriptionId") String subscriptionId) {
this.subscriptionId = subscriptionId;
}
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonWithEvents.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonWithEvents.java
index 2f798df..be5ba2c 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonWithEvents.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/SubscriptionJsonWithEvents.java
@@ -58,13 +58,13 @@ public class SubscriptionJsonWithEvents extends SubscriptionJsonSimple {
}
@JsonCreator
- public SubscriptionReadEventJson(@JsonProperty("event_id") String eventId,
- @JsonProperty("billing_period") String billingPeriod,
- @JsonProperty("requested_dt") DateTime requestedDate,
- @JsonProperty("effective_dt") DateTime effectiveDate,
+ public SubscriptionReadEventJson(@JsonProperty("eventId") String eventId,
+ @JsonProperty("billingPeriod") String billingPeriod,
+ @JsonProperty("requestedDt") DateTime requestedDate,
+ @JsonProperty("effectiveDt") DateTime effectiveDate,
@JsonProperty("product") String product,
- @JsonProperty("price_list") String priceList,
- @JsonProperty("event_type") String eventType,
+ @JsonProperty("priceList") String priceList,
+ @JsonProperty("eventType") String eventType,
@JsonProperty("phase") String phase) {
super(billingPeriod, requestedDate, product, priceList, eventType, phase);
this.eventId = eventId;
@@ -97,8 +97,8 @@ public class SubscriptionJsonWithEvents extends SubscriptionJsonSimple {
@JsonCreator
public SubscriptionDeletedEventJson(@JsonProperty("event_id") String eventId,
@JsonProperty("billing_period") String billingPeriod,
- @JsonProperty("requested_dt") DateTime requestedDate,
- @JsonProperty("effective_dt") DateTime effectiveDate,
+ @JsonProperty("requested_date") DateTime requestedDate,
+ @JsonProperty("effective_date") DateTime effectiveDate,
@JsonProperty("product") String product,
@JsonProperty("price_list") String priceList,
@JsonProperty("event_type") String eventType,
@@ -112,7 +112,7 @@ public class SubscriptionJsonWithEvents extends SubscriptionJsonSimple {
public static class SubscriptionNewEventJson extends SubscriptionBaseEventJson {
@JsonCreator
public SubscriptionNewEventJson(@JsonProperty("billing_period") String billingPeriod,
- @JsonProperty("requested_dt") DateTime requestedDate,
+ @JsonProperty("requested_date") DateTime requestedDate,
@JsonProperty("product") String product,
@JsonProperty("price_list") String priceList,
@JsonProperty("event_type") String eventType,
@@ -165,7 +165,7 @@ public class SubscriptionJsonWithEvents extends SubscriptionJsonSimple {
@JsonCreator
public SubscriptionBaseEventJson(@JsonProperty("billing_period") String billingPeriod,
- @JsonProperty("requested_dt") DateTime requestedDate,
+ @JsonProperty("requested_date") DateTime requestedDate,
@JsonProperty("product") String product,
@JsonProperty("price_list") String priceList,
@JsonProperty("event_type") String eventType,
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/AccountResource.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/AccountResource.java
index 92aafb3..b8db3f8 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/AccountResource.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/AccountResource.java
@@ -243,6 +243,7 @@ public class AccountResource implements BaseJaxrsResource {
Account account = accountApi.getAccountById(UUID.fromString(accountId));
List<Invoice> invoices = invoiceApi.getInvoicesByAccount(account.getId());
+
List<PaymentAttempt> payments = new LinkedList<PaymentAttempt>();
if (invoices.size() > 0) {
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/InvoiceResource.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/InvoiceResource.java
index 27b7817..fd2ec57 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/InvoiceResource.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/InvoiceResource.java
@@ -48,7 +48,8 @@ import com.ning.billing.account.api.AccountUserApi;
import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoiceApiException;
import com.ning.billing.invoice.api.InvoiceUserApi;
-import com.ning.billing.jaxrs.json.InvoiceJson;
+
+import com.ning.billing.jaxrs.json.InvoiceJsonSimple;
import com.ning.billing.jaxrs.util.Context;
import com.ning.billing.jaxrs.util.JaxrsUriBuilder;
@@ -57,7 +58,7 @@ import com.ning.billing.jaxrs.util.JaxrsUriBuilder;
public class InvoiceResource implements BaseJaxrsResource {
- private static final Logger log = LoggerFactory.getLogger(AccountResource.class);
+ private static final Logger log = LoggerFactory.getLogger(InvoiceResource.class);
private final DateTimeFormatter DATE_TIME_FORMATTER = ISODateTimeFormat.dateTime();
@@ -85,9 +86,9 @@ public class InvoiceResource implements BaseJaxrsResource {
Preconditions.checkNotNull(accountId, "% query parameter must be specified", QUERY_ACCOUNT_ID);
accountApi.getAccountById(UUID.fromString(accountId));
List<Invoice> invoices = invoiceApi.getInvoicesByAccount(UUID.fromString(accountId));
- List<InvoiceJson> result = new LinkedList<InvoiceJson>();
+ List<InvoiceJsonSimple> result = new LinkedList<InvoiceJsonSimple>();
for (Invoice cur : invoices) {
- result.add(new InvoiceJson(cur));
+ result.add(new InvoiceJsonSimple(cur));
}
return Response.status(Status.OK).entity(result).build();
} catch (AccountApiException e) {
@@ -102,14 +103,14 @@ public class InvoiceResource implements BaseJaxrsResource {
@Produces(APPLICATION_JSON)
public Response getInvoice(@PathParam("invoiceId") String invoiceId) {
Invoice invoice = invoiceApi.getInvoice(UUID.fromString(invoiceId));
- InvoiceJson json = new InvoiceJson(invoice);
+ InvoiceJsonSimple json = new InvoiceJsonSimple(invoice);
return Response.status(Status.OK).entity(json).build();
}
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
- public Response createFutureInvoice(final InvoiceJson invoice,
+ public Response createFutureInvoice(final InvoiceJsonSimple invoice,
@QueryParam(QUERY_ACCOUNT_ID) final String accountId,
@QueryParam(QUERY_TARGET_DATE) final String targetDate,
@QueryParam(QUERY_DRY_RUN) @DefaultValue("false") final Boolean dryRun,
@@ -128,7 +129,7 @@ public class InvoiceResource implements BaseJaxrsResource {
Invoice generatedInvoice = invoiceApi.triggerInvoiceGeneration(UUID.fromString(accountId), inputDate, dryRun.booleanValue(),
context.createContext(createdBy, reason, comment));
if (dryRun) {
- return Response.status(Status.OK).entity(new InvoiceJson(generatedInvoice)).build();
+ return Response.status(Status.OK).entity(new InvoiceJsonSimple(generatedInvoice)).build();
} else {
return uriBuilder.buildResponse(InvoiceResource.class, "getInvoice", generatedInvoice.getId());
}
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/PaymentResource.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/PaymentResource.java
index c2f5391..2988f5a 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/PaymentResource.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/PaymentResource.java
@@ -28,7 +28,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
-import com.ning.billing.jaxrs.json.PaymentJson;
+import com.ning.billing.jaxrs.json.PaymentJsonSimple;
@Path("/1.0/payment")
@@ -53,7 +53,7 @@ public class PaymentResource {
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
@Path("/{invoiceId:\\w+-\\w+-\\w+-\\w+-\\w+}")
- public Response createInstantPayment(PaymentJson payment,
+ public Response createInstantPayment(PaymentJsonSimple payment,
@PathParam("invoiceId") String invoiceId,
@QueryParam("last4CC") String last4CC,
@QueryParam("nameOnCC") String nameOnCC) {
diff --git a/junction/src/main/java/com/ning/billing/junction/api/blocking/DefaultBlockingApi.java b/junction/src/main/java/com/ning/billing/junction/api/blocking/DefaultBlockingApi.java
index 62878ad..904d303 100644
--- a/junction/src/main/java/com/ning/billing/junction/api/blocking/DefaultBlockingApi.java
+++ b/junction/src/main/java/com/ning/billing/junction/api/blocking/DefaultBlockingApi.java
@@ -21,7 +21,6 @@ import java.util.UUID;
import com.google.inject.Inject;
import com.ning.billing.junction.api.Blockable;
-import com.ning.billing.junction.api.Blockable.Type;
import com.ning.billing.junction.api.BlockingApi;
import com.ning.billing.junction.api.BlockingState;
import com.ning.billing.junction.api.DefaultBlockingState;
@@ -49,8 +48,8 @@ public class DefaultBlockingApi implements BlockingApi {
}
@Override
- public BlockingState getBlockingStateFor(UUID overdueableId, Type type) {
- return dao.getBlockingStateFor(overdueableId, type);
+ public BlockingState getBlockingStateFor(UUID overdueableId) {
+ return dao.getBlockingStateFor(overdueableId);
}
@Override
@@ -59,9 +58,8 @@ public class DefaultBlockingApi implements BlockingApi {
}
@Override
- public SortedSet<BlockingState> getBlockingHistory(UUID overdueableId,
- Type type) {
- return dao.getBlockingHistoryForIdAndType(overdueableId, type);
+ public SortedSet<BlockingState> getBlockingHistory(UUID overdueableId) {
+ return dao.getBlockingHistoryFor(overdueableId);
}
@Override
diff --git a/junction/src/main/java/com/ning/billing/junction/block/DefaultBlockingChecker.java b/junction/src/main/java/com/ning/billing/junction/block/DefaultBlockingChecker.java
index 5fb3f25..8becce5 100644
--- a/junction/src/main/java/com/ning/billing/junction/block/DefaultBlockingChecker.java
+++ b/junction/src/main/java/com/ning/billing/junction/block/DefaultBlockingChecker.java
@@ -116,7 +116,7 @@ public class DefaultBlockingChecker implements BlockingChecker {
public BlockingAggregator getBlockedStateAccountId(UUID accountId) {
BlockingAggregator result = new BlockingAggregator();
if(accountId != null) {
- BlockingState accountState = dao.getBlockingStateFor(accountId, Blockable.Type.ACCOUNT);
+ BlockingState accountState = dao.getBlockingStateFor(accountId);
result.or(accountState);
}
return result;
diff --git a/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateDao.java b/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateDao.java
index b5b03ae..6f5396d 100644
--- a/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateDao.java
+++ b/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateDao.java
@@ -29,11 +29,11 @@ public interface BlockingStateDao {
//Read
public BlockingState getBlockingStateFor(Blockable blockable);
- public BlockingState getBlockingStateFor(UUID blockableId, Type type);
+ public BlockingState getBlockingStateFor(UUID blockableId);
public SortedSet<BlockingState> getBlockingHistoryFor(Blockable blockable);
- public SortedSet<BlockingState> getBlockingHistoryForIdAndType(UUID blockableId, Type type);
+ public SortedSet<BlockingState> getBlockingHistoryFor(UUID blockableId);
//Write
<T extends Blockable> void setBlockingState(BlockingState state, Clock clock);
diff --git a/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateSqlDao.java b/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateSqlDao.java
index 4345f6d..ba241a4 100644
--- a/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateSqlDao.java
+++ b/junction/src/main/java/com/ning/billing/junction/dao/BlockingStateSqlDao.java
@@ -63,7 +63,7 @@ public interface BlockingStateSqlDao extends BlockingStateDao, CloseMe, Transmog
@Override
@SqlQuery
@Mapper(BlockingHistorySqlMapper.class)
- public abstract BlockingState getBlockingStateFor(@Bind(binder = UUIDBinder.class) UUID overdueableId, @Bind(binder = BlockableTypeBinder.class) Type type);
+ public abstract BlockingState getBlockingStateFor(@Bind(binder = UUIDBinder.class) UUID overdueableId);
@Override
@SqlQuery
@@ -73,7 +73,7 @@ public interface BlockingStateSqlDao extends BlockingStateDao, CloseMe, Transmog
@Override
@SqlQuery
@Mapper(BlockingHistorySqlMapper.class)
- public abstract SortedSet<BlockingState> getBlockingHistoryForIdAndType(@Bind(binder = UUIDBinder.class) UUID blockableId, @Bind(binder = BlockableTypeBinder.class) Type type);
+ public abstract SortedSet<BlockingState> getBlockingHistoryFor(@Bind(binder = UUIDBinder.class) UUID blockableId);
public class BlockingHistorySqlMapper extends MapperBase implements ResultSetMapper<BlockingState> {
diff --git a/junction/src/main/java/com/ning/billing/junction/plumbing/billing/BlockingCalculator.java b/junction/src/main/java/com/ning/billing/junction/plumbing/billing/BlockingCalculator.java
index 9c1aab1..999c5d6 100644
--- a/junction/src/main/java/com/ning/billing/junction/plumbing/billing/BlockingCalculator.java
+++ b/junction/src/main/java/com/ning/billing/junction/plumbing/billing/BlockingCalculator.java
@@ -85,8 +85,8 @@ public class BlockingCalculator {
SortedSet<BillingEvent> billingEventsToRemove = new TreeSet<BillingEvent>();
for(UUID bundleId : bundleMap.keySet()) {
- SortedSet<BlockingState> blockingEvents = blockingApi.getBlockingHistory(bundleId, Blockable.Type.SUBSCRIPTION_BUNDLE);
- blockingEvents.addAll(blockingApi.getBlockingHistory(account.getId(), Blockable.Type.ACCOUNT));
+ SortedSet<BlockingState> blockingEvents = blockingApi.getBlockingHistory(bundleId);
+ blockingEvents.addAll(blockingApi.getBlockingHistory(account.getId()));
List<DisabledDuration> blockingDurations = createBlockingDurations(blockingEvents);
for (Subscription subscription: bundleMap.get(bundleId)) {
diff --git a/junction/src/main/resources/com/ning/billing/junction/dao/BlockingStateSqlDao.sql.stg b/junction/src/main/resources/com/ning/billing/junction/dao/BlockingStateSqlDao.sql.stg
index 98125a2..0bd6686 100644
--- a/junction/src/main/resources/com/ning/billing/junction/dao/BlockingStateSqlDao.sql.stg
+++ b/junction/src/main/resources/com/ning/billing/junction/dao/BlockingStateSqlDao.sql.stg
@@ -17,25 +17,6 @@ getBlockingStateFor() ::= <<
;
>>
-getBlockingStateForIdAndType() ::= <<
- select
- id
- , state
- , type
- , service
- , block_change
- , block_entitlement
- , block_billing
- , created_date
- from blocking_states
- where id = :id
- and type = :type
- order by created_date desc
- limit 1
- ;
->>
-
-
getBlockingHistoryFor() ::= <<
select
id
@@ -52,23 +33,6 @@ getBlockingHistoryFor() ::= <<
;
>>
-getBlockingHistoryForIdAndType() ::= <<
- select
- id
- , state
- , type
- , service
- , block_change
- , block_entitlement
- , block_billing
- , created_date
- from blocking_states
- where id = :id
- and type = :type
- order by created_date asc
- ;
->>
-
setBlockingState() ::= <<
insert into blocking_states (
id
diff --git a/junction/src/test/java/com/ning/billing/junction/api/blocking/TestBlockingApi.java b/junction/src/test/java/com/ning/billing/junction/api/blocking/TestBlockingApi.java
index db1d1e0..c6241d8 100644
--- a/junction/src/test/java/com/ning/billing/junction/api/blocking/TestBlockingApi.java
+++ b/junction/src/test/java/com/ning/billing/junction/api/blocking/TestBlockingApi.java
@@ -103,7 +103,7 @@ public class TestBlockingApi {
((ZombieControl)bundle).addResult("getId", uuid);
Assert.assertEquals(api.getBlockingStateFor(bundle).getStateName(), overdueStateName2);
- Assert.assertEquals(api.getBlockingStateFor(bundle.getId(), Blockable.Type.SUBSCRIPTION_BUNDLE).getStateName(), overdueStateName2);
+ Assert.assertEquals(api.getBlockingStateFor(bundle.getId()).getStateName(), overdueStateName2);
}
@@ -131,7 +131,7 @@ public class TestBlockingApi {
SortedSet<BlockingState> history1 = api.getBlockingHistory(bundle);
- SortedSet<BlockingState> history2 = api.getBlockingHistory(bundle.getId(), Blockable.Type.get(bundle));
+ SortedSet<BlockingState> history2 = api.getBlockingHistory(bundle.getId());
Assert.assertEquals(history1.size(), 2);
Assert.assertEquals(history1.first().getStateName(), overdueStateName);
diff --git a/junction/src/test/java/com/ning/billing/junction/blocking/TestBlockingChecker.java b/junction/src/test/java/com/ning/billing/junction/blocking/TestBlockingChecker.java
index b0247f1..0bff4da 100644
--- a/junction/src/test/java/com/ning/billing/junction/blocking/TestBlockingChecker.java
+++ b/junction/src/test/java/com/ning/billing/junction/blocking/TestBlockingChecker.java
@@ -32,7 +32,6 @@ import com.ning.billing.entitlement.api.user.EntitlementUserApi;
import com.ning.billing.entitlement.api.user.Subscription;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
import com.ning.billing.junction.api.Blockable;
-import com.ning.billing.junction.api.Blockable.Type;
import com.ning.billing.junction.api.BlockingApiException;
import com.ning.billing.junction.api.BlockingState;
import com.ning.billing.junction.api.DefaultBlockingState;
@@ -54,9 +53,9 @@ public class TestBlockingChecker {
@Override
public BlockingState getBlockingStateFor(Blockable blockable) {
- if(blockable instanceof Account) {
+ if(blockable.getId() == account.getId()) {
return accountState;
- } else if(blockable instanceof Subscription) {
+ } else if(blockable.getId() == subscription.getId()) {
return subscriptionState;
} else {
return bundleState;
@@ -64,10 +63,10 @@ public class TestBlockingChecker {
}
@Override
- public BlockingState getBlockingStateFor(UUID blockableId, Type type) {
- if(type == Blockable.Type.ACCOUNT) {
+ public BlockingState getBlockingStateFor(UUID blockableId) {
+ if(blockableId == account.getId()) {
return accountState;
- } else if(type == Blockable.Type.SUBSCRIPTION) {
+ } else if(blockableId == subscription.getId()) {
return subscriptionState;
} else {
return bundleState;
@@ -80,7 +79,7 @@ public class TestBlockingChecker {
}
@Override
- public SortedSet<BlockingState> getBlockingHistoryForIdAndType(UUID overdueableId, Type type) {
+ public SortedSet<BlockingState> getBlockingHistoryFor(UUID overdueableId) {
throw new NotImplementedException();
}
@@ -97,18 +96,19 @@ public class TestBlockingChecker {
@BeforeClass(groups={"fast"})
public void setup() {
- subscription = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
- ((ZombieControl) subscription).addResult("getId", new UUID(0L,0L));
+ account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
+ ((ZombieControl) account).addResult("getId", UUID.randomUUID());
bundle = BrainDeadProxyFactory.createBrainDeadProxyFor(SubscriptionBundle.class);
- ((ZombieControl) bundle).addResult("getAccountId", new UUID(0L,0L));
- ((ZombieControl) bundle).addResult("getId", new UUID(0L,0L));
+ ((ZombieControl) bundle).addResult("getAccountId", account.getId());
+ ((ZombieControl) bundle).addResult("getId", UUID.randomUUID());
((ZombieControl) bundle).addResult("getKey", "key");
- ((ZombieControl) subscription).addResult("getBundleId", new UUID(0L,0L));
- account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
- ((ZombieControl) account).addResult("getId", new UUID(0L,0L));
-
+ subscription = BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
+ ((ZombieControl) subscription).addResult("getId", UUID.randomUUID());
+ ((ZombieControl) subscription).addResult("getBundleId", bundle.getId());
+
+
Injector i = Guice.createInjector(new AbstractModule() {
@Override
diff --git a/junction/src/test/java/com/ning/billing/junction/dao/TestBlockingDao.java b/junction/src/test/java/com/ning/billing/junction/dao/TestBlockingDao.java
index 0c3b8c8..8e02e55 100644
--- a/junction/src/test/java/com/ning/billing/junction/dao/TestBlockingDao.java
+++ b/junction/src/test/java/com/ning/billing/junction/dao/TestBlockingDao.java
@@ -93,7 +93,7 @@ public class TestBlockingDao {
((ZombieControl)bundle).addResult("getId", uuid);
Assert.assertEquals(dao.getBlockingStateFor(bundle).getStateName(), state2.getStateName());
- Assert.assertEquals(dao.getBlockingStateFor(bundle.getId(), Blockable.Type.SUBSCRIPTION_BUNDLE).getStateName(), overdueStateName2);
+ Assert.assertEquals(dao.getBlockingStateFor(bundle.getId()).getStateName(), overdueStateName2);
}
@@ -121,7 +121,7 @@ public class TestBlockingDao {
SortedSet<BlockingState> history1 = dao.getBlockingHistoryFor(bundle);
- SortedSet<BlockingState> history2 = dao.getBlockingHistoryForIdAndType(bundle.getId(), Blockable.Type.get(bundle));
+ SortedSet<BlockingState> history2 = dao.getBlockingHistoryFor(bundle.getId());
Assert.assertEquals(history1.size(), 2);
Assert.assertEquals(history1.first().getStateName(), overdueStateName);
diff --git a/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestDefaultEntitlementBillingApi.java b/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestDefaultEntitlementBillingApi.java
index 0d0d14b..85e239f 100644
--- a/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestDefaultEntitlementBillingApi.java
+++ b/junction/src/test/java/com/ning/billing/junction/plumbing/billing/TestDefaultEntitlementBillingApi.java
@@ -389,7 +389,7 @@ public class TestDefaultEntitlementBillingApi {
public <T extends Blockable> void setBlockingState(BlockingState state) {}
@Override
- public BlockingState getBlockingStateFor(UUID overdueableId, Type type) {
+ public BlockingState getBlockingStateFor(UUID overdueableId) {
return null;
}
@@ -399,8 +399,8 @@ public class TestDefaultEntitlementBillingApi {
}
@Override
- public SortedSet<BlockingState> getBlockingHistory(UUID overdueableId, Type type) {
- if(type == Type.SUBSCRIPTION_BUNDLE) {
+ public SortedSet<BlockingState> getBlockingHistory(UUID overdueableId) {
+ if(overdueableId == bunId) {
return blockingStates;
}
return new TreeSet<BlockingState>();
overdue/pom.xml 13(+6 -7)
diff --git a/overdue/pom.xml b/overdue/pom.xml
index 2182ffc..3662f2b 100644
--- a/overdue/pom.xml
+++ b/overdue/pom.xml
@@ -46,6 +46,12 @@
<artifactId>jdbi</artifactId>
</dependency>
<dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+
+ <!-- TEST SCOPE -->
+ <dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
@@ -93,13 +99,6 @@
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
- <!-- Strangely this is needed in order to run the tests in local db mode -->
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <scope>test</scope>
- </dependency>
-
</dependencies>
<build>
<plugins>
diff --git a/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java b/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java
index 06acac9..9f45075 100644
--- a/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java
+++ b/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java
@@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.ning.billing.config.NotificationConfig;
import com.ning.billing.overdue.OverdueProperties;
+import com.ning.billing.overdue.listener.OverdueListener;
import com.ning.billing.overdue.service.DefaultOverdueService;
import com.ning.billing.util.notificationq.NotificationQueue;
import com.ning.billing.util.notificationq.NotificationQueueService;
@@ -75,16 +76,8 @@ public class DefaultOverdueCheckNotifier implements OverdueCheckNotifier {
return config.isNotificationProcessingOff();
}
@Override
- public long getNotificationSleepTimeMs() {
- return config.getNotificationSleepTimeMs();
- }
- @Override
- public int getDaoMaxReadyEvents() {
- return config.getDaoMaxReadyEvents();
- }
- @Override
- public long getDaoClaimTimeMs() {
- return config.getDaoClaimTimeMs();
+ public long getSleepTimeMs() {
+ return config.getSleepTimeMs();
}
});
} catch (NotificationQueueAlreadyExists e) {
@@ -105,7 +98,7 @@ public class DefaultOverdueCheckNotifier implements OverdueCheckNotifier {
}
private void processEvent(UUID overdueableId, DateTime eventDateTime) {
- listener.handleNextOverdueCheck(overdueableId, eventDateTime);
+ listener.handleNextOverdueCheck(overdueableId);
}
diff --git a/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckPoster.java b/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckPoster.java
index 106a5c4..81ba766 100644
--- a/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckPoster.java
+++ b/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckPoster.java
@@ -42,14 +42,14 @@ public class DefaultOverdueCheckPoster implements OverdueCheckPoster {
}
@Override
- public void insertOverdueCheckNotification(final Transmogrifier transactionalDao, final Blockable overdueable, final DateTime futureNotificationTime) {
+ public void insertOverdueCheckNotification(final Blockable overdueable, final DateTime futureNotificationTime) {
NotificationQueue checkOverdueQueue;
try {
checkOverdueQueue = notificationQueueService.getNotificationQueue(DefaultOverdueService.OVERDUE_SERVICE_NAME,
DefaultOverdueCheckNotifier.OVERDUE_CHECK_NOTIFIER_QUEUE);
log.info("Queuing overdue check notification. id: {}, timestamp: {}", overdueable.getId().toString(), futureNotificationTime.toString());
- checkOverdueQueue.recordFutureNotificationFromTransaction(transactionalDao, futureNotificationTime, new NotificationKey(){
+ checkOverdueQueue.recordFutureNotification(futureNotificationTime, new NotificationKey(){
@Override
public String toString() {
return overdueable.getId().toString();
@@ -58,9 +58,12 @@ public class DefaultOverdueCheckPoster implements OverdueCheckPoster {
} catch (NoSuchNotificationQueue e) {
log.error("Attempting to put items on a non-existent queue (DefaultOverdueCheck).", e);
}
+
}
- public void clearNotificationEventsFor(final Blockable overdueable) {
+
+ @Override
+ public void clearNotificationsFor(final Blockable overdueable) {
NotificationQueue checkOverdueQueue;
try {
checkOverdueQueue = notificationQueueService.getNotificationQueue(DefaultOverdueService.OVERDUE_SERVICE_NAME,
@@ -70,4 +73,5 @@ public class DefaultOverdueCheckPoster implements OverdueCheckPoster {
log.error("Attempting to clear items from a non-existent queue (DefaultOverdueCheck).", e);
}
}
+
}
diff --git a/overdue/src/main/java/com/ning/billing/ovedue/notification/OverdueCheckPoster.java b/overdue/src/main/java/com/ning/billing/ovedue/notification/OverdueCheckPoster.java
index 8105bc7..3a2aa48 100644
--- a/overdue/src/main/java/com/ning/billing/ovedue/notification/OverdueCheckPoster.java
+++ b/overdue/src/main/java/com/ning/billing/ovedue/notification/OverdueCheckPoster.java
@@ -24,7 +24,8 @@ import com.ning.billing.junction.api.Blockable;
public interface OverdueCheckPoster {
- void insertOverdueCheckNotification(Transmogrifier transactionalDao,
- Blockable overdueable, DateTime futureNotificationTime);
+ void insertOverdueCheckNotification(Blockable blockable, DateTime futureNotificationTime);
+
+ void clearNotificationsFor(Blockable blockable);
}
\ No newline at end of file
diff --git a/overdue/src/main/java/com/ning/billing/overdue/api/DefaultOverdueUserApi.java b/overdue/src/main/java/com/ning/billing/overdue/api/DefaultOverdueUserApi.java
index 8a9ea68..83487ea 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/api/DefaultOverdueUserApi.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/api/DefaultOverdueUserApi.java
@@ -20,12 +20,12 @@ import org.apache.commons.lang.NotImplementedException;
import com.google.inject.Inject;
import com.ning.billing.ErrorCode;
-import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.catalog.api.CatalogService;
import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.junction.api.BlockingApi;
+import com.ning.billing.overdue.OverdueApiException;
import com.ning.billing.overdue.OverdueState;
import com.ning.billing.overdue.OverdueUserApi;
import com.ning.billing.overdue.config.OverdueConfig;
@@ -57,13 +57,13 @@ public class DefaultOverdueUserApi implements OverdueUserApi {
String stateName = accessApi.getBlockingStateFor(overdueable).getStateName();
OverdueStateSet<SubscriptionBundle> states = overdueConfig.getBundleStateSet();
return (OverdueState<T>) states.findState(stateName);
- } catch (CatalogApiException e) {
+ } catch (OverdueApiException e) {
throw new OverdueError(e, ErrorCode.OVERDUE_CAT_ERROR_ENCOUNTERED,overdueable.getId(), overdueable.getClass().getSimpleName());
}
}
@Override
- public <T extends Blockable> OverdueState<T> refreshOverdueStateFor(T overdueable) throws OverdueError, CatalogApiException, EntitlementUserApiException {
+ public <T extends Blockable> OverdueState<T> refreshOverdueStateFor(T overdueable) throws OverdueError, OverdueApiException {
OverdueWrapper<T> wrapper = factory.createOverdueWrapperFor(overdueable);
return wrapper.refresh();
}
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 82ad93c..abd4e0a 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
@@ -18,44 +18,57 @@ package com.ning.billing.overdue.applicator;
import org.apache.commons.lang.NotImplementedException;
import org.joda.time.DateTime;
+import org.joda.time.Period;
import com.google.inject.Inject;
import com.ning.billing.ErrorCode;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.junction.api.BlockingApi;
import com.ning.billing.junction.api.DefaultBlockingState;
-
+import com.ning.billing.ovedue.notification.OverdueCheckPoster;
+import com.ning.billing.overdue.OverdueApiException;
import com.ning.billing.overdue.OverdueService;
import com.ning.billing.overdue.OverdueState;
import com.ning.billing.overdue.config.api.OverdueError;
+import com.ning.billing.util.clock.Clock;
public class OverdueStateApplicator<T extends Blockable>{
private final BlockingApi blockingApi;
+ private final Clock clock;
+ private final OverdueCheckPoster poster;
@Inject
- public OverdueStateApplicator(BlockingApi accessApi) {
+ public OverdueStateApplicator(BlockingApi accessApi, Clock clock, OverdueCheckPoster poster) {
this.blockingApi = accessApi;
+ this.clock = clock;
+ this.poster = poster;
}
- public void apply(T overdueable, OverdueState<T> previousOverdueState, OverdueState<T> nextOverdueState, DateTime timeOfNextCheck) throws OverdueError {
+ public void apply(T overdueable, OverdueState<T> previousOverdueState, OverdueState<T> nextOverdueState) throws OverdueError {
if(previousOverdueState.getName().equals(nextOverdueState.getName())) {
return; // nothing to do
}
-
+
storeNewState(overdueable, nextOverdueState);
-
- if(timeOfNextCheck != null && !nextOverdueState.isClearState()) {
- createFutureNotification(overdueable, timeOfNextCheck);
+ try {
+ Period reevaluationInterval = nextOverdueState.getReevaluationInterval();
+ if(!nextOverdueState.isClearState()) {
+ createFutureNotification(overdueable, clock.getUTCNow().plus(reevaluationInterval));
+ }
+ } catch(OverdueApiException e) {
+ if(e.getCode() != ErrorCode.OVERDUE_NO_REEVALUATION_INTERVAL.getCode()) {
+ new OverdueError(e);
+ }
}
if(nextOverdueState.isClearState()) {
clear(overdueable);
}
-
- //If new state is clear state reset next events and override table
- throw new NotImplementedException();
+
+
+
}
@@ -82,17 +95,13 @@ public class OverdueStateApplicator<T extends Blockable>{
protected void createFutureNotification(T overdueable,
DateTime timeOfNextCheck) {
- // TODO MDW
-
- }
+ poster.insertOverdueCheckNotification(overdueable, timeOfNextCheck);
+ }
-
- protected void clear(T overdueable) {
- //TODO MDW
- // Clear future notification checks
- // Clear any overrides
-
+ protected void clear(T blockable) {
+ //Need to clear the overrride table here too (when we add it)
+ poster.clearNotificationsFor(blockable);
}
}
diff --git a/overdue/src/main/java/com/ning/billing/overdue/config/DefaultCondition.java b/overdue/src/main/java/com/ning/billing/overdue/config/DefaultCondition.java
index 08c13a9..44f6c99 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/config/DefaultCondition.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/config/DefaultCondition.java
@@ -26,6 +26,8 @@ import javax.xml.bind.annotation.XmlElementWrapper;
import org.joda.time.DateTime;
+import com.ning.billing.catalog.api.Duration;
+import com.ning.billing.catalog.api.TimeUnit;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.overdue.config.api.BillingState;
import com.ning.billing.overdue.config.api.PaymentResponse;
@@ -90,4 +92,13 @@ public class DefaultCondition<T extends Blockable> extends ValidatingConfig<Over
@Override
public void initialize(OverdueConfig root, URI uri) {
}
+
+ public Duration getTimeOffset() {
+ if (timeSinceEarliestUnpaidInvoiceEqualsOrExceeds != null) {
+ return timeSinceEarliestUnpaidInvoiceEqualsOrExceeds;
+ } else {
+ return new DefaultDuration().setUnit(TimeUnit.DAYS).setNumber(0); // zero time
+ }
+
+ }
}
diff --git a/overdue/src/main/java/com/ning/billing/overdue/config/DefaultOverdueState.java b/overdue/src/main/java/com/ning/billing/overdue/config/DefaultOverdueState.java
index 9a448c2..690d717 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/config/DefaultOverdueState.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/config/DefaultOverdueState.java
@@ -22,7 +22,14 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlID;
+import org.joda.time.DateTime;
+import org.joda.time.Period;
+
+import com.ning.billing.ErrorCode;
+import com.ning.billing.catalog.api.TimeUnit;
+import com.ning.billing.entitlement.api.user.SubscriptionBundle;
import com.ning.billing.junction.api.Blockable;
+import com.ning.billing.overdue.OverdueApiException;
import com.ning.billing.overdue.OverdueState;
import com.ning.billing.util.config.ValidatingConfig;
import com.ning.billing.util.config.ValidationError;
@@ -55,6 +62,11 @@ public class DefaultOverdueState<T extends Blockable> extends ValidatingConfig<O
@XmlElement(required=false, name="isClearState")
private Boolean isClearState = false;
+ @XmlElement(required=false, name="autoReevaluationInterval")
+ private DefaultDuration autoReevaluationInterval;
+
+
+
//Other actions could include
// - send email
// - trigger payment retry?
@@ -91,7 +103,14 @@ public class DefaultOverdueState<T extends Blockable> extends ValidatingConfig<O
public boolean disableEntitlementAndChangesBlocked() {
return disableEntitlement;
}
-
+
+ @Override
+ public Period getReevaluationInterval() throws OverdueApiException {
+ if(autoReevaluationInterval == null || autoReevaluationInterval.getUnit() == TimeUnit.UNLIMITED || autoReevaluationInterval.getNumber() == 0) {
+ throw new OverdueApiException(ErrorCode.OVERDUE_NO_REEVALUATION_INTERVAL, name);
+ }
+ return autoReevaluationInterval.toJodaPeriod();
+ }
protected DefaultCondition<T> getCondition() {
return condition;
diff --git a/overdue/src/main/java/com/ning/billing/overdue/config/DefaultOverdueStateSet.java b/overdue/src/main/java/com/ning/billing/overdue/config/DefaultOverdueStateSet.java
index bbda620..277fb1b 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/config/DefaultOverdueStateSet.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/config/DefaultOverdueStateSet.java
@@ -19,12 +19,14 @@ package com.ning.billing.overdue.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
-import org.apache.commons.lang.NotImplementedException;
import org.joda.time.DateTime;
+import org.joda.time.MutablePeriod;
+import org.joda.time.Period;
import com.ning.billing.ErrorCode;
-import com.ning.billing.catalog.api.CatalogApiException;
+import com.ning.billing.catalog.api.Duration;
import com.ning.billing.junction.api.Blockable;
+import com.ning.billing.overdue.OverdueApiException;
import com.ning.billing.overdue.OverdueState;
import com.ning.billing.overdue.config.api.BillingState;
import com.ning.billing.overdue.config.api.OverdueStateSet;
@@ -33,57 +35,52 @@ import com.ning.billing.util.config.ValidationErrors;
@XmlAccessorType(XmlAccessType.NONE)
public abstract class DefaultOverdueStateSet<T extends Blockable> extends ValidatingConfig<OverdueConfig> implements OverdueStateSet<T> {
+ private static final Period ZERO_PERIOD = new Period();
private DefaultOverdueState<T> clearState;
-
+
protected abstract DefaultOverdueState<T>[] getStates();
-
- private DefaultOverdueState<T> getClearState() throws CatalogApiException {
+
+ private DefaultOverdueState<T> getClearState() throws OverdueApiException {
for(DefaultOverdueState<T> overdueState : getStates()) {
if(overdueState.isClearState()) {
return overdueState;
}
}
- throw new CatalogApiException(ErrorCode.CAT_MISSING_CLEAR_STATE);
+ throw new OverdueApiException(ErrorCode.CAT_MISSING_CLEAR_STATE);
}
-
+
@Override
- public OverdueState<T> findState(String stateName) throws CatalogApiException {
+ public OverdueState<T> findState(String stateName) throws OverdueApiException {
for(DefaultOverdueState<T> state: getStates()) {
if(state.getName().equals(stateName) ) { return state; }
}
- throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_OVEDUE_STATE, stateName);
+ throw new OverdueApiException(ErrorCode.CAT_NO_SUCH_OVEDUE_STATE, stateName);
}
-
-
+
+
/* (non-Javadoc)
* @see com.ning.billing.catalog.overdue.OverdueBillingState#findClearState()
*/
@Override
- public DefaultOverdueState<T> findClearState() throws CatalogApiException {
+ public DefaultOverdueState<T> findClearState() throws OverdueApiException {
if (clearState != null) {
clearState = getClearState();
}
return clearState;
}
-
+
/* (non-Javadoc)
* @see com.ning.billing.catalog.overdue.OverdueBillingState#calculateOverdueState(com.ning.billing.catalog.api.overdue.BillingState, org.joda.time.DateTime)
*/
@Override
- public DefaultOverdueState<T> calculateOverdueState(BillingState<T> billingState, DateTime now) throws CatalogApiException {
- for(DefaultOverdueState<T> overdueState : getStates()) {
- if(overdueState.getCondition().evaluate(billingState, now)) {
- return overdueState;
- }
+ public DefaultOverdueState<T> calculateOverdueState(BillingState<T> billingState, DateTime now) throws OverdueApiException {
+ for(DefaultOverdueState<T> overdueState : getStates()) {
+ if(overdueState.getCondition().evaluate(billingState, now)) {
+ return overdueState;
}
- return findClearState();
- }
-
- @Override
- public DateTime dateOfNextCheck(BillingState<T> billingState, DateTime now) {
- throw new NotImplementedException();
+ }
+ return findClearState();
}
-
@Override
public ValidationErrors validate(OverdueConfig root,
@@ -93,13 +90,13 @@ public abstract class DefaultOverdueStateSet<T extends Blockable> extends Valida
}
try {
getClearState();
- } catch (CatalogApiException e) {
+ } catch (OverdueApiException e) {
if(e.getCode() == ErrorCode.CAT_MISSING_CLEAR_STATE.getCode()) {
errors.add("Overdue state set is missing a clear state.",
root.getURI(), this.getClass(), "");
- }
+ }
}
-
+
return errors;
}
}
diff --git a/overdue/src/main/java/com/ning/billing/overdue/config/OverdueConfig.java b/overdue/src/main/java/com/ning/billing/overdue/config/OverdueConfig.java
index 1217122..16d5a51 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/config/OverdueConfig.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/config/OverdueConfig.java
@@ -38,7 +38,6 @@ public class OverdueConfig extends ValidatingConfig<OverdueConfig> {
return bundleOverdueStates;
}
-
@Override
public ValidationErrors validate(OverdueConfig root,
ValidationErrors errors) {
diff --git a/overdue/src/main/java/com/ning/billing/overdue/config/OverdueStatesBundle.java b/overdue/src/main/java/com/ning/billing/overdue/config/OverdueStatesBundle.java
index 50d000b..3f07db5 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/config/OverdueStatesBundle.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/config/OverdueStatesBundle.java
@@ -18,7 +18,14 @@ package com.ning.billing.overdue.config;
import javax.xml.bind.annotation.XmlElement;
+import org.joda.time.DateTime;
+
+import com.ning.billing.ErrorCode;
+import com.ning.billing.catalog.api.Duration;
+import com.ning.billing.catalog.api.TimeUnit;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.overdue.OverdueApiException;
+import com.ning.billing.overdue.OverdueState;
public class OverdueStatesBundle extends DefaultOverdueStateSet<SubscriptionBundle>{
diff --git a/overdue/src/main/java/com/ning/billing/overdue/listener/OverdueDispatcher.java b/overdue/src/main/java/com/ning/billing/overdue/listener/OverdueDispatcher.java
new file mode 100644
index 0000000..8f2d03f
--- /dev/null
+++ b/overdue/src/main/java/com/ning/billing/overdue/listener/OverdueDispatcher.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.overdue.listener;
+
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.ning.billing.account.api.Account;
+import com.ning.billing.account.api.AccountApiException;
+import com.ning.billing.account.api.AccountUserApi;
+import com.ning.billing.entitlement.api.user.EntitlementUserApi;
+import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
+import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.junction.api.Blockable;
+import com.ning.billing.overdue.OverdueApiException;
+import com.ning.billing.overdue.config.api.OverdueError;
+import com.ning.billing.overdue.wrapper.OverdueWrapper;
+import com.ning.billing.overdue.wrapper.OverdueWrapperFactory;
+
+public class OverdueDispatcher {
+ Logger log = LoggerFactory.getLogger(OverdueDispatcher.class);
+
+ private final EntitlementUserApi entitlementUserApi;
+ private final AccountUserApi accountUserApi;
+ private final OverdueWrapperFactory factory;
+
+ @Inject
+ public OverdueDispatcher(AccountUserApi accountUserApi,
+ EntitlementUserApi entitlementUserApi,
+ OverdueWrapperFactory factory) {
+ this.accountUserApi = accountUserApi;
+ this.entitlementUserApi = entitlementUserApi;
+ this.factory = factory;
+ }
+
+ public void processOverdueForAccount(UUID accountId) {
+ try {
+ Account account = accountUserApi.getAccountById(accountId);
+ processOverdue(account);
+ } catch (AccountApiException e) {
+ log.error("Error processing Overdue for Account with id: " + accountId.toString(), e);
+ }
+ }
+
+ public void processOverdueForBundle(UUID bundleId) {
+ try {
+ SubscriptionBundle bundle = entitlementUserApi.getBundleFromId(bundleId);
+ processOverdue(bundle);
+ } catch (EntitlementUserApiException e) {
+ log.error("Error processing Overdue for Bundle with id: " + bundleId.toString(), e);
+ }
+ }
+
+ public void processOverdue(Blockable bloackable) {
+ try {
+ OverdueWrapper<?> wrapper = factory.createOverdueWrapperFor(bloackable);
+ wrapper.refresh();
+ } catch (OverdueError e) {
+ log.error("Error processing Overdue for Blockable with id: " + bloackable.getId().toString(), e);
+ } catch (OverdueApiException e) {
+ log.error("Error processing Overdue for Blockable with id: " + bloackable.getId().toString(), e);
+ }
+ }
+
+ public void processOverdue(UUID blockableId) {
+
+
+ }
+
+}
diff --git a/overdue/src/main/java/com/ning/billing/overdue/listener/OverdueListener.java b/overdue/src/main/java/com/ning/billing/overdue/listener/OverdueListener.java
new file mode 100644
index 0000000..2c193b4
--- /dev/null
+++ b/overdue/src/main/java/com/ning/billing/overdue/listener/OverdueListener.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.overdue.listener;
+
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.eventbus.Subscribe;
+import com.google.inject.Inject;
+import com.ning.billing.payment.api.PaymentApi;
+import com.ning.billing.payment.api.PaymentAttempt;
+import com.ning.billing.payment.api.PaymentErrorEvent;
+import com.ning.billing.payment.api.PaymentInfoEvent;
+
+public class OverdueListener {
+ OverdueDispatcher dispatcher;
+
+ //
+ //TODO disabled overdue for prod deployment - comments should be removed
+ //
+
+ private final static Logger log = LoggerFactory.getLogger(OverdueListener.class);
+ private final PaymentApi paymentApi;
+
+ @Inject
+ public OverdueListener(OverdueDispatcher dispatcher, PaymentApi paymentApi) {
+ this.dispatcher = dispatcher;
+ this.paymentApi = paymentApi;
+ }
+
+ @Subscribe
+ public void handlePaymentInfoEvent(final PaymentInfoEvent event) {
+// String paymentId = event.getPaymentId();
+// PaymentAttempt attempt = paymentApi.getPaymentAttemptForPaymentId(paymentId);
+// UUID accountId = attempt.getAccountId();
+// dispatcher.processOverdueForAccount(accountId);
+ }
+
+ @Subscribe
+ public void handlePaymentErrorEvent(final PaymentErrorEvent event) {
+// UUID accountId = event.getAccountId();
+// dispatcher.processOverdueForAccount(accountId);
+ }
+
+ public void handleNextOverdueCheck(UUID overdueableId) {
+// dispatcher.processOverdue(overdueableId);
+ }
+
+
+}
diff --git a/overdue/src/main/java/com/ning/billing/overdue/OverdueProperties.java b/overdue/src/main/java/com/ning/billing/overdue/OverdueProperties.java
index 267eeb0..b4f4d0e 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/OverdueProperties.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/OverdueProperties.java
@@ -26,19 +26,9 @@ import com.ning.billing.config.NotificationConfig;
public interface OverdueProperties extends NotificationConfig, KillbillConfig {
@Override
- @Config("killbill.overdue.dao.claim.time")
- @Default("60000")
- public long getDaoClaimTimeMs();
-
- @Override
- @Config("killbill.overdue.dao.ready.max")
- @Default("10")
- public int getDaoMaxReadyEvents();
-
- @Override
@Config("killbill.overdue.engine.notifications.sleep")
@Default("500")
- public long getNotificationSleepTimeMs();
+ public long getSleepTimeMs();
@Override
@Config("killbill.notifications.off")
diff --git a/overdue/src/main/java/com/ning/billing/overdue/wrapper/OverdueWrapper.java b/overdue/src/main/java/com/ning/billing/overdue/wrapper/OverdueWrapper.java
index 0223803..97220d5 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/wrapper/OverdueWrapper.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/wrapper/OverdueWrapper.java
@@ -16,10 +16,10 @@
package com.ning.billing.overdue.wrapper;
-import com.ning.billing.catalog.api.CatalogApiException;
import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.junction.api.BlockingApi;
+import com.ning.billing.overdue.OverdueApiException;
import com.ning.billing.overdue.OverdueState;
import com.ning.billing.overdue.applicator.OverdueStateApplicator;
import com.ning.billing.overdue.calculator.BillingStateCalculator;
@@ -49,15 +49,20 @@ public class OverdueWrapper<T extends Blockable> {
this.overdueStateApplicator = overdueStateApplicator;
}
- public OverdueState<T> refresh() throws OverdueError, CatalogApiException, EntitlementUserApiException {
- OverdueState<T> nextOverdueState;
- BillingState<T> billingState = billingStateCalcuator.calculateBillingState(overdueable);
- String previousOverdueStateName = api.getBlockingStateFor(overdueable).getStateName();
- nextOverdueState = overdueStateSet.calculateOverdueState(billingState, clock.getUTCNow());
- if (!previousOverdueStateName.equals(nextOverdueState.getName())) {
- overdueStateApplicator.apply(overdueable, nextOverdueState, nextOverdueState, overdueStateSet.dateOfNextCheck(billingState, clock.getUTCNow()));
- }
+ public OverdueState<T> refresh() throws OverdueError, OverdueApiException {
+ try {
+ OverdueState<T> nextOverdueState;
+ BillingState<T> billingState = billingStateCalcuator.calculateBillingState(overdueable);
+ String previousOverdueStateName = api.getBlockingStateFor(overdueable).getStateName();
+ nextOverdueState = overdueStateSet.calculateOverdueState(billingState, clock.getUTCNow());
+
+ if(!previousOverdueStateName.equals(nextOverdueState.getName())) {
+ overdueStateApplicator.apply(overdueable, nextOverdueState, nextOverdueState);
+ }
- return nextOverdueState;
+ return nextOverdueState;
+ } catch (EntitlementUserApiException e) {
+ throw new OverdueError(e);
+ }
}
}
\ No newline at end of file
diff --git a/overdue/src/main/java/com/ning/billing/overdue/wrapper/OverdueWrapperFactory.java b/overdue/src/main/java/com/ning/billing/overdue/wrapper/OverdueWrapperFactory.java
index d542e24..0fd6854 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/wrapper/OverdueWrapperFactory.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/wrapper/OverdueWrapperFactory.java
@@ -16,11 +16,19 @@
package com.ning.billing.overdue.wrapper;
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.google.inject.Inject;
import com.ning.billing.ErrorCode;
+import com.ning.billing.entitlement.api.user.EntitlementUserApi;
+import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
import com.ning.billing.entitlement.api.user.SubscriptionBundle;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.junction.api.BlockingApi;
+import com.ning.billing.junction.api.BlockingState;
import com.ning.billing.overdue.applicator.OverdueStateApplicator;
import com.ning.billing.overdue.calculator.BillingStateCalculatorBundle;
import com.ning.billing.overdue.config.OverdueConfig;
@@ -29,8 +37,10 @@ import com.ning.billing.overdue.service.ExtendedOverdueService;
import com.ning.billing.util.clock.Clock;
public class OverdueWrapperFactory {
+ private static final Logger log = LoggerFactory.getLogger(OverdueWrapperFactory.class);
private final OverdueConfig overdueConfig;
+ private final EntitlementUserApi entitlementApi;
private final BillingStateCalculatorBundle billingStateCalcuatorBundle;
private final OverdueStateApplicator<SubscriptionBundle> overdueStateApplicatorBundle;
private final BlockingApi api;
@@ -38,9 +48,12 @@ public class OverdueWrapperFactory {
@Inject
public OverdueWrapperFactory(BlockingApi api, ExtendedOverdueService service, Clock clock,
- BillingStateCalculatorBundle billingStateCalcuatorBundle, OverdueStateApplicator<SubscriptionBundle> overdueStateApplicatorBundle) {
+ BillingStateCalculatorBundle billingStateCalcuatorBundle,
+ OverdueStateApplicator<SubscriptionBundle> overdueStateApplicatorBundle,
+ EntitlementUserApi entitlementApi) {
this.billingStateCalcuatorBundle = billingStateCalcuatorBundle;
this.overdueStateApplicatorBundle = overdueStateApplicatorBundle;
+ this.entitlementApi = entitlementApi;
this.overdueConfig = service.getOverdueConfig();
this.api = api;
this.clock = clock;
@@ -56,5 +69,26 @@ public class OverdueWrapperFactory {
}
}
+ @SuppressWarnings("unchecked")
+ public <T extends Blockable> OverdueWrapper<T> createOverdueWrapperFor(UUID id) throws OverdueError {
+ BlockingState state = api.getBlockingStateFor(id);
+
+ try {
+ switch (state.getType()) {
+ case SUBSCRIPTION_BUNDLE : {
+ SubscriptionBundle bundle = entitlementApi.getBundleFromId(id);
+ return (OverdueWrapper<T>)new OverdueWrapper<SubscriptionBundle>(bundle, api, overdueConfig.getBundleStateSet(),
+ clock, billingStateCalcuatorBundle, overdueStateApplicatorBundle );
+ }
+ default : {
+ throw new OverdueError(ErrorCode.OVERDUE_TYPE_NOT_SUPPORTED, id, state.getType());
+ }
+
+ }
+ } catch (EntitlementUserApiException e) {
+ throw new OverdueError(e);
+ }
+ }
+
}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/notification/MockOverdueCheckPoster.java b/overdue/src/test/java/com/ning/billing/overdue/notification/MockOverdueCheckPoster.java
index 29d30ca..c1cfb65 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/notification/MockOverdueCheckPoster.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/notification/MockOverdueCheckPoster.java
@@ -17,7 +17,6 @@
package com.ning.billing.overdue.notification;
import org.joda.time.DateTime;
-import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
import com.ning.billing.junction.api.Blockable;
import com.ning.billing.ovedue.notification.OverdueCheckPoster;
@@ -25,9 +24,15 @@ import com.ning.billing.ovedue.notification.OverdueCheckPoster;
public class MockOverdueCheckPoster implements OverdueCheckPoster {
@Override
- public void insertOverdueCheckNotification(Transmogrifier transactionalDao, Blockable overdueable,
+ public void insertOverdueCheckNotification(Blockable overdueable,
DateTime futureNotificationTime) {
// TODO Auto-generated method stub
}
+
+ @Override
+ public void clearNotificationsFor(Blockable blockable) {
+ // TODO Auto-generated method stub
+
+ }
}
diff --git a/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java b/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java
index dca8cb7..7f48dda 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java
@@ -28,8 +28,6 @@ import org.apache.commons.io.IOUtils;
import org.joda.time.DateTime;
import org.skife.config.ConfigurationObjectFactory;
import org.skife.jdbi.v2.IDBI;
-import org.skife.jdbi.v2.Transaction;
-import org.skife.jdbi.v2.TransactionStatus;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -54,9 +52,9 @@ import com.ning.billing.mock.glue.MockJunctionModule;
import com.ning.billing.ovedue.notification.DefaultOverdueCheckNotifier;
import com.ning.billing.ovedue.notification.DefaultOverdueCheckPoster;
import com.ning.billing.ovedue.notification.OverdueCheckPoster;
-import com.ning.billing.ovedue.notification.OverdueListener;
import com.ning.billing.overdue.OverdueProperties;
import com.ning.billing.overdue.glue.OverdueModule;
+import com.ning.billing.overdue.listener.OverdueListener;
import com.ning.billing.util.bus.Bus;
import com.ning.billing.util.bus.InMemoryBus;
import com.ning.billing.util.callcontext.CallContextFactory;
@@ -68,7 +66,6 @@ import com.ning.billing.util.customfield.dao.CustomFieldDao;
import com.ning.billing.util.globallocker.GlobalLocker;
import com.ning.billing.util.globallocker.MySqlGlobalLocker;
import com.ning.billing.util.notificationq.DefaultNotificationQueueService;
-import com.ning.billing.util.notificationq.DummySqlTest;
import com.ning.billing.util.notificationq.NotificationQueueService;
import com.ning.billing.util.notificationq.dao.NotificationSqlDao;
import com.ning.billing.util.tag.dao.AuditedTagDao;
@@ -77,7 +74,7 @@ import com.ning.billing.util.tag.dao.TagDao;
public class TestOverdueCheckNotifier {
private Clock clock;
private DefaultOverdueCheckNotifier notifier;
- private DummySqlTest dao;
+
private Bus eventBus;
private MysqlTestingHelper helper;
private OverdueListenerMock listener;
@@ -88,11 +85,11 @@ public class TestOverdueCheckNotifier {
UUID latestSubscriptionId = null;
public OverdueListenerMock() {
- super();
+ super(null,null);
}
@Override
- public void handleNextOverdueCheck(UUID subscriptionId, DateTime eventDateTime) {
+ public void handleNextOverdueCheck(UUID subscriptionId) {
eventCount++;
latestSubscriptionId=subscriptionId;
}
@@ -158,7 +155,6 @@ public class TestOverdueCheckNotifier {
eventBus.start();
notifier.initialize();
notifier.start();
- dao = dbi.onDemand(DummySqlTest.class);
}
private void startMysql() throws IOException, ClassNotFoundException, SQLException {
@@ -180,16 +176,7 @@ public class TestOverdueCheckNotifier {
final OverdueCheckPoster poster = new DefaultOverdueCheckPoster(notificationQueueService);
-
- dao.inTransaction(new Transaction<Void, DummySqlTest>() {
- @Override
- public Void inTransaction(DummySqlTest transactional,
- TransactionStatus status) throws Exception {
-
- poster.insertOverdueCheckNotification(transactional, blockable, readyTime);
- return null;
- }
- });
+ poster.insertOverdueCheckNotification(blockable, readyTime);
// Move time in the future after the notification effectiveDate
diff --git a/server/src/main/java/com/ning/billing/server/listeners/KillbillGuiceListener.java b/server/src/main/java/com/ning/billing/server/listeners/KillbillGuiceListener.java
index 227e94a..1aaef9b 100644
--- a/server/src/main/java/com/ning/billing/server/listeners/KillbillGuiceListener.java
+++ b/server/src/main/java/com/ning/billing/server/listeners/KillbillGuiceListener.java
@@ -72,9 +72,11 @@ public class KillbillGuiceListener extends SetupServer
killbillBusService = theInjector.getInstance(BusService.class);
killbilleventHandler = theInjector.getInstance(KillbillEventHandler.class);
+ /*
ObjectMapper mapper = theInjector.getInstance(ObjectMapper.class);
mapper.setPropertyNamingStrategy(new PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy());
-
+*/
+
//
// Fire all Startup levels up to service start
//
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java b/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
index 4b21087..414f2a0 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestAccount.java
@@ -71,11 +71,11 @@ public class TestAccount extends TestJaxrsBase {
AccountJson objFromJson = mapper.readValue(baseJson, AccountJson.class);
Assert.assertTrue(objFromJson.equals(input));
- // Update ACCOUNT
- AccountJson newInput = new AccountJson(objFromJson.getAcountId(),
+ // Update Account
+ AccountJson newInput = new AccountJson(objFromJson.getAccountId(),
"zozo", 4, objFromJson.getExternalKey(), "rr@google.com", 18, "EUR", "none", "UTC", "bl1", "bh2", "", "ca", "usa", "415-255-2991");
baseJson = mapper.writeValueAsString(newInput);
- final String uri = BaseJaxrsResource.ACCOUNTS_PATH + "/" + objFromJson.getAcountId();
+ final String uri = BaseJaxrsResource.ACCOUNTS_PATH + "/" + objFromJson.getAccountId();
response = doPut(uri, baseJson, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
Assert.assertEquals(response.getStatusCode(), Status.OK.getStatusCode());
baseJson = response.getResponseBody();
@@ -88,7 +88,7 @@ public class TestAccount extends TestJaxrsBase {
public void testUpdateNonExistentAccount() throws Exception {
AccountJson input = getAccountJson("xoxo", "shghaahwe", "xoxo@yahoo.com");
String baseJson = mapper.writeValueAsString(input);
- final String uri = BaseJaxrsResource.ACCOUNTS_PATH + "/" + input.getAcountId();
+ final String uri = BaseJaxrsResource.ACCOUNTS_PATH + "/" + input.getAccountId();
Response response = doPut(uri, baseJson, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
Assert.assertEquals(response.getStatusCode(), Status.NO_CONTENT.getStatusCode());
String body = response.getResponseBody();
@@ -113,27 +113,25 @@ public class TestAccount extends TestJaxrsBase {
@Test(groups="slow", enabled=true)
public void testAccountTimeline() throws Exception {
- DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
- clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
+ clock.setTime(new DateTime(2012, 4, 25, 0, 3, 42, 0));
AccountJson accountJson = createAccount("poney", "shdddqgfhwe", "poney@yahoo.com");
assertNotNull(accountJson);
- BundleJsonNoSubsciptions bundleJson = createBundle(accountJson.getAcountId(), "996599");
+ BundleJsonNoSubsciptions bundleJson = createBundle(accountJson.getAccountId(), "996599");
assertNotNull(bundleJson);
SubscriptionJsonNoEvents subscriptionJson = createSubscription(bundleJson.getBundleId(), "Shotgun", ProductCategory.BASE.toString(), BillingPeriod.MONTHLY.toString(), true);
assertNotNull(subscriptionJson);
// MOVE AFTER TRIAL
- Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(3).plusDays(1));
- clock.addDeltaFromReality(it.toDurationMillis());
+ clock.addMonths(3);
crappyWaitForLackOfProperSynchonization();
- final String uri = BaseJaxrsResource.ACCOUNTS_PATH + "/" + accountJson.getAcountId() + "/" + BaseJaxrsResource.TIMELINE;
+ final String uri = BaseJaxrsResource.ACCOUNTS_PATH + "/" + accountJson.getAccountId() + "/" + BaseJaxrsResource.TIMELINE;
Response response = doGet(uri, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
Assert.assertEquals(response.getStatusCode(), Status.OK.getStatusCode());
@@ -142,7 +140,7 @@ public class TestAccount extends TestJaxrsBase {
assertNotNull(objFromJson);
log.info(baseJson);
- Assert.assertEquals(objFromJson.getPayments().size(), 3);
+ Assert.assertEquals(objFromJson.getPayments().size(), 3);
Assert.assertEquals(objFromJson.getInvoices().size(), 4);
Assert.assertEquals(objFromJson.getBundles().size(), 1);
Assert.assertEquals(objFromJson.getBundles().get(0).getSubscriptions().size(), 1);
@@ -162,7 +160,7 @@ public class TestAccount extends TestJaxrsBase {
Map<String, String> queryParams = new HashMap<String, String>();
queryParams.put(BaseJaxrsResource.QUERY_TAGS, input.getName());
- String uri = BaseJaxrsResource.ACCOUNTS_PATH + "/" + BaseJaxrsResource.TAGS + "/" + accountJson.getAcountId() ;
+ String uri = BaseJaxrsResource.ACCOUNTS_PATH + "/" + BaseJaxrsResource.TAGS + "/" + accountJson.getAccountId() ;
response = doPost(uri, null, queryParams, DEFAULT_HTTP_TIMEOUT_SEC);
assertEquals(response.getStatusCode(), Status.CREATED.getStatusCode());
@@ -192,7 +190,7 @@ public class TestAccount extends TestJaxrsBase {
customFields.add(new CustomFieldJson("3", "value3"));
String baseJson = mapper.writeValueAsString(customFields);
- String uri = BaseJaxrsResource.ACCOUNTS_PATH + "/" + BaseJaxrsResource.CUSTOM_FIELDS + "/" + accountJson.getAcountId() ;
+ String uri = BaseJaxrsResource.ACCOUNTS_PATH + "/" + BaseJaxrsResource.CUSTOM_FIELDS + "/" + accountJson.getAccountId() ;
Response response = doPost(uri,baseJson, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
assertEquals(response.getStatusCode(), Status.CREATED.getStatusCode());
String location = response.getHeader("Location");
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestBundle.java b/server/src/test/java/com/ning/billing/jaxrs/TestBundle.java
index f0182bd..7795d0c 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestBundle.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestBundle.java
@@ -44,7 +44,7 @@ public class TestBundle extends TestJaxrsBase {
public void testBundleOk() throws Exception {
AccountJson accountJson = createAccount("xlxl", "shdgfhkkl", "xlxl@yahoo.com");
- BundleJsonNoSubsciptions bundleJson = createBundle(accountJson.getAcountId(), "12345");
+ BundleJsonNoSubsciptions bundleJson = createBundle(accountJson.getAccountId(), "12345");
// Retrieves by external key
Map<String, String> queryParams = new HashMap<String, String>();
@@ -61,10 +61,10 @@ public class TestBundle extends TestJaxrsBase {
public void testBundleFromAccount() throws Exception {
AccountJson accountJson = createAccount("xaxa", "saagfhkkl", "xaxa@yahoo.com");
- BundleJsonNoSubsciptions bundleJson1 = createBundle(accountJson.getAcountId(), "156567");
- BundleJsonNoSubsciptions bundleJson2 = createBundle(accountJson.getAcountId(), "265658");
+ BundleJsonNoSubsciptions bundleJson1 = createBundle(accountJson.getAccountId(), "156567");
+ BundleJsonNoSubsciptions bundleJson2 = createBundle(accountJson.getAccountId(), "265658");
- String uri = BaseJaxrsResource.ACCOUNTS_PATH + "/" + accountJson.getAcountId().toString() + "/" + BaseJaxrsResource.BUNDLES;
+ String uri = BaseJaxrsResource.ACCOUNTS_PATH + "/" + accountJson.getAccountId().toString() + "/" + BaseJaxrsResource.BUNDLES;
Response response = doGet(uri, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
Assert.assertEquals(response.getStatusCode(), Status.OK.getStatusCode());
String baseJson = response.getResponseBody();
@@ -96,7 +96,7 @@ public class TestBundle extends TestJaxrsBase {
Assert.assertEquals(response.getStatusCode(), Status.NO_CONTENT.getStatusCode());
- uri = BaseJaxrsResource.ACCOUNTS_PATH + "/" + accountJson.getAcountId().toString() + "/" + BaseJaxrsResource.BUNDLES;
+ uri = BaseJaxrsResource.ACCOUNTS_PATH + "/" + accountJson.getAccountId().toString() + "/" + BaseJaxrsResource.BUNDLES;
response = doGet(uri, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
Assert.assertEquals(response.getStatusCode(), Status.OK.getStatusCode());
String baseJson = response.getResponseBody();
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestInvoice.java b/server/src/test/java/com/ning/billing/jaxrs/TestInvoice.java
index 9a039fd..aba67b8 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestInvoice.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestInvoice.java
@@ -38,7 +38,7 @@ import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.catalog.api.ProductCategory;
import com.ning.billing.jaxrs.json.AccountJson;
import com.ning.billing.jaxrs.json.BundleJsonNoSubsciptions;
-import com.ning.billing.jaxrs.json.InvoiceJson;
+import com.ning.billing.jaxrs.json.InvoiceJsonSimple;
import com.ning.billing.jaxrs.json.SubscriptionJsonNoEvents;
import com.ning.billing.jaxrs.resources.BaseJaxrsResource;
import com.ning.http.client.Response;
@@ -60,7 +60,7 @@ public class TestInvoice extends TestJaxrsBase {
AccountJson accountJson = createAccount("poupou", "qhddffrwe", "poupou@yahoo.com");
assertNotNull(accountJson);
- BundleJsonNoSubsciptions bundleJson = createBundle(accountJson.getAcountId(), "9967599");
+ BundleJsonNoSubsciptions bundleJson = createBundle(accountJson.getAccountId(), "9967599");
assertNotNull(bundleJson);
SubscriptionJsonNoEvents subscriptionJson = createSubscription(bundleJson.getBundleId(), "Shotgun", ProductCategory.BASE.toString(), BillingPeriod.MONTHLY.toString(), true);
@@ -74,12 +74,12 @@ public class TestInvoice extends TestJaxrsBase {
String uri = BaseJaxrsResource.INVOICES_PATH;
Map<String, String> queryParams = new HashMap<String, String>();
- queryParams.put(BaseJaxrsResource.QUERY_ACCOUNT_ID, accountJson.getAcountId());
+ queryParams.put(BaseJaxrsResource.QUERY_ACCOUNT_ID, accountJson.getAccountId());
Response response = doGet(uri, queryParams, DEFAULT_HTTP_TIMEOUT_SEC);
Assert.assertEquals(response.getStatusCode(), Status.OK.getStatusCode());
String baseJson = response.getResponseBody();
- List<InvoiceJson> objFromJson = mapper.readValue(baseJson, new TypeReference<List<InvoiceJson>>() {});
+ List<InvoiceJsonSimple> objFromJson = mapper.readValue(baseJson, new TypeReference<List<InvoiceJsonSimple>>() {});
assertNotNull(objFromJson);
log.info(baseJson);
assertEquals(objFromJson.size(), 4);
@@ -89,7 +89,7 @@ public class TestInvoice extends TestJaxrsBase {
response = doGet(uri, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
Assert.assertEquals(response.getStatusCode(), Status.OK.getStatusCode());
baseJson = response.getResponseBody();
- InvoiceJson firstInvoiceJson = mapper.readValue(baseJson, InvoiceJson.class);
+ InvoiceJsonSimple firstInvoiceJson = mapper.readValue(baseJson, InvoiceJsonSimple.class);
assertNotNull(objFromJson);
assertEquals(firstInvoiceJson, objFromJson.get(0));
@@ -101,7 +101,7 @@ public class TestInvoice extends TestJaxrsBase {
response = doPost(uri, null, queryParams, DEFAULT_HTTP_TIMEOUT_SEC);
Assert.assertEquals(response.getStatusCode(), Status.OK.getStatusCode());
baseJson = response.getResponseBody();
- InvoiceJson futureInvoice = mapper.readValue(baseJson, InvoiceJson.class);
+ InvoiceJsonSimple futureInvoice = mapper.readValue(baseJson, InvoiceJsonSimple.class);
assertNotNull(futureInvoice);
log.info(baseJson);
@@ -118,7 +118,7 @@ public class TestInvoice extends TestJaxrsBase {
response = doGet(uri, queryParams, DEFAULT_HTTP_TIMEOUT_SEC);
assertEquals(response.getStatusCode(), Status.OK.getStatusCode());
baseJson = response.getResponseBody();
- objFromJson = mapper.readValue(baseJson, new TypeReference<List<InvoiceJson>>() {});
+ objFromJson = mapper.readValue(baseJson, new TypeReference<List<InvoiceJsonSimple>>() {});
assertNotNull(objFromJson);
log.info(baseJson);
assertEquals(objFromJson.size(), 5);
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java b/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java
index cf9eddd..0a0d619 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java
@@ -91,7 +91,7 @@ public class TestJaxrsBase {
private final static String PLUGIN_NAME = "noop";
- protected static final int DEFAULT_HTTP_TIMEOUT_SEC = 5;
+ protected static final int DEFAULT_HTTP_TIMEOUT_SEC = 500000; // 5;
protected static final Map<String, String> DEFAULT_EMPTY_QUERY = new HashMap<String, String>();
@@ -235,7 +235,7 @@ public class TestJaxrsBase {
mapper.registerModule(new JodaModule());
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
- mapper.setPropertyNamingStrategy(new PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy());
+ //mapper.setPropertyNamingStrategy(new PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy());
busHandler = new TestApiListener(null);
this.helper = listener.getMysqlTestingHelper();
@@ -491,7 +491,7 @@ public class TestJaxrsBase {
* but until we have a strong need for it, this is in the TODO list...
*/
protected void crappyWaitForLackOfProperSynchonization() throws Exception {
- Thread.sleep(7000);
+ Thread.sleep(5000);
}
}
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestSubscription.java b/server/src/test/java/com/ning/billing/jaxrs/TestSubscription.java
index 4a74dfc..d43c858 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestSubscription.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestSubscription.java
@@ -53,7 +53,7 @@ public class TestSubscription extends TestJaxrsBase {
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
AccountJson accountJson = createAccount("xil", "shdxilhkkl", "xil@yahoo.com");
- BundleJsonNoSubsciptions bundleJson = createBundle(accountJson.getAcountId(), "99999");
+ BundleJsonNoSubsciptions bundleJson = createBundle(accountJson.getAccountId(), "99999");
String productName = "Shotgun";
BillingPeriod term = BillingPeriod.MONTHLY;
diff --git a/server/src/test/resources/killbill.properties b/server/src/test/resources/killbill.properties
index 3463266..9aa3e66 100644
--- a/server/src/test/resources/killbill.properties
+++ b/server/src/test/resources/killbill.properties
@@ -10,6 +10,11 @@ user.timezone=UTC
com.ning.core.server.jetty.logPath=/var/tmp/.logs
+killbill.payment.engine.notifications.sleep=100
+killbill.invoice.engine.notifications.sleep=100
+killbill.entitlement.engine.notifications.sleep=100
+killbill.billing.util.persistent.bus.sleep=100
+killbill.billing.util.persistent.bus.nbThreads=1
# Local DB
#com.ning.billing.dbi.test.useLocalDb=true
diff --git a/util/src/main/java/com/ning/billing/util/bus/dao/BusEventEntry.java b/util/src/main/java/com/ning/billing/util/bus/dao/BusEventEntry.java
index b9c6faa..8e98211 100644
--- a/util/src/main/java/com/ning/billing/util/bus/dao/BusEventEntry.java
+++ b/util/src/main/java/com/ning/billing/util/bus/dao/BusEventEntry.java
@@ -17,19 +17,19 @@ package com.ning.billing.util.bus.dao;
import org.joda.time.DateTime;
-import com.ning.billing.util.notificationq.NotificationLifecycle;
+import com.ning.billing.util.queue.PersistentQueueEntryLifecycle;
-public class BusEventEntry implements NotificationLifecycle {
+public class BusEventEntry implements PersistentQueueEntryLifecycle {
private final long id;
private final String owner;
private final String createdOwner;
private final DateTime nextAvailable;
- private final NotificationLifecycleState processingState;
+ private final PersistentQueueEntryLifecycleState processingState;
private final String busEventClass;
private final String busEventJson;
- public BusEventEntry(final long id, final String createdOwner, final String owner, final DateTime nextAvailable, NotificationLifecycleState processingState, final String busEventClass, final String busEventJson) {
+ public BusEventEntry(final long id, final String createdOwner, final String owner, final DateTime nextAvailable, PersistentQueueEntryLifecycleState processingState, final String busEventClass, final String busEventJson) {
this.id = id;
this.createdOwner = createdOwner;
this.owner = owner;
@@ -73,7 +73,7 @@ public class BusEventEntry implements NotificationLifecycle {
}
@Override
- public NotificationLifecycleState getProcessingState() {
+ public PersistentQueueEntryLifecycleState getProcessingState() {
return processingState;
}
diff --git a/util/src/main/java/com/ning/billing/util/bus/dao/PersistentBusSqlDao.java b/util/src/main/java/com/ning/billing/util/bus/dao/PersistentBusSqlDao.java
index 7da7d08..ca98098 100644
--- a/util/src/main/java/com/ning/billing/util/bus/dao/PersistentBusSqlDao.java
+++ b/util/src/main/java/com/ning/billing/util/bus/dao/PersistentBusSqlDao.java
@@ -34,7 +34,7 @@ import org.skife.jdbi.v2.tweak.ResultSetMapper;
import com.ning.billing.util.dao.BinderBase;
import com.ning.billing.util.dao.MapperBase;
-import com.ning.billing.util.notificationq.NotificationLifecycle.NotificationLifecycleState;
+import com.ning.billing.util.queue.PersistentQueueEntryLifecycle.PersistentQueueEntryLifecycleState;
@ExternalizedSqlViaStringTemplate3()
public interface PersistentBusSqlDao extends Transactional<PersistentBusSqlDao>, CloseMe {
@@ -72,7 +72,7 @@ public interface PersistentBusSqlDao extends Transactional<PersistentBusSqlDao>,
stmt.bind("creatingOwner", evt.getCreatedOwner());
stmt.bind("processingAvailableDate", getDate(evt.getNextAvailableDate()));
stmt.bind("processingOwner", evt.getOwner());
- stmt.bind("processingState", NotificationLifecycleState.AVAILABLE.toString());
+ stmt.bind("processingState", PersistentQueueEntryLifecycleState.AVAILABLE.toString());
}
}
@@ -88,7 +88,7 @@ public interface PersistentBusSqlDao extends Transactional<PersistentBusSqlDao>,
final String eventJson = r.getString("event_json");
final DateTime nextAvailableDate = getDate(r, "processing_available_date");
final String processingOwner = r.getString("processing_owner");
- final NotificationLifecycleState processingState = NotificationLifecycleState.valueOf(r.getString("processing_state"));
+ final PersistentQueueEntryLifecycleState processingState = PersistentQueueEntryLifecycleState.valueOf(r.getString("processing_state"));
return new BusEventEntry(recordId, createdOwner, processingOwner, nextAvailableDate, processingState, className, eventJson);
}
diff --git a/util/src/main/java/com/ning/billing/util/bus/PersistentBus.java b/util/src/main/java/com/ning/billing/util/bus/PersistentBus.java
index bfce245..92b35d7 100644
--- a/util/src/main/java/com/ning/billing/util/bus/PersistentBus.java
+++ b/util/src/main/java/com/ning/billing/util/bus/PersistentBus.java
@@ -33,19 +33,19 @@ import org.slf4j.LoggerFactory;
import com.google.common.eventbus.EventBus;
import com.google.inject.Inject;
+import com.google.inject.name.Named;
+import com.ning.billing.config.PersistentQueueConfig;
import com.ning.billing.util.Hostname;
import com.ning.billing.util.bus.dao.BusEventEntry;
import com.ning.billing.util.bus.dao.PersistentBusSqlDao;
import com.ning.billing.util.clock.Clock;
+import com.ning.billing.util.glue.BusModule;
import com.ning.billing.util.queue.PersistentQueueBase;
public class PersistentBus extends PersistentQueueBase implements Bus {
- private final static int NB_BUS_THREADS = 1;
- private final static long TIMEOUT_MSEC = 15L * 1000L; // 15 sec
private final static long DELTA_IN_PROCESSING_TIME_MS = 1000L * 60L * 5L; // 5 minutes
- private final static long SLEEP_TIME_MS = 1000; // 1 sec
private final static int MAX_BUS_EVENTS = 1;
private static final Logger log = LoggerFactory.getLogger(PersistentBus.class);
@@ -80,15 +80,16 @@ public class PersistentBus extends PersistentQueueBase implements Bus {
}
@Inject
- public PersistentBus(final IDBI dbi, final Clock clock) {
- super("Bus", Executors.newFixedThreadPool(NB_BUS_THREADS, new ThreadFactory() {
+ public PersistentBus(final IDBI dbi, final Clock clock, final PersistentBusConfig config) {
+
+ super("Bus", Executors.newFixedThreadPool(config.getNbThreads(), new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new Thread(new ThreadGroup(DefaultBusService.EVENT_BUS_GROUP_NAME),
r,
DefaultBusService.EVENT_BUS_TH_NAME);
}
- }), NB_BUS_THREADS, TIMEOUT_MSEC, SLEEP_TIME_MS);
+ }), config.getNbThreads(), config);
this.dao = dbi.onDemand(PersistentBusSqlDao.class);
this.clock = clock;
this.objectMapper = new ObjectMapper();
diff --git a/util/src/main/java/com/ning/billing/util/bus/PersistentBusConfig.java b/util/src/main/java/com/ning/billing/util/bus/PersistentBusConfig.java
new file mode 100644
index 0000000..a2e9879
--- /dev/null
+++ b/util/src/main/java/com/ning/billing/util/bus/PersistentBusConfig.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package com.ning.billing.util.bus;
+
+import org.skife.config.Config;
+import org.skife.config.Default;
+
+import com.ning.billing.config.PersistentQueueConfig;
+
+public interface PersistentBusConfig extends PersistentQueueConfig {
+
+ @Override
+ @Config("killbill.billing.util.persistent.bus.sleep")
+ @Default("500")
+ public long getSleepTimeMs();
+
+ @Config("killbill.billing.util.persistent.bus.nbThreads")
+ @Default("3")
+ public int getNbThreads();
+}
diff --git a/util/src/main/java/com/ning/billing/util/glue/BusModule.java b/util/src/main/java/com/ning/billing/util/glue/BusModule.java
index 656253d..2793208 100644
--- a/util/src/main/java/com/ning/billing/util/glue/BusModule.java
+++ b/util/src/main/java/com/ning/billing/util/glue/BusModule.java
@@ -16,10 +16,16 @@
package com.ning.billing.util.glue;
+import org.skife.config.ConfigurationObjectFactory;
+
import com.google.inject.AbstractModule;
+import com.google.inject.name.Names;
+import com.ning.billing.config.EntitlementConfig;
+import com.ning.billing.config.PersistentQueueConfig;
import com.ning.billing.util.bus.DefaultBusService;
import com.ning.billing.util.bus.Bus;
import com.ning.billing.util.bus.BusService;
+import com.ning.billing.util.bus.PersistentBusConfig;
import com.ning.billing.util.bus.InMemoryBus;
import com.ning.billing.util.bus.PersistentBus;
@@ -58,9 +64,14 @@ public class BusModule extends AbstractModule {
}
+ protected void configurePersistentBusConfig() {
+ final PersistentBusConfig config = new ConfigurationObjectFactory(System.getProperties()).build(PersistentBusConfig.class);
+ bind(PersistentBusConfig.class).toInstance(config);
+ }
+
private void configurePersistentEventBus() {
+ configurePersistentBusConfig();
bind(Bus.class).to(PersistentBus.class).asEagerSingleton();
-
}
private void configureInMemoryEventBus() {
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/dao/NotificationSqlDao.java b/util/src/main/java/com/ning/billing/util/notificationq/dao/NotificationSqlDao.java
index 1ae51ee..cbfc564 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/dao/NotificationSqlDao.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/dao/NotificationSqlDao.java
@@ -39,7 +39,7 @@ import org.skife.jdbi.v2.tweak.ResultSetMapper;
import com.ning.billing.util.notificationq.DefaultNotification;
import com.ning.billing.util.notificationq.Notification;
-import com.ning.billing.util.notificationq.NotificationLifecycle.NotificationLifecycleState;
+import com.ning.billing.util.queue.PersistentQueueEntryLifecycle.PersistentQueueEntryLifecycleState;
@ExternalizedSqlViaStringTemplate3()
public interface NotificationSqlDao extends Transactional<NotificationSqlDao>, CloseMe {
@@ -78,7 +78,7 @@ public interface NotificationSqlDao extends Transactional<NotificationSqlDao>, C
stmt.bind("queueName", evt.getQueueName());
stmt.bind("processingAvailableDate", getDate(evt.getNextAvailableDate()));
stmt.bind("processingOwner", evt.getOwner());
- stmt.bind("processingState", NotificationLifecycleState.AVAILABLE.toString());
+ stmt.bind("processingState", PersistentQueueEntryLifecycleState.AVAILABLE.toString());
}
}
@@ -96,7 +96,7 @@ public interface NotificationSqlDao extends Transactional<NotificationSqlDao>, C
final DateTime effectiveDate = getDate(r, "effective_date");
final DateTime nextAvailableDate = getDate(r, "processing_available_date");
final String processingOwner = r.getString("processing_owner");
- final NotificationLifecycleState processingState = NotificationLifecycleState.valueOf(r.getString("processing_state"));
+ final PersistentQueueEntryLifecycleState processingState = PersistentQueueEntryLifecycleState.valueOf(r.getString("processing_state"));
return new DefaultNotification(ordering, id, createdOwner, processingOwner, queueName, nextAvailableDate,
processingState, notificationKey, effectiveDate);
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotification.java b/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotification.java
index d6f1453..c71343d 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotification.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotification.java
@@ -27,13 +27,13 @@ public class DefaultNotification extends EntityBase implements Notification {
private final String createdOwner;
private final String queueName;
private final DateTime nextAvailableDate;
- private final NotificationLifecycleState lifecycleState;
+ private final PersistentQueueEntryLifecycleState lifecycleState;
private final String notificationKey;
private final DateTime effectiveDate;
public DefaultNotification(long ordering, UUID id, String createdOwner, String owner, String queueName, DateTime nextAvailableDate,
- NotificationLifecycleState lifecycleState,
+ PersistentQueueEntryLifecycleState lifecycleState,
String notificationKey, DateTime effectiveDate) {
super(id);
this.ordering = ordering;
@@ -47,7 +47,7 @@ public class DefaultNotification extends EntityBase implements Notification {
}
public DefaultNotification(String queueName, String createdOwner, String notificationKey, DateTime effectiveDate) {
- this(-1L, UUID.randomUUID(), createdOwner, null, queueName, null, NotificationLifecycleState.AVAILABLE, notificationKey, effectiveDate);
+ this(-1L, UUID.randomUUID(), createdOwner, null, queueName, null, PersistentQueueEntryLifecycleState.AVAILABLE, notificationKey, effectiveDate);
}
@Override
public Long getOrdering() {
@@ -65,7 +65,7 @@ public class DefaultNotification extends EntityBase implements Notification {
}
@Override
- public NotificationLifecycleState getProcessingState() {
+ public PersistentQueueEntryLifecycleState getProcessingState() {
return lifecycleState;
}
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueue.java b/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueue.java
index 4f114b6..6b50914 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueue.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueue.java
@@ -88,9 +88,9 @@ public class DefaultNotificationQueue extends NotificationQueueBase {
private List<Notification> getReadyNotifications() {
final Date now = clock.getUTCNow().toDate();
- final Date nextAvailable = clock.getUTCNow().plus(config.getDaoClaimTimeMs()).toDate();
+ final Date nextAvailable = clock.getUTCNow().plus(CLAIM_TIME_MS).toDate();
- List<Notification> input = dao.getReadyNotifications(now, hostname, config.getDaoMaxReadyEvents(), getFullQName());
+ List<Notification> input = dao.getReadyNotifications(now, hostname, CLAIM_TIME_MS, getFullQName());
List<Notification> claimedNotifications = new ArrayList<Notification>();
for (Notification cur : input) {
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/Notification.java b/util/src/main/java/com/ning/billing/util/notificationq/Notification.java
index bd3169a..37caa4e 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/Notification.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/Notification.java
@@ -17,9 +17,11 @@
package com.ning.billing.util.notificationq;
import com.ning.billing.util.entity.Entity;
+import com.ning.billing.util.queue.PersistentQueueEntryLifecycle;
+
import org.joda.time.DateTime;
-public interface Notification extends NotificationLifecycle, Entity {
+public interface Notification extends PersistentQueueEntryLifecycle, Entity {
public Long getOrdering();
public String getNotificationKey();
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueue.java b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueue.java
index d5c2425..f28ff63 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueue.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueue.java
@@ -26,45 +26,48 @@ import com.ning.billing.util.queue.QueueLifecycle;
public interface NotificationQueue extends QueueLifecycle {
- /**
- *
- * Record the need to be called back when the notification is ready
- *
- * @param futureNotificationTime the time at which the notification is ready
- * @param notificationKey the key for that notification
- */
- public void recordFutureNotification(final DateTime futureNotificationTime, final NotificationKey notificationKey);
+ /**
+ *
+ * Record the need to be called back when the notification is ready
+ *
+ * @param futureNotificationTime the time at which the notification is ready
+ * @param notificationKey the key for that notification
+ */
+ public void recordFutureNotification(final DateTime futureNotificationTime, final NotificationKey notificationKey);
- /**
- *
- * Record from within a transaction the need to be called back when the notification is ready
- *
- * @param transactionalDao the transactionalDao
- * @param futureNotificationTime the time at which the notification is ready
- * @param notificationKey the key for that notification
- */
- public void recordFutureNotificationFromTransaction(final Transmogrifier transactionalDao,
- final DateTime futureNotificationTime, final NotificationKey notificationKey);
+ /**
+ *
+ * Record from within a transaction the need to be called back when the notification is ready
+ *
+ * @param transactionalDao the transactionalDao
+ * @param futureNotificationTime the time at which the notification is ready
+ * @param notificationKey the key for that notification
+ */
+ public void recordFutureNotificationFromTransaction(final Transmogrifier transactionalDao,
+ final DateTime futureNotificationTime, final NotificationKey notificationKey);
- /**
- * Remove all notifications associated with this key
- *
- * @param key
- */
- public void removeNotificationsByKey(UUID key);
+
+ /**
+ * Remove all notifications associated with this key
+ *
+ * @param key
+ */
+ public void removeNotificationsByKey(UUID key);
+
+ /**
+ * This is only valid when the queue has been configured with isNotificationProcessingOff is true
+ * In which case, it will callback users for all the ready notifications.
+ *
+ * @return the number of entries we processed
+ */
+ public int processReadyNotification();
+
+ /**
+ *
+ * @return the name of that queue
+ */
+ public String getFullQName();
- /**
- * This is only valid when the queue has been configured with isNotificationProcessingOff is true
- * In which case, it will callback users for all the ready notifications.
- *
- * @return the number of entries we processed
- */
- public int processReadyNotification();
- /**
- *
- * @return the name of that queue
- */
- public String getFullQName();
}
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueBase.java b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueBase.java
index 7c82db6..cd3c0c2 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueBase.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueBase.java
@@ -35,11 +35,15 @@ public abstract class NotificationQueueBase extends PersistentQueueBase implemen
protected final static Logger log = LoggerFactory.getLogger(NotificationQueueBase.class);
- protected static final String NOTIFICATION_THREAD_PREFIX = "Notification-";
- protected static final long STOP_WAIT_TIMEOUT_MS = 60000;
-
- protected final String svcName;
- protected final String queueName;
+ public final static int CLAIM_TIME_MS = (5 * 60 * 1000); // 5 minutes
+
+ private final static String NOTIFICATION_THREAD_PREFIX = "Notification-";
+ private final static int NB_THREADS = 1;
+
+
+ private final String svcName;
+ private final String queueName;
+
protected final NotificationQueueHandler handler;
protected final NotificationConfig config;
@@ -64,7 +68,7 @@ public abstract class NotificationQueueBase extends PersistentQueueBase implemen
});
return th;
}
- }), 1, STOP_WAIT_TIMEOUT_MS, config.getNotificationSleepTimeMs());
+ }), NB_THREADS, config);
this.clock = clock;
this.svcName = svcName;
@@ -75,6 +79,21 @@ public abstract class NotificationQueueBase extends PersistentQueueBase implemen
this.nbProcessedEvents = new AtomicLong();
}
+ @Override
+ public void startQueue() {
+ if (config.isNotificationProcessingOff()) {
+ return;
+ }
+ super.startQueue();
+ }
+
+ @Override
+ public void stopQueue() {
+ if (config.isNotificationProcessingOff()) {
+ return;
+ }
+ super.stopQueue();
+ }
@Override
public int processReadyNotification() {
diff --git a/util/src/main/java/com/ning/billing/util/queue/PersistentQueueBase.java b/util/src/main/java/com/ning/billing/util/queue/PersistentQueueBase.java
index a6844ad..0ffe882 100644
--- a/util/src/main/java/com/ning/billing/util/queue/PersistentQueueBase.java
+++ b/util/src/main/java/com/ning/billing/util/queue/PersistentQueueBase.java
@@ -22,26 +22,28 @@ import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.ning.billing.config.PersistentQueueConfig;
+
public abstract class PersistentQueueBase implements QueueLifecycle {
private static final Logger log = LoggerFactory.getLogger(PersistentQueueBase.class);
-
+
+ private static final long waitTimeoutMs = 15L * 1000L; // 15 seconds
+
private final int nbThreads;
private final Executor executor;
private final String svcName;
private final long sleepTimeMs;
- private final long waitTimeoutMs;
private boolean isProcessingEvents;
private int curActiveThreads;
- public PersistentQueueBase(final String svcName, final Executor executor, final int nbThreads, final long waitTimeoutMs, final long sleepTimeMs) {
+ public PersistentQueueBase(final String svcName, final Executor executor, final int nbThreads, final PersistentQueueConfig config) {
this.executor = executor;
this.nbThreads = nbThreads;
this.svcName = svcName;
- this.waitTimeoutMs = waitTimeoutMs;
- this.sleepTimeMs = sleepTimeMs;
+ this.sleepTimeMs = config.getSleepTimeMs();
this.isProcessingEvents = false;
this.curActiveThreads = 0;
}
diff --git a/util/src/test/java/com/ning/billing/util/notificationq/dao/TestNotificationSqlDao.java b/util/src/test/java/com/ning/billing/util/notificationq/dao/TestNotificationSqlDao.java
index 6cf0eb9..7c61363 100644
--- a/util/src/test/java/com/ning/billing/util/notificationq/dao/TestNotificationSqlDao.java
+++ b/util/src/test/java/com/ning/billing/util/notificationq/dao/TestNotificationSqlDao.java
@@ -38,8 +38,8 @@ import com.google.inject.Inject;
import com.ning.billing.dbi.MysqlTestingHelper;
import com.ning.billing.util.notificationq.DefaultNotification;
import com.ning.billing.util.notificationq.Notification;
-import com.ning.billing.util.notificationq.NotificationLifecycle.NotificationLifecycleState;
import com.ning.billing.util.notificationq.dao.NotificationSqlDao.NotificationSqlMapper;
+import com.ning.billing.util.queue.PersistentQueueEntryLifecycle.PersistentQueueEntryLifecycleState;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@@ -116,7 +116,7 @@ public class TestNotificationSqlDao {
assertEquals(notification.getNotificationKey(), notificationKey);
validateDate(notification.getEffectiveDate(), effDt);
assertEquals(notification.getOwner(), null);
- assertEquals(notification.getProcessingState(), NotificationLifecycleState.AVAILABLE);
+ assertEquals(notification.getProcessingState(), PersistentQueueEntryLifecycleState.AVAILABLE);
assertEquals(notification.getNextAvailableDate(), null);
DateTime nextAvailable = now.plusMinutes(5);
@@ -128,7 +128,7 @@ public class TestNotificationSqlDao {
assertEquals(notification.getNotificationKey(), notificationKey);
validateDate(notification.getEffectiveDate(), effDt);
assertEquals(notification.getOwner().toString(), ownerId);
- assertEquals(notification.getProcessingState(), NotificationLifecycleState.IN_PROCESSING);
+ assertEquals(notification.getProcessingState(), PersistentQueueEntryLifecycleState.IN_PROCESSING);
validateDate(notification.getNextAvailableDate(), nextAvailable);
dao.clearNotification(notification.getId().toString(), ownerId);
@@ -137,7 +137,7 @@ public class TestNotificationSqlDao {
assertEquals(notification.getNotificationKey(), notificationKey);
validateDate(notification.getEffectiveDate(), effDt);
//assertEquals(notification.getOwner(), null);
- assertEquals(notification.getProcessingState(), NotificationLifecycleState.PROCESSED);
+ assertEquals(notification.getProcessingState(), PersistentQueueEntryLifecycleState.PROCESSED);
validateDate(notification.getNextAvailableDate(), nextAvailable);
}
diff --git a/util/src/test/java/com/ning/billing/util/notificationq/MockNotificationQueue.java b/util/src/test/java/com/ning/billing/util/notificationq/MockNotificationQueue.java
index 7d8b477..8e9cce4 100644
--- a/util/src/test/java/com/ning/billing/util/notificationq/MockNotificationQueue.java
+++ b/util/src/test/java/com/ning/billing/util/notificationq/MockNotificationQueue.java
@@ -28,8 +28,8 @@ import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
import com.ning.billing.config.NotificationConfig;
import com.ning.billing.util.clock.Clock;
-import com.ning.billing.util.notificationq.NotificationLifecycle.NotificationLifecycleState;
import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueHandler;
+import com.ning.billing.util.queue.PersistentQueueEntryLifecycle.PersistentQueueEntryLifecycleState;
public class MockNotificationQueue extends NotificationQueueBase implements NotificationQueue {
private final TreeSet<Notification> notifications;
@@ -67,7 +67,7 @@ public class MockNotificationQueue extends NotificationQueueBase implements Noti
List<Notification> result = new ArrayList<Notification>();
for (Notification notification : notifications) {
- if (notification.getProcessingState() == NotificationLifecycleState.AVAILABLE) {
+ if (notification.getProcessingState() == PersistentQueueEntryLifecycleState.AVAILABLE) {
result.add(notification);
}
}
@@ -96,7 +96,7 @@ public class MockNotificationQueue extends NotificationQueueBase implements Noti
result = readyNotifications.size();
for (Notification cur : readyNotifications) {
handler.handleReadyNotification(cur.getNotificationKey(), cur.getEffectiveDate());
- DefaultNotification processedNotification = new DefaultNotification(-1L, cur.getId(), hostname, hostname, "MockQueue", clock.getUTCNow().plus(config.getDaoClaimTimeMs()), NotificationLifecycleState.PROCESSED, cur.getNotificationKey(), cur.getEffectiveDate());
+ DefaultNotification processedNotification = new DefaultNotification(-1L, cur.getId(), hostname, hostname, "MockQueue", clock.getUTCNow().plus(CLAIM_TIME_MS), PersistentQueueEntryLifecycleState.PROCESSED, cur.getNotificationKey(), cur.getEffectiveDate());
oldNotifications.add(cur);
processedNotifications.add(processedNotification);
}
diff --git a/util/src/test/java/com/ning/billing/util/notificationq/TestNotificationQueue.java b/util/src/test/java/com/ning/billing/util/notificationq/TestNotificationQueue.java
index 80f4a5c..50f0a68 100644
--- a/util/src/test/java/com/ning/billing/util/notificationq/TestNotificationQueue.java
+++ b/util/src/test/java/com/ning/billing/util/notificationq/TestNotificationQueue.java
@@ -288,17 +288,9 @@ public class TestNotificationQueue {
return false;
}
@Override
- public long getNotificationSleepTimeMs() {
+ public long getSleepTimeMs() {
return 10;
}
- @Override
- public int getDaoMaxReadyEvents() {
- return 1;
- }
- @Override
- public long getDaoClaimTimeMs() {
- return 60000;
- }
};
@@ -397,17 +389,9 @@ public class TestNotificationQueue {
return off;
}
@Override
- public long getNotificationSleepTimeMs() {
+ public long getSleepTimeMs() {
return sleepTime;
}
- @Override
- public int getDaoMaxReadyEvents() {
- return maxReadyEvents;
- }
- @Override
- public long getDaoClaimTimeMs() {
- return claimTimeMs;
- }
};
}