r2866 - in trunk: lima-business/src/main/java/org/chorem/lima/business lima-business/src/main/java/org/chorem/lima/business/ejb lima-swing/src/main/java/org/chorem/lima/ui/account lima-swing/src/main/java/org/chorem/lima/ui/account/model lima-swing/src/main/resources/i18n
Author: jpepin Date: 2010-04-19 17:15:40 +0200 (Mon, 19 Apr 2010) New Revision: 2866 Log: Ajout m?\195?\169thode de suppression r?\195?\169cursive des sous-comptes contenus dans un compte 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 trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/model/AccountTreeTableModel.java trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 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-04-19 13:19:30 UTC (rev 2865) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java 2010-04-19 15:15:40 UTC (rev 2866) @@ -50,8 +50,10 @@ void updateAccount(Account account) throws LimaException; - void removeAccount(Account account) throws LimaException; + int removeAccount(Account account) throws LimaException; + void removeAccountwithSubAccounts(Account account) throws LimaException; + Account getAccountNumber(String numAccount) throws LimaException; List<Account> getChildrenAccounts(Account masterAccount) throws LimaException; 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-04-19 13:19:30 UTC (rev 2865) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2010-04-19 15:15:40 UTC (rev 2866) @@ -23,7 +23,10 @@ import java.util.ArrayList; import java.util.List; +import java.util.ListIterator; +import javassist.bytecode.Descriptor.Iterator; + import javax.ejb.Stateless; import org.apache.commons.collections.CollectionUtils; @@ -124,12 +127,25 @@ transaction = rootContext.beginTransaction(); // test si le numero de compte existe deja - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); - List<Account> existingAccounts = + + + + + AccountDAO accountDAO = + LimaCallaoDAOHelper.getAccountDAO(transaction); + + + + /* Suggestion Florian qui marche pas + * List<Account> existingAccounts = accountDAO.findAllByAccountNumber(account.getAccountNumber()); - if (CollectionUtils.isNotEmpty(existingAccounts)) { + if (CollectionUtils.isNotEmpty(existingAccounts))*/ + + Account existAccount = accountDAO.findByAccountNumber(account.getAccountNumber()); + if (existAccount != null) { throw new LimaBusinessException(_( - "An account already exists with this number : %s", account.getAccountNumber())); + "An account already exists with this number : %s", + account.getAccountNumber())); } accountDAO.create(account); @@ -179,8 +195,9 @@ } //test si le parent ne contient pas de subaccount - List<Account> existingSubAccounts = masterAccount.getSubAccounts(); - if (CollectionUtils.isNotEmpty(existingSubAccounts)){ + if (masterAccount.getSubAccounts().size() > 0) + /*List<Account> existingSubAccounts = masterAccount.getSubAccounts(); + if (CollectionUtils.isNotEmpty(existingSubAccounts))*/{ throw new LimaBusinessException( "Subledger must create on a account whithout subaccount : "); @@ -479,7 +496,8 @@ try { transaction = rootContext.beginTransaction(); - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); + AccountDAO accountDAO = + LimaCallaoDAOHelper.getAccountDAO(transaction); List<Account> accounts = accountDAO.findAll(); accountsList.addAll(accounts); } @@ -535,7 +553,8 @@ try { transaction = rootContext.beginTransaction(); - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); + AccountDAO accountDAO = + LimaCallaoDAOHelper.getAccountDAO(transaction); TopiaQuery query = accountDAO.createQuery(); @@ -544,7 +563,8 @@ query.add("generalLedger", TopiaQuery.Op.EQ, null); } else { - query.add("masterAccount = :value or generalLedger = :value").addParam("value", masterAccount); + query.add("masterAccount = :value or generalLedger = :value") + .addParam("value", masterAccount); } // TODO Erreur Lazy TopiaQuery /*if (log.isDebugEnabled()) { @@ -587,11 +607,12 @@ * ATTENTION : si il existe une entrée comptable associée au numéro de * compte, il est alors impossible de supprimer le compte. * + * Si un compte contient des sous comptes la fonction retourne -1 * @param account * @throws LimaException */ @Override - public void removeAccount(Account account) throws LimaException { + public int removeAccount(Account account) throws LimaException { /*String result = ServiceHelper.RESPOND_ERROR; Account deleteAccount = searchAccount(accountNumber); // Si le compte n'existe pas @@ -667,12 +688,12 @@ } } return result;*/ - + int result = 0; TopiaContext transaction = null; try { transaction = rootContext.beginTransaction(); - // Vérifie si une entrée ne possède pas ce numéro de compte. + //Check if an account has not his number // FIXME !IMPORTANT! check that subaccounts have no entries too EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(transaction); Entry firstEntry = entryDAO.findByAccount(account); @@ -681,12 +702,19 @@ throw new LimaBusinessException("Can't delete account with entries"); } + //Check if the account is not empty, return -1 + List<Account> existingSubAccounts = getChildrenAccounts(account); + if (CollectionUtils.isNotEmpty(existingSubAccounts)){ + result =-1; + } + else { // remove account - // FIXME !IMPORTANT! check that subaccounts are also deleted - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); + AccountDAO accountDAO = + LimaCallaoDAOHelper.getAccountDAO(transaction); accountDAO.delete(account); // commit transaction.commitTransaction(); + } } catch (TopiaException ex) { doCatch(transaction, ex, log); @@ -694,7 +722,38 @@ finally { doFinally(transaction, log); } + return result; } + + /** + * Delete an account and all his subaccounts + * @param account + * @throws LimaException + */ + public void removeAccountwithSubAccounts(Account account) throws LimaException{ + TopiaContext transaction = null; + try{ + transaction = rootContext.beginTransaction(); + AccountDAO accountDAO = + LimaCallaoDAOHelper.getAccountDAO(transaction); + List<Account> existingSubAccounts = getChildrenAccounts(account); + ListIterator itr = existingSubAccounts.listIterator(); + while(itr.hasNext()){ + Account subaccount = (Account) itr.next(); + removeAccountwithSubAccounts(subaccount); + } + // remove account + accountDAO.delete(account); + // commit + transaction.commitTransaction(); + } + catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } + } /* * Permet d'effacer un compte à partir d'un compte DTO. Il appelle la @@ -767,38 +826,18 @@ transaction = rootContext.beginTransaction(); // update account - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); + AccountDAO accountDAO = + LimaCallaoDAOHelper.getAccountDAO(transaction); accountDAO.update(account); // commit 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 update account", ex); } - 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 update account", ex); - } - } - } } @Override @@ -809,36 +848,16 @@ transaction = rootContext.beginTransaction(); // get account from his number - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(transaction); + AccountDAO accountDAO = + LimaCallaoDAOHelper.getAccountDAO(transaction); account = accountDAO.findByAccountNumber(numAccount); } 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 get account from his number", ex); } throw new LimaException("Can't get account from his number", ex); } - 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 get account from his number", ex); - } - } - } return account; } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2010-04-19 13:19:30 UTC (rev 2865) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2010-04-19 15:15:40 UTC (rev 2866) @@ -201,7 +201,25 @@ TreePath treePath = view.getAccountsTreeTable().getPathForRow(selectedRow); Account account = (Account) treePath.getLastPathComponent(); try { - accountsTreeTableModel.removeAccount(treePath, account); + int result = accountsTreeTableModel.removeAccount(treePath, account); + if (result ==-1){ + int n2 = JOptionPane.showConfirmDialog(view, + _("lima.question.confirmremove.account"), + _("lima.question"), + JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE); + if (n2 == JOptionPane.YES_OPTION) { + // update view of treetable + try { + accountsTreeTableModel.removeAccountwithSubAccounts(treePath, account); + } catch (LimaException ex) { + if (log.isErrorEnabled()) { + log.error("Can't delete account", ex); + } + ErrorHelper.showErrorDialog("Can't delete account", ex); + } + } + } } catch (LimaException ex) { if (log.isErrorEnabled()) { log.error("Can't delete account", ex); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/model/AccountTreeTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/model/AccountTreeTableModel.java 2010-04-19 13:19:30 UTC (rev 2865) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/model/AccountTreeTableModel.java 2010-04-19 15:15:40 UTC (rev 2866) @@ -253,11 +253,21 @@ * @param account * @throws LimaException */ - public void removeAccount(TreePath path, Account account) throws LimaException { + public int removeAccount(TreePath path, Account account) throws LimaException { // Calling account service int index = getIndexOfChild( path.getParentPath().getLastPathComponent(), account); - accountService.removeAccount(account); + int result = accountService.removeAccount(account); + if (result==0){ + modelSupport.fireChildRemoved(path.getParentPath(), index, account); + } + return result; + } + + public void removeAccountwithSubAccounts(TreePath path, Account account) throws LimaException { + int index = getIndexOfChild( + path.getParentPath().getLastPathComponent(), account); + accountService.removeAccountwithSubAccounts(account); modelSupport.fireChildRemoved(path.getParentPath(), index, account); } } Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties 2010-04-19 13:19:30 UTC (rev 2865) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties 2010-04-19 15:15:40 UTC (rev 2866) @@ -235,6 +235,7 @@ lima.question=Question lima.question.load.accounts=There is no existing accounts in Lima. Do you want to load default accounts ? lima.question.remove.account=Do you want to remove this account ? +lima.question.confirmremove.account=This account have subaccounts, do you want remove this account ? lima.question.remove.entry=Do you want to remove this entry ? lima.question.remove.journal=Do you want to remove this journal ? lima.question.remove.transaction=Do you want to remove this transaction ? Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-04-19 13:19:30 UTC (rev 2865) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-04-19 15:15:40 UTC (rev 2866) @@ -228,6 +228,7 @@ lima.question=Question lima.question.load.accounts=Il n'y a aucun plan comptable existant dans Lima. Voulez-vous en charger un par d\u00E9faut ? lima.question.remove.account=Voulez-vous supprimer ce compte? +lima.question.confirmremove.account=Ce compte poss\u00E8de des sous comptes, voulez-vous supprimer ce compte ? lima.question.remove.entry=Voulez-vous supprimer cette ligne de transaction? lima.question.remove.journal=Voulez-vous supprimer ce journal? lima.question.remove.transaction=Voulez-vous supprimer cette transaction?
participants (1)
-
jpepin@users.chorem.org