Lima-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
August 2014
- 1 participants
- 25 discussions
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
by dcosse@users.chorem.org 04 Aug '14
by dcosse@users.chorem.org 04 Aug '14
04 Aug '14
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)
1
0
r3891 - in trunk: . lima-business/src/main/java/org/chorem/lima/business/ejb lima-business/src/test/java/org/chorem/lima/business lima-business/src/test/resources/ebp lima-business-api/src/main/java/org/chorem/lima/business/api lima-callao/src/main/java/org/chorem/lima/entity
by dcosse@users.chorem.org 04 Aug '14
by dcosse@users.chorem.org 04 Aug '14
04 Aug '14
Author: dcosse
Date: 2014-08-04 12:44:17 +0200 (Mon, 04 Aug 2014)
New Revision: 3891
Url: http://forge.chorem.org/projects/lima/repository/revisions/3891
Log:
refs #1032 import des ?\195?\169critures depuis EBP
Modified:
trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/EntryBookService.java
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/FiscalPeriodService.java
trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java
trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java
trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.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/FiscalPeriodServiceImpl.java
trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java
trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java
trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/VatStatementServiceImpl.java
trunk/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java
trunk/lima-business/src/test/resources/ebp/ecritures.txt
trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryTopiaDao.java
trunk/pom.xml
Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java
===================================================================
--- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2014-08-01 15:52:09 UTC (rev 3890)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2014-08-04 10:44:17 UTC (rev 3891)
@@ -129,7 +129,7 @@
for (int i = 0; i < size; i++) {
FinancialStatementAmounts fStatementAmounts =
financialStatementAmounts.get(i);
- if (fStatementAmounts.getLevel() == 1 && !fStatementAmounts.getSubAmount()) {
+ if (fStatementAmounts.getLevel() == 1 && !fStatementAmounts.isSubAmount()) {
if (first) {
first = false;
} else {
@@ -200,7 +200,7 @@
}
//Phrase phrase;
String tabLabel = "";
- if (financialStatementAmount.getHeader()) {
+ if (financialStatementAmount.isHeader()) {
tabLabel = boldBegin + tab + label + boldEnd;
} else {
tabLabel = tab + label;
@@ -521,8 +521,8 @@
balanceReport += "\t\t<tbody>\n";
for (ReportsDatas reportsDatas : list) {
- String soldeDebit = String.valueOf(reportsDatas.getSoldeDebit() ? reportsDatas.getAmountSolde() : 0);
- String soldeCredit = String.valueOf(reportsDatas.getSoldeDebit() ? 0 : reportsDatas.getAmountSolde());
+ String soldeDebit = String.valueOf(reportsDatas.isSoldeDebit() ? reportsDatas.getAmountSolde() : 0);
+ String soldeCredit = String.valueOf(reportsDatas.isSoldeDebit() ? 0 : reportsDatas.getAmountSolde());
String [] columnsBalanceAmount = {reportsDatas.getAccount().getAccountNumber(), reportsDatas.getAccount().getLabel(),
reportsDatas.getAmountDebit().toString(), reportsDatas.getAmountCredit().toString(),
@@ -532,7 +532,7 @@
currentAmountDebit = currentAmountDebit.add(reportsDatas.getAmountDebit());
currentAmountCredit = currentAmountCredit.add(reportsDatas.getAmountCredit());
- if (reportsDatas.getSoldeDebit()) {
+ if (reportsDatas.isSoldeDebit()) {
currentSoldeDebit = currentSoldeDebit.add(reportsDatas.getAmountSolde());
} else {
currentSoldeCredit = currentSoldeCredit.add(reportsDatas.getAmountSolde());
@@ -668,7 +668,7 @@
for (GeneralEntryBooksDatas generalEntryBooksDataInList : list) {
if (!generalEntryBooksDataInList.getDebit().equals(BigDecimal.ZERO) && !generalEntryBooksDataInList.getCredit().equals(BigDecimal.ZERO)) {
- if (!generalEntryBooksDataInList.getAmount() && !generalEntryBooksDataInList.getSubAmount()) {
+ if (!generalEntryBooksDataInList.isAmount() && !generalEntryBooksDataInList.isSubAmount()) {
String code;
String description;
if (!entryBookCode.equals(generalEntryBooksDataInList.getCode())) {
@@ -687,7 +687,7 @@
even = !even;
} else {
String amount;
- if (generalEntryBooksDataInList.getAmount()) {
+ if (generalEntryBooksDataInList.isAmount()) {
amount = t("lima-business.document.amounts");
} else {
amount = t("lima-business.document.amountsperiod", generalEntryBooksDataInList.getPeriod());
Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java
===================================================================
--- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2014-08-01 15:52:09 UTC (rev 3890)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2014-08-04 10:44:17 UTC (rev 3891)
@@ -58,6 +58,13 @@
public class EntryBookServiceImpl extends AbstractLimaService implements EntryBookService {
@Override
+ public EntryBook createNewEntryBook(){
+ EntryBookTopiaDao entryBookTopiaDao = getDaoHelper().getEntryBookDao();
+ EntryBook result = entryBookTopiaDao.newInstance();
+ return result;
+ }
+
+ @Override
public boolean createOrUpdateEntryBook(EntryBook entryBook) {
EntryBookTopiaDao entryBookTopiaDao = getDaoHelper().getEntryBookDao();
EntryBook existingEntryBook = entryBookTopiaDao.forCodeEquals(entryBook.getCode()).findUniqueOrNull();
Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java
===================================================================
--- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2014-08-01 15:52:09 UTC (rev 3890)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2014-08-04 10:44:17 UTC (rev 3891)
@@ -427,7 +427,7 @@
true,
selectedBeginDate,
selectedEndDate);
- if (reportsDatas.getSoldeDebit()) {
+ if (reportsDatas.isSoldeDebit()) {
debitTemp = debitTemp.add(reportsDatas.getAmountSolde());
} else {
creditTemp = creditTemp.add(reportsDatas.getAmountSolde());
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-01 15:52:09 UTC (rev 3890)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2014-08-04 10:44:17 UTC (rev 3891)
@@ -97,6 +97,13 @@
}
@Override
+ public Entry createNewEntry(){
+ EntryTopiaDao entryTopiaDao = getDaoHelper().getEntryDao();
+ Entry result = entryTopiaDao.newInstance();
+ return result;
+ }
+
+ @Override
public FinancialTransaction createFinancialTransaction(FinancialTransaction financialtransaction)
throws LockedFinancialPeriodException, LockedEntryBookException {
@@ -129,6 +136,14 @@
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/FiscalPeriodServiceImpl.java
===================================================================
--- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2014-08-01 15:52:09 UTC (rev 3890)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2014-08-04 10:44:17 UTC (rev 3891)
@@ -198,6 +198,14 @@
}
@Override
+ public List<FiscalPeriod> getAllUnblockedFiscalPeriodsByBeginDate() {
+
+ FiscalPeriodTopiaDao fiscalPeriodTopiaDao = getDaoHelper().getFiscalPeriodDao();
+ List<FiscalPeriod> result = fiscalPeriodTopiaDao.forLockedEquals(false).setOrderByArguments(FiscalPeriod.PROPERTY_BEGIN_DATE).findAll();
+ return result;
+ }
+
+ @Override
public FiscalPeriod getLastFiscalPeriod() {
FiscalPeriodTopiaDao fiscalPeriodTopiaDao = getDaoHelper().getFiscalPeriodDao();
@@ -405,7 +413,7 @@
beginEntry.setFinancialTransaction(endfinancialTransaction);
beginEntry.setAccount(report.getAccount());
beginEntry.setAmount(report.getAmountSolde().abs());
- beginEntry.setDebit(!report.getSoldeDebit());
+ beginEntry.setDebit(!report.isSoldeDebit());
financialTransactionService.createEntry(beginEntry);
//save amounts inside account number 891
@@ -415,7 +423,7 @@
beginEntry.setFinancialTransaction(endfinancialTransaction);
beginEntry.setAccount(endRetainedAccount);
beginEntry.setAmount(report.getAmountSolde().abs());
- beginEntry.setDebit(report.getSoldeDebit());
+ beginEntry.setDebit(report.isSoldeDebit());
financialTransactionService.createEntry(beginEntry);
//open new year accounts if new year exists and a date has been found for the transaction
@@ -426,7 +434,7 @@
beginEntry.setFinancialTransaction(beginfinancialTransaction);
beginEntry.setAccount(report.getAccount());
beginEntry.setAmount(report.getAmountSolde().abs());
- beginEntry.setDebit(report.getSoldeDebit());
+ beginEntry.setDebit(report.isSoldeDebit());
financialTransactionService.createEntry(beginEntry);
//close account by removing amount from account number 890
beginEntry = new EntryImpl();
@@ -435,7 +443,7 @@
beginEntry.setFinancialTransaction(beginfinancialTransaction);
beginEntry.setAccount(endRetainedAccount);
beginEntry.setAmount(report.getAmountSolde().abs());
- beginEntry.setDebit(!report.getSoldeDebit());
+ beginEntry.setDebit(!report.isSoldeDebit());
financialTransactionService.createEntry(beginEntry);
}
}
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-01 15:52:09 UTC (rev 3890)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-08-04 10:44:17 UTC (rev 3891)
@@ -62,12 +62,9 @@
import org.chorem.lima.business.ejb.ebp.EntryBookEBPModel;
import org.chorem.lima.business.ejb.ebp.EntryEBPModel;
import org.chorem.lima.business.utils.EntryEBPComparator;
-import org.chorem.lima.business.utils.FiscalPeriodComparator;
import org.chorem.lima.entity.Account;
import org.chorem.lima.entity.Entry;
import org.chorem.lima.entity.EntryBook;
-import org.chorem.lima.entity.EntryBookImpl;
-import org.chorem.lima.entity.EntryImpl;
import org.chorem.lima.entity.FinancialStatement;
import org.chorem.lima.entity.FinancialTransaction;
import org.chorem.lima.entity.FiscalPeriod;
@@ -140,6 +137,13 @@
}
};
+ 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);
@@ -642,15 +646,15 @@
@Override
public ImportResult importEntriesFromEbp(String datas) {
+ // use for logs
+ long before = System.currentTimeMillis();
+
ImportResult result = new ImportResult();
if (datas.isEmpty()) {
result.getException().addException(0, new ImportEbpException(t("lima-business.import.ebpnoentry")));
return result;
}
- // use for logs
- long before = System.currentTimeMillis();
-
List<Account> accounts = accountService.getAllAccounts();
if (accounts == null) {
accounts = Lists.newArrayList();
@@ -665,22 +669,18 @@
InputStream contentStream = null;
try {
- contentStream = IOUtils.toInputStream(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());
// Get all the valid fiscalPeriods Ordered by date.
- List<FiscalPeriod> fiscalPeriods = fiscalPeriodService
- .getAllUnblockedFiscalPeriods();
- Collections.sort(fiscalPeriods, new FiscalPeriodComparator());
+ List<FiscalPeriod> fiscalPeriods = fiscalPeriodService.getAllUnblockedFiscalPeriodsByBeginDate();
// There are no valid fiscalPeriods -> exception
if (fiscalPeriods.isEmpty()) {
@@ -731,34 +731,6 @@
// create entry
else {
-
- // find financial transactions for entry period.
- List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(fiscalPeriodsBiginDate, fiscalPeriodsEndingDate);
- Map<Date, FinancialTransaction> financialTransactionsByDate = new HashMap<>();
- for (FinancialTransaction transaction : financialTransactions) {
- financialTransactionsByDate.put(transaction.getTransactionDate(), transaction);
- }
-
- // creation of the entry
- // initialisation of this attributs
-
- entry = new EntryImpl();
-
- // 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());
-
// 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
@@ -774,13 +746,37 @@
// if entrybook not exist create it !
if (entryBook == null) {
- entryBook = new EntryBookImpl();
+ entryBook = entryBookService.createNewEntryBook();
entryBook.setCode(entryBookCode);
//financialTransaction = null;
// create it
entryBook = entryBookService.createEntryBook(entryBook);
indexedEntryBooks.put(entryBook.getCode(), entryBook);
}
+
+ // 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));
+
+ // creation of the entry
+ // initialisation of this attributs
+ entry = financialTransactionService.createNewEntry();
+
+ // 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());
+
try {
// create transaction
financialTransaction = financialTransactionsByDate.get(dateEcr);
@@ -795,10 +791,12 @@
financialTransaction.setEntryBook(entryBook);
financialTransaction.setTransactionDate(dateEcr);
financialTransaction = financialTransactionService.createFinancialTransaction(financialTransaction);
+ financialTransactionsByDate.put(financialTransaction.getTransactionDate(), financialTransaction);
}
financialTransaction.addEntry(entry);
financialTransactionService.createEntry(entry);
+
} catch (LockedFinancialPeriodException | LockedEntryBookException e) {
result.getException().addException(lineIndex, e);
lineIndex++;
Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java
===================================================================
--- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2014-08-01 15:52:09 UTC (rev 3890)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2014-08-04 10:44:17 UTC (rev 3891)
@@ -339,7 +339,7 @@
balanceTrial.addReportsDatas(reportsDatas);
}
- if (reportsDatas.getSoldeDebit()) {
+ if (reportsDatas.isSoldeDebit()) {
debit = debit.add(amount);
} else {
credit = credit.add(amount);
Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/VatStatementServiceImpl.java
===================================================================
--- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/VatStatementServiceImpl.java 2014-08-01 15:52:09 UTC (rev 3890)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/VatStatementServiceImpl.java 2014-08-04 10:44:17 UTC (rev 3891)
@@ -216,7 +216,7 @@
ReportsDatas reportsDatas = reportService.
generateAccountsReports(account, true,
selectedBeginDate, selectedEndDate);
- if (reportsDatas.getSoldeDebit()) {
+ if (reportsDatas.isSoldeDebit()) {
debitTemp = debitTemp.add(reportsDatas.getAmountSolde());
} else {
creditTemp = creditTemp.add(reportsDatas.getAmountSolde());
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-01 15:52:09 UTC (rev 3890)
+++ trunk/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java 2014-08-04 10:44:17 UTC (rev 3891)
@@ -47,6 +47,7 @@
import java.io.InputStream;
import java.nio.charset.Charset;
import java.text.ParseException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.zip.ZipEntry;
@@ -385,19 +386,45 @@
fiscalPeriod.setEndDate(df.parse("December 31, 2010"));
fiscalPeriodService.createFiscalPeriod(fiscalPeriod);
- String [] accountNumbers = {"62610000","44566000","40104200","62510000","40100000","401TEEMP","51200000","60630000","411TECLI"};
+ String [] accountNumbers = {"62610000","40104200","62510000","40100000","401TEEMP","51200000","60630000","411TECLI"};
+
for (String accountNumber : accountNumbers) {
Account account = new AccountImpl();
account.setAccountNumber(accountNumber);
accountService.createAccount(account);
}
+ String [] _31JanuaryFTaccountNumbers = {"44566000","51210000", "40810000", "50300000", "411XAGAG", "65800000", "27180000", "27618000"};
+ List<Account> _31JanuaryFTaccounts = new ArrayList<>();
+ for (String accountNumber : _31JanuaryFTaccountNumbers) {
+ Account account = new AccountImpl();
+ account.setAccountNumber(accountNumber);
+ _31JanuaryFTaccounts.add(accountService.createAccount(account));
+ }
+
+ String [] entyBookCodes = {"AC", "AN", "BQ", "VE"};
+ for (String entryBookCode : entyBookCodes) {
+ EntryBook entryBook = entryBookService.createNewEntryBook();
+ entryBook.setCode(entryBookCode);
+ entryBookService.createEntryBook(entryBook);
+ }
+
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.assertEquals(19, result.getNbCreated());
+ 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);
+
+ Assert.assertEquals(1, _31JanuaryFinancialTransactions.size());
+ FinancialTransaction financialTransaction = _31JanuaryFinancialTransactions.get(0);
+ Collection<Entry> entries = financialTransaction.getEntry();
+ for (Entry entry : entries) {
+ Assert.assertNotEquals(-1, _31JanuaryFTaccounts.indexOf(entry.getAccount()));
+ }
}
@Test
Modified: trunk/lima-business/src/test/resources/ebp/ecritures.txt
===================================================================
--- trunk/lima-business/src/test/resources/ebp/ecritures.txt 2014-08-01 15:52:09 UTC (rev 3890)
+++ trunk/lima-business/src/test/resources/ebp/ecritures.txt 2014-08-04 10:44:17 UTC (rev 3891)
@@ -18,3 +18,12 @@
BQ,51200000,15/02/2010,,16/02/2010,15/02/2010,,VIRT,,MonFournisseur,0,32.17,,0,0,0,0,0,,,,0,,,0x00000000,0,,,,,,,,Non
BQ,411TECLI,20/04/2010,,19/04/2010,20/04/2010,,VIRT,,Test Client,0,5395.44,,0,0,0,0,0,AAV,,,0,,,0x00000000,0,,19/04/2010,,,,,,Non
VE,411TECLI,15/03/2010,,26/03/2010,15/03/2010,,FA100315-01,,Test Client,5395.44,0,,0,0,0,0,0,AAV,,,0,,,0x00000000,0,,19/04/2010,,,,,,Non
+AC,44566000,31/01/2010,,31/01/2010,31/01/2010,,298,,Forfait Adsl ovh 12,1.48,0,,0,0,0,0,0,,,,0,,,0x00000000,0,,21/01/2013,,,,,,Non
+AN,27180000,31/01/2010,,31/01/2010,31/01/2010,,AN,,REPORT A NOUVEAU,1,0,,0,0,0,0,0,,,,0,,,0x00000000,0,,,,,,,,Non
+AN,27618000,31/01/2010,,31/01/2010,31/01/2010,,AN,,REPORT A NOUVEAU,43756.22,0,,0,0,0,0,0,,,,0,,,0x00000000,0,,,,,,,,Non
+AN,40810000,31/01/2010,,31/01/2010,31/01/2010,,AN,,REPORT A NOUVEAU,0,146.7,,0,0,0,0,0,,,,0,,,0x00000000,0,,,,,,,,Non
+AN,51210000,31/01/2010,,31/01/2010,31/01/2010,,AN,,REPORT A NOUVEAU,307923.64,0,,0,0,0,0,0,,,,0,,,0x00000000,0,,,,,,,,Non
+BQ,411XAGAG,31/01/2010,,31/01/2010,31/01/2010,,VIRT,,XAGA Group,0,1973.4,,0,0,0,0,0,AAA,,,0,,,0x00000000,0,,10/01/2012,,,,,,Non
+BQ,50300000,31/01/2010,,31/01/2010,31/01/2010,,VIRT,,rachat FCP 11/07/2011 saisie � l'envers,0,31706.8,,0,0,0,0,0,,,,0,,,0x00000000,0,,,,,,,,Non
+BQ,50300000,31/01/2010,,31/01/2010,31/01/2010,,VIRT,,rachat FCP 11/07/2011 sasie � l'envers,0,31706.8,,0,0,0,0,0,,,,0,,,0x00000000,0,,,,,,,,Non
+BQ,65800000,31/01/2010,,31/01/2010,31/01/2010,,VIRT,,ecart bq 31/12/2011,0.83,0,,0,0,0,0,0,,,,0,,,0x00000000,0,,,,,,,,Non
Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/EntryBookService.java
===================================================================
--- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/EntryBookService.java 2014-08-01 15:52:09 UTC (rev 3890)
+++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/EntryBookService.java 2014-08-04 10:44:17 UTC (rev 3891)
@@ -60,6 +60,12 @@
List<EntryBook> getAllEntryBooks();
/**
+ * Create new EntryBook not persisted yet.
+ * @return
+ */
+ EntryBook createNewEntryBook();
+
+ /**
* Create or update the given entry book
* @param entryBook
* @return true if updated, false if created
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-01 15:52:09 UTC (rev 3890)
+++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java 2014-08-04 10:44:17 UTC (rev 3891)
@@ -59,6 +59,12 @@
*/
FinancialTransaction createNewFinancialTransaction();
+ /**
+ * Create new Entry not persisted yet.
+ * @return
+ */
+ Entry createNewEntry();
+
FinancialTransaction createFinancialTransaction(FinancialTransaction financialtransaction)
throws LockedFinancialPeriodException, LockedEntryBookException;
@@ -74,6 +80,8 @@
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-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java
===================================================================
--- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java 2014-08-01 15:52:09 UTC (rev 3890)
+++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java 2014-08-04 10:44:17 UTC (rev 3891)
@@ -58,6 +58,8 @@
List<FiscalPeriod> getAllUnblockedFiscalPeriods();
+ List<FiscalPeriod> getAllUnblockedFiscalPeriodsByBeginDate();
+
FiscalPeriod getLastFiscalPeriod();
FiscalPeriod createFiscalPeriod(FiscalPeriod fiscalPeriod)
Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryTopiaDao.java
===================================================================
--- trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryTopiaDao.java 2014-08-01 15:52:09 UTC (rev 3890)
+++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/EntryTopiaDao.java 2014-08-04 10:44:17 UTC (rev 3891)
@@ -200,12 +200,12 @@
}
String alias = builder.getAlias();
- if (!filter.getDisplayLettered() && filter.getDisplayUnlettred()){
+ if (!filter.isDisplayLettered() && filter.isDisplayUnlettred()){
builder.addWhereClause( alias + "." + Entry.PROPERTY_LETTERING + " is null " +
"OR " + alias + "." + Entry.PROPERTY_LETTERING + " = ''");
- } else if (filter.getDisplayLettered() && !filter.getDisplayUnlettred()){
+ } else if (filter.isDisplayLettered() && !filter.isDisplayUnlettred()){
builder.addWhereClause( alias + "." + Entry.PROPERTY_LETTERING + " is not null " +
"OR " + alias + "." + Entry.PROPERTY_LETTERING + " != ''");
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-08-01 15:52:09 UTC (rev 3890)
+++ trunk/pom.xml 2014-08-04 10:44:17 UTC (rev 3891)
@@ -177,7 +177,7 @@
<nuitonDecoratorVersion>3.0-alpha-3</nuitonDecoratorVersion>
<nuitonProfilingVersion>2.7.1</nuitonProfilingVersion>
<nuitonCsvVersion>3.0-rc-2</nuitonCsvVersion>
- <eugeneVersion>2.12-SNAPSHOT</eugeneVersion>
+ <eugeneVersion>3.0-SNAPSHOT</eugeneVersion>
<nuitonI18nVersion>3.1</nuitonI18nVersion>
<topiaVersion>3.0-SNAPSHOT</topiaVersion>
1
0
r3890 - in trunk: lima-business/src/main/java/org/chorem/lima/business/ejb lima-business-api/src/main/java/org/chorem/lima/business/api lima-swing/src/main/java/org/chorem/lima/ui/importexport
by dcosse@users.chorem.org 01 Aug '14
by dcosse@users.chorem.org 01 Aug '14
01 Aug '14
Author: dcosse
Date: 2014-08-01 17:52:09 +0200 (Fri, 01 Aug 2014)
New Revision: 3890
Url: http://forge.chorem.org/projects/lima/repository/revisions/3890
Log:
refs #1032 correction sur import export
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/ImportService.java
trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java
trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.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-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java
Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java
===================================================================
--- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2014-08-01 14:29:33 UTC (rev 3889)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2014-08-01 15:52:09 UTC (rev 3890)
@@ -36,6 +36,8 @@
import org.chorem.lima.business.utils.AccountComparator;
import org.chorem.lima.entity.Account;
import org.chorem.lima.entity.AccountTopiaDao;
+import org.nuiton.util.beans.Binder;
+import org.nuiton.util.beans.BinderFactory;
import javax.ejb.Remote;
import javax.ejb.Stateless;
@@ -219,8 +221,12 @@
// DAO
AccountTopiaDao accountDao = getDaoHelper().getAccountDao();
- accountingRules.updateAccountRules(account);
- Account result = accountDao.update(account);
+ Account originalAccount = accountDao.forAccountNumberEquals(account.getAccountNumber()).findUnique();
+ Binder<Account, Account> binder = BinderFactory.newBinder(Account.class, Account.class);
+ binder.copy(account, originalAccount, Account.PROPERTY_LABEL, Account.PROPERTY_THIRD_PARTY);
+ //binder.copyExcluding(account, originalAccount, Account.PROPERTY_TOPIA_ID);
+ accountingRules.updateAccountRules(originalAccount);
+ Account result = accountDao.update(originalAccount);
return result;
}
Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java
===================================================================
--- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2014-08-01 14:29:33 UTC (rev 3889)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2014-08-01 15:52:09 UTC (rev 3890)
@@ -107,7 +107,7 @@
@EJB
protected IdentityService identityService;
- public static final String JAVA_IO_TMPDIR = "java.io.tmpdir";
+ public static final String JAVA_IO_TMPDIR = System.getProperty("java.io.tmpdir")+"/";
protected File exportAccountsFile(String charset) throws Exception {
AccountTopiaDao accountTopiaDao = getDaoHelper().getAccountDao();
@@ -115,7 +115,7 @@
File result = null;
if (entities != null && entities.size() > 0) {
AccountModel model = new AccountModel();
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ String tmpDir = JAVA_IO_TMPDIR;
result = new File(tmpDir + "accounts.csv");
Export.exportToFile(model, entities, result, Charset.forName(charset));
@@ -143,7 +143,7 @@
List<EntryBook> entities = entryBookTopiaDao.findAll();
File result = null;
if (entities != null && !entities.isEmpty()) {
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ String tmpDir = JAVA_IO_TMPDIR;
result = new File(tmpDir + "entryBooks.csv");
EntryBookModel model = new EntryBookModel();
Export.exportToFile(model, entities, result, Charset.forName(charset));
@@ -175,7 +175,7 @@
File result = null;
if (entities != null && !entities.isEmpty()) {
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ String tmpDir = JAVA_IO_TMPDIR;
result = new File(tmpDir + "fiscalPeriod.csv");
FiscalPeriodModel model = new FiscalPeriodModel();
Export.exportToFile(model, entities, result, Charset.forName(charset));
@@ -208,7 +208,7 @@
List<FinancialTransaction> entities = financialTransactionTopiaDao.findAll();
if (entities != null && !entities.isEmpty()) {
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ String tmpDir = JAVA_IO_TMPDIR;
result = new File(tmpDir + "financialTransactions.csv");
FinancialTransactionModel model = new FinancialTransactionModel(entryBookService);
Export.exportToFile(model, entities, result, Charset.forName(charset));
@@ -223,7 +223,7 @@
File result = null;
if (entities != null && !entities.isEmpty()) {
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ String tmpDir = JAVA_IO_TMPDIR;
result = new File(tmpDir + "entries.csv");
EntryModel model = new EntryModel(accountService, financialTransactionService , humanReadable);
Export.exportToFile(model, entities, result, Charset.forName(charset));
@@ -260,7 +260,7 @@
@Override
public String exportFinancialStatements(String charset) throws Exception {
String stResult = null;
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ String tmpDir = JAVA_IO_TMPDIR;
File fileResult = new File(tmpDir + "financialStatements.csv");
List<FinancialStatement> rootFinancialStatements = financialStatementService.getRootFinancialStatements();
@@ -289,7 +289,7 @@
@Override
public String exportVatStatements(String charset) throws Exception {
String stResult = null;
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ String tmpDir = JAVA_IO_TMPDIR;
File fileResult = new File(tmpDir + "vatStatements.csv");
List<VatStatement> rootVatStatements = vatStatementService.getRootVatStatements();
@@ -313,7 +313,7 @@
List<Identity> identities = new ArrayList<>();
identities.add(identity);
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ String tmpDir = JAVA_IO_TMPDIR;
result = new File(tmpDir + "identity.csv");
IdentityModel model = new IdentityModel();
Export.exportToFile(model, identities, result, Charset.forName(charset));
@@ -371,7 +371,7 @@
List<Account> accounts = accountService.getAllAccounts();
if (accounts != null && !accounts.isEmpty()) {
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ String tmpDir = JAVA_IO_TMPDIR;
result = new File(tmpDir + "accounts.csv");
AccountEBPModel model = new AccountEBPModel();
Export.exportToFile(model, accounts, result, Charset.forName(charset));
@@ -391,7 +391,7 @@
if (entries != null && !entries.isEmpty()) {
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ String tmpDir = JAVA_IO_TMPDIR;
result = new File(tmpDir + "entries.csv");
EntryEBPModel model = new EntryEBPModel();
Export.exportToFile(model, entries, result, Charset.forName(charset));
@@ -411,7 +411,7 @@
if (entryBooks != null && !entryBooks.isEmpty()) {
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ String tmpDir = JAVA_IO_TMPDIR;
result = new File(tmpDir + "entryBooks.csv");
EntryBookModel model = new EntryBookModel();
Export.exportToFile(model, entryBooks, result, Charset.forName(charset));
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-01 14:29:33 UTC (rev 3889)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2014-08-01 15:52:09 UTC (rev 3890)
@@ -90,6 +90,13 @@
protected static final Log log = LogFactory.getLog(FinancialTransactionServiceImpl.class);
@Override
+ public FinancialTransaction createNewFinancialTransaction(){
+ FinancialTransactionTopiaDao financialtransactionTopiaDao = getDaoHelper().getFinancialTransactionDao();
+ FinancialTransaction financialTransaction = financialtransactionTopiaDao.newInstance();
+ return financialTransaction;
+ }
+
+ @Override
public FinancialTransaction createFinancialTransaction(FinancialTransaction financialtransaction)
throws LockedFinancialPeriodException, LockedEntryBookException {
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-01 14:29:33 UTC (rev 3889)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-08-01 15:52:09 UTC (rev 3890)
@@ -70,7 +70,6 @@
import org.chorem.lima.entity.EntryImpl;
import org.chorem.lima.entity.FinancialStatement;
import org.chorem.lima.entity.FinancialTransaction;
-import org.chorem.lima.entity.FinancialTransactionImpl;
import org.chorem.lima.entity.FiscalPeriod;
import org.chorem.lima.entity.Identity;
import org.chorem.lima.entity.VatStatement;
@@ -236,10 +235,8 @@
financialTransactionService.createFinancialTransaction(financialTransaction);
lineIndex++;
result.increaseCreated();
- } catch (LockedFinancialPeriodException e) {
+ } catch (LockedFinancialPeriodException | LockedEntryBookException e) {
result.getException().addException(lineIndex, e);
- } catch (LockedEntryBookException e) {
- result.getException().addException(lineIndex, e);
}
}
@@ -623,6 +620,26 @@
}
@Override
+ public ImportResult importEntryBookFromEbp(String datas) {
+ ImportResult result = new ImportResult();
+
+ ImportModel<EntryBook> model = new EntryBookEBPModel();
+
+ InputStream contentStream = IOUtils.toInputStream(datas);
+ Import<EntryBook> entryBooks = Import.newImport(model, contentStream);
+
+ for (EntryBook entryEBP : entryBooks) {
+ boolean updated = entryBookService.createOrUpdateEntryBook(entryEBP);
+ if (updated) {
+ result.increaseUpdated();
+ } else {
+ result.increaseCreated();
+ }
+ }
+ return result;
+ }
+
+ @Override
public ImportResult importEntriesFromEbp(String datas) {
ImportResult result = new ImportResult();
@@ -674,7 +691,7 @@
}
// attributes declaration
- FinancialTransaction financialTransaction = null;
+ FinancialTransaction financialTransaction;
Date dateEcr;
Account account;
Entry entry;
@@ -774,14 +791,12 @@
financialTransaction.getEntryBook()
.getCode()))) {
// create financial transaction
- financialTransaction = new FinancialTransactionImpl();
+ financialTransaction = financialTransactionService.createNewFinancialTransaction();
financialTransaction.setEntryBook(entryBook);
financialTransaction.setTransactionDate(dateEcr);
financialTransaction = financialTransactionService.createFinancialTransaction(financialTransaction);
}
- financialTransaction.getEntry().add(entry);
- // Inside the db, the entries reference the financialTransaction
- entry.setFinancialTransaction(financialTransaction);
+ financialTransaction.addEntry(entry);
financialTransactionService.createEntry(entry);
} catch (LockedFinancialPeriodException | LockedEntryBookException e) {
@@ -806,26 +821,6 @@
return result;
}
- @Override
- public ImportResult importEntryBookFromEbp(String datas) {
- ImportResult result = new ImportResult();
-
- ImportModel<EntryBook> model = new EntryBookEBPModel();
-
- InputStream contentStream = IOUtils.toInputStream(datas);
- Import<EntryBook> entryBooks = Import.newImport(model, contentStream);
-
- for (EntryBook entryEBP : entryBooks) {
- boolean updated = entryBookService.createOrUpdateEntryBook(entryEBP);
- if (updated) {
- result.increaseUpdated();
- } else {
- result.increaseCreated();
- }
- }
- return result;
- }
-
//#######################################################################################################
// @Override
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-01 14:29:33 UTC (rev 3889)
+++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java 2014-08-01 15:52:09 UTC (rev 3890)
@@ -53,6 +53,11 @@
public interface FinancialTransactionService {
+ /**
+ * Create new FinancialTransaction not persisted yet.
+ * @return
+ */
+ FinancialTransaction createNewFinancialTransaction();
FinancialTransaction createFinancialTransaction(FinancialTransaction financialtransaction)
throws LockedFinancialPeriodException, LockedEntryBookException;
Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java
===================================================================
--- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java 2014-08-01 14:29:33 UTC (rev 3889)
+++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java 2014-08-01 15:52:09 UTC (rev 3890)
@@ -53,10 +53,10 @@
ImportResult importAccountFromEbp(String datas);
+ ImportResult importEntryBookFromEbp(String datas);
+
ImportResult importEntriesFromEbp(String datas);
- ImportResult importEntryBookFromEbp(String datas);
-
// String importAsPDF(String data,
// ImportExportEntityEnum importExportEntityEnum,
// boolean saveMode);
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-08-01 14:29:33 UTC (rev 3889)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-08-01 15:52:09 UTC (rev 3890)
@@ -235,6 +235,8 @@
//For windows ebp
datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding());
importResult = importService.importEntriesFromEbp(datas);
+ // TODO DCossé 24/07/14 change result
+ result = "SUCCESS";
break;
}
} catch (ImportEbpException e) {
1
0
Author: dcosse
Date: 2014-08-01 16:29:33 +0200 (Fri, 01 Aug 2014)
New Revision: 3889
Url: http://forge.chorem.org/projects/lima/repository/revisions/3889
Log:
refs #1032 import des journaux depuis EBP
Added:
trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java
trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java
trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.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
Removed:
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
Modified:
trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/AccountEBPModel.java
trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java
trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ImportServiceRuleFrTest.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountComboBoxModel.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookComboBoxModel.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FinancialPeriodComboBoxModel.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxModel.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/LeafAccountComboBoxModel.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/AccountsPane.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/EntryBooksPane.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FinancialTransactionsPane.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FiscalYearsPane.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/identity/IdentityForm.css
trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/opening/CreateIdentityPanel.css
trunk/lima-swing/src/main/java/org/chorem/lima/ui/opening/CreateIdentityPanelHandler.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java
Copied: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java (from rev 3888, trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java)
===================================================================
--- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java (rev 0)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -0,0 +1,424 @@
+/*
+ * #%L
+ * Lima business
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric
+ * %%
+ * 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.ejb;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.chorem.lima.LimaTechnicalException;
+import org.chorem.lima.business.api.AccountService;
+import org.chorem.lima.business.api.EntryBookService;
+import org.chorem.lima.business.api.ExportService;
+import org.chorem.lima.business.api.FinancialStatementService;
+import org.chorem.lima.business.api.FinancialTransactionService;
+import org.chorem.lima.business.api.IdentityService;
+import org.chorem.lima.business.api.VatStatementService;
+import org.chorem.lima.business.ejb.csv.AccountModel;
+import org.chorem.lima.business.ejb.csv.EntryBookModel;
+import org.chorem.lima.business.ejb.csv.EntryModel;
+import org.chorem.lima.business.ejb.csv.FinancialStatementModel;
+import org.chorem.lima.business.ejb.csv.FinancialTransactionModel;
+import org.chorem.lima.business.ejb.csv.FiscalPeriodModel;
+import org.chorem.lima.business.ejb.csv.IdentityModel;
+import org.chorem.lima.business.ejb.csv.VatStatementModel;
+import org.chorem.lima.business.ejb.ebp.AccountEBPModel;
+import org.chorem.lima.business.ejb.ebp.EntryEBPModel;
+import org.chorem.lima.entity.Account;
+import org.chorem.lima.entity.AccountTopiaDao;
+import org.chorem.lima.entity.Entry;
+import org.chorem.lima.entity.EntryBook;
+import org.chorem.lima.entity.EntryBookTopiaDao;
+import org.chorem.lima.entity.EntryTopiaDao;
+import org.chorem.lima.entity.FinancialStatement;
+import org.chorem.lima.entity.FinancialTransaction;
+import org.chorem.lima.entity.FinancialTransactionTopiaDao;
+import org.chorem.lima.entity.FiscalPeriod;
+import org.chorem.lima.entity.FiscalPeriodTopiaDao;
+import org.chorem.lima.entity.Identity;
+import org.chorem.lima.entity.VatStatement;
+import org.nuiton.csv.Export;
+
+import javax.ejb.EJB;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * CSV import export service.
+ *
+ * @version $Revision$
+ * <p/>
+ * Last update : $Date$
+ * By : $Author$
+ */
+@Stateless
+(a)Remote(ExportService.class)
+@TransactionAttribute
+public class ExportServiceImpl extends AbstractLimaService implements ExportService {
+
+ @EJB
+ protected EntryBookService entryBookService;
+
+ @EJB
+ protected AccountService accountService;
+
+ @EJB
+ protected FinancialTransactionService financialTransactionService;
+
+ @EJB
+ protected FinancialStatementService financialStatementService;
+
+ @EJB
+ protected VatStatementService vatStatementService;
+
+ @EJB
+ protected IdentityService identityService;
+
+ public static final String JAVA_IO_TMPDIR = "java.io.tmpdir";
+
+ protected File exportAccountsFile(String charset) throws Exception {
+ AccountTopiaDao accountTopiaDao = getDaoHelper().getAccountDao();
+ List<Account> entities = accountTopiaDao.findAll();
+ File result = null;
+ if (entities != null && entities.size() > 0) {
+ AccountModel model = new AccountModel();
+ String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+
+ result = new File(tmpDir + "accounts.csv");
+ Export.exportToFile(model, entities, result, Charset.forName(charset));
+ }
+ return result;
+ }
+
+ @Override
+ public String exportAccountsAsCSV(String charset) {
+ String result = null;
+ try {
+ File file = exportAccountsFile(charset);
+ if (file != null) {
+ FileInputStream inputStream = new FileInputStream(file);
+ result = IOUtils.toString(inputStream);
+ }
+ } catch (Exception e) {
+ throw new LimaTechnicalException(e);
+ }
+ return result;
+ }
+
+ protected File exportEntryBooksFile(String charset) throws Exception {
+ EntryBookTopiaDao entryBookTopiaDao = getDaoHelper().getEntryBookDao();
+ List<EntryBook> entities = entryBookTopiaDao.findAll();
+ File result = null;
+ if (entities != null && !entities.isEmpty()) {
+ String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ result = new File(tmpDir + "entryBooks.csv");
+ EntryBookModel model = new EntryBookModel();
+ Export.exportToFile(model, entities, result, Charset.forName(charset));
+ }
+
+ return result;
+ }
+
+
+ @Override
+ public String exportEntryBooksAsCSV(String charset) {
+ String result = null;
+ try {
+ File file = exportEntryBooksFile(charset);
+ if (file != null) {
+ FileInputStream inputStream = new FileInputStream(file);
+ result = IOUtils.toString(inputStream);
+ }
+ } catch (Exception e) {
+ throw new LimaTechnicalException(e);
+ }
+ return result;
+ }
+
+ protected File exportFiscalPeriodFile(String charset) throws Exception {
+
+ FiscalPeriodTopiaDao dao = getDaoHelper().getFiscalPeriodDao();
+ List<FiscalPeriod> entities = dao.findAll();
+
+ File result = null;
+ if (entities != null && !entities.isEmpty()) {
+ String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ result = new File(tmpDir + "fiscalPeriod.csv");
+ FiscalPeriodModel model = new FiscalPeriodModel();
+ Export.exportToFile(model, entities, result, Charset.forName(charset));
+ }
+
+
+ return result;
+ }
+
+ @Override
+ public String exportFiscalPeriodsAsCSV(String charset) {
+ String result = null;
+ try {
+ File file = exportFiscalPeriodFile(charset);
+ if (file != null) {
+ FileInputStream inputStream = new FileInputStream(file);
+ result = IOUtils.toString(inputStream);
+ }
+ } catch (Exception e) {
+ throw new LimaTechnicalException(e);
+ }
+ return result;
+ }
+
+ protected File exportFinancialTransactionsFile(String charset) throws Exception {
+ File result = null;
+
+ FinancialTransactionTopiaDao financialTransactionTopiaDao =
+ getDaoHelper().getFinancialTransactionDao();
+ List<FinancialTransaction> entities = financialTransactionTopiaDao.findAll();
+
+ if (entities != null && !entities.isEmpty()) {
+ String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ result = new File(tmpDir + "financialTransactions.csv");
+ FinancialTransactionModel model = new FinancialTransactionModel(entryBookService);
+ Export.exportToFile(model, entities, result, Charset.forName(charset));
+ }
+
+ return result;
+ }
+
+ protected File exportEntriesFile(String charset, Boolean humanReadable) throws Exception {
+ EntryTopiaDao dao = getDaoHelper().getEntryDao();
+ List<Entry> entities = dao.findAll();
+
+ File result = null;
+ if (entities != null && !entities.isEmpty()) {
+ String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ result = new File(tmpDir + "entries.csv");
+ EntryModel model = new EntryModel(accountService, financialTransactionService , humanReadable);
+ Export.exportToFile(model, entities, result, Charset.forName(charset));
+ }
+
+ return result;
+ }
+
+ @Override
+ public String exportEntriesAsCSV(String charset, Boolean humanReadable) {
+ String result = null;
+ try {
+ File file = exportEntriesFile(charset, humanReadable);
+ if (file != null) {
+ FileInputStream inputStream = new FileInputStream(file);
+ result = IOUtils.toString(inputStream);
+ }
+ } catch (Exception e) {
+ throw new LimaTechnicalException(e);
+ }
+ return result;
+ }
+
+ protected List<FinancialStatement> getAllSubFinancialStatements(List<FinancialStatement> result, Collection<FinancialStatement> subFinancialStatements) {
+ if (subFinancialStatements != null) {
+ for (FinancialStatement subFinancialStatement : subFinancialStatements) {
+ result.add(subFinancialStatement);
+ getAllSubFinancialStatements(result, subFinancialStatement.getSubFinancialStatements());
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public String exportFinancialStatements(String charset) throws Exception {
+ String stResult = null;
+ String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ File fileResult = new File(tmpDir + "financialStatements.csv");
+
+ List<FinancialStatement> rootFinancialStatements = financialStatementService.getRootFinancialStatements();
+ if (rootFinancialStatements != null) {
+ FinancialStatementModel model = new FinancialStatementModel();
+ List<FinancialStatement> financialStatements = new ArrayList<>();
+ getAllSubFinancialStatements(financialStatements, rootFinancialStatements);
+ Export.exportToFile(model, financialStatements, fileResult, Charset.forName(charset));
+ FileInputStream inputStream = new FileInputStream(fileResult);
+ stResult = IOUtils.toString(inputStream);
+
+ }
+ return stResult;
+ }
+
+ protected List<VatStatement> getAllSubVATStatements(List<VatStatement> result, Collection<VatStatement> subVATStatements) {
+ if (subVATStatements != null) {
+ for (VatStatement subVATStatement : subVATStatements) {
+ result.add(subVATStatement);
+ getAllSubVATStatements(result, subVATStatement.getSubVatStatements());
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public String exportVatStatements(String charset) throws Exception {
+ String stResult = null;
+ String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ File fileResult = new File(tmpDir + "vatStatements.csv");
+
+ List<VatStatement> rootVatStatements = vatStatementService.getRootVatStatements();
+ if (rootVatStatements != null) {
+ VatStatementModel model = new VatStatementModel();
+ List<VatStatement> vatStatements = new ArrayList<>();
+ getAllSubVATStatements(vatStatements, rootVatStatements);
+ Export.exportToFile(model, vatStatements, fileResult, Charset.forName(charset));
+ FileInputStream inputStream = new FileInputStream(fileResult);
+ stResult = IOUtils.toString(inputStream);
+
+ }
+ return stResult;
+ }
+
+ protected File exportIdentity(String charset) throws Exception {
+ File result = null;
+
+ Identity identity = identityService.getIdentity();
+ if (identity != null) {
+ List<Identity> identities = new ArrayList<>();
+ identities.add(identity);
+
+ String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ result = new File(tmpDir + "identity.csv");
+ IdentityModel model = new IdentityModel();
+ Export.exportToFile(model, identities, result, Charset.forName(charset));
+ }
+ return result;
+ }
+
+ @Override
+ public String exportBackup(String charset) {
+ ByteArrayOutputStream rstBao = new ByteArrayOutputStream();
+ ZipOutputStream export = null;
+ try {
+ List<File> files = Lists.newArrayList();
+ files.add(exportAccountsFile(charset));
+ files.add(exportEntryBooksFile(charset));
+ files.add(exportFiscalPeriodFile(charset));
+ files.add(exportFinancialTransactionsFile(charset));
+ files.add(exportEntriesFile(charset, false));
+ files.add(exportIdentity(charset));
+
+ export = new ZipOutputStream(rstBao);
+
+ for (File file : files) {
+ if (file != null) {
+ ZipEntry ze= new ZipEntry(file.getName());
+ export.putNextEntry(ze);
+ int len;
+ byte[] buffer = new byte[1024];
+ FileInputStream stream = new FileInputStream(file);
+ while ((len = stream.read(buffer)) > 0) {
+ export.write(buffer, 0, len);
+ }
+ stream.close();
+ FileUtils.forceDelete(file);
+ }
+ }
+ export.flush();
+
+ } catch (Exception e) {
+ throw new LimaTechnicalException(e);
+ } finally {
+ IOUtils.closeQuietly(export);
+ }
+ byte[] bytes = rstBao.toByteArray();
+ return Base64.encodeBase64String(bytes);
+ }
+
+ //####################################### EBP ##############################################
+
+ @Override
+ public String exportAccountAsEbp(String charset) throws Exception {
+ String stResult = null;
+ File result;
+
+ List<Account> accounts = accountService.getAllAccounts();
+ if (accounts != null && !accounts.isEmpty()) {
+
+ String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ result = new File(tmpDir + "accounts.csv");
+ AccountEBPModel model = new AccountEBPModel();
+ Export.exportToFile(model, accounts, result, Charset.forName(charset));
+ FileInputStream inputStream = new FileInputStream(result);
+ stResult = IOUtils.toString(inputStream);
+
+ }
+ return stResult;
+ }
+
+ @Override
+ public String exportEntriesAsEbp(String charset) throws Exception {
+ String stResult = null;
+ File result;
+
+ List<Entry> entries = getDaoHelper().getEntryDao().findAll();
+
+ if (entries != null && !entries.isEmpty()) {
+
+ String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ result = new File(tmpDir + "entries.csv");
+ EntryEBPModel model = new EntryEBPModel();
+ Export.exportToFile(model, entries, result, Charset.forName(charset));
+ FileInputStream inputStream = new FileInputStream(result);
+ stResult = IOUtils.toString(inputStream);
+
+ }
+ return stResult;
+ }
+
+ @Override
+ public String exportEntryBookAsEbp(String charset) throws Exception {
+ String stResult = null;
+ File result;
+
+ List<EntryBook> entryBooks = entryBookService.getAllEntryBooks();
+
+ if (entryBooks != null && !entryBooks.isEmpty()) {
+
+ String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ result = new File(tmpDir + "entryBooks.csv");
+ EntryBookModel model = new EntryBookModel();
+ Export.exportToFile(model, entryBooks, result, Charset.forName(charset));
+ FileInputStream inputStream = new FileInputStream(result);
+ stResult = IOUtils.toString(inputStream);
+
+ }
+ return stResult;
+ }
+}
Copied: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java (from rev 3888, trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java)
===================================================================
--- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java (rev 0)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -0,0 +1,889 @@
+package org.chorem.lima.business.ejb;
+
+/*
+ * #%L
+ * Lima :: business
+ * %%
+ * Copyright (C) 2008 - 2014 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%
+ */
+
+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;
+import org.chorem.lima.beans.EntryEBP;
+import org.chorem.lima.beans.FinancialStatementImport;
+import org.chorem.lima.beans.VatStatementImport;
+import org.chorem.lima.business.AlreadyExistAccountException;
+import org.chorem.lima.business.AlreadyExistFinancialStatement;
+import org.chorem.lima.business.AlreadyExistVatStatement;
+import org.chorem.lima.business.FiscalPeriodException;
+import org.chorem.lima.business.ImportEbpException;
+import org.chorem.lima.business.ImportResult;
+import org.chorem.lima.business.InvalidAccountNumberException;
+import org.chorem.lima.business.LockedEntryBookException;
+import org.chorem.lima.business.LockedFinancialPeriodException;
+import org.chorem.lima.business.MoreOneUnlockFiscalPeriodException;
+import org.chorem.lima.business.NotAllowedLabel;
+import org.chorem.lima.business.api.AccountService;
+import org.chorem.lima.business.api.EntryBookService;
+import org.chorem.lima.business.api.EntryService;
+import org.chorem.lima.business.api.FinancialStatementService;
+import org.chorem.lima.business.api.FinancialTransactionService;
+import org.chorem.lima.business.api.FiscalPeriodService;
+import org.chorem.lima.business.api.IdentityService;
+import org.chorem.lima.business.api.ImportService;
+import org.chorem.lima.business.api.VatStatementService;
+import org.chorem.lima.business.ejb.csv.AccountModel;
+import org.chorem.lima.business.ejb.csv.EntryBookModel;
+import org.chorem.lima.business.ejb.csv.EntryModel;
+import org.chorem.lima.business.ejb.csv.FinancialStatementModel;
+import org.chorem.lima.business.ejb.csv.FinancialTransactionModel;
+import org.chorem.lima.business.ejb.csv.FiscalPeriodModel;
+import org.chorem.lima.business.ejb.csv.IdentityModel;
+import org.chorem.lima.business.ejb.csv.VatStatementModel;
+import org.chorem.lima.business.ejb.ebp.AccountEBPModel;
+import org.chorem.lima.business.ejb.ebp.EntryBookEBPModel;
+import org.chorem.lima.business.ejb.ebp.EntryEBPModel;
+import org.chorem.lima.business.utils.EntryEBPComparator;
+import org.chorem.lima.business.utils.FiscalPeriodComparator;
+import org.chorem.lima.entity.Account;
+import org.chorem.lima.entity.Entry;
+import org.chorem.lima.entity.EntryBook;
+import org.chorem.lima.entity.EntryBookImpl;
+import org.chorem.lima.entity.EntryImpl;
+import org.chorem.lima.entity.FinancialStatement;
+import org.chorem.lima.entity.FinancialTransaction;
+import org.chorem.lima.entity.FinancialTransactionImpl;
+import org.chorem.lima.entity.FiscalPeriod;
+import org.chorem.lima.entity.Identity;
+import org.chorem.lima.entity.VatStatement;
+import org.nuiton.csv.Import;
+import org.nuiton.csv.ImportModel;
+import org.nuiton.util.beans.Binder;
+import org.nuiton.util.beans.BinderFactory;
+
+import javax.ejb.EJB;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.nuiton.i18n.I18n.t;
+
+/**
+ * Created by davidcosse on 03/06/14.
+ */
+@Stateless
+(a)Remote(ImportService.class)
+@TransactionAttribute
+public class ImportServiceImpl extends AbstractLimaService implements ImportService {
+
+ @EJB
+ protected EntryBookService entryBookService;
+
+ @EJB
+ protected AccountService accountService;
+
+ @EJB
+ protected FinancialTransactionService financialTransactionService;
+
+ @EJB
+ protected FiscalPeriodService fiscalPeriodService;
+
+ @EJB
+ protected EntryService entryService;
+
+ @EJB
+ protected FinancialStatementService financialStatementService;
+
+ @EJB
+ protected VatStatementService vatStatementService;
+
+ @EJB
+ protected IdentityService identityService;
+
+ protected static final Function<Account, String> GET_ACCOUNT_NUMBER = new Function<Account, String>() {
+ @Override
+ public String apply(Account input) {
+ return input.getAccountNumber();
+ }
+ };
+
+ protected static final Function<EntryBook, String> GET_ENTRY_BOOK_CODE = new Function<EntryBook, String>() {
+ @Override
+ public String apply(EntryBook input) {
+ return input.getCode();
+ }
+ };
+
+ @Override
+ public ImportResult importAccountAsCSV(String contents) {
+ InputStream contentStream = IOUtils.toInputStream(contents);
+
+ ImportResult result = new ImportResult();
+ try {
+ 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 {
+ updated = accountService.createOrUbdateAccount(account);
+ if (updated) {
+ result.increaseUpdated();
+ } else {
+ result.increaseCreated();
+ }
+ } catch (InvalidAccountNumberException e) {
+ result.getException().addException(indexLine, e);
+ }
+ indexLine++;
+ }
+ } finally {
+ IOUtils.closeQuietly(contentStream);
+ }
+ return result;
+ }
+
+ @Override
+ public ImportResult importEntryBooksAsCSV(String contents) {
+ InputStream contentStream = IOUtils.toInputStream(contents);
+ ImportResult result = new ImportResult();
+ try {
+ ImportModel<EntryBook> model = new EntryBookModel();
+
+ Import<EntryBook> entryBooks = Import.newImport(model, contentStream);
+ for (EntryBook entryBook : entryBooks) {
+ boolean updated = entryBookService.createOrUpdateEntryBook(entryBook);
+ if(updated) {
+ result.increaseUpdated();
+ } else {
+ result.increaseCreated();
+ }
+ }
+ } finally {
+ IOUtils.closeQuietly(contentStream);
+ }
+ return result;
+ }
+
+ @Override
+ public ImportResult importFiscalPeriodsAsCSV(String contents) {
+ InputStream contentStream = IOUtils.toInputStream(contents);
+ ImportResult result = new ImportResult();
+ try {
+ ImportModel<FiscalPeriod> model = new FiscalPeriodModel();
+
+ 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);
+ } catch (MoreOneUnlockFiscalPeriodException e) {
+ result.increaseIgnored();
+ }
+ } finally {
+ IOUtils.closeQuietly(contentStream);
+ }
+ return result;
+ }
+
+ protected ImportResult importFinancialTransactionsAsCSV(String contents) {
+ ImportResult result = new ImportResult();
+
+ // import and save FinancialTransactions
+ InputStream contentStream = IOUtils.toInputStream(contents);
+ try {
+ ImportModel<FinancialTransaction> model = new FinancialTransactionModel(entryBookService);
+
+ Import<FinancialTransaction> financialTransactions = Import.newImport(model, contentStream);
+
+ int lineIndex = 0;
+ for (FinancialTransaction financialTransaction : financialTransactions) {
+ try {
+ financialTransactionService.createFinancialTransaction(financialTransaction);
+ lineIndex++;
+ result.increaseCreated();
+ } catch (LockedFinancialPeriodException e) {
+ result.getException().addException(lineIndex, e);
+ } catch (LockedEntryBookException e) {
+ result.getException().addException(lineIndex, e);
+ }
+ }
+
+ } finally {
+ IOUtils.closeQuietly(contentStream);
+ }
+ return result;
+ }
+
+ @Override
+ public ImportResult importEntriesAsCSV(String contents) {
+ // import and save entries
+ InputStream contentStream = IOUtils.toInputStream(contents);
+ ImportResult result = new ImportResult();
+ try {
+ ImportModel<Entry> model = new EntryModel(accountService, financialTransactionService, false);
+ Import<Entry> entries = Import.newImport(model, contentStream);
+ for (Entry entry : entries) {
+ entryService.createEntry(entry);
+ result.increaseCreated();
+ }
+ } finally {
+ IOUtils.closeQuietly(contentStream);
+ }
+ return result;
+ }
+
+ public ImportResult importIdentityAsCSV(String contents) {
+ ImportResult result = new ImportResult();
+ // import and save identity
+ if (StringUtils.isNotBlank(contents)){
+ InputStream contentStream = null;
+ try {
+ contentStream = IOUtils.toInputStream(contents);
+ ImportModel<Identity> model = new IdentityModel();
+ Import<Identity> identities = Import.newImport(model, contentStream);
+ for (Identity identity : identities) {
+ identityService.updateIdentity(identity);
+ result.increaseCreated();
+ }
+ } finally {
+ IOUtils.closeQuietly(contentStream);
+ }
+ }
+
+ return result;
+ }
+
+ protected FinancialStatement returnFinancialStatement (FinancialStatement rootFinancialStatement, String subFinancialStatementLabel) throws AlreadyExistFinancialStatement, NotAllowedLabel {
+ Collection<FinancialStatement> subFinancialStatements = rootFinancialStatement.getSubFinancialStatements();
+ FinancialStatement targetedFinancialStatement = null;
+
+ // look for financial statement from tree range
+ if (subFinancialStatements != null) {
+ for (FinancialStatement subFinancialStatement : subFinancialStatements) {
+ if(subFinancialStatement.getLabel().equals(subFinancialStatementLabel)){
+ targetedFinancialStatement = subFinancialStatement;
+ break;
+ }
+ }
+ }
+
+ // the target financialStatement has not been created yet so we create it now.
+ if (targetedFinancialStatement == null) {
+ // not found, we need to create it
+ targetedFinancialStatement = financialStatementService.newFinancialStatement();
+ targetedFinancialStatement.setLabel(subFinancialStatementLabel);
+ // create targetedFinancialStatement and rootFinancialStatement if needed
+ targetedFinancialStatement = financialStatementService.createFinancialStatement(rootFinancialStatement, targetedFinancialStatement);
+ targetedFinancialStatement.getMasterFinancialStatement();
+ }
+ return targetedFinancialStatement;
+ }
+
+ protected FinancialStatement returnRootFinancialStatement(FinancialStatement financialStatement) {
+ FinancialStatement rootFinancialStatement = null;
+ while (rootFinancialStatement == null) {
+ if (financialStatement.getMasterFinancialStatement() == null){
+ rootFinancialStatement = financialStatement;
+ } else {
+ financialStatement = financialStatement.getMasterFinancialStatement();
+ }
+ }
+ return rootFinancialStatement;
+ }
+
+ @Override
+ public ImportResult importFinancialStatementsAsCSV(String contents) {
+ ImportResult result = new ImportResult();
+
+ // import and save FinancialTransactions
+ InputStream contentStream = IOUtils.toInputStream(contents);
+ try {
+ ImportModel<FinancialStatementImport> model = new FinancialStatementModel();
+
+ Import<FinancialStatementImport> financialStatementImports = Import.newImport(model, contentStream);
+
+ // path, FinancialStatement
+ Map<String, FinancialStatement> orderedFinancialStatements = new HashMap<>();
+
+ List<FinancialStatement> rootFinancialStatements = financialStatementService.getRootFinancialStatements();
+ for (FinancialStatement rootFinancialStatement : rootFinancialStatements) {
+ 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();
+ binder.copyExcluding(financialStatementBean, financialStatement, FinancialStatement.PROPERTY_MASTER_FINANCIAL_STATEMENT);
+
+ try{
+ // full path to master
+ String masterPath = financialStatementBean.getMasterFinancialStatement();
+
+ if (StringUtils.isBlank(masterPath)) {
+ // case of financialStatement is root
+ // look if root exists
+ // It can not have several FinancialStatement with the same from same path
+ FinancialStatement rootFinancialStatement = orderedFinancialStatements.get(financialStatementBean.getLabel());
+
+ if (rootFinancialStatement == null) {
+ rootFinancialStatement = financialStatement;
+ rootFinancialStatement = financialStatementService.createFinancialStatement(null, rootFinancialStatement);
+ } else {
+ // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted
+ // the sub financial statements
+ Binder<FinancialStatement, FinancialStatement> rootBinder = BinderFactory.newBinder(FinancialStatement.class, FinancialStatement.class);
+ rootBinder.copyExcluding(financialStatement, rootFinancialStatement, FinancialStatement.PROPERTY_SUB_FINANCIAL_STATEMENTS);
+ }
+ orderedFinancialStatements.put(rootFinancialStatement.getLabel(), rootFinancialStatement);
+ } else {
+ String[] masterNames = masterPath.split("/");
+ String rootMasterName = masterNames[0];
+
+ FinancialStatement rootFinancialStatement = orderedFinancialStatements.get(rootMasterName);
+
+ // case of not ordered import and subFinancialStatement is looking for it's master that has not been created yet
+ if (rootFinancialStatement == null) {
+ rootFinancialStatement = financialStatementService.newFinancialStatement();
+ rootFinancialStatement.setLabel(rootMasterName);
+ rootFinancialStatement = financialStatementService.createFinancialStatement(null, rootFinancialStatement);
+ orderedFinancialStatements.put(rootMasterName, rootFinancialStatement);
+ }
+
+ // explore branches to find the financialStatement's master one
+ FinancialStatement branchesFinancialStatement = rootFinancialStatement;
+ for (int i = 1; i < masterNames.length; i++) {// 0 is root
+ String masterName = masterNames[i];
+ branchesFinancialStatement = returnFinancialStatement(branchesFinancialStatement, masterName);
+ }
+
+ // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted
+ // the sub financial statements
+ boolean alreadyCreated = false;
+ if (branchesFinancialStatement != null && branchesFinancialStatement.getSubFinancialStatements() != null) {
+ for (FinancialStatement bfs : branchesFinancialStatement.getSubFinancialStatements()) {
+ if (bfs.getLabel().equals(financialStatement.getLabel())){
+ Binder<FinancialStatement, FinancialStatement> rootBinder = BinderFactory.newBinder(FinancialStatement.class, FinancialStatement.class);
+ rootBinder.copyExcluding(bfs, financialStatement, FinancialStatement.PROPERTY_SUB_FINANCIAL_STATEMENTS);
+ alreadyCreated = true;
+ break;
+ }
+ }
+ }
+
+ // if necessary financial statement is created
+ if (!alreadyCreated) {
+ // if the master finacial statement has been modified then the current one is replace by the new one.
+ financialStatement = financialStatementService.createFinancialStatement(branchesFinancialStatement, financialStatement);
+ FinancialStatement targetedRootFinancialStatement = returnRootFinancialStatement(financialStatement);
+
+ // replace modified root financial statement with new one
+ if (orderedFinancialStatements.get(targetedRootFinancialStatement.getLabel()) != null) {
+ orderedFinancialStatements.put(targetedRootFinancialStatement.getLabel(), targetedRootFinancialStatement);
+ }
+ }
+
+ }
+ result.increaseCreated();
+ lineIndex++;
+ } catch (AlreadyExistFinancialStatement e) {
+ result.getException().addException(lineIndex, e);
+ } catch (NotAllowedLabel e) {
+ result.getException().addException(lineIndex, e);
+ }
+ }
+
+ } finally {
+ IOUtils.closeQuietly(contentStream);
+ }
+ return result;
+ }
+
+ protected VatStatement returnVATStatement (VatStatement rootVATStatement, String subVATStatementLabel) throws AlreadyExistVatStatement, NotAllowedLabel {
+ Collection<VatStatement> subVatStatements = rootVATStatement.getSubVatStatements();
+ VatStatement targetedVATStatement = null;
+
+ // look for vatStatement from tree range
+ if (subVatStatements != null) {
+ for (VatStatement subVatStatement : subVatStatements) {
+ if(subVatStatement.getLabel().equals(subVATStatementLabel)){
+ targetedVATStatement = subVatStatement;
+ break;
+ }
+ }
+ }
+
+ //
+ if (targetedVATStatement == null) {
+ // not found, we need to create it
+ targetedVATStatement = vatStatementService.newVatStatement();
+ targetedVATStatement.setLabel(subVATStatementLabel);
+ // create targetedVATStatement and rootVATStatement if needed
+ targetedVATStatement = vatStatementService.createVatStatement(rootVATStatement, targetedVATStatement);
+ targetedVATStatement.getMasterVatStatement();
+ }
+ return targetedVATStatement;
+ }
+
+ protected VatStatement returnRootVATStatement(VatStatement vatStatement) {
+ VatStatement rootVatStatement = null;
+ while (rootVatStatement == null) {
+ if (vatStatement.getMasterVatStatement() == null){
+ rootVatStatement = vatStatement;
+ } else {
+ vatStatement = vatStatement.getMasterVatStatement();
+ }
+ }
+ return rootVatStatement;
+ }
+
+ @Override
+ public ImportResult importVATStatementsAsCSV(String contents) {
+ ImportResult result = new ImportResult();
+
+ // import and save VATStatements
+ InputStream contentStream = IOUtils.toInputStream(contents);
+ try {
+ ImportModel<VatStatementImport> model = new VatStatementModel();
+
+ Import<VatStatementImport> vatStatementImports = Import.newImport(model, contentStream);
+
+ // path, vatStatement
+ Map<String, VatStatement> orderedVATStatements = new HashMap<>();
+
+ List<VatStatement> rootVatStatements = vatStatementService.getRootVatStatements();
+ for (VatStatement vatStatement : rootVatStatements) {
+ 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();
+ binder.copyExcluding(vatStatementBean, vatStatement, VatStatement.PROPERTY_MASTER_VAT_STATEMENT);
+
+ try{
+ // full path to master
+ String masterPath = vatStatementBean.getMasterVatStatement();
+
+ if (StringUtils.isBlank(masterPath)) {
+ // case of vatStatement is root
+ // look if root exists
+ // It can not have several vatStatement with the same from same path
+ VatStatement rootVATStatement = orderedVATStatements.get(vatStatementBean.getLabel());
+
+ if (rootVATStatement == null) {
+ rootVATStatement = vatStatement;
+ rootVATStatement = vatStatementService.createVatStatement(null, rootVATStatement);
+ } else {
+ // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted
+ // the sub vatStatements
+ Binder<VatStatement, VatStatement> rootBinder = BinderFactory.newBinder(VatStatement.class, VatStatement.class);
+ rootBinder.copyExcluding(vatStatement, rootVATStatement, VatStatement.PROPERTY_SUB_VAT_STATEMENTS);
+ }
+ orderedVATStatements.put(rootVATStatement.getLabel(), rootVATStatement);
+ } else {
+ String[] masterNames = masterPath.split("/");
+ String rootMasterName = masterNames[0];
+
+ VatStatement rootVATStatement = orderedVATStatements.get(rootMasterName);
+
+ // case of not ordered import and subVATStatement is looking for it's master that has not been created yet
+ if (rootVATStatement == null) {
+ rootVATStatement = vatStatementService.newVatStatement();
+ rootVATStatement.setLabel(rootMasterName);
+ rootVATStatement = vatStatementService.createVatStatement(null, rootVATStatement);
+ orderedVATStatements.put(rootMasterName, rootVATStatement);
+ }
+
+ // explore branches to find the vatStatement's master one
+ VatStatement branchesVATStatement = rootVATStatement;
+ for (int i = 1; i < masterNames.length; i++) {// 0 is root
+ String masterName = masterNames[i];
+ branchesVATStatement = returnVATStatement(branchesVATStatement, masterName);
+ }
+
+ // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted
+ // the sub vatStatements
+ boolean alreadyCreated = false;
+ if (branchesVATStatement != null && branchesVATStatement.getSubVatStatements() != null) {
+ for (VatStatement bfs : branchesVATStatement.getSubVatStatements()) {
+ if (bfs.getLabel().equals(vatStatement.getLabel())){
+ Binder<VatStatement, VatStatement> rootBinder = BinderFactory.newBinder(VatStatement.class, VatStatement.class);
+ rootBinder.copyExcluding(bfs, vatStatement, VatStatement.PROPERTY_SUB_VAT_STATEMENTS);
+ alreadyCreated = true;
+ break;
+ }
+ }
+ }
+
+ // if necessary vatStatement is created
+ if (!alreadyCreated) {
+ // if the master vatStatement has been modified then the current one is replace by the new one.
+ vatStatement = vatStatementService.createVatStatement(branchesVATStatement, vatStatement);
+ VatStatement targetedRootVATStatement = returnRootVATStatement(vatStatement);
+
+ // replace modified root vatStatement with new one
+ if (orderedVATStatements.get(targetedRootVATStatement.getLabel()) != null) {
+ orderedVATStatements.put(targetedRootVATStatement.getLabel(), targetedRootVATStatement);
+ }
+ }
+
+ }
+ result.increaseCreated();
+ lineIndex++;
+ } catch (AlreadyExistVatStatement e) {
+ result.getException().addException(lineIndex, e);
+ } catch (NotAllowedLabel e) {
+ result.getException().addException(lineIndex, e);
+ }
+ }
+
+ } finally {
+ IOUtils.closeQuietly(contentStream);
+ }
+ return result;
+ }
+
+ @Override
+ public List<ImportResult> importBackup(String entryBooks, String financialTransactions, String fiscalPeriods, String accounts, String entries, String identity) throws AlreadyExistAccountException, InvalidAccountNumberException {
+ List<ImportResult> results = new ArrayList<>();
+ results.add(importAccountAsCSV(accounts));
+ results.add(importEntryBooksAsCSV(entryBooks));
+ results.add(importFiscalPeriodsAsCSV(fiscalPeriods));
+ results.add(importFinancialTransactionsAsCSV(financialTransactions));
+ results.add(importEntriesAsCSV(entries));
+ results.add(importIdentityAsCSV(identity));
+ return results;
+ }
+
+ //####################################### EBP ##############################################
+
+
+ @Override
+ public ImportResult importAccountFromEbp(String datas) {
+ ImportResult result = new ImportResult();
+
+ ImportModel<Account> model = new AccountEBPModel();
+
+ 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);
+ }
+ if (updated) {
+ result.increaseUpdated();
+ } else {
+ result.increaseCreated();
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public ImportResult importEntriesFromEbp(String datas) {
+
+ ImportResult result = new ImportResult();
+ if (datas.isEmpty()) {
+ result.getException().addException(0, new ImportEbpException(t("lima-business.import.ebpnoentry")));
+ return result;
+ }
+
+ // use for logs
+ long before = System.currentTimeMillis();
+
+ List<Account> accounts = accountService.getAllAccounts();
+ if (accounts == null) {
+ accounts = Lists.newArrayList();
+ }
+ Map<String, Account> indexedAccounts = Maps.newHashMap(Maps.uniqueIndex(accounts, GET_ACCOUNT_NUMBER));
+
+ List<EntryBook> entryBooks = entryBookService.getAllEntryBooks();
+ if (entryBooks == null) {
+ entryBooks = Lists.newArrayList();
+ }
+ Map<String, EntryBook> indexedEntryBooks = Maps.newHashMap(Maps.uniqueIndex(entryBooks, GET_ENTRY_BOOK_CODE));
+
+ InputStream contentStream = null;
+ try {
+ 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());
+
+ // Get all the valid fiscalPeriods Ordered by date.
+ List<FiscalPeriod> fiscalPeriods = fiscalPeriodService
+ .getAllUnblockedFiscalPeriods();
+ Collections.sort(fiscalPeriods, new FiscalPeriodComparator());
+
+ // 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;
+ }
+
+ // attributes declaration
+ FinancialTransaction financialTransaction = null;
+ Date dateEcr;
+ Account account;
+ Entry entry;
+ BigDecimal debit;
+ String entryBookCode;
+ EntryBook entryBook;
+
+ // 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++;
+ 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 {
+
+ // find financial transactions for entry period.
+ List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(fiscalPeriodsBiginDate, fiscalPeriodsEndingDate);
+ Map<Date, FinancialTransaction> financialTransactionsByDate = new HashMap<>();
+ for (FinancialTransaction transaction : financialTransactions) {
+ financialTransactionsByDate.put(transaction.getTransactionDate(), transaction);
+ }
+
+ // creation of the entry
+ // initialisation of this attributs
+
+ entry = new EntryImpl();
+
+ // 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());
+
+ // 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.
+
+ entryBookCode = entryEBP.getJournal();
+ // entryBook loading
+ entryBook = indexedEntryBooks.get(entryBookCode);
+
+ // if entrybook not exist create it !
+ if (entryBook == null) {
+ entryBook = new EntryBookImpl();
+ entryBook.setCode(entryBookCode);
+ //financialTransaction = null;
+ // create it
+ entryBook = entryBookService.createEntryBook(entryBook);
+ indexedEntryBooks.put(entryBook.getCode(), entryBook);
+ }
+ try {
+ // create transaction
+ financialTransaction = financialTransactionsByDate.get(dateEcr);
+ if (financialTransaction == null
+ || !(dateEcr.equals(financialTransaction
+ .getTransactionDate()) && entryBook
+ .getCode().equals(
+ financialTransaction.getEntryBook()
+ .getCode()))) {
+ // create financial transaction
+ financialTransaction = new FinancialTransactionImpl();
+ financialTransaction.setEntryBook(entryBook);
+ financialTransaction.setTransactionDate(dateEcr);
+ financialTransaction = financialTransactionService.createFinancialTransaction(financialTransaction);
+ }
+ financialTransaction.getEntry().add(entry);
+ // Inside the db, the entries reference the financialTransaction
+ entry.setFinancialTransaction(financialTransaction);
+ financialTransactionService.createEntry(entry);
+
+ } catch (LockedFinancialPeriodException | LockedEntryBookException e) {
+ result.getException().addException(lineIndex, e);
+ lineIndex++;
+ continue;
+ }
+
+ }
+ result.increaseCreated();
+ lineIndex++;
+ }
+
+ if (log.isInfoEnabled()) {
+ long after = System.currentTimeMillis();
+ log.info("Imported form EBP : " + entryEBPs.size() + " entries in "
+ + (after - before) + " ms");
+ }
+ } finally {
+ IOUtils.closeQuietly(contentStream);
+ }
+ return result;
+ }
+
+ @Override
+ public ImportResult importEntryBookFromEbp(String datas) {
+ ImportResult result = new ImportResult();
+
+ ImportModel<EntryBook> model = new EntryBookEBPModel();
+
+ InputStream contentStream = IOUtils.toInputStream(datas);
+ Import<EntryBook> entryBooks = Import.newImport(model, contentStream);
+
+ for (EntryBook entryEBP : entryBooks) {
+ boolean updated = entryBookService.createOrUpdateEntryBook(entryEBP);
+ if (updated) {
+ result.increaseUpdated();
+ } else {
+ result.increaseCreated();
+ }
+ }
+ return result;
+ }
+
+ //#######################################################################################################
+
+// @Override
+// public String importAsPDF(String datas,
+// ImportExportEntityEnum importExportEntityEnum,
+// boolean setMode) {
+//
+// StringBuilder result = new StringBuilder();
+//
+// PDDocument doc = null;
+// try {
+// String path = LimaConfig.getInstance().getReportsDir().getAbsolutePath();
+//
+// String filePathDefault = path + File.separator
+// + DocumentsEnum.VAT.getFileName() + "_default.pdf";
+// String filePathStructured = path + File.separator
+// + DocumentsEnum.VAT.getFileName() + "_structure.pdf";
+//
+// InputStream reportsStream = new FileInputStream(datas);
+// //DocumentServiceImpl.class.getResourceAsStream("/reports/vat_form_fr.pdf");
+// // load the document
+// doc = PDDocument.load(reportsStream);
+//
+// //save default vat document with empty boxes
+// if (setMode) {
+// doc.save(filePathDefault);
+// }
+//
+// //search for all PDFBox
+// List<PDField> FieldList = doc.getDocumentCatalog().getAcroForm().getFields();
+//
+// //display inside each box their name
+// for (PDField pdField : FieldList) {
+// pdField.setValue(pdField.getFullyQualifiedName());
+// }
+//
+// // save the structured document
+// doc.save(filePathStructured);
+//
+// //sets the new pdf url to be used as pdf document edited for reports
+// if (setMode) {
+// LimaConfig.getInstance().setVatPDFUrl(datas);
+// }
+// } catch (IOException ex) {
+// log.error("Can't read vat pdf", ex);
+// result.append("Can't read vat pdf");
+// } catch (COSVisitorException ex) {
+// log.error("Can't save vat pdf", ex);
+// result.append("Can't save vat pdf");
+// } finally {
+// try {
+// if (doc != null) {
+// doc.close();
+// }
+// } catch (Exception e) {
+// // Nothing to do
+// }
+// }
+// return result.toString();
+// }
+}
Deleted: 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-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -1,424 +0,0 @@
-/*
- * #%L
- * Lima business
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric
- * %%
- * 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.ejb;
-
-import com.google.common.collect.Lists;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.chorem.lima.LimaTechnicalException;
-import org.chorem.lima.business.api.AccountService;
-import org.chorem.lima.business.api.EntryBookService;
-import org.chorem.lima.business.api.FinancialStatementService;
-import org.chorem.lima.business.api.FinancialTransactionService;
-import org.chorem.lima.business.api.IdentityService;
-import org.chorem.lima.business.api.NewExportService;
-import org.chorem.lima.business.api.VatStatementService;
-import org.chorem.lima.business.ejb.csv.AccountModel;
-import org.chorem.lima.business.ejb.csv.EntryBookModel;
-import org.chorem.lima.business.ejb.csv.EntryModel;
-import org.chorem.lima.business.ejb.csv.FinancialStatementModel;
-import org.chorem.lima.business.ejb.csv.FinancialTransactionModel;
-import org.chorem.lima.business.ejb.csv.FiscalPeriodModel;
-import org.chorem.lima.business.ejb.csv.IdentityModel;
-import org.chorem.lima.business.ejb.csv.VatStatementModel;
-import org.chorem.lima.business.ejb.ebp.AccountEBPModel;
-import org.chorem.lima.business.ejb.ebp.EntryEBPModel;
-import org.chorem.lima.entity.Account;
-import org.chorem.lima.entity.AccountTopiaDao;
-import org.chorem.lima.entity.Entry;
-import org.chorem.lima.entity.EntryBook;
-import org.chorem.lima.entity.EntryBookTopiaDao;
-import org.chorem.lima.entity.EntryTopiaDao;
-import org.chorem.lima.entity.FinancialStatement;
-import org.chorem.lima.entity.FinancialTransaction;
-import org.chorem.lima.entity.FinancialTransactionTopiaDao;
-import org.chorem.lima.entity.FiscalPeriod;
-import org.chorem.lima.entity.FiscalPeriodTopiaDao;
-import org.chorem.lima.entity.Identity;
-import org.chorem.lima.entity.VatStatement;
-import org.nuiton.csv.Export;
-
-import javax.ejb.EJB;
-import javax.ejb.Remote;
-import javax.ejb.Stateless;
-import javax.ejb.TransactionAttribute;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-/**
- * CSV import export service.
- *
- * @version $Revision$
- * <p/>
- * Last update : $Date$
- * By : $Author$
- */
-@Stateless
-(a)Remote(NewExportService.class)
-@TransactionAttribute
-public class NewExportServiceImpl extends AbstractLimaService implements NewExportService {
-
- @EJB
- protected EntryBookService entryBookService;
-
- @EJB
- protected AccountService accountService;
-
- @EJB
- protected FinancialTransactionService financialTransactionService;
-
- @EJB
- protected FinancialStatementService financialStatementService;
-
- @EJB
- protected VatStatementService vatStatementService;
-
- @EJB
- protected IdentityService identityService;
-
- public static final String JAVA_IO_TMPDIR = "java.io.tmpdir";
-
- protected File exportAccountsFile(String charset) throws Exception {
- AccountTopiaDao accountTopiaDao = getDaoHelper().getAccountDao();
- List<Account> entities = accountTopiaDao.findAll();
- File result = null;
- if (entities != null && entities.size() > 0) {
- AccountModel model = new AccountModel();
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
-
- result = new File(tmpDir + "accounts.csv");
- Export.exportToFile(model, entities, result, Charset.forName(charset));
- }
- return result;
- }
-
- @Override
- public String exportAccountsAsCSV(String charset) {
- String result = null;
- try {
- File file = exportAccountsFile(charset);
- if (file != null) {
- FileInputStream inputStream = new FileInputStream(file);
- result = IOUtils.toString(inputStream);
- }
- } catch (Exception e) {
- throw new LimaTechnicalException(e);
- }
- return result;
- }
-
- protected File exportEntryBooksFile(String charset) throws Exception {
- EntryBookTopiaDao entryBookTopiaDao = getDaoHelper().getEntryBookDao();
- List<EntryBook> entities = entryBookTopiaDao.findAll();
- File result = null;
- if (entities != null && !entities.isEmpty()) {
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
- result = new File(tmpDir + "entryBooks.csv");
- EntryBookModel model = new EntryBookModel();
- Export.exportToFile(model, entities, result, Charset.forName(charset));
- }
-
- return result;
- }
-
-
- @Override
- public String exportEntryBooksAsCSV(String charset) {
- String result = null;
- try {
- File file = exportEntryBooksFile(charset);
- if (file != null) {
- FileInputStream inputStream = new FileInputStream(file);
- result = IOUtils.toString(inputStream);
- }
- } catch (Exception e) {
- throw new LimaTechnicalException(e);
- }
- return result;
- }
-
- protected File exportFiscalPeriodFile(String charset) throws Exception {
-
- FiscalPeriodTopiaDao dao = getDaoHelper().getFiscalPeriodDao();
- List<FiscalPeriod> entities = dao.findAll();
-
- File result = null;
- if (entities != null && !entities.isEmpty()) {
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
- result = new File(tmpDir + "fiscalPeriod.csv");
- FiscalPeriodModel model = new FiscalPeriodModel();
- Export.exportToFile(model, entities, result, Charset.forName(charset));
- }
-
-
- return result;
- }
-
- @Override
- public String exportFiscalPeriodsAsCSV(String charset) {
- String result = null;
- try {
- File file = exportFiscalPeriodFile(charset);
- if (file != null) {
- FileInputStream inputStream = new FileInputStream(file);
- result = IOUtils.toString(inputStream);
- }
- } catch (Exception e) {
- throw new LimaTechnicalException(e);
- }
- return result;
- }
-
- protected File exportFinancialTransactionsFile(String charset) throws Exception {
- File result = null;
-
- FinancialTransactionTopiaDao financialTransactionTopiaDao =
- getDaoHelper().getFinancialTransactionDao();
- List<FinancialTransaction> entities = financialTransactionTopiaDao.findAll();
-
- if (entities != null && !entities.isEmpty()) {
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
- result = new File(tmpDir + "financialTransactions.csv");
- FinancialTransactionModel model = new FinancialTransactionModel(entryBookService);
- Export.exportToFile(model, entities, result, Charset.forName(charset));
- }
-
- return result;
- }
-
- protected File exportEntriesFile(String charset, Boolean humanReadable) throws Exception {
- EntryTopiaDao dao = getDaoHelper().getEntryDao();
- List<Entry> entities = dao.findAll();
-
- File result = null;
- if (entities != null && !entities.isEmpty()) {
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
- result = new File(tmpDir + "entries.csv");
- EntryModel model = new EntryModel(accountService, financialTransactionService , humanReadable);
- Export.exportToFile(model, entities, result, Charset.forName(charset));
- }
-
- return result;
- }
-
- @Override
- public String exportEntriesAsCSV(String charset, Boolean humanReadable) {
- String result = null;
- try {
- File file = exportEntriesFile(charset, humanReadable);
- if (file != null) {
- FileInputStream inputStream = new FileInputStream(file);
- result = IOUtils.toString(inputStream);
- }
- } catch (Exception e) {
- throw new LimaTechnicalException(e);
- }
- return result;
- }
-
- protected List<FinancialStatement> getAllSubFinancialStatements(List<FinancialStatement> result, Collection<FinancialStatement> subFinancialStatements) {
- if (subFinancialStatements != null) {
- for (FinancialStatement subFinancialStatement : subFinancialStatements) {
- result.add(subFinancialStatement);
- getAllSubFinancialStatements(result, subFinancialStatement.getSubFinancialStatements());
- }
- }
- return result;
- }
-
- @Override
- public String exportFinancialStatements(String charset) throws Exception {
- String stResult = null;
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
- File fileResult = new File(tmpDir + "financialStatements.csv");
-
- List<FinancialStatement> rootFinancialStatements = financialStatementService.getRootFinancialStatements();
- if (rootFinancialStatements != null) {
- FinancialStatementModel model = new FinancialStatementModel();
- List<FinancialStatement> financialStatements = new ArrayList<>();
- getAllSubFinancialStatements(financialStatements, rootFinancialStatements);
- Export.exportToFile(model, financialStatements, fileResult, Charset.forName(charset));
- FileInputStream inputStream = new FileInputStream(fileResult);
- stResult = IOUtils.toString(inputStream);
-
- }
- return stResult;
- }
-
- protected List<VatStatement> getAllSubVATStatements(List<VatStatement> result, Collection<VatStatement> subVATStatements) {
- if (subVATStatements != null) {
- for (VatStatement subVATStatement : subVATStatements) {
- result.add(subVATStatement);
- getAllSubVATStatements(result, subVATStatement.getSubVatStatements());
- }
- }
- return result;
- }
-
- @Override
- public String exportVatStatements(String charset) throws Exception {
- String stResult = null;
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
- File fileResult = new File(tmpDir + "vatStatements.csv");
-
- List<VatStatement> rootVatStatements = vatStatementService.getRootVatStatements();
- if (rootVatStatements != null) {
- VatStatementModel model = new VatStatementModel();
- List<VatStatement> vatStatements = new ArrayList<>();
- getAllSubVATStatements(vatStatements, rootVatStatements);
- Export.exportToFile(model, vatStatements, fileResult, Charset.forName(charset));
- FileInputStream inputStream = new FileInputStream(fileResult);
- stResult = IOUtils.toString(inputStream);
-
- }
- return stResult;
- }
-
- protected File exportIdentity(String charset) throws Exception {
- File result = null;
-
- Identity identity = identityService.getIdentity();
- if (identity != null) {
- List<Identity> identities = new ArrayList<>();
- identities.add(identity);
-
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
- result = new File(tmpDir + "identity.csv");
- IdentityModel model = new IdentityModel();
- Export.exportToFile(model, identities, result, Charset.forName(charset));
- }
- return result;
- }
-
- @Override
- public String exportBackup(String charset) {
- ByteArrayOutputStream rstBao = new ByteArrayOutputStream();
- ZipOutputStream export = null;
- try {
- List<File> files = Lists.newArrayList();
- files.add(exportAccountsFile(charset));
- files.add(exportEntryBooksFile(charset));
- files.add(exportFiscalPeriodFile(charset));
- files.add(exportFinancialTransactionsFile(charset));
- files.add(exportEntriesFile(charset, false));
- files.add(exportIdentity(charset));
-
- export = new ZipOutputStream(rstBao);
-
- for (File file : files) {
- if (file != null) {
- ZipEntry ze= new ZipEntry(file.getName());
- export.putNextEntry(ze);
- int len;
- byte[] buffer = new byte[1024];
- FileInputStream stream = new FileInputStream(file);
- while ((len = stream.read(buffer)) > 0) {
- export.write(buffer, 0, len);
- }
- stream.close();
- FileUtils.forceDelete(file);
- }
- }
- export.flush();
-
- } catch (Exception e) {
- throw new LimaTechnicalException(e);
- } finally {
- IOUtils.closeQuietly(export);
- }
- byte[] bytes = rstBao.toByteArray();
- return Base64.encodeBase64String(bytes);
- }
-
- //####################################### EBP ##############################################
-
- @Override
- public String exportAccountAsEbp(String charset) throws Exception {
- String stResult = null;
- File result;
-
- List<Account> accounts = accountService.getAllAccounts();
- if (accounts != null && !accounts.isEmpty()) {
-
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
- result = new File(tmpDir + "accounts.csv");
- AccountEBPModel model = new AccountEBPModel();
- Export.exportToFile(model, accounts, result, Charset.forName(charset));
- FileInputStream inputStream = new FileInputStream(result);
- stResult = IOUtils.toString(inputStream);
-
- }
- return stResult;
- }
-
- @Override
- public String exportEntriesAsEbp(String charset) throws Exception {
- String stResult = null;
- File result;
-
- List<Entry> entries = getDaoHelper().getEntryDao().findAll();
-
- if (entries != null && !entries.isEmpty()) {
-
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
- result = new File(tmpDir + "entries.csv");
- EntryEBPModel model = new EntryEBPModel();
- Export.exportToFile(model, entries, result, Charset.forName(charset));
- FileInputStream inputStream = new FileInputStream(result);
- stResult = IOUtils.toString(inputStream);
-
- }
- return stResult;
- }
-
- @Override
- public String exportEntryBookAsEbp(String charset) throws Exception {
- String stResult = null;
- File result;
-
- List<EntryBook> entryBooks = entryBookService.getAllEntryBooks();
-
- if (entryBooks != null && !entryBooks.isEmpty()) {
-
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
- result = new File(tmpDir + "entryBooks.csv");
- EntryBookModel model = new EntryBookModel();
- Export.exportToFile(model, entryBooks, result, Charset.forName(charset));
- FileInputStream inputStream = new FileInputStream(result);
- stResult = IOUtils.toString(inputStream);
-
- }
- return stResult;
- }
-}
Deleted: 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-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -1,889 +0,0 @@
-package org.chorem.lima.business.ejb;
-
-/*
- * #%L
- * Lima :: business
- * %%
- * Copyright (C) 2008 - 2014 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%
- */
-
-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;
-import org.chorem.lima.beans.EntryEBP;
-import org.chorem.lima.beans.FinancialStatementImport;
-import org.chorem.lima.beans.VatStatementImport;
-import org.chorem.lima.business.AlreadyExistAccountException;
-import org.chorem.lima.business.AlreadyExistFinancialStatement;
-import org.chorem.lima.business.AlreadyExistVatStatement;
-import org.chorem.lima.business.FiscalPeriodException;
-import org.chorem.lima.business.ImportEbpException;
-import org.chorem.lima.business.ImportResult;
-import org.chorem.lima.business.InvalidAccountNumberException;
-import org.chorem.lima.business.LockedEntryBookException;
-import org.chorem.lima.business.LockedFinancialPeriodException;
-import org.chorem.lima.business.MoreOneUnlockFiscalPeriodException;
-import org.chorem.lima.business.NotAllowedLabel;
-import org.chorem.lima.business.api.AccountService;
-import org.chorem.lima.business.api.EntryBookService;
-import org.chorem.lima.business.api.EntryService;
-import org.chorem.lima.business.api.FinancialStatementService;
-import org.chorem.lima.business.api.FinancialTransactionService;
-import org.chorem.lima.business.api.FiscalPeriodService;
-import org.chorem.lima.business.api.IdentityService;
-import org.chorem.lima.business.api.NewImportService;
-import org.chorem.lima.business.api.VatStatementService;
-import org.chorem.lima.business.ejb.csv.AccountModel;
-import org.chorem.lima.business.ejb.csv.EntryBookModel;
-import org.chorem.lima.business.ejb.csv.EntryModel;
-import org.chorem.lima.business.ejb.csv.FinancialStatementModel;
-import org.chorem.lima.business.ejb.csv.FinancialTransactionModel;
-import org.chorem.lima.business.ejb.csv.FiscalPeriodModel;
-import org.chorem.lima.business.ejb.csv.IdentityModel;
-import org.chorem.lima.business.ejb.csv.VatStatementModel;
-import org.chorem.lima.business.ejb.ebp.AccountEBPModel;
-import org.chorem.lima.business.ejb.ebp.EntryBookEBPModel;
-import org.chorem.lima.business.ejb.ebp.EntryEBPModel;
-import org.chorem.lima.business.utils.EntryEBPComparator;
-import org.chorem.lima.business.utils.FiscalPeriodComparator;
-import org.chorem.lima.entity.Account;
-import org.chorem.lima.entity.Entry;
-import org.chorem.lima.entity.EntryBook;
-import org.chorem.lima.entity.EntryBookImpl;
-import org.chorem.lima.entity.EntryImpl;
-import org.chorem.lima.entity.FinancialStatement;
-import org.chorem.lima.entity.FinancialTransaction;
-import org.chorem.lima.entity.FinancialTransactionImpl;
-import org.chorem.lima.entity.FiscalPeriod;
-import org.chorem.lima.entity.Identity;
-import org.chorem.lima.entity.VatStatement;
-import org.nuiton.csv.Import;
-import org.nuiton.csv.ImportModel;
-import org.nuiton.util.beans.Binder;
-import org.nuiton.util.beans.BinderFactory;
-
-import javax.ejb.EJB;
-import javax.ejb.Remote;
-import javax.ejb.Stateless;
-import javax.ejb.TransactionAttribute;
-import java.io.InputStream;
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.nuiton.i18n.I18n.t;
-
-/**
- * Created by davidcosse on 03/06/14.
- */
-@Stateless
-(a)Remote(NewImportService.class)
-@TransactionAttribute
-public class NewImportServiceImpl extends AbstractLimaService implements NewImportService {
-
- @EJB
- protected EntryBookService entryBookService;
-
- @EJB
- protected AccountService accountService;
-
- @EJB
- protected FinancialTransactionService financialTransactionService;
-
- @EJB
- protected FiscalPeriodService fiscalPeriodService;
-
- @EJB
- protected EntryService entryService;
-
- @EJB
- protected FinancialStatementService financialStatementService;
-
- @EJB
- protected VatStatementService vatStatementService;
-
- @EJB
- protected IdentityService identityService;
-
- protected static final Function<Account, String> GET_ACCOUNT_NUMBER = new Function<Account, String>() {
- @Override
- public String apply(Account input) {
- return input.getAccountNumber();
- }
- };
-
- protected static final Function<EntryBook, String> GET_ENTRY_BOOK_CODE = new Function<EntryBook, String>() {
- @Override
- public String apply(EntryBook input) {
- return input.getCode();
- }
- };
-
- @Override
- public ImportResult importAccountAsCSV(String contents) {
- InputStream contentStream = IOUtils.toInputStream(contents);
-
- ImportResult result = new ImportResult();
- try {
- 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 {
- updated = accountService.createOrUbdateAccount(account);
- if (updated) {
- result.increaseUpdated();
- } else {
- result.increaseCreated();
- }
- } catch (InvalidAccountNumberException e) {
- result.getException().addException(indexLine, e);
- }
- indexLine++;
- }
- } finally {
- IOUtils.closeQuietly(contentStream);
- }
- return result;
- }
-
- @Override
- public ImportResult importEntryBooksAsCSV(String contents) {
- InputStream contentStream = IOUtils.toInputStream(contents);
- ImportResult result = new ImportResult();
- try {
- ImportModel<EntryBook> model = new EntryBookModel();
-
- Import<EntryBook> entryBooks = Import.newImport(model, contentStream);
- for (EntryBook entryBook : entryBooks) {
- boolean updated = entryBookService.createOrUpdateEntryBook(entryBook);
- if(updated) {
- result.increaseUpdated();
- } else {
- result.increaseCreated();
- }
- }
- } finally {
- IOUtils.closeQuietly(contentStream);
- }
- return result;
- }
-
- @Override
- public ImportResult importFiscalPeriodsAsCSV(String contents) {
- InputStream contentStream = IOUtils.toInputStream(contents);
- ImportResult result = new ImportResult();
- try {
- ImportModel<FiscalPeriod> model = new FiscalPeriodModel();
-
- 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);
- } catch (MoreOneUnlockFiscalPeriodException e) {
- result.increaseIgnored();
- }
- } finally {
- IOUtils.closeQuietly(contentStream);
- }
- return result;
- }
-
- protected ImportResult importFinancialTransactionsAsCSV(String contents) {
- ImportResult result = new ImportResult();
-
- // import and save FinancialTransactions
- InputStream contentStream = IOUtils.toInputStream(contents);
- try {
- ImportModel<FinancialTransaction> model = new FinancialTransactionModel(entryBookService);
-
- Import<FinancialTransaction> financialTransactions = Import.newImport(model, contentStream);
-
- int lineIndex = 0;
- for (FinancialTransaction financialTransaction : financialTransactions) {
- try {
- financialTransactionService.createFinancialTransaction(financialTransaction);
- lineIndex++;
- result.increaseCreated();
- } catch (LockedFinancialPeriodException e) {
- result.getException().addException(lineIndex, e);
- } catch (LockedEntryBookException e) {
- result.getException().addException(lineIndex, e);
- }
- }
-
- } finally {
- IOUtils.closeQuietly(contentStream);
- }
- return result;
- }
-
- @Override
- public ImportResult importEntriesAsCSV(String contents) {
- // import and save entries
- InputStream contentStream = IOUtils.toInputStream(contents);
- ImportResult result = new ImportResult();
- try {
- ImportModel<Entry> model = new EntryModel(accountService, financialTransactionService, false);
- Import<Entry> entries = Import.newImport(model, contentStream);
- for (Entry entry : entries) {
- entryService.createEntry(entry);
- result.increaseCreated();
- }
- } finally {
- IOUtils.closeQuietly(contentStream);
- }
- return result;
- }
-
- public ImportResult importIdentityAsCSV(String contents) {
- ImportResult result = new ImportResult();
- // import and save identity
- if (StringUtils.isNotBlank(contents)){
- InputStream contentStream = null;
- try {
- contentStream = IOUtils.toInputStream(contents);
- ImportModel<Identity> model = new IdentityModel();
- Import<Identity> identities = Import.newImport(model, contentStream);
- for (Identity identity : identities) {
- identityService.updateIdentity(identity);
- result.increaseCreated();
- }
- } finally {
- IOUtils.closeQuietly(contentStream);
- }
- }
-
- return result;
- }
-
- protected FinancialStatement returnFinancialStatement (FinancialStatement rootFinancialStatement, String subFinancialStatementLabel) throws AlreadyExistFinancialStatement, NotAllowedLabel {
- Collection<FinancialStatement> subFinancialStatements = rootFinancialStatement.getSubFinancialStatements();
- FinancialStatement targetedFinancialStatement = null;
-
- // look for financial statement from tree range
- if (subFinancialStatements != null) {
- for (FinancialStatement subFinancialStatement : subFinancialStatements) {
- if(subFinancialStatement.getLabel().equals(subFinancialStatementLabel)){
- targetedFinancialStatement = subFinancialStatement;
- break;
- }
- }
- }
-
- // the target financialStatement has not been created yet so we create it now.
- if (targetedFinancialStatement == null) {
- // not found, we need to create it
- targetedFinancialStatement = financialStatementService.newFinancialStatement();
- targetedFinancialStatement.setLabel(subFinancialStatementLabel);
- // create targetedFinancialStatement and rootFinancialStatement if needed
- targetedFinancialStatement = financialStatementService.createFinancialStatement(rootFinancialStatement, targetedFinancialStatement);
- targetedFinancialStatement.getMasterFinancialStatement();
- }
- return targetedFinancialStatement;
- }
-
- protected FinancialStatement returnRootFinancialStatement(FinancialStatement financialStatement) {
- FinancialStatement rootFinancialStatement = null;
- while (rootFinancialStatement == null) {
- if (financialStatement.getMasterFinancialStatement() == null){
- rootFinancialStatement = financialStatement;
- } else {
- financialStatement = financialStatement.getMasterFinancialStatement();
- }
- }
- return rootFinancialStatement;
- }
-
- @Override
- public ImportResult importFinancialStatementsAsCSV(String contents) {
- ImportResult result = new ImportResult();
-
- // import and save FinancialTransactions
- InputStream contentStream = IOUtils.toInputStream(contents);
- try {
- ImportModel<FinancialStatementImport> model = new FinancialStatementModel();
-
- Import<FinancialStatementImport> financialStatementImports = Import.newImport(model, contentStream);
-
- // path, FinancialStatement
- Map<String, FinancialStatement> orderedFinancialStatements = new HashMap<>();
-
- List<FinancialStatement> rootFinancialStatements = financialStatementService.getRootFinancialStatements();
- for (FinancialStatement rootFinancialStatement : rootFinancialStatements) {
- 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();
- binder.copyExcluding(financialStatementBean, financialStatement, FinancialStatement.PROPERTY_MASTER_FINANCIAL_STATEMENT);
-
- try{
- // full path to master
- String masterPath = financialStatementBean.getMasterFinancialStatement();
-
- if (StringUtils.isBlank(masterPath)) {
- // case of financialStatement is root
- // look if root exists
- // It can not have several FinancialStatement with the same from same path
- FinancialStatement rootFinancialStatement = orderedFinancialStatements.get(financialStatementBean.getLabel());
-
- if (rootFinancialStatement == null) {
- rootFinancialStatement = financialStatement;
- rootFinancialStatement = financialStatementService.createFinancialStatement(null, rootFinancialStatement);
- } else {
- // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted
- // the sub financial statements
- Binder<FinancialStatement, FinancialStatement> rootBinder = BinderFactory.newBinder(FinancialStatement.class, FinancialStatement.class);
- rootBinder.copyExcluding(financialStatement, rootFinancialStatement, FinancialStatement.PROPERTY_SUB_FINANCIAL_STATEMENTS);
- }
- orderedFinancialStatements.put(rootFinancialStatement.getLabel(), rootFinancialStatement);
- } else {
- String[] masterNames = masterPath.split("/");
- String rootMasterName = masterNames[0];
-
- FinancialStatement rootFinancialStatement = orderedFinancialStatements.get(rootMasterName);
-
- // case of not ordered import and subFinancialStatement is looking for it's master that has not been created yet
- if (rootFinancialStatement == null) {
- rootFinancialStatement = financialStatementService.newFinancialStatement();
- rootFinancialStatement.setLabel(rootMasterName);
- rootFinancialStatement = financialStatementService.createFinancialStatement(null, rootFinancialStatement);
- orderedFinancialStatements.put(rootMasterName, rootFinancialStatement);
- }
-
- // explore branches to find the financialStatement's master one
- FinancialStatement branchesFinancialStatement = rootFinancialStatement;
- for (int i = 1; i < masterNames.length; i++) {// 0 is root
- String masterName = masterNames[i];
- branchesFinancialStatement = returnFinancialStatement(branchesFinancialStatement, masterName);
- }
-
- // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted
- // the sub financial statements
- boolean alreadyCreated = false;
- if (branchesFinancialStatement != null && branchesFinancialStatement.getSubFinancialStatements() != null) {
- for (FinancialStatement bfs : branchesFinancialStatement.getSubFinancialStatements()) {
- if (bfs.getLabel().equals(financialStatement.getLabel())){
- Binder<FinancialStatement, FinancialStatement> rootBinder = BinderFactory.newBinder(FinancialStatement.class, FinancialStatement.class);
- rootBinder.copyExcluding(bfs, financialStatement, FinancialStatement.PROPERTY_SUB_FINANCIAL_STATEMENTS);
- alreadyCreated = true;
- break;
- }
- }
- }
-
- // if necessary financial statement is created
- if (!alreadyCreated) {
- // if the master finacial statement has been modified then the current one is replace by the new one.
- financialStatement = financialStatementService.createFinancialStatement(branchesFinancialStatement, financialStatement);
- FinancialStatement targetedRootFinancialStatement = returnRootFinancialStatement(financialStatement);
-
- // replace modified root financial statement with new one
- if (orderedFinancialStatements.get(targetedRootFinancialStatement.getLabel()) != null) {
- orderedFinancialStatements.put(targetedRootFinancialStatement.getLabel(), targetedRootFinancialStatement);
- }
- }
-
- }
- result.increaseCreated();
- lineIndex++;
- } catch (AlreadyExistFinancialStatement e) {
- result.getException().addException(lineIndex, e);
- } catch (NotAllowedLabel e) {
- result.getException().addException(lineIndex, e);
- }
- }
-
- } finally {
- IOUtils.closeQuietly(contentStream);
- }
- return result;
- }
-
- protected VatStatement returnVATStatement (VatStatement rootVATStatement, String subVATStatementLabel) throws AlreadyExistVatStatement, NotAllowedLabel {
- Collection<VatStatement> subVatStatements = rootVATStatement.getSubVatStatements();
- VatStatement targetedVATStatement = null;
-
- // look for vatStatement from tree range
- if (subVatStatements != null) {
- for (VatStatement subVatStatement : subVatStatements) {
- if(subVatStatement.getLabel().equals(subVATStatementLabel)){
- targetedVATStatement = subVatStatement;
- break;
- }
- }
- }
-
- //
- if (targetedVATStatement == null) {
- // not found, we need to create it
- targetedVATStatement = vatStatementService.newVatStatement();
- targetedVATStatement.setLabel(subVATStatementLabel);
- // create targetedVATStatement and rootVATStatement if needed
- targetedVATStatement = vatStatementService.createVatStatement(rootVATStatement, targetedVATStatement);
- targetedVATStatement.getMasterVatStatement();
- }
- return targetedVATStatement;
- }
-
- protected VatStatement returnRootVATStatement(VatStatement vatStatement) {
- VatStatement rootVatStatement = null;
- while (rootVatStatement == null) {
- if (vatStatement.getMasterVatStatement() == null){
- rootVatStatement = vatStatement;
- } else {
- vatStatement = vatStatement.getMasterVatStatement();
- }
- }
- return rootVatStatement;
- }
-
- @Override
- public ImportResult importVATStatementsAsCSV(String contents) {
- ImportResult result = new ImportResult();
-
- // import and save VATStatements
- InputStream contentStream = IOUtils.toInputStream(contents);
- try {
- ImportModel<VatStatementImport> model = new VatStatementModel();
-
- Import<VatStatementImport> vatStatementImports = Import.newImport(model, contentStream);
-
- // path, vatStatement
- Map<String, VatStatement> orderedVATStatements = new HashMap<>();
-
- List<VatStatement> rootVatStatements = vatStatementService.getRootVatStatements();
- for (VatStatement vatStatement : rootVatStatements) {
- 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();
- binder.copyExcluding(vatStatementBean, vatStatement, VatStatement.PROPERTY_MASTER_VAT_STATEMENT);
-
- try{
- // full path to master
- String masterPath = vatStatementBean.getMasterVatStatement();
-
- if (StringUtils.isBlank(masterPath)) {
- // case of vatStatement is root
- // look if root exists
- // It can not have several vatStatement with the same from same path
- VatStatement rootVATStatement = orderedVATStatements.get(vatStatementBean.getLabel());
-
- if (rootVATStatement == null) {
- rootVATStatement = vatStatement;
- rootVATStatement = vatStatementService.createVatStatement(null, rootVATStatement);
- } else {
- // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted
- // the sub vatStatements
- Binder<VatStatement, VatStatement> rootBinder = BinderFactory.newBinder(VatStatement.class, VatStatement.class);
- rootBinder.copyExcluding(vatStatement, rootVATStatement, VatStatement.PROPERTY_SUB_VAT_STATEMENTS);
- }
- orderedVATStatements.put(rootVATStatement.getLabel(), rootVATStatement);
- } else {
- String[] masterNames = masterPath.split("/");
- String rootMasterName = masterNames[0];
-
- VatStatement rootVATStatement = orderedVATStatements.get(rootMasterName);
-
- // case of not ordered import and subVATStatement is looking for it's master that has not been created yet
- if (rootVATStatement == null) {
- rootVATStatement = vatStatementService.newVatStatement();
- rootVATStatement.setLabel(rootMasterName);
- rootVATStatement = vatStatementService.createVatStatement(null, rootVATStatement);
- orderedVATStatements.put(rootMasterName, rootVATStatement);
- }
-
- // explore branches to find the vatStatement's master one
- VatStatement branchesVATStatement = rootVATStatement;
- for (int i = 1; i < masterNames.length; i++) {// 0 is root
- String masterName = masterNames[i];
- branchesVATStatement = returnVATStatement(branchesVATStatement, masterName);
- }
-
- // in case it exist (not ordered import and previously created) values are bind to the previously created one excepted
- // the sub vatStatements
- boolean alreadyCreated = false;
- if (branchesVATStatement != null && branchesVATStatement.getSubVatStatements() != null) {
- for (VatStatement bfs : branchesVATStatement.getSubVatStatements()) {
- if (bfs.getLabel().equals(vatStatement.getLabel())){
- Binder<VatStatement, VatStatement> rootBinder = BinderFactory.newBinder(VatStatement.class, VatStatement.class);
- rootBinder.copyExcluding(bfs, vatStatement, VatStatement.PROPERTY_SUB_VAT_STATEMENTS);
- alreadyCreated = true;
- break;
- }
- }
- }
-
- // if necessary vatStatement is created
- if (!alreadyCreated) {
- // if the master vatStatement has been modified then the current one is replace by the new one.
- vatStatement = vatStatementService.createVatStatement(branchesVATStatement, vatStatement);
- VatStatement targetedRootVATStatement = returnRootVATStatement(vatStatement);
-
- // replace modified root vatStatement with new one
- if (orderedVATStatements.get(targetedRootVATStatement.getLabel()) != null) {
- orderedVATStatements.put(targetedRootVATStatement.getLabel(), targetedRootVATStatement);
- }
- }
-
- }
- result.increaseCreated();
- lineIndex++;
- } catch (AlreadyExistVatStatement e) {
- result.getException().addException(lineIndex, e);
- } catch (NotAllowedLabel e) {
- result.getException().addException(lineIndex, e);
- }
- }
-
- } finally {
- IOUtils.closeQuietly(contentStream);
- }
- return result;
- }
-
- @Override
- public List<ImportResult> importBackup(String entryBooks, String financialTransactions, String fiscalPeriods, String accounts, String entries, String identity) throws AlreadyExistAccountException, InvalidAccountNumberException {
- List<ImportResult> results = new ArrayList<>();
- results.add(importAccountAsCSV(accounts));
- results.add(importEntryBooksAsCSV(entryBooks));
- results.add(importFiscalPeriodsAsCSV(fiscalPeriods));
- results.add(importFinancialTransactionsAsCSV(financialTransactions));
- results.add(importEntriesAsCSV(entries));
- results.add(importIdentityAsCSV(identity));
- return results;
- }
-
- //####################################### EBP ##############################################
-
-
- @Override
- public ImportResult importAccountFromEbp(String datas) {
- ImportResult result = new ImportResult();
-
- ImportModel<Account> model = new AccountEBPModel();
-
- 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);
- }
- if (updated) {
- result.increaseUpdated();
- } else {
- result.increaseCreated();
- }
- }
- return result;
- }
-
- @Override
- public ImportResult importEntriesFromEbp(String datas) {
-
- ImportResult result = new ImportResult();
- if (datas.isEmpty()) {
- result.getException().addException(0, new ImportEbpException(t("lima-business.import.ebpnoentry")));
- return result;
- }
-
- // use for logs
- long before = System.currentTimeMillis();
-
- List<Account> accounts = accountService.getAllAccounts();
- if (accounts == null) {
- accounts = Lists.newArrayList();
- }
- Map<String, Account> indexedAccounts = Maps.newHashMap(Maps.uniqueIndex(accounts, GET_ACCOUNT_NUMBER));
-
- List<EntryBook> entryBooks = entryBookService.getAllEntryBooks();
- if (entryBooks == null) {
- entryBooks = Lists.newArrayList();
- }
- Map<String, EntryBook> indexedEntryBooks = Maps.newHashMap(Maps.uniqueIndex(entryBooks, GET_ENTRY_BOOK_CODE));
-
- InputStream contentStream = null;
- try {
- 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());
-
- // Get all the valid fiscalPeriods Ordered by date.
- List<FiscalPeriod> fiscalPeriods = fiscalPeriodService
- .getAllUnblockedFiscalPeriods();
- Collections.sort(fiscalPeriods, new FiscalPeriodComparator());
-
- // 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;
- }
-
- // attributes declaration
- FinancialTransaction financialTransaction = null;
- Date dateEcr;
- Account account;
- Entry entry;
- BigDecimal debit;
- String entryBookCode;
- EntryBook entryBook;
-
- // 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++;
- 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 {
-
- // find financial transactions for entry period.
- List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(fiscalPeriodsBiginDate, fiscalPeriodsEndingDate);
- Map<Date, FinancialTransaction> financialTransactionsByDate = new HashMap<>();
- for (FinancialTransaction transaction : financialTransactions) {
- financialTransactionsByDate.put(transaction.getTransactionDate(), transaction);
- }
-
- // creation of the entry
- // initialisation of this attributs
-
- entry = new EntryImpl();
-
- // 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());
-
- // 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.
-
- entryBookCode = entryEBP.getJournal();
- // entryBook loading
- entryBook = indexedEntryBooks.get(entryBookCode);
-
- // if entrybook not exist create it !
- if (entryBook == null) {
- entryBook = new EntryBookImpl();
- entryBook.setCode(entryBookCode);
- //financialTransaction = null;
- // create it
- entryBook = entryBookService.createEntryBook(entryBook);
- indexedEntryBooks.put(entryBook.getCode(), entryBook);
- }
- try {
- // create transaction
- financialTransaction = financialTransactionsByDate.get(dateEcr);
- if (financialTransaction == null
- || !(dateEcr.equals(financialTransaction
- .getTransactionDate()) && entryBook
- .getCode().equals(
- financialTransaction.getEntryBook()
- .getCode()))) {
- // create financial transaction
- financialTransaction = new FinancialTransactionImpl();
- financialTransaction.setEntryBook(entryBook);
- financialTransaction.setTransactionDate(dateEcr);
- financialTransaction = financialTransactionService.createFinancialTransaction(financialTransaction);
- }
- financialTransaction.getEntry().add(entry);
- // Inside the db, the entries reference the financialTransaction
- entry.setFinancialTransaction(financialTransaction);
- financialTransactionService.createEntry(entry);
-
- } catch (LockedFinancialPeriodException | LockedEntryBookException e) {
- result.getException().addException(lineIndex, e);
- lineIndex++;
- continue;
- }
-
- }
- result.increaseCreated();
- lineIndex++;
- }
-
- if (log.isInfoEnabled()) {
- long after = System.currentTimeMillis();
- log.info("Imported form EBP : " + entryEBPs.size() + " entries in "
- + (after - before) + " ms");
- }
- } finally {
- IOUtils.closeQuietly(contentStream);
- }
- return result;
- }
-
- @Override
- public ImportResult importEntryBookFromEbp(String datas) {
- ImportResult result = new ImportResult();
-
- ImportModel<EntryBook> model = new EntryBookEBPModel();
-
- InputStream contentStream = IOUtils.toInputStream(datas);
- Import<EntryBook> entryBooks = Import.newImport(model, contentStream);
-
- for (EntryBook entryEBP : entryBooks) {
- boolean updated = entryBookService.createOrUpdateEntryBook(entryEBP);
- if (updated) {
- result.increaseUpdated();
- } else {
- result.increaseCreated();
- }
- }
- return result;
- }
-
- //#######################################################################################################
-
-// @Override
-// public String importAsPDF(String datas,
-// ImportExportEntityEnum importExportEntityEnum,
-// boolean setMode) {
-//
-// StringBuilder result = new StringBuilder();
-//
-// PDDocument doc = null;
-// try {
-// String path = LimaConfig.getInstance().getReportsDir().getAbsolutePath();
-//
-// String filePathDefault = path + File.separator
-// + DocumentsEnum.VAT.getFileName() + "_default.pdf";
-// String filePathStructured = path + File.separator
-// + DocumentsEnum.VAT.getFileName() + "_structure.pdf";
-//
-// InputStream reportsStream = new FileInputStream(datas);
-// //DocumentServiceImpl.class.getResourceAsStream("/reports/vat_form_fr.pdf");
-// // load the document
-// doc = PDDocument.load(reportsStream);
-//
-// //save default vat document with empty boxes
-// if (setMode) {
-// doc.save(filePathDefault);
-// }
-//
-// //search for all PDFBox
-// List<PDField> FieldList = doc.getDocumentCatalog().getAcroForm().getFields();
-//
-// //display inside each box their name
-// for (PDField pdField : FieldList) {
-// pdField.setValue(pdField.getFullyQualifiedName());
-// }
-//
-// // save the structured document
-// doc.save(filePathStructured);
-//
-// //sets the new pdf url to be used as pdf document edited for reports
-// if (setMode) {
-// LimaConfig.getInstance().setVatPDFUrl(datas);
-// }
-// } catch (IOException ex) {
-// log.error("Can't read vat pdf", ex);
-// result.append("Can't read vat pdf");
-// } catch (COSVisitorException ex) {
-// log.error("Can't save vat pdf", ex);
-// result.append("Can't save vat pdf");
-// } finally {
-// try {
-// if (doc != null) {
-// doc.close();
-// }
-// } catch (Exception e) {
-// // Nothing to do
-// }
-// }
-// return result.toString();
-// }
-}
Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/AccountEBPModel.java
===================================================================
--- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/AccountEBPModel.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/AccountEBPModel.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -1,5 +1,27 @@
package org.chorem.lima.business.ejb.ebp;
+/*
+ * #%L
+ * Lima :: business
+ * %%
+ * Copyright (C) 2008 - 2014 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%
+ */
+
import org.chorem.lima.business.ejb.csv.AbstractLimaModel;
import org.chorem.lima.entity.Account;
import org.chorem.lima.entity.AccountImpl;
Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/AccountEBPModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java
===================================================================
--- trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -31,13 +31,13 @@
import org.chorem.lima.business.api.AccountService;
import org.chorem.lima.business.api.EntryBookService;
import org.chorem.lima.business.api.EntryService;
+import org.chorem.lima.business.api.ExportService;
import org.chorem.lima.business.api.FinancialPeriodService;
import org.chorem.lima.business.api.FinancialStatementService;
import org.chorem.lima.business.api.FinancialTransactionService;
import org.chorem.lima.business.api.FiscalPeriodService;
import org.chorem.lima.business.api.IdentityService;
-import org.chorem.lima.business.api.NewExportService;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.business.api.ReportService;
import org.chorem.lima.business.api.VatStatementService;
import org.chorem.lima.entity.Account;
@@ -96,8 +96,8 @@
protected FiscalPeriodService fiscalPeriodService;
protected ReportService reportService;
protected EntryService entryService;
- protected NewImportService newImportService;
- protected NewExportService newExportService;
+ protected ImportService importService;
+ protected ExportService exportService;
protected FinancialStatementService financialStatementService;
protected VatStatementService vatStatementService;
protected IdentityService identityService;
@@ -140,8 +140,8 @@
financialStatementService = LimaServiceFactory.getService(FinancialStatementService.class);
vatStatementService = LimaServiceFactory.getService(VatStatementService.class);
- newImportService = LimaServiceFactory.getService(NewImportService.class);
- newExportService = LimaServiceFactory.getService(NewExportService.class);
+ importService = LimaServiceFactory.getService(ImportService.class);
+ exportService = LimaServiceFactory.getService(ExportService.class);
identityService = LimaServiceFactory.getService(IdentityService.class);
}
}
Copied: trunk/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java (from rev 3888, trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java)
===================================================================
--- trunk/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java (rev 0)
+++ trunk/lima-business/src/test/java/org/chorem/lima/business/ImportExportServiceTest.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -0,0 +1,544 @@
+package org.chorem.lima.business;
+
+/*
+ * #%L
+ * Lima :: business
+ * %%
+ * Copyright (C) 2008 - 2014 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%
+ */
+
+import com.google.common.collect.Lists;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.io.IOUtils;
+import org.chorem.lima.LimaTechnicalException;
+import org.chorem.lima.entity.Account;
+import org.chorem.lima.entity.AccountImpl;
+import org.chorem.lima.entity.Entry;
+import org.chorem.lima.entity.EntryBook;
+import org.chorem.lima.entity.EntryBookImpl;
+import org.chorem.lima.entity.FinancialStatement;
+import org.chorem.lima.entity.FinancialTransaction;
+import org.chorem.lima.entity.FiscalPeriod;
+import org.chorem.lima.entity.FiscalPeriodImpl;
+import org.chorem.lima.entity.Identity;
+import org.chorem.lima.entity.IdentityImpl;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+import java.text.ParseException;
+import java.util.Collection;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+/**
+ * Created by davidcosse on 03/06/14.
+ */
+public class ImportExportServiceTest extends AbstractLimaTest {
+
+ @Test
+ public void testExportImportAccounts() throws Exception {
+ initTestWithFiscalPeriod();
+ // make sure they are some accounts.
+ List<Account> accounts = accountService.getAllAccounts();
+ Assert.assertTrue(accountService.getAllAccounts().size() > 0);
+
+
+ // export accounts
+ String tmpDir = System.getProperty("java.io.tmpdir")+"/";
+ String export = exportService.exportAccountsAsCSV(Charset.defaultCharset().name());
+ InputStream stream = IOUtils.toInputStream(export);
+ FileOutputStream res = new FileOutputStream(tmpDir + "export-accounts.csv");
+ IOUtils.copy(stream, res);
+
+ // remove accounts
+ int nbEntities = accounts.size();
+ for (Account account : accounts) {
+ accountService.removeAccount(account);
+ }
+ Assert.assertEquals(0, accountService.getAllAccounts().size());
+
+ // import accounts
+ InputStream contentStream = null;
+ try {
+ contentStream = new FileInputStream(tmpDir + "export-accounts.csv");
+ String inportStream = IOUtils.toString(contentStream);
+ ImportResult result = importService.importAccountAsCSV(inportStream);
+
+ // make sure all account have been created
+ Assert.assertEquals(nbEntities, accountService.getAllAccounts().size());
+ Assert.assertEquals(nbEntities, result.getNbCreated());
+ Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty());
+ } finally {
+ IOUtils.closeQuietly(contentStream);
+ }
+ }
+
+ @Test
+ public void testExportImportEntryBooks() throws Exception {
+ initTestWithEntryBooks();
+
+ String tmpDir = System.getProperty("java.io.tmpdir")+"/";
+ String export = exportService.exportEntryBooksAsCSV(Charset.defaultCharset().name());
+ InputStream stream = IOUtils.toInputStream(export);
+ FileOutputStream res = new FileOutputStream(tmpDir + "export-EntryBooks.csv");
+ IOUtils.copy(stream, res);
+
+ List<EntryBook> entryBooks = entryBookService.getAllEntryBooks();
+ int nbEntities = entryBooks.size();
+ Assert.assertEquals(3, nbEntities);
+
+ for (EntryBook entryBook : entryBooks) {
+ entryBookService.removeEntryBook(entryBook);
+ }
+
+ Assert.assertEquals(0, entryBookService.getAllEntryBooks().size());
+
+ FileInputStream contentStream = null;
+ ImportResult result;
+ try {
+ contentStream = new FileInputStream(tmpDir + "export-EntryBooks.csv");
+ String inportStream = IOUtils.toString(contentStream);
+ result = importService.importEntryBooksAsCSV(inportStream);
+ } finally {
+ IOUtils.closeQuietly(contentStream);
+ }
+
+ Assert.assertEquals(nbEntities, entryBookService.getAllEntryBooks().size());
+ Assert.assertEquals(nbEntities, result.getNbCreated());
+ Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty());
+ }
+
+ @Test
+ public void testExportImportEntries() throws Exception {
+ initTestWithFinancialTransaction();
+
+ List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012"));
+ List<Entry> entries = Lists.newArrayList();
+ Assert.assertFalse(financialTransactions.isEmpty());
+ for (FinancialTransaction financialTransaction : financialTransactions) {
+ entries.addAll(financialTransaction.getEntry());
+ }
+ int nbEntities = entries.size();
+ Assert.assertEquals(2,nbEntities);
+
+ //test export
+ String tmpDir = System.getProperty("java.io.tmpdir")+"/";
+ String export = exportService.exportEntriesAsCSV(Charset.defaultCharset().name(), false);
+ InputStream stream = IOUtils.toInputStream(export);
+ FileOutputStream res = new FileOutputStream(tmpDir + "export-entries.csv");
+ IOUtils.copy(stream, res);
+
+ for (Entry entry : entries) {
+ FinancialTransaction financialTransaction = entry.getFinancialTransaction();
+ financialTransactionService.removeEntry(entry);
+ financialTransactionService.updateFinancialTransaction(financialTransaction);
+ }
+
+ // ake sure all entries have been cleared
+ entries.clear();//
+
+ financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012"));
+ for (FinancialTransaction financialTransaction : financialTransactions) {
+ entries.addAll(financialTransaction.getEntry());
+ }
+ Assert.assertTrue(entries.isEmpty());
+
+ // test import
+ FileInputStream contentStream = null;
+ ImportResult result;
+ try {
+ contentStream = new FileInputStream(tmpDir + "export-entries.csv");
+ String inputStream = IOUtils.toString(contentStream);
+ result = importService.importEntriesAsCSV(inputStream);
+ } finally {
+ IOUtils.closeQuietly(contentStream);
+ }
+
+ // valid import
+ financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012"));
+ Assert.assertEquals(1, financialTransactions.size());
+ for (FinancialTransaction financialTransaction : financialTransactions) {
+ entries.addAll(financialTransaction.getEntry());
+ }
+
+ Assert.assertEquals(nbEntities, entries.size());
+ Assert.assertEquals(nbEntities, result.getNbCreated());
+ Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty());
+ }
+
+ @Test
+ public void testExportImportFiscalPeriodsAsCSV() throws Exception {
+ initTestWithFiscalPeriod();
+
+ String tmpDir = System.getProperty("java.io.tmpdir")+"/";
+ String export = exportService.exportFiscalPeriodsAsCSV(Charset.defaultCharset().name());
+ InputStream stream = IOUtils.toInputStream(export);
+ FileOutputStream res = new FileOutputStream(tmpDir + "export-fiscal-periods.csv");
+ IOUtils.copy(stream, res);
+
+ List<FiscalPeriod> fiscalPeriods = fiscalPeriodService.getAllFiscalPeriods();
+ int nbFiscalPeriods = fiscalPeriods.size();
+ Assert.assertEquals(1, nbFiscalPeriods);
+
+ initAbstractTest();
+
+ Assert.assertEquals(0, fiscalPeriodService.getAllFiscalPeriods().size());
+
+ FileInputStream contentStream = null;
+ ImportResult result;
+ try {
+ contentStream = new FileInputStream(tmpDir + "export-fiscal-periods.csv");
+ String inputStream = IOUtils.toString(contentStream);
+ result = importService.importFiscalPeriodsAsCSV(inputStream);
+ } finally {
+ IOUtils.closeQuietly(contentStream);
+ }
+
+ Assert.assertEquals(nbFiscalPeriods, fiscalPeriodService.getAllFiscalPeriods().size());
+ Assert.assertEquals(nbFiscalPeriods, result.getNbCreated());
+ Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty());
+ }
+
+ @Test
+ public void exportImportAllAsCSVTest() throws Exception {
+ initTestWithFinancialTransaction();
+ Identity identity = new IdentityImpl();
+ identity.setName("Code Lutin");
+ identity.setAddress("12 Avenue Jules Verne");
+ identity.setZipCode("44230");
+ identity.setCity("Saint-Sébastien-sur-Loire");
+ identityService.updateIdentity(identity);
+
+ String export = exportService.exportBackup("UTF-8");
+
+ String tmpDir = System.getProperty("java.io.tmpdir")+"/TMP_BACKUP.zip";
+ createZipFile(tmpDir, export);
+
+
+ initAbstractTest();
+
+ List<ImportResult> importResults;
+ importResults = importAllFromZipFile(tmpDir);
+
+ String[] imported = {"accounts", "entryBooks", "fiscalPeriod", "financialTransactions", "entries", "identity"};
+ Assert.assertEquals(6, importResults.size());
+ for (int i = 0; i < importResults.size(); i++) {
+ 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());
+ }
+ }
+
+ protected void createZipFile(String path, String zippedBase64Str) throws Exception {
+ byte[] bytes = Base64.decodeBase64(zippedBase64Str);
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
+ IOUtils.copy(inputStream, new FileOutputStream(path));
+ }
+
+ protected List<ImportResult> importAllFromZipFile(String filePath) {
+ ZipInputStream zipInputStream = null;
+ String tmpDir = System.getProperty("java.io.tmpdir")+"/";
+ FileInputStream inputStream = null;
+ try {
+ inputStream = new FileInputStream(filePath);
+
+ zipInputStream = new ZipInputStream(inputStream);
+
+ ZipEntry entry;
+ while ((entry = zipInputStream.getNextEntry()) != null) {
+ byte[] buffer = new byte[2048];
+ FileOutputStream fileoutputstream = null;
+
+ if (entry.getName().equalsIgnoreCase("accounts.csv")) {
+ fileoutputstream = new FileOutputStream(tmpDir + "accounts.csv");
+ } else if (entry.getName().equalsIgnoreCase("entryBooks.csv")) {
+ fileoutputstream = new FileOutputStream(tmpDir + "entryBooks.csv");
+ } else if (entry.getName().equalsIgnoreCase("fiscalPeriod.csv")) {
+ fileoutputstream = new FileOutputStream(tmpDir + "fiscalPeriods.csv");
+ } else if (entry.getName().equalsIgnoreCase("financialTransactions.csv")) {
+ fileoutputstream = new FileOutputStream(tmpDir + "financialTransactions.csv");
+ } else if (entry.getName().equalsIgnoreCase("entries.csv")) {
+ fileoutputstream = new FileOutputStream(tmpDir + "entries.csv");
+ } else if (entry.getName().equalsIgnoreCase("identity.csv")) {
+ fileoutputstream = new FileOutputStream(tmpDir + "identity.csv");
+ }
+ int n;
+
+ if (fileoutputstream != null) {
+ while ((n = zipInputStream.read(buffer, 0, 2048)) > -1) {
+ fileoutputstream.write(buffer, 0, n);
+ }
+ fileoutputstream.close();
+ }
+
+ zipInputStream.closeEntry();
+ }
+ } catch (Exception e) {
+ throw new LimaTechnicalException("could not extract zip file", e);
+ } finally {
+ IOUtils.closeQuietly(zipInputStream);
+ IOUtils.closeQuietly(inputStream);
+ }
+ InputStream transactionsStream, entryBooksStream, fiscalPeriodsStream, entriesStream, accountsStream, identityStream;
+ List<ImportResult> results;
+ try {
+ entryBooksStream = new FileInputStream(tmpDir + "entryBooks.csv");
+ String entryBooksStreamString = IOUtils.toString(entryBooksStream);
+ IOUtils.closeQuietly(entryBooksStream);
+
+ // import
+ transactionsStream = new FileInputStream(tmpDir + "financialTransactions.csv");
+ String transactionsStreamString = IOUtils.toString(transactionsStream);
+ IOUtils.closeQuietly(transactionsStream);
+
+ fiscalPeriodsStream = new FileInputStream(tmpDir + "fiscalPeriods.csv");
+ String fiscalPeriodsStreamString = IOUtils.toString(fiscalPeriodsStream);
+ IOUtils.closeQuietly(fiscalPeriodsStream);
+
+ entriesStream = new FileInputStream(tmpDir + "entries.csv");
+ String entriesStreamString = IOUtils.toString(entriesStream);
+ IOUtils.closeQuietly(entriesStream);
+
+ accountsStream = new FileInputStream(tmpDir + "accounts.csv");
+ String accountsStreamString = IOUtils.toString(accountsStream);
+ IOUtils.closeQuietly(accountsStream);
+
+ identityStream = new FileInputStream(tmpDir + "identity.csv");
+ String identityStreamString = IOUtils.toString(identityStream);
+ IOUtils.closeQuietly(identityStream);
+
+ results = importService.importBackup(entryBooksStreamString, transactionsStreamString, fiscalPeriodsStreamString, accountsStreamString, entriesStreamString, identityStreamString);
+
+ } catch (Exception ex) {
+ if(log.isInfoEnabled()) {
+ log.info(ex);
+ }
+ throw new LimaTechnicalException("could not import files", ex);
+ }
+ return results;
+ }
+
+
+ @Test
+ public void testImportFiscalStatementsAsCSV() throws Exception {
+ // not ordered csv import file
+ String bcr_developed = IOUtils.toString(ImportExportServiceTest.class.getResourceAsStream("/import/bcr_developed.csv"));
+
+ ImportResult result;
+
+ result = importService.importFinancialStatementsAsCSV(bcr_developed);
+
+ Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty());
+ Assert.assertEquals(162, result.getNbCreated());
+ Assert.assertEquals(162, financialStatementService.getAllFinancialStatements().size());
+ FinancialStatement actifImmobiliseStatement = financialStatementService.getFinancialStatementByLabel("ACTIF IMMOBILISÉ");
+ Collection<FinancialStatement> subFinancialStatements = actifImmobiliseStatement.getSubFinancialStatements();
+ Assert.assertEquals(3, subFinancialStatements.size());
+ FinancialStatement bilanActifStatement = financialStatementService.getFinancialStatementByLabel("BILAN ACTIF");
+ subFinancialStatements = bilanActifStatement.getSubFinancialStatements();
+ Assert.assertEquals(6, subFinancialStatements.size());
+ }
+
+ //vat_shortened.csv
+ @Test
+ public void testImportVATStatementsAsCSV() throws Exception {
+ // not ordered csv import file
+ String bcr_developed = IOUtils.toString(ImportExportServiceTest.class.getResourceAsStream("/import/vat_shortened.csv"));
+
+ ImportResult result;
+
+ result = importService.importVATStatementsAsCSV(bcr_developed);
+
+ Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty());
+ Assert.assertEquals(55, result.getNbCreated());
+ Assert.assertEquals(55, vatStatementService.getAllVatStatements().size());
+ }
+
+ @Test
+ public void testImportEntriesFromEBP() throws Exception {
+ // create fiscal period (mandatory for import)
+ FiscalPeriod fiscalPeriod = new FiscalPeriodImpl();
+ fiscalPeriod.setBeginDate(df.parse("January 1, 2010"));
+ fiscalPeriod.setEndDate(df.parse("December 31, 2010"));
+ fiscalPeriodService.createFiscalPeriod(fiscalPeriod);
+
+ String [] accountNumbers = {"62610000","44566000","40104200","62510000","40100000","401TEEMP","51200000","60630000","411TECLI"};
+ for (String accountNumber : accountNumbers) {
+ Account account = new AccountImpl();
+ account.setAccountNumber(accountNumber);
+ accountService.createAccount(account);
+ }
+
+ 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.assertEquals(19, result.getNbCreated());
+ entriesStream.close();
+ }
+
+ @Test
+ public void testImportEntryBooksFromEBP() throws IOException {
+ InputStream entryBookStream = ImportExportServiceTest.class.getResourceAsStream("/ebp/journaux.txt");
+ String entryBookData = IOUtils.toString(entryBookStream, "ISO-8859-1");
+ entryBookStream.close();
+
+ // set somme already existing entryBooks
+ String [] entryBookCodes = {"AC","AN"};
+ for (String entryBookCode : entryBookCodes) {
+ EntryBook entryBook = new EntryBookImpl();
+ entryBook.setCode(entryBookCode);
+ entryBookService.createEntryBook(entryBook);
+ }
+
+ ImportResult result = importService.importEntryBookFromEbp(entryBookData);
+ Assert.assertEquals(7, result.getNbCreated());
+ Assert.assertEquals(2, result.getNbUpdated());
+ EntryBook updatedEntryBook = entryBookService.getEntryBookByCode("AC");
+ Assert.assertEquals("Achats de marchandises", updatedEntryBook.getLabel());
+ }
+
+ @Test
+ public void testExportImportEntriesEbp() throws Exception {
+ initTestWithFinancialTransaction();
+
+ List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012"));
+ List<Entry> entries = Lists.newArrayList();
+ Assert.assertFalse(financialTransactions.isEmpty());
+ for (FinancialTransaction financialTransaction : financialTransactions) {
+ entries.addAll(financialTransaction.getEntry());
+ }
+ Assert.assertTrue(!entries.isEmpty());
+ int nbEntities = entries.size();
+
+ //test export
+ String tmpDir = System.getProperty("java.io.tmpdir")+"/";
+ String export = exportService.exportEntriesAsEbp(Charset.defaultCharset().name());
+ InputStream stream = IOUtils.toInputStream(export);
+ FileOutputStream res = new FileOutputStream(tmpDir + "export-entries-EBP.csv");
+ IOUtils.copy(stream, res);
+
+ for (Entry entry : entries) {
+ FinancialTransaction financialTransaction = entry.getFinancialTransaction();
+ financialTransactionService.removeEntry(entry);
+ financialTransactionService.updateFinancialTransaction(financialTransaction);
+ }
+
+ // ake sure all entries have been cleared
+ entries.clear();//
+
+ financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012"));
+ for (FinancialTransaction financialTransaction : financialTransactions) {
+ entries.addAll(financialTransaction.getEntry());
+ }
+ Assert.assertTrue(entries.isEmpty());
+
+ // test import
+ FileInputStream contentStream = null;
+ ImportResult result;
+ try {
+ contentStream = new FileInputStream(tmpDir + "export-entries-EBP.csv");
+ String inputStream = IOUtils.toString(contentStream);
+ result = importService.importEntriesFromEbp(inputStream);
+ } finally {
+ IOUtils.closeQuietly(contentStream);
+ }
+
+ // valid import
+ financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012"));
+ Assert.assertEquals(1, financialTransactions.size());
+ for (FinancialTransaction financialTransaction : financialTransactions) {
+ entries.addAll(financialTransaction.getEntry());
+ }
+
+ Assert.assertEquals(nbEntities, entries.size());
+ Assert.assertEquals(nbEntities, result.getNbCreated());
+ Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty());
+ for (Entry entry : entries) {
+ Assert.assertTrue(42.0 == entry.getAmount().doubleValue());
+ }
+ }
+
+ protected void importEBPData() throws IOException, ParseException, BeginAfterEndFiscalPeriodException,
+ NotBeginNextDayOfLastFiscalPeriodException, MoreOneUnlockFiscalPeriodException, ImportEbpException {
+
+ // create fiscal period (mandatory for import)
+ FiscalPeriod fiscalPeriod = new FiscalPeriodImpl();
+ fiscalPeriod.setBeginDate(df.parse("January 1, 2012"));
+ fiscalPeriod.setEndDate(df.parse("December 31, 2012"));
+ fiscalPeriodService.createFiscalPeriod(fiscalPeriod);
+
+ // import files
+ InputStream accountStream = null, entryBookStream = null, entriesStream = null;
+ try {
+ accountStream = ImportExportServiceTest.class.getResourceAsStream("/ebp/comptes.txt");
+ entryBookStream = ImportExportServiceTest.class.getResourceAsStream("/ebp/journaux.txt");
+ entriesStream = ImportExportServiceTest.class.getResourceAsStream("/ebp/ecritures.txt");
+
+ importService.importAccountFromEbp(IOUtils.toString(accountStream, "ISO-8859-1"));
+ importService.importEntryBookFromEbp(IOUtils.toString(entryBookStream, "ISO-8859-1"));
+ importService.importEntriesFromEbp(IOUtils.toString(entriesStream, "ISO-8859-1"));
+ }
+ finally {
+ IOUtils.closeQuietly(accountStream);
+ IOUtils.closeQuietly(entryBookStream);
+ IOUtils.closeQuietly(entriesStream);
+ }
+ }
+
+ /**
+ * Do some test on imported accounts.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testImportAccountsEBP() throws Exception {
+ importEBPData();
+
+ Assert.assertEquals(571, accountService.getAllAccounts().size());
+ Assert.assertEquals("Créances", accountService.getAccountByNumber("78174000").getLabel());
+
+ // test employe and client
+ Assert.assertNotNull(accountService.getAccountByNumber("401TEEMP"));
+ Assert.assertNotNull(accountService.getAccountByNumber("411TECLI"));
+ }
+
+ /**
+ * Test que les comptes tiers sont correctement rattachés à l'arbre du
+ * plan comptable.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testImportCreateIntermediateAccount() throws Exception {
+ importEBPData();
+
+ Account compteTiers = accountService.getAccountByNumber("4");
+ Account employeAccount = accountService.getAccountByNumber("401TEEMP");
+ Assert.assertNotNull(compteTiers);
+ Assert.assertNotNull(employeAccount);
+ }
+}
Deleted: 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-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -1,544 +0,0 @@
-package org.chorem.lima.business;
-
-/*
- * #%L
- * Lima :: business
- * %%
- * Copyright (C) 2008 - 2014 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%
- */
-
-import com.google.common.collect.Lists;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.IOUtils;
-import org.chorem.lima.LimaTechnicalException;
-import org.chorem.lima.entity.Account;
-import org.chorem.lima.entity.AccountImpl;
-import org.chorem.lima.entity.Entry;
-import org.chorem.lima.entity.EntryBook;
-import org.chorem.lima.entity.EntryBookImpl;
-import org.chorem.lima.entity.FinancialStatement;
-import org.chorem.lima.entity.FinancialTransaction;
-import org.chorem.lima.entity.FiscalPeriod;
-import org.chorem.lima.entity.FiscalPeriodImpl;
-import org.chorem.lima.entity.Identity;
-import org.chorem.lima.entity.IdentityImpl;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.ByteArrayInputStream;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.Charset;
-import java.text.ParseException;
-import java.util.Collection;
-import java.util.List;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-/**
- * Created by davidcosse on 03/06/14.
- */
-public class NewImportExportServiceTest extends AbstractLimaTest {
-
- @Test
- public void testExportImportAccounts() throws Exception {
- initTestWithFiscalPeriod();
- // make sure they are some accounts.
- List<Account> accounts = accountService.getAllAccounts();
- Assert.assertTrue(accountService.getAllAccounts().size() > 0);
-
-
- // export accounts
- String tmpDir = System.getProperty("java.io.tmpdir")+"/";
- String export = newExportService.exportAccountsAsCSV(Charset.defaultCharset().name());
- InputStream stream = IOUtils.toInputStream(export);
- FileOutputStream res = new FileOutputStream(tmpDir + "export-accounts.csv");
- IOUtils.copy(stream, res);
-
- // remove accounts
- int nbEntities = accounts.size();
- for (Account account : accounts) {
- accountService.removeAccount(account);
- }
- Assert.assertEquals(0, accountService.getAllAccounts().size());
-
- // import accounts
- InputStream contentStream = null;
- try {
- contentStream = new FileInputStream(tmpDir + "export-accounts.csv");
- String inportStream = IOUtils.toString(contentStream);
- ImportResult result = newImportService.importAccountAsCSV(inportStream);
-
- // make sure all account have been created
- Assert.assertEquals(nbEntities, accountService.getAllAccounts().size());
- Assert.assertEquals(nbEntities, result.getNbCreated());
- Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty());
- } finally {
- IOUtils.closeQuietly(contentStream);
- }
- }
-
- @Test
- public void testExportImportEntryBooks() throws Exception {
- initTestWithEntryBooks();
-
- String tmpDir = System.getProperty("java.io.tmpdir")+"/";
- String export = newExportService.exportEntryBooksAsCSV(Charset.defaultCharset().name());
- InputStream stream = IOUtils.toInputStream(export);
- FileOutputStream res = new FileOutputStream(tmpDir + "export-EntryBooks.csv");
- IOUtils.copy(stream, res);
-
- List<EntryBook> entryBooks = entryBookService.getAllEntryBooks();
- int nbEntities = entryBooks.size();
- Assert.assertEquals(3, nbEntities);
-
- for (EntryBook entryBook : entryBooks) {
- entryBookService.removeEntryBook(entryBook);
- }
-
- Assert.assertEquals(0, entryBookService.getAllEntryBooks().size());
-
- FileInputStream contentStream = null;
- ImportResult result;
- try {
- contentStream = new FileInputStream(tmpDir + "export-EntryBooks.csv");
- String inportStream = IOUtils.toString(contentStream);
- result = newImportService.importEntryBooksAsCSV(inportStream);
- } finally {
- IOUtils.closeQuietly(contentStream);
- }
-
- Assert.assertEquals(nbEntities, entryBookService.getAllEntryBooks().size());
- Assert.assertEquals(nbEntities, result.getNbCreated());
- Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty());
- }
-
- @Test
- public void testExportImportEntries() throws Exception {
- initTestWithFinancialTransaction();
-
- List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012"));
- List<Entry> entries = Lists.newArrayList();
- Assert.assertFalse(financialTransactions.isEmpty());
- for (FinancialTransaction financialTransaction : financialTransactions) {
- entries.addAll(financialTransaction.getEntry());
- }
- int nbEntities = entries.size();
- Assert.assertEquals(2,nbEntities);
-
- //test export
- String tmpDir = System.getProperty("java.io.tmpdir")+"/";
- 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);
-
- for (Entry entry : entries) {
- FinancialTransaction financialTransaction = entry.getFinancialTransaction();
- financialTransactionService.removeEntry(entry);
- financialTransactionService.updateFinancialTransaction(financialTransaction);
- }
-
- // ake sure all entries have been cleared
- entries.clear();//
-
- financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012"));
- for (FinancialTransaction financialTransaction : financialTransactions) {
- entries.addAll(financialTransaction.getEntry());
- }
- Assert.assertTrue(entries.isEmpty());
-
- // test import
- FileInputStream contentStream = null;
- ImportResult result;
- try {
- contentStream = new FileInputStream(tmpDir + "export-entries.csv");
- String inputStream = IOUtils.toString(contentStream);
- result = newImportService.importEntriesAsCSV(inputStream);
- } finally {
- IOUtils.closeQuietly(contentStream);
- }
-
- // valid import
- financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012"));
- Assert.assertEquals(1, financialTransactions.size());
- for (FinancialTransaction financialTransaction : financialTransactions) {
- entries.addAll(financialTransaction.getEntry());
- }
-
- Assert.assertEquals(nbEntities, entries.size());
- Assert.assertEquals(nbEntities, result.getNbCreated());
- Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty());
- }
-
- @Test
- public void testExportImportFiscalPeriodsAsCSV() throws Exception {
- initTestWithFiscalPeriod();
-
- String tmpDir = System.getProperty("java.io.tmpdir")+"/";
- 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);
-
- List<FiscalPeriod> fiscalPeriods = fiscalPeriodService.getAllFiscalPeriods();
- int nbFiscalPeriods = fiscalPeriods.size();
- Assert.assertEquals(1, nbFiscalPeriods);
-
- initAbstractTest();
-
- Assert.assertEquals(0, fiscalPeriodService.getAllFiscalPeriods().size());
-
- FileInputStream contentStream = null;
- ImportResult result;
- try {
- contentStream = new FileInputStream(tmpDir + "export-fiscal-periods.csv");
- String inputStream = IOUtils.toString(contentStream);
- result = newImportService.importFiscalPeriodsAsCSV(inputStream);
- } finally {
- IOUtils.closeQuietly(contentStream);
- }
-
- Assert.assertEquals(nbFiscalPeriods, fiscalPeriodService.getAllFiscalPeriods().size());
- Assert.assertEquals(nbFiscalPeriods, result.getNbCreated());
- Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty());
- }
-
- @Test
- public void exportImportAllAsCSVTest() throws Exception {
- initTestWithFinancialTransaction();
- Identity identity = new IdentityImpl();
- identity.setName("Code Lutin");
- identity.setAddress("12 Avenue Jules Verne");
- identity.setZipCode("44230");
- identity.setCity("Saint-Sébastien-sur-Loire");
- identityService.updateIdentity(identity);
-
- String export = newExportService.exportBackup("UTF-8");
-
- String tmpDir = System.getProperty("java.io.tmpdir")+"/TMP_BACKUP.zip";
- createZipFile(tmpDir, export);
-
-
- initAbstractTest();
-
- List<ImportResult> importResults;
- importResults = importAllFromZipFile(tmpDir);
-
- String[] imported = {"accounts", "entryBooks", "fiscalPeriod", "financialTransactions", "entries", "identity"};
- Assert.assertEquals(6, importResults.size());
- for (int i = 0; i < importResults.size(); i++) {
- 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());
- }
- }
-
- protected void createZipFile(String path, String zippedBase64Str) throws Exception {
- byte[] bytes = Base64.decodeBase64(zippedBase64Str);
- ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
- IOUtils.copy(inputStream, new FileOutputStream(path));
- }
-
- protected List<ImportResult> importAllFromZipFile(String filePath) {
- ZipInputStream zipInputStream = null;
- String tmpDir = System.getProperty("java.io.tmpdir")+"/";
- FileInputStream inputStream = null;
- try {
- inputStream = new FileInputStream(filePath);
-
- zipInputStream = new ZipInputStream(inputStream);
-
- ZipEntry entry;
- while ((entry = zipInputStream.getNextEntry()) != null) {
- byte[] buffer = new byte[2048];
- FileOutputStream fileoutputstream = null;
-
- if (entry.getName().equalsIgnoreCase("accounts.csv")) {
- fileoutputstream = new FileOutputStream(tmpDir + "accounts.csv");
- } else if (entry.getName().equalsIgnoreCase("entryBooks.csv")) {
- fileoutputstream = new FileOutputStream(tmpDir + "entryBooks.csv");
- } else if (entry.getName().equalsIgnoreCase("fiscalPeriod.csv")) {
- fileoutputstream = new FileOutputStream(tmpDir + "fiscalPeriods.csv");
- } else if (entry.getName().equalsIgnoreCase("financialTransactions.csv")) {
- fileoutputstream = new FileOutputStream(tmpDir + "financialTransactions.csv");
- } else if (entry.getName().equalsIgnoreCase("entries.csv")) {
- fileoutputstream = new FileOutputStream(tmpDir + "entries.csv");
- } else if (entry.getName().equalsIgnoreCase("identity.csv")) {
- fileoutputstream = new FileOutputStream(tmpDir + "identity.csv");
- }
- int n;
-
- if (fileoutputstream != null) {
- while ((n = zipInputStream.read(buffer, 0, 2048)) > -1) {
- fileoutputstream.write(buffer, 0, n);
- }
- fileoutputstream.close();
- }
-
- zipInputStream.closeEntry();
- }
- } catch (Exception e) {
- throw new LimaTechnicalException("could not extract zip file", e);
- } finally {
- IOUtils.closeQuietly(zipInputStream);
- IOUtils.closeQuietly(inputStream);
- }
- InputStream transactionsStream, entryBooksStream, fiscalPeriodsStream, entriesStream, accountsStream, identityStream;
- List<ImportResult> results;
- try {
- entryBooksStream = new FileInputStream(tmpDir + "entryBooks.csv");
- String entryBooksStreamString = IOUtils.toString(entryBooksStream);
- IOUtils.closeQuietly(entryBooksStream);
-
- // import
- transactionsStream = new FileInputStream(tmpDir + "financialTransactions.csv");
- String transactionsStreamString = IOUtils.toString(transactionsStream);
- IOUtils.closeQuietly(transactionsStream);
-
- fiscalPeriodsStream = new FileInputStream(tmpDir + "fiscalPeriods.csv");
- String fiscalPeriodsStreamString = IOUtils.toString(fiscalPeriodsStream);
- IOUtils.closeQuietly(fiscalPeriodsStream);
-
- entriesStream = new FileInputStream(tmpDir + "entries.csv");
- String entriesStreamString = IOUtils.toString(entriesStream);
- IOUtils.closeQuietly(entriesStream);
-
- accountsStream = new FileInputStream(tmpDir + "accounts.csv");
- String accountsStreamString = IOUtils.toString(accountsStream);
- IOUtils.closeQuietly(accountsStream);
-
- identityStream = new FileInputStream(tmpDir + "identity.csv");
- String identityStreamString = IOUtils.toString(identityStream);
- IOUtils.closeQuietly(identityStream);
-
- results = newImportService.importBackup(entryBooksStreamString, transactionsStreamString, fiscalPeriodsStreamString, accountsStreamString, entriesStreamString, identityStreamString);
-
- } catch (Exception ex) {
- if(log.isInfoEnabled()) {
- log.info(ex);
- }
- throw new LimaTechnicalException("could not import files", ex);
- }
- return results;
- }
-
-
- @Test
- public void testImportFiscalStatementsAsCSV() throws Exception {
- // not ordered csv import file
- String bcr_developed = IOUtils.toString(NewImportExportServiceTest.class.getResourceAsStream("/import/bcr_developed.csv"));
-
- ImportResult result;
-
- result = newImportService.importFinancialStatementsAsCSV(bcr_developed);
-
- Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty());
- Assert.assertEquals(162, result.getNbCreated());
- Assert.assertEquals(162, financialStatementService.getAllFinancialStatements().size());
- FinancialStatement actifImmobiliseStatement = financialStatementService.getFinancialStatementByLabel("ACTIF IMMOBILISÉ");
- Collection<FinancialStatement> subFinancialStatements = actifImmobiliseStatement.getSubFinancialStatements();
- Assert.assertEquals(3, subFinancialStatements.size());
- FinancialStatement bilanActifStatement = financialStatementService.getFinancialStatementByLabel("BILAN ACTIF");
- subFinancialStatements = bilanActifStatement.getSubFinancialStatements();
- Assert.assertEquals(6, subFinancialStatements.size());
- }
-
- //vat_shortened.csv
- @Test
- public void testImportVATStatementsAsCSV() throws Exception {
- // not ordered csv import file
- String bcr_developed = IOUtils.toString(NewImportExportServiceTest.class.getResourceAsStream("/import/vat_shortened.csv"));
-
- ImportResult result;
-
- result = newImportService.importVATStatementsAsCSV(bcr_developed);
-
- Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty());
- Assert.assertEquals(55, result.getNbCreated());
- Assert.assertEquals(55, vatStatementService.getAllVatStatements().size());
- }
-
- @Test
- public void testImportEntriesFromEBP() throws Exception {
- // create fiscal period (mandatory for import)
- FiscalPeriod fiscalPeriod = new FiscalPeriodImpl();
- fiscalPeriod.setBeginDate(df.parse("January 1, 2010"));
- fiscalPeriod.setEndDate(df.parse("December 31, 2010"));
- fiscalPeriodService.createFiscalPeriod(fiscalPeriod);
-
- String [] accountNumbers = {"62610000","44566000","40104200","62510000","40100000","401TEEMP","51200000","60630000","411TECLI"};
- for (String accountNumber : accountNumbers) {
- Account account = new AccountImpl();
- account.setAccountNumber(accountNumber);
- accountService.createAccount(account);
- }
-
- InputStream entriesStream = NewImportExportServiceTest.class.getResourceAsStream("/ebp/ecritures.txt");
- String entriesData = IOUtils.toString(entriesStream, "ISO-8859-1");
- ImportResult result = newImportService.importEntriesFromEbp(entriesData);
- Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty());
- Assert.assertEquals(19, result.getNbCreated());
- entriesStream.close();
- }
-
- @Test
- public void testImportEntryBooksFromEBP() throws IOException {
- InputStream entryBookStream = NewImportExportServiceTest.class.getResourceAsStream("/ebp/journaux.txt");
- String entryBookData = IOUtils.toString(entryBookStream, "ISO-8859-1");
- entryBookStream.close();
-
- // set somme already existing entryBooks
- String [] entryBookCodes = {"AC","AN"};
- for (String entryBookCode : entryBookCodes) {
- EntryBook entryBook = new EntryBookImpl();
- entryBook.setCode(entryBookCode);
- entryBookService.createEntryBook(entryBook);
- }
-
- ImportResult result = newImportService.importEntryBookFromEbp(entryBookData);
- Assert.assertEquals(7, result.getNbCreated());
- Assert.assertEquals(2, result.getNbUpdated());
- EntryBook updatedEntryBook = entryBookService.getEntryBookByCode("AC");
- Assert.assertEquals("Achats de marchandises", updatedEntryBook.getLabel());
- }
-
- @Test
- public void testExportImportEntriesEbp() throws Exception {
- initTestWithFinancialTransaction();
-
- List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012"));
- List<Entry> entries = Lists.newArrayList();
- Assert.assertFalse(financialTransactions.isEmpty());
- for (FinancialTransaction financialTransaction : financialTransactions) {
- entries.addAll(financialTransaction.getEntry());
- }
- Assert.assertTrue(!entries.isEmpty());
- int nbEntities = entries.size();
-
- //test export
- String tmpDir = System.getProperty("java.io.tmpdir")+"/";
- String export = newExportService.exportEntriesAsEbp(Charset.defaultCharset().name());
- InputStream stream = IOUtils.toInputStream(export);
- FileOutputStream res = new FileOutputStream(tmpDir + "export-entries-EBP.csv");
- IOUtils.copy(stream, res);
-
- for (Entry entry : entries) {
- FinancialTransaction financialTransaction = entry.getFinancialTransaction();
- financialTransactionService.removeEntry(entry);
- financialTransactionService.updateFinancialTransaction(financialTransaction);
- }
-
- // ake sure all entries have been cleared
- entries.clear();//
-
- financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012"));
- for (FinancialTransaction financialTransaction : financialTransactions) {
- entries.addAll(financialTransaction.getEntry());
- }
- Assert.assertTrue(entries.isEmpty());
-
- // test import
- FileInputStream contentStream = null;
- ImportResult result;
- try {
- contentStream = new FileInputStream(tmpDir + "export-entries-EBP.csv");
- String inputStream = IOUtils.toString(contentStream);
- result = newImportService.importEntriesFromEbp(inputStream);
- } finally {
- IOUtils.closeQuietly(contentStream);
- }
-
- // valid import
- financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012"));
- Assert.assertEquals(1, financialTransactions.size());
- for (FinancialTransaction financialTransaction : financialTransactions) {
- entries.addAll(financialTransaction.getEntry());
- }
-
- Assert.assertEquals(nbEntities, entries.size());
- Assert.assertEquals(nbEntities, result.getNbCreated());
- Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty());
- for (Entry entry : entries) {
- Assert.assertTrue(42.0 == entry.getAmount().doubleValue());
- }
- }
-
- protected void importEBPData() throws IOException, ParseException, BeginAfterEndFiscalPeriodException,
- NotBeginNextDayOfLastFiscalPeriodException, MoreOneUnlockFiscalPeriodException, ImportEbpException {
-
- // create fiscal period (mandatory for import)
- FiscalPeriod fiscalPeriod = new FiscalPeriodImpl();
- fiscalPeriod.setBeginDate(df.parse("January 1, 2012"));
- fiscalPeriod.setEndDate(df.parse("December 31, 2012"));
- fiscalPeriodService.createFiscalPeriod(fiscalPeriod);
-
- // import files
- InputStream accountStream = null, entryBookStream = null, entriesStream = null;
- try {
- accountStream = NewImportExportServiceTest.class.getResourceAsStream("/ebp/comptes.txt");
- entryBookStream = NewImportExportServiceTest.class.getResourceAsStream("/ebp/journaux.txt");
- entriesStream = NewImportExportServiceTest.class.getResourceAsStream("/ebp/ecritures.txt");
-
- newImportService.importAccountFromEbp(IOUtils.toString(accountStream, "ISO-8859-1"));
- newImportService.importEntryBookFromEbp(IOUtils.toString(entryBookStream, "ISO-8859-1"));
- newImportService.importEntriesFromEbp(IOUtils.toString(entriesStream, "ISO-8859-1"));
- }
- finally {
- IOUtils.closeQuietly(accountStream);
- IOUtils.closeQuietly(entryBookStream);
- IOUtils.closeQuietly(entriesStream);
- }
- }
-
- /**
- * Do some test on imported accounts.
- *
- * @throws Exception
- */
- @Test
- public void testImportAccountsEBP() throws Exception {
- importEBPData();
-
- Assert.assertEquals(571, accountService.getAllAccounts().size());
- Assert.assertEquals("Créances", accountService.getAccountByNumber("78174000").getLabel());
-
- // test employe and client
- Assert.assertNotNull(accountService.getAccountByNumber("401TEEMP"));
- Assert.assertNotNull(accountService.getAccountByNumber("411TECLI"));
- }
-
- /**
- * Test que les comptes tiers sont correctement rattachés à l'arbre du
- * plan comptable.
- *
- * @throws Exception
- */
- @Test
- public void testImportCreateIntermediateAccount() throws Exception {
- importEBPData();
-
- Account compteTiers = accountService.getAccountByNumber("4");
- Account employeAccount = accountService.getAccountByNumber("401TEEMP");
- Assert.assertNotNull(compteTiers);
- Assert.assertNotNull(employeAccount);
- }
-}
Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ImportServiceRuleFrTest.java
===================================================================
--- trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ImportServiceRuleFrTest.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ImportServiceRuleFrTest.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -24,8 +24,8 @@
package org.chorem.lima.business.accountingrules;
import org.chorem.lima.business.AccountingRules;
+import org.chorem.lima.business.ImportExportServiceTest;
import org.chorem.lima.business.LimaConfig;
-import org.chorem.lima.business.NewImportExportServiceTest;
import org.junit.Assert;
import org.junit.Test;
@@ -44,7 +44,7 @@
* Last update : $Date$
* By : $Author$
*/
-public class ImportServiceRuleFrTest extends NewImportExportServiceTest {
+public class ImportServiceRuleFrTest extends ImportExportServiceTest {
protected Properties getTestConfiguration() {
Properties config = super.getTestConfiguration();
Copied: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java (from rev 3888, 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/ExportService.java (rev 0)
+++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -0,0 +1,64 @@
+/*
+ * #%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.api;
+
+/**
+ * Import export service.
+ * <p/>
+ * Currently import and export as XML.
+ *
+ * @author chatellier
+ * @version $Revision$
+ * <p/>
+ * Last update : $Date$
+ * By : $Author$
+ */
+public interface ExportService {
+
+ //####################################### CSV ##############################################
+
+ String exportAccountsAsCSV(String charset);
+
+ String exportEntryBooksAsCSV(String charset);
+
+ String exportFiscalPeriodsAsCSV(String charset);
+
+ String exportEntriesAsCSV(String charset, Boolean humanReadable);
+
+ String exportFinancialStatements(String charset) throws Exception;
+
+ String exportVatStatements(String charset) throws Exception;
+
+ String exportBackup(String charset);
+
+ //####################################### EBP ##############################################
+
+ String exportAccountAsEbp(String charset) throws Exception;
+
+ String exportEntriesAsEbp(String charset) throws Exception;
+
+ String exportEntryBookAsEbp(String charset) throws Exception;
+}
Copied: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java (from rev 3888, 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/ImportService.java (rev 0)
+++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -0,0 +1,63 @@
+package org.chorem.lima.business.api;
+
+/*
+ * #%L
+ * Lima :: business API
+ * %%
+ * Copyright (C) 2008 - 2014 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%
+ */
+
+import org.chorem.lima.business.AlreadyExistAccountException;
+import org.chorem.lima.business.ImportResult;
+import org.chorem.lima.business.InvalidAccountNumberException;
+
+import java.util.List;
+
+/**
+ * Created by davidcosse on 03/06/14.
+ */
+public interface ImportService {
+
+ //####################################### CSV ##############################################
+
+ ImportResult importAccountAsCSV(String contents);
+
+ ImportResult importEntryBooksAsCSV(String contents);
+
+ ImportResult importFiscalPeriodsAsCSV(String contents);
+
+ ImportResult importEntriesAsCSV(String contents);
+
+ ImportResult importFinancialStatementsAsCSV(String contents);
+
+ ImportResult importVATStatementsAsCSV(String contents);
+
+ List<ImportResult> importBackup(String entryBooks, String transactions, String fiscalPeriods, String accounts, String entries, String identity) throws AlreadyExistAccountException, InvalidAccountNumberException;
+
+ //####################################### EBP ##############################################
+
+ ImportResult importAccountFromEbp(String datas);
+
+ ImportResult importEntriesFromEbp(String datas);
+
+ ImportResult importEntryBookFromEbp(String datas);
+
+// String importAsPDF(String data,
+// ImportExportEntityEnum importExportEntityEnum,
+// boolean saveMode);
+}
Deleted: 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-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -1,64 +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.api;
-
-/**
- * Import export service.
- * <p/>
- * Currently import and export as XML.
- *
- * @author chatellier
- * @version $Revision$
- * <p/>
- * Last update : $Date$
- * By : $Author$
- */
-public interface NewExportService {
-
- //####################################### CSV ##############################################
-
- String exportAccountsAsCSV(String charset);
-
- String exportEntryBooksAsCSV(String charset);
-
- String exportFiscalPeriodsAsCSV(String charset);
-
- String exportEntriesAsCSV(String charset, Boolean humanReadable);
-
- String exportFinancialStatements(String charset) throws Exception;
-
- String exportVatStatements(String charset) throws Exception;
-
- String exportBackup(String charset);
-
- //####################################### EBP ##############################################
-
- String exportAccountAsEbp(String charset) throws Exception;
-
- String exportEntriesAsEbp(String charset) throws Exception;
-
- String exportEntryBookAsEbp(String charset) throws Exception;
-}
Deleted: 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-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -1,63 +0,0 @@
-package org.chorem.lima.business.api;
-
-/*
- * #%L
- * Lima :: business API
- * %%
- * Copyright (C) 2008 - 2014 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%
- */
-
-import org.chorem.lima.business.AlreadyExistAccountException;
-import org.chorem.lima.business.ImportResult;
-import org.chorem.lima.business.InvalidAccountNumberException;
-
-import java.util.List;
-
-/**
- * Created by davidcosse on 03/06/14.
- */
-public interface NewImportService {
-
- //####################################### CSV ##############################################
-
- ImportResult importAccountAsCSV(String contents);
-
- ImportResult importEntryBooksAsCSV(String contents);
-
- ImportResult importFiscalPeriodsAsCSV(String contents);
-
- ImportResult importEntriesAsCSV(String contents);
-
- ImportResult importFinancialStatementsAsCSV(String contents);
-
- ImportResult importVATStatementsAsCSV(String contents);
-
- List<ImportResult> importBackup(String entryBooks, String transactions, String fiscalPeriods, String accounts, String entries, String identity) throws AlreadyExistAccountException, InvalidAccountNumberException;
-
- //####################################### EBP ##############################################
-
- ImportResult importAccountFromEbp(String datas);
-
- ImportResult importEntriesFromEbp(String datas);
-
- ImportResult importEntryBookFromEbp(String datas);
-
-// String importAsPDF(String data,
-// ImportExportEntityEnum importExportEntityEnum,
-// boolean saveMode);
-}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -33,7 +33,7 @@
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.UsedAccountException;
import org.chorem.lima.business.api.AccountService;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.entity.Account;
import org.chorem.lima.enums.AccountsChartEnum;
import org.chorem.lima.enums.ImportExportEnum;
@@ -117,7 +117,7 @@
public AccountViewHandler(AccountView view) {
this.view = view;
// Gets factory service
- LimaServiceFactory.addServiceListener(NewImportService.class, this);
+ LimaServiceFactory.addServiceListener(ImportService.class, this);
accountService = LimaServiceFactory.getService(AccountService.class);
errorHelper = new ErrorHelper(LimaConfig.getInstance());
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountComboBoxModel.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountComboBoxModel.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountComboBoxModel.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -29,7 +29,7 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.AccountService;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.entity.Account;
import org.chorem.lima.service.LimaServiceFactory;
@@ -56,7 +56,7 @@
LimaServiceFactory.getService(
AccountService.class);
LimaServiceFactory.addServiceListener(AccountService.class, this);
- LimaServiceFactory.addServiceListener(NewImportService.class, this);
+ LimaServiceFactory.addServiceListener(ImportService.class, this);
datasCache = getDataList();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookComboBoxModel.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookComboBoxModel.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookComboBoxModel.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -29,7 +29,7 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.EntryBookService;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.entity.EntryBook;
import org.chorem.lima.service.LimaServiceFactory;
@@ -62,7 +62,7 @@
entryBookService =
LimaServiceFactory.getService(EntryBookService.class);
LimaServiceFactory.addServiceListener(EntryBookService.class, this);
- LimaServiceFactory.addServiceListener(NewImportService.class, this);
+ LimaServiceFactory.addServiceListener(ImportService.class, this);
cacheDatas = getDataList();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FinancialPeriodComboBoxModel.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FinancialPeriodComboBoxModel.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FinancialPeriodComboBoxModel.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -30,7 +30,7 @@
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.FinancialPeriodService;
import org.chorem.lima.business.api.FiscalPeriodService;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.entity.FinancialPeriod;
import org.chorem.lima.entity.FiscalPeriod;
import org.chorem.lima.service.LimaServiceFactory;
@@ -84,7 +84,7 @@
FinancialPeriodService.class);
LimaServiceFactory.addServiceListener(FinancialPeriodService.class, this);
LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this);
- LimaServiceFactory.addServiceListener(NewImportService.class, this);
+ LimaServiceFactory.addServiceListener(ImportService.class, this);
if (displayAllPeriods) {
datasCache = getAllDataList();
} else {
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxModel.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxModel.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxModel.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -29,7 +29,7 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.FiscalPeriodService;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.entity.FiscalPeriod;
import org.chorem.lima.service.LimaServiceFactory;
@@ -54,7 +54,7 @@
LimaServiceFactory.getService(
FiscalPeriodService.class);
LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this);
- LimaServiceFactory.addServiceListener(NewImportService.class, this);
+ LimaServiceFactory.addServiceListener(ImportService.class, this);
datasCache = getDataList();
if (log.isDebugEnabled()) {
@@ -69,7 +69,7 @@
LimaServiceFactory.getService(
FiscalPeriodService.class);
LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this);
- LimaServiceFactory.addServiceListener(NewImportService.class, this);
+ LimaServiceFactory.addServiceListener(ImportService.class, this);
datasCache = getAllDataList();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/LeafAccountComboBoxModel.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/LeafAccountComboBoxModel.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/LeafAccountComboBoxModel.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -29,7 +29,7 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.AccountService;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.business.utils.AccountComparator;
import org.chorem.lima.entity.Account;
import org.chorem.lima.service.LimaServiceFactory;
@@ -57,7 +57,7 @@
accountService =
LimaServiceFactory.getService(AccountService.class);
LimaServiceFactory.addServiceListener(AccountService.class, this);
- LimaServiceFactory.addServiceListener(NewImportService.class, this);
+ LimaServiceFactory.addServiceListener(ImportService.class, this);
datasCache = getDataList();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -31,7 +31,7 @@
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.UsedEntryBookException;
import org.chorem.lima.business.api.EntryBookService;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.entity.EntryBook;
import org.chorem.lima.entity.EntryBookImpl;
import org.chorem.lima.enums.EntryBooksChartEnum;
@@ -72,7 +72,7 @@
public EntryBookViewHandler(EntryBookView view) {
this.view = view;
entryBookService = LimaServiceFactory.getService(EntryBookService.class);
- LimaServiceFactory.addServiceListener(NewImportService.class, this);
+ LimaServiceFactory.addServiceListener(ImportService.class, this);
errorHelper = new ErrorHelper(LimaConfig.getInstance());
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -36,7 +36,7 @@
import org.chorem.lima.business.WithoutEntryBookFinancialTransactionsException;
import org.chorem.lima.business.api.FinancialPeriodService;
import org.chorem.lima.business.api.FiscalPeriodService;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.business.utils.FinancialPeriodComparator;
import org.chorem.lima.entity.ClosedPeriodicEntryBook;
import org.chorem.lima.entity.Entry;
@@ -77,7 +77,7 @@
this.view = view;
financialPeriodService = LimaServiceFactory.getService(FinancialPeriodService.class);
- LimaServiceFactory.addServiceListener(NewImportService.class, this);
+ LimaServiceFactory.addServiceListener(ImportService.class, this);
LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this);
errorHelper = new ErrorHelper(LimaConfig.getInstance());
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -29,7 +29,7 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.FinancialStatementService;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.entity.Account;
import org.chorem.lima.entity.FinancialStatement;
import org.chorem.lima.entity.FinancialStatementImpl;
@@ -74,7 +74,7 @@
financialStatementService =
LimaServiceFactory.getService(
FinancialStatementService.class);
- LimaServiceFactory.addServiceListener(NewImportService.class, this);
+ LimaServiceFactory.addServiceListener(ImportService.class, this);
init();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -39,7 +39,7 @@
import org.chorem.lima.business.api.FinancialPeriodService;
import org.chorem.lima.business.api.FinancialTransactionService;
import org.chorem.lima.business.api.FiscalPeriodService;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.entity.Entry;
import org.chorem.lima.entity.EntryBook;
import org.chorem.lima.entity.EntryImpl;
@@ -105,7 +105,7 @@
financialTransactionService = LimaServiceFactory.getService(FinancialTransactionService.class);
LimaServiceFactory.addServiceListener(FinancialPeriodService.class, this);
LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this);
- LimaServiceFactory.addServiceListener(NewImportService.class, this);
+ LimaServiceFactory.addServiceListener(ImportService.class, this);
errorHelper = new ErrorHelper(LimaConfig.getInstance());
initShortCuts();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/AccountsPane.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/AccountsPane.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/AccountsPane.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -30,7 +30,7 @@
import org.chorem.lima.LimaContext;
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.AccountService;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.service.LimaServiceFactory;
import org.chorem.lima.ui.MainView;
@@ -60,7 +60,7 @@
accountService = LimaServiceFactory.getService(AccountService.class);
LimaServiceFactory.addServiceListener(AccountService.class, this);
- LimaServiceFactory.addServiceListener(NewImportService.class, this);
+ LimaServiceFactory.addServiceListener(ImportService.class, this);
refresh();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/EntryBooksPane.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/EntryBooksPane.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/EntryBooksPane.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -30,7 +30,7 @@
import org.chorem.lima.LimaContext;
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.EntryBookService;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.entity.EntryBook;
import org.chorem.lima.service.LimaServiceFactory;
import org.chorem.lima.ui.MainView;
@@ -62,7 +62,7 @@
entryBookService = LimaServiceFactory.getService(EntryBookService.class);
LimaServiceFactory.addServiceListener(EntryBookService.class, this);
- LimaServiceFactory.addServiceListener(NewImportService.class, this);
+ LimaServiceFactory.addServiceListener(ImportService.class, this);
refresh();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FinancialTransactionsPane.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FinancialTransactionsPane.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FinancialTransactionsPane.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -32,7 +32,7 @@
import org.chorem.lima.business.api.EntryBookService;
import org.chorem.lima.business.api.FinancialTransactionService;
import org.chorem.lima.business.api.FiscalPeriodService;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.entity.EntryBook;
import org.chorem.lima.entity.FinancialTransaction;
import org.chorem.lima.entity.FiscalPeriod;
@@ -73,7 +73,7 @@
entryBookService = LimaServiceFactory.getService(EntryBookService.class);
LimaServiceFactory.addServiceListener(FinancialTransactionService.class, this);
LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this);
- LimaServiceFactory.addServiceListener(NewImportService.class, this);
+ LimaServiceFactory.addServiceListener(ImportService.class, this);
refresh();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FiscalYearsPane.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FiscalYearsPane.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FiscalYearsPane.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -30,7 +30,7 @@
import org.chorem.lima.LimaContext;
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.FiscalPeriodService;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.entity.FiscalPeriod;
import org.chorem.lima.service.LimaServiceFactory;
import org.chorem.lima.ui.MainView;
@@ -68,7 +68,7 @@
fiscalPeriodService = LimaServiceFactory.getService(FiscalPeriodService.class);
LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this);
- LimaServiceFactory.addServiceListener(NewImportService.class, this);
+ LimaServiceFactory.addServiceListener(ImportService.class, this);
refresh();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/identity/IdentityForm.css
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/identity/IdentityForm.css 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/identity/IdentityForm.css 2014-08-01 14:29:33 UTC (rev 3889)
@@ -1,3 +1,24 @@
+/*
+ * #%L
+ * Lima :: Swing
+ * %%
+ * Copyright (C) 2008 - 2014 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%
+ */
#dialog {
modal : true;
defaultCloseOperation : {JDialog.DO_NOTHING_ON_CLOSE};
Property changes on: trunk/lima-swing/src/main/java/org/chorem/lima/ui/identity/IdentityForm.css
___________________________________________________________________
Added: svn:eol-style
+ native
Added: svn:keywords
+ Author Date Id Revision HeadURL
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-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -35,8 +35,8 @@
import org.chorem.lima.LimaTechnicalException;
import org.chorem.lima.business.ImportEbpException;
import org.chorem.lima.business.ImportResult;
-import org.chorem.lima.business.api.NewExportService;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ExportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.enums.EncodingEnum;
import org.chorem.lima.enums.ImportExportEnum;
import org.chorem.lima.service.LimaServiceFactory;
@@ -82,15 +82,10 @@
*/
protected EncodingEnum encodingEnum;
- protected NewImportService importService;
+ protected ImportService importService;
- @Deprecated
- protected NewExportService exportService;
+ protected ExportService exportService;
- protected NewImportService newImportService;
-
- protected NewExportService newExportService;
-
private ImportExportWaitView waitView;
protected ErrorHelper errorHelper;
@@ -99,8 +94,8 @@
viewComponent = view;
//services
- newImportService = LimaServiceFactory.getService(NewImportService.class);
- newExportService = LimaServiceFactory.getService(NewExportService.class);
+ importService = LimaServiceFactory.getService(ImportService.class);
+ exportService = LimaServiceFactory.getService(ExportService.class);
//create the wait dialog panel
waitView = new ImportExportWaitView();
@@ -141,40 +136,40 @@
//####################################### CSV ##############################################
case CSV_ACCOUNTCHARTS_EXPORT:
- datas = newExportService.exportAccountsAsCSV(charset.name());
+ datas = exportService.exportAccountsAsCSV(charset.name());
createFile(filePath, charset.name(), datas);
break;
case CSV_ACCOUNTCHARTS_IMPORT:
datas = extractFile(filePath, charset.name());
- importResult = newImportService.importAccountAsCSV(datas);
+ importResult = importService.importAccountAsCSV(datas);
// TODO DCossé 24/07/14 change result
result = "SUCCESS";
break;
case CSV_ENTRYBOOKS_EXPORT:
- datas = newExportService.exportEntryBooksAsCSV(charset.name());
+ datas = exportService.exportEntryBooksAsCSV(charset.name());
createFile(filePath, charset.name(), datas);
break;
case CSV_ENTRYBOOKS_IMPORT:
datas = extractFile(filePath, charset.name());
- importResult = newImportService.importEntryBooksAsCSV(datas);
+ importResult = importService.importEntryBooksAsCSV(datas);
// TODO DCossé 24/07/14 change result
result = "SUCCESS";
break;
case CSV_ENTRIES_EXPORT:
- datas = newExportService.exportEntriesAsCSV(charset.name(), true);
+ datas = exportService.exportEntriesAsCSV(charset.name(), true);
createFile(filePath, charset.name(), datas);
break;
case CSV_ENTRIES_IMPORT:
datas = extractFile(filePath, charset.name());
- importResult = newImportService.importEntriesAsCSV(datas);
+ importResult = importService.importEntriesAsCSV(datas);
// TODO DCossé 24/07/14 change result
result = "SUCCESS";
break;
case CSV_ALL_EXPORT:
- datas = newExportService.exportBackup(charset.name());
+ datas = exportService.exportBackup(charset.name());
createZipFile(filePath, datas);
break;
case CSV_ALL_IMPORT:
@@ -184,23 +179,23 @@
break;
case CSV_VAT_EXPORT:
- datas = newExportService.exportVatStatements(charset.name());
+ datas = exportService.exportVatStatements(charset.name());
createFile(filePath, charset.name(), datas);
break;
case CSV_VAT_IMPORT:
datas = extractFile(filePath, charset.name());
- importResult = newImportService.importVATStatementsAsCSV(datas);
+ importResult = importService.importVATStatementsAsCSV(datas);
// TODO DCossé 24/07/14 change result
result = "SUCCESS";
break;
case CSV_FINANCIALSTATEMENTS_EXPORT:
- datas = newExportService.exportFinancialStatements(charset.name());
+ datas = exportService.exportFinancialStatements(charset.name());
createFile(filePath, charset.name(), datas);
break;
case CSV_FINANCIALSTATEMENTS_IMPORT:
datas = extractFile(filePath, charset.name());
- importResult = newImportService.importFinancialStatementsAsCSV(datas);
+ importResult = importService.importFinancialStatementsAsCSV(datas);
// TODO DCossé 24/07/14 change result
result = "SUCCESS";
break;
@@ -209,37 +204,37 @@
case EBP_ACCOUNTCHARTS_EXPORT:
//For windows ebp
- datas = newExportService.exportAccountAsEbp(charset.name());
+ datas = exportService.exportAccountAsEbp(charset.name());
createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas);
break;
case EBP_ACCOUNTCHARTS_IMPORT:
//For windows ebp
datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding());
- importResult = newImportService.importAccountFromEbp(datas);
+ importResult = importService.importAccountFromEbp(datas);
// TODO DCossé 24/07/14 change result
result = "SUCCESS";
break;
case EBP_ENTRYBOOKS_EXPORT:
- datas = newExportService.exportEntryBookAsEbp(charset.name());
+ datas = exportService.exportEntryBookAsEbp(charset.name());
createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas);
break;
case EBP_ENTRYBOOKS_IMPORT:
datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding());
- importResult = newImportService.importEntryBookFromEbp(datas);
+ importResult = importService.importEntryBookFromEbp(datas);
// TODO DCossé 24/07/14 change result
result = "SUCCESS";
break;
case EBP_ENTRIES_EXPORT:
//For windows ebp
- datas = newExportService.exportEntriesAsEbp(charset.name());
+ datas = exportService.exportEntriesAsEbp(charset.name());
createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas);
break;
case EBP_ENTRIES_IMPORT:
//For windows ebp
datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding());
- importResult = newImportService.importEntriesFromEbp(datas);
+ importResult = importService.importEntriesFromEbp(datas);
break;
}
} catch (ImportEbpException e) {
@@ -506,7 +501,7 @@
String identityStreamString = IOUtils.toString(identityStream);
IOUtils.closeQuietly(identityStream);
- results = newImportService.importBackup(entryBooksStreamString, transactionsStreamString, fiscalPeriodsStreamString, accountsStreamString, entriesStreamString, identityStreamString);
+ results = importService.importBackup(entryBooksStreamString, transactionsStreamString, fiscalPeriodsStreamString, accountsStreamString, entriesStreamString, identityStreamString);
} catch (Exception ex) {
if(log.isInfoEnabled()) {
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/opening/CreateIdentityPanel.css
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/opening/CreateIdentityPanel.css 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/opening/CreateIdentityPanel.css 2014-08-01 14:29:33 UTC (rev 3889)
@@ -1,3 +1,24 @@
+/*
+ * #%L
+ * Lima :: Swing
+ * %%
+ * Copyright (C) 2008 - 2014 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%
+ */
#nameLabel {
text : "lima.identity.name";
}
Property changes on: trunk/lima-swing/src/main/java/org/chorem/lima/ui/opening/CreateIdentityPanel.css
___________________________________________________________________
Added: svn:eol-style
+ native
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/opening/CreateIdentityPanelHandler.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/opening/CreateIdentityPanelHandler.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/opening/CreateIdentityPanelHandler.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -1,5 +1,27 @@
package org.chorem.lima.ui.opening;
+/*
+ * #%L
+ * Lima :: Swing
+ * %%
+ * Copyright (C) 2008 - 2014 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%
+ */
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.lima.business.api.IdentityService;
Property changes on: trunk/lima-swing/src/main/java/org/chorem/lima/ui/opening/CreateIdentityPanelHandler.java
___________________________________________________________________
Added: svn:eol-style
+ native
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java 2014-08-01 14:29:33 UTC (rev 3889)
@@ -27,7 +27,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.lima.business.ServiceListener;
-import org.chorem.lima.business.api.NewImportService;
+import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.business.api.VatStatementService;
import org.chorem.lima.entity.VatStatement;
import org.chorem.lima.entity.VatStatementImpl;
@@ -59,7 +59,7 @@
vatStatementService =
LimaServiceFactory.getService(
VatStatementService.class);
- LimaServiceFactory.addServiceListener(NewImportService.class, this);
+ LimaServiceFactory.addServiceListener(ImportService.class, this);
init();
}
1
0
Author: dcosse
Date: 2014-08-01 16:20:36 +0200 (Fri, 01 Aug 2014)
New Revision: 3888
Url: http://forge.chorem.org/projects/lima/repository/revisions/3888
Log:
refs #1032 nouvelle impl?\195?\169mentation des imports export EBP
Added:
trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/AccountEBPModel.java
Removed:
trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java
trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportServiceLocal.java
trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java
trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java
trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java
trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java
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/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java
trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/EntryEBPModel.java
trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java
trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java
trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ImportServiceRuleFrTest.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountComboBoxModel.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookComboBoxModel.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FinancialPeriodComboBoxModel.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxModel.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/LeafAccountComboBoxModel.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/AccountsPane.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/EntryBooksPane.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FinancialTransactionsPane.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FiscalYearsPane.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java
trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java
Deleted: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java
===================================================================
--- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -1,702 +0,0 @@
-/*
- * #%L
- * Lima business
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric
- * %%
- * 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.ejb;
-
-import au.com.bytecode.opencsv.CSVWriter;
-import org.apache.commons.lang3.StringUtils;
-import org.chorem.lima.FinancialStatementWayEnum;
-import org.chorem.lima.LimaTechnicalException;
-import org.chorem.lima.business.LimaException;
-import org.chorem.lima.business.api.EntryBookService;
-import org.chorem.lima.business.api.ExportService;
-import org.chorem.lima.business.api.ExportServiceLocal;
-import org.chorem.lima.business.utils.ImportExportEntityEnum;
-import org.chorem.lima.entity.Account;
-import org.chorem.lima.entity.AccountTopiaDao;
-import org.chorem.lima.entity.ClosedPeriodicEntryBook;
-import org.chorem.lima.entity.ClosedPeriodicEntryBookTopiaDao;
-import org.chorem.lima.entity.Entry;
-import org.chorem.lima.entity.EntryBook;
-import org.chorem.lima.entity.EntryBookTopiaDao;
-import org.chorem.lima.entity.FinancialStatement;
-import org.chorem.lima.entity.FinancialStatementTopiaDao;
-import org.chorem.lima.entity.FinancialTransaction;
-import org.chorem.lima.entity.FinancialTransactionTopiaDao;
-import org.chorem.lima.entity.FiscalPeriod;
-import org.chorem.lima.entity.FiscalPeriodTopiaDao;
-import org.chorem.lima.entity.Identity;
-import org.chorem.lima.entity.IdentityTopiaDao;
-import org.chorem.lima.entity.VatStatement;
-import org.chorem.lima.entity.VatStatementTopiaDao;
-
-import javax.ejb.EJB;
-import javax.ejb.Local;
-import javax.ejb.Remote;
-import javax.ejb.Stateless;
-import javax.ejb.TransactionAttribute;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.text.SimpleDateFormat;
-import java.util.List;
-
-/**
- * CSV import export service.
- *
- * @version $Revision$
- * <p/>
- * Last update : $Date$
- * By : $Author$
- */
-@Stateless
-(a)Remote(ExportService.class)
-(a)Local(ExportServiceLocal.class)
-@TransactionAttribute
-public class ExportServiceImpl extends AbstractLimaService implements ExportService, ExportServiceLocal {
-
- private static final SimpleDateFormat SDATEFORMAT =
- new SimpleDateFormat("dd,MM,yyyy HH:mm:ss");
-
- protected final String DATE_PATTERN = "dd/MM/yyyy";
-
- @EJB
- private EntryBookService entryBookService;
-
- //############## EXPORT EBP
-
- /**
- * Export entries to EBP
- * Structure example : DatEcr,Journal,Compte,Libelle,Piece,Debit,Credit,Lettre
- * 01/01/2013,AN,101,Capital,1,0,100000.00,C
- */
- @Override
- public String exportEntriesAsEBP() {
- SimpleDateFormat epbDateFormat = new SimpleDateFormat(DATE_PATTERN);
- StringWriter out = new StringWriter();
- CSVWriter csvWriter = null;
-
- try {
- csvWriter = new CSVWriter(out,
- CSVWriter.DEFAULT_SEPARATOR,
- CSVWriter.NO_QUOTE_CHARACTER);
-
- //export entries
- FinancialTransactionTopiaDao financialTransactionTopiaDao =
- getDaoHelper().getFinancialTransactionDao();
- List<FinancialTransaction> listFinancialTransaction =
- financialTransactionTopiaDao.findAll();
-
- String[] nextLine = new String[8];
-
- // Add the header line
- if (!listFinancialTransaction.isEmpty()) {
- nextLine[0] = "DatEcr";
- nextLine[1] = "Journal";
- nextLine[2] = "Compte";
- nextLine[3] = "Libelle";
- nextLine[4] = "Piece";
- nextLine[5] = "Debit";
- nextLine[6] = "Credit";
- nextLine[7] = "Lettre";
- // Ajoute la ligne au fichier
- csvWriter.writeNext(nextLine);
- }
-
- String date, debitcredit, debit, credit, entrybookCode, accountNumber;
- EntryBook entryBook;
- Account account;
-
- // For all financialTransaction
- for (FinancialTransaction financialTransaction : listFinancialTransaction) {
- date = epbDateFormat.format(financialTransaction.getTransactionDate());
-
- entryBook = financialTransaction.getEntryBook();
-
- entrybookCode = entryBook == null ? "" : entryBook.getCode();
-
- for (Entry entry : financialTransaction.getEntry()) {
- account = entry.getAccount();
-
- if (account != null) {
- accountNumber = entry.getAccount().getAccountNumber();
- } else {
- accountNumber = "";
- }
-
- debit = "0";
- credit = "0";
- if (entry.isDebit()) {
- debitcredit = "D";
- debit = entry.getAmount().toString();
- } else {
- debitcredit = "C";
- credit = entry.getAmount().toString();
- }
-
- nextLine[0] = date;
- nextLine[1] = entrybookCode;
- nextLine[2] = accountNumber;
- nextLine[3] = StringUtils.remove(entry.getDescription(), ",");
- nextLine[4] = entry.getVoucher();
- nextLine[5] = debit;
- nextLine[6] = credit;
- nextLine[7] = debitcredit;
-
- // Ajoute la ligne au fichier
- csvWriter.writeNext(nextLine);
- }
- }
- // Write cache in string
- csvWriter.flush();
- } catch (IOException e) {
- throw new LimaTechnicalException(e);
- } finally {
- if (csvWriter != null) {
- try {
- csvWriter.close();
- out.close();
- } catch (IOException e) {
- // nothing to do
- }
- }
- }
- return out.getBuffer().toString();
- }
-
- /**
- * Export accounts chart to EBP
- * Structure ebp - example :
- * 411DUPOND,DUPOND,,21 rue du bois, 78120, Rambouillet, France,,0135698475,0135698475
- */
- @Override
- public String exportAccountsAsEBP() {
- StringWriter out = new StringWriter();
- CSVWriter csvWriter = null;
-
- try {
- csvWriter = new CSVWriter(out,
- CSVWriter.DEFAULT_SEPARATOR,
- CSVWriter.NO_QUOTE_CHARACTER);
- //export accounts
- //Numero,Intitule,Type,bLetManuel,bLetAuto,bLetAppro,bCentPhysique,bCentJournal,bCentGLivre,bGeleDebit,bGeleCredit,bNoEchAna,TypeRel,Categorie,CodeTVA,TypeTVA,Lettrage,Encours,Seuil,Remise,Escompte,Devise,RIB0NomBanque,RIB0AdrBanque,RIB0Agence,RIB0Guichet,RIB0Compte,RIB0CleRIB,RIB1NomBanque,RIB1AdrBanque,RIB1Agence,RIB1Guichet,RIB1Compte,RIB1CleRIB,RIB2NomBanque,RIB2AdrBanque,RIB2Agence,RIB2Guichet,RIB2Compte,RIB2CleRIB,AdresseCivilite,AdresseRaiSoc,AdresseAdresse,AdresseCodePostal,AdresseVille,AdressePays,NII,Contact0Interloc,Contact0Fonction,Contact0TelNumTel,Contact0TelNumFax,Contact0Infos,Contact1Interloc,Contact1Fonction,Contact1TelNumTel,Contact1TelNumFax,Contact1Infos,Contact2Interloc,Contact2Fonction,Contact2TelNumTel,Contact2TelNumFax,Contact2Infos,Contact3Interloc,Contact3Fonction,Contact3TelNumTel,Contact3TelNumFax,Contact3Infos,Contact4Interloc,Contact4Fonction,Contact4TelNumTel,Contact4TelNumFax,Contact4Infos,CodeRegle,NbJours,TypeJours,Limite,Grille1,Grille2,Grille3,SectGeo,SectAct,ObjCA,TailleCA,NbEmpl,Commercial,JoursMois,CptTva,CptCharge,bDecouvertAutorise,MntDecouvertAutorise,EMailTiers,WebSiteTiers,NatAchat,NatVente,NatDepense,NatRecette,NumCptBqCH,NumClearing,NumIBAN,LetPart,TypeAchatTVA,IBAN0Pays,IBAN0Controle,IBAN0Contenu,IBAN1Pays,IBAN1Controle,IBAN1Contenu,IBAN2Pays,IBAN2Controle,IBAN2Contenu,BIC0Banque,BIC0Pays,BIC0Localisation,BIC0Branche,BIC1Banque,BIC1Pays,BIC1Localisation,BIC1Branche,BIC2Banque,BIC2Pays,BIC2Localisation,BIC2Branche,LibBIC0,LibBIC1,LibBIC2
-
- String[] nextLine = new String[2];
- // Add the header line
- nextLine[0] = "Numero";
- nextLine[1] = "Intitule";
- csvWriter.writeNext(nextLine);
-
- // Récupère tous les comptes
- AccountTopiaDao accountTopiaDao = getDaoHelper().getAccountDao();
- List<Account> listAccount = accountTopiaDao.findAll();
- // Pour tous les comptes
- for (Account account : listAccount) {
- nextLine[0] = account.getAccountNumber();
- nextLine[1] = StringUtils.remove(account.getLabel(), ",");
- // Ajoute la ligne au fichier
- csvWriter.writeNext(nextLine);
- }
- // Write cache in string
- csvWriter.flush();
- csvWriter.close();
- } catch (IOException e) {
- throw new LimaTechnicalException(e);
- } finally {
- if (csvWriter != null) {
- try {
- csvWriter.close();
- out.close();
- } catch (IOException e) {
- // nothing to do
- }
- }
- }
- return out.getBuffer().toString();
- }
-
- @Override
- public String exportEntryBooksAsEBP() {
- StringWriter out = new StringWriter();
- CSVWriter csvWriter = null;
-
- try {
- csvWriter = new CSVWriter(out,
- CSVWriter.DEFAULT_SEPARATOR,
- CSVWriter.NO_QUOTE_CHARACTER);
-
- //entryBooks to export
- List<EntryBook> entryBooks = entryBookService.getAllEntryBooks();
-
- //Code,Type,Libelle,TypePiece,NextPiece,CpteType,CpteCompte,Contact,RIBNomBanque,RIBAdrBanque,RIBAgence,RIBGuichet,RIBCompte,RIBCleRIB,Lcr,Preleve,MemoDateCreat,MemoDateModif,Devise,CompteTP,NumCptBqCH,NumClearing,bSaisieKM
- String[] nextLine = new String[2];
- // Add the header line
- nextLine[0] = "Code";
- nextLine[1] = "Libelle";
- // Ajoute la ligne au fichier
- csvWriter.writeNext(nextLine);
-
- if (entryBooks != null && !entryBooks.isEmpty()) {
- for (EntryBook entryBook:entryBooks) {
- nextLine[0] = entryBook.getCode();
- nextLine[1] = StringUtils.remove(entryBook.getLabel(), ",");
- // Ajoute la ligne au fichier
- csvWriter.writeNext(nextLine);
- }
- }
-
- // Write cache in string
- csvWriter.flush();
-
- } catch (IOException e) {
- throw new LimaTechnicalException(e);
- } finally {
- if (csvWriter != null) {
- try {
- csvWriter.close();
- out.close();
- } catch (IOException e) {
- // nothing to do
- }
- }
- }
- return out.getBuffer().toString();
- }
-
-
- //############## EXPORT CSV
-
- /** Export integrality of database in CSV */
- @Override
- public String exportAsCSV() {
- StringWriter out = new StringWriter();
- CSVWriter csvWriter = null;
-
- try {
- csvWriter = new CSVWriter(out, ';');
- exportAccountsChartAsCSV(csvWriter);
- exportEntryBookChartAsCSV(csvWriter);
- exportFinancialStatementChartAsCSV(csvWriter);
- exportFiscalPeriodAsCSV(csvWriter);
- exportClosedPeriodicEntryBooksAsCSV(csvWriter);
- exportFinancialTransactionsAndEntriesAsCSV(csvWriter);
- exportIdentityAsCSV(csvWriter);
- // Write cache in string
- csvWriter.flush();
- } catch (IOException e) {
- throw new LimaTechnicalException(e);
- } finally {
- if (csvWriter != null) {
- try {
- csvWriter.close();
- out.close();
- } catch (IOException e) {
- // nothing to do
- }
- }
- }
- return out.getBuffer().toString();
- }
-
-
- /** Remote methode call from UI. */
- @Override
- public String exportFinancialStatementChartAsCSV() {
-
- StringWriter out = new StringWriter();
- CSVWriter csvWriter = null;
-
- try {
- csvWriter = new CSVWriter(out, ';');
- exportFinancialStatementChartAsCSV(csvWriter);
- // Write cache in file
- csvWriter.flush();
-
- } catch (IOException e) {
- throw new LimaTechnicalException(e);
- } finally {
- if (csvWriter != null) {
- try {
- csvWriter.close();
- out.close();
- } catch (IOException e) {
- // nothing to do
- }
- }
- }
- return out.getBuffer().toString();
- }
-
-
- /**
- * Local methode, export financialstatements from database
- * structure : TYPE | Label | Header | Accounts | DebitAccounts
- * | CreditAccounts | ProvisionDeprecationAccounts | SubAmount
- * | HeaderAmount | MasterFinancialStatement
- *
- * @param csvWriter
- * @throws LimaException
- */
- public void exportFinancialStatementChartAsCSV(CSVWriter csvWriter) {
- String[] nextLine = new String[12];
- // Get all Financialstatements
- FinancialStatementTopiaDao financialStatementTopiaDao =
- getDaoHelper().getFinancialStatementDao();
-
- List<FinancialStatement> listFinancialStatements =
- financialStatementTopiaDao.findAllOrderedByCreateDate();
-
- // For all Financialstatements
- for (FinancialStatement financialStatement : listFinancialStatements) {
- nextLine[0] = ImportExportEntityEnum.FINANCIALSTATEMENT.getLabel();
- nextLine[1] = financialStatement.getLabel();
- nextLine[2] = Boolean.toString(
- financialStatement.isHeader());
- nextLine[3] = financialStatement.getAccounts();
- nextLine[4] = financialStatement.getDebitAccounts();
- nextLine[5] = financialStatement.getCreditAccounts();
- nextLine[6] = financialStatement.
- getProvisionDeprecationAccounts();
- nextLine[7] = Boolean.toString(
- financialStatement.isSubAmount());
- nextLine[8] = Boolean.toString(
- financialStatement.isHeaderAmount());
- FinancialStatement masterFinancialStatement =
- financialStatement.getMasterFinancialStatement();
- String masterFinancialStatementString = masterFinancialStatement == null ? "" : StringUtils.remove(masterFinancialStatement.getLabel(), ";");
- nextLine[9] = masterFinancialStatementString;
- FinancialStatementWayEnum financialStatementWayEnum = financialStatement.getWay();
- String financialStatementWay = "";
- if (financialStatementWayEnum != null) {
- financialStatementWay = financialStatementWayEnum.name();
- }
- nextLine[10] = financialStatementWay;
- // Add line in file
- csvWriter.writeNext(nextLine);
- }
- }
-
- /** Remote method call from UI. */
- @Override
- public String exportVatStatementChartAsCSV() {
-
- StringWriter out = new StringWriter();
- CSVWriter csvWriter = null;
-
- try {
- csvWriter = new CSVWriter(out, ';');
- exportVatStatementChartAsCSV(csvWriter);
- // Write cache in file
- csvWriter.flush();
- } catch (IOException e) {
- throw new LimaTechnicalException(e);
- } finally {
- if (csvWriter != null) {
- try {
- csvWriter.close();
- out.close();
- } catch (IOException e) {
- // nothing to do
- }
- }
- }
- return out.getBuffer().toString();
-
- }
-
- /**
- * Local methode, export vatstatements from database
- * vatstatement Structure : TYPE | boxName | label | header
- * | accounts | masterVatStatement
- *
- * @param csvWriter
- * @throws LimaException
- */
- public void exportVatStatementChartAsCSV(CSVWriter csvWriter) {
- String[] nextLine = new String[6];
- // Get all Vatstatements
- VatStatementTopiaDao vatStatementTopiaDao = getDaoHelper().getVatStatementDao();
-
- List<VatStatement> listVatStatements =
- vatStatementTopiaDao.findAllOrderedByCreateDate();
-
- // For all Vatstatements
- for (VatStatement vatStatement : listVatStatements) {
- nextLine[0] = ImportExportEntityEnum.VATSTATEMENT.getLabel();
- nextLine[1] = vatStatement.getBoxName();
- nextLine[2] = vatStatement.getLabel();
- nextLine[3] = Boolean.toString(
- vatStatement.isHeader());
- nextLine[4] = vatStatement.getAccounts();
- VatStatement masterVatStatement =
- vatStatement.getMasterVatStatement();
- String masterVatStatementString = "";
- if (masterVatStatement != null) {
- masterVatStatementString =
- masterVatStatement.getLabel();
- }
- nextLine[5] = masterVatStatementString;
-
- csvWriter.writeNext(nextLine);
- }
- }
-
-
- /** Remote methode call from UI. */
- @Override
- public String exportEntryBookChartAsCSV() {
-
- StringWriter out = new StringWriter();
- CSVWriter csvWriter = null;
-
- try {
- csvWriter = new CSVWriter(out, ';');
- exportEntryBookChartAsCSV(csvWriter);
- // Write cache in file
- csvWriter.flush();
- } catch (IOException e) {
- throw new LimaTechnicalException(e);
- } finally {
- if (csvWriter != null) {
- try {
- csvWriter.close();
- out.close();
- } catch (IOException e) {
- // nothing to do
- }
- }
- }
- return out.getBuffer().toString();
- }
-
-
- /**
- * Local methode, export entrybooks from database
- * Structure : TYPE | Code | Label | Type
- *
- * @param csvWriter
- * @throws LimaException
- */
- public void exportEntryBookChartAsCSV(CSVWriter csvWriter) {
-
- String[] nextLine = new String[3];
- // Get all entrybook
- EntryBookTopiaDao entryBookTopiaDao = getDaoHelper().getEntryBookDao();
- List<EntryBook> listEntryBook = entryBookTopiaDao.findAll();
- // For all EntryBook
- for (EntryBook entryBook : listEntryBook) {
- nextLine[0] = ImportExportEntityEnum.ENTRYBOOK.getLabel();
- nextLine[1] = entryBook.getCode();
- nextLine[2] = StringUtils.remove(entryBook.getLabel(), ";");
- // Ajoute la ligne au fichier
- csvWriter.writeNext(nextLine);
- }
- }
-
-
- /** Remote methode call from UI. */
- @Override
- public String exportAccountsChartAsCSV() {
- StringWriter out = new StringWriter();
- CSVWriter csvWriter = null;
-
- try {
- csvWriter = new CSVWriter(out, ';');
- exportAccountsChartAsCSV(csvWriter);
- // Write cache in file
- csvWriter.flush();
- } catch (IOException e) {
- throw new LimaTechnicalException(e);
- } finally {
- if (csvWriter != null) {
- try {
- csvWriter.close();
- out.close();
- } catch (IOException e) {
- // nothing to do
- }
- }
- }
- return out.getBuffer().toString();
- }
-
-
- /**
- * Local methode, export accounts from database
- * Structure : TYPE | AccountNumber | Label | ThirdParty | MasterAccount | GeneralLedger
- *
- * @param csvWriter
- * @throws LimaException
- */
- public void exportAccountsChartAsCSV(CSVWriter csvWriter) {
- String[] nextLine = new String[6];
- // Récupère tous les comptes
- AccountTopiaDao accountTopiaDao =
- getDaoHelper().getAccountDao();
- List<Account> listAccount = accountTopiaDao.findAll();
- // Pour tous les comptes
- for (Account account : listAccount) {
- nextLine[0] = ImportExportEntityEnum.ACCOUNT.getLabel();
- nextLine[1] = account.getAccountNumber();
- nextLine[2] = StringUtils.remove(account.getLabel(), ";");
- nextLine[3] = account.getThirdParty();
-
- // Ajoute la ligne au fichier
- csvWriter.writeNext(nextLine);
- }
- }
-
-
- /**
- * Local methode, export financialtransactions from database
- * Structure : TYPE | TransactionDate | AmountDebit | AmountCredit
- * | FinancialPeriod BeginDate | FinancialPeriod EndDate | EntryBook Code
- *
- * @param csvWriter
- * @throws LimaException
- */
- public void exportFinancialTransactionsAndEntriesAsCSV(CSVWriter csvWriter) {
- int numTransaction = 0;
- // Get all financialtransactions
-
- FinancialTransactionTopiaDao financialTransactionTopiaDao =
- getDaoHelper().getFinancialTransactionDao();
- List<FinancialTransaction> listFinancialTransaction =
- financialTransactionTopiaDao.findAll();
- // For all financialTransaction
- for (FinancialTransaction financialTransaction : listFinancialTransaction) {
- String[] nextLine = new String[8];
- nextLine[0] = ImportExportEntityEnum.FINANCIALTRANSACTION.getLabel();
- nextLine[1] = String.valueOf(numTransaction);
- nextLine[2] = SDATEFORMAT.format(financialTransaction.getTransactionDate());
- nextLine[3] = financialTransaction.getAmountDebit().toString();
- nextLine[4] = financialTransaction.getAmountCredit().toString();
- EntryBook entryBook = financialTransaction.getEntryBook();
- if (entryBook != null) {
- nextLine[5] = entryBook.getCode();
- }
- // Ajoute la ligne au fichier
- csvWriter.writeNext(nextLine);
-
- nextLine = new String[10];
- for (Entry entry : financialTransaction.getEntry()) {
- nextLine[0] = ImportExportEntityEnum.ENTRY.getLabel();
- nextLine[1] = String.valueOf(numTransaction);
- nextLine[2] = entry.getDescription();
- nextLine[3] = entry.getAmount().toString();
- nextLine[4] = Boolean.toString(entry.isDebit());
- nextLine[5] = entry.getLettering();
- nextLine[6] = entry.getDetail();
- nextLine[7] = entry.getVoucher();
- nextLine[8] = entry.getPosition();
- nextLine[9] = entry.getAccount().getAccountNumber();
- // Ajoute la ligne au fichier
- csvWriter.writeNext(nextLine);
- }
- numTransaction++;
- }
- }
-
-
- /**
- * Local methode, export fiscalperiods from database
- * Structure : TYPE | BeginDate | EndDate | Locked
- *
- * @param csvWriter
- * @throws LimaException
- */
- public void exportFiscalPeriodAsCSV(CSVWriter csvWriter) {
- String[] nextLine = new String[4];
- // Get all fiscalperiod
- FiscalPeriodTopiaDao fiscalPeriodTopiaDao =
- getDaoHelper().getFiscalPeriodDao();
- List<FiscalPeriod> listFiscalPeriod =
- fiscalPeriodTopiaDao.findAll();
- // For all Entry
- for (FiscalPeriod fiscalPeriod : listFiscalPeriod) {
- nextLine[0] = ImportExportEntityEnum.FISCALPERIOD.getLabel();
- nextLine[1] = SDATEFORMAT.format(fiscalPeriod.getBeginDate());
- nextLine[2] = SDATEFORMAT.format(fiscalPeriod.getEndDate());
- nextLine[3] = Boolean.toString(fiscalPeriod.isLocked());
- // Ajoute la ligne au fichier
- csvWriter.writeNext(nextLine);
- }
- }
-
- /**
- * Local methode, export ClosedPeriodicEntryBooks from database
- * Structure : TYPE | Locked | FinancialPeriod beginDate | FinancialPeriod endDate | EntryBook Code
- *
- * @param csvWriter
- * @throws LimaException
- */
- public void exportClosedPeriodicEntryBooksAsCSV(CSVWriter csvWriter) {
- String[] nextLine = new String[5];
- // Get all fiscalperiod
- ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookTopiaDao =
- getDaoHelper().getClosedPeriodicEntryBookDao();
- List<ClosedPeriodicEntryBook> listClosedPeriodicEntryBook =
- closedPeriodicEntryBookTopiaDao.findAll();
- // For all Entry
- for (ClosedPeriodicEntryBook closedPeriodicEntryBook : listClosedPeriodicEntryBook) {
- nextLine[0] = ImportExportEntityEnum.CLOSEDPERIODICENTRYBOOK.getLabel();
- nextLine[1] = Boolean.toString(
- closedPeriodicEntryBook.isLocked());
- nextLine[2] =
- SDATEFORMAT.format(closedPeriodicEntryBook.getFinancialPeriod().
- getBeginDate());
- nextLine[3] =
- SDATEFORMAT.format(closedPeriodicEntryBook.getFinancialPeriod().
- getEndDate());
- nextLine[4] = closedPeriodicEntryBook.getEntryBook().getCode();
- // Ajoute la ligne au fichier
- csvWriter.writeNext(nextLine);
- }
- }
-
- public void exportIdentityAsCSV(CSVWriter csvWriter) {
- String[] nextLine = new String[12];
- // Get identity
- IdentityTopiaDao identityTopiaDao = getDaoHelper().getIdentityDao();
- List<Identity> identities = identityTopiaDao.findAll();
- if (identities.size() != 0) {
-
- Identity identity = identities.get(0);
- nextLine[0] = ImportExportEntityEnum.IDENTITY.getLabel();
- nextLine[1] = identity.getName();
- nextLine[2] = identity.getDescription();
- nextLine[3] = identity.getAddress();
- nextLine[4] = identity.getAddress2();
- nextLine[5] = identity.getCity();
- nextLine[6] = identity.getPhoneNumber();
- nextLine[7] = identity.getEmail();
- nextLine[8] = identity.getZipCode();
- nextLine[9] = identity.getVatNumber();
- nextLine[10] = identity.getClassificationCode();
- nextLine[11] = identity.getBusinessNumber();
- // Ajoute la ligne au fichier
- csvWriter.writeNext(nextLine);
- }
- }
-}
Deleted: 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-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -1,294 +0,0 @@
-/*
- * #%L
- * Lima business
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric
- * %%
- * 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.ejb;
-
-import au.com.bytecode.opencsv.CSVReader;
-import com.google.common.base.Function;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.pdfbox.exceptions.COSVisitorException;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.interactive.form.PDField;
-import org.chorem.lima.business.AlreadyExistAccountException;
-import org.chorem.lima.business.ImportEbpException;
-import org.chorem.lima.business.InvalidAccountNumberException;
-import org.chorem.lima.business.LimaConfig;
-import org.chorem.lima.business.api.AccountService;
-import org.chorem.lima.business.api.ClosedPeriodicEntryBookService;
-import org.chorem.lima.business.api.EntryBookService;
-import org.chorem.lima.business.api.EntryService;
-import org.chorem.lima.business.api.FinancialPeriodService;
-import org.chorem.lima.business.api.FinancialTransactionService;
-import org.chorem.lima.business.api.FiscalPeriodService;
-import org.chorem.lima.business.api.IdentityService;
-import org.chorem.lima.business.api.ImportService;
-import org.chorem.lima.business.utils.DocumentsEnum;
-import org.chorem.lima.business.utils.ImportExportEntityEnum;
-import org.chorem.lima.entity.Account;
-import org.chorem.lima.entity.AccountImpl;
-import org.chorem.lima.entity.EntryBook;
-import org.chorem.lima.entity.Identity;
-import org.chorem.lima.entity.IdentityImpl;
-
-import javax.ejb.EJB;
-import javax.ejb.Remote;
-import javax.ejb.Stateless;
-import javax.ejb.TransactionAttribute;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringReader;
-import java.text.SimpleDateFormat;
-import java.util.List;
-import java.util.Map;
-
-import static org.nuiton.i18n.I18n.t;
-
-/**
- * Import export service.
- * Currently import and export as CSV and EBP.
- */
-@Stateless
-(a)Remote(ImportService.class)
-@TransactionAttribute
-public class ImportServiceImpl extends AbstractLimaService implements ImportService {
-
- private static final Log log = LogFactory.getLog(ImportServiceImpl.class);
-
- protected static final Function<Account, String> GET_ACCOUNT_NUMBER = new Function<Account, String>() {
- @Override
- public String apply(Account input) {
- return input.getAccountNumber();
- }
- };
-
- protected static final Function<EntryBook, String> GET_ENTRY_BOOK_CODE = new Function<EntryBook, String>() {
- @Override
- public String apply(EntryBook input) {
- return input.getCode();
- }
- };
- protected final String DATE_PATTERN = "dd/MM/yyyy";
-
- @EJB
- private AccountService accountService;
-
- @EJB
- private FiscalPeriodService fiscalPeriodService;
-
- @EJB
- private FinancialPeriodService financialPeriodService;
-
- @EJB
- private FinancialTransactionService financialTransactionService;
-
- @EJB
- private EntryBookService entryBookService;
-
- @EJB
- private IdentityService identityService;
-
- @EJB
- private ClosedPeriodicEntryBookService closedPeriodicEntryBookService;
-
- @EJB
- private EntryService entryService;
-
- private static final SimpleDateFormat SDATEFORMAT = new SimpleDateFormat(
- "dd,MM,yyyy HH:mm:ss");
-
- // ################ IMPORT THIRD PART ACCOUNTING SOFTWARE ################
-
- @Override
- public String importAccountsChartFromEbp(String datas) throws ImportEbpException{
- long before = System.currentTimeMillis();
- List<Account> accounts = accountService.getAllAccounts();
- if (accounts == null) {
- accounts = Lists.newArrayList();
- }
- Map<String, Account> indexedAccounts = Maps.newHashMap(Maps.uniqueIndex(accounts, GET_ACCOUNT_NUMBER));
-
- StringBuilder result = new StringBuilder();
- CSVReader csvReader = null;
- try {
- csvReader = new CSVReader(new StringReader(datas));
-
- // check header is valid
- String[] headers = csvReader.readNext();
- String columnName;
- Integer numIndex = null;
- Integer intituleIndex = null;
- for (int i = 0; i < headers.length; i++) {
- columnName = headers[i];
- if (columnName.equalsIgnoreCase("Numero")) {
- numIndex = i;
- } else if (columnName.equalsIgnoreCase("Intitule")) {
- intituleIndex = i;
- }
- }
-
- int nbAccountCreated = 0;
- if (numIndex != null && intituleIndex != null) {
- String[] line;
- line = csvReader.readNext();
- while (line != null) {
- String accountNumber = line[numIndex];
- String label = line[intituleIndex];
- Account account = indexedAccounts.get(accountNumber);
- // an account can be created but not updated.
- if (account == null) {
- account = new AccountImpl();
- account.setAccountNumber(accountNumber);
- account.setLabel(label);
- try {
- accountService.createAccount(account);
- result.append(t("lima-business.import.account.added",
- accountNumber, label));
- nbAccountCreated++;
- } catch (AlreadyExistAccountException e) {
- result.append(t("lima-business.import.account.alreadyExist",
- accountNumber, label));
- } catch (InvalidAccountNumberException e) {
- result.append(t("lima-business.import.account.InvalidAccountNumber",
- accountNumber, label));
- }
- }
- line = csvReader.readNext();
- }
- } else {
- throw new ImportEbpException(
- t("lima-business.import.noaccount"));
- }
-
- if (log.isInfoEnabled()) {
- long after = System.currentTimeMillis();
- log.info("Imported form EBP : " + nbAccountCreated + " accounts in "
- + (after - before) + " ms");
- }
-
- } catch (IOException e) {
- throw new ImportEbpException("Can't import", e);
- } finally {
- if (csvReader != null) {
- try {
- csvReader.close();
- } catch (IOException e) {
- // on fait rien
- }
- }
- }
- return result.toString();
- }
-
- // ################ IMPORT ################
-
- @Override
- public String importAsPDF(String datas,
- ImportExportEntityEnum importExportEntityEnum,
- boolean setMode) {
-
- StringBuilder result = new StringBuilder();
-
- PDDocument doc = null;
- try {
- String path = LimaConfig.getInstance().getReportsDir().getAbsolutePath();
-
- String filePathDefault = path + File.separator
- + DocumentsEnum.VAT.getFileName() + "_default.pdf";
- String filePathStructured = path + File.separator
- + DocumentsEnum.VAT.getFileName() + "_structure.pdf";
-
- InputStream reportsStream = new FileInputStream(datas);
- //DocumentServiceImpl.class.getResourceAsStream("/reports/vat_form_fr.pdf");
- // load the document
- doc = PDDocument.load(reportsStream);
-
- //save default vat document with empty boxes
- if (setMode) {
- doc.save(filePathDefault);
- }
-
- //search for all PDFBox
- List<PDField> FieldList = doc.getDocumentCatalog().getAcroForm().getFields();
-
- //display inside each box their name
- for (PDField pdField : FieldList) {
- pdField.setValue(pdField.getFullyQualifiedName());
- }
-
- // save the structured document
- doc.save(filePathStructured);
-
- //sets the new pdf url to be used as pdf document edited for reports
- if (setMode) {
- LimaConfig.getInstance().setVatPDFUrl(datas);
- }
- } catch (IOException ex) {
- log.error("Can't read vat pdf", ex);
- result.append("Can't read vat pdf");
- } catch (COSVisitorException ex) {
- log.error("Can't save vat pdf", ex);
- result.append("Can't save vat pdf");
- } finally {
- try {
- if (doc != null) {
- doc.close();
- }
- } catch (Exception e) {
- // Nothing to do
- }
- }
- return result.toString();
- }
-
- protected String importIdentity(String[] nextLine) {
- StringBuilder result = new StringBuilder();
-
- Identity identity = new IdentityImpl();
- nextLine[0] = ImportExportEntityEnum.IDENTITY.getLabel();
- identity.setName(nextLine[1]);
- identity.setDescription(nextLine[2]);
- identity.setAddress(nextLine[3]);
- identity.setAddress2(nextLine[4]);
- identity.setCity(nextLine[5]);
- identity.setPhoneNumber(nextLine[6]);
- identity.setEmail(nextLine[7]);
- identity.setZipCode(nextLine[8]);
- identity.setVatNumber(nextLine[9]);
- identity.setClassificationCode(nextLine[10]);
- identity.setBusinessNumber(nextLine[11]);
-
- identityService.updateIdentity(identity);
- // create it
- result.append(t("lima-business.import.identityadded", identity.getName()));
-
- return result.toString();
- }
-
-}
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-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -45,6 +45,8 @@
import org.chorem.lima.business.ejb.csv.FiscalPeriodModel;
import org.chorem.lima.business.ejb.csv.IdentityModel;
import org.chorem.lima.business.ejb.csv.VatStatementModel;
+import org.chorem.lima.business.ejb.ebp.AccountEBPModel;
+import org.chorem.lima.business.ejb.ebp.EntryEBPModel;
import org.chorem.lima.entity.Account;
import org.chorem.lima.entity.AccountTopiaDao;
import org.chorem.lima.entity.Entry;
@@ -107,46 +109,6 @@
public static final String JAVA_IO_TMPDIR = "java.io.tmpdir";
- @Override
- public String exportBackup(String charset) {
- ByteArrayOutputStream rstBao = new ByteArrayOutputStream();
- ZipOutputStream export = null;
- try {
- List<File> files = Lists.newArrayList();
- files.add(exportAccountsFile(charset));
- files.add(exportEntryBooksFile(charset));
- files.add(exportFiscalPeriodFile(charset));
- files.add(exportFinancialTransactionsFile(charset));
- files.add(exportEntriesFile(charset, false));
- files.add(exportIdentity(charset));
-
- export = new ZipOutputStream(rstBao);
-
- for (File file : files) {
- if (file != null) {
- ZipEntry ze= new ZipEntry(file.getName());
- export.putNextEntry(ze);
- int len;
- byte[] buffer = new byte[1024];
- FileInputStream stream = new FileInputStream(file);
- while ((len = stream.read(buffer)) > 0) {
- export.write(buffer, 0, len);
- }
- stream.close();
- FileUtils.forceDelete(file);
- }
- }
- export.flush();
-
- } catch (Exception e) {
- throw new LimaTechnicalException(e);
- } finally {
- IOUtils.closeQuietly(export);
- }
- byte[] bytes = rstBao.toByteArray();
- return Base64.encodeBase64String(bytes);
- }
-
protected File exportAccountsFile(String charset) throws Exception {
AccountTopiaDao accountTopiaDao = getDaoHelper().getAccountDao();
List<Account> entities = accountTopiaDao.findAll();
@@ -270,22 +232,6 @@
return result;
}
- protected File exportIdentity(String charset) throws Exception {
- File result = null;
-
- Identity identity = identityService.getIdentity();
- if (identity != null) {
- List<Identity> identities = new ArrayList<>();
- identities.add(identity);
-
- String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
- result = new File(tmpDir + "identity.csv");
- IdentityModel model = new IdentityModel();
- Export.exportToFile(model, identities, result, Charset.forName(charset));
- }
- return result;
- }
-
@Override
public String exportEntriesAsCSV(String charset, Boolean humanReadable) {
String result = null;
@@ -301,6 +247,16 @@
return result;
}
+ protected List<FinancialStatement> getAllSubFinancialStatements(List<FinancialStatement> result, Collection<FinancialStatement> subFinancialStatements) {
+ if (subFinancialStatements != null) {
+ for (FinancialStatement subFinancialStatement : subFinancialStatements) {
+ result.add(subFinancialStatement);
+ getAllSubFinancialStatements(result, subFinancialStatement.getSubFinancialStatements());
+ }
+ }
+ return result;
+ }
+
@Override
public String exportFinancialStatements(String charset) throws Exception {
String stResult = null;
@@ -320,11 +276,11 @@
return stResult;
}
- public List<FinancialStatement> getAllSubFinancialStatements(List<FinancialStatement> result, Collection<FinancialStatement> subFinancialStatements) {
- if (subFinancialStatements != null) {
- for (FinancialStatement subFinancialStatement : subFinancialStatements) {
- result.add(subFinancialStatement);
- getAllSubFinancialStatements(result, subFinancialStatement.getSubFinancialStatements());
+ protected List<VatStatement> getAllSubVATStatements(List<VatStatement> result, Collection<VatStatement> subVATStatements) {
+ if (subVATStatements != null) {
+ for (VatStatement subVATStatement : subVATStatements) {
+ result.add(subVATStatement);
+ getAllSubVATStatements(result, subVATStatement.getSubVatStatements());
}
}
return result;
@@ -349,13 +305,120 @@
return stResult;
}
- public List<VatStatement> getAllSubVATStatements(List<VatStatement> result, Collection<VatStatement> subVATStatements) {
- if (subVATStatements != null) {
- for (VatStatement subVATStatement : subVATStatements) {
- result.add(subVATStatement);
- getAllSubVATStatements(result, subVATStatement.getSubVatStatements());
- }
+ protected File exportIdentity(String charset) throws Exception {
+ File result = null;
+
+ Identity identity = identityService.getIdentity();
+ if (identity != null) {
+ List<Identity> identities = new ArrayList<>();
+ identities.add(identity);
+
+ String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ result = new File(tmpDir + "identity.csv");
+ IdentityModel model = new IdentityModel();
+ Export.exportToFile(model, identities, result, Charset.forName(charset));
}
return result;
}
+
+ @Override
+ public String exportBackup(String charset) {
+ ByteArrayOutputStream rstBao = new ByteArrayOutputStream();
+ ZipOutputStream export = null;
+ try {
+ List<File> files = Lists.newArrayList();
+ files.add(exportAccountsFile(charset));
+ files.add(exportEntryBooksFile(charset));
+ files.add(exportFiscalPeriodFile(charset));
+ files.add(exportFinancialTransactionsFile(charset));
+ files.add(exportEntriesFile(charset, false));
+ files.add(exportIdentity(charset));
+
+ export = new ZipOutputStream(rstBao);
+
+ for (File file : files) {
+ if (file != null) {
+ ZipEntry ze= new ZipEntry(file.getName());
+ export.putNextEntry(ze);
+ int len;
+ byte[] buffer = new byte[1024];
+ FileInputStream stream = new FileInputStream(file);
+ while ((len = stream.read(buffer)) > 0) {
+ export.write(buffer, 0, len);
+ }
+ stream.close();
+ FileUtils.forceDelete(file);
+ }
+ }
+ export.flush();
+
+ } catch (Exception e) {
+ throw new LimaTechnicalException(e);
+ } finally {
+ IOUtils.closeQuietly(export);
+ }
+ byte[] bytes = rstBao.toByteArray();
+ return Base64.encodeBase64String(bytes);
+ }
+
+ //####################################### EBP ##############################################
+
+ @Override
+ public String exportAccountAsEbp(String charset) throws Exception {
+ String stResult = null;
+ File result;
+
+ List<Account> accounts = accountService.getAllAccounts();
+ if (accounts != null && !accounts.isEmpty()) {
+
+ String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ result = new File(tmpDir + "accounts.csv");
+ AccountEBPModel model = new AccountEBPModel();
+ Export.exportToFile(model, accounts, result, Charset.forName(charset));
+ FileInputStream inputStream = new FileInputStream(result);
+ stResult = IOUtils.toString(inputStream);
+
+ }
+ return stResult;
+ }
+
+ @Override
+ public String exportEntriesAsEbp(String charset) throws Exception {
+ String stResult = null;
+ File result;
+
+ List<Entry> entries = getDaoHelper().getEntryDao().findAll();
+
+ if (entries != null && !entries.isEmpty()) {
+
+ String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ result = new File(tmpDir + "entries.csv");
+ EntryEBPModel model = new EntryEBPModel();
+ Export.exportToFile(model, entries, result, Charset.forName(charset));
+ FileInputStream inputStream = new FileInputStream(result);
+ stResult = IOUtils.toString(inputStream);
+
+ }
+ return stResult;
+ }
+
+ @Override
+ public String exportEntryBookAsEbp(String charset) throws Exception {
+ String stResult = null;
+ File result;
+
+ List<EntryBook> entryBooks = entryBookService.getAllEntryBooks();
+
+ if (entryBooks != null && !entryBooks.isEmpty()) {
+
+ String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/";
+ result = new File(tmpDir + "entryBooks.csv");
+ EntryBookModel model = new EntryBookModel();
+ Export.exportToFile(model, entryBooks, result, Charset.forName(charset));
+ FileInputStream inputStream = new FileInputStream(result);
+ stResult = IOUtils.toString(inputStream);
+
+ }
+ return stResult;
+ }
}
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-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -58,6 +58,7 @@
import org.chorem.lima.business.ejb.csv.FiscalPeriodModel;
import org.chorem.lima.business.ejb.csv.IdentityModel;
import org.chorem.lima.business.ejb.csv.VatStatementModel;
+import org.chorem.lima.business.ejb.ebp.AccountEBPModel;
import org.chorem.lima.business.ejb.ebp.EntryBookEBPModel;
import org.chorem.lima.business.ejb.ebp.EntryEBPModel;
import org.chorem.lima.business.utils.EntryEBPComparator;
@@ -301,7 +302,7 @@
}
}
- //
+ // the target financialStatement has not been created yet so we create it now.
if (targetedFinancialStatement == null) {
// not found, we need to create it
targetedFinancialStatement = financialStatementService.newFinancialStatement();
@@ -591,7 +592,37 @@
return results;
}
+ //####################################### EBP ##############################################
+
+
@Override
+ public ImportResult importAccountFromEbp(String datas) {
+ ImportResult result = new ImportResult();
+
+ ImportModel<Account> model = new AccountEBPModel();
+
+ 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);
+ }
+ if (updated) {
+ result.increaseUpdated();
+ } else {
+ result.increaseCreated();
+ }
+ }
+ return result;
+ }
+
+ @Override
public ImportResult importEntriesFromEbp(String datas) {
ImportResult result = new ImportResult();
@@ -621,13 +652,13 @@
ImportModel<EntryEBP> model = new EntryEBPModel();
- Import<EntryEBP> entryEBPs = Import.newImport(model, contentStream);
- List<EntryEBP> list = new ArrayList<>();
- for (EntryEBP entryEBP : entryEBPs) {
- list.add(entryEBP);
+ Import<EntryEBP> importedEntryEBPs = Import.newImport(model, contentStream);
+ List<EntryEBP> entryEBPs = new ArrayList<>();
+ for (EntryEBP entryEBP : importedEntryEBPs) {
+ entryEBPs.add(entryEBP);
}
- Collections.sort(list, new EntryEBPComparator());
+ Collections.sort(entryEBPs, new EntryEBPComparator());
// Get all the valid fiscalPeriods Ordered by date.
List<FiscalPeriod> fiscalPeriods = fiscalPeriodService
@@ -657,20 +688,23 @@
// the entry entity is created and the association with it's dependant entites (Account are FinancialTransaction) are created
int lineIndex = 0;
- for (EntryEBP entryEBP : list) {
+ for (EntryEBP entryEBP : entryEBPs) {
dateEcr = entryEBP.getDatEcr();
// account loading
account = indexedAccounts.get(entryEBP.getCompte());
// if entry date have fiscalperiod open
- if (dateEcr.compareTo(fiscalPeriods.get(0).getBeginDate()) < 0
- || dateEcr.compareTo(fiscalPeriods.get(fiscalPeriods.size() - 1).getEndDate()) > 0) {
+ 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++;
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())));
@@ -681,6 +715,13 @@
// create entry
else {
+ // find financial transactions for entry period.
+ List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(fiscalPeriodsBiginDate, fiscalPeriodsEndingDate);
+ Map<Date, FinancialTransaction> financialTransactionsByDate = new HashMap<>();
+ for (FinancialTransaction transaction : financialTransactions) {
+ financialTransactionsByDate.put(transaction.getTransactionDate(), transaction);
+ }
+
// creation of the entry
// initialisation of this attributs
@@ -689,7 +730,7 @@
// the entry has one amount witch can be Debit or Credit
// regarding the value of the boolean:debit
debit = entryEBP.getDebit();
- if (BigDecimal.ZERO.compareTo(debit)==0) {
+ if (debit == null || BigDecimal.ZERO.compareTo(debit)==0) {
entry.setDebit(false);
entry.setAmount(entryEBP.getCredit());
} else {
@@ -724,8 +765,8 @@
indexedEntryBooks.put(entryBook.getCode(), entryBook);
}
try {
-
// create transaction
+ financialTransaction = financialTransactionsByDate.get(dateEcr);
if (financialTransaction == null
|| !(dateEcr.equals(financialTransaction
.getTransactionDate()) && entryBook
@@ -756,7 +797,7 @@
if (log.isInfoEnabled()) {
long after = System.currentTimeMillis();
- log.info("Imported form EBP : " + list.size() + " entries in "
+ log.info("Imported form EBP : " + entryEBPs.size() + " entries in "
+ (after - before) + " ms");
}
} finally {
@@ -784,4 +825,65 @@
}
return result;
}
+
+ //#######################################################################################################
+
+// @Override
+// public String importAsPDF(String datas,
+// ImportExportEntityEnum importExportEntityEnum,
+// boolean setMode) {
+//
+// StringBuilder result = new StringBuilder();
+//
+// PDDocument doc = null;
+// try {
+// String path = LimaConfig.getInstance().getReportsDir().getAbsolutePath();
+//
+// String filePathDefault = path + File.separator
+// + DocumentsEnum.VAT.getFileName() + "_default.pdf";
+// String filePathStructured = path + File.separator
+// + DocumentsEnum.VAT.getFileName() + "_structure.pdf";
+//
+// InputStream reportsStream = new FileInputStream(datas);
+// //DocumentServiceImpl.class.getResourceAsStream("/reports/vat_form_fr.pdf");
+// // load the document
+// doc = PDDocument.load(reportsStream);
+//
+// //save default vat document with empty boxes
+// if (setMode) {
+// doc.save(filePathDefault);
+// }
+//
+// //search for all PDFBox
+// List<PDField> FieldList = doc.getDocumentCatalog().getAcroForm().getFields();
+//
+// //display inside each box their name
+// for (PDField pdField : FieldList) {
+// pdField.setValue(pdField.getFullyQualifiedName());
+// }
+//
+// // save the structured document
+// doc.save(filePathStructured);
+//
+// //sets the new pdf url to be used as pdf document edited for reports
+// if (setMode) {
+// LimaConfig.getInstance().setVatPDFUrl(datas);
+// }
+// } catch (IOException ex) {
+// log.error("Can't read vat pdf", ex);
+// result.append("Can't read vat pdf");
+// } catch (COSVisitorException ex) {
+// log.error("Can't save vat pdf", ex);
+// result.append("Can't save vat pdf");
+// } finally {
+// try {
+// if (doc != null) {
+// doc.close();
+// }
+// } catch (Exception e) {
+// // Nothing to do
+// }
+// }
+// return result.toString();
+// }
}
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-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/AbstractLimaModel.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -30,11 +30,13 @@
import org.chorem.lima.business.api.EntryBookService;
import org.chorem.lima.business.api.FinancialTransactionService;
import org.chorem.lima.entity.Account;
+import org.chorem.lima.entity.Entry;
import org.chorem.lima.entity.EntryBook;
import org.chorem.lima.entity.FinancialStatement;
import org.chorem.lima.entity.FinancialTransaction;
import org.chorem.lima.entity.VatStatement;
import org.nuiton.csv.ValueFormatter;
+import org.nuiton.csv.ValueGetter;
import org.nuiton.csv.ValueParser;
import org.nuiton.csv.ext.AbstractImportModel;
@@ -193,8 +195,7 @@
public String format(Date value) {
String result;
if (value != null) {
- SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
- result = format.format(value);
+ result = simpleDateFormat.format(value);
} else {
result = "";
}
@@ -210,8 +211,7 @@
public Date parse(String value) throws ParseException {
Date result = null;
if (!Strings.isNullOrEmpty(value)) {
- SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
- result = format.parse(value);
+ result = simpleDateFormat.parse(value);
}
return result;
}
@@ -383,4 +383,46 @@
return result;
}
};
+
+ protected static final ValueFormatter<FinancialTransaction> FINANCIAL_TRANSACTION_TO_ENTRY_BOOK_FORMATTER = new ValueFormatter<FinancialTransaction>() {
+ @Override
+ public String format(FinancialTransaction value) {
+ String result;
+ if (value != null) {
+ result = value.getEntryBook().getCode();
+ } else {
+ result = "";
+ }
+ return result;
+ }
+ };
+
+ protected static final ValueFormatter<FinancialTransaction> FINANCIAL_TRANSACTION_TO_TRANSACTION_DATE_FORMATTER = new ValueFormatter<FinancialTransaction>() {
+ @Override
+ public String format(FinancialTransaction value) {
+ String result;
+ if (value != null) {
+ result = simpleDateFormat.format(value.getTransactionDate());
+ } else {
+ result = "";
+ }
+ return result;
+ }
+ };
+
+ protected static final ValueGetter<Entry, String> ENTRY_DEBIT_GETTER = new ValueGetter<Entry, String>() {
+ @Override
+ public String get(Entry entry) throws Exception {
+ String result = entry.isDebit() ? String.valueOf(entry.getAmount()) : "";
+ return result;
+ }
+ };
+
+ protected static final ValueGetter<Entry, String> ENTRY_CREDIT_GETTER = new ValueGetter<Entry, String>() {
+ @Override
+ public String get(Entry entry) throws Exception {
+ String result = entry.isDebit() ? "" : String.valueOf(entry.getAmount());
+ return result;
+ }
+ };
}
Added: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/AccountEBPModel.java
===================================================================
--- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/AccountEBPModel.java (rev 0)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/AccountEBPModel.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -0,0 +1,132 @@
+package org.chorem.lima.business.ejb.ebp;
+
+import org.chorem.lima.business.ejb.csv.AbstractLimaModel;
+import org.chorem.lima.entity.Account;
+import org.chorem.lima.entity.AccountImpl;
+import org.nuiton.csv.ExportModel;
+import org.nuiton.csv.ExportableColumn;
+import org.nuiton.csv.ModelBuilder;
+
+/**
+ * Created by davidcosse on 01/08/14.
+ */
+public class AccountEBPModel extends AbstractLimaModel<Account> implements ExportModel<Account> {
+
+
+ public AccountEBPModel() {
+ super(',');
+ newMandatoryColumn("Numero", Account.PROPERTY_ACCOUNT_NUMBER);
+ newOptionalColumn("Intitule", Account.PROPERTY_LABEL);
+ newIgnoredColumn("Type");
+ newIgnoredColumn("bLetManuel");
+ newIgnoredColumn("bLetAuto");
+ newIgnoredColumn("bLetAppro");
+ newIgnoredColumn("bCentPhysique");
+ newIgnoredColumn("bCentJournal");
+ newIgnoredColumn("bCentGLivre");
+ newIgnoredColumn("bGeleDebit");
+ newIgnoredColumn("bGeleCredit");
+ newIgnoredColumn("bNoEchAna");
+ newIgnoredColumn("TypeRel");
+ newIgnoredColumn("Categorie");
+ newIgnoredColumn("CodeTVA");
+ newIgnoredColumn("TypeTVA");
+ newIgnoredColumn("Lettrage");
+ newIgnoredColumn("Encours");
+ newIgnoredColumn("Seuil");
+ newIgnoredColumn("Remise");
+ newIgnoredColumn("Escompte");
+ newIgnoredColumn("Devise");
+ newIgnoredColumn("RIB0NomBanque");
+ newIgnoredColumn("RIB0AdrBanque");
+ newIgnoredColumn("RIB0Agence");
+ newIgnoredColumn("RIB0Guichet");
+ newIgnoredColumn("RIB0Compte");
+ newIgnoredColumn("RIB0CleRIB");
+ newIgnoredColumn("RIB1NomBanque");
+ newIgnoredColumn("RIB1AdrBanque");
+ newIgnoredColumn("RIB1Agence");
+ newIgnoredColumn("RIB1Guichet");
+ newIgnoredColumn("RIB1Compte");
+ newIgnoredColumn("RIB1CleRIB");
+ newIgnoredColumn("RIB2NomBanque");
+ newIgnoredColumn("RIB2AdrBanque");
+ newIgnoredColumn("RIB2Agence");
+ newIgnoredColumn("RIB2Guichet");
+ newIgnoredColumn("RIB2Compte");
+ newIgnoredColumn("RIB2CleRIB");
+ newIgnoredColumn("AdresseCivilite");
+ newIgnoredColumn("AdresseRaiSoc");
+ newIgnoredColumn("AdresseAdresse");
+ newIgnoredColumn("AdresseCodePostal");
+ newIgnoredColumn("AdresseVille");
+ newIgnoredColumn("AdressePays");
+ newIgnoredColumn("NII");
+ newIgnoredColumn("Contact0Interloc");
+ newIgnoredColumn("Contact0Fonction");
+ newIgnoredColumn("Contact0TelNumTel");
+ newIgnoredColumn("Contact0TelNumFax");
+ newIgnoredColumn("Contact0Infos");
+ newIgnoredColumn("Contact1Interloc");
+ newIgnoredColumn("Contact1Fonction");
+ newIgnoredColumn("Contact1TelNumTel");
+ newIgnoredColumn("Contact1TelNumFax");
+ newIgnoredColumn("Contact1Infos");
+ newIgnoredColumn("Contact2Interloc");
+ newIgnoredColumn("Contact2Fonction");
+ newIgnoredColumn("Contact2TelNumTel");
+ newIgnoredColumn("Contact2TelNumFax");
+ newIgnoredColumn("Contact2Infos");
+ newIgnoredColumn("Contact3Interloc");
+ newIgnoredColumn("Contact3Fonction");
+ newIgnoredColumn("Contact3TelNumTel");
+ newIgnoredColumn("Contact3TelNumFax");
+ newIgnoredColumn("Contact3Infos");
+ newIgnoredColumn("Contact4Interloc");
+ newIgnoredColumn("Contact4Fonction");
+ newIgnoredColumn("Contact4TelNumTel");
+ newIgnoredColumn("Contact4TelNumFax");
+ newIgnoredColumn("Contact4Infos");
+ newIgnoredColumn("CodeRegle");
+ newIgnoredColumn("NbJours");
+ newIgnoredColumn("TypeJours");
+ newIgnoredColumn("Limite");
+ newIgnoredColumn("Grille1");
+ newIgnoredColumn("Grille2");
+ newIgnoredColumn("Grille3");
+ newIgnoredColumn("SectGeo");
+ newIgnoredColumn("SectAct");
+ newIgnoredColumn("ObjCA");
+ newIgnoredColumn("TailleCA");
+ newIgnoredColumn("NbEmpl");
+ newIgnoredColumn("Commercial");
+ newIgnoredColumn("JoursMois");
+ newIgnoredColumn("CptTva");
+ newIgnoredColumn("CptCharge");
+ newIgnoredColumn("bDecouvertAutorise");
+ newIgnoredColumn("MntDecouvertAutorise");
+ newIgnoredColumn("EMailTiers");
+ newIgnoredColumn("WebSiteTiers");
+ newIgnoredColumn("NatAchat");
+ newIgnoredColumn("NatVente");
+ newIgnoredColumn("NatDepense");
+ newIgnoredColumn("NatRecette");
+ newIgnoredColumn("NumCptBqCH");
+ newIgnoredColumn("NumClearing");
+ newIgnoredColumn("NumIBAN");
+ newIgnoredColumn("LetPart");
+ }
+
+ @Override
+ public Iterable<ExportableColumn<Account, Object>> getColumnsForExport() {
+ ModelBuilder<Account> modelBuilder = new ModelBuilder<>();
+ modelBuilder.newColumnForExport("Numero", Account.PROPERTY_ACCOUNT_NUMBER);
+ modelBuilder.newColumnForExport("Intitule", Account.PROPERTY_LABEL);
+ return (Iterable) modelBuilder.getColumnsForExport();
+ }
+
+ @Override
+ public Account newEmptyInstance() {
+ return new AccountImpl();
+ }
+}
Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/EntryEBPModel.java
===================================================================
--- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/EntryEBPModel.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ebp/EntryEBPModel.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -25,6 +25,7 @@
import org.chorem.lima.beans.EntryEBP;
import org.chorem.lima.beans.EntryEBPImpl;
import org.chorem.lima.business.ejb.csv.AbstractLimaModel;
+import org.chorem.lima.entity.Entry;
import org.nuiton.csv.ExportModel;
import org.nuiton.csv.ExportableColumn;
import org.nuiton.csv.ModelBuilder;
@@ -32,7 +33,7 @@
/**
* Created by davidcosse on 03/06/14.
*/
-public class EntryEBPModel extends AbstractLimaModel<EntryEBP> implements ExportModel<EntryEBP> {
+public class EntryEBPModel extends AbstractLimaModel<EntryEBP> implements ExportModel<Entry> {
public EntryEBPModel() {
super(',');
@@ -73,16 +74,16 @@
}
@Override
- public Iterable<ExportableColumn<EntryEBP, Object>> getColumnsForExport() {
- ModelBuilder<EntryEBP> modelBuilder = new ModelBuilder<>();
- modelBuilder.newColumnForExport("Journal", EntryEBP.PROPERTY_JOURNAL);
- modelBuilder.newColumnForExport("Compte", EntryEBP.PROPERTY_COMPTE, ACCOUNT_TO_ACCOUNT_NUMBER_FORMATTER);
- modelBuilder.newColumnForExport("DatEcr", EntryEBP.PROPERTY_DAT_ECR, DATE_FORMATTER);
- modelBuilder.newColumnForExport("Piece", EntryEBP.PROPERTY_PIECE);
- modelBuilder.newColumnForExport("Libelle", EntryEBP.PROPERTY_LIBELLE);
- modelBuilder.newColumnForExport("Debit", EntryEBP.PROPERTY_DEBIT, BIG_DECIMAL_FORMATTER);
- modelBuilder.newColumnForExport("Credit", EntryEBP.PROPERTY_CREDIT, BIG_DECIMAL_FORMATTER);
- modelBuilder.newColumnForExport("Lettre", EntryEBP.PROPERTY_LETTRE);
+ public Iterable<ExportableColumn<Entry, Object>> getColumnsForExport() {
+ ModelBuilder<Entry> modelBuilder = new ModelBuilder<>();
+ modelBuilder.newColumnForExport("Journal", Entry.PROPERTY_FINANCIAL_TRANSACTION, FINANCIAL_TRANSACTION_TO_ENTRY_BOOK_FORMATTER);
+ modelBuilder.newColumnForExport("Compte", Entry.PROPERTY_ACCOUNT, ACCOUNT_TO_ACCOUNT_NUMBER_FORMATTER);
+ modelBuilder.newColumnForExport("DatEcr", Entry.PROPERTY_FINANCIAL_TRANSACTION, FINANCIAL_TRANSACTION_TO_TRANSACTION_DATE_FORMATTER);
+ modelBuilder.newColumnForExport("Piece", Entry.PROPERTY_VOUCHER);
+ modelBuilder.newColumnForExport("Libelle", Entry.PROPERTY_DESCRIPTION);
+ modelBuilder.newColumnForExport("Debit", ENTRY_DEBIT_GETTER);
+ modelBuilder.newColumnForExport("Credit", ENTRY_CREDIT_GETTER);
+ modelBuilder.newColumnForExport("Lettre", Entry.PROPERTY_LETTERING);
return (Iterable) modelBuilder.getColumnsForExport();
}
Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java
===================================================================
--- trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -36,7 +36,6 @@
import org.chorem.lima.business.api.FinancialTransactionService;
import org.chorem.lima.business.api.FiscalPeriodService;
import org.chorem.lima.business.api.IdentityService;
-import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.business.api.NewExportService;
import org.chorem.lima.business.api.NewImportService;
import org.chorem.lima.business.api.ReportService;
@@ -96,7 +95,6 @@
protected FinancialTransactionService financialTransactionService;
protected FiscalPeriodService fiscalPeriodService;
protected ReportService reportService;
- protected ImportService importService;
protected EntryService entryService;
protected NewImportService newImportService;
protected NewExportService newExportService;
@@ -138,7 +136,6 @@
financialTransactionService = LimaServiceFactory.getService(FinancialTransactionService.class);
fiscalPeriodService = LimaServiceFactory.getService(FiscalPeriodService.class);
reportService = LimaServiceFactory.getService(ReportService.class);
- importService = LimaServiceFactory.getService(ImportService.class);
entryService = LimaServiceFactory.getService(EntryService.class);
financialStatementService = LimaServiceFactory.getService(FinancialStatementService.class);
vatStatementService = LimaServiceFactory.getService(VatStatementService.class);
Deleted: trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java
===================================================================
--- trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -1,113 +0,0 @@
-/*
- * #%L
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2012 Codelutin, Chatellier Eric
- * %%
- * 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;
-
-import org.apache.commons.io.IOUtils;
-import org.chorem.lima.entity.Account;
-import org.chorem.lima.entity.FiscalPeriod;
-import org.chorem.lima.entity.FiscalPeriodImpl;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.ParseException;
-
-/**
- * Test du service d'import en faisant des import/export EBP et xml.
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
- */
-public class ImportServiceImplTest extends AbstractLimaTest {
-
- /**
- * Import files available in src/test/resources/ebp.
- *
- * @throws IOException
- * @throws ParseException
- * @throws BeginAfterEndFiscalPeriodException
- * @throws NotBeginNextDayOfLastFiscalPeriodException
- * @throws MoreOneUnlockFiscalPeriodException
- * @throws ImportEbpException
- */
- protected void importEBPData() throws IOException, ParseException, BeginAfterEndFiscalPeriodException,
- NotBeginNextDayOfLastFiscalPeriodException, MoreOneUnlockFiscalPeriodException, ImportEbpException {
-
- // create fiscal period (mandatory for import)
- FiscalPeriod fiscalPeriod = new FiscalPeriodImpl();
- fiscalPeriod.setBeginDate(df.parse("January 1, 2012"));
- fiscalPeriod.setEndDate(df.parse("December 31, 2012"));
- fiscalPeriodService.createFiscalPeriod(fiscalPeriod);
-
- // import files
- InputStream accountStream = null;
- try {
- accountStream = ImportServiceImplTest.class.getResourceAsStream("/ebp/comptes.txt");
- String accountData = IOUtils.toString(accountStream, "ISO-8859-1");
- importService.importAccountsChartFromEbp(accountData);
- accountStream.close();
- }
- finally {
- IOUtils.closeQuietly(accountStream);
- }
- }
-
- /**
- * Do some test on imported accounts.
- *
- * @throws Exception
- */
- @Test
- public void testImportAccountsEBP() throws Exception {
- importEBPData();
-
- Assert.assertEquals(571, accountService.getAllAccounts().size());
- Assert.assertEquals("Créances", accountService.getAccountByNumber("78174000").getLabel());
-
- // test employe and client
- Assert.assertNotNull(accountService.getAccountByNumber("401TEEMP"));
- Assert.assertNotNull(accountService.getAccountByNumber("411TECLI"));
- }
-
- /**
- * Test que les comptes tiers sont correctement rattachés à l'arbre du
- * plan comptable.
- *
- * @throws Exception
- */
- @Test
- public void testImportCreateIntermediaiteAccount() throws Exception {
- importEBPData();
-
- Account compteTiers = accountService.getAccountByNumber("4");
- Account employeAccount = accountService.getAccountByNumber("401TEEMP");
- Assert.assertNotNull(compteTiers);
- Assert.assertNotNull(employeAccount);
- }
-
-}
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-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -46,6 +46,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
+import java.text.ParseException;
import java.util.Collection;
import java.util.List;
import java.util.zip.ZipEntry;
@@ -344,7 +345,7 @@
@Test
public void testImportFiscalStatementsAsCSV() throws Exception {
// not ordered csv import file
- String bcr_developed = IOUtils.toString(ImportServiceImplTest.class.getResourceAsStream("/import/bcr_developed.csv"));
+ String bcr_developed = IOUtils.toString(NewImportExportServiceTest.class.getResourceAsStream("/import/bcr_developed.csv"));
ImportResult result;
@@ -365,7 +366,7 @@
@Test
public void testImportVATStatementsAsCSV() throws Exception {
// not ordered csv import file
- String bcr_developed = IOUtils.toString(ImportServiceImplTest.class.getResourceAsStream("/import/vat_shortened.csv"));
+ String bcr_developed = IOUtils.toString(NewImportExportServiceTest.class.getResourceAsStream("/import/vat_shortened.csv"));
ImportResult result;
@@ -419,4 +420,125 @@
EntryBook updatedEntryBook = entryBookService.getEntryBookByCode("AC");
Assert.assertEquals("Achats de marchandises", updatedEntryBook.getLabel());
}
+
+ @Test
+ public void testExportImportEntriesEbp() throws Exception {
+ initTestWithFinancialTransaction();
+
+ List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012"));
+ List<Entry> entries = Lists.newArrayList();
+ Assert.assertFalse(financialTransactions.isEmpty());
+ for (FinancialTransaction financialTransaction : financialTransactions) {
+ entries.addAll(financialTransaction.getEntry());
+ }
+ Assert.assertTrue(!entries.isEmpty());
+ int nbEntities = entries.size();
+
+ //test export
+ String tmpDir = System.getProperty("java.io.tmpdir")+"/";
+ String export = newExportService.exportEntriesAsEbp(Charset.defaultCharset().name());
+ InputStream stream = IOUtils.toInputStream(export);
+ FileOutputStream res = new FileOutputStream(tmpDir + "export-entries-EBP.csv");
+ IOUtils.copy(stream, res);
+
+ for (Entry entry : entries) {
+ FinancialTransaction financialTransaction = entry.getFinancialTransaction();
+ financialTransactionService.removeEntry(entry);
+ financialTransactionService.updateFinancialTransaction(financialTransaction);
+ }
+
+ // ake sure all entries have been cleared
+ entries.clear();//
+
+ financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012"));
+ for (FinancialTransaction financialTransaction : financialTransactions) {
+ entries.addAll(financialTransaction.getEntry());
+ }
+ Assert.assertTrue(entries.isEmpty());
+
+ // test import
+ FileInputStream contentStream = null;
+ ImportResult result;
+ try {
+ contentStream = new FileInputStream(tmpDir + "export-entries-EBP.csv");
+ String inputStream = IOUtils.toString(contentStream);
+ result = newImportService.importEntriesFromEbp(inputStream);
+ } finally {
+ IOUtils.closeQuietly(contentStream);
+ }
+
+ // valid import
+ financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("April 4, 2012"),df.parse("December 31, 2012"));
+ Assert.assertEquals(1, financialTransactions.size());
+ for (FinancialTransaction financialTransaction : financialTransactions) {
+ entries.addAll(financialTransaction.getEntry());
+ }
+
+ Assert.assertEquals(nbEntities, entries.size());
+ Assert.assertEquals(nbEntities, result.getNbCreated());
+ Assert.assertTrue(result.getException().getAllExceptionsByLine().isEmpty());
+ for (Entry entry : entries) {
+ Assert.assertTrue(42.0 == entry.getAmount().doubleValue());
+ }
+ }
+
+ protected void importEBPData() throws IOException, ParseException, BeginAfterEndFiscalPeriodException,
+ NotBeginNextDayOfLastFiscalPeriodException, MoreOneUnlockFiscalPeriodException, ImportEbpException {
+
+ // create fiscal period (mandatory for import)
+ FiscalPeriod fiscalPeriod = new FiscalPeriodImpl();
+ fiscalPeriod.setBeginDate(df.parse("January 1, 2012"));
+ fiscalPeriod.setEndDate(df.parse("December 31, 2012"));
+ fiscalPeriodService.createFiscalPeriod(fiscalPeriod);
+
+ // import files
+ InputStream accountStream = null, entryBookStream = null, entriesStream = null;
+ try {
+ accountStream = NewImportExportServiceTest.class.getResourceAsStream("/ebp/comptes.txt");
+ entryBookStream = NewImportExportServiceTest.class.getResourceAsStream("/ebp/journaux.txt");
+ entriesStream = NewImportExportServiceTest.class.getResourceAsStream("/ebp/ecritures.txt");
+
+ newImportService.importAccountFromEbp(IOUtils.toString(accountStream, "ISO-8859-1"));
+ newImportService.importEntryBookFromEbp(IOUtils.toString(entryBookStream, "ISO-8859-1"));
+ newImportService.importEntriesFromEbp(IOUtils.toString(entriesStream, "ISO-8859-1"));
+ }
+ finally {
+ IOUtils.closeQuietly(accountStream);
+ IOUtils.closeQuietly(entryBookStream);
+ IOUtils.closeQuietly(entriesStream);
+ }
+ }
+
+ /**
+ * Do some test on imported accounts.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testImportAccountsEBP() throws Exception {
+ importEBPData();
+
+ Assert.assertEquals(571, accountService.getAllAccounts().size());
+ Assert.assertEquals("Créances", accountService.getAccountByNumber("78174000").getLabel());
+
+ // test employe and client
+ Assert.assertNotNull(accountService.getAccountByNumber("401TEEMP"));
+ Assert.assertNotNull(accountService.getAccountByNumber("411TECLI"));
+ }
+
+ /**
+ * Test que les comptes tiers sont correctement rattachés à l'arbre du
+ * plan comptable.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testImportCreateIntermediateAccount() throws Exception {
+ importEBPData();
+
+ Account compteTiers = accountService.getAccountByNumber("4");
+ Account employeAccount = accountService.getAccountByNumber("401TEEMP");
+ Assert.assertNotNull(compteTiers);
+ Assert.assertNotNull(employeAccount);
+ }
}
Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ImportServiceRuleFrTest.java
===================================================================
--- trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ImportServiceRuleFrTest.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/ImportServiceRuleFrTest.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -24,8 +24,8 @@
package org.chorem.lima.business.accountingrules;
import org.chorem.lima.business.AccountingRules;
-import org.chorem.lima.business.ImportServiceImplTest;
import org.chorem.lima.business.LimaConfig;
+import org.chorem.lima.business.NewImportExportServiceTest;
import org.junit.Assert;
import org.junit.Test;
@@ -44,7 +44,7 @@
* Last update : $Date$
* By : $Author$
*/
-public class ImportServiceRuleFrTest extends ImportServiceImplTest {
+public class ImportServiceRuleFrTest extends NewImportExportServiceTest {
protected Properties getTestConfiguration() {
Properties config = super.getTestConfiguration();
Deleted: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java
===================================================================
--- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportService.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -1,88 +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.api;
-
-import org.chorem.lima.business.LimaException;
-
-/**
- * Import export service.
- * <p/>
- * Currently import and export as XML.
- *
- * @author chatellier
- * @version $Revision$
- * <p/>
- * Last update : $Date$
- * By : $Author$
- */
-public interface ExportService {
-
-
- /**
- * Get database export as CSV;
- *
- * @return export as byte array
- * @throws LimaException
- */
- String exportAsCSV();
-
- /**
- * export entrybook chart as CSV.
- */
- String exportEntryBookChartAsCSV();
-
- /**
- * export financialstatement chart as CSV.
- */
- String exportFinancialStatementChartAsCSV();
-
- /**
- * export vatstatement chart as CSV
- */
- String exportVatStatementChartAsCSV();
-
- /**
- * export accounts chart as CSV.
- */
- String exportAccountsChartAsCSV();
-
- /**
- * export entries as EBP
- */
- String exportEntriesAsEBP();
-
- /**
- * export accounts as EBP
- */
- String exportAccountsAsEBP();
-
- /**
- * export entryBooks as EBP
- * @return
- * @throws LimaException
- */
- String exportEntryBooksAsEBP();
-}
Deleted: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportServiceLocal.java
===================================================================
--- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportServiceLocal.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ExportServiceLocal.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -1,41 +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.api;
-
-/**
- * Import export service.
- * <p/>
- * Currently import and export as XML.
- *
- * @author chatellier
- * @version $Revision$
- * <p/>
- * Last update : $Date$
- * By : $Author$
- */
-public interface ExportServiceLocal extends ExportService {
-
-}
Deleted: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java
===================================================================
--- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -1,56 +0,0 @@
-/*
- * #%L
- * Lima business
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric
- * %%
- * 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.api;
-
-import org.chorem.lima.business.ImportEbpException;
-import org.chorem.lima.business.LimaException;
-import org.chorem.lima.business.utils.ImportExportEntityEnum;
-
-/**
- * Import export service.
- * Currently import and export as CSV and EBP.
- */
-public interface ImportService {
-
- /**
- * Import accounts as EBP import.
- *
- * @param data import file content as string (remote service can't take File)
- * @return result log
- * @throws LimaException
- */
- String importAccountsChartFromEbp(String data) throws ImportEbpException;
-
- /**
- * @deprecated import file (local, can't be used in remote mode)
- * and wrong place for this method
- */
- String importAsPDF(String data,
- ImportExportEntityEnum importExportEntityEnum,
- boolean saveMode);
-
-
-}
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-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -38,7 +38,7 @@
*/
public interface NewExportService {
- String exportBackup(String charset);
+ //####################################### CSV ##############################################
String exportAccountsAsCSV(String charset);
@@ -51,4 +51,14 @@
String exportFinancialStatements(String charset) throws Exception;
String exportVatStatements(String charset) throws Exception;
+
+ String exportBackup(String charset);
+
+ //####################################### EBP ##############################################
+
+ String exportAccountAsEbp(String charset) throws Exception;
+
+ String exportEntriesAsEbp(String charset) throws Exception;
+
+ String exportEntryBookAsEbp(String charset) throws Exception;
}
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-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -33,6 +33,8 @@
*/
public interface NewImportService {
+ //####################################### CSV ##############################################
+
ImportResult importAccountAsCSV(String contents);
ImportResult importEntryBooksAsCSV(String contents);
@@ -47,7 +49,15 @@
List<ImportResult> importBackup(String entryBooks, String transactions, String fiscalPeriods, String accounts, String entries, String identity) throws AlreadyExistAccountException, InvalidAccountNumberException;
+ //####################################### EBP ##############################################
+
+ ImportResult importAccountFromEbp(String datas);
+
ImportResult importEntriesFromEbp(String datas);
ImportResult importEntryBookFromEbp(String datas);
+
+// String importAsPDF(String data,
+// ImportExportEntityEnum importExportEntityEnum,
+// boolean saveMode);
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -33,7 +33,7 @@
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.UsedAccountException;
import org.chorem.lima.business.api.AccountService;
-import org.chorem.lima.business.api.ImportService;
+import org.chorem.lima.business.api.NewImportService;
import org.chorem.lima.entity.Account;
import org.chorem.lima.enums.AccountsChartEnum;
import org.chorem.lima.enums.ImportExportEnum;
@@ -46,12 +46,7 @@
import org.jdesktop.swingx.treetable.MutableTreeTableNode;
import org.jdesktop.swingx.treetable.TreeTableNode;
-import javax.swing.AbstractAction;
-import javax.swing.ActionMap;
-import javax.swing.InputMap;
-import javax.swing.JComponent;
-import javax.swing.JOptionPane;
-import javax.swing.KeyStroke;
+import javax.swing.*;
import javax.swing.tree.TreePath;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
@@ -122,7 +117,7 @@
public AccountViewHandler(AccountView view) {
this.view = view;
// Gets factory service
- LimaServiceFactory.addServiceListener(ImportService.class, this);
+ LimaServiceFactory.addServiceListener(NewImportService.class, this);
accountService = LimaServiceFactory.getService(AccountService.class);
errorHelper = new ErrorHelper(LimaConfig.getInstance());
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountComboBoxModel.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountComboBoxModel.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/AccountComboBoxModel.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -29,12 +29,11 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.AccountService;
-import org.chorem.lima.business.api.ImportService;
+import org.chorem.lima.business.api.NewImportService;
import org.chorem.lima.entity.Account;
import org.chorem.lima.service.LimaServiceFactory;
-import javax.swing.AbstractListModel;
-import javax.swing.ComboBoxModel;
+import javax.swing.*;
import java.util.List;
/** Account combo box model. */
@@ -57,7 +56,7 @@
LimaServiceFactory.getService(
AccountService.class);
LimaServiceFactory.addServiceListener(AccountService.class, this);
- LimaServiceFactory.addServiceListener(ImportService.class, this);
+ LimaServiceFactory.addServiceListener(NewImportService.class, this);
datasCache = getDataList();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookComboBoxModel.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookComboBoxModel.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookComboBoxModel.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -29,12 +29,11 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.EntryBookService;
-import org.chorem.lima.business.api.ImportService;
+import org.chorem.lima.business.api.NewImportService;
import org.chorem.lima.entity.EntryBook;
import org.chorem.lima.service.LimaServiceFactory;
-import javax.swing.AbstractListModel;
-import javax.swing.ComboBoxModel;
+import javax.swing.*;
import java.util.List;
/**
@@ -63,7 +62,7 @@
entryBookService =
LimaServiceFactory.getService(EntryBookService.class);
LimaServiceFactory.addServiceListener(EntryBookService.class, this);
- LimaServiceFactory.addServiceListener(ImportService.class, this);
+ LimaServiceFactory.addServiceListener(NewImportService.class, this);
cacheDatas = getDataList();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FinancialPeriodComboBoxModel.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FinancialPeriodComboBoxModel.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FinancialPeriodComboBoxModel.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -30,13 +30,12 @@
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.FinancialPeriodService;
import org.chorem.lima.business.api.FiscalPeriodService;
-import org.chorem.lima.business.api.ImportService;
+import org.chorem.lima.business.api.NewImportService;
import org.chorem.lima.entity.FinancialPeriod;
import org.chorem.lima.entity.FiscalPeriod;
import org.chorem.lima.service.LimaServiceFactory;
-import javax.swing.AbstractListModel;
-import javax.swing.ComboBoxModel;
+import javax.swing.*;
import java.util.List;
/**
@@ -85,7 +84,7 @@
FinancialPeriodService.class);
LimaServiceFactory.addServiceListener(FinancialPeriodService.class, this);
LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this);
- LimaServiceFactory.addServiceListener(ImportService.class, this);
+ LimaServiceFactory.addServiceListener(NewImportService.class, this);
if (displayAllPeriods) {
datasCache = getAllDataList();
} else {
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxModel.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxModel.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxModel.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -29,12 +29,11 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.FiscalPeriodService;
-import org.chorem.lima.business.api.ImportService;
+import org.chorem.lima.business.api.NewImportService;
import org.chorem.lima.entity.FiscalPeriod;
import org.chorem.lima.service.LimaServiceFactory;
-import javax.swing.AbstractListModel;
-import javax.swing.ComboBoxModel;
+import javax.swing.*;
import java.util.List;
public class FiscalPeriodComboBoxModel extends AbstractListModel implements ComboBoxModel, ServiceListener {
@@ -55,7 +54,7 @@
LimaServiceFactory.getService(
FiscalPeriodService.class);
LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this);
- LimaServiceFactory.addServiceListener(ImportService.class, this);
+ LimaServiceFactory.addServiceListener(NewImportService.class, this);
datasCache = getDataList();
if (log.isDebugEnabled()) {
@@ -70,7 +69,7 @@
LimaServiceFactory.getService(
FiscalPeriodService.class);
LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this);
- LimaServiceFactory.addServiceListener(ImportService.class, this);
+ LimaServiceFactory.addServiceListener(NewImportService.class, this);
datasCache = getAllDataList();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/LeafAccountComboBoxModel.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/LeafAccountComboBoxModel.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/LeafAccountComboBoxModel.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -29,13 +29,12 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.AccountService;
-import org.chorem.lima.business.api.ImportService;
+import org.chorem.lima.business.api.NewImportService;
import org.chorem.lima.business.utils.AccountComparator;
import org.chorem.lima.entity.Account;
import org.chorem.lima.service.LimaServiceFactory;
-import javax.swing.AbstractListModel;
-import javax.swing.ComboBoxModel;
+import javax.swing.*;
import java.util.Collections;
import java.util.List;
@@ -58,7 +57,7 @@
accountService =
LimaServiceFactory.getService(AccountService.class);
LimaServiceFactory.addServiceListener(AccountService.class, this);
- LimaServiceFactory.addServiceListener(ImportService.class, this);
+ LimaServiceFactory.addServiceListener(NewImportService.class, this);
datasCache = getDataList();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -28,10 +28,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.lima.LimaConfig;
-import org.chorem.lima.business.UsedEntryBookException;
import org.chorem.lima.business.ServiceListener;
+import org.chorem.lima.business.UsedEntryBookException;
import org.chorem.lima.business.api.EntryBookService;
-import org.chorem.lima.business.api.ImportService;
+import org.chorem.lima.business.api.NewImportService;
import org.chorem.lima.entity.EntryBook;
import org.chorem.lima.entity.EntryBookImpl;
import org.chorem.lima.enums.EntryBooksChartEnum;
@@ -41,12 +41,7 @@
import org.chorem.lima.util.ErrorHelper;
import org.jdesktop.swingx.JXTable;
-import javax.swing.AbstractAction;
-import javax.swing.ActionMap;
-import javax.swing.InputMap;
-import javax.swing.JComponent;
-import javax.swing.JOptionPane;
-import javax.swing.KeyStroke;
+import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
@@ -77,7 +72,7 @@
public EntryBookViewHandler(EntryBookView view) {
this.view = view;
entryBookService = LimaServiceFactory.getService(EntryBookService.class);
- LimaServiceFactory.addServiceListener(ImportService.class, this);
+ LimaServiceFactory.addServiceListener(NewImportService.class, this);
errorHelper = new ErrorHelper(LimaConfig.getInstance());
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -36,7 +36,7 @@
import org.chorem.lima.business.WithoutEntryBookFinancialTransactionsException;
import org.chorem.lima.business.api.FinancialPeriodService;
import org.chorem.lima.business.api.FiscalPeriodService;
-import org.chorem.lima.business.api.ImportService;
+import org.chorem.lima.business.api.NewImportService;
import org.chorem.lima.business.utils.FinancialPeriodComparator;
import org.chorem.lima.entity.ClosedPeriodicEntryBook;
import org.chorem.lima.entity.Entry;
@@ -46,12 +46,7 @@
import org.chorem.lima.util.ErrorHelper;
import org.jdesktop.swingx.JXTable;
-import javax.swing.AbstractAction;
-import javax.swing.ActionMap;
-import javax.swing.InputMap;
-import javax.swing.JComponent;
-import javax.swing.JOptionPane;
-import javax.swing.KeyStroke;
+import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.Collections;
@@ -82,7 +77,7 @@
this.view = view;
financialPeriodService = LimaServiceFactory.getService(FinancialPeriodService.class);
- LimaServiceFactory.addServiceListener(ImportService.class, this);
+ LimaServiceFactory.addServiceListener(NewImportService.class, this);
LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this);
errorHelper = new ErrorHelper(LimaConfig.getInstance());
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -29,7 +29,7 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.FinancialStatementService;
-import org.chorem.lima.business.api.ImportService;
+import org.chorem.lima.business.api.NewImportService;
import org.chorem.lima.entity.Account;
import org.chorem.lima.entity.FinancialStatement;
import org.chorem.lima.entity.FinancialStatementImpl;
@@ -41,15 +41,9 @@
import org.jdesktop.swingx.JXTreeTable;
import org.nuiton.util.Resource;
-import javax.swing.AbstractAction;
-import javax.swing.ActionMap;
-import javax.swing.InputMap;
-import javax.swing.JComponent;
-import javax.swing.JOptionPane;
-import javax.swing.JTextArea;
-import javax.swing.KeyStroke;
+import javax.swing.*;
import javax.swing.tree.TreePath;
-import java.awt.Component;
+import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
@@ -80,7 +74,7 @@
financialStatementService =
LimaServiceFactory.getService(
FinancialStatementService.class);
- LimaServiceFactory.addServiceListener(ImportService.class, this);
+ LimaServiceFactory.addServiceListener(NewImportService.class, this);
init();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -39,7 +39,7 @@
import org.chorem.lima.business.api.FinancialPeriodService;
import org.chorem.lima.business.api.FinancialTransactionService;
import org.chorem.lima.business.api.FiscalPeriodService;
-import org.chorem.lima.business.api.ImportService;
+import org.chorem.lima.business.api.NewImportService;
import org.chorem.lima.entity.Entry;
import org.chorem.lima.entity.EntryBook;
import org.chorem.lima.entity.EntryImpl;
@@ -51,14 +51,7 @@
import org.chorem.lima.ui.common.FinancialTransactionTableModel;
import org.chorem.lima.util.ErrorHelper;
-import javax.swing.AbstractAction;
-import javax.swing.ActionMap;
-import javax.swing.InputMap;
-import javax.swing.JComboBox;
-import javax.swing.JComponent;
-import javax.swing.JOptionPane;
-import javax.swing.KeyStroke;
-import javax.swing.ListSelectionModel;
+import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.TableColumnModelEvent;
@@ -112,7 +105,7 @@
financialTransactionService = LimaServiceFactory.getService(FinancialTransactionService.class);
LimaServiceFactory.addServiceListener(FinancialPeriodService.class, this);
LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this);
- LimaServiceFactory.addServiceListener(ImportService.class, this);
+ LimaServiceFactory.addServiceListener(NewImportService.class, this);
errorHelper = new ErrorHelper(LimaConfig.getInstance());
initShortCuts();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/AccountsPane.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/AccountsPane.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/AccountsPane.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -30,7 +30,7 @@
import org.chorem.lima.LimaContext;
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.AccountService;
-import org.chorem.lima.business.api.ImportService;
+import org.chorem.lima.business.api.NewImportService;
import org.chorem.lima.service.LimaServiceFactory;
import org.chorem.lima.ui.MainView;
@@ -60,7 +60,7 @@
accountService = LimaServiceFactory.getService(AccountService.class);
LimaServiceFactory.addServiceListener(AccountService.class, this);
- LimaServiceFactory.addServiceListener(ImportService.class, this);
+ LimaServiceFactory.addServiceListener(NewImportService.class, this);
refresh();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/EntryBooksPane.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/EntryBooksPane.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/EntryBooksPane.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -30,7 +30,7 @@
import org.chorem.lima.LimaContext;
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.EntryBookService;
-import org.chorem.lima.business.api.ImportService;
+import org.chorem.lima.business.api.NewImportService;
import org.chorem.lima.entity.EntryBook;
import org.chorem.lima.service.LimaServiceFactory;
import org.chorem.lima.ui.MainView;
@@ -62,7 +62,7 @@
entryBookService = LimaServiceFactory.getService(EntryBookService.class);
LimaServiceFactory.addServiceListener(EntryBookService.class, this);
- LimaServiceFactory.addServiceListener(ImportService.class, this);
+ LimaServiceFactory.addServiceListener(NewImportService.class, this);
refresh();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FinancialTransactionsPane.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FinancialTransactionsPane.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FinancialTransactionsPane.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -32,7 +32,7 @@
import org.chorem.lima.business.api.EntryBookService;
import org.chorem.lima.business.api.FinancialTransactionService;
import org.chorem.lima.business.api.FiscalPeriodService;
-import org.chorem.lima.business.api.ImportService;
+import org.chorem.lima.business.api.NewImportService;
import org.chorem.lima.entity.EntryBook;
import org.chorem.lima.entity.FinancialTransaction;
import org.chorem.lima.entity.FiscalPeriod;
@@ -73,7 +73,7 @@
entryBookService = LimaServiceFactory.getService(EntryBookService.class);
LimaServiceFactory.addServiceListener(FinancialTransactionService.class, this);
LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this);
- LimaServiceFactory.addServiceListener(ImportService.class, this);
+ LimaServiceFactory.addServiceListener(NewImportService.class, this);
refresh();
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FiscalYearsPane.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FiscalYearsPane.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/FiscalYearsPane.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -30,7 +30,7 @@
import org.chorem.lima.LimaContext;
import org.chorem.lima.business.ServiceListener;
import org.chorem.lima.business.api.FiscalPeriodService;
-import org.chorem.lima.business.api.ImportService;
+import org.chorem.lima.business.api.NewImportService;
import org.chorem.lima.entity.FiscalPeriod;
import org.chorem.lima.service.LimaServiceFactory;
import org.chorem.lima.ui.MainView;
@@ -68,7 +68,7 @@
fiscalPeriodService = LimaServiceFactory.getService(FiscalPeriodService.class);
LimaServiceFactory.addServiceListener(FiscalPeriodService.class, this);
- LimaServiceFactory.addServiceListener(ImportService.class, this);
+ LimaServiceFactory.addServiceListener(NewImportService.class, this);
refresh();
}
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-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -35,11 +35,8 @@
import org.chorem.lima.LimaTechnicalException;
import org.chorem.lima.business.ImportEbpException;
import org.chorem.lima.business.ImportResult;
-import org.chorem.lima.business.api.ExportService;
-import org.chorem.lima.business.api.ImportService;
import org.chorem.lima.business.api.NewExportService;
import org.chorem.lima.business.api.NewImportService;
-import org.chorem.lima.business.utils.ImportExportEntityEnum;
import org.chorem.lima.enums.EncodingEnum;
import org.chorem.lima.enums.ImportExportEnum;
import org.chorem.lima.service.LimaServiceFactory;
@@ -85,10 +82,10 @@
*/
protected EncodingEnum encodingEnum;
- protected ImportService importService;
+ protected NewImportService importService;
@Deprecated
- protected ExportService exportService;
+ protected NewExportService exportService;
protected NewImportService newImportService;
@@ -102,8 +99,6 @@
viewComponent = view;
//services
- importService = LimaServiceFactory.getService(ImportService.class);
- exportService = LimaServiceFactory.getService(ExportService.class);
newImportService = LimaServiceFactory.getService(NewImportService.class);
newExportService = LimaServiceFactory.getService(NewExportService.class);
@@ -143,101 +138,91 @@
ImportResult importResult;
try {
switch (importExportMethodeF) {
- case CSV_ALL_EXPORT:
- datas = newExportService.exportBackup(charset.name());
- createZipFile(filePath, datas);
- break;
+ //####################################### CSV ##############################################
+
case CSV_ACCOUNTCHARTS_EXPORT:
datas = newExportService.exportAccountsAsCSV(charset.name());
createFile(filePath, charset.name(), datas);
break;
+
+ case CSV_ACCOUNTCHARTS_IMPORT:
+ datas = extractFile(filePath, charset.name());
+ importResult = newImportService.importAccountAsCSV(datas);
+ // TODO DCossé 24/07/14 change result
+ result = "SUCCESS";
+ break;
+
case CSV_ENTRYBOOKS_EXPORT:
datas = newExportService.exportEntryBooksAsCSV(charset.name());
createFile(filePath, charset.name(), datas);
break;
+ case CSV_ENTRYBOOKS_IMPORT:
+ datas = extractFile(filePath, charset.name());
+ importResult = newImportService.importEntryBooksAsCSV(datas);
+ // TODO DCossé 24/07/14 change result
+ result = "SUCCESS";
+ break;
case CSV_ENTRIES_EXPORT:
datas = newExportService.exportEntriesAsCSV(charset.name(), true);
createFile(filePath, charset.name(), datas);
break;
- case CSV_FINANCIALSTATEMENTS_EXPORT:
- try {
- datas = newExportService.exportFinancialStatements(charset.name());
- createFile(filePath, charset.name(), datas);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ case CSV_ENTRIES_IMPORT:
+ datas = extractFile(filePath, charset.name());
+ importResult = newImportService.importEntriesAsCSV(datas);
+ // TODO DCossé 24/07/14 change result
+ result = "SUCCESS";
break;
- case CSV_VAT_EXPORT:
- try {
- datas = newExportService.exportVatStatements(charset.name());
- createFile(filePath, charset.name(), datas);
- } catch (Exception e) {
- e.printStackTrace();
- }
+
+ case CSV_ALL_EXPORT:
+ datas = newExportService.exportBackup(charset.name());
+ createZipFile(filePath, datas);
break;
- case EBP_ACCOUNTCHARTS_EXPORT:
- //For windows ebp
- datas = exportService.exportAccountsAsEBP();
- createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas);
- break;
- case EBP_ENTRIES_EXPORT:
- //For windows ebp
- datas = exportService.exportEntriesAsEBP();
- createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas);
- break;
case CSV_ALL_IMPORT:
List<ImportResult> allResults = importAllFromZipFile(filePath);
// TODO DCossé 24/07/14 change result
result = "SUCCESS";
break;
- case CSV_ACCOUNTCHARTS_IMPORT:
- datas = extractFile(filePath, charset.name());
- importResult = newImportService.importAccountAsCSV(datas);
- // TODO DCossé 24/07/14 change result
- result = "SUCCESS";
+
+ case CSV_VAT_EXPORT:
+ datas = newExportService.exportVatStatements(charset.name());
+ createFile(filePath, charset.name(), datas);
break;
- case CSV_ENTRYBOOKS_IMPORT:
+ case CSV_VAT_IMPORT:
datas = extractFile(filePath, charset.name());
- importResult = newImportService.importEntryBooksAsCSV(datas);
+ importResult = newImportService.importVATStatementsAsCSV(datas);
// TODO DCossé 24/07/14 change result
result = "SUCCESS";
break;
+
+ case CSV_FINANCIALSTATEMENTS_EXPORT:
+ datas = newExportService.exportFinancialStatements(charset.name());
+ createFile(filePath, charset.name(), datas);
+ break;
case CSV_FINANCIALSTATEMENTS_IMPORT:
datas = extractFile(filePath, charset.name());
importResult = newImportService.importFinancialStatementsAsCSV(datas);
// TODO DCossé 24/07/14 change result
result = "SUCCESS";
break;
- case CSV_ENTRIES_IMPORT:
- datas = extractFile(filePath, charset.name());
- importResult = newImportService.importEntriesAsCSV(datas);
- // TODO DCossé 24/07/14 change result
- result = "SUCCESS";
+
+ //####################################### EBP ##############################################
+
+ case EBP_ACCOUNTCHARTS_EXPORT:
+ //For windows ebp
+ datas = newExportService.exportAccountAsEbp(charset.name());
+ createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas);
break;
- case CSV_VAT_IMPORT:
- datas = extractFile(filePath, charset.name());
- importResult = newImportService.importVATStatementsAsCSV(datas);
- // TODO DCossé 24/07/14 change result
- result = "SUCCESS";
- break;
- case PDF_VAT_IMPORT:
- int response = JOptionPane.showConfirmDialog(waitView,
- t("lima.importexport.usevatpdf"),
- t("lima.common.confirmation"), JOptionPane.YES_NO_OPTION);
- extractFile(filePath, charset.name());
- result = importService.importAsPDF(filePath, ImportExportEntityEnum.VATPDF, response == JOptionPane.YES_OPTION);
- break;
case EBP_ACCOUNTCHARTS_IMPORT:
//For windows ebp
datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding());
- result = importService.importAccountsChartFromEbp(datas);
+ importResult = newImportService.importAccountFromEbp(datas);
// TODO DCossé 24/07/14 change result
result = "SUCCESS";
break;
- case EBP_ENTRIES_IMPORT:
- //For windows ebp
- datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding());
- importResult = newImportService.importEntriesFromEbp(datas);
+
+ case EBP_ENTRYBOOKS_EXPORT:
+ datas = newExportService.exportEntryBookAsEbp(charset.name());
+ createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas);
break;
case EBP_ENTRYBOOKS_IMPORT:
datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding());
@@ -245,13 +230,23 @@
// TODO DCossé 24/07/14 change result
result = "SUCCESS";
break;
- case EBP_ENTRYBOOKS_EXPORT:
- datas = exportService.exportEntryBooksAsEBP();
+
+ case EBP_ENTRIES_EXPORT:
+ //For windows ebp
+ datas = newExportService.exportEntriesAsEbp(charset.name());
createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas);
break;
+ case EBP_ENTRIES_IMPORT:
+ //For windows ebp
+ datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding());
+ importResult = newImportService.importEntriesFromEbp(datas);
+ break;
}
} catch (ImportEbpException e) {
errorHelper.showErrorMessage(t(e.getMessage()));
+ } catch (Exception e) {
+ // TODO DCossé 01/08/14 it should be an other exception
+ e.printStackTrace();
}
return result;
}
Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java
===================================================================
--- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java 2014-07-31 19:50:37 UTC (rev 3887)
+++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java 2014-08-01 14:20:36 UTC (rev 3888)
@@ -27,7 +27,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.lima.business.ServiceListener;
-import org.chorem.lima.business.api.ImportService;
+import org.chorem.lima.business.api.NewImportService;
import org.chorem.lima.business.api.VatStatementService;
import org.chorem.lima.entity.VatStatement;
import org.chorem.lima.entity.VatStatementImpl;
@@ -35,15 +35,9 @@
import org.chorem.lima.enums.VatStatementsChartEnum;
import org.chorem.lima.service.LimaServiceFactory;
import org.chorem.lima.ui.importexport.ImportExport;
-import org.chorem.lima.util.ErrorHelper;
import org.jdesktop.swingx.JXTreeTable;
-import javax.swing.AbstractAction;
-import javax.swing.ActionMap;
-import javax.swing.InputMap;
-import javax.swing.JComponent;
-import javax.swing.JOptionPane;
-import javax.swing.KeyStroke;
+import javax.swing.*;
import javax.swing.tree.TreePath;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
@@ -65,7 +59,7 @@
vatStatementService =
LimaServiceFactory.getService(
VatStatementService.class);
- LimaServiceFactory.addServiceListener(ImportService.class, this);
+ LimaServiceFactory.addServiceListener(NewImportService.class, this);
init();
}
1
0