lekt...@apache.org wrote: > Author: lektran > Date: Sun Apr 18 00:16:52 2010 > New Revision: 935278 > > URL: http://svn.apache.org/viewvc?rev=935278&view=rev > Log: > A few examples of using groovy's first() list method instead of > EntityUtil.getFirst(List) > > Modified: > > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/EditInvoice.groovy > > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/OrderListInvoiceItem.groovy > > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/order/BillingAccountOrders.groovy > > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/payment/BillingAccounts.groovy > > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/GlAccountTrialBalance.groovy > > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/TransactionTotals.groovy > > Modified: > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/EditInvoice.groovy > URL: > http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/EditInvoice.groovy?rev=935278&r1=935277&r2=935278&view=diff > ============================================================================== > --- > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/EditInvoice.groovy > (original) > +++ > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/EditInvoice.groovy > Sun Apr 18 00:16:52 2010 > @@ -77,7 +77,8 @@ if (invoice) { > // also create a map with tax grand total amount by VAT tax: it is > also required in invoices by UE > taxRate = invoiceItem.getRelatedOne("TaxAuthorityRateProduct"); > if (taxRate && "VAT_TAX".equals(taxRate.taxAuthorityRateTypeId)) { > - taxInfo = > EntityUtil.getFirst(EntityUtil.filterByDate(delegator.findByAnd("PartyTaxAuthInfo", > UtilMisc.toMap("partyId", billingParty.partyId, "taxAuthGeoId", > taxRate.taxAuthGeoId, "taxAuthPartyId", taxRate.taxAuthPartyId)), > invoice.invoiceDate)); > + taxInfos = > EntityUtil.filterByDate(delegator.findByAnd("PartyTaxAuthInfo", [partyId : > billingParty.partyId, taxAuthGeoId : taxRate.taxAuthGeoId, taxAuthPartyId : > taxRate.taxAuthPartyId]), invoice.invoiceDate); > + taxInfo = taxInfos.first(); > if (taxInfo) { > context.billingPartyTaxId = taxInfo.partyTaxId; > }
Why the split into multiple lines? None of the other changes do this. > > Modified: > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/OrderListInvoiceItem.groovy > URL: > http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/OrderListInvoiceItem.groovy?rev=935278&r1=935277&r2=935278&view=diff > ============================================================================== > --- > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/OrderListInvoiceItem.groovy > (original) > +++ > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/invoice/OrderListInvoiceItem.groovy > Sun Apr 18 00:16:52 2010 > @@ -32,7 +32,7 @@ if (invoiceItemList) { > invoiceItemList.each { invoiceItem -> > invoiceItemSeqId = invoiceItem.invoiceItemSeqId; > invoiceId = invoiceItem.invoiceId; > - orderItemBilling = > EntityUtil.getFirst(delegator.findByAnd("OrderItemBilling", [invoiceId : > invoiceId, invoiceItemSeqId : invoiceItemSeqId])); > + orderItemBilling = delegator.findByAnd("OrderItemBilling", > [invoiceId : invoiceId, invoiceItemSeqId : invoiceItemSeqId]).first(); > Map invoiceItemMap = FastMap.newInstance(); > invoiceItemMap.putAll((Map) invoiceItem); > if (orderItemBilling) { > > Modified: > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/order/BillingAccountOrders.groovy > URL: > http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/order/BillingAccountOrders.groovy?rev=935278&r1=935277&r2=935278&view=diff > ============================================================================== > --- > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/order/BillingAccountOrders.groovy > (original) > +++ > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/order/BillingAccountOrders.groovy > Sun Apr 18 00:16:52 2010 > @@ -27,7 +27,7 @@ if (billingAccountId) { > if (orderList) { > orderList.each { orderHeader -> > orderId = orderHeader.orderId; > - orderBillingAcc = > EntityUtil.getFirst(delegator.findByAnd("OrderHeaderAndPaymentPref", [orderId > : orderId])); > + orderBillingAcc = > delegator.findByAnd("OrderHeaderAndPaymentPref", [orderId : orderId]).first(); > orderBillingAccMap = FastMap.newInstance(); > if (orderBillingAcc.paymentMethodTypeId.equals("EXT_BILLACT") && > orderBillingAcc.paymentStatusId.equals("PAYMENT_NOT_RECEIVED")) { > orderBillingAccMap.putAll(orderBillingAcc); > > Modified: > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/payment/BillingAccounts.groovy > URL: > http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/payment/BillingAccounts.groovy?rev=935278&r1=935277&r2=935278&view=diff > ============================================================================== > --- > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/payment/BillingAccounts.groovy > (original) > +++ > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/payment/BillingAccounts.groovy > Sun Apr 18 00:16:52 2010 > @@ -25,7 +25,7 @@ currencyUomId = null; > billingAccounts = []; > if (partyId) { > billingAccountAndRoles = delegator.findByAnd("BillingAccountAndRole", > [partyId : partyId]); > - if (billingAccountAndRoles) currencyUomId = > EntityUtil.getFirst(billingAccountAndRoles).accountCurrencyUomId; > + if (billingAccountAndRoles) currencyUomId = > billingAccountAndRoles.first().accountCurrencyUomId; > if (currencyUomId) billingAccounts = > BillingAccountWorker.makePartyBillingAccountList(userLogin, currencyUomId, > partyId, delegator, dispatcher); > } > context.billingAccounts = billingAccounts; > \ No newline at end of file > > Modified: > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/GlAccountTrialBalance.groovy > URL: > http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/GlAccountTrialBalance.groovy?rev=935278&r1=935277&r2=935278&view=diff > ============================================================================== > --- > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/GlAccountTrialBalance.groovy > (original) > +++ > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/GlAccountTrialBalance.groovy > Sun Apr 18 00:16:52 2010 > @@ -32,7 +32,7 @@ if (organizationPartyId) { > customTimePeriodResults = dispatcher.runSync("findCustomTimePeriods", > [findDate : UtilDateTime.nowTimestamp(), organizationPartyId : > organizationPartyId, onlyIncludePeriodTypeIdList : > onlyIncludePeriodTypeIdList, userLogin : userLogin]); > customTimePeriodList = customTimePeriodResults.customTimePeriodList; > if (UtilValidate.isNotEmpty(customTimePeriodList)) { > - context.timePeriod = > (EntityUtil.getFirst(customTimePeriodList)).customTimePeriodId; > + context.timePeriod = customTimePeriodList.first().customTimePeriodId; > } > decimals = UtilNumber.getBigDecimalScale("ledger.decimals"); > rounding = UtilNumber.getBigDecimalRoundingMode("ledger.rounding"); > > Modified: > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/TransactionTotals.groovy > URL: > http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/TransactionTotals.groovy?rev=935278&r1=935277&r2=935278&view=diff > ============================================================================== > --- > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/TransactionTotals.groovy > (original) > +++ > ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/TransactionTotals.groovy > Sun Apr 18 00:16:52 2010 > @@ -76,7 +76,7 @@ if (postedTransactionTotals) { > > timePeriodAndExprs.add(EntityCondition.makeCondition("organizationPartyId", > EntityOperator.EQUALS, organizationPartyId)); > > timePeriodAndExprs.add(EntityCondition.makeCondition("glAccountId", > EntityOperator.EQUALS, postedTransactionTotal.glAccountId)); > > timePeriodAndExprs.add(EntityCondition.makeCondition("customTimePeriodId", > EntityOperator.EQUALS, lastClosedTimePeriod.customTimePeriodId)); > - lastTimePeriodHistory = > EntityUtil.getFirst(delegator.findList("GlAccountAndHistory", > EntityCondition.makeCondition(timePeriodAndExprs, EntityOperator.AND), null, > null, null, false)); > + lastTimePeriodHistory = > delegator.findList("GlAccountAndHistory", > EntityCondition.makeCondition(timePeriodAndExprs, EntityOperator.AND), null, > null, null, false).first(); > if (lastTimePeriodHistory) { > accountMap = UtilMisc.toMap("glAccountId", > lastTimePeriodHistory.glAccountId, "accountCode", > lastTimePeriodHistory.accountCode, "accountName", > lastTimePeriodHistory.accountName, "balance", > lastTimePeriodHistory.getBigDecimal("endingBalance"), "openingD", > lastTimePeriodHistory.getBigDecimal("postedDebits"), "openingC", > lastTimePeriodHistory.getBigDecimal("postedCredits"), "D", BigDecimal.ZERO, > "C", BigDecimal.ZERO); > } > @@ -121,7 +121,7 @@ andExprs.add(EntityCondition.makeConditi > andCond = EntityCondition.makeCondition(andExprs, EntityOperator.AND); > List postedDebitTransactionTotals = > delegator.findList("AcctgTransEntrySums", andCond, UtilMisc.toSet("amount"), > null, null, false); > if (postedDebitTransactionTotals) { > - postedDebitTransactionTotal = > EntityUtil.getFirst(postedDebitTransactionTotals); > + postedDebitTransactionTotal = postedDebitTransactionTotals.first(); > if (postedDebitTransactionTotal && postedDebitTransactionTotal.amount) { > postedTotalDebit = postedDebitTransactionTotal.amount; > } > @@ -137,7 +137,7 @@ andExprs.add(EntityCondition.makeConditi > andCond = EntityCondition.makeCondition(andExprs, EntityOperator.AND); > List postedCreditTransactionTotals = > delegator.findList("AcctgTransEntrySums", andCond, UtilMisc.toSet("amount"), > null, null, false); > if (postedCreditTransactionTotals) { > - postedCreditTransactionTotal = > EntityUtil.getFirst(postedCreditTransactionTotals); > + postedCreditTransactionTotal = postedCreditTransactionTotals.first(); > if (postedCreditTransactionTotal && postedCreditTransactionTotal.amount) > { > postedTotalCredit = postedCreditTransactionTotal.amount; > } > @@ -173,7 +173,7 @@ if (unpostedTransactionTotals) { > > timePeriodAndExprs.add(EntityCondition.makeCondition("organizationPartyId", > EntityOperator.EQUALS, organizationPartyId)); > > timePeriodAndExprs.add(EntityCondition.makeCondition("glAccountId", > EntityOperator.EQUALS, unpostedTransactionTotal.glAccountId)); > > timePeriodAndExprs.add(EntityCondition.makeCondition("customTimePeriodId", > EntityOperator.EQUALS, lastClosedTimePeriod.customTimePeriodId)); > - lastTimePeriodHistory = > EntityUtil.getFirst(delegator.findList("GlAccountAndHistory", > EntityCondition.makeCondition(timePeriodAndExprs, EntityOperator.AND), null, > null, null, false)); > + lastTimePeriodHistory = > delegator.findList("GlAccountAndHistory", > EntityCondition.makeCondition(timePeriodAndExprs, EntityOperator.AND), null, > null, null, false).first(); > if (lastTimePeriodHistory) { > accountMap = UtilMisc.toMap("glAccountId", > lastTimePeriodHistory.glAccountId, "accountCode", > lastTimePeriodHistory.accountCode, "accountName", > lastTimePeriodHistory.accountName, "balance", > lastTimePeriodHistory.getBigDecimal("endingBalance"), "openingD", > lastTimePeriodHistory.getBigDecimal("postedDebits"), "openingC", > lastTimePeriodHistory.getBigDecimal("postedCredits"), "D", BigDecimal.ZERO, > "C", BigDecimal.ZERO); > } > @@ -218,7 +218,7 @@ andExprs.add(EntityCondition.makeConditi > andCond = EntityCondition.makeCondition(andExprs, EntityOperator.AND); > List unpostedDebitTransactionTotals = > delegator.findList("AcctgTransEntrySums", andCond, UtilMisc.toSet("amount"), > null, null, false); > if (unpostedDebitTransactionTotals) { > - unpostedDebitTransactionTotal = > EntityUtil.getFirst(unpostedDebitTransactionTotals); > + unpostedDebitTransactionTotal = unpostedDebitTransactionTotals.first(); > if (unpostedDebitTransactionTotal && > unpostedDebitTransactionTotal.amount) { > unpostedTotalDebit = unpostedDebitTransactionTotal.amount; > } > @@ -234,7 +234,7 @@ andExprs.add(EntityCondition.makeConditi > andCond = EntityCondition.makeCondition(andExprs, EntityOperator.AND); > List unpostedCreditTransactionTotals = > delegator.findList("AcctgTransEntrySums", andCond, UtilMisc.toSet("amount"), > null, null, false); > if (unpostedCreditTransactionTotals) { > - unpostedCreditTransactionTotal = > EntityUtil.getFirst(unpostedCreditTransactionTotals); > + unpostedCreditTransactionTotal = unpostedCreditTransactionTotals.first(); > if (unpostedCreditTransactionTotal && > unpostedCreditTransactionTotal.amount) { > unpostedTotalCredit = unpostedCreditTransactionTotal.amount; > } > @@ -269,7 +269,7 @@ if (allTransactionTotals) { > > timePeriodAndExprs.add(EntityCondition.makeCondition("organizationPartyId", > EntityOperator.EQUALS, organizationPartyId)); > > timePeriodAndExprs.add(EntityCondition.makeCondition("glAccountId", > EntityOperator.EQUALS, allTransactionTotal.glAccountId)); > > timePeriodAndExprs.add(EntityCondition.makeCondition("customTimePeriodId", > EntityOperator.EQUALS, lastClosedTimePeriod.customTimePeriodId)); > - lastTimePeriodHistory = > EntityUtil.getFirst(delegator.findList("GlAccountAndHistory", > EntityCondition.makeCondition(timePeriodAndExprs, EntityOperator.AND), null, > null, null, false)); > + lastTimePeriodHistory = > delegator.findList("GlAccountAndHistory", > EntityCondition.makeCondition(timePeriodAndExprs, EntityOperator.AND), null, > null, null, false).first(); > if (lastTimePeriodHistory) { > accountMap = UtilMisc.toMap("glAccountId", > lastTimePeriodHistory.glAccountId, "accountCode", > lastTimePeriodHistory.accountCode, "accountName", > lastTimePeriodHistory.accountName, "balance", > lastTimePeriodHistory.getBigDecimal("endingBalance"), "openingD", > lastTimePeriodHistory.getBigDecimal("postedDebits"), "openingC", > lastTimePeriodHistory.getBigDecimal("postedCredits"), "D", BigDecimal.ZERO, > "C", BigDecimal.ZERO); > } > @@ -313,7 +313,7 @@ andExprs.add(EntityCondition.makeConditi > andCond = EntityCondition.makeCondition(andExprs, EntityOperator.AND); > List allDebitTransactionTotals = delegator.findList("AcctgTransEntrySums", > andCond, UtilMisc.toSet("amount"), null, null, false); > if (allDebitTransactionTotals) { > - allDebitTransactionTotal = > EntityUtil.getFirst(allDebitTransactionTotals); > + allDebitTransactionTotal = allDebitTransactionTotals.first(); > if (allDebitTransactionTotal && allDebitTransactionTotal.amount) { > allTotalDebit = allDebitTransactionTotal.amount; > } > @@ -328,7 +328,7 @@ andExprs.add(EntityCondition.makeConditi > andCond = EntityCondition.makeCondition(andExprs, EntityOperator.AND); > List allCreditTransactionTotals = delegator.findList("AcctgTransEntrySums", > andCond, UtilMisc.toSet("amount"), null, null, false); > if (allCreditTransactionTotals) { > - allCreditTransactionTotal = > EntityUtil.getFirst(allCreditTransactionTotals); > + allCreditTransactionTotal = allCreditTransactionTotals.first(); > if (allCreditTransactionTotal && allCreditTransactionTotal.amount) { > allTotalCredit = allCreditTransactionTotal.amount; > } > >