コード例 #1
0
  @Override
  public List<Adult> matchAdults(Long externalHomeFolderId) throws CvqException {
    ExternalHomeFolder ehf =
        (ExternalHomeFolder) genericDAO.findById(ExternalHomeFolder.class, externalHomeFolderId);
    ExternalIndividual ehfr = ehf.getResponsible();

    if (ehfr == null) return new ArrayList<Adult>();

    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("firstName", ehfr.getFirstName());
    parameters.put("lastName", ehfr.getLastName());
    parameters.put("email", ehfr.getEmail());
    parameters.put("homePhone", ehfr.getHomePhone());
    parameters.put("address", ehf.getAddress());
    List<Adult> adults = adultDAO.matchAdults(parameters);
    List<Adult> responsibles = new ArrayList<Adult>();
    for (Adult adult : adults) {
      for (IndividualRole ir : adult.getIndividualRoles())
        if (ir.getRole().equals(RoleType.HOME_FOLDER_RESPONSIBLE)) responsibles.add(adult);
    }
    return responsibles;
  }
コード例 #2
0
 /*
     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;
 }