Author: dcosse Date: 2014-07-23 17:44:45 +0200 (Wed, 23 Jul 2014) New Revision: 3860 Url: http://forge.chorem.org/projects/lima/repository/revisions/3860 Log: refs #1032 export entries as CSV replace financialTransaction id by financialTransaction date Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.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/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/EntryModel.java trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 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-23 14:52:58 UTC (rev 3859) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java 2014-07-23 15:44:45 UTC (rev 3860) @@ -99,7 +99,7 @@ files.add(exportEntryBooksFile(charset)); files.add(exportFiscalPeriodFile(charset)); files.add(exportFinancialTransactionsFile(charset)); - files.add(exportEntriesFile(charset)); + files.add(exportEntriesFile(charset, false)); export = new ZipOutputStream(rstBao); @@ -139,7 +139,7 @@ } @Override - public String exportAccountsStream(String charset) { + public String exportAccountsAsCSV(String charset) { String result; try { File file = exportAccountsFile(charset); @@ -165,7 +165,7 @@ @Override - public String exportEntryBooksStream(String charset) { + public String exportEntryBooksAsCSV(String charset) { String result; try { File file = exportEntryBooksFile(charset); @@ -191,7 +191,7 @@ } @Override - public String exportFiscalPeriodsStream(String charset) { + public String exportFiscalPeriodsAsCSV(String charset) { String result; try { File file = exportFiscalPeriodFile(charset); @@ -219,7 +219,7 @@ } @Override - public String exportFinancialTransactionsAsStream(String charset) { + public String exportFinancialTransactionsAsCSV(String charset) { String result; try { File file = exportFinancialTransactionsFile(charset); @@ -231,13 +231,13 @@ return result; } - protected File exportEntriesFile(String charset) throws Exception { + protected File exportEntriesFile(String charset, Boolean humanReadable) throws Exception { EntryTopiaDao dao = getDaoHelper().getEntryDao(); List<Entry> entities = dao.findAll(); String tmpDir = System.getProperty("java.io.tmpdir")+"/"; File result = new File(tmpDir + "entries.csv"); - EntryModel model = new EntryModel(accountService, financialTransactionService); + EntryModel model = new EntryModel(accountService, financialTransactionService , humanReadable); Export.exportToFile(model, entities, result, Charset.forName(charset)); return result; } @@ -246,7 +246,7 @@ public String exportEntriesAsCSV(String charset) { String result; try { - File file = exportEntriesFile(charset); + File file = exportEntriesFile(charset, true); FileInputStream inputStream = new FileInputStream(file); result = IOUtils.toString(inputStream); } catch (Exception e) { 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-23 14:52:58 UTC (rev 3859) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java 2014-07-23 15:44:45 UTC (rev 3860) @@ -181,7 +181,7 @@ // import and save entries InputStream contentStream = IOUtils.toInputStream(contents); try { - ImportModel<Entry> model = new EntryModel(accountService, financialTransactionService); + ImportModel<Entry> model = new EntryModel(accountService, financialTransactionService, false); Import<Entry> result = Import.newImport(model, contentStream); EntryTopiaDao dao = getDaoHelper().getEntryDao(); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java 2014-07-23 14:52:58 UTC (rev 3859) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java 2014-07-23 15:44:45 UTC (rev 3860) @@ -52,6 +52,10 @@ protected static AccountService accountService; + protected static Boolean humanReadable; + + protected static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); + public AbstractLimaModel(char separator) { super(separator); } @@ -290,12 +294,12 @@ } }; - protected static final ValueFormatter<FinancialTransaction> FINANCIAL_TRANSACTION_TO_FINANCIAL_TRANSACTION_ID_FORMATTER = new ValueFormatter<FinancialTransaction>() { + protected static final ValueFormatter<FinancialTransaction> FINANCIAL_TRANSACTION_TO_FINANCIAL_TRANSACTION_FORMATTER = new ValueFormatter<FinancialTransaction>() { @Override public String format(FinancialTransaction value) { String result; if (value != null) { - result = value.getTopiaId(); + result = humanReadable ? simpleDateFormat.format(value.getTransactionDate()) : value.getTopiaId(); } else { result = ""; } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/EntryModel.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/EntryModel.java 2014-07-23 14:52:58 UTC (rev 3859) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/EntryModel.java 2014-07-23 15:44:45 UTC (rev 3860) @@ -35,10 +35,11 @@ */ public class EntryModel extends AbstractLimaModel<Entry> implements ExportModel<Entry> { - public EntryModel(AccountService accountService, FinancialTransactionService financialTransactionService) { + public EntryModel(AccountService accountService, FinancialTransactionService financialTransactionService, boolean humanReadable) { super(';'); AbstractLimaModel.accountService = accountService; AbstractLimaModel.financialTransactionService = financialTransactionService; + AbstractLimaModel.humanReadable = humanReadable; newMandatoryColumn("account", Entry.PROPERTY_ACCOUNT, ACCOUNT_NUMBER_TO_ACCOUNT_TRANSACTION_PARSER); newOptionalColumn("amount", Entry.PROPERTY_AMOUNT, BIG_DECIMAL_WITH_NULL_PARSER); @@ -62,7 +63,7 @@ modelBuilder.newColumnForExport("voucher", Entry.PROPERTY_VOUCHER); modelBuilder.newColumnForExport("description", Entry.PROPERTY_DESCRIPTION); modelBuilder.newColumnForExport("lettering", Entry.PROPERTY_LETTERING); - modelBuilder.newColumnForExport("financialTransaction", Entry.PROPERTY_FINANCIAL_TRANSACTION, FINANCIAL_TRANSACTION_TO_FINANCIAL_TRANSACTION_ID_FORMATTER); + modelBuilder.newColumnForExport("financialTransaction", Entry.PROPERTY_FINANCIAL_TRANSACTION, FINANCIAL_TRANSACTION_TO_FINANCIAL_TRANSACTION_FORMATTER); return (Iterable) modelBuilder.getColumnsForExport(); } 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-23 14:52:58 UTC (rev 3859) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java 2014-07-23 15:44:45 UTC (rev 3860) @@ -15,14 +15,11 @@ import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import java.util.zip.ZipOutputStream; /** * Created by davidcosse on 03/06/14. @@ -39,7 +36,7 @@ // export accounts String tmpDir = System.getProperty("java.io.tmpdir")+"/"; - String export = newExportService.exportAccountsStream(Charset.defaultCharset().name()); + String export = newExportService.exportAccountsAsCSV(Charset.defaultCharset().name()); InputStream stream = IOUtils.toInputStream(export); FileOutputStream res = new FileOutputStream(tmpDir + "export-accounts.csv"); IOUtils.copy(stream, res); @@ -70,7 +67,7 @@ initTestWithEntryBooks(); String tmpDir = System.getProperty("java.io.tmpdir")+"/"; - String export = newExportService.exportEntryBooksStream(Charset.defaultCharset().name()); + String export = newExportService.exportEntryBooksAsCSV(Charset.defaultCharset().name()); InputStream stream = IOUtils.toInputStream(export); FileOutputStream res = new FileOutputStream(tmpDir + "export-EntryBooks.csv"); IOUtils.copy(stream, res); @@ -102,7 +99,7 @@ initTestWithFinancialTransaction(); String tmpDir = System.getProperty("java.io.tmpdir")+"/"; - String export = newExportService.exportFinancialTransactionsAsStream(Charset.defaultCharset().name()); + String export = newExportService.exportFinancialTransactionsAsCSV(Charset.defaultCharset().name()); InputStream stream = IOUtils.toInputStream(export); FileOutputStream res = new FileOutputStream(tmpDir + "export-financial-transactions.csv"); IOUtils.copy(stream, res); @@ -189,7 +186,7 @@ initTestWithFiscalPeriod(); String tmpDir = System.getProperty("java.io.tmpdir")+"/"; - String export = newExportService.exportFiscalPeriodsStream(Charset.defaultCharset().name()); + String export = newExportService.exportFiscalPeriodsAsCSV(Charset.defaultCharset().name()); InputStream stream = IOUtils.toInputStream(export); FileOutputStream res = new FileOutputStream(tmpDir + "export-fiscal-periods.csv"); IOUtils.copy(stream, res); 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-23 14:52:58 UTC (rev 3859) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.java 2014-07-23 15:44:45 UTC (rev 3860) @@ -40,13 +40,13 @@ String exportAllAsCSV(String charset); - String exportAccountsStream(String charset); + String exportAccountsAsCSV(String charset); - String exportEntryBooksStream(String charset); + String exportEntryBooksAsCSV(String charset); - String exportFiscalPeriodsStream(String charset); + String exportFiscalPeriodsAsCSV(String charset); - String exportFinancialTransactionsAsStream(String charset); + String exportFinancialTransactionsAsCSV(String charset); String exportEntriesAsCSV(String charset); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java 2014-07-23 14:52:58 UTC (rev 3859) +++ trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java 2014-07-23 15:44:45 UTC (rev 3860) @@ -33,9 +33,10 @@ CSV_ALL_EXPORT(false, false), CSV_ALL_IMPORT(true, true), CSV_ACCOUNTCHARTS_EXPORT(false, true), CSV_ACCOUNTCHARTS_IMPORT(true, true), CSV_ENTRYBOOKS_EXPORT(false, true), CSV_ENTRYBOOKS_IMPORT(true, true), + CSV_ENTRIES_EXPORT(false, true),CSV_ENTRIES_IMPORT(true, true), CSV_FINANCIALSTATEMENTS_EXPORT(false, true), CSV_FINANCIALSTATEMENTS_IMPORT(true, true), CSV_VAT_EXPORT(false, true), CSV_VAT_IMPORT(true, true), - CSV_ENTRIES_IMPORT(true, true), + PDF_VAT_EXPORT(false, true), PDF_VAT_IMPORT(true, true), EBP_ACCOUNTCHARTS_EXPORT(false, false), EBP_ENTRIES_EXPORT(false, false), EBP_ACCOUNTCHARTS_IMPORT(true, true), EBP_ENTRIES_IMPORT(true, true), Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2014-07-23 14:52:58 UTC (rev 3859) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2014-07-23 15:44:45 UTC (rev 3860) @@ -83,6 +83,8 @@ onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.CSV_ENTRYBOOKS_EXPORT)'/> <JMenuItem text="lima.ui.importexport.accountcharts" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.CSV_ACCOUNTCHARTS_EXPORT)'/> + <JMenuItem text="lima.ui.importexport.financialtransactions" + onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.CSV_ENTRIES_EXPORT)'/> <JMenuItem text="lima.ui.importexport.financialstatements" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.CSV_FINANCIALSTATEMENTS_EXPORT)'/> <JMenuItem text="lima.ui.importexport.vatstatements" 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-23 14:52:58 UTC (rev 3859) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-07-23 15:44:45 UTC (rev 3860) @@ -152,13 +152,17 @@ createZipFile(filePath, datas); break; case CSV_ACCOUNTCHARTS_EXPORT: - datas = exportService.exportAccountsChartAsCSV(); + datas = newExportService.exportAccountsAsCSV(charset.name()); createFile(filePath, charset.name(), datas); break; case CSV_ENTRYBOOKS_EXPORT: - datas = exportService.exportEntryBookChartAsCSV(); + datas = newExportService.exportEntryBooksAsCSV(charset.name()); createFile(filePath, charset.name(), datas); break; + case CSV_ENTRIES_EXPORT: + datas = newExportService.exportEntriesAsCSV(charset.name()); + createFile(filePath, charset.name(), datas); + break; case CSV_FINANCIALSTATEMENTS_EXPORT: datas = exportService.exportFinancialStatementChartAsCSV(); createFile(filePath, charset.name(), datas);