/**
   * Determine if person has a specific Role in organization person Chart.
   *
   * @param person person
   * @param function person's function
   */
  private void defineDetailledChartRoles(OrganizationalPerson pers, String function) {

    // Priority to avoid conflicted syntaxes : central then categories
    boolean roleDefined = false;

    // central
    for (OrganizationalRole role : config.getPersonnsChartCentralLabel()) {
      if (isFunctionMatchingRole(function, role)) {
        pers.setVisibleOnCenter(true);
        pers.setVisibleCenterRole(role);
        roleDefined = true;
        break;
      }
    }

    // categories
    if (!roleDefined) {
      int order = 0;
      for (OrganizationalRole role : config.getPersonnsChartCategoriesLabel()) {
        if (isFunctionMatchingRole(function, role)) {
          pers.setVisibleCategory(new PersonCategory(role.getLabel(), role.getLdapKey(), order));
          roleDefined = true;
          break;
        }
        order++;
      }
    }

    if (!roleDefined) {
      pers.setVisibleCategory(new PersonCategory("Personnel"));
    }
  }
  /**
   * Get all distinct person categories represented by a given person list.
   *
   * @param personList the person list
   * @return a Set of PersonCategory
   */
  private Set<PersonCategory> getCategories(List<OrganizationalPerson> personList) {
    Set<PersonCategory> categories = new TreeSet<PersonCategory>();

    for (OrganizationalPerson person : personList) {
      // if person is a key Actor of organizationUnit, it will appear in main Cell, so ignore that
      // actor's category
      if (!person.isVisibleOnCenter() && person.getVisibleCategory() != null) {
        categories.add(person.getVisibleCategory());
      }
    }

    return categories;
  }
  private void defineChartRoles(OrganizationalPerson person, OrganizationalChartType type) {
    // defined the boxes with persons inside
    if (StringUtil.isDefined(person.getFonction())) {
      switch (type) {
        case TYPE_UNITCHART:
          defineUnitChartRoles(person, person.getFonction());
          break;

        default:
          defineDetailledChartRoles(person, person.getFonction());
          break;
      }
    } else {
      person.setVisibleCategory(new PersonCategory("Personnel"));
    }
  }
  /**
   * Determine if person has a specific Role in organization Chart.
   *
   * @param person person
   * @param function person's function
   */
  private void defineUnitChartRoles(OrganizationalPerson person, String function) {

    // Priority to avoid conflicted syntaxes : right, left and then central
    boolean roleDefined = false;

    // right
    for (OrganizationalRole role : config.getUnitsChartRightLabel()) {
      if (isFunctionMatchingRole(function, role)) {
        person.setVisibleOnRight(true);
        person.setVisibleRightRole(role);
        roleDefined = true;
        break;
      }
    }

    // left
    if (!roleDefined) {
      for (OrganizationalRole role : config.getUnitsChartLeftLabel()) {
        if (isFunctionMatchingRole(function, role)) {
          person.setVisibleOnLeft(true);
          person.setVisibleLeftRole(role);
          roleDefined = true;
          break;
        }
      }
    }

    // central
    if (!roleDefined) {
      for (OrganizationalRole role : config.getUnitsChartCentralLabel()) {
        if (isFunctionMatchingRole(function, role)) {
          person.setVisibleOnCenter(true);
          person.setVisibleCenterRole(role);
          roleDefined = true;
          break;
        }
      }
    }
  }
  private List<OrganizationalPerson> getOUMembers(String rootOu, OrganizationalChartType type) {

    List<OrganizationalPerson> personList = new ArrayList<OrganizationalPerson>();

    if (rootOu.equalsIgnoreCase("ou=Metallica,ou=Bands,dc=mondomain,dc=com")) {

      OrganizationalPerson person1 =
          new OrganizationalPerson(
              0, -1, "James Hetfield", "leader", "Une description", "Metallica", "hetfield");
      HashMap<String, String> person1Detail = new HashMap<String, String>();
      person1Detail.put("Instrument", "Chant & guitare");
      person1.setDetail(person1Detail);
      defineChartRoles(person1, type);
      personList.add(person1);

      OrganizationalPerson person2 =
          new OrganizationalPerson(
              1, -1, "Kirk Hammett", "musicien", "Une autre description", "Metallica", "hammett");
      Map<String, String> person2Detail = new HashMap<String, String>(1);
      person2Detail.put("Instrument", "Guitare");
      person2.setDetail(person2Detail);
      defineChartRoles(person2, type);
      personList.add(person2);

      OrganizationalPerson person21 =
          new OrganizationalPerson(
              2, -1, "Lars Ulrich", "musicien", "Une autre description", "Metallica", "ulrich");
      Map<String, String> person21Detail = new HashMap<String, String>(1);
      person21Detail.put("Instrument", "Batterie");
      person21.setDetail(person21Detail);
      defineChartRoles(person21, type);
      personList.add(person21);
    }
    Collections.sort(personList, new OrganizationalPersonComparator());
    return personList;
  }