Author: lektran Date: Sun Oct 5 20:52:54 2014 New Revision: 1629540 URL: http://svn.apache.org/r1629540 Log: Convert a few more classes to use EntityQuery
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/GlEvents.java ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/GlEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/GlEvents.java?rev=1629540&r1=1629539&r2=1629540&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/GlEvents.java (original) +++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/GlEvents.java Sun Oct 5 20:52:54 2014 @@ -32,6 +32,7 @@ import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ServiceUtil; @@ -64,7 +65,7 @@ public static String createReconcileAcco organizationPartyId = (String) ctx.get("organizationPartyId" + suffix); glAccountId = (String) ctx.get("glAccountId" + suffix); try { - GenericValue acctgTransEntry = delegator.findOne("AcctgTransEntry", UtilMisc.toMap("acctgTransId", acctgTransId, "acctgTransEntrySeqId", acctgTransEntrySeqId), false); + GenericValue acctgTransEntry = EntityQuery.use(delegator).from("AcctgTransEntry").where("acctgTransId", acctgTransId, "acctgTransEntrySeqId", acctgTransEntrySeqId).queryOne(); if (UtilValidate.isNotEmpty(acctgTransEntry)) { //calculate amount for each AcctgTransEntry according to glAccountId based on debit and credit debitCreditFlag = acctgTransEntry.getString("debitCreditFlag"); @@ -102,7 +103,7 @@ public static String createReconcileAcco acctgTransId = (String) ctx.get("acctgTransId" + suffix); acctgTransEntrySeqId = (String) ctx.get("acctgTransEntrySeqId" + suffix); try { - GenericValue acctgTransEntry = delegator.findOne("AcctgTransEntry", UtilMisc.toMap("acctgTransId", acctgTransId, "acctgTransEntrySeqId", acctgTransEntrySeqId), false); + GenericValue acctgTransEntry = EntityQuery.use(delegator).from("AcctgTransEntry").where("acctgTransId", acctgTransId, "acctgTransEntrySeqId", acctgTransEntrySeqId).queryOne(); if (UtilValidate.isNotEmpty(acctgTransEntry)) { reconciledAmount = acctgTransEntry.getString("amount"); acctgTransId = acctgTransEntry.getString("acctgTransId"); Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java?rev=1629540&r1=1629539&r2=1629540&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java (original) +++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java Sun Oct 5 20:52:54 2014 @@ -230,8 +230,8 @@ public class PaymentGatewayServices { } if (UtilValidate.isNotEmpty(billToPartyId)) { - otherPaymentMethodAndCreditCardList = delegator.findByAnd("PaymentMethodAndCreditCard", UtilMisc.toMap("partyId", billToPartyId, "paymentMethodTypeId", "CREDIT_CARD"), null, false); - otherPaymentMethodAndCreditCardList = EntityUtil.filterByDate(otherPaymentMethodAndCreditCardList, true); + otherPaymentMethodAndCreditCardList = EntityQuery.use(delegator).from("PaymentMethodAndCreditCard") + .where("partyId", billToPartyId, "paymentMethodTypeId", "CREDIT_CARD").filterByDate().queryList(); } if (UtilValidate.isNotEmpty(otherPaymentMethodAndCreditCardList)) { @@ -336,11 +336,11 @@ public class PaymentGatewayServices { // get the payments to auth Map<String, String> lookupMap = UtilMisc.toMap("orderId", orderId, "statusId", "PAYMENT_NOT_AUTH"); List<String> orderList = UtilMisc.toList("maxAmount"); - paymentPrefs = delegator.findByAnd("OrderPaymentPreference", lookupMap, orderList, false); + paymentPrefs = EntityQuery.use(delegator).from("OrderPaymentPreference").where(lookupMap).orderBy(orderList).queryList(); if (reAuth) { lookupMap.put("orderId", orderId); lookupMap.put("statusId", "PAYMENT_AUTHORIZED"); - paymentPrefs.addAll(delegator.findByAnd("OrderPaymentPreference", lookupMap, orderList, false)); + paymentPrefs.addAll(EntityQuery.use(delegator).from("OrderPaymentPreference").where(lookupMap).orderBy(orderList).queryList()); } } catch (GenericEntityException gee) { Debug.logError(gee, "Problems getting the order information", module); @@ -740,7 +740,7 @@ public class PaymentGatewayServices { EntityCondition con3 = EntityCondition.makeCondition(UtilMisc.toList(con2, authExpr), EntityOperator.OR); EntityExpr orderExpr = EntityCondition.makeCondition("orderId", EntityOperator.EQUALS, orderId); EntityCondition con4 = EntityCondition.makeCondition(UtilMisc.toList(con3, orderExpr), EntityOperator.AND); - paymentPrefs = delegator.findList("OrderPaymentPreference", con4, null, null, null, false); + paymentPrefs = EntityQuery.use(delegator).from("OrderPaymentPreference").where(con4).queryList(); } catch (GenericEntityException gee) { Debug.logError(gee, "Problems getting entity record(s), see stack trace", module); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); @@ -1181,13 +1181,13 @@ public class PaymentGatewayServices { orderHeader = EntityQuery.use(delegator).from("OrderHeader").where("orderId", orderId).queryOne(); // get the payment prefs - Map<String, String> lookupMap = UtilMisc.toMap("orderId", orderId, "statusId", "PAYMENT_AUTHORIZED"); - List<String> orderList = UtilMisc.toList("-maxAmount"); - paymentPrefs = delegator.findByAnd("OrderPaymentPreference", lookupMap, orderList, false); + paymentPrefs = EntityQuery.use(delegator).from("OrderPaymentPreference") + .where("orderId", orderId, "statusId", "PAYMENT_AUTHORIZED").orderBy("-maxAmount").queryList(); if (UtilValidate.isNotEmpty(billingAccountId)) { - lookupMap = UtilMisc.toMap("orderId", orderId, "paymentMethodTypeId", "EXT_BILLACT", "statusId", "PAYMENT_NOT_RECEIVED"); - paymentPrefsBa = delegator.findByAnd("OrderPaymentPreference", lookupMap, orderList, false); + paymentPrefsBa = EntityQuery.use(delegator).from("OrderPaymentPreference") + .where("orderId", orderId, "paymentMethodTypeId", "EXT_BILLACT", "statusId", "PAYMENT_NOT_RECEIVED") + .orderBy("-maxAmount").queryList(); } } catch (GenericEntityException gee) { Debug.logError(gee, "Problems getting entity record(s), see stack trace", module); Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java?rev=1629540&r1=1629539&r2=1629540&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java (original) +++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java Sun Oct 5 20:52:54 2014 @@ -35,6 +35,7 @@ import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.security.Security; import org.ofbiz.service.DispatchContext; @@ -73,7 +74,7 @@ public class PaymentMethodServices { GenericValue paymentMethod = null; try { - paymentMethod = delegator.findOne("PaymentMethod", UtilMisc.toMap("paymentMethodId", paymentMethodId), false); + paymentMethod = EntityQuery.use(delegator).from("PaymentMethod").where("paymentMethodId", paymentMethodId).queryOne(); } catch (GenericEntityException e) { Debug.logWarning(e.toString(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, @@ -213,8 +214,8 @@ public class PaymentMethodServices { GenericValue tempVal = null; try { - List<GenericValue> allPCWPs = delegator.findByAnd("PartyContactWithPurpose", - UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId), null, false); + List<GenericValue> allPCWPs = EntityQuery.use(delegator).from("PartyContactWithPurpose") + .where("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId).queryList(); allPCWPs = EntityUtil.filterByDate(allPCWPs, null, "contactFromDate", "contactThruDate", true); allPCWPs = EntityUtil.filterByDate(allPCWPs, null, "purposeFromDate", "purposeThruDate", true); tempVal = EntityUtil.getFirst(allPCWPs); @@ -275,8 +276,8 @@ public class PaymentMethodServices { String paymentMethodId = (String) context.get("paymentMethodId"); try { - creditCard = delegator.findOne("CreditCard", UtilMisc.toMap("paymentMethodId", paymentMethodId), false); - paymentMethod = delegator.findOne("PaymentMethod", UtilMisc.toMap("paymentMethodId", paymentMethodId), false); + creditCard = EntityQuery.use(delegator).from("CreditCard").where("paymentMethodId", paymentMethodId).queryOne(); + paymentMethod = EntityQuery.use(delegator).from("PaymentMethod").where("paymentMethodId", paymentMethodId).queryOne(); } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, @@ -388,8 +389,8 @@ public class PaymentMethodServices { GenericValue tempVal = null; try { - List<GenericValue> allPCWPs = delegator.findByAnd("PartyContactWithPurpose", - UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId), null, false); + List<GenericValue> allPCWPs = EntityQuery.use(delegator).from("PartyContactWithPurpose") + .where("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId).queryList(); allPCWPs = EntityUtil.filterByDate(allPCWPs, null, "contactFromDate", "contactThruDate", true); allPCWPs = EntityUtil.filterByDate(allPCWPs, null, "purposeFromDate", "purposeThruDate", true); @@ -448,7 +449,7 @@ public class PaymentMethodServices { Delegator delegator = dctx.getDelegator(); GenericValue creditCard; try { - creditCard = delegator.findOne("CreditCard", UtilMisc.toMap("paymentMethodId", paymentMethodId), false); + creditCard = EntityQuery.use(delegator).from("CreditCard").where("paymentMethodId", paymentMethodId).queryOne(); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); @@ -563,8 +564,8 @@ public class PaymentMethodServices { String paymentMethodId = (String) context.get("paymentMethodId"); try { - giftCard = delegator.findOne("GiftCard", UtilMisc.toMap("paymentMethodId", paymentMethodId), false); - paymentMethod = delegator.findOne("PaymentMethod", UtilMisc.toMap("paymentMethodId", paymentMethodId), false); + giftCard = EntityQuery.use(delegator).from("GiftCard").where("paymentMethodId", paymentMethodId).queryOne(); + paymentMethod = EntityQuery.use(delegator).from("PaymentMethod").where("paymentMethodId", paymentMethodId).queryOne(); } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, @@ -729,8 +730,8 @@ public class PaymentMethodServices { GenericValue tempVal = null; try { - List<GenericValue> allPCWPs = delegator.findByAnd("PartyContactWithPurpose", - UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId), null, false); + List<GenericValue> allPCWPs = EntityQuery.use(delegator).from("PartyContactWithPurpose") + .where("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId).queryList(); allPCWPs = EntityUtil.filterByDate(allPCWPs, null, "contactFromDate", "contactThruDate", true); allPCWPs = EntityUtil.filterByDate(allPCWPs, null, "purposeFromDate", "purposeThruDate", true); @@ -795,9 +796,9 @@ public class PaymentMethodServices { String paymentMethodId = (String) context.get("paymentMethodId"); try { - eftAccount = delegator.findOne("EftAccount", UtilMisc.toMap("paymentMethodId", paymentMethodId), false); + eftAccount = EntityQuery.use(delegator).from("EftAccount").where("paymentMethodId", paymentMethodId).queryOne(); paymentMethod = - delegator.findOne("PaymentMethod", UtilMisc.toMap("paymentMethodId", paymentMethodId), false); + EntityQuery.use(delegator).from("PaymentMethod").where("paymentMethodId", paymentMethodId).queryOne(); } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, @@ -858,8 +859,8 @@ public class PaymentMethodServices { GenericValue tempVal = null; try { - List<GenericValue> allPCWPs = delegator.findByAnd("PartyContactWithPurpose", - UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId), null, false); + List<GenericValue> allPCWPs = EntityQuery.use(delegator).from("PartyContactWithPurpose") + .where("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId).queryList(); allPCWPs = EntityUtil.filterByDate(allPCWPs, null, "contactFromDate", "contactThruDate", true); allPCWPs = EntityUtil.filterByDate(allPCWPs, null, "purposeFromDate", "purposeThruDate", true); tempVal = EntityUtil.getFirst(allPCWPs); Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java?rev=1629540&r1=1629539&r2=1629540&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java (original) +++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentWorker.java Sun Oct 5 20:52:54 2014 @@ -39,6 +39,7 @@ import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; import org.ofbiz.entity.condition.EntityExpr; import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; @@ -59,7 +60,7 @@ public class PaymentWorker { public static List<Map<String, GenericValue>> getPartyPaymentMethodValueMaps(Delegator delegator, String partyId, Boolean showOld) { List<Map<String, GenericValue>> paymentMethodValueMaps = FastList.newInstance(); try { - List<GenericValue> paymentMethods = delegator.findByAnd("PaymentMethod", UtilMisc.toMap("partyId", partyId), null, false); + List<GenericValue> paymentMethods = EntityQuery.use(delegator).from("PaymentMethod").where("partyId", partyId).queryList(); if (!showOld) paymentMethods = EntityUtil.filterByDate(paymentMethods, true); @@ -113,10 +114,10 @@ public class PaymentWorker { if (UtilValidate.isNotEmpty(paymentMethodId)) { try { - paymentMethod = delegator.findOne("PaymentMethod", UtilMisc.toMap("paymentMethodId", paymentMethodId), false); - creditCard = delegator.findOne("CreditCard", UtilMisc.toMap("paymentMethodId", paymentMethodId), false); - giftCard = delegator.findOne("GiftCard", UtilMisc.toMap("paymentMethodId", paymentMethodId), false); - eftAccount = delegator.findOne("EftAccount", UtilMisc.toMap("paymentMethodId", paymentMethodId), false); + paymentMethod = EntityQuery.use(delegator).from("PaymentMethod").where("paymentMethodId", paymentMethodId).queryOne(); + creditCard = EntityQuery.use(delegator).from("CreditCard").where("paymentMethodId", paymentMethodId).queryOne(); + giftCard = EntityQuery.use(delegator).from("GiftCard").where("paymentMethodId", paymentMethodId).queryOne(); + eftAccount = EntityQuery.use(delegator).from("EftAccount").where("paymentMethodId", paymentMethodId).queryOne(); } catch (GenericEntityException e) { Debug.logWarning(e, module); } @@ -156,23 +157,21 @@ public class PaymentWorker { } public static GenericValue getPaymentAddress(Delegator delegator, String partyId) { - List<GenericValue> paymentAddresses = null; + GenericValue purpose = null; try { - paymentAddresses = delegator.findByAnd("PartyContactWithPurpose", - UtilMisc.toMap("partyId", partyId, "contactMechPurposeTypeId", "PAYMENT_LOCATION"), - UtilMisc.toList("-purposeFromDate"), false); - paymentAddresses = EntityUtil.filterByDate(paymentAddresses, null, "contactFromDate", "contactThruDate", true); - paymentAddresses = EntityUtil.filterByDate(paymentAddresses, null, "purposeFromDate", "purposeThruDate", true); + purpose = EntityQuery.use(delegator).from("PartyContactWithPurpose") + .where("partyId", partyId, "contactMechPurposeTypeId", "PAYMENT_LOCATION") + .orderBy("-purposeFromDate").filterByDate("contactFromDate", "contactThruDate", "purposeFromDate", "purposeThruDate") + .queryFirst(); } catch (GenericEntityException e) { Debug.logError(e, "Trouble getting PartyContactWithPurpose view entity list", module); } // get the address for the primary contact mech - GenericValue purpose = EntityUtil.getFirst(paymentAddresses); GenericValue postalAddress = null; if (purpose != null) { try { - postalAddress = delegator.findOne("PostalAddress", UtilMisc.toMap("contactMechId", purpose.getString("contactMechId")), false); + postalAddress = EntityQuery.use(delegator).from("PostalAddress").where("contactMechId", purpose.getString("contactMechId")).queryOne(); } catch (GenericEntityException e) { Debug.logError(e, "Trouble getting PostalAddress record for contactMechId: " + purpose.getString("contactMechId"), module); } @@ -217,7 +216,7 @@ public class PaymentWorker { GenericValue payment = null; try { - payment = delegator.findOne("Payment", UtilMisc.toMap("paymentId", paymentId), false); + payment = EntityQuery.use(delegator).from("Payment").where("paymentId", paymentId).queryOne(); } catch (GenericEntityException e) { Debug.logError(e, "Problem getting Payment", module); } @@ -237,7 +236,7 @@ public class PaymentWorker { GenericValue paymentApplication = null; BigDecimal appliedAmount = BigDecimal.ZERO; try { - paymentApplication = delegator.findOne("PaymentApplication", UtilMisc.toMap("paymentApplicationId", paymentApplicationId), false); + paymentApplication = EntityQuery.use(delegator).from("PaymentApplication").where("paymentApplicationId", paymentApplicationId).queryOne(); appliedAmount = paymentApplication.getBigDecimal("amountApplied"); if (paymentApplication.get("paymentId") != null) { GenericValue payment = paymentApplication.getRelatedOne("Payment", false); @@ -323,7 +322,7 @@ public class PaymentWorker { GenericValue payment = null; try { - payment = delegator.findOne("Payment", UtilMisc.toMap("paymentId", paymentId), false); + payment = EntityQuery.use(delegator).from("Payment").where("paymentId", paymentId).queryOne(); } catch (GenericEntityException e) { Debug.logError(e, "Problem getting Payment", module); }