svn commit: r1818550 - in /ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount: FinAccountPaymentServices.java FinAccountProductServices.java FinAccountServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1818550 - in /ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount: FinAccountPaymentServices.java FinAccountProductServices.java FinAccountServices.java

mbrohl
Author: mbrohl
Date: Mon Dec 18 10:41:55 2017
New Revision: 1818550

URL: http://svn.apache.org/viewvc?rev=1818550&view=rev
Log:
Improved: General refactoring and code improvements, package
org.apache.ofbiz.accounting.finaccount.
(OFBIZ-9884)

Thanks Julian Leichert for reporting and providing the patches.

Modified:
    ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountPaymentServices.java
    ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountProductServices.java
    ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountServices.java

Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountPaymentServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountPaymentServices.java?rev=1818550&r1=1818549&r2=1818550&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountPaymentServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountPaymentServices.java Mon Dec 18 10:41:55 2017
@@ -92,18 +92,23 @@ public class FinAccountPaymentServices {
         // obtain the order information
         OrderReadHelper orh = new OrderReadHelper(delegator, orderId);
 
-        // NOTE DEJ20070808: this means that we want store related settings for where the item is being purchased,
-        //NOT where the account was setup; should this be changed to use settings from the store where the account was setup?
+        // NOTE DEJ20070808: this means that we want store related settings for where
+        // the item is being purchased,
+        // NOT where the account was setup; should this be changed to use settings from
+        // the store where the account was setup?
         String productStoreId = orh.getProductStoreId();
 
-        // TODO, NOTE DEJ20070808: why is this setup this way anyway? for the allowAuthToNegative wouldn't that be better setup
-        //on the FinAccount and not on the ProductStoreFinActSetting? maybe an override on the FinAccount would be good...
+        // TODO, NOTE DEJ20070808: why is this setup this way anyway? for the
+        // allowAuthToNegative wouldn't that be better setup
+        // on the FinAccount and not on the ProductStoreFinActSetting? maybe an override
+        // on the FinAccount would be good...
 
         // get the financial account
         GenericValue finAccount;
         if (finAccountId != null) {
             try {
-                finAccount = EntityQuery.use(delegator).from("FinAccount").where("finAccountId", finAccountId).queryOne();
+                finAccount = EntityQuery.use(delegator).from("FinAccount").where("finAccountId", finAccountId)
+                        .queryOne();
             } catch (GenericEntityException e) {
                 Debug.logError(e, module);
                 return ServiceUtil.returnError(e.getMessage());
@@ -114,16 +119,16 @@ public class FinAccountPaymentServices {
                     finAccount = FinAccountHelper.getFinAccountFromCode(finAccountCode, delegator);
                 } catch (GenericEntityException e) {
                     Debug.logError(e, module);
-                    return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+                    return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                             "AccountingFinAccountCannotLocateItFromAccountCode", locale));
                 }
             } else {
-                return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+                return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                         "AccountingFinAccountIdAndFinAccountCodeAreNull", locale));
             }
         }
         if (finAccount == null) {
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                     "AccountingFinAccountIdInvalid", locale));
         }
 
@@ -133,13 +138,19 @@ public class FinAccountPaymentServices {
 
         try {
             // fin the store requires a pin number; validate the PIN with the code
-            Map<String, Object> findProductStoreFinActSettingMap = UtilMisc.<String, Object>toMap("productStoreId", productStoreId, "finAccountTypeId", finAccountTypeId);
-            GenericValue finAccountSettings = EntityQuery.use(delegator).from("ProductStoreFinActSetting").where(findProductStoreFinActSettingMap).cache().queryOne();
+            Map<String, Object> findProductStoreFinActSettingMap = UtilMisc.<String, Object>toMap("productStoreId",
+                    productStoreId, "finAccountTypeId", finAccountTypeId);
+            GenericValue finAccountSettings = EntityQuery.use(delegator).from("ProductStoreFinActSetting").where(
+                    findProductStoreFinActSettingMap).cache().queryOne();
 
             if (finAccountSettings == null) {
-                Debug.logWarning("In finAccountPreAuth could not find ProductStoreFinActSetting record, values searched by: " + findProductStoreFinActSettingMap, module);
+                Debug.logWarning(
+                        "In finAccountPreAuth could not find ProductStoreFinActSetting record, values searched by: "
+                                + findProductStoreFinActSettingMap, module);
+            }
+            if (Debug.verboseOn()) {
+                Debug.logVerbose("In finAccountPreAuth finAccountSettings=" + finAccountSettings, module);
             }
-            if (Debug.verboseOn()) Debug.logVerbose("In finAccountPreAuth finAccountSettings=" + finAccountSettings, module);
 
             BigDecimal minBalance = FinAccountHelper.ZERO;
             String allowAuthToNegative = "N";
@@ -155,7 +166,7 @@ public class FinAccountPaymentServices {
                 if ("Y".equals(finAccountSettings.getString("requirePinCode"))) {
                     if (!FinAccountHelper.validatePin(delegator, finAccountCode, finAccountPin)) {
                         Map<String, Object> result = ServiceUtil.returnSuccess();
-                        result.put("authMessage", UtilProperties.getMessage(resourceError,
+                        result.put("authMessage", UtilProperties.getMessage(resourceError,
                                 "AccountingFinAccountPinCodeCombinatorNotFound", locale));
                         result.put("authResult", Boolean.FALSE);
                         result.put("processAmount", amount);
@@ -169,10 +180,11 @@ public class FinAccountPaymentServices {
             }
 
             // check for expiration date
-            if ((finAccount.getTimestamp("thruDate") != null) && (finAccount.getTimestamp("thruDate").before(UtilDateTime.nowTimestamp()))) {
+            if ((finAccount.getTimestamp("thruDate") != null) && (finAccount.getTimestamp("thruDate").before(
+                    UtilDateTime.nowTimestamp()))) {
                 Map<String, Object> result = ServiceUtil.returnSuccess();
-                result.put("authMessage", UtilProperties.getMessage(resourceError,
-                        "AccountingFinAccountExpired",
+                result.put("authMessage", UtilProperties.getMessage(resourceError,
+                        "AccountingFinAccountExpired",
                         UtilMisc.toMap("thruDate", finAccount.getTimestamp("thruDate")), locale));
                 result.put("authResult", Boolean.FALSE);
                 result.put("processAmount", amount);
@@ -184,21 +196,23 @@ public class FinAccountPaymentServices {
             }
 
             // check for account being in bad standing somehow
-            if ("FNACT_NEGPENDREPL".equals(statusId) || "FNACT_MANFROZEN".equals(statusId) || "FNACT_CANCELLED".equals(statusId)) {
+            if ("FNACT_NEGPENDREPL".equals(statusId) || "FNACT_MANFROZEN".equals(statusId) || "FNACT_CANCELLED".equals(
+                    statusId)) {
                 // refresh the finaccount
                 finAccount.refresh();
                 statusId = finAccount.getString("statusId");
 
-                if ("FNACT_NEGPENDREPL".equals(statusId) || "FNACT_MANFROZEN".equals(statusId) || "FNACT_CANCELLED".equals(statusId)) {
+                if ("FNACT_NEGPENDREPL".equals(statusId) || "FNACT_MANFROZEN".equals(statusId) || "FNACT_CANCELLED"
+                        .equals(statusId)) {
                     Map<String, Object> result = ServiceUtil.returnSuccess();
                     if ("FNACT_NEGPENDREPL".equals(statusId)) {
-                        result.put("authMessage", UtilProperties.getMessage(resourceError,
+                        result.put("authMessage", UtilProperties.getMessage(resourceError,
                                 "AccountingFinAccountNegative", locale));
                     } else if ("FNACT_MANFROZEN".equals(statusId)) {
-                        result.put("authMessage", UtilProperties.getMessage(resourceError,
+                        result.put("authMessage", UtilProperties.getMessage(resourceError,
                                 "AccountingFinAccountFrozen", locale));
                     } else if ("FNACT_CANCELLED".equals(statusId)) {
-                        result.put("authMessage", UtilProperties.getMessage(resourceError,
+                        result.put("authMessage", UtilProperties.getMessage(resourceError,
                                 "AccountingFinAccountCancelled", locale));
                     }
                     result.put("authResult", Boolean.FALSE);
@@ -211,7 +225,8 @@ public class FinAccountPaymentServices {
                 }
             }
 
-            // check the amount to authorize against the available balance of fin account, which includes active authorizations as well as transactions
+            // check the amount to authorize against the available balance of fin account,
+            // which includes active authorizations as well as transactions
             BigDecimal availableBalance = finAccount.getBigDecimal("availableBalance");
             if (availableBalance == null) {
                 availableBalance = FinAccountHelper.ZERO;
@@ -219,11 +234,13 @@ public class FinAccountPaymentServices {
                 BigDecimal availableBalanceOriginal = availableBalance;
                 availableBalance = availableBalance.setScale(FinAccountHelper.decimals, FinAccountHelper.rounding);
                 if (availableBalance.compareTo(availableBalanceOriginal) != 0) {
-                    Debug.logWarning("In finAccountPreAuth for finAccountId [" + finAccountId + "] availableBalance [" + availableBalanceOriginal + "] was different after rounding [" + availableBalance + "]; it should never have made it into the database this way, so check whatever put it there.", module);
+                    Debug.logWarning("In finAccountPreAuth for finAccountId [" + finAccountId + "] availableBalance ["
+                            + availableBalanceOriginal + "] was different after rounding [" + availableBalance
+                            + "]; it should never have made it into the database this way, so check whatever put it there.",
+                            module);
                 }
             }
 
-
             Map<String, Object> result = ServiceUtil.returnSuccess();
             String authMessage = null;
             Boolean processResult;
@@ -256,7 +273,8 @@ public class FinAccountPaymentServices {
                 // refresh the account
                 finAccount.refresh();
             } else {
-                Debug.logWarning("Attempted to authorize [" + amount + "] against a balance of only [" + availableBalance + "] for finAccountId [" + finAccountId + "]", module);
+                Debug.logWarning("Attempted to authorize [" + amount + "] against a balance of only ["
+                        + availableBalance + "] for finAccountId [" + finAccountId + "]", module);
                 refNum = "0"; // a refNum is always required from authorization
                 authMessage = "Insufficient funds";
                 processResult = Boolean.FALSE;
@@ -272,15 +290,10 @@ public class FinAccountPaymentServices {
             Debug.logInfo("FinAccont Auth: " + result, module);
 
             return result;
-        } catch (GenericEntityException ex) {
-            Debug.logError(ex, "Cannot authorize financial account", module);
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
-                    "AccountingFinAccountCannotBeAuthorized",
-                    UtilMisc.toMap("errorString", ex.getMessage()), locale));
-        } catch (GenericServiceException ex) {
+        } catch (GenericEntityException | GenericServiceException ex) {
             Debug.logError(ex, "Cannot authorize financial account", module);
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
-                    "AccountingFinAccountCannotBeAuthorized",
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+                    "AccountingFinAccountCannotBeAuthorized",
                     UtilMisc.toMap("errorString", ex.getMessage()), locale));
         }
     }
@@ -336,7 +349,7 @@ public class FinAccountPaymentServices {
             authTrans = PaymentGatewayServices.getAuthTransaction(orderPaymentPreference);
         }
         if (authTrans == null) {
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                     "AccountingFinAccountCannotCapture", locale));
         }
 
@@ -344,7 +357,8 @@ public class FinAccountPaymentServices {
         String finAccountAuthId = authTrans.getString("referenceNum");
         GenericValue finAccountAuth;
         try {
-            finAccountAuth = EntityQuery.use(delegator).from("FinAccountAuth").where("finAccountAuthId", finAccountAuthId).queryOne();
+            finAccountAuth = EntityQuery.use(delegator).from("FinAccountAuth").where("finAccountAuthId",
+                    finAccountAuthId).queryOne();
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
             return ServiceUtil.returnError(e.getMessage());
@@ -364,16 +378,17 @@ public class FinAccountPaymentServices {
         // make sure authorization has not expired
         Timestamp authExpiration = finAccountAuth.getTimestamp("thruDate");
         if ((authExpiration != null) && (authExpiration.before(UtilDateTime.nowTimestamp()))) {
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
-                    "AccountingFinAccountAuthorizationExpired",
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+                    "AccountingFinAccountAuthorizationExpired",
                     UtilMisc.toMap("paymentGatewayResponseId", authTrans.getString("paymentGatewayResponseId"),
                             "authExpiration", authExpiration), locale));
         }
 
         // make sure the fin account itself has not expired
-        if ((finAccount.getTimestamp("thruDate") != null) && (finAccount.getTimestamp("thruDate").before(UtilDateTime.nowTimestamp()))) {
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
-                    "AccountingFinAccountExpired",
+        if ((finAccount.getTimestamp("thruDate") != null) && (finAccount.getTimestamp("thruDate").before(UtilDateTime
+                .nowTimestamp()))) {
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+                    "AccountingFinAccountExpired",
                     UtilMisc.toMap("thruDate", finAccount.getTimestamp("thruDate")), locale));
         }
         String finAccountId = finAccount.getString("finAccountId");
@@ -408,7 +423,7 @@ public class FinAccountPaymentServices {
         }
 
         // build the withdraw context
-        Map<String, Object> withdrawCtx = new HashMap<String, Object>();
+        Map<String, Object> withdrawCtx = new HashMap<>();
         withdrawCtx.put("finAccountId", finAccountId);
         withdrawCtx.put("productStoreId", productStoreId);
         withdrawCtx.put("currency", currency);
@@ -477,12 +492,12 @@ public class FinAccountPaymentServices {
         }
 
         if (finAccountId == null) {
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                     "AccountingFinAccountNotFound", UtilMisc.toMap("finAccountId", ""), locale));
         }
 
         // call the deposit service
-        Map<String, Object> depositCtx = new HashMap<String, Object>();
+        Map<String, Object> depositCtx = new HashMap<>();
         depositCtx.put("finAccountId", finAccountId);
         depositCtx.put("productStoreId", productStoreId);
         depositCtx.put("isRefund", Boolean.TRUE);
@@ -532,7 +547,9 @@ public class FinAccountPaymentServices {
         String orderId = (String) context.get("orderId");
         Boolean requireBalance = (Boolean) context.get("requireBalance");
         BigDecimal amount = (BigDecimal) context.get("amount");
-        if (requireBalance == null) requireBalance = Boolean.TRUE;
+        if (requireBalance == null) {
+            requireBalance = Boolean.TRUE;
+        }
 
         final String WITHDRAWAL = "WITHDRAWAL";
 
@@ -547,7 +564,7 @@ public class FinAccountPaymentServices {
 
         // validate the amount
         if (amount.compareTo(BigDecimal.ZERO) < 0) {
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                     "AccountingFinAccountMustBePositive", locale));
         }
 
@@ -561,18 +578,20 @@ public class FinAccountPaymentServices {
 
         // verify we have a financial account
         if (finAccount == null) {
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                     "AccountingFinAccountNotFound", UtilMisc.toMap("finAccountId", ""), locale));
         }
 
         // make sure the fin account itself has not expired
-        if ((finAccount.getTimestamp("thruDate") != null) && (finAccount.getTimestamp("thruDate").before(UtilDateTime.nowTimestamp()))) {
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
-                    "AccountingFinAccountExpired",
+        if ((finAccount.getTimestamp("thruDate") != null) && (finAccount.getTimestamp("thruDate").before(UtilDateTime
+                .nowTimestamp()))) {
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+                    "AccountingFinAccountExpired",
                     UtilMisc.toMap("thruDate", finAccount.getTimestamp("thruDate")), locale));
         }
 
-        // check the actual balance (excluding authorized amounts) and create the transaction if it is sufficient
+        // check the actual balance (excluding authorized amounts) and create the
+        // transaction if it is sufficient
         BigDecimal previousBalance = finAccount.getBigDecimal("actualBalance");
         if (previousBalance == null) {
             previousBalance = FinAccountHelper.ZERO;
@@ -587,8 +606,10 @@ public class FinAccountPaymentServices {
             refNum = "N/A";
         } else {
             try {
-                refNum = FinAccountPaymentServices.createFinAcctPaymentTransaction(delegator, dispatcher, userLogin, amount,
-                        productStoreId, partyId, orderId, orderItemSeqId, currencyUom, WITHDRAWAL, finAccountId, reasonEnumId);
+                refNum = FinAccountPaymentServices.createFinAcctPaymentTransaction(delegator, dispatcher, userLogin,
+                        amount,
+                        productStoreId, partyId, orderId, orderItemSeqId, currencyUom, WITHDRAWAL, finAccountId,
+                        reasonEnumId);
                 finAccount.refresh();
                 balance = finAccount.getBigDecimal("actualBalance");
                 procResult = Boolean.TRUE;
@@ -643,20 +664,21 @@ public class FinAccountPaymentServices {
             finAccount = EntityQuery.use(delegator).from("FinAccount").where("finAccountId", finAccountId).queryOne();
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                     "AccountingFinAccountNotFound", UtilMisc.toMap("finAccountId", finAccountId), locale));
         }
 
         // verify we have a financial account
         if (finAccount == null) {
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                     "AccountingFinAccountNotFound", UtilMisc.toMap("finAccountId", ""), locale));
         }
 
         // make sure the fin account itself has not expired
-        if ((finAccount.getTimestamp("thruDate") != null) && (finAccount.getTimestamp("thruDate").before(UtilDateTime.nowTimestamp()))) {
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
-                    "AccountingFinAccountExpired",
+        if ((finAccount.getTimestamp("thruDate") != null) && (finAccount.getTimestamp("thruDate").before(UtilDateTime
+                .nowTimestamp()))) {
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+                    "AccountingFinAccountExpired",
                     UtilMisc.toMap("thruDate", finAccount.getTimestamp("thruDate")), locale));
         }
         Debug.logInfo("Deposit into financial account #" + finAccountId + " [" + amount + "]", module);
@@ -685,9 +707,11 @@ public class FinAccountPaymentServices {
             actualBalance = FinAccountHelper.ZERO;
         } else {
             if (actualBalance.compareTo(BigDecimal.ZERO) < 0) {
-                // balance went below zero, set negative pending replenishment status so that no more auths or captures will go through until it is replenished
+                // balance went below zero, set negative pending replenishment status so that no
+                // more auths or captures will go through until it is replenished
                 try {
-                    Map<String, Object> rollbackCtx = UtilMisc.toMap("userLogin", userLogin, "finAccountId", finAccountId, "statusId", "FNACT_NEGPENDREPL");
+                    Map<String, Object> rollbackCtx = UtilMisc.toMap("userLogin", userLogin, "finAccountId",
+                            finAccountId, "statusId", "FNACT_NEGPENDREPL");
                     dispatcher.addRollbackService("updateFinAccount", rollbackCtx, true);
                 } catch (GenericServiceException e) {
                     Debug.logError(e, module);
@@ -724,7 +748,7 @@ public class FinAccountPaymentServices {
             return ServiceUtil.returnError(e.getMessage());
         }
         if (finAccount == null) {
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                     "AccountingFinAccountNotFound", UtilMisc.toMap("finAccountId", finAccountId), locale));
         }
         String currency = finAccount.getString("currencyUomId");
@@ -748,35 +772,41 @@ public class FinAccountPaymentServices {
         if (productStoreId == null) {
             productStoreId = getLastProductStoreId(delegator, finAccountId);
             if (productStoreId == null) {
-                return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+                return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                         "AccountingFinAccountCannotBeReplenish", locale));
             }
         }
 
         // get the product store settings
         GenericValue finAccountSettings;
-        Map<String, Object> psfasFindMap = UtilMisc.<String, Object>toMap("productStoreId", productStoreId, "finAccountTypeId", finAccount.getString("finAccountTypeId"));
+        Map<String, Object> psfasFindMap = UtilMisc.<String, Object>toMap("productStoreId", productStoreId,
+                "finAccountTypeId", finAccount.getString("finAccountTypeId"));
         try {
-            finAccountSettings = EntityQuery.use(delegator).from("ProductStoreFinActSetting").where(psfasFindMap).cache().queryOne();
+            finAccountSettings = EntityQuery.use(delegator).from("ProductStoreFinActSetting").where(psfasFindMap)
+                    .cache().queryOne();
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
             return ServiceUtil.returnError(e.getMessage());
         }
         if (finAccountSettings == null) {
-            Debug.logWarning("finAccountReplenish Warning: not replenishing FinAccount [" + finAccountId  + "] because no ProductStoreFinActSetting record found for: " + psfasFindMap, module);
+            Debug.logWarning("finAccountReplenish Warning: not replenishing FinAccount [" + finAccountId
+                    + "] because no ProductStoreFinActSetting record found for: " + psfasFindMap, module);
             // no settings; don't replenish
             return ServiceUtil.returnSuccess();
         }
 
         BigDecimal replenishThreshold = finAccountSettings.getBigDecimal("replenishThreshold");
         if (replenishThreshold == null) {
-            Debug.logWarning("finAccountReplenish Warning: not replenishing FinAccount [" + finAccountId  + "] because ProductStoreFinActSetting.replenishThreshold field was null for: " + psfasFindMap, module);
+            Debug.logWarning("finAccountReplenish Warning: not replenishing FinAccount [" + finAccountId
+                    + "] because ProductStoreFinActSetting.replenishThreshold field was null for: " + psfasFindMap,
+                    module);
             return ServiceUtil.returnSuccess();
         }
 
         BigDecimal replenishLevel = finAccount.getBigDecimal("replenishLevel");
         if (replenishLevel == null || replenishLevel.compareTo(BigDecimal.ZERO) == 0) {
-            Debug.logWarning("finAccountReplenish Warning: not replenishing FinAccount [" + finAccountId  + "] because FinAccount.replenishLevel field was null or 0", module);
+            Debug.logWarning("finAccountReplenish Warning: not replenishing FinAccount [" + finAccountId
+                    + "] because FinAccount.replenishLevel field was null or 0", module);
             // no replenish level set; this account goes not support auto-replenish
             return ServiceUtil.returnSuccess();
         }
@@ -786,7 +816,9 @@ public class FinAccountPaymentServices {
 
         // see if we are within the threshold for replenishment
         if (balance.compareTo(replenishThreshold) > -1) {
-            Debug.logInfo("finAccountReplenish Info: Not replenishing FinAccount [" + finAccountId  + "] because balance [" + balance + "] is greater than the replenishThreshold [" + replenishThreshold + "]", module);
+            Debug.logInfo("finAccountReplenish Info: Not replenishing FinAccount [" + finAccountId
+                    + "] because balance [" + balance + "] is greater than the replenishThreshold ["
+                    + replenishThreshold + "]", module);
             // not ready
             return ServiceUtil.returnSuccess();
         }
@@ -794,7 +826,8 @@ public class FinAccountPaymentServices {
         // configure rollback service to set status to Negative Pending Replenishment
         if ("FNACT_NEGPENDREPL".equals(statusId)) {
             try {
-                Map<String, Object> rollbackCtx = UtilMisc.toMap("userLogin", userLogin, "finAccountId", finAccountId, "statusId", "FNACT_NEGPENDREPL");
+                Map<String, Object> rollbackCtx = UtilMisc.toMap("userLogin", userLogin, "finAccountId", finAccountId,
+                        "statusId", "FNACT_NEGPENDREPL");
                 dispatcher.addRollbackService("updateFinAccount", rollbackCtx, true);
             } catch (GenericServiceException e) {
                 Debug.logError(e, module);
@@ -805,13 +838,13 @@ public class FinAccountPaymentServices {
         String replenishMethod = finAccountSettings.getString("replenishMethodEnumId");
         BigDecimal depositAmount;
         if (replenishMethod == null || "FARP_TOP_OFF".equals(replenishMethod)) {
-            //the deposit is level - balance (500 - (-10) = 510 || 500 - (10) = 490)
+            // the deposit is level - balance (500 - (-10) = 510 || 500 - (10) = 490)
             depositAmount = replenishLevel.subtract(balance);
         } else if ("FARP_REPLENISH_LEVEL".equals(replenishMethod)) {
-            //the deposit is replenish-level itself
+            // the deposit is replenish-level itself
             depositAmount = replenishLevel;
         } else {
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                     "AccountingFinAccountUnknownReplenishMethod", locale));
         }
 
@@ -819,35 +852,40 @@ public class FinAccountPaymentServices {
         String ownerPartyId = finAccount.getString("ownerPartyId");
         if (ownerPartyId == null) {
             // no owner cannot replenish; (not fatal, just not supported by this account)
-            Debug.logWarning("finAccountReplenish Warning: No owner attached to financial account [" + finAccountId + "] cannot auto-replenish", module);
+            Debug.logWarning("finAccountReplenish Warning: No owner attached to financial account [" + finAccountId
+                    + "] cannot auto-replenish", module);
             return ServiceUtil.returnSuccess();
         }
 
         // get the payment method to use to replenish
         String paymentMethodId = finAccount.getString("replenishPaymentId");
         if (paymentMethodId == null) {
-            Debug.logWarning("finAccountReplenish Warning: No payment method (replenishPaymentId) attached to financial account [" + finAccountId + "] cannot auto-replenish", module);
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+            Debug.logWarning(
+                    "finAccountReplenish Warning: No payment method (replenishPaymentId) attached to financial account ["
+                            + finAccountId + "] cannot auto-replenish", module);
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                     "AccountingFinAccountNoPaymentMethodAssociatedWithReplenishAccount", locale));
         }
 
         GenericValue paymentMethod;
         try {
-            paymentMethod = EntityQuery.use(delegator).from("PaymentMethod").where("paymentMethodId", paymentMethodId).queryOne();
+            paymentMethod = EntityQuery.use(delegator).from("PaymentMethod").where("paymentMethodId", paymentMethodId)
+                    .queryOne();
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
             return ServiceUtil.returnError(e.getMessage());
         }
         if (paymentMethod == null) {
             // no payment methods on file; cannot replenish
-            Debug.logWarning("finAccountReplenish Warning: No payment method found for ID [" + paymentMethodId + "] for party [" + ownerPartyId + "] cannot auto-replenish", module);
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+            Debug.logWarning("finAccountReplenish Warning: No payment method found for ID [" + paymentMethodId
+                    + "] for party [" + ownerPartyId + "] cannot auto-replenish", module);
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                     "AccountingFinAccountNoPaymentMethodAssociatedWithReplenishAccount", locale));
         }
 
         // hit the payment method for the amount to replenish
         Map<String, BigDecimal> orderItemMap = UtilMisc.toMap("Auto-Replenishment FA #" + finAccountId, depositAmount);
-        Map<String, Object> replOrderCtx = new HashMap<String, Object>();
+        Map<String, Object> replOrderCtx = new HashMap<>();
         replOrderCtx.put("productStoreId", productStoreId);
         replOrderCtx.put("paymentMethodId", paymentMethod.getString("paymentMethodId"));
         replOrderCtx.put("currency", currency);
@@ -867,14 +905,14 @@ public class FinAccountPaymentServices {
         String orderId = (String) replResp.get("orderId");
 
         // create the deposit
-        Map<String, Object> depositCtx = new HashMap<String, Object>();
+        Map<String, Object> depositCtx = new HashMap<>();
         depositCtx.put("productStoreId", productStoreId);
         depositCtx.put("finAccountId", finAccountId);
         depositCtx.put("currency", currency);
         depositCtx.put("partyId", ownerPartyId);
         depositCtx.put("orderId", orderId);
         depositCtx.put("orderItemSeqId", "00001"); // always one item on a replish order
-        depositCtx.put("amount",  depositAmount);
+        depositCtx.put("amount", depositAmount);
         depositCtx.put("reasonEnumId", "FATR_REPLENISH");
         depositCtx.put("userLogin", userLogin);
         try {
@@ -910,8 +948,8 @@ public class FinAccountPaymentServices {
                     .where(
                             EntityCondition.makeCondition("finAccountTransTypeId", EntityOperator.EQUALS, "DEPOSIT"),
                             EntityCondition.makeCondition("finAccountId", EntityOperator.EQUALS, finAccountId),
-                            EntityCondition.makeCondition("orderId", EntityOperator.NOT_EQUAL, null)
-                    ).orderBy("-transactionDate").queryFirst();
+                            EntityCondition.makeCondition("orderId", EntityOperator.NOT_EQUAL, null)).orderBy(
+                                    "-transactionDate").queryFirst();
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
         }
@@ -925,8 +963,9 @@ public class FinAccountPaymentServices {
         // none found; pick one from our set stores
         try {
             GenericValue store = EntityQuery.use(delegator).from("ProductStore").orderBy("productStoreId").queryFirst();
-            if (store != null)
+            if (store != null) {
                 return store.getString("productStoreId");
+            }
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
         }
@@ -934,8 +973,10 @@ public class FinAccountPaymentServices {
         return null;
     }
 
-    private static String createFinAcctPaymentTransaction(Delegator delegator, LocalDispatcher dispatcher, GenericValue userLogin, BigDecimal amount,
-            String productStoreId, String partyId, String orderId, String orderItemSeqId, String currencyUom, String txType, String finAccountId, String reasonEnumId) throws GeneralException {
+    private static String createFinAcctPaymentTransaction(Delegator delegator, LocalDispatcher dispatcher,
+            GenericValue userLogin, BigDecimal amount,
+            String productStoreId, String partyId, String orderId, String orderItemSeqId, String currencyUom,
+            String txType, String finAccountId, String reasonEnumId) throws GeneralException {
 
         final String coParty = ProductStoreWorker.getProductStorePayToPartyId(productStoreId, delegator);
         final String paymentMethodType = "FIN_ACCOUNT";

Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountProductServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountProductServices.java?rev=1818550&r1=1818549&r2=1818550&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountProductServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountProductServices.java Mon Dec 18 10:41:55 2017
@@ -45,14 +45,15 @@ import org.apache.ofbiz.service.LocalDis
 import org.apache.ofbiz.service.ServiceUtil;
 
 /**
- * FinAccountProductServices - Financial Accounts created from product purchases (i.e. gift certificates)
+ * FinAccountProductServices - Financial Accounts created from product purchases
+ * (i.e. gift certificates)
  */
 public class FinAccountProductServices {
 
     public static final String module = FinAccountProductServices.class.getName();
     public static final String resourceOrderError = "OrderErrorUiLabels";
     public static final String resourceError = "AccountingErrorUiLabels";
-    
+
     public static Map<String, Object> createPartyFinAccountFromPurchase(DispatchContext dctx, Map<String, Object> context) {
         // this service should always be called via FULFILLMENT_EXTASYNC
         LocalDispatcher dispatcher = dctx.getDispatcher();
@@ -71,7 +72,7 @@ public class FinAccountProductServices {
             orderHeader = orderItem.getRelatedOne("OrderHeader", false);
         } catch (GenericEntityException e) {
             Debug.logError(e, "Unable to get OrderHeader from OrderItem", module);
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceOrderError,
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceOrderError,
                     "OrderCannotGetOrderHeader", UtilMisc.toMap("orderId", orderId), locale));
         }
 
@@ -128,8 +129,8 @@ public class FinAccountProductServices {
         }
         if (productStoreId == null) {
             Debug.logFatal("Unable to create financial accout; no productStoreId on OrderHeader : " + orderId, module);
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
-                    "AccountingFinAccountCannotCreate",
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+                    "AccountingFinAccountCannotCreate",
                     UtilMisc.toMap("orderId", orderId), locale));
         }
 
@@ -174,7 +175,7 @@ public class FinAccountProductServices {
         }
 
         // create the context for FSE
-        Map<String, Object> expContext = new HashMap<String, Object>();
+        Map<String, Object> expContext = new HashMap<>();
         expContext.put("orderHeader", orderHeader);
         expContext.put("orderItem", orderItem);
         expContext.put("party", party);
@@ -191,7 +192,7 @@ public class FinAccountProductServices {
         BigDecimal deposit = price.multiply(quantity).setScale(FinAccountHelper.decimals, FinAccountHelper.rounding);
 
         // create the financial account
-        Map<String, Object> createCtx = new HashMap<String, Object>();
+        Map<String, Object> createCtx = new HashMap<>();
         String finAccountId;
 
         createCtx.put("finAccountTypeId", finAccountTypeId);
@@ -223,7 +224,7 @@ public class FinAccountProductServices {
         finAccountId = (String) createResp.get("finAccountId");
 
         // create the owner role
-        Map<String, Object> roleCtx = new HashMap<String, Object>();
+        Map<String, Object> roleCtx = new HashMap<>();
         roleCtx.put("partyId", partyId);
         roleCtx.put("roleTypeId", "OWNER");
         roleCtx.put("finAccountId", finAccountId);
@@ -242,7 +243,7 @@ public class FinAccountProductServices {
         }
 
         // create the initial deposit
-        Map<String, Object> depositCtx = new HashMap<String, Object>();
+        Map<String, Object> depositCtx = new HashMap<>();
         depositCtx.put("finAccountId", finAccountId);
         depositCtx.put("productStoreId", productStoreId);
         depositCtx.put("currency", currency);

Modified: ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountServices.java?rev=1818550&r1=1818549&r2=1818550&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/finaccount/FinAccountServices.java Mon Dec 18 10:41:55 2017
@@ -77,9 +77,11 @@ public class FinAccountServices {
         try {
             // find the most recent (active) service credit account for the specified party
             String partyId = (String) context.get("partyId");
-            Map<String, String> lookupMap = UtilMisc.toMap("finAccountTypeId", finAccountTypeId, "ownerPartyId", partyId);
+            Map<String, String> lookupMap = UtilMisc.toMap("finAccountTypeId", finAccountTypeId, "ownerPartyId",
+                    partyId);
 
-            // if a productStoreId is present, restrict the accounts returned using the store's payToPartyId
+            // if a productStoreId is present, restrict the accounts returned using the
+            // store's payToPartyId
             String productStoreId = (String) context.get("productStoreId");
             if (UtilValidate.isNotEmpty(productStoreId)) {
                 String payToPartyId = ProductStoreWorker.getProductStorePayToPartyId(productStoreId, delegator);
@@ -97,9 +99,11 @@ public class FinAccountServices {
             // check for an existing account
             GenericValue creditAccount;
             if (finAccountId != null) {
-                creditAccount = EntityQuery.use(delegator).from("FinAccount").where("finAccountId", finAccountId).queryOne();
+                creditAccount = EntityQuery.use(delegator).from("FinAccount").where("finAccountId", finAccountId)
+                        .queryOne();
             } else {
-                creditAccount = EntityQuery.use(delegator).from("FinAccount").where(lookupMap).orderBy("-fromDate").filterByDate().queryFirst();
+                creditAccount = EntityQuery.use(delegator).from("FinAccount").where(lookupMap).orderBy("-fromDate")
+                        .filterByDate().queryFirst();
             }
 
             if (creditAccount == null) {
@@ -124,10 +128,11 @@ public class FinAccountServices {
                 if (createAccountResult != null) {
                     String creditAccountId = (String) createAccountResult.get("finAccountId");
                     if (UtilValidate.isNotEmpty(creditAccountId)) {
-                        creditAccount = EntityQuery.use(delegator).from("FinAccount").where("finAccountId", creditAccountId).queryOne();
+                        creditAccount = EntityQuery.use(delegator).from("FinAccount").where("finAccountId",
+                                creditAccountId).queryOne();
 
                         // create the owner role
-                        Map<String, Object> roleCtx = new HashMap<String, Object>();
+                        Map<String, Object> roleCtx = new HashMap<>();
                         roleCtx.put("partyId", partyId);
                         roleCtx.put("roleTypeId", "OWNER");
                         roleCtx.put("finAccountId", creditAccountId);
@@ -146,13 +151,13 @@ public class FinAccountServices {
                     }
                 }
                 if (creditAccount == null) {
-                    return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+                    return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                             "AccountingFinAccountCannotCreditAccount", locale));
                 }
             }
 
             // create the credit transaction
-            Map<String, Object> transactionMap = new HashMap<String, Object>();
+            Map<String, Object> transactionMap = new HashMap<>();
             transactionMap.put("finAccountTransTypeId", "ADJUSTMENT");
             transactionMap.put("finAccountId", creditAccount.getString("finAccountId"));
             transactionMap.put("partyId", partyId);
@@ -165,7 +170,7 @@ public class FinAccountServices {
             if (ServiceUtil.isError(creditTransResult) || ServiceUtil.isFailure(creditTransResult)) {
                 return ServiceUtil.returnError(ServiceUtil.getErrorMessage(creditTransResult));
             }
-        } catch (GenericEntityException|GenericServiceException ge) {
+        } catch (GenericEntityException | GenericServiceException ge) {
             return ServiceUtil.returnError(ge.getMessage());
         }
 
@@ -188,9 +193,10 @@ public class FinAccountServices {
             GenericValue productStoreFinAccountSetting = EntityQuery.use(delegator).from("ProductStoreFinActSetting")
                     .where("productStoreId", productStoreId, "finAccountTypeId", finAccountTypeId).cache().queryOne();
             if (productStoreFinAccountSetting == null) {
-                return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
-                        "AccountingFinAccountSetting",
-                        UtilMisc.toMap("productStoreId", productStoreId, "finAccountTypeId", finAccountTypeId), locale));
+                return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+                        "AccountingFinAccountSetting",
+                        UtilMisc.toMap("productStoreId", productStoreId, "finAccountTypeId", finAccountTypeId),
+                        locale));
             }
 
             Long accountCodeLength = productStoreFinAccountSetting.getLong("accountCodeLength");
@@ -214,7 +220,7 @@ public class FinAccountServices {
             }
 
             // set the dates/userlogin
-            if (UtilValidate.isNotEmpty(accountValidDays)){
+            if (UtilValidate.isNotEmpty(accountValidDays)) {
                 inContext.put("thruDate", UtilDateTime.getDayEnd(now, accountValidDays));
             }
             inContext.put("fromDate", now);
@@ -233,9 +239,7 @@ public class FinAccountServices {
             result.put("finAccountId", createResult.get("finAccountId"));
             result.put("finAccountCode", finAccountCode);
             return result;
-        } catch (GenericEntityException ex) {
-            return ServiceUtil.returnError(ex.getMessage());
-        } catch (GenericServiceException ex) {
+        } catch (GenericEntityException | GenericServiceException ex) {
             return ServiceUtil.returnError(ex.getMessage());
         }
     }
@@ -256,14 +260,15 @@ public class FinAccountServices {
             }
         } else {
             try {
-                finAccount = EntityQuery.use(delegator).from("FinAccount").where("finAccountId", finAccountId).queryOne();
+                finAccount = EntityQuery.use(delegator).from("FinAccount").where("finAccountId", finAccountId)
+                        .queryOne();
             } catch (GenericEntityException e) {
                 Debug.logError(e, module);
                 return ServiceUtil.returnError(e.getMessage());
             }
         }
         if (finAccount == null) {
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                     "AccountingFinAccountNotFound", UtilMisc.toMap("finAccountId", finAccountId), locale));
         }
 
@@ -278,7 +283,8 @@ public class FinAccountServices {
         }
 
         String statusId = finAccount.getString("statusId");
-        Debug.logInfo("FinAccount Balance [" + balance + "] Available [" + availableBalance + "] - Status: " + statusId, module);
+        Debug.logInfo("FinAccount Balance [" + balance + "] Available [" + availableBalance + "] - Status: " + statusId,
+                module);
 
         Map<String, Object> result = ServiceUtil.returnSuccess();
         result.put("availableBalance", availableBalance);
@@ -293,7 +299,7 @@ public class FinAccountServices {
         Locale locale = (Locale) context.get("locale");
 
         if (finAccountId == null) {
-            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+            return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                     "AccountingFinAccountNotFound", UtilMisc.toMap("finAccountId", ""), locale));
         }
 
@@ -306,7 +312,9 @@ public class FinAccountServices {
 
         if (finAccount != null) {
             String statusId = finAccount.getString("statusId");
-            if (statusId == null) statusId = "FNACT_ACTIVE";
+            if (statusId == null) {
+                statusId = "FNACT_ACTIVE";
+            }
 
             BigDecimal balance = finAccount.getBigDecimal("actualBalance");
             if (balance == null) {
@@ -317,10 +325,12 @@ public class FinAccountServices {
 
             if ("FNACT_ACTIVE".equals(statusId) && balance.compareTo(FinAccountHelper.ZERO) < 1) {
                 finAccount.set("statusId", "FNACT_MANFROZEN");
-                Debug.logInfo("Financial account [" + finAccountId + "] has passed its threshold [" + balance + "] (Frozen)", module);
+                Debug.logInfo("Financial account [" + finAccountId + "] has passed its threshold [" + balance
+                        + "] (Frozen)", module);
             } else if ("FNACT_MANFROZEN".equals(statusId) && balance.compareTo(FinAccountHelper.ZERO) > 0) {
                 finAccount.set("statusId", "FNACT_ACTIVE");
-                Debug.logInfo("Financial account [" + finAccountId + "] has been made current [" + balance + "] (Un-Frozen)", module);
+                Debug.logInfo("Financial account [" + finAccountId + "] has been made current [" + balance
+                        + "] (Un-Frozen)", module);
             }
             try {
                 finAccount.store();
@@ -350,7 +360,7 @@ public class FinAccountServices {
         if (finAccount != null) {
             // check to make sure the account is refundable
             if (!"Y".equals(finAccount.getString("isRefundable"))) {
-                return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+                return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                         "AccountingFinAccountIsNotRefundable", locale));
             }
 
@@ -358,9 +368,10 @@ public class FinAccountServices {
             BigDecimal availableBalance = finAccount.getBigDecimal("availableBalance");
             BigDecimal actualBalance = finAccount.getBigDecimal("actualBalance");
 
-            // if they do not match, then there are outstanding authorizations which need to be settled first
+            // if they do not match, then there are outstanding authorizations which need to
+            // be settled first
             if (actualBalance.compareTo(availableBalance) != 0) {
-                return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
+                return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                         "AccountingFinAccountCannotBeRefunded", locale));
             }
 
@@ -369,11 +380,13 @@ public class FinAccountServices {
                 BigDecimal remainingBalance = new BigDecimal(actualBalance.toString());
                 BigDecimal refundAmount = BigDecimal.ZERO;
 
-                List<EntityExpr> exprs = UtilMisc.toList(EntityCondition.makeCondition("finAccountTransTypeId", EntityOperator.EQUALS, "DEPOSIT"),
+                List<EntityExpr> exprs = UtilMisc.toList(EntityCondition.makeCondition("finAccountTransTypeId",
+                        EntityOperator.EQUALS, "DEPOSIT"),
                         EntityCondition.makeCondition("finAccountId", EntityOperator.EQUALS, finAccountId));
                 EntityCondition condition = EntityCondition.makeCondition(exprs, EntityOperator.AND);
 
-                try (EntityListIterator eli  = EntityQuery.use(delegator).from("FinAccountTrans").where(condition).orderBy("-transactionDate").queryIterator()) {
+                try (EntityListIterator eli = EntityQuery.use(delegator).from("FinAccountTrans").where(condition)
+                        .orderBy("-transactionDate").queryIterator()) {
                     GenericValue trans;
                     while (remainingBalance.compareTo(FinAccountHelper.ZERO) < 0 && (trans = eli.next()) != null) {
                         String orderId = trans.getString("orderId");
@@ -381,9 +394,11 @@ public class FinAccountServices {
 
                         // make sure there is an order available to refund
                         if (orderId != null && orderItemSeqId != null) {
-                            GenericValue orderHeader = EntityQuery.use(delegator).from("OrderHeader").where("orderId",orderId).queryOne();
+                            GenericValue orderHeader = EntityQuery.use(delegator).from("OrderHeader").where("orderId",
+                                    orderId).queryOne();
                             GenericValue productStore = orderHeader.getRelatedOne("ProductStore", false);
-                            GenericValue orderItem = EntityQuery.use(delegator).from("OrderItem").where("orderId", orderId, "orderItemSeqId", orderItemSeqId).queryOne();
+                            GenericValue orderItem = EntityQuery.use(delegator).from("OrderItem").where("orderId",
+                                    orderId, "orderItemSeqId", orderItemSeqId).queryOne();
                             if (!"ITEM_CANCELLED".equals(orderItem.getString("statusId"))) {
 
                                 // make sure the item hasn't already been returned
@@ -398,7 +413,9 @@ public class FinAccountServices {
                                     refundAmount = refundAmount.add(refAmt);
 
                                     // create the return header
-                                    Map<String, Object> rhCtx = UtilMisc.toMap("returnHeaderTypeId", "CUSTOMER_RETURN", "fromPartyId", finAccount.getString("ownerPartyId"), "toPartyId", productStore.getString("payToPartyId"), "userLogin", userLogin);
+                                    Map<String, Object> rhCtx = UtilMisc.toMap("returnHeaderTypeId", "CUSTOMER_RETURN",
+                                            "fromPartyId", finAccount.getString("ownerPartyId"), "toPartyId",
+                                            productStore.getString("payToPartyId"), "userLogin", userLogin);
                                     Map<String, Object> rhResp = dispatcher.runSync("createReturnHeader", rhCtx);
                                     if (ServiceUtil.isError(rhResp)) {
                                         throw new GeneralException(ServiceUtil.getErrorMessage(rhResp));
@@ -406,7 +423,7 @@ public class FinAccountServices {
                                     String returnId = (String) rhResp.get("returnId");
 
                                     // create the return item
-                                    Map<String, Object> returnItemCtx = new HashMap<String, Object>();
+                                    Map<String, Object> returnItemCtx = new HashMap<>();
                                     returnItemCtx.put("returnId", returnId);
                                     returnItemCtx.put("orderId", orderId);
                                     returnItemCtx.put("description", orderItem.getString("itemDescription"));
@@ -419,36 +436,41 @@ public class FinAccountServices {
                                     returnItemCtx.put("returnItemTypeId", "RET_NPROD_ITEM");
                                     returnItemCtx.put("userLogin", userLogin);
 
-                                    Map<String, Object> retItResp = dispatcher.runSync("createReturnItem", returnItemCtx);
+                                    Map<String, Object> retItResp = dispatcher.runSync("createReturnItem",
+                                            returnItemCtx);
                                     if (ServiceUtil.isError(retItResp)) {
                                         throw new GeneralException(ServiceUtil.getErrorMessage(retItResp));
                                     }
                                     String returnItemSeqId = (String) retItResp.get("returnItemSeqId");
 
                                     // approve the return
-                                    Map<String, Object> appRet = UtilMisc.toMap("statusId", "RETURN_ACCEPTED", "returnId", returnId, "userLogin", userLogin);
+                                    Map<String, Object> appRet = UtilMisc.toMap("statusId", "RETURN_ACCEPTED",
+                                            "returnId", returnId, "userLogin", userLogin);
                                     Map<String, Object> appResp = dispatcher.runSync("updateReturnHeader", appRet);
                                     if (ServiceUtil.isError(appResp)) {
                                         throw new GeneralException(ServiceUtil.getErrorMessage(appResp));
                                     }
 
                                     // "receive" the return - should trigger the refund
-                                    Map<String, Object> recRet = UtilMisc.toMap("statusId", "RETURN_RECEIVED", "returnId", returnId, "userLogin", userLogin);
+                                    Map<String, Object> recRet = UtilMisc.toMap("statusId", "RETURN_RECEIVED",
+                                            "returnId", returnId, "userLogin", userLogin);
                                     Map<String, Object> recResp = dispatcher.runSync("updateReturnHeader", recRet);
                                     if (ServiceUtil.isError(recResp)) {
                                         throw new GeneralException(ServiceUtil.getErrorMessage(recResp));
                                     }
 
                                     // get the return item
-                                    GenericValue returnItem = EntityQuery.use(delegator).from("ReturnItem").where("returnId", returnId, "returnItemSeqId", returnItemSeqId).queryOne();
+                                    GenericValue returnItem = EntityQuery.use(delegator).from("ReturnItem").where(
+                                            "returnId", returnId, "returnItemSeqId", returnItemSeqId).queryOne();
                                     GenericValue response = returnItem.getRelatedOne("ReturnItemResponse", false);
                                     if (response == null) {
-                                        throw new GeneralException("No return response found for: " + returnItem.getPrimaryKey());
+                                        throw new GeneralException("No return response found for: " + returnItem
+                                                .getPrimaryKey());
                                     }
                                     String paymentId = response.getString("paymentId");
 
                                     // create the adjustment transaction
-                                    Map<String, Object> txCtx = new HashMap<String, Object>();
+                                    Map<String, Object> txCtx = new HashMap<>();
                                     txCtx.put("finAccountTransTypeId", "ADJUSTMENT");
                                     txCtx.put("finAccountId", finAccountId);
                                     txCtx.put("orderId", orderId);
@@ -473,7 +495,7 @@ public class FinAccountServices {
 
                 // check to make sure we balanced out
                 if (remainingBalance.compareTo(FinAccountHelper.ZERO) == 1) {
-                    result = ServiceUtil.returnSuccess(UtilProperties.getMessage(resourceError,
+                    result = ServiceUtil.returnSuccess(UtilProperties.getMessage(resourceError,
                             "AccountingFinAccountPartiallyRefunded", locale));
                 }
             }