r3861 - in trunk: lima-business/src/main/java/org/chorem/lima/business/ejb lima-business/src/test/java/org/chorem/lima/business lima-business-api/src/main/java/org/chorem/lima/business/api lima-swing/src/main/java/org/chorem/lima/ui/importexport
Author: dcosse Date: 2014-07-23 18:36:19 +0200 (Wed, 23 Jul 2014) New Revision: 3861 Url: http://forge.chorem.org/projects/lima/repository/revisions/3861 Log: refs #1032 progression migration vers nouveaux services 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/NewImportService.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/test/java/org/chorem/lima/business/NewImportExportServiceTest.java 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 15:44:45 UTC (rev 3860) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java 2014-07-23 16:36:19 UTC (rev 3861) @@ -26,6 +26,7 @@ package org.chorem.lima.business.ejb; import com.google.common.collect.Lists; +import com.sun.org.apache.xpath.internal.operations.Bool; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -243,10 +244,10 @@ } @Override - public String exportEntriesAsCSV(String charset) { + public String exportEntriesAsCSV(String charset, Boolean humanReadable) { String result; try { - File file = exportEntriesFile(charset, true); + File file = exportEntriesFile(charset, humanReadable); 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 15:44:45 UTC (rev 3860) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java 2014-07-23 16:36:19 UTC (rev 3861) @@ -23,6 +23,7 @@ */ import com.google.common.base.Function; +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import org.apache.commons.io.IOUtils; import org.chorem.lima.business.BeginAfterEndFiscalPeriodException; @@ -85,8 +86,15 @@ @EJB private FiscalPeriodService fiscalPeriodService; + protected static final Function<TopiaEntity, String> GET_TOPIA_ID = new Function<TopiaEntity, String>() { + @Override + public String apply(TopiaEntity input) { + return input == null ? null : input.getTopiaId(); + } + }; + @Override - public void importAccountAsCSV(String contents) { + public String importAccountAsCSV(String contents) { InputStream contentStream = IOUtils.toInputStream(contents); try { @@ -106,11 +114,11 @@ } finally { IOUtils.closeQuietly(contentStream); } - + return "SUCCES"; } @Override - public void importEntryBooksAsCSV(String contents) { + public String importEntryBooksAsCSV(String contents) { InputStream contentStream = IOUtils.toInputStream(contents); try { ImportModel<EntryBook> model = new EntryBookModel(); @@ -125,6 +133,7 @@ } finally { IOUtils.closeQuietly(contentStream); } + return "SUCCES"; } @Override @@ -155,29 +164,32 @@ } @Override - public void importFinancialTransactionsAsCSV(String contents) { + public String importFinancialTransactionsAsCSV(String contents) { + + EntryBookTopiaDao entryBookdao = getDaoHelper().getEntryBookDao(); + Preconditions.checkArgument(entryBookdao.count() > 0, "Les journaux doivent avoir été importé."); + // import and save FinancialTransactions InputStream contentStream = IOUtils.toInputStream(contents); try { ImportModel<FinancialTransaction> model = new FinancialTransactionModel(entryBookService); - + FinancialTransactionTopiaDao dao = getDaoHelper().getFinancialTransactionDao(); Import<FinancialTransaction> result = Import.newImport(model, contentStream); dao.createAll(result); } finally { IOUtils.closeQuietly(contentStream); } + return "SUCCES"; } - protected static final Function<TopiaEntity, String> GET_TOPIA_ID = new Function<TopiaEntity, String>() { - @Override - public String apply(TopiaEntity input) { - return input == null ? null : input.getTopiaId(); - } - }; + @Override + public String importEntriesAsCSV(String contents) { + AccountTopiaDao accountDao = getDaoHelper().getAccountDao(); + FinancialTransactionTopiaDao financialTransactionDao = getDaoHelper().getFinancialTransactionDao(); - @Override - public void importEntriesAsCSV(String contents) { + Preconditions.checkArgument(accountDao.count() > 0 && financialTransactionDao.count() > 0, "Les comptes et trasactions financières doivent avoir été importé."); + // import and save entries InputStream contentStream = IOUtils.toInputStream(contents); try { @@ -190,14 +202,16 @@ } finally { IOUtils.closeQuietly(contentStream); } + return "SUCCES"; } @Override - public void importAllAsCSV(String entryBooks, String financialTransactions, String fiscalPeriods, String accounts, String entries){ + public String importAllAsCSV(String entryBooks, String financialTransactions, String fiscalPeriods, String accounts, String entries){ + importAccountAsCSV(accounts); importEntryBooksAsCSV(entryBooks); + importFiscalPeriodsAsCSV(fiscalPeriods); importFinancialTransactionsAsCSV(financialTransactions); - importFiscalPeriodsAsCSV(fiscalPeriods); - importAccountAsCSV(accounts); importEntriesAsCSV(entries); + return "SUCCES"; } } 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 15:44:45 UTC (rev 3860) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java 2014-07-23 16:36:19 UTC (rev 3861) @@ -141,7 +141,7 @@ //test export String tmpDir = System.getProperty("java.io.tmpdir")+"/"; - String export = newExportService.exportEntriesAsCSV(Charset.defaultCharset().name()); + String export = newExportService.exportEntriesAsCSV(Charset.defaultCharset().name(), false); InputStream stream = IOUtils.toInputStream(export); FileOutputStream res = new FileOutputStream(tmpDir + "export-entries.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 15:44:45 UTC (rev 3860) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.java 2014-07-23 16:36:19 UTC (rev 3861) @@ -48,5 +48,5 @@ String exportFinancialTransactionsAsCSV(String charset); - String exportEntriesAsCSV(String charset); + String exportEntriesAsCSV(String charset, Boolean humanReadable); } 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-23 15:44:45 UTC (rev 3860) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java 2014-07-23 16:36:19 UTC (rev 3861) @@ -27,15 +27,15 @@ */ public interface NewImportService { - void importAccountAsCSV(String contents); + String importAccountAsCSV(String contents); - void importEntryBooksAsCSV(String contents); + String importEntryBooksAsCSV(String contents); String importFiscalPeriodsAsCSV(String contents); - void importFinancialTransactionsAsCSV(String contents); + String importFinancialTransactionsAsCSV(String contents); - void importEntriesAsCSV(String contents); + String importEntriesAsCSV(String contents); - void importAllAsCSV(String entryBooks, String transactions, String fiscalPeriods, String accounts, String entries); + String importAllAsCSV(String entryBooks, String transactions, String fiscalPeriods, String accounts, String entries); } 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 15:44:45 UTC (rev 3860) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-07-23 16:36:19 UTC (rev 3861) @@ -160,7 +160,7 @@ createFile(filePath, charset.name(), datas); break; case CSV_ENTRIES_EXPORT: - datas = newExportService.exportEntriesAsCSV(charset.name()); + datas = newExportService.exportEntriesAsCSV(charset.name(), true); createFile(filePath, charset.name(), datas); break; case CSV_FINANCIALSTATEMENTS_EXPORT: @@ -186,24 +186,24 @@ break; case CSV_ACCOUNTCHARTS_IMPORT: datas = extractFile(filePath, charset.name()); - result = importService.importAsCSV(datas, ImportExportEntityEnum.ACCOUNT); + result = newImportService.importAccountAsCSV(datas); break; case CSV_ENTRYBOOKS_IMPORT: datas = extractFile(filePath, charset.name()); - result = importService.importAsCSV(datas, ImportExportEntityEnum.ENTRYBOOK); + result = newImportService.importEntryBooksAsCSV(datas); break; case CSV_FINANCIALSTATEMENTS_IMPORT: datas = extractFile(filePath, charset.name()); result = importService.importAsCSV(datas, ImportExportEntityEnum.FINANCIALSTATEMENT); break; + case CSV_ENTRIES_IMPORT: + datas = extractFile(filePath, charset.name()); + result = newImportService.importEntriesAsCSV(datas); + break; case CSV_VAT_IMPORT: datas = extractFile(filePath, charset.name()); result = importService.importAsCSV(datas, ImportExportEntityEnum.VATSTATEMENT); break; - case CSV_ENTRIES_IMPORT: - datas = extractFile(filePath, charset.name()); - result = importService.importAsCSV(datas, ImportExportEntityEnum.ENTRY); - break; case PDF_VAT_IMPORT: int response = JOptionPane.showConfirmDialog(waitView, t("lima.importexport.usevatpdf"),
participants (1)
-
dcosse@users.chorem.org