Re: [Lima-devel] [Lima-commits] 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
@@ -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 Il veut mieux retourner une exception dans ce cas
Le 19/04/2010 17:15, jpepin@users.chorem.org a écrit : plutôt que -1 -- Éric <chatellier@codelutin.com> Tel: 02 40 50 29 28 http://www.codelutin.com
Le 19/04/2010 17:37, Eric Chatellier a écrit :
Le 19/04/2010 17:15, jpepin@users.chorem.org a écrit :
[...]
+ //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
Il veut mieux retourner une exception dans ce cas plutôt que -1
Et attention à l'indentation. Merci, Arnaud. -- Société Code Lutin http://www.codelutin.com tel : 02 40 50 29 28 fax : 09 59 92 29 28
participants (2)
-
Arnaud Thimel -
Eric Chatellier