This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository lima. See https://gitlab.nuiton.org/chorem/lima.git commit 52e819691951759ef962f2d3590ff079caea98b6 Author: David Cossé <cosse@codelutin.com> Date: Fri Jul 8 18:57:24 2016 +0200 refs #1174 ajout d'une exception pour gérer le cas ou l'on essaye de supprimer un compte qui 'existe pas --- .../java/org/chorem/lima/business/api/AccountService.java | 3 ++- .../chorem/lima/business/exceptions/UnexistingAccount.java | 11 +++++++++++ .../main/java/org/chorem/lima/business/AccountingRules.java | 3 ++- .../lima/business/accountingrules/DefaultAccountingRules.java | 10 +++++++--- .../java/org/chorem/lima/business/ejb/AccountServiceImpl.java | 11 ++++++----- .../java/org/chorem/lima/ui/account/AccountViewHandler.java | 7 +++++-- .../src/main/resources/i18n/lima-swing_en_GB.properties | 1 + .../src/main/resources/i18n/lima-swing_fr_FR.properties | 1 + 8 files changed, 35 insertions(+), 12 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..f8c7528 --- /dev/null +++ b/lima-business-api/src/main/java/org/chorem/lima/business/exceptions/UnexistingAccount.java @@ -0,0 +1,11 @@ +package org.chorem.lima.business.exceptions; + +/** + * Created by davidcosse on 08/07/16. + */ +public class UnexistingAccount extends AccountException { + + 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..410bf2b 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 @@ -41,6 +41,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; @@ -63,7 +64,7 @@ import java.math.BigDecimal; import java.util.Date; import java.util.List; -; + /** * Defaults rules, if no localized rules classes is instantiated @@ -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()); } @@ -210,7 +214,7 @@ public class DefaultAccountingRules implements AccountingRules { EntryTopiaDao entryDao = getDaoHelper().getEntryDao(); ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookTopiaDao = getDaoHelper().getClosedPeriodicEntryBookDao(); // reload object in current transaction - closedPeriodicEntryBook = closedPeriodicEntryBookTopiaDao.findByTopiaId(closedPeriodicEntryBook.getTopiaId()); + closedPeriodicEntryBook = closedPeriodicEntryBookTopiaDao.forTopiaIdEquals(closedPeriodicEntryBook.getTopiaId()).findUnique(); // Check if all financial transactions of closedperiodicentrybook are equilibrate FinancialPeriod period = closedPeriodicEntryBook.getFinancialPeriod(); 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..63add0f 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); } @@ -231,7 +232,7 @@ public class AccountServiceImpl extends AbstractLimaService implements AccountSe // TODO sbavencoff 18/07/2014 revoir la selection des comptes #1046 @Override public List<Account> stringToListAccounts(String selectedAccounts) { - Set<Account> accounts = new HashSet<Account>(); + Set<Account> accounts = new HashSet<>(); if (selectedAccounts != null) { AccountTopiaDao accountDao = getDaoHelper().getAccountDao(); //Remove Spaces @@ -293,7 +294,7 @@ public class AccountServiceImpl extends AbstractLimaService implements AccountSe first = false; } } - return new ArrayList<Account>(accounts); + return new ArrayList<>(accounts); } @Override 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..0b3d79d 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; @@ -204,7 +205,7 @@ public class AccountViewHandler implements ServiceListener { } // render in tree node hierarchy for DefaultTreeTableModel - SortedMap<String, DefaultMutableTreeTableNode> nodeCache = new TreeMap<String, DefaultMutableTreeTableNode>(REVERSE_ACCOUNT_LENGTH_COMPARATOR); + SortedMap<String, DefaultMutableTreeTableNode> nodeCache = new TreeMap<>(REVERSE_ACCOUNT_LENGTH_COMPARATOR); DefaultMutableTreeTableNode root = new DefaultMutableTreeTableNode(null); for (Account account : accounts) { // find parent @@ -325,7 +326,7 @@ public class AccountViewHandler implements ServiceListener { * @return node list */ protected List<MutableTreeTableNode> findSubNodes(TreeTableNode currentNode, String accountNumber) { - List<MutableTreeTableNode> nodes = new ArrayList<MutableTreeTableNode>(); + List<MutableTreeTableNode> nodes = new ArrayList<>(); for (int childIndex = 0; childIndex < currentNode.getChildCount(); childIndex++) { MutableTreeTableNode child = (MutableTreeTableNode)currentNode.getChildAt(childIndex); Account account = (Account)child.getUserObject(); @@ -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 29d8443..9022472 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 4f261ab..541d2e3 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>.