r2815 - in trunk/lima-business/src/main/java/org/chorem/lima/business: . ejb
Author: echatellier Date: 2010-03-26 12:36:00 +0100 (Fri, 26 Mar 2010) New Revision: 2815 Log: Am?\195?\169lioration du service pour recuperer seulement les fils d'un compte en particulier. Added: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AbstractLimaService.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java 2010-03-25 13:40:03 UTC (rev 2814) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java 2010-03-26 11:36:00 UTC (rev 2815) @@ -48,4 +48,6 @@ void updateAccount(Account account) throws LimaException; void removeAccount(Account account) throws LimaException; + + List<Account> getChildrenAccounts(Account masterAccount) throws LimaException; } Added: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AbstractLimaService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AbstractLimaService.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AbstractLimaService.java 2010-03-26 11:36:00 UTC (rev 2815) @@ -0,0 +1,79 @@ +/* *##% + * Copyright (C) 2010 Code Lutin, Chatellier Eric + * + * 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.ejb; + +import org.apache.commons.logging.Log; +import org.chorem.lima.business.LimaException; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; + +/** + * TODO add comment here. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public abstract class AbstractLimaService { + + /** + * Generic code used to rollback a transaction. + * + * TODO : replace this by JTA + * + * @throws LimaException + */ + protected void doCatch(TopiaContext transaction, Exception cause, Log log) throws LimaException { + if (transaction != null) { + try { + transaction.rollbackTransaction(); + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.error("Error during rollback context", eee); + } + } + } + if (log.isErrorEnabled()) { + log.error("Error during create account", cause); + } + throw new LimaException("Exception during query", cause); + } + + /** + * Generic code used too close a transaction. + * + * @param transaction transaction to close + * @param log log (can be null) + * @throws LimaException + */ + protected void doFinally(TopiaContext transaction, Log log) throws LimaException { + if (transaction != null) { + try { + transaction.closeContext(); + } catch (TopiaException ex) { + if (log != null && log.isErrorEnabled()) { + log.error("Can't close transaction", ex); + } + throw new LimaException("Can't close transaction", ex); + } + } + } +} Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AbstractLimaService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL 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-03-25 13:40:03 UTC (rev 2814) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2010-03-26 11:36:00 UTC (rev 2815) @@ -43,6 +43,7 @@ import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.framework.TopiaQuery; /** * Permet d'implémenter le Plan Comptable Général. @@ -53,7 +54,7 @@ * @author Rémi Chapelet */ @Stateless -public class AccountServiceImpl implements AccountService { +public class AccountServiceImpl extends AbstractLimaService implements AccountService { private static final Log log = LogFactory.getLog(AccountServiceImpl.class); @@ -117,33 +118,13 @@ transaction.commitTransaction(); } catch (TopiaException ex) { - if (transaction != null) { - try { - transaction.rollbackTransaction(); - } catch (TopiaException e) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - } - } - if (log.isErrorEnabled()) { - log.error("Error during create account", ex); - } - throw new LimaException("Can't create account", ex); + doCatch(transaction, ex, log); } finally { - if (transaction != null) { - try { - transaction.closeContext(); - } catch (TopiaException ex) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - throw new LimaException("Can't create account", ex); - } - } + doFinally(transaction, log); } } + /*public String createAccount (String accountNumber, String label,Account masterAccount,String type) { String result = ServiceHelper.RESPOND_ERROR; @@ -377,8 +358,7 @@ }*/ /** - * Permet de convertir tous les comptes en DTO. Il recherche dans un premier - * temps tous les comptes "master". + * Permet de convertir tous les comptes. * * @return * @throws LimaException @@ -423,31 +403,75 @@ accountsList.addAll(accounts); } catch (TopiaException ex) { - if (transaction != null) { - try { - transaction.rollbackTransaction(); - } catch (TopiaException e) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } + + return accountsList; + } + + /** + * Permet de recuperer la liste des comptes fils d'un compte en particulier. + * + * @param masterAccount (can be null) + * @return + * @throws LimaException + */ + @Override + public List<Account> getChildrenAccounts(Account masterAccount) throws LimaException { + /*ArrayList<AccountDTO> listAccountDTO = new ArrayList<AccountDTO>(); + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + AccountDAO accountDAO = LimaCallaoDAOHelper + .getAccountDAO(topiaContext); + // Recherche des comptes enfants + List<Account> listAccount = accountDAO.findAll(); + // Pour chaque compte + // Converti entity en DTO + convertAccount.setTransaction(topiaContext); + for (Account account : listAccount) { + // Pour les comptes sans père + if (account.getMasterAccount() == null) { + AccountDTO accountDTO = convertAccount.accountEntityToDto( + account, null); + listAccountDTO.add(accountDTO); } } - if (log.isErrorEnabled()) { - log.error("Error during create account", ex); + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return listAccountDTO;*/ + + List<Account> accountsList = new ArrayList<Account>(); + + TopiaContext transaction = null; + try { + transaction = rootContext.beginTransaction(); + + AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); + + TopiaQuery query = accountDAO.createQuery(); + // masterAccount is not visible, but column "masterAccount" + // exist in Account table + query.add("masterAccount", masterAccount); + + if (log.isDebugEnabled()) { + log.debug("getChildrenAccounts query : " + query); } - throw new LimaException("Can't create account", ex); + + accountsList.addAll(accountDAO.findAllByQuery(query)); } + catch (TopiaException ex) { + doCatch(transaction, ex, log); + } finally { - if (transaction != null) { - try { - transaction.closeContext(); - } catch (TopiaException ex) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - throw new LimaException("Can't create account", ex); - } - } + doFinally(transaction, log); } return accountsList; @@ -577,31 +601,10 @@ accountDAO.delete(account); } catch (TopiaException ex) { - if (transaction != null) { - try { - transaction.rollbackTransaction(); - } catch (TopiaException e) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - } - } - if (log.isErrorEnabled()) { - log.error("Error during create account", ex); - } - throw new LimaException("Can't delete account", ex); + doCatch(transaction, ex, log); } finally { - if (transaction != null) { - try { - transaction.closeContext(); - } catch (TopiaException ex) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - throw new LimaException("Can't delete account", ex); - } - } + doFinally(transaction, log); } }
participants (1)
-
echatellier@users.chorem.org