/*
    Account Id
    Account Value
    Account Date
    Account Label
    External Family Account Id
 */
 @Override
 public Map<String, Integer> importDepositAccounts(
     Long externalApplicationId, String broker, byte[] csvDatas)
     throws CvqModelException, CvqObjectNotFoundException {
   ExternalDepositAccountItem edai;
   ExternalHomeFolder ehf;
   ExternalApplication ea = getExternalApplicationById(externalApplicationId);
   Map<String, Integer> report = new HashMap<String, Integer>();
   report.put("created", 0);
   report.put("updated", 0);
   report.put("ignored", 0);
   try {
     CSVReader csvReader = new CSVReader(new StringReader(new String(csvDatas)), ',', '"', 1);
     for (Object o : csvReader.readAll()) {
       boolean updated = false;
       String[] line = (String[]) o;
       ehf =
           genericDAO
               .simpleSelect(ExternalHomeFolder.class)
               .and("externalId", line[4])
               .and("externalApplication", ea)
               .unique();
       if (ehf == null) {
         report.put("ignored", report.get("ignored") + 1);
         continue;
       }
       edai =
           genericDAO
               .simpleSelect(ExternalDepositAccountItem.class)
               .and("externalItemId", line[0])
               .and("externalApplicationId", String.valueOf(externalApplicationId))
               .unique();
       if (edai != null) {
         genericDAO.delete(edai);
         report.put("updated", report.get("updated") + 1);
         updated = true;
       }
       edai =
           new ExternalDepositAccountItem(
               line[3],
               Double.valueOf(line[1]),
               EXTERNAL_APPLICATION_LABEL,
               line[0],
               DateUtils.parseIso(line[2]),
               Double.valueOf(line[1]),
               broker);
       edai.setExternalApplicationId(ea.getId().toString());
       edai.setExternalHomeFolderId(ehf.getExternalId());
       genericDAO.create(edai);
       if (!updated) report.put("created", report.get("created") + 1);
     }
   } catch (Exception e) {
     logger.error(e.getMessage());
     e.printStackTrace();
     HibernateUtil.getSession().getTransaction().rollback();
     throw new CvqModelException("external.error.csvImport");
   }
   return report;
 }
 /*
    Account Id
    Holder Name
    Holder Surname
    Value
    Payment Date
    Payment Type
    Payment Ack
    Cvq Ack
    External Family Account Id
 */
 @Override
 public Map<String, Integer> importDepositAccountsDetails(
     Long externalApplicationId, byte[] csvDatas)
     throws CvqModelException, CvqObjectNotFoundException {
   ExternalDepositAccountItemDetail edaid;
   ExternalDepositAccountItem edai;
   Map<String, Integer> report = new HashMap<String, Integer>();
   report.put("created", 0);
   report.put("ignored", 0);
   List<ExternalDepositAccountItem> allDepositAccounts =
       genericDAO.simpleSelect(ExternalDepositAccountItem.class).list();
   for (ExternalDepositAccountItem depositAccount : allDepositAccounts) {
     depositAccount.getAccountDetails().clear();
     genericDAO.update(depositAccount);
   }
   try {
     CSVReader csvReader = new CSVReader(new StringReader(new String(csvDatas)), ',', '"', 1);
     for (Object o : csvReader.readAll()) {
       String[] line = (String[]) o;
       edai =
           genericDAO
               .simpleSelect(ExternalDepositAccountItem.class)
               .and("externalItemId", line[0])
               .and("externalApplicationId", String.valueOf(externalApplicationId))
               .unique();
       if (edai == null) {
         report.put("ignored", report.get("ignored") + 1);
         continue;
       }
       edaid =
           new ExternalDepositAccountItemDetail(
               DateUtils.parseIso(line[4]),
               line[1],
               line[2],
               Integer.valueOf(line[3]),
               line[5],
               line[0],
               null);
       edai.addAccountDetail(edaid);
       edaid.setExternalDepositAccountItem(edai);
       genericDAO.update(edai);
       report.put("created", report.get("created") + 1);
     }
   } catch (Exception e) {
     logger.error(e.getMessage());
     e.printStackTrace();
     HibernateUtil.getSession().getTransaction().rollback();
     throw new CvqModelException("external.error.csvImport");
   }
   return report;
 }