This is an automated email from the git hooks/post-receive script. New commit to branch feature/1369-demarage-initial in repository lima. See https://gitlab.nuiton.org/chorem/lima.git commit 45cac9a26f1bddfae8f8a910b2917d30628a83f6 Author: David Cossé <cosse@codelutin.com> Date: Thu Sep 8 15:20:44 2016 +0200 refs #1174 Rollback Changes, les résultats ne sont pas satifaisant au regard de la balance de référence --- .../lima/business/ejb/ImportServiceImpl.java | 84 ++++++---------------- .../lima/business/ImportExportServiceTest.java | 25 +++---- 2 files changed, 30 insertions(+), 79 deletions(-) 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 11feab7..11a23d1 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 @@ -23,7 +23,6 @@ package org.chorem.lima.business.ejb; */ import com.google.common.base.Function; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Ordering; import com.google.common.collect.Sets; @@ -988,7 +987,7 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ // the entry entity is created and the association with it's dependant entites (Account are FinancialTransaction) are created Date fiscalPeriodsBeginDate = fiscalPeriods.get(0).getBeginDate(); Date fiscalPeriodsEndingDate = fiscalPeriods.get(fiscalPeriods.size() - 1).getEndDate(); - Map<EntryBook, Map<Date, Set<FinancialTransaction>>> entryBookFinancialTransactionsByDate = getEntryBookFinancialTransactionOrderedByDate(fiscalPeriodsBeginDate, fiscalPeriodsEndingDate); + Map<EntryBook, Map<Date, FinancialTransaction>> entryBookFinancialTransactionByDate = getEntryBookFinancialTransactionOrderedByDate(fiscalPeriodsBeginDate, fiscalPeriodsEndingDate); for (EntryEBP entryEBP : entryEBPs) { Date dateEcr = entryEBP.getDatEcr(); @@ -1007,7 +1006,7 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ try { // find financial transactions for entry period and entrybook - addEntryToFinancialTransaction(entry, entryEBP.getJournal(), indexedEntryBooks, entryBookFinancialTransactionsByDate, dateEcr); + addEntryToFinancialTransaction(entry, entryEBP.getJournal(), indexedEntryBooks, entryBookFinancialTransactionByDate, dateEcr); } catch (LockedFinancialPeriodException | LockedEntryBookException | AlreadyExistEntryBookException | AfterLastFiscalPeriodException | BeforeFirstFiscalPeriodException e) { result.addException(e); @@ -1051,68 +1050,34 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ return entry; } - protected void addEntryToFinancialTransaction(Entry entry, String entryBookCode, Map<String, EntryBook> indexedEntryBooks, Map<EntryBook, Map<Date, Set<FinancialTransaction>>> entryBookFinancialTransactionsByDate, Date dateEcr) throws LockedFinancialPeriodException, LockedEntryBookException, AlreadyExistEntryBookException, AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException { + protected void addEntryToFinancialTransaction(Entry entry, String entryBookCode, Map<String, EntryBook> indexedEntryBooks, Map<EntryBook, Map<Date, FinancialTransaction>> entryBookFinancialTransactionByDate, Date dateEcr) throws LockedFinancialPeriodException, LockedEntryBookException, AlreadyExistEntryBookException, AfterLastFiscalPeriodException, BeforeFirstFiscalPeriodException { EntryBook entryBook = getEntryBook(indexedEntryBooks, entryBookCode); - Map<Date, Set<FinancialTransaction>> financialTransactionsByDate = entryBookFinancialTransactionsByDate.get(entryBook); + Map<Date, FinancialTransaction> financialTransactionsByDate = entryBookFinancialTransactionByDate.get(entryBook); if (financialTransactionsByDate == null) { financialTransactionsByDate = new HashMap<>(); - entryBookFinancialTransactionsByDate.put(entryBook, financialTransactionsByDate); + entryBookFinancialTransactionByDate.put(entryBook, financialTransactionsByDate); } - // find financial transaction for this required date and required voucher. - Set<FinancialTransaction> financialTransactionsForDate = financialTransactionsByDate.get(dateEcr); - if (financialTransactionsForDate == null) { - financialTransactionsForDate = Sets.newHashSet(); - financialTransactionsByDate.put(dateEcr, financialTransactionsForDate); - } - - String voucher = entry.getVoucher(); - - // look for an existing one - FinancialTransaction financialTransactionForDateAndVoucher = getFinancialTransactionForVoucher(financialTransactionsForDate, voucher); - - // if none exist a new one is created - if (financialTransactionForDateAndVoucher == null - || !(dateEcr.equals(financialTransactionForDateAndVoucher.getTransactionDate()) && entryBook + // create transaction + FinancialTransaction financialTransaction = financialTransactionsByDate.get(dateEcr); + if (financialTransaction == null + || !(dateEcr.equals(financialTransaction + .getTransactionDate()) && entryBook .getCode().equals( - financialTransactionForDateAndVoucher.getEntryBook() + financialTransaction.getEntryBook() .getCode()))) { // create financial transaction - financialTransactionForDateAndVoucher = financialTransactionService.createNewFinancialTransaction(); - financialTransactionForDateAndVoucher.setEntryBook(entryBook); - financialTransactionForDateAndVoucher.setTransactionDate(dateEcr); - financialTransactionForDateAndVoucher = financialTransactionService.createFinancialTransaction(financialTransactionForDateAndVoucher); - financialTransactionsForDate.add(financialTransactionForDateAndVoucher); + financialTransaction = financialTransactionService.createNewFinancialTransaction(); + financialTransaction.setEntryBook(entryBook); + financialTransaction.setTransactionDate(dateEcr); + financialTransaction = financialTransactionService.createFinancialTransaction(financialTransaction); + financialTransactionsByDate.put(financialTransaction.getTransactionDate(), financialTransaction); } - - // add entry to financial transaction - financialTransactionForDateAndVoucher.addEntry(entry); + financialTransaction.addEntry(entry); financialTransactionService.createEntry(entry); } - private FinancialTransaction getFinancialTransactionForVoucher(Set<FinancialTransaction> financialTransactions, String voucher) { - FinancialTransaction financialTransactionForEntry = null; - if (financialTransactions != null) { - for (FinancialTransaction financialTransaction : financialTransactions) { - Collection<Entry> entries = financialTransaction.getEntry(); - if (entries != null && entries.iterator().hasNext()) { - Entry firstEntry = entries.iterator().next(); - if (firstEntry.getVoucher().contentEquals(voucher)) { - financialTransactionForEntry = financialTransaction; - break; - } - } else { - entries = Lists.newArrayList(); - financialTransaction.setEntry(entries); - financialTransactionForEntry = financialTransaction; - break; - } - } - } - return financialTransactionForEntry; - } - protected EntryBook getEntryBook(Map<String, EntryBook> indexedEntryBooks, String entryBookCode) throws AlreadyExistEntryBookException { EntryBook entryBook; // entryBook loading @@ -1130,24 +1095,19 @@ public class ImportServiceImpl extends AbstractLimaService implements ImportServ return entryBook; } - protected Map<EntryBook, Map<Date, Set<FinancialTransaction>>> getEntryBookFinancialTransactionOrderedByDate(Date fiscalPeriodsBiginDate, Date fiscalPeriodsEndingDate) { - Map<EntryBook, Map<Date, Set<FinancialTransaction>>> entryBookFinancialTransactionByDate = new HashMap<>(); - List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(fiscalPeriodsBiginDate, fiscalPeriodsEndingDate); + protected Map<EntryBook, Map<Date, FinancialTransaction>> getEntryBookFinancialTransactionOrderedByDate(Date fiscalPeriodsBeginDate, Date fiscalPeriodsEndingDate) { + Map<EntryBook, Map<Date, FinancialTransaction>> entryBookFinancialTransactionByDate = new HashMap<>(); + List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(fiscalPeriodsBeginDate, fiscalPeriodsEndingDate); for (FinancialTransaction ft : financialTransactions) { EntryBook eb = ft.getEntryBook(); - Map<Date, Set<FinancialTransaction>> entryBooksFTs = entryBookFinancialTransactionByDate.get(eb); + Map<Date, FinancialTransaction> entryBooksFTs = entryBookFinancialTransactionByDate.get(eb); if (entryBooksFTs == null) { entryBooksFTs = new HashMap<>(); entryBookFinancialTransactionByDate.put(eb, entryBooksFTs); } // maybe not unique financial transaction for one date. // is there a way to know wich one to take ? - Set<FinancialTransaction> financialTransactionsForEntryBook = entryBooksFTs.get(ft.getTransactionDate()); - if (financialTransactionsForEntryBook == null) { - financialTransactionsForEntryBook = Sets.newHashSet(); - } - financialTransactionsForEntryBook.add(ft); - entryBooksFTs.put(ft.getTransactionDate(), financialTransactionsForEntryBook); + entryBooksFTs.put(ft.getTransactionDate(), ft); } return entryBookFinancialTransactionByDate; } diff --git a/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java b/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java index e4e6a4d..4fbd06a 100644 --- a/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java +++ b/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java @@ -56,7 +56,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; -import java.math.BigDecimal; import java.nio.charset.Charset; import java.text.ParseException; import java.util.ArrayList; @@ -566,6 +565,7 @@ public class ImportExportServiceTest extends AbstractLimaTest { entries.addAll(financialTransaction.getEntry()); } Assert.assertTrue(!entries.isEmpty()); + int nbEntities = entries.size(); //test export String tmpDir = System.getProperty("java.io.tmpdir")+"/"; @@ -591,10 +591,11 @@ public class ImportExportServiceTest extends AbstractLimaTest { // test import FileInputStream contentStream = null; + ImportResult result; try { contentStream = new FileInputStream(tmpDir + "export-entries-EBP.csv"); String inputStream = IOUtils.toString(contentStream); - importService.importEntriesFromEbp(inputStream).getImportResults().get(0); + result = importService.importEntriesFromEbp(inputStream).getImportResults().get(0); } finally { IOUtils.closeQuietly(contentStream); } @@ -603,22 +604,12 @@ public class ImportExportServiceTest extends AbstractLimaTest { financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012")); Assert.assertEquals(2, financialTransactions.size()); for (FinancialTransaction financialTransaction : financialTransactions) { - if (financialTransaction.getAmountDebit().compareTo(BigDecimal.valueOf(42.0)) == 0) { - Collection<Entry> voucherAEntries = financialTransaction.getEntry(); - Assert.assertEquals(2L, voucherAEntries.size()); - for (Entry entry : voucherAEntries) { - Assert.assertTrue(entry.getVoucher().contentEquals("voucherA")); - } - } else if (financialTransaction.getAmountDebit().compareTo(BigDecimal.valueOf(12.0)) == 0) { - Collection<Entry> voucherBEntries = financialTransaction.getEntry(); - Assert.assertEquals(3L, voucherBEntries.size()); - for (Entry entry : voucherBEntries) { - Assert.assertTrue(entry.getVoucher().contentEquals("voucherB")); - } - } else { - Assert.fail("Fail to import financial transactions"); - } + entries.addAll(financialTransaction.getEntry()); } + + Assert.assertEquals(nbEntities, entries.size()); + Assert.assertEquals(nbEntities, result.getNbCreated()); + Assert.assertTrue(result.getAllExceptionsByLine().isEmpty()); } protected void importEBPData() throws IOException, ParseException, BeginAfterEndFiscalPeriodException, -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.