public void processCSVList(String url, String agency) throws IOException
{
InputStream inputStream = new URL(url).openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
CSVReader csvReader = new CSVReader(reader);
try
{
// sauter la ligne du header
csvReader.readNext();
List<String[]> csvLines = csvReader.readAll();
for(String[] info : csvLines)
{
Channel c = new Channel();
c.setDescription(info[CHANNEL_DESCRIPTION]);
c.setId(Integer.parseInt(info[CHANNEL_ID]));
Product p = new Product();
p.setId(Integer.parseInt(info[PRODUCT_ID]));
p.setName(info[PRODUCT_NAME]);
Customer cu = new Customer();
cu.setCity(info[CUSTOMER_CITY]);
cu.setFirstName(info[CUSTOMER_FIRSTNAME]);
cu.setGender(info[CUSTOMER_GENDER]);
cu.setId(Integer.valueOf(info[CUSTOMER_ID]));
cu.setIncomeLevel(info[CUSTOMER_INCOME_LEVEL]);
cu.setLastName(info[CUSTOMER_LASTNAME]);
cu.setMaritalStatus(info[CUSTOMER_MARITAL_STATUS]);
channelDAO.addChannel(c);
productDAO.addProduct(p);
customerDAO.addCustomer(cu);
Sale s = new Sale();
s.setAgency(agency);
s.setAmountSold(new BigDecimal(info[SALE_AMOUNT_SOLD]));
s.setChannel(c);
s.setCustomer(cu);
s.setId(Integer.valueOf(info[SALE_ID]));
s.setProduct(p);
s.setQuantitySold(new BigDecimal(info[SALE_QUANTITY_SOLD]));
SimpleDateFormat formatter = new SimpleDateFormat("y-M-d");
try
{
s.setTime(formatter.parse(info[SALE_TIME]));
}
catch (ParseException ex)
{
Logger.getLogger(CSVService.class.getName()).log(Level.SEVERE, null, ex);
}
saleDAO.addSale(s);
}
}
catch (Exception e)
{
Logger.getLogger(CSVService.class.getName()).log(Level.SEVERE, null, e);
}
finally
{
csvReader.close();
reader.close();
inputStream.close();
}
}