@@ -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