Author: dcosse Date: 2014-07-28 17:33:53 +0200 (Mon, 28 Jul 2014) New Revision: 3869 Url: http://forge.chorem.org/projects/lima/repository/revisions/3869 Log: refs #1032 emp?\195?\170che la cr?\195?\169ation de cat?\195?\169gories de transaction financi?\195?\168res ayant le m?\195?\170me nom pour un m?\195?\170me parent Added: trunk/lima-business-api/src/main/java/org/chorem/lima/business/AlreadyExistFinancialTransaction.java Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialStatementService.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartTreeTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.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/ejb/FinancialStatementServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2014-07-28 12:06:55 UTC (rev 3868) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2014-07-28 15:33:53 UTC (rev 3869) @@ -25,6 +25,8 @@ package org.chorem.lima.business.ejb; +import com.google.common.base.Function; +import com.google.common.collect.Maps; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -36,6 +38,7 @@ import org.chorem.lima.beans.FinancialStatementDatas; import org.chorem.lima.beans.FinancialStatementDatasImpl; import org.chorem.lima.beans.ReportsDatas; +import org.chorem.lima.business.AlreadyExistFinancialTransaction; import org.chorem.lima.business.LimaException; import org.chorem.lima.business.api.AccountService; import org.chorem.lima.business.api.FinancialStatementService; @@ -55,6 +58,7 @@ import java.util.Date; import java.util.List; import java.util.StringTokenizer; +import java.util.Map; @Stateless @Remote(FinancialStatementService.class) @@ -69,22 +73,36 @@ protected static final Log log = LogFactory.getLog(FinancialStatementServiceImpl.class); + protected static final Function<FinancialStatement, String> GET_LABEL = new Function<FinancialStatement, String>() { + @Override + public String apply(FinancialStatement input) { + return input == null ? null : input.getLabel(); + } + }; + @Override public void createFinancialStatement(FinancialStatement masterFinancialStatement, - FinancialStatement financialStatement) { + FinancialStatement financialStatement) throws AlreadyExistFinancialTransaction { FinancialStatementTopiaDao financialStatementTopiaDao = getDaoHelper().getFinancialStatementDao(); - financialStatementTopiaDao.create(financialStatement); - FinancialStatement masterfinancialStatementUpdate = null; if (masterFinancialStatement != null) { masterfinancialStatementUpdate = financialStatementTopiaDao.forLabelEquals(masterFinancialStatement.getLabel()).findAnyOrNull(); + + // valid that there are no duplicated financial statement. + Collection<FinancialStatement> subFinancialStatements = masterfinancialStatementUpdate.getSubFinancialStatements(); + Map indexedSubFinancialStatements = Maps.uniqueIndex(subFinancialStatements, GET_LABEL); + if (indexedSubFinancialStatements.get(financialStatement.getLabel()) != null){ + throw new AlreadyExistFinancialTransaction(financialStatement.getLabel(), masterfinancialStatementUpdate.getLabel()); + } } + FinancialStatement result = financialStatementTopiaDao.create(financialStatement); + // check if parent account exist; if (masterfinancialStatementUpdate != null) { - masterfinancialStatementUpdate.addSubFinancialStatements(financialStatement); + masterfinancialStatementUpdate.addSubFinancialStatements(result); financialStatementTopiaDao.update(masterfinancialStatementUpdate); } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-07-28 12:06:55 UTC (rev 3868) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-07-28 15:33:53 UTC (rev 3869) @@ -51,6 +51,7 @@ import org.chorem.lima.beans.VatStatementImport; import org.chorem.lima.beans.VatStatementImportImpl; import org.chorem.lima.business.AlreadyExistAccountException; +import org.chorem.lima.business.AlreadyExistFinancialTransaction; import org.chorem.lima.business.BeginAfterEndFiscalPeriodException; import org.chorem.lima.business.ImportEbpException; import org.chorem.lima.business.InvalidAccountNumberException; @@ -1019,8 +1020,7 @@ for (Iterator<FinancialStatementImport> itr2 = financialStatementImports.iterator(); itr2.hasNext(); ) { FinancialStatementImport financialStatementImport = itr2.next(); - String masterFinancialStatementLabel = financialStatementImport - .getMasterFinancialStatement(); + String masterFinancialStatementLabel = financialStatementImport.getMasterFinancialStatement(); FinancialStatement masterFinancialStatement = financialStatementService.getFinancialStatementByLabel(masterFinancialStatementLabel); if (masterFinancialStatementLabel.equals("") @@ -1057,10 +1057,15 @@ } - financialStatementService - .createFinancialStatement( - masterFinancialStatement, - financialStatement); + try { + financialStatementService + .createFinancialStatement( + masterFinancialStatement, + financialStatement); + } catch (AlreadyExistFinancialTransaction alreadyExistFinancialTransaction) { + result.append(t("lima.importexport.import.alreadyExistFinancialStatement", + alreadyExistFinancialTransaction.getFinancialTransactionLabel(), alreadyExistFinancialTransaction.getMasterLabel())); + } result.append(t("lima-business.import.financialstatementadded", financialStatementImport.getLabel())); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java 2014-07-28 12:06:55 UTC (rev 3868) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java 2014-07-28 15:33:53 UTC (rev 3869) @@ -88,7 +88,7 @@ public static final String JAVA_IO_TMPDIR = "java.io.tmpdir"; @Override - public String exportAllAsCSV(String charset) { + public String exportBackup(String charset) { ByteArrayOutputStream rstBao = new ByteArrayOutputStream(); ZipOutputStream export = null; try { Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java 2014-07-28 12:06:55 UTC (rev 3868) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java 2014-07-28 15:33:53 UTC (rev 3869) @@ -207,7 +207,7 @@ } @Override - public List<ImportResult> importAllAsCSV(String entryBooks, String financialTransactions, String fiscalPeriods, String accounts, String entries) throws AlreadyExistAccountException, InvalidAccountNumberException { + public List<ImportResult> importBackup(String entryBooks, String financialTransactions, String fiscalPeriods, String accounts, String entries) throws AlreadyExistAccountException, InvalidAccountNumberException { List<ImportResult> results = new ArrayList<ImportResult>(); importAccountAsCSV(accounts); importEntryBooksAsCSV(entryBooks); Modified: trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties =================================================================== --- trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties 2014-07-28 12:06:55 UTC (rev 3868) +++ trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties 2014-07-28 15:33:53 UTC (rev 3869) @@ -132,6 +132,7 @@ lima.config.scale.description=Scale lima.config.serveraddress.description=Server Address lima.configFileName.description= +lima.importexport.import.alreadyExistFinancialStatement= lima.reports.account.noaccount= lima.reports.account.noaccounttitle= lima.reports.accounts= @@ -147,3 +148,4 @@ lima.ui.financialtransaction.account= lima.ui.fiscalperiod.fiscalperiod= lima.ui.lettering.accountRegularization= +llima.importexport.import.alreadyExistFinancialStatement= Modified: trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties =================================================================== --- trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties 2014-07-28 12:06:55 UTC (rev 3868) +++ trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties 2014-07-28 15:33:53 UTC (rev 3869) @@ -128,6 +128,7 @@ lima.config.scale.description=Précision lima.config.serveraddress.description=Addresse serveur lima.configFileName.description= +lima.importexport.import.alreadyExistFinancialStatement= lima.reports.account.noaccount= lima.reports.account.noaccounttitle= lima.reports.accounts= @@ -143,3 +144,4 @@ lima.ui.financialtransaction.account= lima.ui.fiscalperiod.fiscalperiod= lima.ui.lettering.accountRegularization= +llima.importexport.import.alreadyExistFinancialStatement= Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java 2014-07-28 12:06:55 UTC (rev 3868) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java 2014-07-28 15:33:53 UTC (rev 3869) @@ -193,7 +193,7 @@ @Test public void exportImportAllAsCSVTest() throws Exception { initTestWithFinancialTransaction(); - String export = newExportService.exportAllAsCSV("UTF-8"); + String export = newExportService.exportBackup("UTF-8"); initAbstractTest(); String tmpDir = System.getProperty("java.io.tmpdir")+"/TMP_BACKUP.zip"; createZipFile(tmpDir, export); @@ -284,7 +284,7 @@ String accountsStreamString = IOUtils.toString(accountsStream); IOUtils.closeQuietly(accountsStream); - results = newImportService.importAllAsCSV(entryBooksStreamString, transactionsStreamString, fiscalPeriodsStreamString, accountsStreamString, entriesStreamString); + results = newImportService.importBackup(entryBooksStreamString, transactionsStreamString, fiscalPeriodsStreamString, accountsStreamString, entriesStreamString); } catch (Exception ex) { if(log.isInfoEnabled()) { Added: trunk/lima-business-api/src/main/java/org/chorem/lima/business/AlreadyExistFinancialTransaction.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/AlreadyExistFinancialTransaction.java (rev 0) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/AlreadyExistFinancialTransaction.java 2014-07-28 15:33:53 UTC (rev 3869) @@ -0,0 +1,24 @@ +package org.chorem.lima.business; + +/** + * Created by davidcosse on 28/07/14. + */ +public class AlreadyExistFinancialTransaction extends LimaException { + private static final long serialVersionUID = 4816249386192290272L; + + protected String financialTransactionLabel; + protected String masterLabel; + + public AlreadyExistFinancialTransaction(String label, String masterLabel) { + this.financialTransactionLabel = label; + this.masterLabel = masterLabel; + } + + public String getFinancialTransactionLabel() { + return financialTransactionLabel; + } + + public String getMasterLabel() { + return masterLabel; + } +} Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialStatementService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialStatementService.java 2014-07-28 12:06:55 UTC (rev 3868) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialStatementService.java 2014-07-28 15:33:53 UTC (rev 3869) @@ -26,6 +26,7 @@ package org.chorem.lima.business.api; import org.chorem.lima.beans.FinancialStatementAmounts; +import org.chorem.lima.business.AlreadyExistFinancialTransaction; import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.FinancialStatement; @@ -37,7 +38,7 @@ void createFinancialStatement(FinancialStatement masterFinancialStatement, - FinancialStatement financialStatement); + FinancialStatement financialStatement) throws AlreadyExistFinancialTransaction; void updateFinancialStatement(FinancialStatement financialStatement); Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.java 2014-07-28 12:06:55 UTC (rev 3868) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.java 2014-07-28 15:33:53 UTC (rev 3869) @@ -38,7 +38,7 @@ */ public interface NewExportService { - String exportAllAsCSV(String charset); + String exportBackup(String charset); String exportAccountsAsCSV(String charset); Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java 2014-07-28 12:06:55 UTC (rev 3868) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java 2014-07-28 15:33:53 UTC (rev 3869) @@ -41,5 +41,5 @@ ImportResult importEntriesAsCSV(String contents); - List<ImportResult> importAllAsCSV(String entryBooks, String transactions, String fiscalPeriods, String accounts, String entries) throws AlreadyExistAccountException, InvalidAccountNumberException; + List<ImportResult> importBackup(String entryBooks, String transactions, String fiscalPeriods, String accounts, String entries) throws AlreadyExistAccountException, InvalidAccountNumberException; } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartTreeTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartTreeTableModel.java 2014-07-28 12:06:55 UTC (rev 3868) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartTreeTableModel.java 2014-07-28 15:33:53 UTC (rev 3869) @@ -28,10 +28,13 @@ import com.google.common.collect.Lists; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.LimaConfig; +import org.chorem.lima.business.AlreadyExistFinancialTransaction; import org.chorem.lima.business.api.FinancialStatementService; import org.chorem.lima.entity.FinancialStatement; import org.chorem.lima.entity.FinancialStatementImpl; import org.chorem.lima.service.LimaServiceFactory; +import org.chorem.lima.util.ErrorHelper; import org.jdesktop.swingx.treetable.AbstractTreeTableModel; import javax.swing.tree.TreePath; @@ -57,6 +60,8 @@ /** Services. */ protected final FinancialStatementService financialStatementService; + protected ErrorHelper errorHelper; + /** Model constructor. Init account service used here. */ public FinancialStatementChartTreeTableModel() { //create root for the tree @@ -64,6 +69,7 @@ // Gets factory service financialStatementService = LimaServiceFactory.getService(FinancialStatementService.class); + errorHelper = new ErrorHelper(LimaConfig.getInstance()); } @@ -203,8 +209,13 @@ if (parentFinancialStatementHeader == getRoot()) { parentFinancialStatementHeader = null; } - financialStatementService.createFinancialStatement( - parentFinancialStatementHeader, financialStatement); + try { + financialStatementService.createFinancialStatement( + parentFinancialStatementHeader, financialStatement); + } catch (AlreadyExistFinancialTransaction alreadyExistFinancialTransaction) { + errorHelper.showErrorMessage(t("lima.importexport.import.alreadyExistFinancialStatement", + alreadyExistFinancialTransaction.getFinancialTransactionLabel(), alreadyExistFinancialTransaction.getMasterLabel())); + } modelSupport.fireTreeStructureChanged(path); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-07-28 12:06:55 UTC (rev 3868) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-07-28 15:33:53 UTC (rev 3869) @@ -152,7 +152,7 @@ try { switch (importExportMethodeF) { case CSV_ALL_EXPORT: - datas = newExportService.exportAllAsCSV(charset.name()); + datas = newExportService.exportBackup(charset.name()); createZipFile(filePath, datas); break; case CSV_ACCOUNTCHARTS_EXPORT: @@ -496,7 +496,7 @@ String entriesStreamString = IOUtils.toString(entriesStream); IOUtils.closeQuietly(entriesStream); - results = newImportService.importAllAsCSV(entryBooksStreamString, transactionsStreamString, fiscalPeriodsStreamString, accountsStreamString, entriesStreamString); + results = newImportService.importBackup(entryBooksStreamString, transactionsStreamString, fiscalPeriodsStreamString, accountsStreamString, entriesStreamString); } catch (Exception ex) { if(log.isInfoEnabled()) { 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 2014-07-28 12:06:55 UTC (rev 3868) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2014-07-28 15:33:53 UTC (rev 3869) @@ -275,6 +275,7 @@ lima.importexport.choiceencoding= lima.importexport.export= lima.importexport.export.terminated= +lima.importexport.import.alreadyExistFinancialStatement=Category with name %s exists for parent %s. lima.importexport.usevatpdf= lima.init.closed=Lima closed at %1$s lima.init.errorclosing=Error during Lima close 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 2014-07-28 12:06:55 UTC (rev 3868) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2014-07-28 15:33:53 UTC (rev 3869) @@ -258,6 +258,7 @@ lima.importexport.choiceencoding=Choix de l'encodage lima.importexport.export= lima.importexport.export.terminated= +lima.importexport.import.alreadyExistFinancialStatement=Une catégorie avec comme nom %s et comme parent %s existe déjà. lima.importexport.usevatpdf=Êtes-vous sûr de vouloir utiliser ce pdf pour la déclaration de TVA ? lima.init.closed=Lima fermé à %1$s lima.init.errorclosing=Erreur lors de la fermeture @@ -548,6 +549,7 @@ lima.warning.nimbus.landf=Le look and feel nymbus n'a pas été trouvé limma.config.thousandseparator.description=Caractère de séparation entre les blocs de milliers limma.config.thousandseparator.label=Séparateur de milliers +llima.importexport.import.alreadyExistFinancialStatement= org.chorem.lima.LimaConfig.NumberSeparator.COMMA= org.chorem.lima.LimaConfig.NumberSeparator.DOT= org.chorem.lima.LimaConfig.NumberSeparator.SPACE=