r2693 - trunk/lima-main/src/main/java/org/chorem/lima/csv
Author: rchapelet Date: 2009-08-27 11:18:03 +0200 (Thu, 27 Aug 2009) New Revision: 2693 Removed: trunk/lima-main/src/main/java/org/chorem/lima/csv/CSVEnum.java trunk/lima-main/src/main/java/org/chorem/lima/csv/CSVImport.java Log: Suppression du package csv (qui ne sert ?\195?\160 rien, n'ai jamais appel?\195?\169). L'import des fichiers csv se font tous dans le package org.chorem.lima.imports Deleted: trunk/lima-main/src/main/java/org/chorem/lima/csv/CSVEnum.java =================================================================== --- trunk/lima-main/src/main/java/org/chorem/lima/csv/CSVEnum.java 2009-08-26 15:17:26 UTC (rev 2692) +++ trunk/lima-main/src/main/java/org/chorem/lima/csv/CSVEnum.java 2009-08-27 09:18:03 UTC (rev 2693) @@ -1,5 +0,0 @@ -package org.chorem.lima.csv; - -public enum CSVEnum { - Journal, Compte, Debit, Libelle, Credit, DatSai, Piece -} Deleted: trunk/lima-main/src/main/java/org/chorem/lima/csv/CSVImport.java =================================================================== --- trunk/lima-main/src/main/java/org/chorem/lima/csv/CSVImport.java 2009-08-26 15:17:26 UTC (rev 2692) +++ trunk/lima-main/src/main/java/org/chorem/lima/csv/CSVImport.java 2009-08-27 09:18:03 UTC (rev 2693) @@ -1,96 +0,0 @@ -package org.chorem.lima.csv; - -import au.com.bytecode.opencsv.CSVReader; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.Main; -import org.chorem.lima.dto.AccountDTO; -import org.chorem.lima.dto.EntryDTO; -import org.chorem.lima.dto.JournalDTO; -import org.chorem.lima.dto.TransactionDTO; -import org.chorem.lima.dto.util.DTOHelper; -import org.chorem.lima.service.util.ServiceHelper; -import org.chorem.lima.util.Util; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.*; - -public class CSVImport { - - private static final Log log = LogFactory.getLog(CSVImport.class); - private CSVReader csvReader; - - public CSVImport(String path) { - //URL url = CSVImport.class.getResource(path); - try { - File f = new File(path); - csvReader = new CSVReader(new FileReader(f), ';'); - } catch ( FileNotFoundException e) - { - - } - } - - public CSVReader getCSVReader() throws FileNotFoundException { - return csvReader; - } - - public Collection<TransactionDTO> getAllTransaction() { - Map<String, TransactionDTO> map = new HashMap<String, TransactionDTO>(); - - // Header - try { - csvReader.readNext(); - // Transactions - String[] nextLine; - while ((nextLine = csvReader.readNext()) != null) { - log.debug("deb : "+nextLine); - String description = nextLine[CSVEnum.Libelle.ordinal()]; - log.debug(description); - String voucher = nextLine[CSVEnum.Piece.ordinal()]; - log.debug(voucher); - Date date = Util.stringToDate(nextLine[CSVEnum.DatSai.ordinal()], "dd/MM/yyyy"); - boolean debit = nextLine[CSVEnum.Credit.ordinal()].equals(DTOHelper.ZERO); - String amount = debit ? nextLine[CSVEnum.Debit.ordinal()] : nextLine[CSVEnum.Credit.ordinal()]; - - /** - * Account - */ - String accountId = nextLine[CSVEnum.Compte.ordinal()]; - AccountDTO accountDTO = ServiceHelper.findAccountById( - ServiceHelper.getAllFlatAccount(Main.getContext().getDataManager().getAccountModel().getData()), - accountId); - if (accountDTO == null) { - log.warn("Import : Account " + accountId + " does not exist."); - continue; - } - - /** - * Journal - */ - String journalId = nextLine[CSVEnum.Journal.ordinal()]; - JournalDTO journalDTO = ServiceHelper.findJournalById( - Main.getContext().getDataManager().getJournalModel().getData(), - journalId); - if (journalDTO == null) { - log.warn("Import : Journal " + journalId + " does not exist."); - continue; - } - - if (!map.containsKey(voucher)) { - // New Transaction - TransactionDTO trans = new TransactionDTO(null, null, date, voucher, description, journalDTO, new LinkedList<EntryDTO>(), null, null); - map.put(voucher, trans); - } - // Entry - TransactionDTO t = map.get(voucher); - t.addChild(new EntryDTO(null, description, amount, debit, null, accountDTO, null, null)); - } - } catch ( Exception e) {} - return map.values(); - } -}
participants (1)
-
rchapelet@users.chorem.org