killbill-memoizeit
Changes
osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/BusinessAnalyticsBase.java 4(+2 -2)
osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentBaseModelDao.java 39(+22 -17)
osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentChargebackModelDao.java 2(+1 -1)
osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentModelDao.java 2(+1 -1)
Details
diff --git a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/BusinessAnalyticsBase.java b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/BusinessAnalyticsBase.java
index 61a5581..7d95a1c 100644
--- a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/BusinessAnalyticsBase.java
+++ b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/BusinessAnalyticsBase.java
@@ -422,8 +422,8 @@ public abstract class BusinessAnalyticsBase {
try {
return paymentApi.getPaymentMethodById(paymentMethodId, true, context);
} catch (PaymentApiException e) {
- logService.log(LogService.LOG_WARNING, "Error retrieving payment method for id " + paymentMethodId, e);
- throw new AnalyticsRefreshException(e);
+ logService.log(LogService.LOG_INFO, "Error retrieving payment method for id " + paymentMethodId + " (already deleted?)", e);
+ return null;
}
}
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 ef83f73..402c98d 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
@@ -33,8 +33,13 @@ import com.ning.billing.payment.api.PaymentMethod;
import com.ning.billing.payment.api.Refund;
import com.ning.billing.util.audit.AuditLog;
+import com.google.common.annotations.VisibleForTesting;
+
public abstract class BusinessInvoicePaymentBaseModelDao extends BusinessModelDaoBase {
+ @VisibleForTesting
+ static final String DEFAULT_PLUGIN_NAME = "__UNKNOWN__";
+
protected static final String INVOICE_PAYMENTS_TABLE_NAME = "bip";
protected static final String INVOICE_PAYMENT_REFUNDS_TABLE_NAME = "bipr";
protected static final String INVOICE_PAYMENT_CHARGEBACKS_TABLE_NAME = "bipc";
@@ -91,7 +96,7 @@ public abstract class BusinessInvoicePaymentBaseModelDao extends BusinessModelDa
final Long invoicePaymentRecordId,
final Payment payment,
final Refund refund,
- final PaymentMethod paymentMethod,
+ @Nullable final PaymentMethod paymentMethod,
@Nullable final AuditLog creationAuditLog,
final Long tenantRecordId,
@Nullable final ReportGroup reportGroup) {
@@ -249,7 +254,7 @@ public abstract class BusinessInvoicePaymentBaseModelDao extends BusinessModelDa
final Long invoicePaymentRecordId,
final Payment payment,
@Nullable final Refund refund,
- final PaymentMethod paymentMethod,
+ @Nullable final PaymentMethod paymentMethod,
@Nullable final AuditLog creationAuditLog,
final Long tenantRecordId,
@Nullable final ReportGroup reportGroup) {
@@ -273,7 +278,7 @@ public abstract class BusinessInvoicePaymentBaseModelDao extends BusinessModelDa
invoicePayment.getLinkedInvoicePaymentId(),
invoicePayment.getAmount(),
invoicePayment.getCurrency() == null ? null : invoicePayment.getCurrency().toString(),
- paymentMethod.getPluginName(),
+ paymentMethod != null ? paymentMethod.getPluginName() : DEFAULT_PLUGIN_NAME,
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),
@@ -281,20 +286,20 @@ public abstract class BusinessInvoicePaymentBaseModelDao extends BusinessModelDa
refund != null ? (refund.getPluginDetail() != null ? refund.getPluginDetail().getGatewayErrorCode() : null) : (payment.getPaymentInfoPlugin() != null ? payment.getPaymentInfoPlugin().getGatewayErrorCode() : null),
refund != null ? (refund.getPluginDetail() != null ? refund.getPluginDetail().getReferenceId() : null) : (payment.getPaymentInfoPlugin() != null ? payment.getPaymentInfoPlugin().getFirstPaymentReferenceId() : null),
refund != null ? null : (payment.getPaymentInfoPlugin() != null ? payment.getPaymentInfoPlugin().getSecondPaymentReferenceId() : null),
- paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getExternalPaymentMethodId() : null,
- paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().isDefaultPaymentMethod() : null,
- paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getType() : null,
- paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getCCName() : null,
- paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getCCType() : null,
- paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getCCExprirationMonth() : null,
- paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getCCExprirationYear() : null,
- paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getCCLast4() : null,
- paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getAddress1() : null,
- paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getAddress2() : null,
- paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getCity() : null,
- paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getState() : null,
- paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getZip() : null,
- paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getCountry() : null,
+ paymentMethod != null ? (paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getExternalPaymentMethodId() : null) : null,
+ paymentMethod != null ? (paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().isDefaultPaymentMethod() : null) : null,
+ paymentMethod != null ? (paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getType() : null) : null,
+ paymentMethod != null ? (paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getCCName() : null) : null,
+ paymentMethod != null ? (paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getCCType() : null) : null,
+ paymentMethod != null ? (paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getCCExprirationMonth() : null) : null,
+ paymentMethod != null ? (paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getCCExprirationYear() : null) : null,
+ paymentMethod != null ? (paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getCCLast4() : null) : null,
+ paymentMethod != null ? (paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getAddress1() : null) : null,
+ paymentMethod != null ? (paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getAddress2() : null) : null,
+ paymentMethod != null ? (paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getCity() : null) : null,
+ paymentMethod != null ? (paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getState() : null) : null,
+ paymentMethod != null ? (paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getZip() : null) : null,
+ paymentMethod != null ? (paymentMethod.getPluginDetail() != null ? paymentMethod.getPluginDetail().getCountry() : null) : null,
invoicePayment.getCreatedDate(),
creationAuditLog != null ? creationAuditLog.getUserName() : null,
creationAuditLog != null ? creationAuditLog.getReasonCode() : null,
diff --git a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentChargebackModelDao.java b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentChargebackModelDao.java
index 82cc0ba..42003e8 100644
--- a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentChargebackModelDao.java
+++ b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentChargebackModelDao.java
@@ -37,7 +37,7 @@ public class BusinessInvoicePaymentChargebackModelDao extends BusinessInvoicePay
final Long invoicePaymentRecordId,
final Payment payment,
final Refund refund,
- final PaymentMethod paymentMethod,
+ @Nullable final PaymentMethod paymentMethod,
@Nullable final AuditLog creationAuditLog,
final Long tenantRecordId,
@Nullable final ReportGroup reportGroup) {
diff --git a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentModelDao.java b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentModelDao.java
index 25ee461..b058c73 100644
--- a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentModelDao.java
+++ b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentModelDao.java
@@ -37,7 +37,7 @@ public class BusinessInvoicePaymentModelDao extends BusinessInvoicePaymentBaseMo
final Long invoicePaymentRecordId,
final Payment payment,
final Refund refund,
- final PaymentMethod paymentMethod,
+ @Nullable final PaymentMethod paymentMethod,
@Nullable final AuditLog creationAuditLog,
final Long tenantRecordId,
@Nullable final ReportGroup reportGroup) {
diff --git a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentRefundModelDao.java b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentRefundModelDao.java
index 98d8d9d..6ebc393 100644
--- a/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentRefundModelDao.java
+++ b/osgi-bundles/bundles/analytics/src/main/java/com/ning/billing/osgi/bundles/analytics/dao/model/BusinessInvoicePaymentRefundModelDao.java
@@ -37,7 +37,7 @@ public class BusinessInvoicePaymentRefundModelDao extends BusinessInvoicePayment
final Long invoicePaymentRecordId,
final Payment payment,
final Refund refund,
- final PaymentMethod paymentMethod,
+ @Nullable final PaymentMethod paymentMethod,
@Nullable final AuditLog creationAuditLog,
final Long tenantRecordId,
@Nullable final ReportGroup reportGroup) {
diff --git a/osgi-bundles/bundles/analytics/src/test/java/com/ning/billing/osgi/bundles/analytics/dao/model/TestBusinessInvoicePaymentModelDao.java b/osgi-bundles/bundles/analytics/src/test/java/com/ning/billing/osgi/bundles/analytics/dao/model/TestBusinessInvoicePaymentModelDao.java
index b4dd1cb..51118ca 100644
--- a/osgi-bundles/bundles/analytics/src/test/java/com/ning/billing/osgi/bundles/analytics/dao/model/TestBusinessInvoicePaymentModelDao.java
+++ b/osgi-bundles/bundles/analytics/src/test/java/com/ning/billing/osgi/bundles/analytics/dao/model/TestBusinessInvoicePaymentModelDao.java
@@ -24,6 +24,60 @@ import com.ning.billing.osgi.bundles.analytics.AnalyticsTestSuiteNoDB;
public class TestBusinessInvoicePaymentModelDao extends AnalyticsTestSuiteNoDB {
@Test(groups = "fast")
+ public void testConstructorWithNullPaymentMethod() throws Exception {
+ final BusinessInvoicePaymentModelDao invoicePaymentModelDao = new BusinessInvoicePaymentModelDao(account,
+ accountRecordId,
+ invoice,
+ invoicePayment,
+ invoicePaymentRecordId,
+ payment,
+ refund,
+ null,
+ auditLog,
+ tenantRecordId,
+ reportGroup);
+ verifyCommonFields(invoicePaymentModelDao);
+ Assert.assertEquals(invoicePaymentModelDao.getPluginName(), BusinessInvoicePaymentBaseModelDao.DEFAULT_PLUGIN_NAME);
+ Assert.assertNull(invoicePaymentModelDao.getPluginCreatedDate());
+ Assert.assertNull(invoicePaymentModelDao.getPluginEffectiveDate());
+ Assert.assertNull(invoicePaymentModelDao.getPluginStatus());
+ Assert.assertNull(invoicePaymentModelDao.getPluginGatewayError());
+ Assert.assertNull(invoicePaymentModelDao.getPluginGatewayErrorCode());
+ Assert.assertNull(invoicePaymentModelDao.getPluginFirstReferenceId());
+ Assert.assertNull(invoicePaymentModelDao.getPluginSecondReferenceId());
+ Assert.assertNull(invoicePaymentModelDao.getPluginPmId());
+ Assert.assertNull(invoicePaymentModelDao.getPluginPmIsDefault());
+ Assert.assertNull(invoicePaymentModelDao.getPluginPmType());
+ Assert.assertNull(invoicePaymentModelDao.getPluginPmCcName());
+ Assert.assertNull(invoicePaymentModelDao.getPluginPmCcType());
+ Assert.assertNull(invoicePaymentModelDao.getPluginPmCcExpirationMonth());
+ Assert.assertNull(invoicePaymentModelDao.getPluginPmCcExpirationYear());
+ Assert.assertNull(invoicePaymentModelDao.getPluginPmCcLast4());
+ Assert.assertNull(invoicePaymentModelDao.getPluginPmAddress1());
+ Assert.assertNull(invoicePaymentModelDao.getPluginPmAddress2());
+ Assert.assertNull(invoicePaymentModelDao.getPluginPmCity());
+ Assert.assertNull(invoicePaymentModelDao.getPluginPmState());
+ Assert.assertNull(invoicePaymentModelDao.getPluginPmZip());
+ Assert.assertNull(invoicePaymentModelDao.getPluginPmCountry());
+ }
+
+ @Test(groups = "fast")
+ public void testConstructorWithNullRefund() throws Exception {
+ final BusinessInvoicePaymentModelDao invoicePaymentModelDao = new BusinessInvoicePaymentModelDao(account,
+ accountRecordId,
+ invoice,
+ invoicePayment,
+ invoicePaymentRecordId,
+ payment,
+ null,
+ paymentMethod,
+ auditLog,
+ tenantRecordId,
+ reportGroup);
+ verifyCommonFields(invoicePaymentModelDao);
+ }
+
+ @Test(groups = "fast")
public void testConstructor() throws Exception {
final BusinessInvoicePaymentModelDao invoicePaymentModelDao = new BusinessInvoicePaymentModelDao(account,
accountRecordId,
@@ -36,6 +90,10 @@ public class TestBusinessInvoicePaymentModelDao extends AnalyticsTestSuiteNoDB {
auditLog,
tenantRecordId,
reportGroup);
+ verifyCommonFields(invoicePaymentModelDao);
+ }
+
+ private void verifyCommonFields(final BusinessInvoicePaymentModelDao invoicePaymentModelDao) {
verifyBusinessModelDaoBase(invoicePaymentModelDao, accountRecordId, tenantRecordId);
Assert.assertEquals(invoicePaymentModelDao.getCreatedDate(), invoicePayment.getCreatedDate());
Assert.assertEquals(invoicePaymentModelDao.getInvoicePaymentRecordId(), invoicePaymentRecordId);
@@ -52,7 +110,7 @@ public class TestBusinessInvoicePaymentModelDao extends AnalyticsTestSuiteNoDB {
Assert.assertEquals(invoicePaymentModelDao.getInvoiceOriginalAmountCharged(), invoice.getOriginalChargedAmount());
Assert.assertEquals(invoicePaymentModelDao.getInvoiceAmountCredited(), invoice.getCreditAdjAmount());
Assert.assertEquals(invoicePaymentModelDao.getInvoicePaymentType(), invoicePayment.getType().toString());
- //Assert.assertEquals(invoicePaymentModelDao.getPaymentNumber(), /* TODO */);
+ Assert.assertEquals(invoicePaymentModelDao.getPaymentNumber(), (Long) payment.getPaymentNumber().longValue());
Assert.assertEquals(invoicePaymentModelDao.getLinkedInvoicePaymentId(), invoicePayment.getLinkedInvoicePaymentId());
Assert.assertEquals(invoicePaymentModelDao.getAmount(), invoicePayment.getAmount());
Assert.assertEquals(invoicePaymentModelDao.getCurrency(), invoicePayment.getCurrency().toString());