r3892 - in trunk: lima-business/src/main/java/org/chorem/lima/business/ejb lima-business/src/main/java/org/chorem/lima/business/utils lima-business/src/test/java/org/chorem/lima/business lima-business-api/src/main/java/org/chorem/lima/business lima-business-api/src/main/java/org/chorem/lima/business/api lima-callao/src/main/xmi
Author: dcosse Date: 2014-08-04 16:18:32 +0200 (Mon, 04 Aug 2014) New Revision: 3892 Url: http://forge.chorem.org/projects/lima/repository/revisions/3892 Log: refs #1032 suppression de beans qui ne sont plus utilis?\195?\169 et refactoring de l'import des entr?\195?\169es EBP Removed: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountEBPComparator.java Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/ImportException.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/ImportResult.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java trunk/lima-callao/src/main/xmi/accounting-model.zargo Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2014-08-04 10:44:17 UTC (rev 3891) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2014-08-04 14:18:32 UTC (rev 3892) @@ -136,14 +136,6 @@ return financialTransactions; } - @Override - public List<FinancialTransaction> getAllFinancialTransactions(Date beginDate, Date endDate, EntryBook entryBook) { - FinancialTransactionTopiaDao transactionTopiaDao = getDaoHelper().getFinancialTransactionDao(); - List<FinancialTransaction> financialTransactions = transactionTopiaDao.findAllByDates(beginDate, endDate, entryBook); - - return financialTransactions; - } - /** Find the last three letters used * and increment them * */ 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-08-04 10:44:17 UTC (rev 3891) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-08-04 14:18:32 UTC (rev 3892) @@ -23,7 +23,6 @@ */ import com.google.common.base.Function; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -137,13 +136,6 @@ } }; - protected static final Function<FinancialTransaction, Date> GET_FINANCIAL_TRANSACTION_DATE_FUNCTION = new Function<FinancialTransaction, Date>() { - @Override - public Date apply(FinancialTransaction input) { - return input.getTransactionDate(); - } - }; - @Override public ImportResult importAccountAsCSV(String contents) { InputStream contentStream = IOUtils.toInputStream(contents); @@ -153,7 +145,6 @@ ImportModel<Account> model = new AccountModel(); Import<Account> accounts = Import.newImport(model, contentStream); // csv line index - int indexLine = 0; boolean updated; for (Account account : accounts) { try { @@ -164,9 +155,8 @@ result.increaseCreated(); } } catch (InvalidAccountNumberException e) { - result.getException().addException(indexLine, e); + result.addException(e); } - indexLine++; } } finally { IOUtils.closeQuietly(contentStream); @@ -205,15 +195,13 @@ Import<FiscalPeriod> fiscalPeriods = Import.newImport(model, contentStream); - int lineIndex = 0; try { for (FiscalPeriod fiscalPeriod : fiscalPeriods) { fiscalPeriodService.createFiscalPeriod(fiscalPeriod); - lineIndex++; result.increaseCreated(); } } catch (FiscalPeriodException e) { - result.getException().addException(lineIndex, e); + result.addException(e); } catch (MoreOneUnlockFiscalPeriodException e) { result.increaseIgnored(); } @@ -233,14 +221,12 @@ Import<FinancialTransaction> financialTransactions = Import.newImport(model, contentStream); - int lineIndex = 0; for (FinancialTransaction financialTransaction : financialTransactions) { try { financialTransactionService.createFinancialTransaction(financialTransaction); - lineIndex++; result.increaseCreated(); } catch (LockedFinancialPeriodException | LockedEntryBookException e) { - result.getException().addException(lineIndex, e); + result.addException(e); } } @@ -346,7 +332,6 @@ orderedFinancialStatements.put(rootFinancialStatement.getLabel(), rootFinancialStatement); } - int lineIndex = 0; for (FinancialStatementImport financialStatementBean : financialStatementImports) { Binder<FinancialStatementImport, FinancialStatement> binder = BinderFactory.newBinder(FinancialStatementImport.class, FinancialStatement.class); FinancialStatement financialStatement = financialStatementService.newFinancialStatement(); @@ -421,11 +406,8 @@ } result.increaseCreated(); - lineIndex++; - } catch (AlreadyExistFinancialStatement e) { - result.getException().addException(lineIndex, e); - } catch (NotAllowedLabel e) { - result.getException().addException(lineIndex, e); + } catch (AlreadyExistFinancialStatement | NotAllowedLabel e) { + result.addException(e); } } @@ -492,7 +474,6 @@ orderedVATStatements.put(vatStatement.getLabel(), vatStatement); } - int lineIndex = 0; for (VatStatementImport vatStatementBean : vatStatementImports) { Binder<VatStatementImport, VatStatement> binder = BinderFactory.newBinder(VatStatementImport.class, VatStatement.class); VatStatement vatStatement = vatStatementService.newVatStatement(); @@ -567,11 +548,8 @@ } result.increaseCreated(); - lineIndex++; - } catch (AlreadyExistVatStatement e) { - result.getException().addException(lineIndex, e); - } catch (NotAllowedLabel e) { - result.getException().addException(lineIndex, e); + } catch (AlreadyExistVatStatement | NotAllowedLabel e) { + result.addException(e); } } @@ -605,14 +583,12 @@ InputStream contentStream = IOUtils.toInputStream(datas); Import<Account> accounts = Import.newImport(model, contentStream); - int lineIndex = 0; for (Account account : accounts) { boolean updated = false; try { updated = accountService.createOrUbdateAccount(account); - lineIndex++; } catch (InvalidAccountNumberException e) { - result.getException().addException(lineIndex, e); + result.addException(e); } if (updated) { result.increaseUpdated(); @@ -643,6 +619,53 @@ return result; } + protected void basicEntriesFromEBPValidation(String datas, List<FiscalPeriod> fiscalPeriods) throws ImportEbpException { + if (datas.isEmpty()) { + throw new ImportEbpException(t("lima-business.import.ebpnoentry")); + } + // There are no valid fiscalPeriods -> exception + if (fiscalPeriods.isEmpty()) { + throw new ImportEbpException( + t("lima-business.import.nofiscalperiodopen")); + } + } + + protected List<EntryEBP> loadDateOrderedEntryEBPbeans(String datas) { + List<EntryEBP> result = new ArrayList<>(); + InputStream contentStream = null; + // convert file to bean + try { + contentStream = IOUtils.toInputStream(datas); + ImportModel<EntryEBP> model = new EntryEBPModel(); + Import<EntryEBP> importedEntryEBPs = Import.newImport(model, contentStream); + for (EntryEBP entryEBP : importedEntryEBPs) { + result.add(entryEBP); + } + // sort been by date + Collections.sort(result, new EntryEBPComparator()); + } finally { + IOUtils.closeQuietly(contentStream); + } + + return result; + } + + protected boolean validEntry(ImportResult importResult, Date dateEcr, Date fiscalPeriodsBiginDate, Date fiscalPeriodsEndingDate, Account account, String targetedAccount) { + boolean result = true; + // if entry date have fiscalperiod open + if (dateEcr.compareTo(fiscalPeriodsBiginDate) < 0 + || dateEcr.compareTo(fiscalPeriodsEndingDate) > 0) { + importResult.addException(new ImportEbpException(t("lima-business.import.entriesoutofdatesrange", dateEcr))); + result = false; + } + // if account not exist not export -> exception + else if (account == null) { + importResult.addException(new ImportEbpException(t("lima-business.import.ebpmissingaccount", targetedAccount))); + result =false; + } + return result; + } + @Override public ImportResult importEntriesFromEbp(String datas) { @@ -650,173 +673,152 @@ long before = System.currentTimeMillis(); ImportResult result = new ImportResult(); - if (datas.isEmpty()) { - result.getException().addException(0, new ImportEbpException(t("lima-business.import.ebpnoentry"))); + + // Get all the valid fiscalPeriods Ordered by date. + List<FiscalPeriod> fiscalPeriods = fiscalPeriodService.getAllUnblockedFiscalPeriodsByBeginDate(); + try { + basicEntriesFromEBPValidation(datas, fiscalPeriods); + } catch (ImportEbpException e) { + result.addException(e); return result; } List<Account> accounts = accountService.getAllAccounts(); - if (accounts == null) { - accounts = Lists.newArrayList(); - } + accounts = accounts == null ? new ArrayList<Account>() : accounts; Map<String, Account> indexedAccounts = Maps.newHashMap(Maps.uniqueIndex(accounts, GET_ACCOUNT_NUMBER)); List<EntryBook> entryBooks = entryBookService.getAllEntryBooks(); - if (entryBooks == null) { - entryBooks = Lists.newArrayList(); - } + entryBooks = entryBooks == null ? new ArrayList<EntryBook>() : entryBooks; Map<String, EntryBook> indexedEntryBooks = Maps.newHashMap(Maps.uniqueIndex(entryBooks, GET_ENTRY_BOOK_CODE)); - InputStream contentStream = null; - try { + List<EntryEBP> entryEBPs = loadDateOrderedEntryEBPbeans(datas); - contentStream = IOUtils.toInputStream(datas); - ImportModel<EntryEBP> model = new EntryEBPModel(); - Import<EntryEBP> importedEntryEBPs = Import.newImport(model, contentStream); - List<EntryEBP> entryEBPs = new ArrayList<>(); - for (EntryEBP entryEBP : importedEntryEBPs) { - entryEBPs.add(entryEBP); - } - Collections.sort(entryEBPs, new EntryEBPComparator()); + // For all entries loaded from the file + // the entry is validate (checking for valide FiscalPeriod and existing Account associated to it) + // if valid entry + // the entry entity is created and the association with it's dependant entites (Account are FinancialTransaction) are created + Date fiscalPeriodsBiginDate = fiscalPeriods.get(0).getBeginDate(); + Date fiscalPeriodsEndingDate = fiscalPeriods.get(fiscalPeriods.size() - 1).getEndDate(); + Map<EntryBook, Map<Date, FinancialTransaction>> entryBookFinancialTransactionByDate = getEntryBookFinancialTransactionOrderedByDate(fiscalPeriodsBiginDate, fiscalPeriodsEndingDate); - // Get all the valid fiscalPeriods Ordered by date. - List<FiscalPeriod> fiscalPeriods = fiscalPeriodService.getAllUnblockedFiscalPeriodsByBeginDate(); + for (EntryEBP entryEBP : entryEBPs) { + Date dateEcr = entryEBP.getDatEcr(); - // There are no valid fiscalPeriods -> exception - if (fiscalPeriods.isEmpty()) { - result.getException().addException(0, new ImportEbpException( - t("lima-business.import.nofiscalperiodopen"))); - // whe don't want to go further. - return result; + // account loading + Account account = indexedAccounts.get(entryEBP.getCompte()); + + if (!validEntry(result, dateEcr, fiscalPeriodsBiginDate, fiscalPeriodsEndingDate, account, entryEBP.getCompte())) { + continue; } + // create entry + else { + // creation of the entry + // initialisation of this attributs + Entry entry = createEntry(entryEBP, account); - // attributes declaration - FinancialTransaction financialTransaction; - Date dateEcr; - Account account; - Entry entry; - BigDecimal debit; - String entryBookCode; - EntryBook entryBook; + try { + // find financial transactions for entry period and entrybook + addEntryToFinancialTransaction(entry, entryEBP.getJournal(), indexedEntryBooks, entryBookFinancialTransactionByDate, dateEcr); - // For all entries loaded from the file - // the entry is validate (checking for valide FiscalPeriod and existing Account associated to it) - // if valid entry - // the entry entity is created and the association with it's dependant entites (Account are FinancialTransaction) are created - - int lineIndex = 0; - for (EntryEBP entryEBP : entryEBPs) { - dateEcr = entryEBP.getDatEcr(); - - // account loading - account = indexedAccounts.get(entryEBP.getCompte()); - - // if entry date have fiscalperiod open - FiscalPeriod firstFiscalPeriod = fiscalPeriods.get(0); - FiscalPeriod lastFiscalPeriod = fiscalPeriods.get(fiscalPeriods.size() - 1); - Date fiscalPeriodsBiginDate = firstFiscalPeriod.getBeginDate(); - Date fiscalPeriodsEndingDate = lastFiscalPeriod.getEndDate(); - if (dateEcr.compareTo(fiscalPeriodsBiginDate) < 0 - || dateEcr.compareTo(fiscalPeriodsEndingDate) > 0) { - result.getException().addException(lineIndex, new ImportEbpException(t("lima-business.import.entriesoutofdatesrange", dateEcr))); - lineIndex++; + } catch (LockedFinancialPeriodException | LockedEntryBookException e) { + result.addException(e); continue; } - // if account not exist not export -> exception - else if (account == null) { - result.getException().addException(lineIndex, new ImportEbpException(t("lima-business.import.ebpmissingaccount", entryEBP.getCompte()))); - lineIndex++; - continue; - } - // create entry - else { - // Association of the entry with the financialTransaction - // Each financialTransaction is associated with an entryBook - // loading of the entryBook from the db according to the entryBookCode - // if the entryBook doesn't exist it's entity is created - // if any financialTransaction exist for the entry - // a financialTransaction entity is created associated with the entryBook - // creation of the entry entity - // association between the entry and the financialTransaction is done. + } + result.increaseCreated(); + } - entryBookCode = entryEBP.getJournal(); - // entryBook loading - entryBook = indexedEntryBooks.get(entryBookCode); + if (log.isInfoEnabled()) { + long after = System.currentTimeMillis(); + log.info("Imported form EBP : " + entryEBPs.size() + " entries in " + + (after - before) + " ms"); + } + return result; + } - // if entrybook not exist create it ! - if (entryBook == null) { - entryBook = entryBookService.createNewEntryBook(); - entryBook.setCode(entryBookCode); - //financialTransaction = null; - // create it - entryBook = entryBookService.createEntryBook(entryBook); - indexedEntryBooks.put(entryBook.getCode(), entryBook); - } + protected Entry createEntry(EntryEBP entryEBP, Account account) { + Entry entry; + BigDecimal debit; + entry = financialTransactionService.createNewEntry(); - // find financial transactions for entry period. - List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(fiscalPeriodsBiginDate, fiscalPeriodsEndingDate, entryBook); - Map<Date, FinancialTransaction> financialTransactionsByDate = Maps.newHashMap(Maps.uniqueIndex(financialTransactions, GET_FINANCIAL_TRANSACTION_DATE_FUNCTION)); + // the entry has one amount witch can be Debit or Credit + // regarding the value of the boolean:debit + debit = entryEBP.getDebit(); + if (debit == null || BigDecimal.ZERO.compareTo(debit)==0) { + entry.setDebit(false); + entry.setAmount(entryEBP.getCredit()); + } else { + entry.setDebit(true); + entry.setAmount(debit); + } + entry.setAccount(account); + entry.setDescription(entryEBP.getLibelle()); + entry.setVoucher(entryEBP.getPiece()); + entry.setLettering(entryEBP.getLettre()); + return entry; + } - // creation of the entry - // initialisation of this attributs - entry = financialTransactionService.createNewEntry(); + protected void addEntryToFinancialTransaction(Entry entry, String entryBookCode, Map<String, EntryBook> indexedEntryBooks, Map<EntryBook, Map<Date, FinancialTransaction>> entryBookFinancialTransactionByDate, Date dateEcr) throws LockedFinancialPeriodException, LockedEntryBookException { - // the entry has one amount witch can be Debit or Credit - // regarding the value of the boolean:debit - debit = entryEBP.getDebit(); - if (debit == null || BigDecimal.ZERO.compareTo(debit)==0) { - entry.setDebit(false); - entry.setAmount(entryEBP.getCredit()); - } else { - entry.setDebit(true); - entry.setAmount(debit); - } - entry.setAccount(account); - entry.setDescription(entryEBP.getLibelle()); - entry.setVoucher(entryEBP.getPiece()); - entry.setLettering(entryEBP.getLettre()); + EntryBook entryBook = getEntryBook(indexedEntryBooks, entryBookCode); + Map<Date, FinancialTransaction> financialTransactionsByDate = entryBookFinancialTransactionByDate.get(entryBook); + if (financialTransactionsByDate == null) { + financialTransactionsByDate = new HashMap<>(); + entryBookFinancialTransactionByDate.put(entryBook, financialTransactionsByDate); + } - try { - // create transaction - financialTransaction = financialTransactionsByDate.get(dateEcr); - if (financialTransaction == null - || !(dateEcr.equals(financialTransaction - .getTransactionDate()) && entryBook - .getCode().equals( - financialTransaction.getEntryBook() - .getCode()))) { - // create financial transaction - financialTransaction = financialTransactionService.createNewFinancialTransaction(); - financialTransaction.setEntryBook(entryBook); - financialTransaction.setTransactionDate(dateEcr); - financialTransaction = financialTransactionService.createFinancialTransaction(financialTransaction); - financialTransactionsByDate.put(financialTransaction.getTransactionDate(), financialTransaction); - } - financialTransaction.addEntry(entry); - financialTransactionService.createEntry(entry); + // create transaction + FinancialTransaction financialTransaction = financialTransactionsByDate.get(dateEcr); + if (financialTransaction == null + || !(dateEcr.equals(financialTransaction + .getTransactionDate()) && entryBook + .getCode().equals( + financialTransaction.getEntryBook() + .getCode()))) { + // create financial transaction + financialTransaction = financialTransactionService.createNewFinancialTransaction(); + financialTransaction.setEntryBook(entryBook); + financialTransaction.setTransactionDate(dateEcr); + financialTransaction = financialTransactionService.createFinancialTransaction(financialTransaction); + financialTransactionsByDate.put(financialTransaction.getTransactionDate(), financialTransaction); + } + financialTransaction.addEntry(entry); + financialTransactionService.createEntry(entry); + } + protected EntryBook getEntryBook(Map<String, EntryBook> indexedEntryBooks, String entryBookCode) { + EntryBook entryBook; + // entryBook loading + entryBook = indexedEntryBooks.get(entryBookCode); - } catch (LockedFinancialPeriodException | LockedEntryBookException e) { - result.getException().addException(lineIndex, e); - lineIndex++; - continue; - } + // if entrybook not exist create it ! + if (entryBook == null) { + entryBook = entryBookService.createNewEntryBook(); + entryBook.setCode(entryBookCode); + //financialTransaction = null; + // create it + entryBook = entryBookService.createEntryBook(entryBook); + indexedEntryBooks.put(entryBook.getCode(), entryBook); + } + return entryBook; + } - } - result.increaseCreated(); - lineIndex++; + protected Map<EntryBook, Map<Date, FinancialTransaction>> getEntryBookFinancialTransactionOrderedByDate(Date fiscalPeriodsBiginDate, Date fiscalPeriodsEndingDate) { + Map<EntryBook, Map<Date, FinancialTransaction>> entryBookFinancialTransactionByDate = new HashMap<>(); + List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(fiscalPeriodsBiginDate, fiscalPeriodsEndingDate); + for (FinancialTransaction ft : financialTransactions) { + EntryBook eb = ft.getEntryBook(); + Map<Date, FinancialTransaction> entryBooksFTs = entryBookFinancialTransactionByDate.get(eb); + if (entryBooksFTs == null) { + entryBooksFTs = new HashMap<>(); + entryBookFinancialTransactionByDate.put(eb, entryBooksFTs); } - - if (log.isInfoEnabled()) { - long after = System.currentTimeMillis(); - log.info("Imported form EBP : " + entryEBPs.size() + " entries in " - + (after - before) + " ms"); - } - } finally { - IOUtils.closeQuietly(contentStream); + // maybe not unique financial transaction for one date. + // is there a way to know wich one to take ? + entryBooksFTs.put(ft.getTransactionDate(), ft); } - return result; + return entryBookFinancialTransactionByDate; } //####################################################################################################### Deleted: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountEBPComparator.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountEBPComparator.java 2014-08-04 10:44:17 UTC (rev 3891) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/AccountEBPComparator.java 2014-08-04 14:18:32 UTC (rev 3892) @@ -1,42 +0,0 @@ -/* - * #%L - * Lima business - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.business.utils; - -import org.chorem.lima.beans.AccountEBP; - -import java.io.Serializable; -import java.util.Comparator; - -public class AccountEBPComparator implements Serializable, Comparator<AccountEBP> { - - private static final long serialVersionUID = 1L; - - @Override - public int compare(AccountEBP o1, AccountEBP o2) { - return o1.getNumero().compareTo(o2.getNumero()); - } - -} Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java 2014-08-04 10:44:17 UTC (rev 3891) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java 2014-08-04 14:18:32 UTC (rev 3892) @@ -90,7 +90,7 @@ // make sure all account have been created Assert.assertEquals(nbEntities, accountService.getAllAccounts().size()); Assert.assertEquals(nbEntities, result.getNbCreated()); - Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty()); + Assert.assertTrue(result.getAllExceptionsByLine().isEmpty()); } finally { IOUtils.closeQuietly(contentStream); } @@ -128,7 +128,7 @@ Assert.assertEquals(nbEntities, entryBookService.getAllEntryBooks().size()); Assert.assertEquals(nbEntities, result.getNbCreated()); - Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty()); + Assert.assertTrue(result.getAllExceptionsByLine().isEmpty()); } @Test @@ -186,7 +186,7 @@ Assert.assertEquals(nbEntities, entries.size()); Assert.assertEquals(nbEntities, result.getNbCreated()); - Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty()); + Assert.assertTrue(result.getAllExceptionsByLine().isEmpty()); } @Test @@ -219,7 +219,7 @@ Assert.assertEquals(nbFiscalPeriods, fiscalPeriodService.getAllFiscalPeriods().size()); Assert.assertEquals(nbFiscalPeriods, result.getNbCreated()); - Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty()); + Assert.assertTrue(result.getAllExceptionsByLine().isEmpty()); } @Test @@ -249,7 +249,7 @@ ImportResult importResult = importResults.get(i); log.info(imported[i] +": created:"+importResult.getNbCreated() + " updated:" + importResult.getNbUpdated() + " ignoded:" + importResult.getNbIgnored()); Assert.assertTrue(importResult.getNbCreated()>0); - Assert.assertTrue(importResult.getException().getAllExceptionsByLine().isEmpty()); + Assert.assertTrue(importResult.getAllExceptionsByLine().isEmpty()); } } @@ -352,7 +352,7 @@ result = importService.importFinancialStatementsAsCSV(bcr_developed); - Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty()); + Assert.assertTrue(result.getAllExceptionsByLine().isEmpty()); Assert.assertEquals(162, result.getNbCreated()); Assert.assertEquals(162, financialStatementService.getAllFinancialStatements().size()); FinancialStatement actifImmobiliseStatement = financialStatementService.getFinancialStatementByLabel("ACTIF IMMOBILISÉ"); @@ -373,7 +373,7 @@ result = importService.importVATStatementsAsCSV(bcr_developed); - Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty()); + Assert.assertTrue(result.getAllExceptionsByLine().isEmpty()); Assert.assertEquals(55, result.getNbCreated()); Assert.assertEquals(55, vatStatementService.getAllVatStatements().size()); } @@ -412,14 +412,22 @@ InputStream entriesStream = ImportExportServiceTest.class.getResourceAsStream("/ebp/ecritures.txt"); String entriesData = IOUtils.toString(entriesStream, "ISO-8859-1"); ImportResult result = importService.importEntriesFromEbp(entriesData); - Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty()); + Assert.assertTrue(result.getAllExceptionsByLine().isEmpty()); Assert.assertEquals(28, result.getNbCreated()); entriesStream.close(); EntryBook entryBook = entryBookService.getEntryBookByCode("AN"); - List<FinancialTransaction> _31JanuaryFinancialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("January 31, 2010"), df.parse("January 31, 2010"), entryBook); + List<FinancialTransaction> _31JanuaryFinancialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("January 31, 2010"), df.parse("January 31, 2010")); - Assert.assertEquals(1, _31JanuaryFinancialTransactions.size()); + Assert.assertEquals(3, _31JanuaryFinancialTransactions.size()); + + List<FinancialTransaction> _AN31JanuaryFinancialTransactions = new ArrayList<>(); + for (FinancialTransaction ft : _31JanuaryFinancialTransactions) { + if (ft.getEntryBook().getCode().equals("AN")){ + _AN31JanuaryFinancialTransactions.add(ft); + } + } + Assert.assertEquals(1, _AN31JanuaryFinancialTransactions.size()); FinancialTransaction financialTransaction = _31JanuaryFinancialTransactions.get(0); Collection<Entry> entries = financialTransaction.getEntry(); for (Entry entry : entries) { @@ -503,7 +511,7 @@ Assert.assertEquals(nbEntities, entries.size()); Assert.assertEquals(nbEntities, result.getNbCreated()); - Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty()); + Assert.assertTrue(result.getAllExceptionsByLine().isEmpty()); for (Entry entry : entries) { Assert.assertTrue(42.0 == entry.getAmount().doubleValue()); } Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/ImportException.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/ImportException.java 2014-08-04 10:44:17 UTC (rev 3891) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/ImportException.java 2014-08-04 14:18:32 UTC (rev 3892) @@ -31,12 +31,4 @@ protected Map<Integer, LimaException> allExceptions = new HashMap<>(); - - public void addException(Integer indexLine, LimaException e) { - allExceptions.put(indexLine, e); - } - - public Map<Integer, LimaException> getAllExceptionsByLine() { - return allExceptions; - } } Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/ImportResult.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/ImportResult.java 2014-08-04 10:44:17 UTC (rev 3891) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/ImportResult.java 2014-08-04 14:18:32 UTC (rev 3892) @@ -23,6 +23,8 @@ */ import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; /** * Created by davidcosse on 24/07/14. @@ -35,13 +37,15 @@ protected int nbIgnored; - protected ImportException exception; + protected int lineIndex; + protected Map<Integer, LimaException> allExceptions = new HashMap<>(); + public ImportResult() { - this.exception = new ImportException(); nbCreated = 0; nbUpdated = 0; nbIgnored = 0; + lineIndex = 0; } public int getNbCreated() { @@ -56,19 +60,27 @@ return nbIgnored; } - public ImportException getException() { - return exception; + public void increaseCreated() { + nbCreated++; + lineIndex++; } - public int increaseCreated() { - return nbCreated++; + public void increaseUpdated() { + nbUpdated++; + lineIndex++; } - public int increaseUpdated() { - return nbUpdated++; + public void increaseIgnored() { + nbIgnored++; + lineIndex++; } - public int increaseIgnored() { - return nbIgnored++; + public void addException(LimaException e) { + allExceptions.put(this.lineIndex, e); + lineIndex++; } + + public Map<Integer, LimaException> getAllExceptionsByLine() { + return allExceptions; + } } Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java 2014-08-04 10:44:17 UTC (rev 3891) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java 2014-08-04 14:18:32 UTC (rev 3892) @@ -80,8 +80,6 @@ List<FinancialTransaction> getAllFinancialTransactions(Date beginDate, Date endDate); - List<FinancialTransaction> getAllFinancialTransactions(Date beginDate, Date endDate, EntryBook entryBook); - List<FinancialTransaction> getAllFinancialTransactions(FinancialPeriod period, EntryBook entryBook); List<FinancialTransaction> getAllInexactFinancialTransactions(FiscalPeriod fiscalPeriod); Modified: trunk/lima-callao/src/main/xmi/accounting-model.zargo =================================================================== (Binary files differ)
participants (1)
-
dcosse@users.chorem.org