/**
   * 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"));
    }
  }
  @Override
  public OrganizationalChart getOrganizationChart(String baseOu, OrganizationalChartType type) {

    List<OrganizationalPerson> ouMembers = null;
    List<OrganizationalUnit> units = null;

    // beginning node of the search
    String rootOu = (StringUtil.isDefined(baseOu)) ? baseOu : config.getRoot();

    // Parent definition = top of the chart
    String[] ous = rootOu.split(",");
    String[] firstOu = ous[0].split("=");
    OrganizationalUnit root = new OrganizationalUnit(firstOu[1], rootOu);
    if (StringUtil.isDefined(baseOu)) {
      root.setParentName("Racine");
      root.setParentOu(config.getRoot());
    }

    // get members
    ouMembers = getOUMembers(rootOu, type);
    root.setHasMembers(!ouMembers.isEmpty());

    // get sub organization units
    if (type == OrganizationalChartType.TYPE_UNITCHART) {
      units = getSubOrganizationUnits(rootOu);
    }

    boolean silverpeasUserLinkable = StringUtil.isDefined(config.getDomainId());

    OrganizationalChart chart = null;
    switch (type) {
      case TYPE_UNITCHART:
        chart = new OrganizationalChart(root, units, ouMembers, silverpeasUserLinkable);
        break;

      default:
        Set<PersonCategory> categories = getCategories(ouMembers);
        chart = new OrganizationalChart(root, ouMembers, categories, silverpeasUserLinkable);
        break;
    }

    return chart;
  }
  /**
   * 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;
        }
      }
    }
  }
  @Override
  public void configure(OrganizationChartLDAPConfiguration config) {
    config.setRoot("OU=Bands,dc=mondomain,dc=com");
    config.setAttUnit("");
    List<OrganizationalRole> rightRoles = new ArrayList<OrganizationalRole>();
    rightRoles.add(new OrganizationalRole("Chanteurs", "chanteur"));
    config.setUnitsChartRightLabel(rightRoles);

    List<OrganizationalRole> leftRoles = new ArrayList<OrganizationalRole>();
    leftRoles.add(new OrganizationalRole("Musiciens", "musicien"));
    config.setUnitsChartLeftLabel(leftRoles);

    List<OrganizationalRole> centralCategory = new ArrayList<OrganizationalRole>();
    centralCategory.add(new OrganizationalRole("Leader", "leader"));
    config.setPersonnsChartCentralLabel(centralCategory);

    List<OrganizationalRole> categories = new ArrayList<OrganizationalRole>();
    categories.add(new OrganizationalRole("Musiciens", "musicien"));
    config.setPersonnsChartCategoriesLabel(categories);

    this.config = config;
  }