killbill-aplcache
Changes
osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/api/BusinessInvoicePayment.java 33(+33 -0)
osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentBaseModelDao.java 44(+41 -3)
osgi-bundles/bundles/analytics/src/main/resources/com/ning/billing/osgi/bundles/analytics/dao/BusinessAnalyticsSqlDao.sql.stg 14(+14 -0)
Details
diff --git a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/api/BusinessInvoicePayment.java b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/api/BusinessInvoicePayment.java
index 1b05d1a..e2b2d82 100644
--- a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/api/BusinessInvoicePayment.java
+++ b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/api/BusinessInvoicePayment.java
@@ -39,10 +39,13 @@ public class BusinessInvoicePayment extends BusinessEntityBase {
private final BigDecimal invoiceOriginalAmountCharged;
private final BigDecimal invoiceAmountCredited;
private final String invoicePaymentType;
+ private final UUID paymentId;
+ private final UUID refundId;
private final Long paymentNumber;
private final UUID linkedInvoicePaymentId;
private final BigDecimal amount;
private final String currency;
+ private final String pluginName;
private final DateTime pluginCreatedDate;
private final DateTime pluginEffectiveDate;
private final String pluginStatus;
@@ -87,10 +90,13 @@ public class BusinessInvoicePayment extends BusinessEntityBase {
this.invoiceOriginalAmountCharged = businessInvoicePaymentBaseModelDao.getInvoiceOriginalAmountCharged();
this.invoiceAmountCredited = businessInvoicePaymentBaseModelDao.getInvoiceAmountCredited();
this.invoicePaymentType = businessInvoicePaymentBaseModelDao.getInvoicePaymentType();
+ this.paymentId = businessInvoicePaymentBaseModelDao.getPaymentId();
+ this.refundId = businessInvoicePaymentBaseModelDao.getRefundId();
this.paymentNumber = businessInvoicePaymentBaseModelDao.getPaymentNumber();
this.linkedInvoicePaymentId = businessInvoicePaymentBaseModelDao.getLinkedInvoicePaymentId();
this.amount = businessInvoicePaymentBaseModelDao.getAmount();
this.currency = businessInvoicePaymentBaseModelDao.getCurrency();
+ this.pluginName = businessInvoicePaymentBaseModelDao.getPluginName();
this.pluginCreatedDate = businessInvoicePaymentBaseModelDao.getPluginCreatedDate();
this.pluginEffectiveDate = businessInvoicePaymentBaseModelDao.getPluginEffectiveDate();
this.pluginStatus = businessInvoicePaymentBaseModelDao.getPluginStatus();
@@ -166,6 +172,14 @@ public class BusinessInvoicePayment extends BusinessEntityBase {
return invoicePaymentType;
}
+ public UUID getPaymentId() {
+ return paymentId;
+ }
+
+ public UUID getRefundId() {
+ return refundId;
+ }
+
public Long getPaymentNumber() {
return paymentNumber;
}
@@ -182,6 +196,10 @@ public class BusinessInvoicePayment extends BusinessEntityBase {
return currency;
}
+ public String getPluginName() {
+ return pluginName;
+ }
+
public DateTime getPluginCreatedDate() {
return pluginCreatedDate;
}
@@ -282,10 +300,13 @@ public class BusinessInvoicePayment extends BusinessEntityBase {
sb.append(", invoiceOriginalAmountCharged=").append(invoiceOriginalAmountCharged);
sb.append(", invoiceAmountCredited=").append(invoiceAmountCredited);
sb.append(", invoicePaymentType='").append(invoicePaymentType).append('\'');
+ sb.append(", paymentId=").append(paymentId);
+ sb.append(", refundId=").append(refundId);
sb.append(", paymentNumber=").append(paymentNumber);
sb.append(", linkedInvoicePaymentId=").append(linkedInvoicePaymentId);
sb.append(", amount=").append(amount);
sb.append(", currency='").append(currency).append('\'');
+ sb.append(", pluginName='").append(pluginName).append('\'');
sb.append(", pluginCreatedDate=").append(pluginCreatedDate);
sb.append(", pluginEffectiveDate=").append(pluginEffectiveDate);
sb.append(", pluginStatus='").append(pluginStatus).append('\'');
@@ -373,9 +394,18 @@ public class BusinessInvoicePayment extends BusinessEntityBase {
if (linkedInvoicePaymentId != null ? !linkedInvoicePaymentId.equals(that.linkedInvoicePaymentId) : that.linkedInvoicePaymentId != null) {
return false;
}
+ if (paymentId != null ? !paymentId.equals(that.paymentId) : that.paymentId != null) {
+ return false;
+ }
+ if (refundId != null ? !refundId.equals(that.refundId) : that.refundId != null) {
+ return false;
+ }
if (paymentNumber != null ? !paymentNumber.equals(that.paymentNumber) : that.paymentNumber != null) {
return false;
}
+ if (pluginName != null ? !pluginName.equals(that.pluginName) : that.pluginName != null) {
+ return false;
+ }
if (pluginCreatedDate != null ? !pluginCreatedDate.equals(that.pluginCreatedDate) : that.pluginCreatedDate != null) {
return false;
}
@@ -459,10 +489,13 @@ public class BusinessInvoicePayment extends BusinessEntityBase {
result = 31 * result + (invoiceOriginalAmountCharged != null ? invoiceOriginalAmountCharged.hashCode() : 0);
result = 31 * result + (invoiceAmountCredited != null ? invoiceAmountCredited.hashCode() : 0);
result = 31 * result + (invoicePaymentType != null ? invoicePaymentType.hashCode() : 0);
+ result = 31 * result + (paymentId != null ? paymentId.hashCode() : 0);
+ result = 31 * result + (refundId != null ? refundId.hashCode() : 0);
result = 31 * result + (paymentNumber != null ? paymentNumber.hashCode() : 0);
result = 31 * result + (linkedInvoicePaymentId != null ? linkedInvoicePaymentId.hashCode() : 0);
result = 31 * result + (amount != null ? amount.hashCode() : 0);
result = 31 * result + (currency != null ? currency.hashCode() : 0);
+ result = 31 * result + (pluginName != null ? pluginName.hashCode() : 0);
result = 31 * result + (pluginCreatedDate != null ? pluginCreatedDate.hashCode() : 0);
result = 31 * result + (pluginEffectiveDate != null ? pluginEffectiveDate.hashCode() : 0);
result = 31 * result + (pluginStatus != null ? pluginStatus.hashCode() : 0);
diff --git a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentBaseModelDao.java b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentBaseModelDao.java
index 5a3523b..7cfb5f5 100644
--- a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentBaseModelDao.java
+++ b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentBaseModelDao.java
@@ -55,10 +55,13 @@ public abstract class BusinessInvoicePaymentBaseModelDao extends BusinessModelDa
private BigDecimal invoiceOriginalAmountCharged;
private BigDecimal invoiceAmountCredited;
private String invoicePaymentType;
+ private UUID paymentId;
+ private UUID refundId;
private Long paymentNumber;
private UUID linkedInvoicePaymentId;
private BigDecimal amount;
private String currency;
+ private String pluginName;
private DateTime pluginCreatedDate;
private DateTime pluginEffectiveDate;
private String pluginStatus;
@@ -147,10 +150,13 @@ public abstract class BusinessInvoicePaymentBaseModelDao extends BusinessModelDa
final BigDecimal invoiceOriginalAmountCharged,
final BigDecimal invoiceAmountCredited,
final String invoicePaymentType,
+ final UUID paymentId,
+ final UUID refundId,
final Long paymentNumber,
final UUID linkedInvoicePaymentId,
final BigDecimal amount,
final String currency,
+ final String pluginName,
final DateTime pluginCreatedDate,
final DateTime pluginEffectiveDate,
final String pluginStatus,
@@ -206,10 +212,13 @@ public abstract class BusinessInvoicePaymentBaseModelDao extends BusinessModelDa
this.invoiceOriginalAmountCharged = invoiceOriginalAmountCharged;
this.invoiceAmountCredited = invoiceAmountCredited;
this.invoicePaymentType = invoicePaymentType;
+ this.paymentId = paymentId;
+ this.refundId = refundId;
this.paymentNumber = paymentNumber;
this.linkedInvoicePaymentId = linkedInvoicePaymentId;
this.amount = amount;
this.currency = currency;
+ this.pluginName = pluginName;
this.pluginCreatedDate = pluginCreatedDate;
this.pluginEffectiveDate = pluginEffectiveDate;
this.pluginStatus = pluginStatus;
@@ -258,10 +267,13 @@ public abstract class BusinessInvoicePaymentBaseModelDao extends BusinessModelDa
invoice.getOriginalChargedAmount(),
invoice.getCreditAdjAmount(),
invoicePayment.getType().toString(),
+ payment.getId(),
+ refund != null ? refund.getId() : null,
payment.getPaymentNumber() == null ? null : payment.getPaymentNumber().longValue(),
invoicePayment.getLinkedInvoicePaymentId(),
invoicePayment.getAmount(),
invoicePayment.getCurrency() == null ? null : invoicePayment.getCurrency().toString(),
+ paymentMethod.getPluginName(),
refund != null ? (refund.getPluginDetail() != null ? refund.getPluginDetail().getCreatedDate() : null) : (payment.getPaymentInfoPlugin() != null ? payment.getPaymentInfoPlugin().getCreatedDate() : null),
refund != null ? (refund.getPluginDetail() != null ? refund.getPluginDetail().getEffectiveDate() : null) : (payment.getPaymentInfoPlugin() != null ? payment.getPaymentInfoPlugin().getEffectiveDate() : null),
refund != null ? (refund.getPluginDetail() != null ? refund.getPluginDetail().getStatus().toString() : null) : (payment.getPaymentInfoPlugin() != null ? payment.getPaymentInfoPlugin().getStatus().toString() : null),
@@ -351,6 +363,14 @@ public abstract class BusinessInvoicePaymentBaseModelDao extends BusinessModelDa
return invoicePaymentType;
}
+ public UUID getPaymentId() {
+ return paymentId;
+ }
+
+ public UUID getRefundId() {
+ return refundId;
+ }
+
public Long getPaymentNumber() {
return paymentNumber;
}
@@ -367,6 +387,10 @@ public abstract class BusinessInvoicePaymentBaseModelDao extends BusinessModelDa
return currency;
}
+ public String getPluginName() {
+ return pluginName;
+ }
+
public DateTime getPluginCreatedDate() {
return pluginCreatedDate;
}
@@ -453,9 +477,8 @@ public abstract class BusinessInvoicePaymentBaseModelDao extends BusinessModelDa
@Override
public String toString() {
- final StringBuilder sb = new StringBuilder();
- sb.append("BusinessInvoicePaymentBaseModelDao");
- sb.append("{invoicePaymentRecordId=").append(invoicePaymentRecordId);
+ final StringBuilder sb = new StringBuilder("BusinessInvoicePaymentBaseModelDao{");
+ sb.append("invoicePaymentRecordId=").append(invoicePaymentRecordId);
sb.append(", invoicePaymentId=").append(invoicePaymentId);
sb.append(", invoiceId=").append(invoiceId);
sb.append(", invoiceNumber=").append(invoiceNumber);
@@ -469,10 +492,13 @@ public abstract class BusinessInvoicePaymentBaseModelDao extends BusinessModelDa
sb.append(", invoiceOriginalAmountCharged=").append(invoiceOriginalAmountCharged);
sb.append(", invoiceAmountCredited=").append(invoiceAmountCredited);
sb.append(", invoicePaymentType='").append(invoicePaymentType).append('\'');
+ sb.append(", paymentId=").append(paymentId);
+ sb.append(", refundId=").append(refundId);
sb.append(", paymentNumber=").append(paymentNumber);
sb.append(", linkedInvoicePaymentId=").append(linkedInvoicePaymentId);
sb.append(", amount=").append(amount);
sb.append(", currency='").append(currency).append('\'');
+ sb.append(", pluginName='").append(pluginName).append('\'');
sb.append(", pluginCreatedDate=").append(pluginCreatedDate);
sb.append(", pluginEffectiveDate=").append(pluginEffectiveDate);
sb.append(", pluginStatus='").append(pluginStatus).append('\'');
@@ -563,6 +589,12 @@ public abstract class BusinessInvoicePaymentBaseModelDao extends BusinessModelDa
if (linkedInvoicePaymentId != null ? !linkedInvoicePaymentId.equals(that.linkedInvoicePaymentId) : that.linkedInvoicePaymentId != null) {
return false;
}
+ if (paymentId != null ? !paymentId.equals(that.paymentId) : that.paymentId != null) {
+ return false;
+ }
+ if (refundId != null ? !refundId.equals(that.refundId) : that.refundId != null) {
+ return false;
+ }
if (paymentNumber != null ? !paymentNumber.equals(that.paymentNumber) : that.paymentNumber != null) {
return false;
}
@@ -581,6 +613,9 @@ public abstract class BusinessInvoicePaymentBaseModelDao extends BusinessModelDa
if (pluginGatewayErrorCode != null ? !pluginGatewayErrorCode.equals(that.pluginGatewayErrorCode) : that.pluginGatewayErrorCode != null) {
return false;
}
+ if (pluginName != null ? !pluginName.equals(that.pluginName) : that.pluginName != null) {
+ return false;
+ }
if (pluginPmAddress1 != null ? !pluginPmAddress1.equals(that.pluginPmAddress1) : that.pluginPmAddress1 != null) {
return false;
}
@@ -650,10 +685,13 @@ public abstract class BusinessInvoicePaymentBaseModelDao extends BusinessModelDa
result = 31 * result + (invoiceOriginalAmountCharged != null ? invoiceOriginalAmountCharged.hashCode() : 0);
result = 31 * result + (invoiceAmountCredited != null ? invoiceAmountCredited.hashCode() : 0);
result = 31 * result + (invoicePaymentType != null ? invoicePaymentType.hashCode() : 0);
+ result = 31 * result + (paymentId != null ? paymentId.hashCode() : 0);
+ result = 31 * result + (refundId != null ? refundId.hashCode() : 0);
result = 31 * result + (paymentNumber != null ? paymentNumber.hashCode() : 0);
result = 31 * result + (linkedInvoicePaymentId != null ? linkedInvoicePaymentId.hashCode() : 0);
result = 31 * result + (amount != null ? amount.hashCode() : 0);
result = 31 * result + (currency != null ? currency.hashCode() : 0);
+ result = 31 * result + (pluginName != null ? pluginName.hashCode() : 0);
result = 31 * result + (pluginCreatedDate != null ? pluginCreatedDate.hashCode() : 0);
result = 31 * result + (pluginEffectiveDate != null ? pluginEffectiveDate.hashCode() : 0);
result = 31 * result + (pluginStatus != null ? pluginStatus.hashCode() : 0);
diff --git a/osgi-bundles/bundles/analytics/src/main/resources/com/ning/billing/osgi/bundles/analytics/dao/BusinessAnalyticsSqlDao.sql.stg b/osgi-bundles/bundles/analytics/src/main/resources/com/ning/billing/osgi/bundles/analytics/dao/BusinessAnalyticsSqlDao.sql.stg
index 4184f2e..e5a2153 100644
--- a/osgi-bundles/bundles/analytics/src/main/resources/com/ning/billing/osgi/bundles/analytics/dao/BusinessAnalyticsSqlDao.sql.stg
+++ b/osgi-bundles/bundles/analytics/src/main/resources/com/ning/billing/osgi/bundles/analytics/dao/BusinessAnalyticsSqlDao.sql.stg
@@ -620,10 +620,12 @@ insert into bip (
, invoice_original_amount_charged
, invoice_amount_credited
, invoice_payment_type
+, payment_id
, payment_number
, linked_invoice_payment_id
, amount
, currency
+, plugin_name
, plugin_created_date
, plugin_effective_date
, plugin_status
@@ -670,10 +672,12 @@ insert into bip (
, :invoiceOriginalAmountCharged
, :invoiceAmountCredited
, :invoicePaymentType
+, :paymentId
, :paymentNumber
, :linkedInvoicePaymentId
, :amount
, :currency
+, :pluginName
, :pluginCreatedDate
, :pluginEffectiveDate
, :pluginStatus
@@ -724,10 +728,13 @@ insert into bipr (
, invoice_original_amount_charged
, invoice_amount_credited
, invoice_payment_type
+, payment_id
+, refund_id
, payment_number
, linked_invoice_payment_id
, amount
, currency
+, plugin_name
, plugin_created_date
, plugin_effective_date
, plugin_status
@@ -774,10 +781,13 @@ insert into bipr (
, :invoiceOriginalAmountCharged
, :invoiceAmountCredited
, :invoicePaymentType
+, :paymentId
+, :refundId
, :paymentNumber
, :linkedInvoicePaymentId
, :amount
, :currency
+, :pluginName
, :pluginCreatedDate
, :pluginEffectiveDate
, :pluginStatus
@@ -828,10 +838,12 @@ insert into bipc (
, invoice_original_amount_charged
, invoice_amount_credited
, invoice_payment_type
+, payment_id
, payment_number
, linked_invoice_payment_id
, amount
, currency
+, plugin_name
, plugin_created_date
, plugin_effective_date
, plugin_status
@@ -878,10 +890,12 @@ insert into bipc (
, :invoiceOriginalAmountCharged
, :invoiceAmountCredited
, :invoicePaymentType
+, :paymentId
, :paymentNumber
, :linkedInvoicePaymentId
, :amount
, :currency
+, :pluginName
, :pluginCreatedDate
, :pluginEffectiveDate
, :pluginStatus
diff --git a/osgi-bundles/bundles/analytics/src/main/resources/com/ning/billing/osgi/bundles/analytics/ddl.sql b/osgi-bundles/bundles/analytics/src/main/resources/com/ning/billing/osgi/bundles/analytics/ddl.sql
index 2e30a2f..3814223 100644
--- a/osgi-bundles/bundles/analytics/src/main/resources/com/ning/billing/osgi/bundles/analytics/ddl.sql
+++ b/osgi-bundles/bundles/analytics/src/main/resources/com/ning/billing/osgi/bundles/analytics/ddl.sql
@@ -390,10 +390,12 @@ create table bip (
, invoice_original_amount_charged numeric(10, 4) default 0
, invoice_amount_credited numeric(10, 4) default 0
, invoice_payment_type varchar(50) default null
+, payment_id char(36) default null
, payment_number bigint default null
, linked_invoice_payment_id char(36) default null
, amount numeric(10, 4) default 0
, currency char(50) default null
+, plugin_name varchar(255) default null
, plugin_created_date datetime default null
, plugin_effective_date datetime default null
, plugin_status varchar(255) default null
@@ -451,10 +453,13 @@ create table bipr (
, invoice_original_amount_charged numeric(10, 4) default 0
, invoice_amount_credited numeric(10, 4) default 0
, invoice_payment_type varchar(50) default null
+, payment_id char(36) default null
+, refund_id char(36) default null
, payment_number bigint default null
, linked_invoice_payment_id char(36) default null
, amount numeric(10, 4) default 0
, currency char(50) default null
+, plugin_name varchar(255) default null
, plugin_created_date datetime default null
, plugin_effective_date datetime default null
, plugin_status varchar(255) default null
@@ -512,10 +517,12 @@ create table bipc (
, invoice_original_amount_charged numeric(10, 4) default 0
, invoice_amount_credited numeric(10, 4) default 0
, invoice_payment_type varchar(50) default null
+, payment_id char(36) default null
, payment_number bigint default null
, linked_invoice_payment_id char(36) default null
, amount numeric(10, 4) default 0
, currency char(50) default null
+, plugin_name varchar(255) default null
, plugin_created_date datetime default null
, plugin_effective_date datetime default null
, plugin_status varchar(255) default null
diff --git a/osgi-bundles/bundles/analytics/src/test/java/com/ning/billing/osgi/bundles/analytics/dao/TestBusinessAnalyticsSqlDao.java b/osgi-bundles/bundles/analytics/src/test/java/com/ning/billing/osgi/bundles/analytics/dao/TestBusinessAnalyticsSqlDao.java
index 55b7496..abd47c7 100644
--- a/osgi-bundles/bundles/analytics/src/test/java/com/ning/billing/osgi/bundles/analytics/dao/TestBusinessAnalyticsSqlDao.java
+++ b/osgi-bundles/bundles/analytics/src/test/java/com/ning/billing/osgi/bundles/analytics/dao/TestBusinessAnalyticsSqlDao.java
@@ -20,11 +20,13 @@ import java.math.BigDecimal;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
+import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.ning.billing.catalog.api.Currency;
import com.ning.billing.entitlement.api.user.Subscription.SubscriptionState;
+import com.ning.billing.invoice.api.InvoicePayment.InvoicePaymentType;
import com.ning.billing.osgi.bundles.analytics.AnalyticsTestSuiteWithEmbeddedDB;
import com.ning.billing.osgi.bundles.analytics.dao.model.BusinessAccountFieldModelDao;
import com.ning.billing.osgi.bundles.analytics.dao.model.BusinessAccountModelDao;
@@ -206,7 +208,7 @@ public class TestBusinessAnalyticsSqlDao extends AnalyticsTestSuiteWithEmbeddedD
invoicePayment,
invoicePaymentRecordId,
payment,
- refund,
+ null,
paymentMethod,
auditLog,
tenantRecordId,
@@ -225,6 +227,33 @@ public class TestBusinessAnalyticsSqlDao extends AnalyticsTestSuiteWithEmbeddedD
}
@Test(groups = "slow")
+ public void testSqlDaoForInvoicePaymentRefund() throws Exception {
+ Mockito.when(invoicePayment.getType()).thenReturn(InvoicePaymentType.REFUND);
+ final BusinessInvoicePaymentBaseModelDao businessInvoicePaymentRefundModelDao = BusinessInvoicePaymentModelDao.create(account,
+ accountRecordId,
+ invoice,
+ invoicePayment,
+ invoicePaymentRecordId,
+ payment,
+ refund,
+ paymentMethod,
+ auditLog,
+ tenantRecordId,
+ reportGroup);
+ // Check the record doesn't exist yet
+ Assert.assertEquals(analyticsSqlDao.getInvoicePaymentsByAccountRecordId(accountRecordId, tenantRecordId, callContext).size(), 0);
+
+ // Create and check we can retrieve it
+ analyticsSqlDao.create(businessInvoicePaymentRefundModelDao.getTableName(), businessInvoicePaymentRefundModelDao, callContext);
+ Assert.assertEquals(analyticsSqlDao.getInvoicePaymentRefundsByAccountRecordId(accountRecordId, tenantRecordId, callContext).size(), 1);
+ Assert.assertEquals(analyticsSqlDao.getInvoicePaymentRefundsByAccountRecordId(accountRecordId, tenantRecordId, callContext).get(0), businessInvoicePaymentRefundModelDao);
+
+ // Delete and verify it doesn't exist anymore
+ analyticsSqlDao.deleteByAccountRecordId(businessInvoicePaymentRefundModelDao.getTableName(), accountRecordId, tenantRecordId, callContext);
+ Assert.assertEquals(analyticsSqlDao.getInvoicePaymentRefundsByAccountRecordId(accountRecordId, tenantRecordId, callContext).size(), 0);
+ }
+
+ @Test(groups = "slow")
public void testSqlDaoForOverdueStatus() throws Exception {
final DateTime endDate = new DateTime(2005, 6, 5, 4, 5, 6, DateTimeZone.UTC);
final BusinessOverdueStatusModelDao businessOverdueStatusModelDao = new BusinessOverdueStatusModelDao(account,