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 15845a629a7b976d519695128d4fa0dd60b661c5 Author: David Cossé <cosse@codelutin.com> Date: Thu Jul 7 17:55:50 2016 +0200 refs #1361 correction sur affichage des erreurs d'import --- .../org/chorem/lima/business/ImportResult.java | 2 + .../lima/business/ejb/ImportServiceImpl.java | 4 +- .../resources/i18n/lima-business_fr_FR.properties | 2 +- .../chorem/lima/ui/importexport/ImportExport.java | 99 +++++++++------------- .../resources/i18n/lima-swing_fr_FR.properties | 2 +- 5 files changed, 46 insertions(+), 63 deletions(-) diff --git a/lima-business-api/src/main/java/org/chorem/lima/business/ImportResult.java b/lima-business-api/src/main/java/org/chorem/lima/business/ImportResult.java index 62e2690..8cec320 100644 --- a/lima-business-api/src/main/java/org/chorem/lima/business/ImportResult.java +++ b/lima-business-api/src/main/java/org/chorem/lima/business/ImportResult.java @@ -83,12 +83,14 @@ public class ImportResult implements Serializable{ public void addException(LimaException e) { allExceptions = allExceptions == null ? new HashMap<Integer, LimaException>() : allExceptions; allExceptions.put(this.lineIndex, e); + nbIgnored++; lineIndex++; } public void addInitException(LimaException e) { allExceptions = allExceptions == null ? new HashMap<Integer, LimaException>() : allExceptions; allExceptions.put(1, e); + nbIgnored++; lineIndex++; } diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java index 9d77b9d..e9b4e0c 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java @@ -880,7 +880,7 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ @Override public ImportExportResults importEntryBookFromEbp(String contents) { ImportExportResults results = new ImportExportResults(); - ImportResult result = results.createAddAndGetImportResult(Account.class); + ImportResult result = results.createAddAndGetImportResult(EntryBook.class); if (StringUtils.isBlank(contents)) { result.addException(new NoDataToImportException()); @@ -958,7 +958,7 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ @Override public ImportExportResults importEntriesFromEbp(String contents) { ImportExportResults results = new ImportExportResults(); - ImportResult result = results.createAddAndGetImportResult(Account.class); + ImportResult result = results.createAddAndGetImportResult(Entry.class); // use for logs long before = System.currentTimeMillis(); diff --git a/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties b/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties index 64845a1..17c85be 100644 --- a/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties +++ b/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties @@ -99,7 +99,7 @@ lima-business.financialtransaction.retainedearnings.voucher=Selon décision AG lima-business.import.ebpmissingaccount=Échec \: Compte %s inexistant. \nCréer tous les comptes avant d'importer les écritures. lima-business.import.entries.error.lockedEntryBook= lima-business.import.entries.error.lockedFinancialPeriod= -lima-business.import.entriesoutofdatesrange=Attention \: Cette entrée %s ne fait partie d'aucune période ouverte. Entrée non importée lima-business.import.noaccount\=Erreur \: Ce fichier ne contient aucun compte. +lima-business.import.entriesoutofdatesrange=Attention \: Cette entrée %s ne fait partie d'aucune période ouverte. Entrée non importée. lima.config.configFileName.description=Nom du fichier de configuration de Lima lima.config.currency.description= lima.config.currency.label= diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java b/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java index d0d0c47..6dfe168 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java @@ -65,16 +65,8 @@ import org.chorem.lima.enums.ImportExportEnum; import org.chorem.lima.util.ErrorHelper; import org.jdesktop.swingx.painter.BusyPainter; -import javax.swing.JComboBox; -import javax.swing.JFileChooser; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.SwingWorker; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Container; +import javax.swing.*; +import java.awt.*; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; @@ -221,7 +213,7 @@ public class ImportExport { } else { throw new LimaTechnicalException("Can't open file from path" + importFilePath); } - log.info("Precessing import:" + importFileUrl.getPath() + " " + importFilePath + " " + importFileUrl.getFile()); + log.info("Processing import:" + importFileUrl.getPath() + " " + importFilePath + " " + importFileUrl.getFile()); processImportExport(verbose, importExportChoice, defaultCharset, null, importFileUrl); } } @@ -231,7 +223,7 @@ public class ImportExport { if (exportFilePath != null) { // if null ==> cancel export File file = new File(exportFilePath); if (file.getParentFile().exists()) { - log.info("Precessing export:" + exportFilePath); + log.info("Processing export:" + exportFilePath); processImportExport(verbose, importExportChoice, Charsets.UTF_8, exportFilePath, null); } else { throw new LimaTechnicalException("Targeted directory can not be found."); @@ -393,34 +385,27 @@ public class ImportExport { } } - DisplayImportExportResultMessage(message, false); + displayImportExportResultMessage(message, false); } protected void ComputeImportResultMessage(List<ImportResult> resultList) { StringBuilder message = new StringBuilder(); message.append(t("lima.import.terminated") + "\n"); - StringBuilder errorMessage = null; for (ImportResult result : resultList) { Class fromSource = result.getFromSource(); message.append("Import "); message.append(getFromSourceMessage(fromSource)); - message.append(t("lima.import.report", result.getNbCreated(), result.getNbUpdated(), result.getNbIgnored()) + "\n"); - Map<Integer, LimaException> exceptionsByLine = result.getAllExceptionsByLine(); - errorMessage = displayErrorMessage(exceptionsByLine); - // message is null if import failed - if (errorMessage == null) { - break; - } else { - message.append(errorMessage.toString()); - } - } + message.append(result.getAllExceptionsByLine().size() > 0 ? "Des erreurs sont survenues lors de l'import, veuillez regarder le fichier de log pour plus de détails.\n" : "Aucune erreur rencontrée\n"); + message.append(t("lima.import.report", result.getNbCreated(), result.getNbIgnored(), result.getNbUpdated())); - if (errorMessage != null) { - DisplayImportExportResultMessage(message, true); + logErrorMessage(result, fromSource); } + + displayImportExportResultMessage(message, true); + } - protected void DisplayImportExportResultMessage(StringBuilder message, Boolean importMode) { + protected void displayImportExportResultMessage(StringBuilder message, Boolean importMode) { if (log.isDebugEnabled()){ log.debug(message.toString()); } @@ -433,60 +418,56 @@ public class ImportExport { JOptionPane.INFORMATION_MESSAGE); } - protected StringBuilder displayErrorMessage(Map<Integer, LimaException> exceptionsByLine) { - StringBuilder result = new StringBuilder(); + protected void logErrorMessage(ImportResult result,Class fromSource) { + Map<Integer, LimaException> exceptionsByLine = result.getAllExceptionsByLine(); if (exceptionsByLine != null) { + StringBuilder errorMessage = new StringBuilder(); + errorMessage.append("\n" + "Import " + getFromSourceMessage(fromSource)); + errorMessage.append("\n" + t("lima.import.report", result.getNbCreated(), result.getNbIgnored(), result.getNbUpdated())); + for (Map.Entry<Integer, LimaException> e:exceptionsByLine.entrySet()) { - result.append(t("lima.import.line", e.getKey()) + "\n"); - LimaException importException = e.getValue(); + String message = "\n" + t("lima.import.line", e.getKey()) + "%s"; + String error; + LimaException importException = e.getValue(); if (importException instanceof InvalidAccountNumberException) { - result.append(t("lima.account.error.invalidAccountNumber", ((InvalidAccountNumberException) importException).getAccountNumber()) + "\n"); + error = t("lima.account.error.invalidAccountNumber", ((InvalidAccountNumberException) importException).getAccountNumber()); } else if (importException instanceof NotNumberAccountNumberException) { - result.append(t("lima.account.error.notNumberAccountNumber", ((NotNumberAccountNumberException) importException).getAccountNumber()) + "\n"); + error = t("lima.account.error.notNumberAccountNumber", ((NotNumberAccountNumberException) importException).getAccountNumber()); } else if (importException instanceof NotAllowedLabelException) { - result.append(t("lima.error.notAllowedLabel", ((NotAllowedLabelException) importException).getLabel()) + "\n"); + error = t("lima.error.notAllowedLabel", ((NotAllowedLabelException) importException).getLabel()); } else if (importException instanceof MoreOneUnlockFiscalPeriodException) { - result.append(t("lima.fiscalPeriod.error.moreOneUnlockFiscalPeriod", ((MoreOneUnlockFiscalPeriodException) importException).getBeginDate(), ((MoreOneUnlockFiscalPeriodException) importException).getEndDate()) + "\n"); + error = t("lima.fiscalPeriod.error.moreOneUnlockFiscalPeriod", ((MoreOneUnlockFiscalPeriodException) importException).getBeginDate(), ((MoreOneUnlockFiscalPeriodException) importException).getEndDate()); } else if (importException instanceof BeginAfterEndFiscalPeriodException) { - result.append(t("lima.fiscalPeriod.error.beginAfterEndFiscalPeriod", ((BeginAfterEndFiscalPeriodException) importException).getFiscalPeriod().getBeginDate(), ((BeginAfterEndFiscalPeriodException) importException).getFiscalPeriod().getEndDate()) + "\n"); + error = t("lima.fiscalPeriod.error.beginAfterEndFiscalPeriod", ((BeginAfterEndFiscalPeriodException) importException).getFiscalPeriod().getBeginDate(), ((BeginAfterEndFiscalPeriodException) importException).getFiscalPeriod().getEndDate()); } else if (importException instanceof NotBeginNextDayOfLastFiscalPeriodException) { - result.append(t("lima.fiscalPeriod.error.notBeginNextDayOfLastFiscalPeriod", ((NotBeginNextDayOfLastFiscalPeriodException) importException).getFiscalPeriod().getBeginDate(), ((NotBeginNextDayOfLastFiscalPeriodException) importException).getFiscalPeriod().getEndDate()) + "\n"); + error = t("lima.fiscalPeriod.error.notBeginNextDayOfLastFiscalPeriod", ((NotBeginNextDayOfLastFiscalPeriodException) importException).getFiscalPeriod().getBeginDate(), ((NotBeginNextDayOfLastFiscalPeriodException) importException).getFiscalPeriod().getEndDate()); } else if (importException instanceof LockedFinancialPeriodException) { - result.append(t("lima.fiscalPeriod.error.lockedFinancialPeriod") + "\n"); + error = t("lima.fiscalPeriod.error.lockedFinancialPeriod"); } else if (importException instanceof LockedEntryBookException) { - result.append(t("lima.entryBook.error.lockedEntryBook", ((LockedEntryBookException) importException).getClosedPeriodicEntryBook().getFinancialPeriod().getBeginDate(), ((LockedEntryBookException) importException).getClosedPeriodicEntryBook().getFinancialPeriod().getEndDate()) + "\n"); + error = t("lima.entryBook.error.lockedEntryBook", ((LockedEntryBookException) importException).getClosedPeriodicEntryBook().getFinancialPeriod().getBeginDate(), ((LockedEntryBookException) importException).getClosedPeriodicEntryBook().getFinancialPeriod().getEndDate()); } else if (importException instanceof AlreadyExistFinancialStatementException) { - result.append(t("lima.financialStatement.error.alreadyExistFinancialStatement", ((AlreadyExistFinancialStatementException) importException).getFinancialStatementLabel()) + "\n"); + error = t("lima.financialStatement.error.alreadyExistFinancialStatement", ((AlreadyExistFinancialStatementException) importException).getFinancialStatementLabel()); } else if (importException instanceof AlreadyExistVatStatementException) { - result.append(t("lima.vatStatement.error.alreadyExistVatStatement", ((AlreadyExistVatStatementException) importException).getVatStatementLabel()) + "\n"); + error = t("lima.vatStatement.error.alreadyExistVatStatement", ((AlreadyExistVatStatementException) importException).getVatStatementLabel()); } else if (importException instanceof NoFiscalPeriodFoundException) { - result.append(t("lima.error.noFiscalPeriodFound") + "\n"); + error = t("lima.error.noFiscalPeriodFound"); } else if (importException instanceof BeforeFirstFiscalPeriodException) { - result.append(t("lima.entries.add.transaction.error.beforeFirstFiscalPeriod", ((BeforeFirstFiscalPeriodException) importException).getDate()) + "\n"); + error = t("lima.entries.add.transaction.error.beforeFirstFiscalPeriod", ((BeforeFirstFiscalPeriodException) importException).getDate()); } else if (importException instanceof AfterLastFiscalPeriodException) { - result.append(t("lima.entries.add.transaction.error.afterLastFiscalPeriod", ((AfterLastFiscalPeriodException) importException).getDate()) + "\n"); + error = t("lima.entries.add.transaction.error.afterLastFiscalPeriod", ((AfterLastFiscalPeriodException) importException).getDate()); } else if (importException instanceof NoDataToImportException) { - errorHelper.showErrorMessage(t("lima.import.error.noDataToImport")); - log.warn(t("lima.import.error.noDataToImport")); - result = null; - break; + error = t("lima.import.error.noDataToImport"); } else if (importException instanceof ImportFileException){ - errorHelper.showErrorMessage(((ImportFileException) importException).getDetailMessage()); - log.warn(((ImportFileException) importException).getDetailMessage()); - result = null; - break; + error = ((ImportFileException) importException).getDetailMessage(); } else { - result.append(t("lima.import.error.unknown") + "\n"); + error = importException.getMessage(); } - try { - throw importException; - } catch (LimaException ex) { - log.error(ex); + if (StringUtils.isNotEmpty(error)) { + errorMessage.append(String.format(message, error)); } - } + log.error(errorMessage.toString()); } - return result; } /** 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 c16da55..4f261ab 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 @@ -450,7 +450,7 @@ lima.importExport.all=Tout lima.importExport.csv=Import/Export CSV lima.importExport.ebp=Import/Export EBP lima.importExport.encoding.choice=Choix de l'encodage -lima.importExport.entry=des entrées terminé. +lima.importExport.entry=des écritures terminé. lima.importExport.entryBook=des journaux terminé. lima.importExport.entryBooks.default=Journaux par défaut lima.importExport.export=Exporter -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.