private String getParentsEmails(IWContext iwc, User child) throws RemoteException {
    String emails = null;
    Email email;

    try {
      Collection parents = getMemberFamilyLogic(iwc).getCustodiansFor(child);

      if (parents != null && !parents.isEmpty()) {
        Iterator iterPar = parents.iterator();
        while (iterPar.hasNext()) {
          User parent = (User) iterPar.next();
          try {
            email = getCommuneUserBusiness(iwc).getUsersMainEmail(parent);
            if (email != null
                && email.getEmailAddress() != null
                && !email.getEmailAddress().equals(" ")) {
              if (emails != null) {
                emails = emails + ", " + email.getEmailAddress();
              } else {
                emails = email.getEmailAddress();
              }
            }
          } catch (NoEmailFoundException nef) {
            nef.printStackTrace();
          }
        }
      }
    } catch (NoCustodianFound ncf) {
    }
    return emails;
  }
  protected List<String> getEmails(Collection<User> users) {
    if (ListUtil.isEmpty(users)) {
      return null;
    }

    UserBusiness userBusiness = getUserBusiness();
    if (userBusiness == null) {
      return null;
    }

    List<String> emails = new ArrayList<String>(users.size());
    for (User user : users) {
      Email email = getEmail(user);
      String emailAddress = email == null ? null : email.getEmailAddress();
      if (!StringUtil.isEmpty(emailAddress) && !emails.contains(emailAddress)) {
        emails.add(emailAddress);
      }
    }

    return emails;
  }
  protected String getUserMail(Integer userId) {
    if (userId == null) {
      return null;
    }

    UserBusiness userBusiness = getUserBusiness();
    if (userBusiness == null) {
      return null;
    }

    User user = null;
    try {
      user = userBusiness.getUser(userId);
    } catch (Exception e) {
      LOGGER.log(Level.WARNING, "Error getting user by id: " + userId, e);
    }
    if (user == null) {
      return null;
    }

    Email email = getEmail(user);
    return email == null ? null : email.getEmailAddress();
  }
  protected String getAttributeValue(IWContext iwc, User user, String alias, String type) {
    if (OpenIDConstants.ATTRIBUTE_ALIAS_EMAIL.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_EMAIL.equals(type)) {
      Email email = null;
      try {
        email = getUserBusiness(iwc).getUsersMainEmail(user);
      } catch (NoEmailFoundException e) {
        /*No action...*/
      } catch (RemoteException e) {
        e.printStackTrace();
      }

      return (email != null ? email.getEmailAddress() : "");
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_PERSONAL_ID.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_PERSONAL_ID.equals(type)) {
      return (user.getPersonalID() != null ? user.getPersonalID() : "");
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_FULL_NAME.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_FULL_NAME.equals(type)) {
      return user.getName();
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_DATE_OF_BIRTH.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_DATE_OF_BIRTH.equals(type)) {
      return (user.getDateOfBirth() != null
          ? new IWTimestamp(user.getDateOfBirth()).toSQLDateString()
          : "");
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_GENDER.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_GENDER.equals(type)) {
      return (user.getGender() != null ? (user.getGender().isMaleGender() ? "M" : "F") : "");
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_NICKNAME.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_FRIENDLY_NAME.equals(type)) {
      return LoginDBHandler.getUserLogin(user).getUserLogin();
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_POSTCODE.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_POSTAL_CODE.equals(type)) {
      try {
        Address address = getUserBusiness(iwc).getUsersMainAddress(user);
        if (address != null) {
          PostalCode postal = address.getPostalCode();
          return postal != null ? postal.getPostalCode() : "";
        }
      } catch (RemoteException re) {
        re.printStackTrace();
      }
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_COUNTRY.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_COUNTRY.equals(type)) {
      try {
        Address address = getUserBusiness(iwc).getUsersMainAddress(user);
        if (address != null) {
          return address.getCountry().getIsoAbbreviation();
        }
      } catch (RemoteException re) {
        re.printStackTrace();
      }
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_LANGUAGE.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_LANGUAGE.equals(type)) {
      if (user.getPreferredLocale() != null) {
        Locale locale = LocaleUtil.getLocale(user.getPreferredLocale());
        return locale.getLanguage() + "-" + locale.getCountry();
      } else {
        try {
          Address address = getUserBusiness(iwc).getUsersMainAddress(user);
          if (address != null) {
            Country country = address.getCountry();
            return country.getIsoAbbreviation().toLowerCase() + "-" + country.getIsoAbbreviation();
          }
        } catch (RemoteException re) {
          re.printStackTrace();
        }
      }
    } else if (OpenIDConstants.ATTRIBUTE_ALIAS_TIMEZONE.equals(alias)
        || OpenIDConstants.ATTRIBUTE_TYPE_TIMEZONE.equals(type)) {
      try {
        Address address = getUserBusiness(iwc).getUsersMainAddress(user);
        if (address != null) {
          Country country = address.getCountry();
          Locale locale =
              new Locale(country.getIsoAbbreviation().toLowerCase(), country.getIsoAbbreviation());
          Calendar calendar = new GregorianCalendar(locale);

          return calendar.getTimeZone().getDisplayName(Locale.ENGLISH);
        }
      } catch (RemoteException re) {
        re.printStackTrace();
      }
    }

    return "";
  }
  /**
   * Send message and e-mail to all administrators for schools belonging to the specified
   * operational fields.
   *
   * @param subject the message subject
   * @param body the message body
   * @param operationalFields the operational field ids
   * @param onlyHomeCommune if true then messages are only sent to home commune schools
   * @return a collection of {school_name, headmaster}
   * @throws NoticeException if incomplete parameters or technical send error
   */
  public Collection sendNotice(
      String subject, String body, String[] operationalFields, boolean onlyHomeCommune)
      throws NoticeException {
    if (body.equals("")) {
      throw new NoticeException(KEY_EMPTY_BODY, DEFAULT_EMPTY_BODY);
    }
    if (body.length() > 4000) {
      body = body.substring(0, 4000);
    }
    if (operationalFields == null) {
      throw new NoticeException(KEY_OPERATIONAL_FIELDS_EMPTY, DEFAULT_OPERATIONAL_FIELDS_EMPTY);
    }
    Map schoolCategories = new HashMap();
    for (int i = 0; i < operationalFields.length; i++) {
      schoolCategories.put(operationalFields[i], operationalFields[i]);
    }
    int homeCommuneId = 0;
    try {
      CommuneHome communeHome = (CommuneHome) getIDOHome(Commune.class);
      Commune homeCommune = communeHome.findDefaultCommune();
      homeCommuneId = ((Integer) homeCommune.getPrimaryKey()).intValue();
    } catch (Exception e) {
    }

    Collection c = new ArrayList();
    try {
      SchoolBusiness sb = getSchoolBusiness();
      SchoolCategory childCareCategory = sb.getCategoryChildcare();
      String childCareCategoryId = childCareCategory.getCategory();
      HashMap messageReceivers = new HashMap();
      HashMap emailReceivers = new HashMap();
      Collection schoolTypes = sb.findAllSchoolTypes();
      Iterator iter = schoolTypes.iterator();
      while (iter.hasNext()) {
        SchoolType st = (SchoolType) iter.next();
        String sc = st.getSchoolCategory();
        if (!schoolCategories.containsKey(sc)) {
          continue;
        }
        int schoolTypeId = ((Integer) st.getPrimaryKey()).intValue();
        Collection schools = sb.findAllSchoolsByType(schoolTypeId);
        Iterator iter2 = schools.iterator();
        while (iter2.hasNext()) {
          School school = (School) iter2.next();
          if (onlyHomeCommune) {
            if (school.getCommuneId() != homeCommuneId) {
              continue;
            }
          }
          Collection users = sb.getSchoolUsers(school);
          Iterator iter3 = users.iterator();
          while (iter3.hasNext()) {
            SchoolUser schoolUser = (SchoolUser) iter3.next();
            User user = schoolUser.getUser();
            Provider provider = new Provider(school);
            if (!sc.equals(childCareCategoryId)
                || (!school.getCentralizedAdministration() && !provider.getPaymentByInvoice())) {
              if (messageReceivers.get(user.getPrimaryKey()) == null) {
                String[] s = new String[2];
                s[0] = school.getName();
                s[1] = user.getName();
                c.add(s);
                boolean sendEMail = true;
                Email email = getUserBusiness().getUserMail(user);
                String emailAddress = null;
                if (email != null) {
                  emailAddress = email.getEmailAddress();
                }
                if (emailAddress != null) {
                  if (emailReceivers.get(emailAddress) != null) {
                    sendEMail = false;
                  }
                  emailReceivers.put(emailAddress, user);
                }
                Message message =
                    getMessageBusiness()
                        .createUserMessage(
                            null, user, null, null, subject, body, body, false, null, false,
                            sendEMail);
                message.store();
                messageReceivers.put(user.getPrimaryKey(), user);
              }
            }
          }
        }
      }
    } catch (RemoteException e) {
      throw new NoticeException(KEY_SYSTEM_ERROR, DEFAULT_SYSTEM_ERROR);
    }
    return c;
  }