Author: jpepin Date: 2010-06-02 17:33:55 +0200 (Wed, 02 Jun 2010) New Revision: 2927 Url: http://chorem.org/repositories/revision/lima/2927 Log: Nettoyage du code dans business. Modification du dao account pour cr?\195?\169er une req?\195?\187ete qui liste les comptes "feuilles". Added: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountComparator.java Removed: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountComparator.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FilesServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java trunk/lima-business/src/main/resources/lima.properties trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java trunk/lima-swing/src/main/resources/lima-config.properties Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2010-06-02 13:17:06 UTC (rev 2926) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2010-06-02 15:33:55 UTC (rev 2927) @@ -32,7 +32,7 @@ import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; -import org.chorem.lima.entity.AccountComparator; +import org.chorem.lima.business.utils.AccountComparator; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountDAO; import org.chorem.lima.entity.LimaCallaoDAOHelper; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2010-06-02 13:17:06 UTC (rev 2926) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2010-06-02 15:33:55 UTC (rev 2927) @@ -141,8 +141,6 @@ LimaCallaoDAOHelper.getEntryBookDAO(transaction); List<EntryBook> EntryBooks = EntryBookDAO.findAll(); EntryBooksList.addAll(EntryBooks); - - commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FilesServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FilesServiceImpl.java 2010-06-02 13:17:06 UTC (rev 2926) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FilesServiceImpl.java 2010-06-02 15:33:55 UTC (rev 2927) @@ -20,9 +20,6 @@ package org.chorem.lima.business.ejb; import java.util.List; - -import javax.ejb.EJB; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.entity.Account; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2010-06-02 13:17:06 UTC (rev 2926) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2010-06-02 15:33:55 UTC (rev 2927) @@ -112,10 +112,7 @@ EntryBookDAO entryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); //create all financial period - log.debug(financialPeriods); for (FinancialPeriod financialPeriod : financialPeriods) { - log.debug(financialPeriod); - //create ClosedPeriodicEntryBook for all entrybook for (EntryBook entryBook : entryBookDAO.findAll()) { //new closed periodic entrybook @@ -153,8 +150,6 @@ FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper. getFinancialPeriodDAO(transaction); result = financialPeriodDAO.findAllByLocked(false); - - commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -254,9 +249,7 @@ query.addLoad(loadFinancialPeriodProperty); //call query - result = closedPeriodicEntryBookDAO.findAllByQuery(query); - - commitTransaction(transaction); + result = closedPeriodicEntryBookDAO.findAllByQuery(query); } catch (TopiaException ex) { doCatch(transaction, ex, log); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2010-06-02 13:17:06 UTC (rev 2926) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2010-06-02 15:33:55 UTC (rev 2927) @@ -138,7 +138,7 @@ if (financialPeriod != null) { query.addEquals("financialPeriod", financialPeriod); } - + query.addOrder(FinancialTransaction.TOPIA_CREATE_DATE); financialTransactions = transactionDAO.findAllByQuery(query); //IMPORTANT : LOADING ENTRIES AND IS COLUMN FOR NO LAZY EXCEPTION Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2010-06-02 13:17:06 UTC (rev 2926) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2010-06-02 15:33:55 UTC (rev 2927) @@ -88,7 +88,6 @@ //check rules before create the account List<FinancialPeriod> financialPeriods = accountingRules.createFiscalPeriodRules(fiscalPeriod, transaction); - log.debug("financialPeriods : "+financialPeriods); financialPeriodService. createFinancialPeriodsWithTransaction(financialPeriods, transaction); @@ -122,9 +121,7 @@ FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); - result = fiscalPeriodDAO.findAll(); - - commitTransaction(transaction); + result = fiscalPeriodDAO.findAll(); } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -150,17 +147,6 @@ FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); result = fiscalPeriodDAO.findAllByLocked(false); - - //IMPORTANT : LOADING FINANCIAL PERIOD FOR NO LAZY EXCEPTION - for (FiscalPeriod fiscalPeriod : result) { - //FIXME besoin d'appeler une lecture bidon de toutes les financialperiod - //TODO make this by topiaquery ? - //sinon il pete tout de même une lazy exception - for (FinancialPeriod financialPeriod : fiscalPeriod.getFinancialPeriod()) { - } - } - - commitTransaction(transaction); } catch (TopiaException ex) { doCatch(transaction, ex, log); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2010-06-02 13:17:06 UTC (rev 2926) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2010-06-02 15:33:55 UTC (rev 2927) @@ -197,7 +197,7 @@ reportsDatas.setAmountDebit(debit); reportsDatas.setAmountSolde(solde); - commitTransaction(topiaContext); + //commitTransaction(topiaContext); } catch (TopiaException ex) { doCatch(topiaContext, ex, log); @@ -250,7 +250,7 @@ reportsDatas.setAmountDebit(debit); reportsDatas.setAmountSolde(solde); - commitTransaction(topiaContext); + //commitTransaction(topiaContext); } catch (TopiaException ex) { doCatch(topiaContext, ex, log); @@ -286,10 +286,6 @@ .addWhere(transactionDateProperty+" BETWEEN :beginDate AND :endDate") .addParam("beginDate", beginDate) .addParam("endDate", endDate); - /*String orderProperty = - TopiaQuery.getProperty(Entry.FINANCIAL_TRANSACTION, - FinancialTransaction.TRANSACTION_DATE); - query.addOrder(orderProperty);*/ //IMPORTANT : LOADING ENTRIES AND IS COLUMN FOR NO LAZY EXCEPTION query.addLoad(Entry.ACCOUNT, Entry.FINANCIAL_TRANSACTION); reportsDatas.setListEntry(entryDAO.findAllByQuery(query)); @@ -322,7 +318,7 @@ reportsDatas.setAmountDebit(debit); reportsDatas.setAmountSolde(solde); - commitTransaction(topiaTransaction); + //commitTransaction(topiaTransaction); } catch (TopiaException ex) { doCatch(topiaTransaction, ex, log); @@ -353,7 +349,8 @@ AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(topiaTransaction); //for each account create a balance sheet with a ReportsDatas - for (Account account : accountDAO.findAllSubAccounts()) { + List<Account> accounts = accountDAO.findAllSubAccounts(); + for (Account account : accounts) { ReportsDatas reportsDatas = generateSubAccountBalanceWithTransaction(account, beginDate, endDate, topiaTransaction); Copied: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountComparator.java (from rev 2923, trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountComparator.java) =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountComparator.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountComparator.java 2010-06-02 15:33:55 UTC (rev 2927) @@ -0,0 +1,35 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + +package org.chorem.lima.business.utils; + +import java.util.Comparator; + +import org.chorem.lima.entity.Account; + +public class AccountComparator implements Comparator<Account>{ + + /** + * sort by accout number in lexicographical order + */ + @Override + public int compare(Account o1, Account o2) { + return o1.getAccountNumber().compareTo(o2.getAccountNumber()); + } + +} Modified: trunk/lima-business/src/main/resources/lima.properties =================================================================== --- trunk/lima-business/src/main/resources/lima.properties 2010-06-02 13:17:06 UTC (rev 2926) +++ trunk/lima-business/src/main/resources/lima.properties 2010-06-02 15:33:55 UTC (rev 2927) @@ -1,6 +1,6 @@ # Proprietes par defaut pour une base de donnees de type H2 hibernate.hbm2ddl.auto=update -hibernate.show_sql=false +#hibernate.show_sql=true hibernate.dialect=org.hibernate.dialect.H2Dialect hibernate.connection.username=sa @@ -8,4 +8,4 @@ hibernate.connection.driver_class=org.h2.Driver hibernate.connection.url=jdbc:h2:file:~/.lima/limadb -lima.rules=org.chorem.lima.business.accountingrules.FranceAccountingRules \ No newline at end of file +lima.rules=org.chorem.lima.business.accountingrules.FranceAccountingRules Deleted: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountComparator.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountComparator.java 2010-06-02 13:17:06 UTC (rev 2926) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountComparator.java 2010-06-02 15:33:55 UTC (rev 2927) @@ -1,35 +0,0 @@ -/* *##% Lima Swing - * Copyright (C) 2008 - 2010 CodeLutin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * ##%*/ - -package org.chorem.lima.entity; - -import java.util.Comparator; - -import org.chorem.lima.entity.Account; - -public class AccountComparator implements Comparator<Account>{ - - /** - * sort by accout number in lexicographical order - */ - @Override - public int compare(Account o1, Account o2) { - return o1.getAccountNumber().compareTo(o2.getAccountNumber()); - } - -} Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java 2010-06-02 13:17:06 UTC (rev 2926) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAOImpl.java 2010-06-02 15:33:55 UTC (rev 2927) @@ -1,10 +1,10 @@ package org.chorem.lima.entity; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaQuery; public class AccountDAOImpl <E extends Account> extends AccountDAOAbstract<E> { @@ -15,18 +15,21 @@ @Override public List<Account> findAllSubAccounts() throws TopiaException { List<Account> accountsList = new ArrayList<Account>(); - - //FIXME use topia query - List<Account> accounts = (List<Account>) findAll(); - for (Account account : accounts) { - //check if parentaccount have no subaccount and no subledgers - if (account.getSubAccounts().size() == 0 - && account.getSubLedgers().size() == 0){ - accountsList.add(account); - } - } - Collections.sort(accountsList, new AccountComparator()); - return accountsList; + TopiaQuery query = createQuery(); + String subAccountsProperty = TopiaQuery.getProperty(Account.SUB_ACCOUNTS); + String subLedgersProperty = TopiaQuery.getProperty(Account.SUB_LEDGERS); + query.addWhere("not exists elements ("+subAccountsProperty+")") + .addWhere("not exists elements ("+subLedgersProperty+")") + .addOrder(Account.ACCOUNT_NUMBER); + + /* alternative query + * wich are the best ? exist or count ? + * + * query.addWhere("size ("+subAccountsProperty+") = 0") + * .addWhere("size ("+subLedgersProperty+") = 0"); + * + */ + return (List<Account>) findAllByQuery(query); } } Modified: trunk/lima-swing/src/main/resources/lima-config.properties =================================================================== --- trunk/lima-swing/src/main/resources/lima-config.properties 2010-06-02 13:17:06 UTC (rev 2926) +++ trunk/lima-swing/src/main/resources/lima-config.properties 2010-06-02 15:33:55 UTC (rev 2927) @@ -23,4 +23,4 @@ #java.naming.factory.initial=org.apache.openejb.client.RemoteInitialContextFactory #java.naming.provider.url=ejbd://127.0.0.1:4201 #java.naming.security.principal=jonathan -#java.naming.security.credentials=secret \ No newline at end of file +#java.naming.security.credentials=secret