Author: jpepin Date: 2010-07-28 11:02:22 +0200 (Wed, 28 Jul 2010) New Revision: 2987 Url: http://chorem.org/repositories/revision/lima/2987 Log: Debug export financial statement, fichi?\195?\169 tri?\195?\169 en ordre Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2010-07-26 16:32:09 UTC (rev 2986) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2010-07-28 09:02:22 UTC (rev 2987) @@ -212,7 +212,7 @@ int i=0; int n=list.size(); while (i<n){ - int j=i+40; + int j=i+35; if (j>n){ j = n; } @@ -252,7 +252,7 @@ chapter.add(paragraphTable); //add page document.add(chapter); - i=i+40; + i=i+35; nbpages++; } } 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 2010-07-26 16:32:09 UTC (rev 2986) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2010-07-28 09:02:22 UTC (rev 2987) @@ -52,6 +52,8 @@ import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.framework.TopiaQuery; + import au.com.bytecode.opencsv.CSVWriter; /** @@ -297,8 +299,12 @@ // Get all Financialstatements FinancialStatementDAO financialStatementDAO = LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); + + TopiaQuery query = financialStatementDAO.createQuery(); + query.addOrder(FinancialStatement.TOPIA_CREATE_DATE); List<FinancialStatement> listFinancialStatements = - financialStatementDAO.findAll(); + financialStatementDAO.findAllByQuery(query); + // For all Financialstatements for (FinancialStatement financialStatement : listFinancialStatements) { nextLine[0] = ImportExportEntityEnum.FINANCIALSTATEMENT.getLabel(); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2010-07-26 16:32:09 UTC (rev 2986) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2010-07-28 09:02:22 UTC (rev 2987) @@ -88,18 +88,21 @@ try { - // check if FinancialStatementHeader label already exist FinancialStatementDAO financialStatementDAO = LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); - FinancialStatement existFinancialStatementHeader = + /* check if FinancialStatementHeader label already exist + * too much strict check, many financialstatement can have the same name + * + * FinancialStatement existFinancialStatementHeader = financialStatementDAO.findByLabel(financialStatement.getLabel()); + if (existFinancialStatementHeader != null) { throw new LimaBusinessException(_( "An financialStatement already exists with this label : %s", financialStatement.getLabel())); - } + }*/ financialStatementDAO.create(financialStatement); @@ -223,7 +226,7 @@ TopiaQuery query = financialStatementDAO.createQuery(); query.addEquals("masterFinancialStatement", masterFinancialStatement) - .addOrder(FinancialStatement.LABEL); + .addOrder(FinancialStatement.TOPIA_CREATE_DATE); financialStatements = financialStatementDAO.findAllByQuery(query); } catch (TopiaException ex) { 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 2010-07-26 16:32:09 UTC (rev 2986) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2010-07-28 09:02:22 UTC (rev 2987) @@ -29,6 +29,7 @@ import java.util.Date; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -103,919 +104,997 @@ * * @version $Revision$ * - * Last update : $Date$ - * By : $Author$ + * Last update : $Date: 2010-07-26 18:32:09 +0200 (lun., 26 juil. 2010) + * $ By : $Author$ */ @Stateless -public class ImportServiceImpl extends AbstractLimaService implements ImportService, ImportServiceLocal { +public class ImportServiceImpl extends AbstractLimaService implements + ImportService, ImportServiceLocal { - private static final Log log = - LogFactory.getLog(ImportServiceImpl.class); - - private TopiaContext rootContext; - - //Services - - @EJB - AccountServiceLocal accountService; - - @EJB - FiscalPeriodServiceLocal fiscalPeriodService; - - @EJB - FinancialPeriodServiceLocal financialPeriodService; - - @EJB - FinancialTransactionServiceLocal financialTransactionService; + private static final Log log = LogFactory.getLog(ImportServiceImpl.class); - @EJB - FinancialStatementServiceLocal financialStatementService; - - @EJB - EntryBookServiceLocal entryBookService; - - @EJB - IdentityServiceLocal identityService; - - private static final SimpleDateFormat SDateFormat = new SimpleDateFormat("dd,MM,yyyy HH:mm:ss"); - + private TopiaContext rootContext; - public ImportServiceImpl() { - LimaConfig config = LimaConfig.getInstance(); - try { - rootContext = TopiaContextFactory.getContext(config.getOptions()); - } catch (TopiaNotFoundException ex) { - if (log.isErrorEnabled()) { - log.error("Can't init topia context", ex); - } - } - } + // Services - //################ IMPORT THIRD PART ACCOUNTING SOFTWARE ################ - - @Override - public String importEntriesFromEbp(String datas) throws LimaException { + @EJB + AccountServiceLocal accountService; + + @EJB + FiscalPeriodServiceLocal fiscalPeriodService; + + @EJB + FinancialPeriodServiceLocal financialPeriodService; + + @EJB + FinancialTransactionServiceLocal financialTransactionService; + + @EJB + FinancialStatementServiceLocal financialStatementService; + + @EJB + EntryBookServiceLocal entryBookService; + + @EJB + IdentityServiceLocal identityService; + + private static final SimpleDateFormat SDateFormat = new SimpleDateFormat( + "dd,MM,yyyy HH:mm:ss"); + + public ImportServiceImpl() { + LimaConfig config = LimaConfig.getInstance(); + try { + rootContext = TopiaContextFactory.getContext(config.getOptions()); + } catch (TopiaNotFoundException ex) { + if (log.isErrorEnabled()) { + log.error("Can't init topia context", ex); + } + } + } + + // ################ IMPORT THIRD PART ACCOUNTING SOFTWARE ################ + + @Override + public String importEntriesFromEbp(String datas) throws LimaException { SimpleDateFormat epbDateFormat = new SimpleDateFormat("dd/MM/yyyy"); - String result = ""; + String result = ""; - TopiaContext topiaContext = null; - try { - topiaContext = beginTransaction(); - - CSVReader csvReader = new CSVReader(new StringReader(datas)); - ColumnPositionMappingStrategy<EntryEBPImpl> strat = new ColumnPositionMappingStrategy<EntryEBPImpl>(); - strat.setType(EntryEBPImpl.class); - //read header to set strategy mapping - strat.setColumnMapping(csvReader.readNext()); - - //check if file have a good header - List<String> headAccount = new ArrayList<String>(); - headAccount.add("Journal"); - headAccount.add("Compte"); - headAccount.add("DatEcr"); - headAccount.add("Piece"); - headAccount.add("Libelle"); - headAccount.add("Debit"); - headAccount.add("Credit"); - headAccount.add("Lettre"); - if (!Arrays.asList(strat.getColumnMapping()).containsAll(headAccount)){ - throw new LimaBusinessException("ERROR : This file contains no entries"); - } - - CsvToBean<EntryEBPImpl> csv = new CsvToBean<EntryEBPImpl>(); - List<EntryEBPImpl> list = csv.parse(strat, csvReader); - - //DAOs - AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(topiaContext); - EntryBookDAO entryBookDAO = - LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); - FinancialPeriodDAO financialPeriodDAO = - LimaCallaoDAOHelper.getFinancialPeriodDAO(topiaContext); - - if (financialPeriodDAO.findAll().size() == 0){ - throw new LimaBusinessException("Can't import entries, no fiscalperiod is open"); - } - - FinancialTransaction financialTransaction = null; - for (EntryEBP entryEBP : list) { - //create entry - Entry entry = new EntryImpl(); - Account account = accountDAO.findByAccountNumber(entryEBP.getCompte()); - //if account not exist not export - if (account == null){ - throw new LimaBusinessException("FAILED : Account " + entryEBP.getCompte() + " not exist !\n" - + "Import or create all accounts before import entries"); - } - else { - entry.setAccount(account); - Double debit = new Double(entryEBP.getDebit()); - Double credit = new Double(entryEBP.getCredit()); - if (debit == 0){ - entry.setDebit(false); - entry.setAmount(credit); - } - else { - entry.setDebit(true); - entry.setAmount(debit); - } - entry.setDescription(entryEBP.getLibelle()); - entry.setLettering(entryEBP.getLettre()); - entry.setVoucher(entryEBP.getPiece()); - Date date = epbDateFormat.parse(entryEBP.getDatEcr()); - String entryBookCode = entryEBP.getJournal(); - EntryBook entryBook = entryBookDAO.findByCode(entryBookCode); - - //if entrybook not exist create it ! - if (entryBook==null){ - entryBook = new EntryBookImpl(); - entryBook.setCode(entryBookCode); - //create it - entryBookService.createEntryBook(entryBook); - result += "WARNING : Entrybook " + entryBook + "not exist was created !\n"; - } + TopiaContext topiaContext = null; + try { + topiaContext = beginTransaction(); - - if (financialTransaction == null || !(date.equals(financialTransaction.getTransactionDate()) && entryBook.getCode().equals(financialTransaction.getEntryBook().getCode()))){ - //update previous financial transaction before create new - if (financialTransaction != null){ - financialTransaction.setAmounts(); - financialTransactionService.updateFinancialTransactionWithTransaction(financialTransaction, topiaContext); - } - //create financial transaction - financialTransaction = new FinancialTransactionImpl(); - financialTransaction.setEntryBook(entryBook); - financialTransaction.setTransactionDate(date); - FinancialPeriod financialPeriod = financialPeriodDAO.findByDate(date); - financialTransaction.setFinancialPeriod(financialPeriod); - financialTransactionService.createFinancialTransactionWithTransaction(financialTransaction, topiaContext); - result += "SUCCES : FinancialTransaction" + date + " " + entryBook.getCode() + " added\n"; + CSVReader csvReader = new CSVReader(new StringReader(datas)); + ColumnPositionMappingStrategy<EntryEBPImpl> strat = new ColumnPositionMappingStrategy<EntryEBPImpl>(); + strat.setType(EntryEBPImpl.class); + // read header to set strategy mapping + strat.setColumnMapping(csvReader.readNext()); - } - financialTransaction.addEntry(entry); - financialTransactionService.createEntryWithTransaction(entry, topiaContext); - result += "SUCCES : Entry" + entry.getDescription() + " " + entry.getAmount() + " added\n"; - } - } - //update last financial transaction - if (financialTransaction != null){ - financialTransaction.setAmounts(); - financialTransactionService.updateFinancialTransactionWithTransaction(financialTransaction, topiaContext); - } - //commit - commitTransaction(topiaContext); - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); - } - catch (IOException eeeIO) { - if (log.isDebugEnabled()){ + // check if file have a good header + List<String> headAccount = new ArrayList<String>(); + headAccount.add("Journal"); + headAccount.add("Compte"); + headAccount.add("DatEcr"); + headAccount.add("Piece"); + headAccount.add("Libelle"); + headAccount.add("Debit"); + headAccount.add("Credit"); + headAccount.add("Lettre"); + if (!Arrays.asList(strat.getColumnMapping()).containsAll( + headAccount)) { + throw new LimaBusinessException( + "ERROR : This file contains no entries"); + } + + CsvToBean<EntryEBPImpl> csv = new CsvToBean<EntryEBPImpl>(); + List<EntryEBPImpl> list = csv.parse(strat, csvReader); + + // DAOs + AccountDAO accountDAO = LimaCallaoDAOHelper + .getAccountDAO(topiaContext); + EntryBookDAO entryBookDAO = LimaCallaoDAOHelper + .getEntryBookDAO(topiaContext); + FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper + .getFinancialPeriodDAO(topiaContext); + + if (financialPeriodDAO.findAll().size() == 0) { + throw new LimaBusinessException( + "Can't import entries, no fiscalperiod is open"); + } + + FinancialTransaction financialTransaction = null; + for (EntryEBP entryEBP : list) { + // create entry + Entry entry = new EntryImpl(); + Account account = accountDAO.findByAccountNumber(entryEBP + .getCompte()); + // if account not exist not export + if (account == null) { + throw new LimaBusinessException( + "FAILED : Account " + + entryEBP.getCompte() + + " not exist !\n" + + "Import or create all accounts before import entries"); + } else { + entry.setAccount(account); + Double debit = new Double(entryEBP.getDebit()); + Double credit = new Double(entryEBP.getCredit()); + if (debit == 0) { + entry.setDebit(false); + entry.setAmount(credit); + } else { + entry.setDebit(true); + entry.setAmount(debit); + } + entry.setDescription(entryEBP.getLibelle()); + entry.setLettering(entryEBP.getLettre()); + entry.setVoucher(entryEBP.getPiece()); + Date date = epbDateFormat.parse(entryEBP.getDatEcr()); + String entryBookCode = entryEBP.getJournal(); + EntryBook entryBook = entryBookDAO + .findByCode(entryBookCode); + + // if entrybook not exist create it ! + if (entryBook == null) { + entryBook = new EntryBookImpl(); + entryBook.setCode(entryBookCode); + // create it + entryBookService.createEntryBook(entryBook); + result += "WARNING : Entrybook " + entryBook + + "not exist was created !\n"; + } + + if (financialTransaction == null + || !(date.equals(financialTransaction + .getTransactionDate()) && entryBook + .getCode().equals( + financialTransaction.getEntryBook() + .getCode()))) { + // update previous financial transaction before create + // new + if (financialTransaction != null) { + financialTransaction.setAmounts(); + financialTransactionService + .updateFinancialTransactionWithTransaction( + financialTransaction, topiaContext); + } + // create financial transaction + financialTransaction = new FinancialTransactionImpl(); + financialTransaction.setEntryBook(entryBook); + financialTransaction.setTransactionDate(date); + FinancialPeriod financialPeriod = financialPeriodDAO + .findByDate(date); + financialTransaction + .setFinancialPeriod(financialPeriod); + financialTransactionService + .createFinancialTransactionWithTransaction( + financialTransaction, topiaContext); + result += "SUCCES : FinancialTransaction" + date + " " + + entryBook.getCode() + " added\n"; + + } + financialTransaction.addEntry(entry); + financialTransactionService.createEntryWithTransaction( + entry, topiaContext); + result += "SUCCES : Entry" + entry.getDescription() + " " + + entry.getAmount() + " added\n"; + } + } + // update last financial transaction + if (financialTransaction != null) { + financialTransaction.setAmounts(); + financialTransactionService + .updateFinancialTransactionWithTransaction( + financialTransaction, topiaContext); + } + // commit + commitTransaction(topiaContext); + } catch (TopiaException eeeTE) { + doCatch(topiaContext, eeeTE, log); + } catch (IOException eeeIO) { + if (log.isDebugEnabled()) { log.debug("Can't read string", eeeIO); } - } - catch (ParseException eeePE) { - if (log.isDebugEnabled()){ + } catch (ParseException eeePE) { + if (log.isDebugEnabled()) { log.debug("Can't parse date", eeePE); } + } finally { + doFinally(topiaContext, log); } - finally { - doFinally(topiaContext, log); - } return result; - } + } - @Override - public String importAccountsChartFromEbp(String datas) throws LimaException{ + @Override + public String importAccountsChartFromEbp(String datas) throws LimaException { String result = ""; - TopiaContext topiaContext = null; - - try { - topiaContext = beginTransaction(); - CSVReader csvReader = new CSVReader(new StringReader(datas)); - ColumnPositionMappingStrategy<AccountEBPImpl> strat = new ColumnPositionMappingStrategy<AccountEBPImpl>(); - strat.setType(AccountEBPImpl.class); - //read header to set strategy mapping - strat.setColumnMapping(csvReader.readNext()); - - //check if file have a good header - List<String> headAccount = new ArrayList<String>(); - headAccount.add("Numero"); - headAccount.add("Intitule"); - if (!Arrays.asList(strat.getColumnMapping()).containsAll(headAccount)){ - throw new LimaBusinessException("ERROR : This file contains no account"); - } - - CsvToBean<AccountEBPImpl> csv = new CsvToBean<AccountEBPImpl>(); - List<AccountEBPImpl> list = csv.parse(strat, csvReader); - Collections.sort(list, new AccountEBPComparator()); - - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(topiaContext); + TopiaContext topiaContext = null; + + try { + topiaContext = beginTransaction(); + CSVReader csvReader = new CSVReader(new StringReader(datas)); + ColumnPositionMappingStrategy<AccountEBPImpl> strat = new ColumnPositionMappingStrategy<AccountEBPImpl>(); + strat.setType(AccountEBPImpl.class); + // read header to set strategy mapping + strat.setColumnMapping(csvReader.readNext()); + + // check if file have a good header + List<String> headAccount = new ArrayList<String>(); + headAccount.add("Numero"); + headAccount.add("Intitule"); + if (!Arrays.asList(strat.getColumnMapping()).containsAll( + headAccount)) { + throw new LimaBusinessException( + "ERROR : This file contains no account"); + } + + CsvToBean<AccountEBPImpl> csv = new CsvToBean<AccountEBPImpl>(); + List<AccountEBPImpl> list = csv.parse(strat, csvReader); + Collections.sort(list, new AccountEBPComparator()); + + AccountDAO accountDAO = LimaCallaoDAOHelper + .getAccountDAO(topiaContext); for (AccountEBP accountEBP : list) { String accountNumber = accountEBP.getNumero(); - if (accountDAO.findByAccountNumber(accountNumber) != null){ - result += "FAILED : Account" + accountNumber + " already exist \n"; - } - else { + if (accountDAO.findByAccountNumber(accountNumber) != null) { + result += "FAILED : Account" + accountNumber + + " already exist \n"; + } else { String label = accountEBP.getIntitule(); Account account = new AccountImpl(); account.setAccountNumber(accountNumber); account.setLabel(label); - + // if account is class account : 1, 2, 3, 4, 5, 6, 7,… int nbCharAccountNumber = accountNumber.length(); - if (nbCharAccountNumber == 1){ - accountService.createAccountWithTransaction(null, account, topiaContext); - result += "SUCCES : Account" + accountNumber + " " + label + " added\n"; - } - else { + if (nbCharAccountNumber == 1) { + accountService.createAccountWithTransaction(null, + account, topiaContext); + result += "SUCCES : Account" + accountNumber + " " + + label + " added\n"; + } else { Account masterAccount = null; int i = 1; - while (masterAccount == null){ - String masterAccountNumber = accountNumber.substring(0, accountNumber.length()-i); - masterAccount = accountDAO.findByAccountNumber(masterAccountNumber); + while (masterAccount == null) { + String masterAccountNumber = accountNumber + .substring(0, accountNumber.length() - i); + masterAccount = accountDAO + .findByAccountNumber(masterAccountNumber); i++; } - accountService.createAccountWithTransaction(masterAccount, account, topiaContext); - result += "SUCCES : Account" + accountNumber + " " + label + " added\n"; + accountService.createAccountWithTransaction( + masterAccount, account, topiaContext); + result += "SUCCES : Account" + accountNumber + " " + + label + " added\n"; } - } + } } - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); - } - catch (IOException eeeIO) { - if (log.isDebugEnabled()){ + } catch (TopiaException eeeTE) { + doCatch(topiaContext, eeeTE, log); + } catch (IOException eeeIO) { + if (log.isDebugEnabled()) { log.debug("Can't read string", eeeIO); } + } finally { + doFinally(topiaContext, log); } - finally { - doFinally(topiaContext, log); - } - - return result; + + return result; } - @Override public void importAsCiel(byte[] data) throws LimaException { // TODO Auto-generated method stub - + } @Override public void importAsSage(byte[] data) throws LimaException { // TODO Auto-generated method stub - + } - - //################ IMPORT ################ + // ################ IMPORT ################ /** * Remote methode to call all entities import from UI */ @Override public String importAllAsCSV(String datas) throws LimaException { - String result = ""; - - Map<String, AccountImport> accounts = new TreeMap<String, AccountImport>(); - - Map<String, FinancialStatementImport> financialStatements = new TreeMap<String, FinancialStatementImport>(); - - List<FiscalPeriod> fiscalPeriods = new ArrayList<FiscalPeriod>(); - - List<ClosedPeriodicEntryBookImport> closedPeriodicEntryBooks = new ArrayList<ClosedPeriodicEntryBookImport>(); - - Map<Integer, FinancialTransactionImport> financialTransactions = new HashMap<Integer,FinancialTransactionImport>(); - - Map<Integer, List<EntryImport>> entries = new HashMap<Integer, List<EntryImport>>(); - - - TopiaContext topiaContext = null; - try { - topiaContext = beginTransaction(); - - String[] nextLine = new String[1]; - CSVReader csvReader = new CSVReader(new StringReader(datas), ';'); - - while ((nextLine = csvReader.readNext()) != null) { - ImportExportEntityEnum importExportEntityEnum = ImportExportEntityEnum.valueOfLabel(nextLine[0]); - if (importExportEntityEnum != null){ - switch (importExportEntityEnum) { - case ACCOUNT: - result += importAccountsChartsCSV(nextLine, accounts, topiaContext); - break; - case ENTRYBOOK: - result += importEntryBooksChartCSV(nextLine, topiaContext); - break; - case FINANCIALSTATEMENT: - result += importFinancialsStatementChartCSV(nextLine, financialStatements, topiaContext); - break; - case FISCALPERIOD: - result += importFiscalPeriodCSV(nextLine, fiscalPeriods, topiaContext); - break; - case CLOSEDPERIODICENTRYBOOK: - importClosedPeriodicEntryBookCSV(nextLine, closedPeriodicEntryBooks, topiaContext); - break; - case FINANCIALTRANSACTION: - importFinancialTransactionsCSV(nextLine, financialTransactions, topiaContext); - break; - case ENTRY: - importEntriesCSV(nextLine, entries, topiaContext); - break; - case IDENTITY: - importIdentity(nextLine, topiaContext); - break; - } - } - } - - //create accounts - result += createAccounts(accounts, topiaContext); - //create financialStatements - result += createFinancialStatements(financialStatements, topiaContext); - //create fiscalperiod - Collections.sort(fiscalPeriods, new FiscalPeriodComparator()); - result += createFiscalPeriod(fiscalPeriods, topiaContext); - //update closedperiodicentrybooks - result += updateClosedPeriodicEntryBooks(closedPeriodicEntryBooks, topiaContext); - //create financialtransaction and entries - result += createFinancialTransactionsAndEntries(financialTransactions, entries, topiaContext); - - commitTransaction(topiaContext); + String result = ""; - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); + Map<String, AccountImport> accounts = new TreeMap<String, AccountImport>(); + + LinkedHashMap<String, ArrayList<FinancialStatementImport>> financialStatements = + new LinkedHashMap<String, ArrayList<FinancialStatementImport>>(); + + List<FiscalPeriod> fiscalPeriods = new ArrayList<FiscalPeriod>(); + + List<ClosedPeriodicEntryBookImport> closedPeriodicEntryBooks = + new ArrayList<ClosedPeriodicEntryBookImport>(); + + Map<Integer, FinancialTransactionImport> financialTransactions = + new HashMap<Integer, FinancialTransactionImport>(); + + Map<Integer, List<EntryImport>> entries = + new HashMap<Integer, List<EntryImport>>(); + + TopiaContext topiaContext = null; + try { + topiaContext = beginTransaction(); + + String[] nextLine = new String[1]; + CSVReader csvReader = new CSVReader(new StringReader(datas), ';'); + + while ((nextLine = csvReader.readNext()) != null) { + ImportExportEntityEnum importExportEntityEnum = ImportExportEntityEnum + .valueOfLabel(nextLine[0]); + if (importExportEntityEnum != null) { + switch (importExportEntityEnum) { + case ACCOUNT: + result += importAccountsChartsCSV(nextLine, accounts, + topiaContext); + break; + case ENTRYBOOK: + result += importEntryBooksChartCSV(nextLine, + topiaContext); + break; + case FINANCIALSTATEMENT: + result += importFinancialsStatementChartCSV(nextLine, + financialStatements, topiaContext); + break; + case FISCALPERIOD: + result += importFiscalPeriodCSV(nextLine, + fiscalPeriods, topiaContext); + break; + case CLOSEDPERIODICENTRYBOOK: + importClosedPeriodicEntryBookCSV(nextLine, + closedPeriodicEntryBooks, topiaContext); + break; + case FINANCIALTRANSACTION: + importFinancialTransactionsCSV(nextLine, + financialTransactions, topiaContext); + break; + case ENTRY: + importEntriesCSV(nextLine, entries, topiaContext); + break; + case IDENTITY: + importIdentity(nextLine, topiaContext); + break; + } + } + } + + // create accounts + result += createAccounts(accounts, topiaContext); + // create financialStatements + result += createFinancialStatements(financialStatements, + topiaContext); + // create fiscalperiod + Collections.sort(fiscalPeriods, new FiscalPeriodComparator()); + result += createFiscalPeriod(fiscalPeriods, topiaContext); + // update closedperiodicentrybooks + result += updateClosedPeriodicEntryBooks(closedPeriodicEntryBooks, + topiaContext); + // create financialtransaction and entries + result += createFinancialTransactionsAndEntries( + financialTransactions, entries, topiaContext); + + commitTransaction(topiaContext); + + } catch (TopiaException eeeTE) { + doCatch(topiaContext, eeeTE, log); + } catch (IOException eeeIO) { + log.debug("Can't create new CSV Reader", eeeIO); + } finally { + doFinally(topiaContext, log); } - catch (IOException eeeIO) { - log.debug("Can't create new CSV Reader",eeeIO); - } - finally { - doFinally(topiaContext, log); - } return result; } - - + /** * Remote methode to call entrybooks import from UI */ @Override - public String importEntryBooksChartAsCSV(String datas) throws LimaException{ - String result = ""; + public String importEntryBooksChartAsCSV(String datas) throws LimaException { + String result = ""; - TopiaContext topiaContext = null; - try { - topiaContext = beginTransaction(); - - String[] nextLine = new String[1]; - CSVReader csvReader = new CSVReader(new StringReader(datas), ';'); - - while ((nextLine = csvReader.readNext()) != null) { - if (ImportExportEntityEnum.valueOfLabel(nextLine[0]) == ImportExportEntityEnum.ENTRYBOOK){ - result += importEntryBooksChartCSV(nextLine, topiaContext); - } - } - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); + TopiaContext topiaContext = null; + try { + topiaContext = beginTransaction(); + + String[] nextLine = new String[1]; + CSVReader csvReader = new CSVReader(new StringReader(datas), ';'); + + while ((nextLine = csvReader.readNext()) != null) { + if (ImportExportEntityEnum.valueOfLabel(nextLine[0]) == ImportExportEntityEnum.ENTRYBOOK) { + result += importEntryBooksChartCSV(nextLine, topiaContext); + } + } + } catch (TopiaException eeeTE) { + doCatch(topiaContext, eeeTE, log); + } catch (IOException eeeIO) { + log.debug("Can't create new CSV Reader", eeeIO); + } finally { + doFinally(topiaContext, log); } - catch (IOException eeeIO) { - log.debug("Can't create new CSV Reader",eeeIO); - } - finally { - doFinally(topiaContext, log); - } return result; } - /** * Remote methode to call financialStatements import from UI */ @Override - public String importFinancialStatementsChartAsCSV(String datas) throws LimaException { - String result = ""; - - //FinancialStatements - Map<String, FinancialStatementImport> financialStatements = - new TreeMap<String, FinancialStatementImport>(); + public String importFinancialStatementsChartAsCSV(String datas) + throws LimaException { + String result = ""; - TopiaContext topiaContext = null; - try { - topiaContext = beginTransaction(); - - String[] nextLine = new String[1]; - CSVReader csvReader = new CSVReader(new StringReader(datas), ';'); - - while ((nextLine = csvReader.readNext()) != null) { - if (ImportExportEntityEnum.valueOfLabel(nextLine[0]) == ImportExportEntityEnum.FINANCIALSTATEMENT){ - result += importFinancialsStatementChartCSV(nextLine, financialStatements, topiaContext); - } - } - - //create financialStatements - result += createFinancialStatements(financialStatements, topiaContext); - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); + // FinancialStatements + LinkedHashMap<String, ArrayList<FinancialStatementImport>> financialStatements = + new LinkedHashMap<String, ArrayList<FinancialStatementImport>>(); + + TopiaContext topiaContext = null; + try { + topiaContext = beginTransaction(); + + String[] nextLine = new String[1]; + CSVReader csvReader = new CSVReader(new StringReader(datas), ';'); + + while ((nextLine = csvReader.readNext()) != null) { + if (ImportExportEntityEnum.valueOfLabel(nextLine[0]) == ImportExportEntityEnum.FINANCIALSTATEMENT) { + result += importFinancialsStatementChartCSV(nextLine, + financialStatements, topiaContext); + } + } + + // create financialStatements + result += createFinancialStatements(financialStatements, + topiaContext); + } catch (TopiaException eeeTE) { + doCatch(topiaContext, eeeTE, log); + } catch (IOException eeeIO) { + log.debug("Can't create new CSV Reader", eeeIO); + } finally { + doFinally(topiaContext, log); } - catch (IOException eeeIO) { - log.debug("Can't create new CSV Reader",eeeIO); - } - finally { - doFinally(topiaContext, log); - } return result; } - - + /** * Remote methode to call accounts import from UI */ @Override public String importAccountsChartAsCSV(String datas) throws LimaException { - String result = ""; - - //Accounts - Map<String, AccountImport> accounts = - new TreeMap<String, AccountImport>(); + String result = ""; - TopiaContext topiaContext = null; - try { - topiaContext = beginTransaction(); - - String[] nextLine = new String[1]; - CSVReader csvReader = new CSVReader(new StringReader(datas), ';'); - - while ((nextLine = csvReader.readNext()) != null) { - if (ImportExportEntityEnum.valueOfLabel(nextLine[0]) == ImportExportEntityEnum.ACCOUNT){ - result += importAccountsChartsCSV(nextLine, accounts, topiaContext); - } - } - - //create accounts - result += createAccounts(accounts, topiaContext); - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); + // Accounts + Map<String, AccountImport> accounts = new TreeMap<String, AccountImport>(); + + TopiaContext topiaContext = null; + try { + topiaContext = beginTransaction(); + + String[] nextLine = new String[1]; + CSVReader csvReader = new CSVReader(new StringReader(datas), ';'); + + while ((nextLine = csvReader.readNext()) != null) { + if (ImportExportEntityEnum.valueOfLabel(nextLine[0]) == ImportExportEntityEnum.ACCOUNT) { + result += importAccountsChartsCSV(nextLine, accounts, + topiaContext); + } + } + + // create accounts + result += createAccounts(accounts, topiaContext); + } catch (TopiaException eeeTE) { + doCatch(topiaContext, eeeTE, log); + } catch (IOException eeeIO) { + log.debug("Can't create new CSV Reader", eeeIO); + } finally { + doFinally(topiaContext, log); } - catch (IOException eeeIO) { - log.debug("Can't create new CSV Reader",eeeIO); - } - finally { - doFinally(topiaContext, log); - } return result; } - - - //################ Import entities an put to lists ################ - + + // ################ Import entities an put to lists ################ + /** - * Import and create accounts - * Structure : TYPE | accountNumber | label | thirdparty | masterAccountNumber | generalLedgerNumber + * Import and create accounts Structure : TYPE | accountNumber | label + * | thirdparty | masterAccountNumber | generalLedgerNumber */ - public String importAccountsChartsCSV(String[] nextLine, Map<String, AccountImport> accounts, TopiaContext topiaContext) throws LimaException{ + public String importAccountsChartsCSV(String[] nextLine, + Map<String, AccountImport> accounts, TopiaContext topiaContext) + throws LimaException { String result = ""; - String accountNumber = nextLine[1]; - String label = nextLine[2]; - String thirdParty = nextLine[3]; - String masterAccountNumber = nextLine[4]; - String generalLedgerNumber = nextLine[5]; - - try { - AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(topiaContext); - - //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); - } - else { - result += "FAILED : The account " - + accountNumber + " already exists !\n"; - } - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); + String accountNumber = nextLine[1]; + String label = nextLine[2]; + String thirdParty = nextLine[3]; + String masterAccountNumber = nextLine[4]; + String generalLedgerNumber = nextLine[5]; + + try { + AccountDAO accountDAO = LimaCallaoDAOHelper + .getAccountDAO(topiaContext); + + // 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); + } else { + result += "FAILED : The account " + accountNumber + + " already exists !\n"; + } + } catch (TopiaException eeeTE) { + doCatch(topiaContext, eeeTE, log); } return result; } - - + /** - * Import and create fiscal period - * Structure : TYPE | BeginDate | EndDate | Locked + * Import and create fiscal period Structure : TYPE | BeginDate | EndDate + * | Locked */ - public String importFiscalPeriodCSV(String[] nextLine, List<FiscalPeriod> fiscalPeriods, TopiaContext topiaContext) throws LimaException { - String result =""; + public String importFiscalPeriodCSV(String[] nextLine, + List<FiscalPeriod> fiscalPeriods, TopiaContext topiaContext) + throws LimaException { + String result = ""; try { - FiscalPeriodDAO fiscalPeriodDAO = - LimaCallaoDAOHelper.getFiscalPeriodDAO(topiaContext); - - FiscalPeriod fiscalPeriod = new FiscalPeriodImpl(); - Date beginDate = SDateFormat.parse(nextLine[1]); - fiscalPeriod.setBeginDate(beginDate); - Date endDate = SDateFormat.parse(nextLine[2]); - fiscalPeriod.setEndDate(endDate); - fiscalPeriod.setLocked(new Boolean(nextLine[3])); + FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper + .getFiscalPeriodDAO(topiaContext); - //if not exist, skip - if (fiscalPeriodDAO.findByNaturalId(beginDate, endDate) == null){ - fiscalPeriods.add(fiscalPeriod); - } - else { - result += "FAILED : The fiscalperiod " - + beginDate + "-" + endDate + " already exists !\n"; - } - } - catch (ParseException eeePE) { - if(log.isDebugEnabled()){ + FiscalPeriod fiscalPeriod = new FiscalPeriodImpl(); + Date beginDate = SDateFormat.parse(nextLine[1]); + fiscalPeriod.setBeginDate(beginDate); + Date endDate = SDateFormat.parse(nextLine[2]); + fiscalPeriod.setEndDate(endDate); + fiscalPeriod.setLocked(new Boolean(nextLine[3])); + + // if not exist, skip + if (fiscalPeriodDAO.findByNaturalId(beginDate, endDate) == null) { + fiscalPeriods.add(fiscalPeriod); + } else { + result += "FAILED : The fiscalperiod " + beginDate + "-" + + endDate + " already exists !\n"; + } + } catch (ParseException eeePE) { + if (log.isDebugEnabled()) { log.debug("Can't parse date", eeePE); } + } catch (TopiaException eeeTE) { + doCatch(topiaContext, eeeTE, log); } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); - } return result; } - - + /** - * Import and create entrybooks - * Structure : TYPE | Code | Label | Type + * Import and create entrybooks Structure : TYPE | Code | Label | Type */ - public String importEntryBooksChartCSV(String[] nextLine, TopiaContext topiaContext) throws LimaException { - String result =""; - try { - - EntryBookDAO entryBookDAO = - LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); - - EntryBook entryBook = new EntryBookImpl(); - entryBook.setCode(nextLine[1]); - entryBook.setLabel(nextLine[2]); - entryBook.setType(nextLine[3]); + public String importEntryBooksChartCSV(String[] nextLine, + TopiaContext topiaContext) throws LimaException { + String result = ""; + try { - //if exist, skip - if (entryBookDAO.findByCode(entryBook.getCode()) != null){ - result += "FAILED : The entrybook " - + entryBook.getLabel() + " already exists !\n"; - } - else { - //create it - entryBookService.createEntryBook(entryBook); - result += "SUCCESS : The financialStatement " + - entryBook.getLabel() + " is created ! \n"; - } - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); + EntryBookDAO entryBookDAO = LimaCallaoDAOHelper + .getEntryBookDAO(topiaContext); + + EntryBook entryBook = new EntryBookImpl(); + entryBook.setCode(nextLine[1]); + entryBook.setLabel(nextLine[2]); + entryBook.setType(nextLine[3]); + + // if exist, skip + if (entryBookDAO.findByCode(entryBook.getCode()) != null) { + result += "FAILED : The entrybook " + entryBook.getLabel() + + " already exists !\n"; + } else { + // create it + entryBookService.createEntryBook(entryBook); + result += "SUCCESS : The financialStatement " + + entryBook.getLabel() + " is created ! \n"; + } + } catch (TopiaException eeeTE) { + doCatch(topiaContext, eeeTE, log); } return result; } - - + /** - * Import and create closedperiodicentrybook import - * Structure : TYPE | BeginDate | EndDate | Locked + * Import and create closedperiodicentrybook import Structure : TYPE | + * BeginDate | EndDate | Locked */ - public void importClosedPeriodicEntryBookCSV(String[] nextLine, List<ClosedPeriodicEntryBookImport> closedPeriodicEntryBooks, TopiaContext topiaContext) throws LimaException { - String locked = nextLine[1]; - String beginDate = nextLine[2]; - String endDate = nextLine[3]; - String entryBookCode = nextLine[4]; - - if (new Boolean(locked)){ - ClosedPeriodicEntryBookImport closedPeriodicEntryBookImport = new ClosedPeriodicEntryBookImportImpl(); - closedPeriodicEntryBookImport.setLocked(locked); - closedPeriodicEntryBookImport.setBeginDateFinancialPeriod(beginDate); - closedPeriodicEntryBookImport.setEndDateFinancialPeriod(endDate); - closedPeriodicEntryBookImport.setCodeEntryBook(entryBookCode); + public void importClosedPeriodicEntryBookCSV(String[] nextLine, + List<ClosedPeriodicEntryBookImport> closedPeriodicEntryBooks, + TopiaContext topiaContext) throws LimaException { + String locked = nextLine[1]; + String beginDate = nextLine[2]; + String endDate = nextLine[3]; + String entryBookCode = nextLine[4]; - closedPeriodicEntryBooks.add(closedPeriodicEntryBookImport); - } + if (new Boolean(locked)) { + ClosedPeriodicEntryBookImport closedPeriodicEntryBookImport = new ClosedPeriodicEntryBookImportImpl(); + closedPeriodicEntryBookImport.setLocked(locked); + closedPeriodicEntryBookImport + .setBeginDateFinancialPeriod(beginDate); + closedPeriodicEntryBookImport.setEndDateFinancialPeriod(endDate); + closedPeriodicEntryBookImport.setCodeEntryBook(entryBookCode); + + closedPeriodicEntryBooks.add(closedPeriodicEntryBookImport); + } } - - + /** - * Import and create financialstatement - * Structure : TYPE | label | header | accounts | debitAccount | creditAccount - * | provisitionDeprecationAccounts | subAmount | headerAmount | masterFinancialStatement - */ - public String importFinancialsStatementChartCSV(String[] nextLine, Map<String, FinancialStatementImport> financialStatements, TopiaContext topiaContext) throws LimaException { + * Import and create financialstatement Structure : TYPE | label | header + * | accounts | debitAccount | creditAccount | + * provisitionDeprecationAccounts | subAmount | headerAmount + * | masterFinancialStatement + */ + + public String importFinancialsStatementChartCSV(String[] nextLine, + LinkedHashMap<String, ArrayList<FinancialStatementImport>> financialStatements, + TopiaContext topiaContext) throws LimaException { String result = ""; - - String label = nextLine[1]; - String header = nextLine[2]; - String accounts = nextLine[3]; - String debitAccounts = nextLine[4]; - String creditAccounts = nextLine[5]; - String provisionDeprecationAccounts = nextLine[6]; - String subAmount = nextLine[7]; - String headerAmount = nextLine[8]; - String masterFinancialStatement = nextLine[9]; - - try { - FinancialStatementDAO financialStatementDAO = - LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); - - //if exist, skip - if (financialStatementDAO.findByLabel(label) == null){ - //create it - FinancialStatementImport financialStatementImport = - new FinancialStatementImportImpl(); - financialStatementImport.setLabel(label); - financialStatementImport.setHeader(header); - financialStatementImport.setAccounts(accounts); - financialStatementImport.setCreditAccounts(creditAccounts); - financialStatementImport.setDebitAccounts(debitAccounts); - financialStatementImport.setHeaderAmount(headerAmount); - financialStatementImport.setProvisionDeprecationAccounts( - provisionDeprecationAccounts); - financialStatementImport.setSubAmount(subAmount); - financialStatementImport.setMasterFinancialStatement( - masterFinancialStatement); - - // put it in hashset - financialStatements.put(label, financialStatementImport); - } - else { - result += "FAILED : The financialstatement " - + label + " already exists !\n"; - } - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); + + String label = nextLine[1]; + String header = nextLine[2]; + String accounts = nextLine[3]; + String debitAccounts = nextLine[4]; + String creditAccounts = nextLine[5]; + String provisionDeprecationAccounts = nextLine[6]; + String subAmount = nextLine[7]; + String headerAmount = nextLine[8]; + String masterFinancialStatement = nextLine[9]; + + try { + FinancialStatementDAO financialStatementDAO = LimaCallaoDAOHelper + .getFinancialStatementDAO(topiaContext); + + // if exist, skip + if (financialStatementDAO.findByLabel(label) == null) { + // create it + FinancialStatementImport financialStatementImport = new FinancialStatementImportImpl(); + financialStatementImport.setLabel(label); + financialStatementImport.setHeader(header); + financialStatementImport.setAccounts(accounts); + financialStatementImport.setCreditAccounts(creditAccounts); + financialStatementImport.setDebitAccounts(debitAccounts); + financialStatementImport.setHeaderAmount(headerAmount); + financialStatementImport + .setProvisionDeprecationAccounts(provisionDeprecationAccounts); + financialStatementImport.setSubAmount(subAmount); + financialStatementImport + .setMasterFinancialStatement(masterFinancialStatement); + + // put it in hashlinkedlist + if (financialStatements.containsKey(label)){ + financialStatements.get(label).add(financialStatementImport); + } + else { + List<FinancialStatementImport> list = new ArrayList<FinancialStatementImport>(); + list.add(financialStatementImport); + financialStatements.put(label, (ArrayList<FinancialStatementImport>) list); + } + } else { + result += "FAILED : The financialstatement " + label + + " already exists !\n"; + } + } catch (TopiaException eeeTE) { + doCatch(topiaContext, eeeTE, log); } return result; } - /** - * Import and create financialtransactions - * Structue : TYPE | NumTransac | TransactionDate | AmountDebit | AmountCredit - * | FinancialPeriod BeginDate | FinancialPeriod EndDate | EntryBook Code + * Import and create financialtransactions Structue : TYPE | NumTransac | + * TransactionDate | AmountDebit | AmountCredit | FinancialPeriod BeginDate + * | FinancialPeriod EndDate | EntryBook Code */ - public void importFinancialTransactionsCSV(String[] nextLine, Map<Integer, FinancialTransactionImport> financialTransactions, TopiaContext topiaContext) throws LimaException { - int num = new Integer(nextLine[1]); - FinancialTransactionImport financialTransactionImport = new FinancialTransactionImportImpl(); - financialTransactionImport.setDate(nextLine[2]); - financialTransactionImport.setAmountDebit(nextLine[3]); - financialTransactionImport.setAmountCredit(nextLine[4]); - financialTransactionImport.setBeginDateFinancialPeriod(nextLine[5]); - financialTransactionImport.setEndDateFinancialPeriod(nextLine[6]); - financialTransactionImport.setCodeEntryBook(nextLine[7]); - - financialTransactions.put(num, financialTransactionImport); + public void importFinancialTransactionsCSV(String[] nextLine, + Map<Integer, FinancialTransactionImport> financialTransactions, + TopiaContext topiaContext) throws LimaException { + int num = new Integer(nextLine[1]); + FinancialTransactionImport financialTransactionImport = new FinancialTransactionImportImpl(); + financialTransactionImport.setDate(nextLine[2]); + financialTransactionImport.setAmountDebit(nextLine[3]); + financialTransactionImport.setAmountCredit(nextLine[4]); + financialTransactionImport.setBeginDateFinancialPeriod(nextLine[5]); + financialTransactionImport.setEndDateFinancialPeriod(nextLine[6]); + financialTransactionImport.setCodeEntryBook(nextLine[7]); + + financialTransactions.put(num, financialTransactionImport); } - - + /** - * Import and create entries - * Structure : TYPE | NumTransac | Description | Amount | Debit | Lettering | Detail | - * Voucher | Position | FinancialTransaction Date | FinancialTransaction EntryBookCode | + * Import and create entries Structure : TYPE | NumTransac | Description | + * Amount | Debit | Lettering | Detail | Voucher | Position + * | FinancialTransaction Date | FinancialTransaction EntryBookCode | * FinancialTransaction AmountDebit | FinancialTransaction AmountCredit */ - public void importEntriesCSV(String[] nextLine, Map<Integer, List<EntryImport>> entries, TopiaContext topiaContext) throws LimaException { - int num = new Integer(nextLine[1]); - - EntryImport entryImport = new EntryImportImpl(); - entryImport.setDescription(nextLine[2]); - entryImport.setAmount(nextLine[3]); - entryImport.setDebit(nextLine[4]); - entryImport.setLettering(nextLine[5]); - entryImport.setDetail(nextLine[6]); - entryImport.setVoucher(nextLine[7]); - entryImport.setPosition(nextLine[8]); - entryImport.setAccount(nextLine[9]); - - if (entries.containsKey(num)){ - List<EntryImport> entryImports = entries.get(num); - entryImports.add(entryImport); - } - else { - List<EntryImport> entryImports = new ArrayList<EntryImport>(); - entryImports.add(entryImport); - entries.put(num, entryImports); - } - } - - - //################ CREATE ENTITY IN DB FOR IMPORT ################ - - - public String createFinancialStatements(Map<String, FinancialStatementImport> financialStatements, TopiaContext topiaContext) throws LimaException { - String result = ""; - try { - - FinancialStatementDAO financialStatementDAO = - LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); - - while (financialStatements.size() > 0){ - for (Iterator<FinancialStatementImport> itr = financialStatements.values().iterator(); itr.hasNext();){ - FinancialStatementImport financialStatementImport = itr.next(); - String masterFinancialStatementLabel = - financialStatementImport.getMasterFinancialStatement(); - FinancialStatement masterFinancialStatement = - financialStatementDAO.findByLabel( - masterFinancialStatementLabel); - - if (masterFinancialStatementLabel.equals("") - || masterFinancialStatement != null){ - //create it - FinancialStatement financialStatement = - new FinancialStatementImpl(); - financialStatement.setLabel( - financialStatementImport.getLabel()); - financialStatement.setHeader(Boolean.parseBoolean( - financialStatementImport.getHeader())); - financialStatement.setAccounts( - financialStatementImport.getAccounts()); - financialStatement.setDebitAccounts( - financialStatementImport.getDebitAccounts()); - financialStatement.setCreditAccounts( - financialStatementImport.getCreditAccounts()); - financialStatement.setProvisionDeprecationAccounts( - financialStatementImport. - getProvisionDeprecationAccounts()); - financialStatement.setSubAmount(Boolean.parseBoolean( - financialStatementImport.getSubAmount())); - financialStatement.setHeaderAmount(Boolean.parseBoolean( - financialStatementImport.getHeaderAmount())); + public void importEntriesCSV(String[] nextLine, + Map<Integer, List<EntryImport>> entries, TopiaContext topiaContext) + throws LimaException { + int num = new Integer(nextLine[1]); - financialStatementService.createFinancialStatementWithTransaction( - masterFinancialStatement, financialStatement, topiaContext); - - result += "SUCCESS : The financialStatement " + - financialStatementImport.getLabel() + " is created ! \n"; - itr.remove(); - } - else if (!financialStatements.containsKey(masterFinancialStatementLabel)){ - result += "FAILED : The financialStatement " + - financialStatementImport.getLabel() + - " have masterFinancialStatement : " + - masterFinancialStatementLabel + "which not exist \n"; - itr.remove(); - } - } - } - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); + EntryImport entryImport = new EntryImportImpl(); + entryImport.setDescription(nextLine[2]); + entryImport.setAmount(nextLine[3]); + entryImport.setDebit(nextLine[4]); + entryImport.setLettering(nextLine[5]); + entryImport.setDetail(nextLine[6]); + entryImport.setVoucher(nextLine[7]); + entryImport.setPosition(nextLine[8]); + entryImport.setAccount(nextLine[9]); + + if (entries.containsKey(num)) { + List<EntryImport> entryImports = entries.get(num); + entryImports.add(entryImport); + } else { + List<EntryImport> entryImports = new ArrayList<EntryImport>(); + entryImports.add(entryImport); + entries.put(num, entryImports); } - return result; } - - public String createFiscalPeriod(List<FiscalPeriod> fiscalPeriods, TopiaContext topiaContext){ + + // ################ CREATE ENTITY IN DB FOR IMPORT ################ + + public String createFinancialStatements(LinkedHashMap<String, ArrayList<FinancialStatementImport>> financialStatements, + TopiaContext topiaContext) throws LimaException { String result = ""; - for (FiscalPeriod fiscalPeriod : fiscalPeriods) { - //create fiscalPeriod - try { - fiscalPeriodService.createFiscalPeriodWithTransaction(fiscalPeriod, topiaContext); - result += "SUCCESS : The fiscalPeriod " + - fiscalPeriod.getBeginDate()+"-"+fiscalPeriod.getEndDate() + " is created ! \n"; + try { + + FinancialStatementDAO financialStatementDAO = LimaCallaoDAOHelper + .getFinancialStatementDAO(topiaContext); + + while (financialStatements.size() > 0) { + for (Iterator<ArrayList<FinancialStatementImport>> itr = financialStatements + .values().iterator(); itr.hasNext();) { + List<FinancialStatementImport> financialStatementImports = + itr.next(); + + for (Iterator<FinancialStatementImport> itr2 = financialStatementImports.iterator(); itr2.hasNext();) { + FinancialStatementImport financialStatementImport = + itr2.next(); + log.debug(financialStatementImport.getLabel()); + String masterFinancialStatementLabel = financialStatementImport + .getMasterFinancialStatement(); + FinancialStatement masterFinancialStatement = financialStatementDAO + .findByLabel(masterFinancialStatementLabel); + + if (masterFinancialStatementLabel.equals("") + || masterFinancialStatement != null) { + // create it + FinancialStatement financialStatement = new FinancialStatementImpl(); + financialStatement.setLabel(financialStatementImport + .getLabel()); + financialStatement.setHeader(Boolean + .parseBoolean(financialStatementImport + .getHeader())); + financialStatement.setAccounts(financialStatementImport + .getAccounts()); + financialStatement + .setDebitAccounts(financialStatementImport + .getDebitAccounts()); + financialStatement + .setCreditAccounts(financialStatementImport + .getCreditAccounts()); + financialStatement + .setProvisionDeprecationAccounts(financialStatementImport + .getProvisionDeprecationAccounts()); + financialStatement.setSubAmount(Boolean + .parseBoolean(financialStatementImport + .getSubAmount())); + financialStatement.setHeaderAmount(Boolean + .parseBoolean(financialStatementImport + .getHeaderAmount())); + + financialStatementService + .createFinancialStatementWithTransaction( + masterFinancialStatement, + financialStatement, topiaContext); + + result += "SUCCESS : The financialStatement " + + financialStatementImport.getLabel() + + " is created ! \n"; + + itr2.remove(); + } else if (!financialStatements + .containsKey(masterFinancialStatementLabel)) { + result += "FAILED : The financialStatement " + + financialStatementImport.getLabel() + + " have masterFinancialStatement : " + + masterFinancialStatementLabel + + "which not exist \n"; + itr2.remove(); + } + } + if (financialStatementImports.isEmpty()){ + itr.remove(); + } } - catch (LimaException eee){ - result += "FAILED : "+eee+" \n"; - } } + } catch (TopiaException eeeTE) { + doCatch(topiaContext, eeeTE, log); + } return result; } - public String createAccounts(Map<String, AccountImport> accounts, TopiaContext topiaContext) throws LimaException { - String result = ""; + public String createFiscalPeriod(List<FiscalPeriod> fiscalPeriods, + TopiaContext topiaContext) { + String result = ""; + for (FiscalPeriod fiscalPeriod : fiscalPeriods) { + // create fiscalPeriod + try { + fiscalPeriodService.createFiscalPeriodWithTransaction( + fiscalPeriod, topiaContext); + result += "SUCCESS : The fiscalPeriod " + + fiscalPeriod.getBeginDate() + "-" + + fiscalPeriod.getEndDate() + " is created ! \n"; + } catch (LimaException eee) { + result += "FAILED : " + eee + " \n"; + } + } + return result; + } - 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()); - - if (generalLedger != null){ - accountService.createSubLedgerWithTransaction(generalLedger, account, topiaContext); - } - else { - accountService.createAccountWithTransaction(masterAccount, account, topiaContext); - } - result += "SUCCESS : The account " + - accountImport.getAccountNumber() + " is created ! \n"; - itr.remove(); - } - else if (!accounts.containsKey(masterAccountNumber) - && !accounts.containsKey(generalLedgerNumber) ){ - result += "FAILED : The account " + - accountImport.getAccountNumber() + " have masterAccount : " + - masterAccountNumber + "which not exist \n"; - itr.remove(); - } - } - } - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); + public String createAccounts(Map<String, AccountImport> accounts, + TopiaContext topiaContext) throws LimaException { + String result = ""; + + 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()); + + if (generalLedger != null) { + accountService.createSubLedgerWithTransaction( + generalLedger, account, topiaContext); + } else { + accountService.createAccountWithTransaction( + masterAccount, account, topiaContext); + } + result += "SUCCESS : The account " + + accountImport.getAccountNumber() + + " is created ! \n"; + itr.remove(); + } else if (!accounts.containsKey(masterAccountNumber) + && !accounts.containsKey(generalLedgerNumber)) { + result += "FAILED : The account " + + accountImport.getAccountNumber() + + " have masterAccount : " + + masterAccountNumber + "which not exist \n"; + itr.remove(); + } + } + } + } catch (TopiaException eeeTE) { + doCatch(topiaContext, eeeTE, log); } return result; } - public String updateClosedPeriodicEntryBooks (List<ClosedPeriodicEntryBookImport> closedPeriodicEntryBooks, TopiaContext topiaContext) throws LimaException { - String result=""; - + public String updateClosedPeriodicEntryBooks( + List<ClosedPeriodicEntryBookImport> closedPeriodicEntryBooks, + TopiaContext topiaContext) throws LimaException { + String result = ""; + try { - FinancialPeriodDAO financialPeriodDAO = - LimaCallaoDAOHelper.getFinancialPeriodDAO(topiaContext); - EntryBookDAO entryBookDAO = - LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); - ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = - LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(topiaContext); + FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper + .getFinancialPeriodDAO(topiaContext); + EntryBookDAO entryBookDAO = LimaCallaoDAOHelper + .getEntryBookDAO(topiaContext); + ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = LimaCallaoDAOHelper + .getClosedPeriodicEntryBookDAO(topiaContext); for (ClosedPeriodicEntryBookImport closedPeriodicEntryBookImport : closedPeriodicEntryBooks) { - //update closedPeriodicEntryBook - Date beginDateFinancialPeriod = - SDateFormat.parse(closedPeriodicEntryBookImport.getBeginDateFinancialPeriod()); - Date endDateFinancialPeriod = - SDateFormat.parse(closedPeriodicEntryBookImport.getEndDateFinancialPeriod()); - FinancialPeriod financialPeriod = - financialPeriodDAO.findByNaturalId(beginDateFinancialPeriod, endDateFinancialPeriod); - String codeEntryBook = closedPeriodicEntryBookImport.getCodeEntryBook(); - EntryBook entryBook = entryBookDAO.findByCode(codeEntryBook); - ClosedPeriodicEntryBook closedPeriodicEntryBook = - closedPeriodicEntryBookDAO.findbyEntryBookAndFinancialPeriod(entryBook, financialPeriod); - try { - financialPeriodService.blockClosedPeriodicEntryBookWithTransaction(closedPeriodicEntryBook, topiaContext); - result += "SUCCESS : The blockClosedPeriodicEntryBook " + - beginDateFinancialPeriod + "-" + endDateFinancialPeriod + ", " + - codeEntryBook + " is updated ! \n"; - } - catch (LimaException eee){ - result += "FAILED : "+eee+" \n"; - } + // update closedPeriodicEntryBook + Date beginDateFinancialPeriod = SDateFormat + .parse(closedPeriodicEntryBookImport + .getBeginDateFinancialPeriod()); + Date endDateFinancialPeriod = SDateFormat + .parse(closedPeriodicEntryBookImport + .getEndDateFinancialPeriod()); + FinancialPeriod financialPeriod = financialPeriodDAO + .findByNaturalId(beginDateFinancialPeriod, + endDateFinancialPeriod); + String codeEntryBook = closedPeriodicEntryBookImport + .getCodeEntryBook(); + EntryBook entryBook = entryBookDAO.findByCode(codeEntryBook); + ClosedPeriodicEntryBook closedPeriodicEntryBook = closedPeriodicEntryBookDAO + .findbyEntryBookAndFinancialPeriod(entryBook, + financialPeriod); + try { + financialPeriodService + .blockClosedPeriodicEntryBookWithTransaction( + closedPeriodicEntryBook, topiaContext); + result += "SUCCESS : The blockClosedPeriodicEntryBook " + + beginDateFinancialPeriod + "-" + + endDateFinancialPeriod + ", " + codeEntryBook + + " is updated ! \n"; + } catch (LimaException eee) { + result += "FAILED : " + eee + " \n"; + } } - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); - } - catch (ParseException eeePE) { - if(log.isDebugEnabled()){ + } catch (TopiaException eeeTE) { + doCatch(topiaContext, eeeTE, log); + } catch (ParseException eeePE) { + if (log.isDebugEnabled()) { log.debug("Can't parse date", eeePE); } } return result; } - public String createFinancialTransactionsAndEntries (Map<Integer, FinancialTransactionImport> financialTransactions, Map<Integer, List<EntryImport>> entries, TopiaContext topiaContext) throws LimaException { + public String createFinancialTransactionsAndEntries( + Map<Integer, FinancialTransactionImport> financialTransactions, + Map<Integer, List<EntryImport>> entries, TopiaContext topiaContext) + throws LimaException { String result = ""; try { - EntryBookDAO entryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); + EntryBookDAO entryBookDAO = LimaCallaoDAOHelper + .getEntryBookDAO(topiaContext); EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); - FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper.getFinancialPeriodDAO(topiaContext); - FinancialTransactionDAO financialTransactionDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(topiaContext); - - for (Map.Entry<Integer, FinancialTransactionImport> map : financialTransactions.entrySet() ){ - FinancialTransactionImport financialTransactionImport = map.getValue(); + FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper + .getFinancialPeriodDAO(topiaContext); + FinancialTransactionDAO financialTransactionDAO = LimaCallaoDAOHelper + .getFinancialTransactionDAO(topiaContext); + AccountDAO accountDAO = LimaCallaoDAOHelper + .getAccountDAO(topiaContext); + + for (Map.Entry<Integer, FinancialTransactionImport> map : financialTransactions + .entrySet()) { + FinancialTransactionImport financialTransactionImport = map + .getValue(); FinancialTransaction financialTransaction = new FinancialTransactionImpl(); - Date dateFinancialTransaction = SDateFormat.parse(financialTransactionImport.getDate()); - financialTransaction.setTransactionDate(dateFinancialTransaction); - financialTransaction.setAmountDebit(new Double(financialTransactionImport.getAmountDebit())); - financialTransaction.setAmountCredit(new Double(financialTransactionImport.getAmountCredit())); - EntryBook entryBook = entryBookDAO.findByCode(financialTransactionImport.getCodeEntryBook()); + Date dateFinancialTransaction = SDateFormat + .parse(financialTransactionImport.getDate()); + financialTransaction + .setTransactionDate(dateFinancialTransaction); + financialTransaction.setAmountDebit(new Double( + financialTransactionImport.getAmountDebit())); + financialTransaction.setAmountCredit(new Double( + financialTransactionImport.getAmountCredit())); + EntryBook entryBook = entryBookDAO + .findByCode(financialTransactionImport + .getCodeEntryBook()); financialTransaction.setEntryBook(entryBook); - - FinancialPeriod financialPeriod = financialPeriodDAO.findByDate(dateFinancialTransaction); - + + FinancialPeriod financialPeriod = financialPeriodDAO + .findByDate(dateFinancialTransaction); + financialTransactionDAO.create(financialTransaction); financialPeriod.addFinancialTransaction(financialTransaction); - + List<EntryImport> entryImports = entries.get(map.getKey()); for (EntryImport entryImport : entryImports) { Entry entry = new EntryImpl(); - Account account = accountDAO.findByAccountNumber(entryImport.getAccount()); + Account account = accountDAO + .findByAccountNumber(entryImport.getAccount()); entry.setAccount(account); entry.setDescription(entryImport.getDescription()); entry.setAmount(new Double(entryImport.getAmount())); @@ -1028,60 +1107,60 @@ financialTransaction.addEntry(entry); } } - } - catch (TopiaException eeeTE){ - doCatch(topiaContext, eeeTE, log); - } - catch (ParseException eeePE) { - if(log.isDebugEnabled()){ + } catch (TopiaException eeeTE) { + doCatch(topiaContext, eeeTE, log); + } catch (ParseException eeePE) { + if (log.isDebugEnabled()) { log.debug("Can't parse date", eeePE); } } return result; } - - public String importIdentity(String[] nextLine, TopiaContext topiaContext) throws LimaException { + + public String importIdentity(String[] nextLine, TopiaContext topiaContext) + throws LimaException { String result = ""; - - Identity identity = new IdentityImpl(); - nextLine[0] = ImportExportEntityEnum.IDENTITY.getLabel(); - identity.setName(nextLine[1]); - identity.setDescription(nextLine[2]); - identity.setAddress(nextLine[3]); - identity.setAddress2(nextLine[4]); - identity.setCity(nextLine[5]); - identity.setPhoneNumber(nextLine[6]); - identity.setEmail(nextLine[7]); - identity.setZipCode(nextLine[8]); - identity.setVatNumber(nextLine[9]); - identity.setClassificationCode(nextLine[10]); - identity.setBusinessNumber(nextLine[11]); - - identityService.updateIdentityWithTransaction(identity, topiaContext); - //create it - result += "SUCCESS : The identity " + - identity.getName() + " is created ! \n"; + Identity identity = new IdentityImpl(); + nextLine[0] = ImportExportEntityEnum.IDENTITY.getLabel(); + identity.setName(nextLine[1]); + identity.setDescription(nextLine[2]); + identity.setAddress(nextLine[3]); + identity.setAddress2(nextLine[4]); + identity.setCity(nextLine[5]); + identity.setPhoneNumber(nextLine[6]); + identity.setEmail(nextLine[7]); + identity.setZipCode(nextLine[8]); + identity.setVatNumber(nextLine[9]); + identity.setClassificationCode(nextLine[10]); + identity.setBusinessNumber(nextLine[11]); + + identityService.updateIdentityWithTransaction(identity, topiaContext); + // create it + result += "SUCCESS : The identity " + identity.getName() + + " is created ! \n"; + return result; } - - protected TopiaContext beginTransaction() throws TopiaException { - // basic check done, make check in database - // TODO move it into JTA - TopiaContext topiaTransaction; - topiaTransaction = rootContext.beginTransaction(); - log.trace("beginTransaction"+topiaTransaction); - return topiaTransaction; - } - - protected void commitTransaction(TopiaContext topiaTransaction) throws TopiaException { - try { - topiaTransaction.commitTransaction(); - } catch (TopiaException eee) { - if (log.isErrorEnabled()) { - log.error("Error during commit context", eee); - } - throw eee; - } - } + + protected TopiaContext beginTransaction() throws TopiaException { + // basic check done, make check in database + // TODO move it into JTA + TopiaContext topiaTransaction; + topiaTransaction = rootContext.beginTransaction(); + log.trace("beginTransaction" + topiaTransaction); + return topiaTransaction; + } + + protected void commitTransaction(TopiaContext topiaTransaction) + throws TopiaException { + try { + topiaTransaction.commitTransaction(); + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.error("Error during commit context", eee); + } + throw eee; + } + } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java 2010-07-26 16:32:09 UTC (rev 2986) +++ trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java 2010-07-28 09:02:22 UTC (rev 2987) @@ -32,6 +32,8 @@ import org.apache.openejb.assembler.classic.Assembler; import org.apache.openejb.loader.SystemInstance; import org.chorem.lima.LimaMain; +import org.chorem.lima.business.ServiceMonitorable; +import org.chorem.lima.business.ejb.AbstractLimaService; /** * This class is a service factory based on embedded openejb container. @@ -87,8 +89,8 @@ return instance; } - public <M> M getService(Class<M> serviceMonitorableClass){ - M result = (M)services.get(serviceMonitorableClass); + public <M> M getService(Class<M> serviceMonitorableClass){ + M result = (M) services.get(serviceMonitorableClass); if (result == null) { Object ejbHome = null; String serviceName = serviceMonitorableClass.getSimpleName().replace("Monitorable", "ImplRemote"); @@ -100,9 +102,8 @@ } } InvocationHandler handler = new ServiceMonitorableHandler(ejbHome); - result = (M) Proxy.newProxyInstance( - serviceMonitorableClass.getClassLoader(), - new Class[]{serviceMonitorableClass}, handler); + result = (M) Proxy.newProxyInstance( serviceMonitorableClass.getClassLoader(), new Class[]{serviceMonitorableClass}, handler); + services.put(serviceMonitorableClass, result); } return result;