Author: dcosse Date: 2014-07-23 15:46:03 +0200 (Wed, 23 Jul 2014) New Revision: 3857 Url: http://forge.chorem.org/projects/lima/repository/revisions/3857 Log: refs #1032 d?\195?\169but de mise en place du nouveau servcice d'import export Added: trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java Removed: trunk/lima-business/src/test/java/org/chorem/lima/business/NewExportServiceTest.java Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/AccountService.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/EntryBookService.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.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/LimaInterceptor.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties trunk/lima-business/src/main/resources/lima.properties trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java trunk/lima-callao/src/main/xmi/accounting-model.zargo trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/HomeView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartView.jaxx trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaInterceptor.java 2014-07-23 13:46:03 UTC (rev 3857) @@ -36,6 +36,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaXAResource; +import org.chorem.lima.entity.AccountImpl; import org.chorem.lima.entity.LimaCallaoTopiaApplicationContext; import org.chorem.lima.entity.LimaCallaoTopiaDaoSupplier; import org.chorem.lima.entity.LimaCallaoTopiaPersistenceContext; @@ -43,6 +44,8 @@ import org.nuiton.topia.persistence.TopiaApplicationContextCache; import com.google.common.base.Function; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.util.TopiaUtil; /** * Interceptor for topia context transaction. @@ -101,6 +104,8 @@ LimaCallaoTopiaPersistenceContext tx = rootContext.newPersistenceContext(); + createShemaIfNeeded(rootContext, tx); + DAO_HELPER.set(tx); Transaction tr = transactionManager.getTransaction(); @@ -125,4 +130,26 @@ return result; } + /** + * Test if schema do not already exists and create it if not found. + * + * @param applicationContext transaction + * @throws TopiaException + */ + protected void createShemaIfNeeded(LimaCallaoTopiaApplicationContext applicationContext, LimaCallaoTopiaPersistenceContext tx) throws TopiaException { + //LimaCallaoTopiaPersistenceContext + if (!schemaExistChecked) { + boolean exist = TopiaUtil.isSchemaExist(tx, AccountImpl.class.getName()); + if (!exist) { + + if (log.isInfoEnabled()) { + log.info("Creating to schema in database"); + } + applicationContext.createSchema(); + } + + schemaExistChecked = true; + } + } + } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2014-07-23 13:46:03 UTC (rev 3857) @@ -62,8 +62,8 @@ @Override public long getAccountCount() { - AccountTopiaDao AccountTopiaDao = getDaoHelper().getAccountDao(); - long result = AccountTopiaDao.count(); + AccountTopiaDao accountTopiaDao = getDaoHelper().getAccountDao(); + long result = accountTopiaDao.count(); return result; } @@ -85,14 +85,14 @@ account.setAccountNumber(account.getAccountNumber().toUpperCase().trim()); // check if account number already exist - AccountTopiaDao AccountTopiaDao = getDaoHelper().getAccountDao(); + AccountTopiaDao accountDao = getDaoHelper().getAccountDao(); - if (AccountTopiaDao.existByNaturalId(account.getAccountNumber())) { + if (accountDao.forNaturalId(account.getAccountNumber()).exists()) { throw new AlreadyExistAccountException(account.getAccountNumber()); } //create it - Account result = AccountTopiaDao.create(account); + Account result = accountDao.create(account); return result; } @@ -101,12 +101,12 @@ public Account getMasterAccount(String accountNumber) { Account account = null; - AccountTopiaDao AccountTopiaDao = getDaoHelper().getAccountDao(); + AccountTopiaDao accountDao = getDaoHelper().getAccountDao(); while (account == null && accountNumber.length() > 1) { accountNumber = accountNumber.substring(0); - account = AccountTopiaDao.forAccountNumberEquals(accountNumber).findUniqueOrNull(); + account = accountDao.forAccountNumberEquals(accountNumber).findUniqueOrNull(); } return account; } @@ -115,8 +115,8 @@ @Override public Account getAccountByNumber(String accountNumber) { - AccountTopiaDao AccountTopiaDao = getDaoHelper().getAccountDao(); - Account account = AccountTopiaDao.forAccountNumberEquals(accountNumber).findUniqueOrNull(); + AccountTopiaDao accountDao = getDaoHelper().getAccountDao(); + Account account = accountDao.forAccountNumberEquals(accountNumber).findUniqueOrNull(); return account; } @@ -126,8 +126,8 @@ @Override public List<Account> getAllAccounts() { - AccountTopiaDao AccountTopiaDao = getDaoHelper().getAccountDao(); - List<Account> accountsList = AccountTopiaDao.findAll(); + AccountTopiaDao accountDao = getDaoHelper().getAccountDao(); + List<Account> accountsList = accountDao.findAll(); Collections.sort(accountsList, new AccountComparator()); return accountsList; @@ -138,8 +138,8 @@ @Override public List<Account> getAllLeafAccounts() { - AccountTopiaDao AccountTopiaDao = getDaoHelper().getAccountDao(); - List<Account> accountsList = AccountTopiaDao.findAllLeafAccounts(); + AccountTopiaDao accountDao = getDaoHelper().getAccountDao(); + List<Account> accountsList = accountDao.findAllLeafAccounts(); return accountsList; } @@ -150,8 +150,8 @@ @Override public List<Account> getAllSubAccounts(Account account) { - AccountTopiaDao AccountTopiaDao = getDaoHelper().getAccountDao(); - List<Account> accountsList = AccountTopiaDao.findAllSubAccounts(account); + AccountTopiaDao accountDao = getDaoHelper().getAccountDao(); + List<Account> accountsList = accountDao.findAllSubAccounts(account); return accountsList; } @@ -174,9 +174,9 @@ accountingRules.removeAccountRules(account); // remove account - AccountTopiaDao AccountTopiaDao = getDaoHelper().getAccountDao(); - Account accountToDelete = AccountTopiaDao.findByTopiaId(account.getTopiaId()); - AccountTopiaDao.delete(accountToDelete); + AccountTopiaDao accountDao = getDaoHelper().getAccountDao(); + Account accountToDelete = accountDao.findByTopiaId(account.getTopiaId()); + accountDao.delete(accountToDelete); } /** @@ -194,9 +194,9 @@ AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); // DAO - AccountTopiaDao AccountTopiaDao = getDaoHelper().getAccountDao(); + AccountTopiaDao accountDao = getDaoHelper().getAccountDao(); accountingRules.updateAccountRules(account); - Account result = AccountTopiaDao.update(account); + Account result = accountDao.update(account); return result; } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2014-07-23 13:46:03 UTC (rev 3857) @@ -69,30 +69,35 @@ // creation du EntryBook result = entryBookTopiaDao.create(entryBook); - //create ClosedPeriodicEntryBook for all unblocked financial period - ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookTopiaDao = - getDaoHelper().getClosedPeriodicEntryBookDao(); - FinancialPeriodTopiaDao financialPeriodTopiaDao = - getDaoHelper().getFinancialPeriodDao(); - // for all unblocked financialperiod - List<FinancialPeriod> financialPeriods = financialPeriodTopiaDao.forProperties(FinancialPeriod.PROPERTY_LOCKED, true).findAll(); - for (FinancialPeriod financialPeriod : financialPeriods) { - - //new closed periodic entrybook - ClosedPeriodicEntryBook closedPeriodicEntryBook = - new ClosedPeriodicEntryBookImpl(); - // set entrybook - closedPeriodicEntryBook.setEntryBook(entryBook); - // set financial period - closedPeriodicEntryBook.setFinancialPeriod(financialPeriod); - // create it - closedPeriodicEntryBookTopiaDao.create(closedPeriodicEntryBook); - } + createClosedPeriodicEntryBook(result); } return result; } @Override + public void createClosedPeriodicEntryBook(EntryBook entryBook) { + //create ClosedPeriodicEntryBook for all unblocked financial period + ClosedPeriodicEntryBookTopiaDao closedPeriodicEntryBookTopiaDao = + getDaoHelper().getClosedPeriodicEntryBookDao(); + FinancialPeriodTopiaDao financialPeriodTopiaDao = + getDaoHelper().getFinancialPeriodDao(); + // for all unblocked financialperiod + List<FinancialPeriod> financialPeriods = financialPeriodTopiaDao.forProperties(FinancialPeriod.PROPERTY_LOCKED, true).findAll(); + for (FinancialPeriod financialPeriod : financialPeriods) { + + //new closed periodic entrybook + ClosedPeriodicEntryBook closedPeriodicEntryBook = + new ClosedPeriodicEntryBookImpl(); + // set entrybook + closedPeriodicEntryBook.setEntryBook(entryBook); + // set financial period + closedPeriodicEntryBook.setFinancialPeriod(financialPeriod); + // create it + closedPeriodicEntryBookTopiaDao.create(closedPeriodicEntryBook); + } + } + + @Override public List<EntryBook> getAllEntryBooks() { // check if entrybook with is name already exist Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2014-07-23 13:46:03 UTC (rev 3857) @@ -155,6 +155,47 @@ return result; } + @Override + public void createFiscalPeriodsClosePeriodicEntryBooks(Collection<FiscalPeriod> fiscalPeriods) throws + BeginAfterEndFiscalPeriodException, NotBeginNextDayOfLastFiscalPeriodException, MoreOneUnlockFiscalPeriodException { + EntryBookTopiaDao entryBookTopiaDao = getDaoHelper().getEntryBookDao(); + AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); + + for (FiscalPeriod fiscalPeriod : fiscalPeriods) { + createFiscalPeriodClosePeriodicEntryBooks(fiscalPeriod, accountingRules, entryBookTopiaDao); + } + } + + protected void createFiscalPeriodClosePeriodicEntryBooks(FiscalPeriod fiscalPeriod, AccountingRules accountingRules, EntryBookTopiaDao entryBookTopiaDao) throws + BeginAfterEndFiscalPeriodException, NotBeginNextDayOfLastFiscalPeriodException, MoreOneUnlockFiscalPeriodException { + + List<FinancialPeriod> financialPeriods; + + financialPeriods = accountingRules.createFiscalPeriodRules(fiscalPeriod); + + // create + fiscalPeriod.addAllFinancialPeriod(financialPeriods); + + //create all financial period + for (FinancialPeriod financialPeriod : financialPeriods) { + + List<ClosedPeriodicEntryBook> closedPeriodicEntryBooks = Lists.newArrayList(); + //create ClosedPeriodicEntryBook for all entrybook + for (EntryBook entryBook : entryBookTopiaDao.findAll()) { + //new closed periodic entrybook + ClosedPeriodicEntryBook closedPeriodicEntryBook = new ClosedPeriodicEntryBookImpl(); + // set entrybook + closedPeriodicEntryBook.setEntryBook(entryBook); + // set financial period + closedPeriodicEntryBook.setFinancialPeriod(financialPeriod); + + closedPeriodicEntryBooks.add(closedPeriodicEntryBook); + } + financialPeriod.addAllEntryBookClosedPeriodicEntryBook(closedPeriodicEntryBooks); + + } + } + /** * return all fiscal period. */ Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-07-23 13:46:03 UTC (rev 3857) @@ -277,7 +277,7 @@ // if account not exist not export -> exception else if (account == null) { - //// TODO DCossé 28/05/14 this message is not displayed on user's error window. + // TODO DCossé 28/05/14 this message is not displayed on user's error window. throw new ImportEbpException(t( "lima-business.import.ebpmissingaccount", entryEBP.getCompte())); @@ -335,8 +335,8 @@ // create transaction if (financialTransaction == null || !(dateEcr.equals(financialTransaction - .getTransactionDate()) && entryBook - .getCode().equals( + .getTransactionDate()) && entryBook + .getCode().equals( financialTransaction.getEntryBook() .getCode()))) { // create financial transaction @@ -349,6 +349,7 @@ "lima-business.import.transactionadded", dateEcr, entryBook.getCode())); } + financialTransaction.getEntry().add(entry); // Inside the db, the entries reference the financialTransaction entry.setFinancialTransaction(financialTransaction); entry = financialTransactionService.createEntry(entry); @@ -369,6 +370,7 @@ } } + if (log.isInfoEnabled()) { long after = System.currentTimeMillis(); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java 2014-07-23 13:46:03 UTC (rev 3857) @@ -145,10 +145,6 @@ File file = exportAccountsFile(charset); FileInputStream inputStream = new FileInputStream(file); result = IOUtils.toString(inputStream); - } catch (FileNotFoundException e) { - throw new LimaTechnicalException(e); - } catch (IOException e) { - throw new LimaTechnicalException(e); } catch (Exception e) { throw new LimaTechnicalException(e); } @@ -175,10 +171,6 @@ File file = exportEntryBooksFile(charset); FileInputStream inputStream = new FileInputStream(file); result = IOUtils.toString(inputStream); - } catch (FileNotFoundException e) { - throw new LimaTechnicalException(e); - } catch (IOException e) { - throw new LimaTechnicalException(e); } catch (Exception e) { throw new LimaTechnicalException(e); } @@ -205,10 +197,6 @@ File file = exportFiscalPeriodFile(charset); FileInputStream inputStream = new FileInputStream(file); result = IOUtils.toString(inputStream); - } catch (FileNotFoundException e) { - throw new LimaTechnicalException(e); - } catch (IOException e) { - throw new LimaTechnicalException(e); } catch (Exception e) { throw new LimaTechnicalException(e); } @@ -237,10 +225,6 @@ File file = exportFinancialTransactionsFile(charset); FileInputStream inputStream = new FileInputStream(file); result = IOUtils.toString(inputStream); - } catch (FileNotFoundException e) { - throw new LimaTechnicalException(e); - } catch (IOException e) { - throw new LimaTechnicalException(e); } catch (Exception e) { throw new LimaTechnicalException(e); } @@ -265,10 +249,6 @@ File file = exportEntriesFile(charset); FileInputStream inputStream = new FileInputStream(file); result = IOUtils.toString(inputStream); - } catch (FileNotFoundException e) { - throw new LimaTechnicalException(e); - } catch (IOException e) { - throw new LimaTechnicalException(e); } catch (Exception e) { throw new LimaTechnicalException(e); } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java 2014-07-23 13:46:03 UTC (rev 3857) @@ -23,15 +23,16 @@ */ import com.google.common.base.Function; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.IOUtils; -import org.chorem.lima.LimaTechnicalException; +import org.chorem.lima.business.BeginAfterEndFiscalPeriodException; +import org.chorem.lima.business.MoreOneUnlockFiscalPeriodException; +import org.chorem.lima.business.NotBeginNextDayOfLastFiscalPeriodException; 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.FinancialTransactionService; +import org.chorem.lima.business.api.FiscalPeriodService; import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.business.ejb.csv.AccountModel; import org.chorem.lima.business.ejb.csv.EntryBookModel; @@ -43,6 +44,7 @@ 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.FinancialTransaction; import org.chorem.lima.entity.FinancialTransactionTopiaDao; import org.chorem.lima.entity.FiscalPeriod; @@ -55,17 +57,11 @@ import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; -import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; import java.io.InputStream; -import java.util.Collection; import java.util.List; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; +import static org.nuiton.i18n.I18n.t; + /** * Created by davidcosse on 03/06/14. */ @@ -81,8 +77,14 @@ private AccountService accountService; @EJB + private EntryService entryService; + + @EJB private FinancialTransactionService financialTransactionService; + @EJB + private FiscalPeriodService fiscalPeriodService; + @Override public void importAccountAsCSV(String contents) { InputStream contentStream = IOUtils.toInputStream(contents); @@ -116,23 +118,40 @@ EntryBookTopiaDao dao = getDaoHelper().getEntryBookDao(); Import<EntryBook> result = Import.newImport(model, contentStream); dao.createAll(result); + + for (EntryBook entryBook : result) { + entryBookService.createClosedPeriodicEntryBook(entryBook); + } } finally { IOUtils.closeQuietly(contentStream); } } @Override - public void importFiscalPeriodsAsCSV(String contents) { + public String importFiscalPeriodsAsCSV(String contents) { + StringBuilder result = new StringBuilder(); InputStream contentStream = IOUtils.toInputStream(contents); try { ImportModel<FiscalPeriod> model = new FiscalPeriodModel(); FiscalPeriodTopiaDao dao = getDaoHelper().getFiscalPeriodDao(); - Import<FiscalPeriod> result = Import.newImport(model, contentStream); - dao.createAll(result); + Import<FiscalPeriod> importedFPs = Import.newImport(model, contentStream); + List<FiscalPeriod> fiscalPeriods = Lists.newArrayList(importedFPs); + try { + fiscalPeriodService.createFiscalPeriodsClosePeriodicEntryBooks(fiscalPeriods); + result.append(t("lima-business.import.fiscalperiodscloseperiodicentrybooks")); + } catch (BeginAfterEndFiscalPeriodException e) { + result.append("Can't import " + t("lima-business.import.FiscalPeriod.error.beginAfterEndFiscalPeriod")); + } catch (MoreOneUnlockFiscalPeriodException e) { + result.append("Can't import " + t("lima-business.import.FiscalPeriod.error.moreOneUnlockFiscalPeriod")); + } catch (NotBeginNextDayOfLastFiscalPeriodException e) { + result.append("Can't import " + t("lima-business.import.FiscalPeriod.error.notBeginNextDayOfLastFiscalPeriod")); + } + dao.createAll(fiscalPeriods); } finally { IOUtils.closeQuietly(contentStream); } + return result.toString(); } @Override @@ -162,104 +181,23 @@ // import and save entries InputStream contentStream = IOUtils.toInputStream(contents); try { - FinancialTransactionTopiaDao financialTransactionTopiaDao = getDaoHelper().getFinancialTransactionDao(); - ImportModel<Entry> model = new EntryModel(accountService, financialTransactionService); Import<Entry> result = Import.newImport(model, contentStream); - Collection<FinancialTransaction> financialTransactions = financialTransactionTopiaDao.findAll(); - ImmutableMap<String, FinancialTransaction> indexedFinancialTransactions = Maps.uniqueIndex(financialTransactions, GET_TOPIA_ID); + EntryTopiaDao dao = getDaoHelper().getEntryDao(); + dao.createAll(result); - for (Entry entry : result) { - FinancialTransaction financialTransaction = entry.getFinancialTransaction(); - financialTransaction = indexedFinancialTransactions.get(financialTransaction.getTopiaId()); - Collection<Entry> fEntries = financialTransaction.getEntry(); - if(fEntries == null) { - fEntries = Lists.newArrayList(); - financialTransaction.setEntry(fEntries); - } - fEntries.add(entry); - } - - financialTransactionTopiaDao.updateAll(indexedFinancialTransactions.values()); - } finally { IOUtils.closeQuietly(contentStream); } } @Override - public void importAllAsCSV(String zippedBase64Str) { - ZipInputStream zipInputStream = null; - - InputStream transactionsStream = null, entryBooksStream = null, fiscalPeriodsStream = null, entriesStream = null, accountsStream = null; - try { - //contentStream = new FileInputStream(path); - byte[] bytes = Base64.decodeBase64(zippedBase64Str); - zipInputStream = new ZipInputStream(new ByteArrayInputStream(bytes)); - - // unzip - ZipEntry entry; - String tmpDir = System.getProperty("java.io.tmpdir")+"/"; - 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"); - } - int n; - - if (fileoutputstream != null) { - while ((n = zipInputStream.read(buffer, 0, 2048)) > -1) { - fileoutputstream.write(buffer, 0, n); - } - fileoutputstream.close(); - } - - zipInputStream.closeEntry(); - } - - entryBooksStream = new FileInputStream(tmpDir + "entryBooks.csv"); - String entryBooksStreamString = IOUtils.toString(entryBooksStream); - importEntryBooksAsCSV(entryBooksStreamString); - - // import - transactionsStream = new FileInputStream(tmpDir + "financialTransactions.csv"); - String transactionsStreamString = IOUtils.toString(transactionsStream); - importFinancialTransactionsAsCSV(transactionsStreamString); - - fiscalPeriodsStream = new FileInputStream(tmpDir + "fiscalPeriods.csv"); - String fiscalPeriodsStreamString = IOUtils.toString(fiscalPeriodsStream); - importFiscalPeriodsAsCSV(fiscalPeriodsStreamString); - - entriesStream = new FileInputStream(tmpDir + "entries.csv"); - String entriesStreamString = IOUtils.toString(entriesStream); - importEntriesAsCSV(entriesStreamString); - - accountsStream = new FileInputStream(tmpDir + "accounts.csv"); - String accountsStreamString = IOUtils.toString(accountsStream); - importAccountAsCSV(accountsStreamString); - - } catch (FileNotFoundException e) { - throw new LimaTechnicalException(e); - } catch (IOException e) { - throw new LimaTechnicalException(e); - } finally { - IOUtils.closeQuietly(zipInputStream); - IOUtils.closeQuietly(transactionsStream); - IOUtils.closeQuietly(entryBooksStream); - IOUtils.closeQuietly(fiscalPeriodsStream); - IOUtils.closeQuietly(entriesStream); - IOUtils.closeQuietly(accountsStream); - } + public void importAllAsCSV(String entryBooks, String financialTransactions, String fiscalPeriods, String entries, String accounts){ + importEntryBooksAsCSV(entryBooks); + importFinancialTransactionsAsCSV(financialTransactions); + importFiscalPeriodsAsCSV(fiscalPeriods); + importEntriesAsCSV(entries); + importAccountAsCSV(accounts); } } Modified: trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties =================================================================== --- trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties 2014-07-23 13:46:03 UTC (rev 3857) @@ -114,6 +114,7 @@ lima-business.import.financialstatementalreadyexist=FAILED \: The financial statement %s already exists \!\n lima-business.import.fiscalperiodadded=SUCCESS \: The fiscalPeriod %s - %s is created \! \n lima-business.import.fiscalperiodalreadyexist=FAILED \: The fiscal period %s - %s already exists \!\n +lima-business.import.fiscalperiodscloseperiodicentrybooks= lima-business.import.identityadded=SUCCESS \: The identity %s is created \! \n lima-business.import.lineformatmismatch=Line format is invalid. lima-business.import.noaccount=ERROR \: This file contains no account Modified: trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties =================================================================== --- trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties 2014-07-23 13:46:03 UTC (rev 3857) @@ -112,6 +112,7 @@ lima-business.import.financialstatementalreadyexist=u00C9chec \: Le mouvement %s exist déjà \!\n lima-business.import.fiscalperiodadded=Succès \: Exercice %s - %s ajoutée \! \n lima-business.import.fiscalperiodalreadyexist=u00C9chec \: L'exerice %s - %s existe déjà \!\n +lima-business.import.fiscalperiodscloseperiodicentrybooks= lima-business.import.identityadded=Succès \: Identité %s ajoutée \! \n lima-business.import.lineformatmismatch=Le format de la ligne est incorrect. lima-business.import.noaccount=Erreur \: Ce fichier ne contient aucun compte. Modified: trunk/lima-business/src/main/resources/lima.properties =================================================================== --- trunk/lima-business/src/main/resources/lima.properties 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-business/src/main/resources/lima.properties 2014-07-23 13:46:03 UTC (rev 3857) @@ -28,3 +28,4 @@ hibernate.connection.password= hibernate.connection.driver_class=org.h2.Driver hibernate.connection.url=jdbc:h2:file:${lima.data.dir}/limadb +hibernate.jdbc.batch_size=50 \ No newline at end of file Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2014-07-23 13:46:03 UTC (rev 3857) @@ -109,7 +109,7 @@ @Before public void initAbstractTest() throws Exception { setUpLocale(); - +// LimaInterceptor.schemaExistChecked = false; Properties options = getTestConfiguration(); LimaConfig config = new LimaTestsConfig("/lima-test.properties", options); initServices(config); Deleted: trunk/lima-business/src/test/java/org/chorem/lima/business/NewExportServiceTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/NewExportServiceTest.java 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/NewExportServiceTest.java 2014-07-23 13:46:03 UTC (rev 3857) @@ -1,250 +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.entity.Account; -import org.chorem.lima.entity.Entry; -import org.chorem.lima.entity.EntryBook; -import org.chorem.lima.entity.FinancialTransaction; -import org.chorem.lima.entity.FiscalPeriod; -import org.junit.Assert; -import org.junit.Test; - -import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.nio.charset.Charset; -import java.util.List; - -/** - * Created by davidcosse on 03/06/14. - */ -public class NewExportServiceTest 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.exportAccountsStream(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); - newImportService.importAccountAsCSV(inportStream); - - // make sure all account have been created - Assert.assertEquals(nbEntities, accountService.getAllAccounts().size()); - } finally { - IOUtils.closeQuietly(contentStream); - } - } - - @Test - public void testExportImportEntryBooks() throws Exception { - initTestWithEntryBooks(); - - String tmpDir = System.getProperty("java.io.tmpdir")+"/"; - String export = newExportService.exportEntryBooksStream(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; - try { - contentStream = new FileInputStream(tmpDir + "export-EntryBooks.csv"); - String inportStream = IOUtils.toString(contentStream); - newImportService.importEntryBooksAsCSV(inportStream); - } finally { - IOUtils.closeQuietly(contentStream); - } - - Assert.assertEquals(nbEntities, entryBookService.getAllEntryBooks().size()); - } - - @Test - public void testExportImportFinancialTransactions() throws Exception { - initTestWithFinancialTransaction(); - - String tmpDir = System.getProperty("java.io.tmpdir")+"/"; - String export = newExportService.exportFinancialTransactionsAsStream(Charset.defaultCharset().name()); - InputStream stream = IOUtils.toInputStream(export); - FileOutputStream res = new FileOutputStream(tmpDir + "export-financial-transactions.csv"); - IOUtils.copy(stream, res); - - List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("January 1, 2012"),df.parse("December 31, 2012")); - int nbEntities = financialTransactions.size(); - Assert.assertEquals(1, nbEntities); - - for (FinancialTransaction financialTransaction : financialTransactions) { - financialTransactionService.removeFinancialTransaction(financialTransaction); - } - - Assert.assertEquals(0, financialTransactionService.getAllFinancialTransactions(df.parse("January 1, 2012"), df.parse("December 31, 2012")).size()); - - FileInputStream contentStream = null; - try { - contentStream = new FileInputStream(tmpDir + "export-financial-transactions.csv"); - String inportStream = IOUtils.toString(contentStream); - newImportService.importFinancialTransactionsAsCSV(inportStream); - } finally { - IOUtils.closeQuietly(contentStream); - } - - Assert.assertEquals(nbEntities, financialTransactionService.getAllFinancialTransactions(df.parse("January 1, 2012"),df.parse("December 31, 2012")).size()); - } - - @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()); - 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); - } - - // check 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; - try { - contentStream = new FileInputStream(tmpDir + "export-entries.csv"); - String inputStream = IOUtils.toString(contentStream); - 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()); - } - - @Test - public void testExportImportFiscalPeriodsAsCSV() throws Exception { - initTestWithFiscalPeriod(); - - String tmpDir = System.getProperty("java.io.tmpdir")+"/"; - String export = newExportService.exportFiscalPeriodsStream(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 nbEntities = fiscalPeriods.size(); - Assert.assertEquals(1, nbEntities); - - initAbstractTest(); - - Assert.assertEquals(0, fiscalPeriodService.getAllFiscalPeriods().size()); - - FileInputStream contentStream = null; - try { - contentStream = new FileInputStream(tmpDir + "export-fiscal-periods.csv"); - String inputStream = IOUtils.toString(contentStream); - newImportService.importFiscalPeriodsAsCSV(inputStream); - } finally { - IOUtils.closeQuietly(contentStream); - } - - Assert.assertEquals(nbEntities, fiscalPeriodService.getAllFiscalPeriods().size()); - } - - @Test - public void exportAllAsCSVTest() throws Exception { - initTestWithFinancialTransaction(); - String export = newExportService.exportAllAsCSV("UTF-8"); - initAbstractTest(); - String tmpDir = System.getProperty("java.io.tmpdir")+"/TMP_BACKUP.zip"; - createZipFile(tmpDir, export); - newImportService.importAllAsCSV(export); - } - - 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)); - } - - -} Copied: trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java (from rev 3833, trunk/lima-business/src/test/java/org/chorem/lima/business/NewExportServiceTest.java) =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java (rev 0) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/NewImportExportServiceTest.java 2014-07-23 13:46:03 UTC (rev 3857) @@ -0,0 +1,337 @@ +package org.chorem.lima.business; + +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.Entry; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.entity.FiscalPeriod; +import org.junit.Assert; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.Charset; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; + +/** + * 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.exportAccountsStream(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); + newImportService.importAccountAsCSV(inportStream); + + // make sure all account have been created + Assert.assertEquals(nbEntities, accountService.getAllAccounts().size()); + } finally { + IOUtils.closeQuietly(contentStream); + } + } + + @Test + public void testExportImportEntryBooks() throws Exception { + initTestWithEntryBooks(); + + String tmpDir = System.getProperty("java.io.tmpdir")+"/"; + String export = newExportService.exportEntryBooksStream(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; + try { + contentStream = new FileInputStream(tmpDir + "export-EntryBooks.csv"); + String inportStream = IOUtils.toString(contentStream); + newImportService.importEntryBooksAsCSV(inportStream); + } finally { + IOUtils.closeQuietly(contentStream); + } + + Assert.assertEquals(nbEntities, entryBookService.getAllEntryBooks().size()); + } + + @Test + public void testExportImportFinancialTransactions() throws Exception { + initTestWithFinancialTransaction(); + + String tmpDir = System.getProperty("java.io.tmpdir")+"/"; + String export = newExportService.exportFinancialTransactionsAsStream(Charset.defaultCharset().name()); + InputStream stream = IOUtils.toInputStream(export); + FileOutputStream res = new FileOutputStream(tmpDir + "export-financial-transactions.csv"); + IOUtils.copy(stream, res); + + List<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("January 1, 2012"),df.parse("December 31, 2012")); + int nbEntities = financialTransactions.size(); + Assert.assertEquals(1, nbEntities); + + for (FinancialTransaction financialTransaction : financialTransactions) { + financialTransactionService.removeFinancialTransaction(financialTransaction); + } + + Assert.assertEquals(0, financialTransactionService.getAllFinancialTransactions(df.parse("January 1, 2012"), df.parse("December 31, 2012")).size()); + + FileInputStream contentStream = null; + try { + contentStream = new FileInputStream(tmpDir + "export-financial-transactions.csv"); + String inportStream = IOUtils.toString(contentStream); + newImportService.importFinancialTransactionsAsCSV(inportStream); + } finally { + IOUtils.closeQuietly(contentStream); + } + + Assert.assertEquals(nbEntities, financialTransactionService.getAllFinancialTransactions(df.parse("January 1, 2012"),df.parse("December 31, 2012")).size()); + } + + @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()); + 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; + try { + contentStream = new FileInputStream(tmpDir + "export-entries.csv"); + String inputStream = IOUtils.toString(contentStream); + 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()); + } + + @Test + public void testExportImportFiscalPeriodsAsCSV() throws Exception { + initTestWithFiscalPeriod(); + + String tmpDir = System.getProperty("java.io.tmpdir")+"/"; + String export = newExportService.exportFiscalPeriodsStream(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 nbEntities = fiscalPeriods.size(); + Assert.assertEquals(1, nbEntities); + + initAbstractTest(); + + Assert.assertEquals(0, fiscalPeriodService.getAllFiscalPeriods().size()); + + FileInputStream contentStream = null; + try { + contentStream = new FileInputStream(tmpDir + "export-fiscal-periods.csv"); + String inputStream = IOUtils.toString(contentStream); + // TODO DCossé 22/07/14 traiter les messages de retour + newImportService.importFiscalPeriodsAsCSV(inputStream); + } finally { + IOUtils.closeQuietly(contentStream); + } + + Assert.assertEquals(nbEntities, fiscalPeriodService.getAllFiscalPeriods().size()); + } + + @Test + public void exportImportAllAsCSVTest() throws Exception { + initTestWithFinancialTransaction(); + String export = newExportService.exportAllAsCSV("UTF-8"); + initAbstractTest(); + String tmpDir = System.getProperty("java.io.tmpdir")+"/TMP_BACKUP.zip"; + createZipFile(tmpDir, export); + + initAbstractTest(); + + FileInputStream contentStream = null; + try { + importAllFromZipFile(tmpDir); + } finally { + IOUtils.closeQuietly(contentStream); + } + } + + 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 String 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"); + } + 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; + 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); + + // TODO DCossé 23/07/14 should be done in one transaction on service side but it doesn't work now + newImportService.importAllAsCSV(entryBooksStreamString, transactionsStreamString, fiscalPeriodsStreamString, entriesStreamString, accountsStreamString); +// newImportService.importEntryBooksAsCSV(entryBooksStreamString); +// if(log.isInfoEnabled()) { +// log.info("jouranux importés"); +// } +// newImportService.importFinancialTransactionsAsCSV(transactionsStreamString); +// if(log.isInfoEnabled()) { +// log.info("transactions importés"); +// } +// newImportService.importFiscalPeriodsAsCSV(fiscalPeriodsStreamString); +// if(log.isInfoEnabled()) { +// log.info("période ficales importés"); +// } +// newImportService.importEntriesAsCSV(entriesStreamString); +// if(log.isInfoEnabled()) { +// log.info("entrées importés"); +// } +// newImportService.importAccountAsCSV(accountsStreamString); +// if(log.isInfoEnabled()) { +// log.info("comptes importés"); +// } + } catch (Exception ex) { + if(log.isInfoEnabled()) { + log.info(ex); + } + throw new LimaTechnicalException("could not import files", ex); + } + return "SUCCES"; + } +} Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/AccountService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/AccountService.java 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/AccountService.java 2014-07-23 13:46:03 UTC (rev 3857) @@ -100,4 +100,5 @@ void removeAccount(Account account) throws UsedAccountException; List<Account> stringToListAccounts(String selectedAccounts); + } Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/EntryBookService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/EntryBookService.java 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/EntryBookService.java 2014-07-23 13:46:03 UTC (rev 3857) @@ -85,4 +85,6 @@ * @throws org.chorem.lima.business.UsedEntryBookException */ void removeEntryBook(EntryBook entryBook) throws UsedEntryBookException; + + void createClosedPeriodicEntryBook(EntryBook entryBook); } Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodService.java 2014-07-23 13:46:03 UTC (rev 3857) @@ -39,6 +39,7 @@ import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FiscalPeriod; +import java.util.Collection; import java.util.List; /** @@ -96,4 +97,9 @@ boolean isRetainedEarnings(FiscalPeriod fiscalPeriod); FiscalPeriod updateEndDate(FiscalPeriod fiscalPeriod); + + void createFiscalPeriodsClosePeriodicEntryBooks(Collection<FiscalPeriod> fiscalPeriods) throws + BeginAfterEndFiscalPeriodException, + NotBeginNextDayOfLastFiscalPeriodException, + MoreOneUnlockFiscalPeriodException; } Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java 2014-07-23 13:46:03 UTC (rev 3857) @@ -31,11 +31,11 @@ void importEntryBooksAsCSV(String contents); - void importFiscalPeriodsAsCSV(String contents); + String importFiscalPeriodsAsCSV(String contents); void importFinancialTransactionsAsCSV(String contents); void importEntriesAsCSV(String contents); - void importAllAsCSV(String zippedBase64Str); + void importAllAsCSV(String entryBooks, String transactions, String fiscalPeriods, String entries, String accounts); } Modified: trunk/lima-callao/src/main/xmi/accounting-model.zargo =================================================================== (Binary files differ) Modified: trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java 2014-07-23 13:46:03 UTC (rev 3857) @@ -30,7 +30,7 @@ * second one to allow or not choce for encoding * */ public enum ImportExportEnum { - CSV_ALL_EXPORT(false, true), CSV_ALL_IMPORT(true, true), + CSV_ALL_EXPORT(false, false), CSV_ALL_IMPORT(true, true), CSV_ACCOUNTCHARTS_EXPORT(false, true), CSV_ACCOUNTCHARTS_IMPORT(true, true), CSV_ENTRYBOOKS_EXPORT(false, true), CSV_ENTRYBOOKS_IMPORT(true, true), CSV_FINANCIALSTATEMENTS_EXPORT(false, true), CSV_FINANCIALSTATEMENTS_IMPORT(true, true), Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx 2014-07-23 13:46:03 UTC (rev 3857) @@ -45,18 +45,18 @@ <JToolBar floatable="false"> <JButton id="addButton" - toolTipText="{ t("lima.ui.account.addaccount") + " (Ctrl+N)"}" + toolTipText="{ "lima.ui.account.addaccount" + " (Ctrl+N)"}" actionIcon='account-new' onActionPerformed="handler.addAccount()"/> <JButton id="updateButton" - toolTipText="{ t("lima.ui.common.update") + " (Ctrl+M)"}" + toolTipText="{ "lima.ui.common.update" + " (Ctrl+M)"}" actionIcon='account-edit' onActionPerformed="handler.updateAccount()" enabled="{isSelectedRow()}"/> <JButton id="removeButton" - toolTipText="{ t("lima.ui.common.remove") + " (Del)"}" + toolTipText="{ "lima.ui.common.remove" + " (Del)"}" actionIcon='account-remove' onActionPerformed="handler.removeAccount()" enabled="{isSelectedRow()}"/> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookView.jaxx 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookView.jaxx 2014-07-23 13:46:03 UTC (rev 3857) @@ -45,18 +45,18 @@ <JToolBar floatable="false"> <JButton id="addButton" - toolTipText="{ t("lima.ui.entrybook.add") + " (Ctrl+N)"}" + toolTipText="{ "lima.ui.entrybook.add" + " (Ctrl+N)"}" actionIcon='entryBook-new' onActionPerformed="handler.addEntryBook()"/> <JButton id="updateButton" - toolTipText="{ t("lima.ui.entrybook.update") + " (Ctrl+M)"}" + toolTipText="{ "lima.ui.entrybook.update" + " (Ctrl+M)"}" actionIcon='entryBook-edit' onActionPerformed="handler.updateEntryBook()" enabled="{isSelectedRow()}"/> <JButton id="removeButton" - toolTipText="{ t("lima.ui.entrybook.remove") + " (Del)"}" + toolTipText="{ "lima.ui.entrybook.remove" + " (Del)"}" actionIcon='entryBook-remove' onActionPerformed="handler.deleteEntryBook()" enabled="{isSelectedRow()}"/> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodView.jaxx 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodView.jaxx 2014-07-23 13:46:03 UTC (rev 3857) @@ -30,7 +30,6 @@ org.chorem.lima.entity.FinancialPeriod org.chorem.lima.ui.financialperiod.FinancialPeriodTable org.chorem.lima.ui.financialperiod.FinancialPeriodTableModel - static org.nuiton.i18n.I18n.t </import> <FinancialPeriodViewHandler id="handler" constructorParams="this"/> @@ -47,7 +46,7 @@ <JToolBar floatable="false"> <JButton id="blockButton" - toolTipText="{ t("lima.ui.financialperiod.block") + " (Ctrl+C)"}" + toolTipText="{ "lima.ui.financialperiod.block" + " (Ctrl+C)"}" actionIcon='financialPeriod-close' onActionPerformed="handler.blockFinancialPeriod()" enabled="{isSelectedPeriod()}"/> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartView.jaxx 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartView.jaxx 2014-07-23 13:46:03 UTC (rev 3857) @@ -28,7 +28,6 @@ <import> javax.swing.ListSelectionModel org.jdesktop.swingx.decorator.HighlighterFactory - static org.nuiton.i18n.I18n.t </import> <FinancialStatementChartViewHandler id="handler" @@ -40,37 +39,37 @@ <JToolBar floatable="false"> <JButton id="addFinancialStatementHeader" - toolTipText="{ t("lima.financialstatement.header.add") + " (Ctrl+Maj+N)"}" + toolTipText="{ "lima.financialstatement.header.add" + " (Ctrl+Maj+N)"}" actionIcon='financialstatement-add-header' onActionPerformed="handler.addFinancialStatementHeader()"/> <JButton id="addFinancialStatementMovement" - toolTipText="{ t("lima.financialstatement.movement.add") + " (Ctrl+N)"}" + toolTipText="{ "lima.financialstatement.movement.add" + " (Ctrl+N)"}" actionIcon='financialstatement-add-movement' onActionPerformed="handler.addFinancialStatementMovement()" enabled="{isSelectedRow()}"/> <JButton id="updateButton" - toolTipText="{ t("lima.common.update") + " (Ctrl+M)"}" + toolTipText="{ "lima.common.update" + " (Ctrl+M)"}" actionIcon='financialstatement-edit' onActionPerformed="handler.updateFinancialStatement()" enabled="{isSelectedRow()}"/> <JButton id="removeButton" - toolTipText="{ t("lima.common.remove") + " (Del)"}" + toolTipText="{ "lima.common.remove" + " (Del)"}" actionIcon='financialstatement-remove' onActionPerformed="handler.removeFinancialStatement()" enabled="{isSelectedRow()}"/> <JButton id="importButton" - toolTipText="{ t("lima.ui.importexport.import") + " (Ctrl+I)"}" + toolTipText="{ "lima.ui.importexport.import" + " (Ctrl+I)"}" actionIcon='financialstatement-import' onActionPerformed="handler.importFinancialStatementChart()"/> <JToolBar.Separator/> <JButton id="checkButton" - toolTipText="{ t("lima.financialstatement.check") + " (Ctrl+F)"}" + toolTipText="{ "lima.financialstatement.check" + " (Ctrl+F)"}" actionIcon='financialstatement-check' onActionPerformed="handler.financialStatementChartCheck()"/> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx 2014-07-23 13:46:03 UTC (rev 3857) @@ -39,11 +39,11 @@ <FinancialTransactionViewHandler id="handler" constructorParams="this"/> <ListSelectionModel - id='selectionModel' - initializer="new DefaultListSelectionModel()" - selectionMode='{ListSelectionModel.SINGLE_SELECTION}' - onValueChanged="handler.selectionChanged()"/> - + id='selectionModel' + initializer="new DefaultListSelectionModel()" + selectionMode='{ListSelectionModel.SINGLE_SELECTION}' + onValueChanged="handler.selectionChanged()"/> + <Boolean id="selectedRow" javaBean="false"/> <Boolean id="transactionInClipBoard" javaBean="false"/> @@ -61,39 +61,39 @@ <row> <cell fill="horizontal"> <JToolBar floatable="false"> - <JButton toolTipText="{ t("lima.entries.addTransaction") + " (Ctrl+Shift+N)"}" + <JButton toolTipText="{ "lima.entries.addTransaction" + " (Ctrl+Shift+N)"}" actionIcon='add-financial-transaction' onActionPerformed="handler.addFinancialTransaction()" /> - <JButton toolTipText="{ t("lima.entries.remove.transaction") + " (Ctrl+Shift+Del)"}" + <JButton toolTipText="{ "lima.entries.remove.transaction" + " (Ctrl+Shift+Del)"}" actionIcon='delete-financial-transaction' enabled="{isSelectedRow()}" onActionPerformed="handler.deleteSelectedTransaction()" /> - <JButton toolTipText="{ t("lima.entries.copy.transaction") + " (Ctrl+Shift+C)"}" actionIcon='copy' + <JButton toolTipText="{ "lima.entries.copy.transaction" + " (Ctrl+Shift+C)"}" actionIcon='copy' enabled="{isSelectedRow()}" onActionPerformed="handler.copyTransaction()" /> - <JButton toolTipText="{ t("lima.entries.paste.transaction") + " (Ctrl+Shift+V)"}" actionIcon='paste' + <JButton toolTipText="{ "lima.entries.paste.transaction" + " (Ctrl+Shift+V)"}" actionIcon='paste' enabled="{isTransactionInClipBoard()}" onActionPerformed="handler.pasteTransaction()" /> <JToolBar.Separator/> - <JButton toolTipText ="{ t("lima.entries.addEntry") + " (Ctrl+N)"}" actionIcon='add-entry' + <JButton toolTipText ="{ "lima.entries.addEntry" + " (Ctrl+N)"}" actionIcon='add-entry' enabled="{isSelectedRow()}" onActionPerformed="handler.addEntry()" /> - <JButton toolTipText="{ t("lima.entries.remove.entry") + " (Ctrl+Del)"}" actionIcon='delete-entry' + <JButton toolTipText="{ "lima.entries.remove.entry" + " (Ctrl+Del)"}" actionIcon='delete-entry' enabled="{isSelectedRow()}" onActionPerformed="handler.deleteSelectedEntry()" /> - <JButton toolTipText="{ t("lima.entries.copy.entry") + " (Ctrl+Alt+C)"}" actionIcon='copy' + <JButton toolTipText="{ "lima.entries.copy.entry" + " (Ctrl+Alt+C)"}" actionIcon='copy' enabled="{isSelectedRow()}" onActionPerformed="handler.copyEntry()" /> - <JButton toolTipText="{ t("lima.entries.paste.entry") + " (Ctrl+Alt+V)"}" actionIcon='paste' + <JButton toolTipText="{ "lima.entries.paste.entry" + " (Ctrl+Alt+V)"}" actionIcon='paste' enabled="{isEntryInClipBoard() && isSelectedRow()}" onActionPerformed="handler.pasteEntry()" /> - <JButton toolTipText="{ t("lima.entries.assign.entries") + " (Ctrl+Alt+A)"}" actionIcon='assign-all-entries-in-transaction' + <JButton toolTipText="{ "lima.entries.assign.entries" + " (Ctrl+Alt+A)"}" actionIcon='assign-all-entries-in-transaction' enabled="{isAssignableInAllEntries() && isSelectedRow()}" onActionPerformed="handler.assignAllEntries()" /> <JToolBar.Separator/> - <JButton toolTipText="{ t("lima.entries.balance") + " (Ctrl+B)"}" actionIcon='balance' + <JButton toolTipText="{ "lima.entries.balance" + " (Ctrl+B)"}" actionIcon='balance' enabled="{!isBalance()}" onActionPerformed="handler.balanceTransaction()" /> @@ -139,10 +139,10 @@ <JScrollPane> <FinancialTransactionTableModel id="financialTransactionTableModel"/> <FinancialTransactionTable - id="financialTransactionTable" rowHeight="22" - constructorParams='handler' - selectionModel='{selectionModel}' - model='{financialTransactionTableModel}'/> + id="financialTransactionTable" rowHeight="22" + constructorParams='handler' + selectionModel='{selectionModel}' + model='{financialTransactionTableModel}'/> </JScrollPane> </cell> </row> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedView.jaxx 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedView.jaxx 2014-07-23 13:46:03 UTC (rev 3857) @@ -53,18 +53,18 @@ <row> <cell fill="horizontal"> <JToolBar floatable="false"> - <JButton toolTipText="{ t("lima.entries.remove.transaction") + " (Ctrl+Shift+Del)"}" + <JButton toolTipText="{ "lima.entries.remove.transaction" + " (Ctrl+Shift+Del)"}" actionIcon='delete-financial-transaction' enabled="{isSelectedRow()}" onActionPerformed="getHandler().deleteSelectedTransaction()" /> - <JButton toolTipText ="{ t("lima.entries.addEntry") + " (Ctrl+N)"}" actionIcon='add-entry' + <JButton toolTipText ="{ "lima.entries.addEntry" + " (Ctrl+N)"}" actionIcon='add-entry' enabled="{isSelectedRow()}" onActionPerformed="getHandler().addEntry()" /> - <JButton toolTipText="{ t("lima.entries.remove.entry") + " (Ctrl+Del)"}" actionIcon='delete-entry' + <JButton toolTipText="{ "lima.entries.remove.entry" + " (Ctrl+Del)"}" actionIcon='delete-entry' enabled="{isSelectedRow()}" onActionPerformed="getHandler().deleteSelectedEntry()" /> <JToolBar.Separator/> - <JButton toolTipText="{ t("lima.entries.balance") + " (Ctrl+B)"}" actionIcon='balance' + <JButton toolTipText="{ "lima.entries.balance" + " (Ctrl+B)"}" actionIcon='balance' enabled="{!isBalance()}" onActionPerformed="handler.balanceTransaction()" /> <JToolBar.Separator/> @@ -79,7 +79,7 @@ getHandler().refresh()" editable="false"/> <JToolBar.Separator/> - <JButton toolTipText="{ t("lima.ui.common.refresh") + " (F5)"}" actionIcon='refresh' + <JButton toolTipText="{ "lima.ui.common.refresh" + " (F5)"}" actionIcon='refresh' onActionPerformed="getHandler().refresh()"/> </JToolBar> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx 2014-07-23 13:46:03 UTC (rev 3857) @@ -28,7 +28,6 @@ <import> javax.swing.ListSelectionModel javax.swing.DefaultListSelectionModel - static org.nuiton.i18n.I18n.t </import> <FiscalPeriodViewHandler id="handler" constructorParams="this"/> @@ -47,24 +46,24 @@ <JToolBar floatable="false"> <JButton id="addButton" - toolTipText="{ t("lima.charts.fiscalperiod.add") + " (Ctrl+N)"}" + toolTipText="{ "lima.charts.fiscalperiod.add" + " (Ctrl+N)"}" actionIcon='fiscalPeriod-new' onActionPerformed="handler.addFiscalPeriod()"/> <JButton id="updateButton" - toolTipText="{ t("lima.charts.fiscalperiod.update") + " (Ctrl+M)"}" + toolTipText="{ "lima.charts.fiscalperiod.update" + " (Ctrl+M)"}" actionIcon='fiscalPeriod-edit' onActionPerformed="handler.updateFiscalPeriod()" enabled="{isDeleteEnabled()}" /> <JButton id="blockButton" - toolTipText="{ t("lima.charts.fiscalperiod.block") + " (Ctrl+B)"}" + toolTipText="{ "lima.charts.fiscalperiod.block" + " (Ctrl+B)"}" actionIcon='fiscalPeriod-close' onActionPerformed="handler.blockFiscalPeriod()" enabled="{isBlockEnabled()}"/> <JButton id="deleteButton" - toolTipText="{ t("lima.charts.fiscalperiod.delete") + " (Del)"}" + toolTipText="{ "lima.charts.fiscalperiod.delete" + " (Del)"}" actionIcon='fiscalPeriod-remove' onActionPerformed="handler.deleteFiscalPeriod()" enabled="{isDeleteEnabled()}"/> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/HomeView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/HomeView.jaxx 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/home/HomeView.jaxx 2014-07-23 13:46:03 UTC (rev 3857) @@ -29,7 +29,6 @@ javax.swing.BoxLayout javax.swing.border.EtchedBorder jaxx.runtime.SwingUtil - static org.nuiton.i18n.I18n.t </import> <Dimension id="fixedSize" javaBean='new Dimension(500,200)'/> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-07-23 13:46:03 UTC (rev 3857) @@ -32,12 +32,12 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.LimaConfig; import org.chorem.lima.LimaTechnicalException; import org.chorem.lima.business.ImportEbpException; import org.chorem.lima.business.api.ExportService; import org.chorem.lima.business.api.ImportService; import org.chorem.lima.business.api.NewExportService; +import org.chorem.lima.business.api.NewImportService; import org.chorem.lima.business.utils.ImportExportEntityEnum; import org.chorem.lima.enums.EncodingEnum; import org.chorem.lima.enums.ImportExportEnum; @@ -64,14 +64,18 @@ import java.io.InputStream; import java.io.OutputStreamWriter; import java.nio.charset.Charset; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.concurrent.ExecutionException; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; import static org.nuiton.i18n.I18n.t; /** * Import export helper. * Calling service with specified file to import and displaying wait view to user. - * + * * @author echatellier * Date : 24 avr. 2012 */ @@ -89,8 +93,11 @@ protected ImportService importService; + @Deprecated protected ExportService exportService; + protected NewImportService newImportService; + protected NewExportService newExportService; private ImportExportWaitView waitView; @@ -103,8 +110,8 @@ //services importService = LimaServiceFactory.getService(ImportService.class); exportService = LimaServiceFactory.getService(ExportService.class); + newImportService = LimaServiceFactory.getService(NewImportService.class); newExportService = LimaServiceFactory.getService(NewExportService.class); - errorHelper = new ErrorHelper(LimaConfig.getInstance()); //create the wait dialog panel waitView = new ImportExportWaitView(); @@ -171,8 +178,7 @@ createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas); break; case CSV_ALL_IMPORT: - datas = extractFile(filePath, charset.name()); - result = importService.importAllAsCSV(datas); + result = importAllFromZipFile(filePath); break; case CSV_ACCOUNTCHARTS_IMPORT: datas = extractFile(filePath, charset.name()); @@ -236,13 +242,18 @@ //hidde wait dialog panel waitView.setVisible(false); + + if(log.isInfoEnabled()) { + log.info(get()); + } + // display result dialog if (verboseMode) { String result = get(); if (importMode && StringUtils.isBlank(result)) { JOptionPane.showMessageDialog(viewComponent, t("lima.ui.importexport.importerror"), t("lima.ui.importexport.importtitle"), JOptionPane.ERROR_MESSAGE); - + } else { if (importMode) { if (log.isDebugEnabled()) { @@ -281,14 +292,10 @@ } } } - } catch (InterruptedException ex) { + } catch (InterruptedException | ExecutionException ex) { if (log.isErrorEnabled()) { log.error("Can't get result message", ex); } - } catch (ExecutionException ex) { - if (log.isErrorEnabled()) { - log.error("Can't get result message", ex); - } } } }.execute(); @@ -312,36 +319,37 @@ JComboBox comboBox = new JComboBox(EncodingEnum.descriptions()); - if(importExportMethode.equals(ImportExportEnum.CSV_ALL_EXPORT)){ + if (importExportMethode.getEncodingOption()) { + JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + panel.add(new JLabel(t("lima.importexport.choiceencoding")), BorderLayout.WEST); + panel.add(comboBox, BorderLayout.CENTER); + ((Container) chooser.getComponent(2)).add(panel, BorderLayout.SOUTH); + } + String approveButtonText; + if (importMode) { + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + approveButtonText = t("lima.ui.importexport.import"); + chooser.setDialogTitle(approveButtonText); + chooser.setApproveButtonText(approveButtonText); + } else if (importExportMethode.equals(ImportExportEnum.CSV_ALL_EXPORT)) { + approveButtonText = t("lima.ui.importexport.export"); + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + chooser.setDialogTitle(approveButtonText); + chooser.setApproveButtonText(approveButtonText); } else { + approveButtonText = t("lima.ui.importexport.export"); + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + chooser.setDialogTitle(approveButtonText); + chooser.setApproveButtonText(approveButtonText); + } + if (chooser.showOpenDialog(viewComponent) == JFileChooser.APPROVE_OPTION) { + filePath = chooser.getSelectedFile().getAbsolutePath(); + if (importExportMethode.getEncodingOption()) { - JPanel panel = new JPanel(); - panel.setLayout(new BorderLayout()); - panel.add(new JLabel(t("lima.importexport.choiceencoding")), BorderLayout.WEST); - panel.add(comboBox, BorderLayout.CENTER); - ((Container) chooser.getComponent(2)).add(panel, BorderLayout.SOUTH); + encodingEnum = EncodingEnum.valueOfDescription((String) comboBox.getSelectedItem()); } - - String approveButtonText; - if (importMode) { - chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - approveButtonText = t("lima.ui.importexport.import"); - chooser.setDialogTitle(approveButtonText); - chooser.setApproveButtonText(approveButtonText); - } else { - approveButtonText = t("lima.ui.importexport.export"); - chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - chooser.setDialogTitle(approveButtonText); - chooser.setApproveButtonText(approveButtonText); - } - if (chooser.showOpenDialog(viewComponent) == JFileChooser.APPROVE_OPTION) { - filePath = chooser.getSelectedFile().getAbsolutePath(); - - if (importExportMethode.getEncodingOption()) { - encodingEnum = EncodingEnum.valueOfDescription((String) comboBox.getSelectedItem()); - } - } } @@ -352,7 +360,7 @@ /** * Get csv datas in string and write file. - * + * * @param filePath * @param charset * @param datas @@ -372,12 +380,12 @@ } finally { IOUtils.closeQuietly(out); } - + } /** * Open csv file and get his datas on a string. - * + * * @param filePath * @param charset * @return @@ -404,9 +412,86 @@ try { byte[] bytes = Base64.decodeBase64(zippedBase64Str); ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); - IOUtils.copy(inputStream, new FileOutputStream(path)); + SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); + IOUtils.copy(inputStream, new FileOutputStream(path+"/LIMA-BACKUP-"+ dateFormat.format(new Date()))); } catch (IOException e) { - throw new LimaTechnicalException(e); + throw new LimaTechnicalException("could not zip file", e); } } + + protected String 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"); + } + 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; + 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); + + newImportService.importAllAsCSV(entryBooksStreamString, transactionsStreamString, fiscalPeriodsStreamString, entriesStreamString, accountsStreamString); + + } catch (Exception ex) { + if(log.isInfoEnabled()) { + log.info(ex); + } + throw new LimaTechnicalException("could not import files", ex); + } + return "SUCCES"; + } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx 2014-07-23 13:46:03 UTC (rev 3857) @@ -54,19 +54,19 @@ <JToolBar floatable="false"> <JButton id="lettered" - toolTipText="{ t("lima.ui.lettering.buttonLettered") + " (Ctrl+L)"}" + toolTipText="{ "lima.ui.lettering.buttonLettered" + " (Ctrl+L)"}" enabled="{editModel.isLettred()}" actionIcon='lettering' onActionPerformed="handler.addLetter()"/> <JButton id="noLettered" - toolTipText="{ t("lima.ui.lettering.buttonNoLettered") + " (Del)"}" + toolTipText="{ "lima.ui.lettering.buttonNoLettered" + " (Del)"}" enabled="{editModel.isUnLettred()}" actionIcon='un-lettering' onActionPerformed="handler.removeLetter()"/> <JButton id="round" - toolTipText="{ t("lima.ui.lettering.buttonEqualize") + " (Ctrl+B)"}" + toolTipText="{ "lima.ui.lettering.buttonEqualize" + " (Ctrl+B)"}" enabled="{editModel.isEqualized()}" actionIcon='balance' onActionPerformed="handler.roundAndCreateEntry()"/> @@ -113,7 +113,7 @@ <JToolBar.Separator/> <JButton id="refresh" - toolTipText="{ t("lima.ui.lettering.buttonRefresh") + " (F5)"}" + toolTipText="{ "lima.ui.lettering.buttonRefresh" + " (F5)"}" actionIcon='refresh' onActionPerformed="handler.updateAllEntries()"/> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartView.jaxx 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartView.jaxx 2014-07-23 13:46:03 UTC (rev 3857) @@ -42,18 +42,18 @@ <JToolBar floatable="false"> <JButton id="addVatStatementMovement" - toolTipText="{ t("lima.vatstatement.movement.add") + " (Ctrl+N)"}" + toolTipText="{ "lima.vatstatement.movement.add" + " (Ctrl+N)"}" actionIcon='vatstatement-new' onActionPerformed="handler.addVatStatementMovement()"/> <JButton id="updateButton" - toolTipText="{ t("lima.common.update") + " (Ctrl+M)"}" + toolTipText="{ "lima.common.update" + " (Ctrl+M)"}" actionIcon='vatstatement-edit' onActionPerformed="handler.updateVatStatement()" enabled="{isSelectedRow()}"/> <JButton id="removeButton" - toolTipText="{ t("lima.common.remove") + " (Del)"}" + toolTipText="{ "lima.common.remove" + " (Del)"}" actionIcon='vatstatement-remove' onActionPerformed="handler.removeVatStatement()" enabled="{isSelectedRow()}"/> Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2014-07-23 13:46:03 UTC (rev 3857) @@ -366,6 +366,7 @@ lima.ui.entry.add.error.beforeFirstFiscalPeriod= lima.ui.entry.add.error.lockedEntryBook= lima.ui.entry.add.error.lockedFinancialPeriod= +lima.ui.entry.add.error.noFinancialPeriod=Any fiscal period are difined. lima.ui.entry.paste.error.afterLastFiscalPeriod= lima.ui.entry.paste.error.beforeFirstFiscalPeriod= lima.ui.entry.paste.error.lockedEntryBook= Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2014-07-23 08:52:27 UTC (rev 3856) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2014-07-23 13:46:03 UTC (rev 3857) @@ -348,6 +348,7 @@ lima.ui.entry.add.error.beforeFirstFiscalPeriod=Impossible d'ajouter une entré car la date de la transaction est avant le %1$te %1$tB %1$tY début du premier exercice. lima.ui.entry.add.error.lockedEntryBook=Impossible d'ajouter une entré car le jounal %2$s (%1$s) est cloturé pour la période du %3$te %3$tB %3$tY au %4$te %4$tB %4$tY. lima.ui.entry.add.error.lockedFinancialPeriod=Impossible d'ajouter une entré car la période fiscale du %3$te %3$tB %3$tY au %4$te %4$tB %4$tY est cloturée. +lima.ui.entry.add.error.noFinancialPeriod=Aucune période fiscale n'est définie. lima.ui.entry.paste.error.afterLastFiscalPeriod=Impossible de copier une entré car la date de la transaction est après le %1$te %1$tB %1$tY fin du dernier exercice. lima.ui.entry.paste.error.beforeFirstFiscalPeriod=Impossible de copier une entré car la date de la transaction est avant le %1$te %1$tB %1$tY début du premier exercice. lima.ui.entry.paste.error.lockedEntryBook=Impossible de copier une entré car le jounal %2$s (%1$s) est cloturé pour la période du %3$te %3$tB %3$tY au %4$te %4$tB %4$tY.