This is an automated email from the git hooks/post-receive script. New commit to branch feature/1174-Import_EBP_Transactions in repository lima. See https://gitlab.nuiton.org/chorem/lima.git commit 7f40bc896c28d4ed8d99e60638e80c277907650b Author: David Cossé <cosse@codelutin.com> Date: Fri Jul 8 10:33:23 2016 +0200 refs #1174 ajout d'une exception pour gérer le cas ou l'on essaye de supprimer un compte qui 'existe pas --- .../chorem/lima/business/api/AccountService.java | 3 +- .../business/exceptions/UnexistingAccount.java | 35 ++++++++++++++++++++++ .../org/chorem/lima/business/AccountingRules.java | 3 +- .../accountingrules/DefaultAccountingRules.java | 6 +++- .../lima/business/ejb/AccountServiceImpl.java | 7 +++-- .../chorem/lima/ui/account/AccountViewHandler.java | 3 ++ .../resources/i18n/lima-swing_en_GB.properties | 1 + .../resources/i18n/lima-swing_fr_FR.properties | 1 + 8 files changed, 53 insertions(+), 6 deletions(-) diff --git a/lima-business-api/src/main/java/org/chorem/lima/business/api/AccountService.java b/lima-business-api/src/main/java/org/chorem/lima/business/api/AccountService.java index 5aba6f6..7686c38 100644 --- a/lima-business-api/src/main/java/org/chorem/lima/business/api/AccountService.java +++ b/lima-business-api/src/main/java/org/chorem/lima/business/api/AccountService.java @@ -27,6 +27,7 @@ import org.chorem.lima.business.exceptions.InvalidAccountNumberException; import org.chorem.lima.business.exceptions.LimaException; import org.chorem.lima.business.exceptions.NotAllowedLabelException; import org.chorem.lima.business.exceptions.NotNumberAccountNumberException; +import org.chorem.lima.business.exceptions.UnexistingAccount; import org.chorem.lima.business.exceptions.UsedAccountException; import org.chorem.lima.entity.Account; @@ -103,7 +104,7 @@ public interface AccountService { Account updateAccount(Account account) throws InvalidAccountNumberException, NotNumberAccountNumberException; - void removeAccount(Account account) throws UsedAccountException; + void removeAccount(Account account) throws UsedAccountException, UnexistingAccount; List<Account> stringToListAccounts(String selectedAccounts); diff --git a/lima-business-api/src/main/java/org/chorem/lima/business/exceptions/UnexistingAccount.java b/lima-business-api/src/main/java/org/chorem/lima/business/exceptions/UnexistingAccount.java new file mode 100644 index 0000000..010c521 --- /dev/null +++ b/lima-business-api/src/main/java/org/chorem/lima/business/exceptions/UnexistingAccount.java @@ -0,0 +1,35 @@ +package org.chorem.lima.business.exceptions; + +/* + * #%L + * Lima :: business API + * %% + * Copyright (C) 2008 - 2014 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +/** + * @author David Cossé + */ +public class UnexistingAccount extends AccountException { + + private static final long serialVersionUID = 1L; + + public UnexistingAccount(String accountNumber, String message) { + super(accountNumber, message); + } +} diff --git a/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java b/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java index a319a22..93cb419 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java +++ b/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java @@ -36,6 +36,7 @@ import org.chorem.lima.business.exceptions.NotLockedClosedPeriodicEntryBooksExce import org.chorem.lima.business.exceptions.NotNumberAccountNumberException; import org.chorem.lima.business.exceptions.UnbalancedEntriesException; import org.chorem.lima.business.exceptions.UnbalancedFinancialTransactionsException; +import org.chorem.lima.business.exceptions.UnexistingAccount; import org.chorem.lima.business.exceptions.UnfilledEntriesException; import org.chorem.lima.business.exceptions.UsedAccountException; import org.chorem.lima.business.exceptions.UsedEntryBookException; @@ -67,7 +68,7 @@ public interface AccountingRules { void updateAccountRules(Account account) throws InvalidAccountNumberException, NotNumberAccountNumberException; - void removeAccountRules(Account account) throws UsedAccountException; + void removeAccountRules(Account account) throws UsedAccountException, UnexistingAccount; /** * Entrybook rules. diff --git a/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java b/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java index 993c31b..98a9a33 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java +++ b/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java @@ -39,6 +39,7 @@ import org.chorem.lima.business.exceptions.NoEmptyFiscalPeriodException; import org.chorem.lima.business.exceptions.NotBeginNextDayOfLastFiscalPeriodException; import org.chorem.lima.business.exceptions.NotLockedClosedPeriodicEntryBooksException; import org.chorem.lima.business.exceptions.NotNumberAccountNumberException; +import org.chorem.lima.business.exceptions.UnexistingAccount; import org.chorem.lima.business.exceptions.UnbalancedEntriesException; import org.chorem.lima.business.exceptions.UnbalancedFinancialTransactionsException; import org.chorem.lima.business.exceptions.UnfilledEntriesException; @@ -175,10 +176,13 @@ public class DefaultAccountingRules implements AccountingRules { * Recursive function */ @Override - public void removeAccountRules(Account account) throws UsedAccountException { + public void removeAccountRules(Account account) throws UsedAccountException, UnexistingAccount { EntryTopiaDao entryTopiaDao = getDaoHelper().getEntryDao(); // Check if account have entries + if (!account.isPersisted()) { + throw new UnexistingAccount(account.getAccountNumber(), "Unsaved Account, this account can not be removed"); + } if (entryTopiaDao.forAccountEquals(account).exists()) { throw new UsedAccountException(account.getAccountNumber()); } diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java index 44022e7..df767a4 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java @@ -31,6 +31,7 @@ import org.chorem.lima.business.exceptions.InvalidAccountNumberException; import org.chorem.lima.business.exceptions.LimaException; import org.chorem.lima.business.exceptions.NotAllowedLabelException; import org.chorem.lima.business.exceptions.NotNumberAccountNumberException; +import org.chorem.lima.business.exceptions.UnexistingAccount; import org.chorem.lima.business.exceptions.UsedAccountException; import org.chorem.lima.business.utils.AccountComparator; import org.chorem.lima.entity.Account; @@ -187,10 +188,10 @@ public class AccountServiceImpl extends AbstractLimaService implements AccountSe * compte ou a un de ses sous-compte, il est alors impossible de supprimer le compte. * * @param account Le compte à supprimer - * @throws LimaException + * @throws UsedAccountException, UnexistingAccount */ @Override - public void removeAccount(Account account) throws UsedAccountException { + public void removeAccount(Account account) throws UsedAccountException, UnexistingAccount { AccountingRules accountingRules = LimaBusinessConfig.getInstance().getAccountingRules(); @@ -199,7 +200,7 @@ public class AccountServiceImpl extends AbstractLimaService implements AccountSe // remove account AccountTopiaDao accountDao = getDaoHelper().getAccountDao(); - Account accountToDelete = accountDao.findByTopiaId(account.getTopiaId()); + Account accountToDelete = accountDao.forTopiaIdEquals(account.getTopiaId()).findUnique(); accountDao.delete(accountToDelete); } diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java b/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java index 85f0b23..93279ec 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java @@ -32,6 +32,7 @@ import org.chorem.lima.business.api.ImportService; import org.chorem.lima.business.exceptions.AlreadyExistAccountException; import org.chorem.lima.business.exceptions.InvalidAccountNumberException; import org.chorem.lima.business.exceptions.NotNumberAccountNumberException; +import org.chorem.lima.business.exceptions.UnexistingAccount; import org.chorem.lima.business.exceptions.UsedAccountException; import org.chorem.lima.entity.Account; import org.chorem.lima.enums.AccountsChartEnum; @@ -436,6 +437,8 @@ public class AccountViewHandler implements ServiceListener { model.removeNodeFromParent(lastNode); } catch (UsedAccountException e) { errorHelper.showErrorMessage(t("lima.account.remove.error.usedAccount", e.getAccountNumber())); + } catch (UnexistingAccount unexistingAccount) { + errorHelper.showErrorMessage(t("lima.account.remove.error.unexistingAcount", unexistingAccount.getAccountNumber())); } } } diff --git a/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties b/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties index 331c21a..363fe27 100644 --- a/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties +++ b/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties @@ -11,6 +11,7 @@ lima.account.import.description=Choose an accounting plan lima.account.number=Account number lima.account.remove.confirm=Do you really want to remove %s account ? lima.account.remove.confirm.title=Delete account +lima.account.remove.error.unexistingAcount=Unexisting account %1$s, it can not be removed lima.account.remove.error.usedAccount=There are financial statement on this account lima.account.update.error.invalidAccountNumber=Invalid account number\: %1$s lima.account.update.form=Update account diff --git a/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties b/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties index 895f7b2..5d8f7dd 100644 --- a/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties +++ b/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties @@ -14,6 +14,7 @@ lima.account.label=Libellé lima.account.number=Numéro de compte lima.account.remove.confirm=Voulez-vous supprimer le compte %s ? lima.account.remove.confirm.title=Suppression d'un compte +lima.account.remove.error.unexistingAcount=Le compte %1$s n'existe pas, le compte ne peut donc pas être supprimé lima.account.remove.error.usedAccount=Il exist des transactions sur ce compte lima.account.update.error.invalidAccountNumber=Le numéro du compte %1$s n'est pas valide lima.account.update.form=Modification d'un compte -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.