Author: dcosse Date: 2014-08-01 17:52:09 +0200 (Fri, 01 Aug 2014) New Revision: 3890 Url: http://forge.chorem.org/projects/lima/repository/revisions/3890 Log: refs #1032 correction sur import export Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2014-08-01 14:29:33 UTC (rev 3889) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2014-08-01 15:52:09 UTC (rev 3890) @@ -36,6 +36,8 @@ import org.chorem.lima.business.utils.AccountComparator; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountTopiaDao; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderFactory; import javax.ejb.Remote; import javax.ejb.Stateless; @@ -219,8 +221,12 @@ // DAO AccountTopiaDao accountDao = getDaoHelper().getAccountDao(); - accountingRules.updateAccountRules(account); - Account result = accountDao.update(account); + Account originalAccount = accountDao.forAccountNumberEquals(account.getAccountNumber()).findUnique(); + Binder<Account, Account> binder = BinderFactory.newBinder(Account.class, Account.class); + binder.copy(account, originalAccount, Account.PROPERTY_LABEL, Account.PROPERTY_THIRD_PARTY); + //binder.copyExcluding(account, originalAccount, Account.PROPERTY_TOPIA_ID); + accountingRules.updateAccountRules(originalAccount); + Account result = accountDao.update(originalAccount); return result; } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2014-08-01 14:29:33 UTC (rev 3889) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2014-08-01 15:52:09 UTC (rev 3890) @@ -107,7 +107,7 @@ @EJB protected IdentityService identityService; - public static final String JAVA_IO_TMPDIR = "java.io.tmpdir"; + public static final String JAVA_IO_TMPDIR = System.getProperty("java.io.tmpdir")+"/"; protected File exportAccountsFile(String charset) throws Exception { AccountTopiaDao accountTopiaDao = getDaoHelper().getAccountDao(); @@ -115,7 +115,7 @@ File result = null; if (entities != null && entities.size() > 0) { AccountModel model = new AccountModel(); - String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/"; + String tmpDir = JAVA_IO_TMPDIR; result = new File(tmpDir + "accounts.csv"); Export.exportToFile(model, entities, result, Charset.forName(charset)); @@ -143,7 +143,7 @@ List<EntryBook> entities = entryBookTopiaDao.findAll(); File result = null; if (entities != null && !entities.isEmpty()) { - String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/"; + String tmpDir = JAVA_IO_TMPDIR; result = new File(tmpDir + "entryBooks.csv"); EntryBookModel model = new EntryBookModel(); Export.exportToFile(model, entities, result, Charset.forName(charset)); @@ -175,7 +175,7 @@ File result = null; if (entities != null && !entities.isEmpty()) { - String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/"; + String tmpDir = JAVA_IO_TMPDIR; result = new File(tmpDir + "fiscalPeriod.csv"); FiscalPeriodModel model = new FiscalPeriodModel(); Export.exportToFile(model, entities, result, Charset.forName(charset)); @@ -208,7 +208,7 @@ List<FinancialTransaction> entities = financialTransactionTopiaDao.findAll(); if (entities != null && !entities.isEmpty()) { - String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/"; + String tmpDir = JAVA_IO_TMPDIR; result = new File(tmpDir + "financialTransactions.csv"); FinancialTransactionModel model = new FinancialTransactionModel(entryBookService); Export.exportToFile(model, entities, result, Charset.forName(charset)); @@ -223,7 +223,7 @@ File result = null; if (entities != null && !entities.isEmpty()) { - String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/"; + String tmpDir = JAVA_IO_TMPDIR; result = new File(tmpDir + "entries.csv"); EntryModel model = new EntryModel(accountService, financialTransactionService , humanReadable); Export.exportToFile(model, entities, result, Charset.forName(charset)); @@ -260,7 +260,7 @@ @Override public String exportFinancialStatements(String charset) throws Exception { String stResult = null; - String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/"; + String tmpDir = JAVA_IO_TMPDIR; File fileResult = new File(tmpDir + "financialStatements.csv"); List<FinancialStatement> rootFinancialStatements = financialStatementService.getRootFinancialStatements(); @@ -289,7 +289,7 @@ @Override public String exportVatStatements(String charset) throws Exception { String stResult = null; - String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/"; + String tmpDir = JAVA_IO_TMPDIR; File fileResult = new File(tmpDir + "vatStatements.csv"); List<VatStatement> rootVatStatements = vatStatementService.getRootVatStatements(); @@ -313,7 +313,7 @@ List<Identity> identities = new ArrayList<>(); identities.add(identity); - String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/"; + String tmpDir = JAVA_IO_TMPDIR; result = new File(tmpDir + "identity.csv"); IdentityModel model = new IdentityModel(); Export.exportToFile(model, identities, result, Charset.forName(charset)); @@ -371,7 +371,7 @@ List<Account> accounts = accountService.getAllAccounts(); if (accounts != null && !accounts.isEmpty()) { - String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/"; + String tmpDir = JAVA_IO_TMPDIR; result = new File(tmpDir + "accounts.csv"); AccountEBPModel model = new AccountEBPModel(); Export.exportToFile(model, accounts, result, Charset.forName(charset)); @@ -391,7 +391,7 @@ if (entries != null && !entries.isEmpty()) { - String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/"; + String tmpDir = JAVA_IO_TMPDIR; result = new File(tmpDir + "entries.csv"); EntryEBPModel model = new EntryEBPModel(); Export.exportToFile(model, entries, result, Charset.forName(charset)); @@ -411,7 +411,7 @@ if (entryBooks != null && !entryBooks.isEmpty()) { - String tmpDir = System.getProperty(JAVA_IO_TMPDIR)+"/"; + String tmpDir = JAVA_IO_TMPDIR; result = new File(tmpDir + "entryBooks.csv"); EntryBookModel model = new EntryBookModel(); Export.exportToFile(model, entryBooks, result, Charset.forName(charset)); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2014-08-01 14:29:33 UTC (rev 3889) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2014-08-01 15:52:09 UTC (rev 3890) @@ -90,6 +90,13 @@ protected static final Log log = LogFactory.getLog(FinancialTransactionServiceImpl.class); @Override + public FinancialTransaction createNewFinancialTransaction(){ + FinancialTransactionTopiaDao financialtransactionTopiaDao = getDaoHelper().getFinancialTransactionDao(); + FinancialTransaction financialTransaction = financialtransactionTopiaDao.newInstance(); + return financialTransaction; + } + + @Override public FinancialTransaction createFinancialTransaction(FinancialTransaction financialtransaction) throws LockedFinancialPeriodException, LockedEntryBookException { Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-08-01 14:29:33 UTC (rev 3889) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2014-08-01 15:52:09 UTC (rev 3890) @@ -70,7 +70,6 @@ import org.chorem.lima.entity.EntryImpl; import org.chorem.lima.entity.FinancialStatement; import org.chorem.lima.entity.FinancialTransaction; -import org.chorem.lima.entity.FinancialTransactionImpl; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.Identity; import org.chorem.lima.entity.VatStatement; @@ -236,10 +235,8 @@ financialTransactionService.createFinancialTransaction(financialTransaction); lineIndex++; result.increaseCreated(); - } catch (LockedFinancialPeriodException e) { + } catch (LockedFinancialPeriodException | LockedEntryBookException e) { result.getException().addException(lineIndex, e); - } catch (LockedEntryBookException e) { - result.getException().addException(lineIndex, e); } } @@ -623,6 +620,26 @@ } @Override + public ImportResult importEntryBookFromEbp(String datas) { + ImportResult result = new ImportResult(); + + ImportModel<EntryBook> model = new EntryBookEBPModel(); + + InputStream contentStream = IOUtils.toInputStream(datas); + Import<EntryBook> entryBooks = Import.newImport(model, contentStream); + + for (EntryBook entryEBP : entryBooks) { + boolean updated = entryBookService.createOrUpdateEntryBook(entryEBP); + if (updated) { + result.increaseUpdated(); + } else { + result.increaseCreated(); + } + } + return result; + } + + @Override public ImportResult importEntriesFromEbp(String datas) { ImportResult result = new ImportResult(); @@ -674,7 +691,7 @@ } // attributes declaration - FinancialTransaction financialTransaction = null; + FinancialTransaction financialTransaction; Date dateEcr; Account account; Entry entry; @@ -774,14 +791,12 @@ financialTransaction.getEntryBook() .getCode()))) { // create financial transaction - financialTransaction = new FinancialTransactionImpl(); + financialTransaction = financialTransactionService.createNewFinancialTransaction(); financialTransaction.setEntryBook(entryBook); financialTransaction.setTransactionDate(dateEcr); financialTransaction = financialTransactionService.createFinancialTransaction(financialTransaction); } - financialTransaction.getEntry().add(entry); - // Inside the db, the entries reference the financialTransaction - entry.setFinancialTransaction(financialTransaction); + financialTransaction.addEntry(entry); financialTransactionService.createEntry(entry); } catch (LockedFinancialPeriodException | LockedEntryBookException e) { @@ -806,26 +821,6 @@ return result; } - @Override - public ImportResult importEntryBookFromEbp(String datas) { - ImportResult result = new ImportResult(); - - ImportModel<EntryBook> model = new EntryBookEBPModel(); - - InputStream contentStream = IOUtils.toInputStream(datas); - Import<EntryBook> entryBooks = Import.newImport(model, contentStream); - - for (EntryBook entryEBP : entryBooks) { - boolean updated = entryBookService.createOrUpdateEntryBook(entryEBP); - if (updated) { - result.increaseUpdated(); - } else { - result.increaseCreated(); - } - } - return result; - } - //####################################################################################################### // @Override Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java 2014-08-01 14:29:33 UTC (rev 3889) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java 2014-08-01 15:52:09 UTC (rev 3890) @@ -53,6 +53,11 @@ public interface FinancialTransactionService { + /** + * Create new FinancialTransaction not persisted yet. + * @return + */ + FinancialTransaction createNewFinancialTransaction(); FinancialTransaction createFinancialTransaction(FinancialTransaction financialtransaction) throws LockedFinancialPeriodException, LockedEntryBookException; Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java 2014-08-01 14:29:33 UTC (rev 3889) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java 2014-08-01 15:52:09 UTC (rev 3890) @@ -53,10 +53,10 @@ ImportResult importAccountFromEbp(String datas); + ImportResult importEntryBookFromEbp(String datas); + ImportResult importEntriesFromEbp(String datas); - ImportResult importEntryBookFromEbp(String datas); - // String importAsPDF(String data, // ImportExportEntityEnum importExportEntityEnum, // boolean saveMode); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-08-01 14:29:33 UTC (rev 3889) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-08-01 15:52:09 UTC (rev 3890) @@ -235,6 +235,8 @@ //For windows ebp datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding()); importResult = importService.importEntriesFromEbp(datas); + // TODO DCossé 24/07/14 change result + result = "SUCCESS"; break; } } catch (ImportEbpException e) {