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 +@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 +@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 -@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 -@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(); }