killbill-memoizeit

payment: trivial style fixes in RefundProcessor Signed-off-by:

8/1/2012 8:00:34 PM

Details

diff --git a/payment/src/main/java/com/ning/billing/payment/core/RefundProcessor.java b/payment/src/main/java/com/ning/billing/payment/core/RefundProcessor.java
index 69fbb4b..b354c70 100644
--- a/payment/src/main/java/com/ning/billing/payment/core/RefundProcessor.java
+++ b/payment/src/main/java/com/ning/billing/payment/core/RefundProcessor.java
@@ -13,12 +13,8 @@
  * License for the specific language governing permissions and limitations
  * under the License.
  */
-package com.ning.billing.payment.core;
-
-import javax.inject.Inject;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+package com.ning.billing.payment.core;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
@@ -28,10 +24,11 @@ import java.util.List;
 import java.util.UUID;
 import java.util.concurrent.ExecutorService;
 
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Collections2;
-import com.google.inject.name.Named;
+import javax.inject.Inject;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import com.ning.billing.ErrorCode;
 import com.ning.billing.account.api.Account;
 import com.ning.billing.account.api.AccountApiException;
@@ -40,9 +37,7 @@ import com.ning.billing.invoice.api.InvoiceApiException;
 import com.ning.billing.invoice.api.InvoicePaymentApi;
 import com.ning.billing.payment.api.DefaultRefund;
 import com.ning.billing.payment.api.PaymentApiException;
-import com.ning.billing.payment.api.PaymentStatus;
 import com.ning.billing.payment.api.Refund;
-import com.ning.billing.payment.dao.PaymentAttemptModelDao;
 import com.ning.billing.payment.dao.PaymentDao;
 import com.ning.billing.payment.dao.PaymentModelDao;
 import com.ning.billing.payment.dao.RefundModelDao;
@@ -57,32 +52,36 @@ import com.ning.billing.util.callcontext.CallOrigin;
 import com.ning.billing.util.callcontext.UserType;
 import com.ning.billing.util.globallocker.GlobalLocker;
 
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+import com.google.inject.name.Named;
+
 import static com.ning.billing.payment.glue.PaymentModule.PLUGIN_EXECUTOR_NAMED;
 
 public class RefundProcessor extends ProcessorBase {
 
-    private final static Logger log = LoggerFactory.getLogger(RefundProcessor.class);
+    private static final Logger log = LoggerFactory.getLogger(RefundProcessor.class);
 
     private final InvoicePaymentApi invoicePaymentApi;
     private final CallContextFactory factory;
 
     @Inject
     public RefundProcessor(final PaymentProviderPluginRegistry pluginRegistry,
-            final AccountUserApi accountUserApi,
-            final InvoicePaymentApi invoicePaymentApi,
-            final Bus eventBus,
-            final CallContextFactory factory,
-            final PaymentDao paymentDao,
-            final GlobalLocker locker,
-            @Named(PLUGIN_EXECUTOR_NAMED) final ExecutorService executor) {
+                           final AccountUserApi accountUserApi,
+                           final InvoicePaymentApi invoicePaymentApi,
+                           final Bus eventBus,
+                           final CallContextFactory factory,
+                           final PaymentDao paymentDao,
+                           final GlobalLocker locker,
+                           @Named(PLUGIN_EXECUTOR_NAMED) final ExecutorService executor) {
         super(pluginRegistry, accountUserApi, eventBus, paymentDao, locker, executor);
         this.invoicePaymentApi = invoicePaymentApi;
         this.factory = factory;
     }
 
-
     public Refund createRefund(final Account account, final UUID paymentId, final BigDecimal refundAmount, final boolean isAdjusted, final CallContext context)
-    throws PaymentApiException {
+            throws PaymentApiException {
 
         return new WithAccountLock<Refund>().processAccountWithLock(locker, account.getExternalKey(), new WithAccountLockCallback<Refund>() {
 
@@ -104,8 +103,8 @@ public class RefundProcessor extends ProcessorBase {
                     int foundPluginCompletedRefunds = 0;
                     RefundModelDao refundInfo = null;
                     BigDecimal totalAmountRefunded = BigDecimal.ZERO;
-                    List<RefundModelDao> existingRefunds = paymentDao.getRefundsForPayment(paymentId);
-                    for (RefundModelDao cur : existingRefunds) {
+                    final List<RefundModelDao> existingRefunds = paymentDao.getRefundsForPayment(paymentId);
+                    for (final RefundModelDao cur : existingRefunds) {
 
                         final BigDecimal existingPositiveAmount = cur.getAmount();
                         if (existingPositiveAmount.compareTo(refundAmount) == 0) {
@@ -132,7 +131,7 @@ public class RefundProcessor extends ProcessorBase {
                     }
 
                     final PaymentPluginApi plugin = getPaymentProviderPlugin(payment.getPaymentMethodId());
-                    int nbExistingRefunds = plugin.getNbRefundForPaymentAmount(account, paymentId, refundAmount);
+                    final int nbExistingRefunds = plugin.getNbRefundForPaymentAmount(account, paymentId, refundAmount);
                     log.debug(String.format("found %d pluginRefunds for paymentId %s and amount %s", nbExistingRefunds, paymentId, refundAmount));
 
                     if (nbExistingRefunds > foundPluginCompletedRefunds) {
@@ -158,14 +157,13 @@ public class RefundProcessor extends ProcessorBase {
         });
     }
 
-
     public Refund getRefund(final UUID refundId)
-    throws PaymentApiException {
+            throws PaymentApiException {
         RefundModelDao result = paymentDao.getRefund(refundId);
         if (result == null) {
             throw new PaymentApiException(ErrorCode.PAYMENT_NO_SUCH_REFUND, refundId);
         }
-        List<RefundModelDao> filteredInput = filterUncompletedPluginRefund(Collections.singletonList(result));
+        final List<RefundModelDao> filteredInput = filterUncompletedPluginRefund(Collections.singletonList(result));
         if (filteredInput.size() == 0) {
             throw new PaymentApiException(ErrorCode.PAYMENT_NO_SUCH_REFUND, refundId);
         }
@@ -177,31 +175,30 @@ public class RefundProcessor extends ProcessorBase {
                                  result.isAdjsuted(), result.getCreatedDate());
     }
 
-
     public List<Refund> getAccountRefunds(final Account account)
-    throws PaymentApiException {
+            throws PaymentApiException {
         List<RefundModelDao> result = paymentDao.getRefundsForAccount(account.getId());
         if (completePluginCompletedRefund(result)) {
             result = paymentDao.getRefundsForAccount(account.getId());
         }
-        List<RefundModelDao> filteredInput = filterUncompletedPluginRefund(result);
+        final List<RefundModelDao> filteredInput = filterUncompletedPluginRefund(result);
         return toRefunds(filteredInput);
     }
 
     public List<Refund> getPaymentRefunds(final UUID paymentId)
-    throws PaymentApiException {
+            throws PaymentApiException {
         List<RefundModelDao> result = paymentDao.getRefundsForPayment(paymentId);
         if (completePluginCompletedRefund(result)) {
             result = paymentDao.getRefundsForPayment(paymentId);
         }
-        List<RefundModelDao> filteredInput = filterUncompletedPluginRefund(result);
+        final List<RefundModelDao> filteredInput = filterUncompletedPluginRefund(result);
         return toRefunds(filteredInput);
     }
 
     public List<Refund> toRefunds(final List<RefundModelDao> in) {
         return new ArrayList<Refund>(Collections2.transform(in, new Function<RefundModelDao, Refund>() {
             @Override
-            public Refund apply(RefundModelDao cur) {
+            public Refund apply(final RefundModelDao cur) {
                 return new DefaultRefund(cur.getId(), cur.getPaymentId(), cur.getAmount(), cur.getCurrency(),
                                          cur.isAdjsuted(), cur.getCreatedDate());
             }
@@ -211,7 +208,7 @@ public class RefundProcessor extends ProcessorBase {
     private List<RefundModelDao> filterUncompletedPluginRefund(final List<RefundModelDao> input) {
         return new ArrayList<RefundModelDao>(Collections2.filter(input, new Predicate<RefundModelDao>() {
             @Override
-            public boolean apply(RefundModelDao in) {
+            public boolean apply(final RefundModelDao in) {
                 return in.getRefundStatus() != RefundStatus.CREATED;
             }
         }));
@@ -219,10 +216,9 @@ public class RefundProcessor extends ProcessorBase {
 
     private boolean completePluginCompletedRefund(final List<RefundModelDao> refunds) throws PaymentApiException {
 
-
         final Collection<RefundModelDao> refundsToBeFixed = Collections2.filter(refunds, new Predicate<RefundModelDao>() {
             @Override
-            public boolean apply(RefundModelDao in) {
+            public boolean apply(final RefundModelDao in) {
                 return in.getRefundStatus() == RefundStatus.PLUGIN_COMPLETED;
             }
         });
@@ -231,14 +227,14 @@ public class RefundProcessor extends ProcessorBase {
         }
 
         try {
-            Account account = accountUserApi.getAccountById(refundsToBeFixed.iterator().next().getAccountId());
+            final Account account = accountUserApi.getAccountById(refundsToBeFixed.iterator().next().getAccountId());
             new WithAccountLock<Void>().processAccountWithLock(locker, account.getExternalKey(), new WithAccountLockCallback<Void>() {
 
                 @Override
                 public Void doOperation() throws PaymentApiException {
                     try {
                         final CallContext context = factory.createCallContext("RefundProcessor", CallOrigin.INTERNAL, UserType.SYSTEM);
-                        for (RefundModelDao cur : refundsToBeFixed) {
+                        for (final RefundModelDao cur : refundsToBeFixed) {
                             invoicePaymentApi.createRefund(cur.getPaymentId(), cur.getAmount(), cur.isAdjsuted(), cur.getId(), context);
                             paymentDao.updateRefundStatus(cur.getId(), RefundStatus.COMPLETED, context);
                         }
@@ -253,15 +249,4 @@ public class RefundProcessor extends ProcessorBase {
             throw new PaymentApiException(e);
         }
     }
-
-    private PaymentAttemptModelDao getPaymentAttempt(final UUID paymentId) {
-        List<PaymentAttemptModelDao> attempts = paymentDao.getAttemptsForPayment(paymentId);
-        for (PaymentAttemptModelDao cur : attempts) {
-            if (cur.getPaymentStatus() == PaymentStatus.SUCCESS) {
-                return cur;
-            }
-        }
-        return null;
-    }
-
 }