/*
    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;
 }
Exemple #2
0
 public List listAdultsByHomeFolder(final Long homeFolderId) {
   StringBuffer sb = new StringBuffer(100);
   sb.append("select adult from Adult as adult")
       .append(" join adult.homeFolder homeFolder")
       .append(" where homeFolder.id = ?");
   return HibernateUtil.getSession()
       .createQuery(sb.toString())
       .setLong(0, homeFolderId.longValue())
       .list();
 }
 /*
    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;
 }
 @SuppressWarnings("unchecked")
 public List<RecreationCenter> listAll() {
   return (List<RecreationCenter>)
       HibernateUtil.getSession().createQuery("from RecreationCenter as recreationCenter").list();
 }
 public RecreationCenter findByName(final String name) {
   Criteria crit = HibernateUtil.getSession().createCriteria(RecreationCenter.class);
   crit.add(Critere.compose("name", name, Critere.EQUALS));
   return (RecreationCenter) crit.uniqueResult();
 }
 /*
     External Individual Id
     Last Name
     First Name
     External Family Account Id
     Address
     Is Responsible
     Email
     Phone
 */
 @Override
 public Map<String, Integer> importHomeFolders(Long externalApplicationId, byte[] csvDatas)
     throws CvqModelException, CvqObjectNotFoundException {
   ExternalHomeFolder ehf;
   ExternalIndividual ei;
   ExternalApplication ea = getExternalApplicationById(externalApplicationId);
   Boolean created = false;
   Map<String, Integer> report = new HashMap<String, Integer>();
   report.put("created", 0);
   report.put("updated", 0);
   try {
     CSVReader csvReader = new CSVReader(new StringReader(new String(csvDatas)), ',', '"', 1);
     for (Object o : csvReader.readAll()) {
       String[] line = (String[]) o;
       ehf =
           genericDAO
               .simpleSelect(ExternalHomeFolder.class)
               .and("externalId", line[3])
               .and("externalApplication", ea)
               .unique();
       if (ehf == null) {
         ehf = new ExternalHomeFolder(line[3], ea, line[4]);
         ea.getExternalHomeFolders().add(ehf);
         genericDAO.create(ehf);
         modifyExternalApplication(ea);
         report.put("created", report.get("created") + 1);
         created = true;
       }
       ei =
           genericDAO
               .simpleSelect(ExternalIndividual.class)
               .and("externalId", line[0])
               .and("externalHomeFolder", ehf)
               .unique();
       if (ei == null) {
         ei =
             new ExternalIndividual(
                 line[0], line[1], line[2], line[6], line[7], "1".equals(line[5]) ? true : false);
         ei.setExternalHomeFolder(ehf);
         ehf.getIndividuals().add(ei);
         if (ei.isResponsible()) ehf.setAddress(line[4]);
         genericDAO.create(ei);
         genericDAO.update(ehf);
         if (!created) report.put("updated", report.get("updated") + 1);
       } else if (!ei.getLastName().equals(line[1])
           || !ei.getFirstName().equals(line[2])
           || (!ehf.getAddress().equals(StringUtils.upperCase(line[4])) && ei.isResponsible())) {
         ei.setLastName(line[1]);
         ei.setFirstName(line[2]);
         if (ei.isResponsible()) ehf.setAddress(line[4]);
         genericDAO.update(ei);
         genericDAO.update(ehf);
         report.put("updated", report.get("updated") + 1);
       }
       HibernateUtil.getSession().flush();
     }
   } catch (Exception e) {
     logger.error(e.getMessage());
     e.printStackTrace();
     HibernateUtil.getSession().getTransaction().rollback();
     throw new CvqModelException("external.error.csvImport");
   }
   return report;
 }
Exemple #7
0
 @Override
 public List<School> getActive() {
   return (List<School>)
       HibernateUtil.getSession().createQuery("from School as s where s.active = true").list();
 }
Exemple #8
0
 @SuppressWarnings("unchecked")
 public List<School> listAll() {
   return (List<School>) HibernateUtil.getSession().createQuery("from School as school").list();
 }