Author: echatellier Date: 2012-04-24 14:41:53 +0200 (Tue, 24 Apr 2012) New Revision: 3381 Url: http://chorem.org/repositories/revision/lima/3381 Log: Fix accounts import Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 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 2012-04-18 14:24:21 UTC (rev 3380) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2012-04-24 12:41:53 UTC (rev 3381) @@ -399,8 +399,8 @@ log.info("Imported form EBP : " + list.size() + " accounts in " + (after-before) + " ms"); } - } catch (Exception eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (Exception ex) { + doCatch(topiaContext, ex); } finally { doFinally(topiaContext); } @@ -415,8 +415,6 @@ public String importAllAsCSV(String datas) throws LimaException { StringBuilder result = new StringBuilder(); - Map<String, AccountImport> accounts = new TreeMap<String, AccountImport>(); - LinkedHashMap<String, ArrayList<FinancialStatementImport>> financialStatements = new LinkedHashMap<String, ArrayList<FinancialStatementImport>>(); @@ -446,7 +444,7 @@ if (importExportEntityEnum != null) { switch (importExportEntityEnum) { case ACCOUNT: - result.append(importAccountsChartsCSV(nextLine, accounts, + result.append(importAccountsChartsCSV(nextLine, topiaContext)); break; case ENTRYBOOK: @@ -483,8 +481,6 @@ } } - // create accounts - result.append(createAccounts(accounts, topiaContext)); // create financialStatements result.append(createFinancialStatements(financialStatements, topiaContext)); @@ -503,8 +499,8 @@ commitTransaction(topiaContext); - } catch (Exception eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (Exception ex) { + doCatch(topiaContext, ex); } finally { doFinally(topiaContext); } @@ -522,15 +518,10 @@ // FinancialStatements LinkedHashMap<String, ArrayList<FinancialStatementImport>> financialStatements = null; - // Accounts - Map<String, AccountImport> accounts = null; // VatStatement LinkedHashMap<String, ArrayList<VatStatementImport>> vatStatements = null; switch (importExportEntityEnum) { - case ACCOUNT: - accounts = new TreeMap<String, AccountImport>(); - break; case FINANCIALSTATEMENT: financialStatements = new LinkedHashMap<String, ArrayList<FinancialStatementImport>>(); break; @@ -552,7 +543,7 @@ result.append(importEntryBooksChartCSV(nextLine, topiaContext)); break; case ACCOUNT: - result.append(importAccountsChartsCSV(nextLine, accounts, + result.append(importAccountsChartsCSV(nextLine, topiaContext)); break; case FINANCIALSTATEMENT: @@ -569,9 +560,6 @@ //create entity switch (importExportEntityEnum) { - case ACCOUNT: - result.append(createAccounts(accounts, topiaContext)); - break; case FINANCIALSTATEMENT: result.append(createFinancialStatements(financialStatements, topiaContext)); @@ -582,8 +570,8 @@ break; } - } catch (Exception eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (Exception ex) { + doCatch(topiaContext, ex); } finally { doFinally(topiaContext); } @@ -632,39 +620,33 @@ LimaConfig.getInstance().setVatPDFUrl(datas); } doc.close(); - } catch (IOException eee) { - log.error("Can't read vat pdf", eee); + } catch (IOException ex) { + log.error("Can't read vat pdf", ex); result.append("Can't read vat pdf"); - } catch (COSVisitorException eee) { - log.error("Can't save vat pdf", eee); + } catch (COSVisitorException ex) { + log.error("Can't save vat pdf", ex); result.append("Can't save vat pdf"); } return result.toString(); } - - // ################ Import entities an put to lists ################ - /** * Import and create accounts Structure : TYPE | accountNumber | label * | thirdparty | masterAccountNumber | generalLedgerNumber * * @param nextLine - * @param accounts * @param topiaContext * @return * @throws LimaException */ protected String importAccountsChartsCSV(String[] nextLine, - Map<String, AccountImport> accounts, TopiaContext topiaContext) throws LimaException { + StringBuilder result = new StringBuilder(); String accountNumber = nextLine[1]; String label = nextLine[2]; String thirdParty = nextLine[3]; - String masterAccountNumber = nextLine[4]; - String generalLedgerNumber = nextLine[5]; try { AccountDAO accountDAO = LimaCallaoDAOHelper @@ -672,20 +654,21 @@ // if not exist, create it if (accountDAO.findByAccountNumber(accountNumber) == null) { - // create it - AccountImport accountImport = new AccountImportImpl(); - accountImport.setAccountNumber(accountNumber); - accountImport.setLabel(label); - accountImport.setThirdParty(thirdParty); - accountImport.setMasterAccount(masterAccountNumber); - accountImport.setGeneralLedger(generalLedgerNumber); - // put it in hashset - accounts.put(accountNumber, accountImport); + + Account account = new AccountImpl(); + account.setAccountNumber(accountNumber); + account.setLabel(label); + account.setThirdParty(thirdParty); + + accountDAO.create(account); + result.append(_("lima-business.import.accountadded", + account.getAccountNumber(), + account.getLabel())); } else { result.append(_("lima-business.import.accountalreadyexist", accountNumber)); } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (TopiaException ex) { + doCatch(topiaContext, ex); } return result.toString(); } @@ -722,10 +705,10 @@ } else { result.append(_("lima-business.import.fiscalperiodalreadyexist", beginDate, endDate)); } - } catch (ParseException eeePE) { - log.error("Can't parse date", eeePE); - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (ParseException ex) { + log.error("Can't parse date", ex); + } catch (TopiaException ex) { + doCatch(topiaContext, ex); } return result.toString(); } @@ -738,8 +721,7 @@ * @return * @throws LimaException */ - protected String importEntryBooksChartCSV(String[] nextLine, - TopiaContext topiaContext) throws LimaException { + protected String importEntryBooksChartCSV(String[] nextLine, TopiaContext topiaContext) throws LimaException { StringBuilder result = new StringBuilder(); try { @@ -758,8 +740,8 @@ entryBookService.createEntryBook(entryBook); result.append(_("lima-business.import.financialstatementadded", entryBook.getLabel())); } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (TopiaException ex) { + doCatch(topiaContext, ex); } return result.toString(); } @@ -853,8 +835,8 @@ } else { result.append(_("lima-business.import.financialstatementalreadyexist", label)); } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (TopiaException ex) { + doCatch(topiaContext, ex); } return result.toString(); } @@ -908,8 +890,8 @@ } else { result.append(_("lima-business.import.vatstatementalreadyexist", label)); } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (TopiaException ex) { + doCatch(topiaContext, ex); } return result.toString(); } @@ -978,6 +960,10 @@ // ################ CREATE ENTITY IN DB FOR IMPORT ################ + /** + * @deprecated do only one method import without bean use (and remove beans) + */ + @Deprecated protected String createFinancialStatements(Map<String, ArrayList<FinancialStatementImport>> financialStatements, TopiaContext topiaContext) throws LimaException { StringBuilder result = new StringBuilder(); @@ -1056,12 +1042,16 @@ } } } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (TopiaException ex) { + doCatch(topiaContext, ex); } return result.toString(); } + /** + * @deprecated do only one method import without bean use (and remove beans) + */ + @Deprecated protected String createVatStatements(Map<String, ArrayList<VatStatementImport>> vatStatements, TopiaContext topiaContext) throws LimaException { @@ -1121,8 +1111,8 @@ } } } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (TopiaException ex) { + doCatch(topiaContext, ex); } return result.toString(); } @@ -1145,58 +1135,10 @@ return result.toString(); } - protected String createAccounts(Map<String, AccountImport> accounts, - TopiaContext topiaContext) throws LimaException { - StringBuilder result = new StringBuilder(); - - try { - AccountDAO accountDAO = LimaCallaoDAOHelper - .getAccountDAO(topiaContext); - - while (accounts.size() > 0) { - for (Iterator<AccountImport> itr = accounts.values().iterator(); itr - .hasNext(); ) { - AccountImport accountImport = itr.next(); - String masterAccountNumber = accountImport - .getMasterAccount(); - String generalLedgerNumber = accountImport - .getGeneralLedger(); - Account masterAccount = accountDAO - .findByAccountNumber(masterAccountNumber); - Account generalLedger = accountDAO - .findByAccountNumber(generalLedgerNumber); - - if (masterAccountNumber.equals("") && generalLedgerNumber - .equals("") - || masterAccount != null || generalLedger != null) { - // create it - Account account = new AccountImpl(); - account.setAccountNumber(accountImport - .getAccountNumber()); - account.setLabel(accountImport.getLabel()); - account.setThirdParty(accountImport.getThirdParty()); - - accountService.createAccount(account); - - result.append(_("lima-business.import.accountadded", - accountImport.getAccountNumber(), - accountImport.getLabel())); - itr.remove(); - } else if (!accounts.containsKey(masterAccountNumber) - && !accounts.containsKey(generalLedgerNumber)) { - result.append(_("lima-business.import.accountnomaster", - accountImport.getAccountNumber(), - masterAccountNumber)); - itr.remove(); - } - } - } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); - } - return result.toString(); - } - + /** + * @deprecated do only one method import without bean use (and remove beans) + */ + @Deprecated protected String updateClosedPeriodicEntryBooks( List<ClosedPeriodicEntryBookImport> closedPeriodicEntryBooks, TopiaContext topiaContext) throws LimaException { @@ -1236,14 +1178,18 @@ result.append(_("lima-business.common.failed", eee)); } } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); - } catch (ParseException eeePE) { - log.error("Can't parse date", eeePE); + } catch (TopiaException ex) { + doCatch(topiaContext, ex); + } catch (ParseException ex) { + log.error("Can't parse date", ex); } return result.toString(); } + /** + * @deprecated do only one method import without bean use (and remove beans) + */ + @Deprecated protected String createFinancialTransactionsAndEntries( Map<Integer, FinancialTransactionImport> financialTransactions, Map<Integer, List<EntryImport>> entries, TopiaContext topiaContext) @@ -1300,10 +1246,10 @@ financialTransaction.addEntry(entry); } } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); - } catch (ParseException eeePE) { - log.error("Can't parse date", eeePE); + } catch (TopiaException ex) { + doCatch(topiaContext, ex); + } catch (ParseException ex) { + log.error("Can't parse date", ex); } return result.toString(); }