/**
   * Get group information with the given id from Silverpeas
   *
   * @param ddManager
   * @param sGroupId
   * @return
   * @throws AdminException
   */
  public Group getGroup(DomainDriverManager ddManager, String sGroupId) throws AdminException {
    try {
      ddManager.getOrganizationSchema();
      GroupRow gr = ddManager.getOrganization().group.getGroup(idAsInt(sGroupId));

      Group group = new Group();

      if (gr != null) {
        group.setId(idAsString(gr.id));
        group.setSpecificId(gr.specificId);
        group.setDomainId(idAsString(gr.domainId));
        group.setSuperGroupId(idAsString(gr.superGroupId));
        group.setName(gr.name);
        group.setDescription(gr.description);
        group.setRule(gr.rule);
      }
      // Get the selected users for this group
      setDirectUsersOfGroup(ddManager, group);

      return group;
    } catch (Exception e) {
      throw new AdminException(
          "GroupManager.getGroup",
          SilverpeasException.ERROR,
          "admin.EX_ERR_GET_GROUP",
          "group Id: '" + sGroupId + "'",
          e);
    } finally {
      ddManager.releaseOrganizationSchema();
    }
  }
  /**
   * Delete the group with the given Id The delete is apply recursively to the sub-groups
   *
   * @param ddManager
   * @param group
   * @param onlyInSilverpeas
   * @return
   * @throws AdminException
   */
  public String deleteGroupById(
      DomainDriverManager ddManager, Group group, boolean onlyInSilverpeas) throws AdminException {
    try {
      ddManager.getOrganizationSchema();
      if (group.getDomainId() != null && !onlyInSilverpeas) {
        ddManager.deleteGroup(group.getId());
      }
      // Delete the group node from Silverpeas
      ddManager.getOrganization().group.removeGroup(idAsInt(group.getId()));

      // Delete index of group information
      ddManager.unindexGroup(group.getId());

      return group.getId();
    } catch (Exception e) {
      SynchroReport.error(
          "GroupManager.deleteGroupById()",
          "problème lors de la suppression du groupe " + group.getName() + " - " + e.getMessage(),
          null);
      throw new AdminException(
          "GroupManager.deleteGroupById",
          SilverpeasException.ERROR,
          "admin.EX_ERR_DELETE_GROUP",
          "group Id: '" + group.getId() + "'",
          e);
    } finally {
      ddManager.releaseOrganizationSchema();
    }
  }
  public String removeDomain(String domainId) throws Exception {
    try {
      startTransaction(false);

      // Remove the domain
      getOrganization().domain.removeDomain(idAsInt(domainId));
      if (domainDriverInstances.get(domainId) != null) {
        domainDriverInstances.remove(domainId);
      }
      this.commit();
      LoginPasswordAuthentication.initDomains();

      return domainId;
    } catch (AdminException e) {
      try {
        this.rollback();
      } catch (Exception e1) {
        SilverTrace.error("admin", "DomainDriverManager.createDomain", "root.EX_ERR_ROLLBACK", e1);
      }
      throw new AdminException(
          "DomainDriverManager.createDomain",
          SilverpeasException.ERROR,
          "admin.EX_ERR_ADD_DOMAIN",
          "domain id: '" + domainId + "'",
          e);
    } finally {
      releaseOrganizationSchema();
    }
  }
 /**
  * Get Silverpeas admin organization
  *
  * @param ddManager
  * @return an array of AdminGroupInst containing the organization
  * @throws AdminException
  */
 public AdminGroupInst[] getAdminOrganization(DomainDriverManager ddManager)
     throws AdminException {
   try {
     ddManager.getOrganizationSchema();
     String[] asGroupIds = this.getAllGroupIds(ddManager);
     Group[] aGroup = new Group[asGroupIds.length];
     for (int nI = 0; nI < asGroupIds.length; nI++) {
       aGroup[nI] = this.getGroup(ddManager, asGroupIds[nI]);
     }
     // Search the root groups
     ArrayList<Integer> alRoot = new ArrayList<Integer>();
     for (int nI = 0; nI < aGroup.length; nI++) {
       if (aGroup[nI].getSuperGroupId() == null) {
         alRoot.add(nI);
       }
     }
     AdminGroupInst[] aAdminGroupInst = new AdminGroupInst[alRoot.size()];
     for (int nI = 0; nI < alRoot.size(); nI++) {
       aAdminGroupInst[nI] = new AdminGroupInst();
       aAdminGroupInst[nI].setGroup(aGroup[alRoot.get(nI)]);
       aAdminGroupInst[nI].setChildrenAdminGroupInst(
           this.getChildrenGroupInst(ddManager, aAdminGroupInst[nI].getGroup().getId(), aGroup));
     }
     return aAdminGroupInst;
   } catch (Exception e) {
     throw new AdminException(
         "GroupManager.getAdminOrganization",
         SilverpeasException.ERROR,
         "admin.EX_ERR_GET_ADMIN_ORGANIZATION",
         e);
   } finally {
     ddManager.releaseOrganizationSchema();
   }
 }
  /**
   * Get group information with the given group name
   *
   * @param ddManager
   * @param sGroupName
   * @param sDomainFatherId
   * @return
   * @throws AdminException
   */
  public Group getGroupByNameInDomain(
      DomainDriverManager ddManager, String sGroupName, String sDomainFatherId)
      throws AdminException {
    try {
      ddManager.getOrganizationSchema();
      Group group = ddManager.getGroupByNameInDomain(sGroupName, sDomainFatherId);

      if (group != null) {
        String specificId = group.getSpecificId();
        GroupRow gr =
            ddManager
                .getOrganization()
                .group
                .getGroupBySpecificId(idAsInt(sDomainFatherId), specificId);
        if (gr != null) {
          group.setId(idAsString(gr.id));
          // Get the selected users for this group
          setDirectUsersOfGroup(ddManager, group);
        } else {
          return null;
        }
      }
      return group;
    } catch (Exception e) {
      throw new AdminException(
          "GroupManager.getGroupByNameInDomain",
          SilverpeasException.ERROR,
          "admin.EX_ERR_GET_GROUP",
          "group Name: '" + sGroupName + "'",
          e);
    } finally {
      ddManager.releaseOrganizationSchema();
    }
  }
  /**
   * Delete given user from Silverpeas
   *
   * @param userId user Id
   * @throws Exception
   */
  @Override
  public void deleteUser(String userId) throws Exception {
    try {
      // Set the OrganizationSchema (if not already done)
      getOrganizationSchema();

      // Get the user information
      UserRow ur = getOrganization().user.getUser(idAsInt(userId));
      if (ur == null) {
        throw new AdminException(
            "DomainDriverManager.deleteUser",
            SilverpeasException.ERROR,
            "admin.EX_ERR_USER_NOT_FOUND",
            "user Id: '" + userId + "'");
      }
      // Get a DomainDriver instance
      DomainDriver domainDriver = this.getDomainDriver(ur.domainId);
      // Get User detail from specific domain
      domainDriver.deleteUser(ur.specificId);
      // Delete index to given user
      unindexUser(userId);
    } catch (AdminException e) {
      throw new AdminException(
          "DomainDriverManager.deleteUser",
          SilverpeasException.ERROR,
          "admin.EX_ERR_DELETE_USER",
          "user Id: '" + userId + "'",
          e);
    } finally {
      releaseOrganizationSchema();
    }
  }
 /**
  * Gets all the root user groups in Silverpeas.
  *
  * @param ddManager the manager of domain drivers in use in Silverpeas.
  * @return an array of root user groups.
  * @throws AdminException if an error occurs while getting the root groups.
  */
 public Group[] getAllRootGroups(DomainDriverManager ddManager) throws AdminException {
   try {
     ddManager.getOrganizationSchema();
     GroupRow[] rows = ddManager.getOrganization().group.getAllRootGroups();
     Group[] rootGroups;
     if (rows != null) {
       rootGroups = new Group[rows.length];
       for (int i = 0; i < rows.length; i++) {
         rootGroups[i] = groupRow2Group(rows[i]);
         setDirectUsersOfGroup(ddManager, rootGroups[i]);
       }
     } else {
       rootGroups = new Group[0];
     }
     return rootGroups;
   } catch (Exception e) {
     throw new AdminException(
         "GroupManager.getAllRootGroupIds",
         SilverpeasException.ERROR,
         "admin.EX_ERR_GET_ALL_ROOT_GROUP_IDS",
         e);
   } finally {
     ddManager.releaseOrganizationSchema();
   }
 }
 /**
  * @param ddManager
  * @param sDomainId
  * @return
  * @throws AdminException
  */
 public Group[] getRootGroupsOfDomain(DomainDriverManager ddManager, String sDomainId)
     throws AdminException {
   try {
     // Get organization
     ddManager.getOrganizationSchema();
     // Get groups of domain from Silverpeas database
     GroupRow[] grs =
         ddManager.getOrganization().group.getAllRootGroupsOfDomain(idAsInt(sDomainId));
     // Convert GroupRow objects in Group Object
     Group[] groups = new Group[grs.length];
     for (int nI = 0; nI < grs.length; nI++) {
       groups[nI] = groupRow2Group(grs[nI]);
       // Get the selected users for this group
       setDirectUsersOfGroup(ddManager, groups[nI]);
     }
     return groups;
   } catch (Exception e) {
     throw new AdminException(
         "GroupManager.getRootGroupsOfDomain",
         SilverpeasException.ERROR,
         "admin.EX_ERR_GET_GROUPS_OF_DOMAIN",
         "domain Id: '" + sDomainId + "'",
         e);
   } finally {
     ddManager.releaseOrganizationSchema();
   }
 }
  /**
   * @param groupId
   * @return Group[]
   */
  @Override
  public Group[] getGroups(String groupId) throws Exception {
    Group[] groups = null;

    try {
      // Set the OrganizationSchema (if not already done)
      getOrganizationSchema();

      // Get the user information
      GroupRow gr = getOrganization().group.getGroup(idAsInt(groupId));
      if (gr == null) {
        throw new AdminException(
            "DomainDriverManager.getGroups",
            SilverpeasException.ERROR,
            "admin.EX_ERR_GROUP_NOT_FOUND",
            "group Id: '" + groupId + "'");
      }

      // Get a DomainDriver instance
      DomainDriver domainDriver = this.getDomainDriver(gr.domainId);

      // Get Groups of Group from specific domain
      groups = domainDriver.getGroups(gr.specificId);
    } catch (AdminException e) {
      throw new AdminException(
          "DomainDriverManager.getGroups",
          SilverpeasException.ERROR,
          "admin.EX_ERR_GET_GROUPS",
          "father group Id: '" + groupId + "'",
          e);
    } finally {
      releaseOrganizationSchema();
    }
    return groups;
  }
  /**
   * /** Check if the given group exists
   *
   * @param ddManager
   * @param sName
   * @return true if a group with the given name
   * @throws AdminException
   */
  public boolean isGroupExist(DomainDriverManager ddManager, String sName) throws AdminException {
    try {
      ddManager.getOrganizationSchema();

      // build GroupRow to search
      GroupRow searchedGroup = new GroupRow();
      searchedGroup.specificId = null;
      searchedGroup.name = sName;
      searchedGroup.description = null;

      // search for group
      GroupRow[] group = ddManager.getOrganization().group.getAllMatchingGroups(searchedGroup);

      return (group.length > 0);
    } catch (Exception e) {
      throw new AdminException(
          "GroupManager.isGroupExist",
          SilverpeasException.ERROR,
          "admin.EX_ERR_IS_GROUP_EXIST",
          "group name: '" + sName + "'",
          e);
    } finally {
      ddManager.releaseOrganizationSchema();
    }
  }
  @Override
  public UserFull getUserFull(String userId) throws Exception {
    UserFull uf = null;
    try {
      // Set the OrganizationSchema (if not already done)
      getOrganizationSchema();
      // Get the user information
      UserRow ur = getOrganization().user.getUser(idAsInt(userId));
      if (ur == null) {
        throw new AdminException(
            "DomainDriverManager.getUser",
            SilverpeasException.ERROR,
            "admin.EX_ERR_USER_NOT_FOUND",
            "user Id: '" + userId + "'");
      }
      // Get a DomainDriver instance
      DomainDriver domainDriver = this.getDomainDriver(ur.domainId);
      // Get User detail from specific domain
      try {
        uf = domainDriver.getUserFull(ur.specificId);
      } catch (AdminException e) {
        SilverTrace.error(
            "admin",
            "DomainDriverManager.getUser",
            "admin.MSG_ERR_GET_USER",
            "user Id: '" + userId + "', domain Id: '" + ur.domainId + "'",
            e);
        uf = new UserFull(domainDriver);
        uf.setLogin(ur.login);
        uf.setFirstName(ur.firstName);
        uf.setLastName(ur.lastName);
        uf.seteMail(ur.eMail);
      }

      // Fill silverpeas info of user details
      uf.setLogin(ur.login);
      uf.setId(userId);
      uf.setSpecificId(ur.specificId);
      uf.setDomainId(idAsString(ur.domainId));
      uf.setAccessLevel(ur.accessLevel);
      uf.setLoginQuestion(ur.loginQuestion);
      uf.setLoginAnswer(ur.loginAnswer);
    } catch (AdminException e) {
      throw new AdminException(
          "DomainDriverManager.getUser",
          SilverpeasException.ERROR,
          "admin.EX_ERR_GET_USER",
          "user Id: '" + userId + "', domain Id: '" + userId + "'",
          e);
    } finally {
      releaseOrganizationSchema();
    }
    return uf;
  }
 public GroupRow[] getAllGroupOfDomain(String domainId) throws Exception {
   try {
     getOrganizationSchema();
     return getOrganization().group.getAllGroupsOfDomain(Integer.parseInt(domainId));
   } catch (AdminException e) {
     throw new AdminException(
         "DomainDriverManager.getGroupIdsOfDomain",
         SilverpeasException.ERROR,
         "admin.admin.MSG_ERR_GET_ALL_GROUPS",
         "domainId = " + domainId,
         e);
   } finally {
     releaseOrganizationSchema();
   }
 }
 public String[] getUserIdsOfDomain(String domainId) throws Exception {
   getOrganizationSchema();
   try {
     return getOrganization().user.getUserIdsOfDomain(Integer.parseInt(domainId));
   } catch (AdminException e) {
     throw new AdminException(
         "DomainDriverManager.getUser",
         SilverpeasException.ERROR,
         "admin.EX_ERR_GET_USERS",
         "domainId = " + domainId,
         e);
   } finally {
     releaseOrganizationSchema();
   }
 }
 /**
  * Remove a user from a group
  *
  * @param ddManager
  * @param sUserId
  * @param sGroupId
  * @throws AdminException
  */
 public void removeUserFromGroup(DomainDriverManager ddManager, String sUserId, String sGroupId)
     throws AdminException {
   try {
     ddManager.getOrganizationSchema();
     ddManager.getOrganization().group.removeUserFromGroup(idAsInt(sUserId), idAsInt(sGroupId));
   } catch (Exception e) {
     throw new AdminException(
         "GroupManager.removeUserFromGroup",
         SilverpeasException.ERROR,
         "admin.EX_ERR_GET_USER_GROUPS",
         "User Id: '" + sUserId + "' GroupId = '" + sGroupId + "'",
         e);
   } finally {
     ddManager.releaseOrganizationSchema();
   }
 }
 /**
  * Get the Silverpeas group id of group qualified by given specific Id and domain id
  *
  * @param ddManager
  * @param sSpecificId
  * @param sDomainId
  * @return
  * @throws AdminException
  */
 public String getGroupIdBySpecificIdAndDomainId(
     DomainDriverManager ddManager, String sSpecificId, String sDomainId) throws AdminException {
   try {
     ddManager.getOrganizationSchema();
     GroupRow gr =
         ddManager.getOrganization().group.getGroupBySpecificId(idAsInt(sDomainId), sSpecificId);
     return idAsString(gr.id);
   } catch (Exception e) {
     throw new AdminException(
         "GroupManager.getGroupIdBySpecificIdAndDomain",
         SilverpeasException.ERROR,
         "admin.EX_ERR_GET_GROUP",
         "group specific Id: '" + sSpecificId + "', domain Id: '" + sDomainId + "'",
         e);
   } finally {
     ddManager.releaseOrganizationSchema();
   }
 }
 /**
  * Get the all the root groups id available in Silverpeas
  *
  * @param ddManager
  * @return
  * @throws AdminException
  */
 public String[] getAllRootGroupIds(DomainDriverManager ddManager) throws AdminException {
   try {
     ddManager.getOrganizationSchema();
     String[] asGroupIds = ddManager.getOrganization().group.getAllRootGroupIds();
     if (asGroupIds != null) {
       return asGroupIds;
     }
     return ArrayUtil.EMPTY_STRING_ARRAY;
   } catch (Exception e) {
     throw new AdminException(
         "GroupManager.getAllRootGroupIds",
         SilverpeasException.ERROR,
         "admin.EX_ERR_GET_ALL_ROOT_GROUP_IDS",
         e);
   } finally {
     ddManager.releaseOrganizationSchema();
   }
 }
  public String[] searchGroupsIds(
      DomainDriverManager ddManager,
      boolean isRootGroup,
      String componentId,
      String[] aProfileId,
      Group modelGroup)
      throws AdminException {
    try {
      // Get organization
      ddManager.getOrganizationSchema();
      GroupRow model = group2GroupRow(modelGroup);
      // The Ids could be equal to -1 !!!! Put it to -2 if null
      if (!StringUtil.isDefined(modelGroup.getId())) {
        model.id = -2;
      }
      if (!StringUtil.isDefined(modelGroup.getDomainId())) {
        model.domainId = -2;
      }
      if (!StringUtil.isDefined(modelGroup.getSuperGroupId())) {
        model.superGroupId = -2;
      }

      int[] aRoleId = null;
      if (aProfileId != null) {
        aRoleId = new int[aProfileId.length];
        for (int i = 0; i < aProfileId.length; i++) {
          aRoleId[i] = idAsInt(aProfileId[i]);
        }
      }
      // Get groups
      return ddManager
          .getOrganization()
          .group
          .searchGroupsIds(isRootGroup, idAsInt(componentId), aRoleId, model);
    } catch (Exception e) {
      throw new AdminException(
          "GroupManager.searchGroupsIdsInGroup",
          SilverpeasException.ERROR,
          "admin.EX_ERR_GET_GROUPS_OF_DOMAIN",
          e);
    } finally {
      ddManager.releaseOrganizationSchema();
    }
  }
  /**
   * @param sKey anthentication key
   * @param removeKey remove after
   * @return
   * @throws Exception
   */
  public Map<String, String> authenticate(String sKey, boolean removeKey) throws Exception {
    Map<String, String> loginDomainId = new HashMap<String, String>();
    try {
      startTransaction(false);

      // Get the domain information
      KeyStoreRow ksr = getOrganization().keyStore.getRecordByKey(idAsInt(sKey));
      if (ksr == null) {
        throw new AdminException(
            "DomainDriverManager.authenticate",
            SilverpeasException.ERROR,
            "admin.EX_ERR_KEY_NOT_FOUND",
            "key: '" + sKey + "'");
      }

      loginDomainId.put("login", ksr.login);
      loginDomainId.put("domainId", idAsString(ksr.domainId));

      // Remove key from keytore in database
      if (removeKey) {
        getOrganization().keyStore.removeKeyStoreRecord(idAsInt(sKey));
      }

      // Commit transaction
      commit();
      return loginDomainId;
    } catch (AdminPersistenceException e) {
      try {
        this.rollback();
      } catch (Exception e1) {
        SilverTrace.error("admin", "DomainDriverManager.authenticate", "root.EX_ERR_ROLLBACK", e1);
      }
      throw new AdminException(
          "DomainDriverManager.authenticate",
          SilverpeasException.ERROR,
          "admin.EX_ERR_AUTHENTICATE",
          "key: '" + sKey + "'",
          e);
    } finally {
      releaseOrganizationSchema();
    }
  }
 /**
  * Get the groups of domain
  *
  * @param ddManager
  * @param sDomainId
  * @return
  * @throws AdminException
  */
 public Group[] getGroupsOfDomain(DomainDriverManager ddManager, String sDomainId)
     throws AdminException {
   try {
     // Get organization
     ddManager.getOrganizationSchema();
     SynchroReport.info(
         "GroupManager.getGroupsOfDomain()",
         "Recherche des groupes du domaine LDAP dans la base...",
         null);
     // Get groups of domain from Silverpeas database
     GroupRow[] grs = ddManager.getOrganization().group.getAllGroupsOfDomain(idAsInt(sDomainId));
     // Convert GroupRow objects in Group Object
     Group[] groups = new Group[grs.length];
     for (int nI = 0; nI < grs.length; nI++) {
       groups[nI] = groupRow2Group(grs[nI]);
       SynchroReport.debug(
           "GroupManager.getGroupsOfDomain()",
           "Groupe trouvé no : "
               + Integer.toString(nI)
               + ", specificID : "
               + groups[nI].getSpecificId()
               + ", desc. : "
               + groups[nI].getDescription(),
           null);
     }
     SynchroReport.info(
         "GroupManager.getGroupsOfDomain()",
         "Récupération de " + grs.length + " groupes du domaine LDAP dans la base",
         null);
     return groups;
   } catch (Exception e) {
     throw new AdminException(
         "GroupManager.getGroupsOfDomain",
         SilverpeasException.ERROR,
         "admin.EX_ERR_GET_GROUPS_OF_DOMAIN",
         "domain Id: '" + sDomainId + "'",
         e);
   } finally {
     ddManager.releaseOrganizationSchema();
   }
 }
 /**
  * Get the all the direct sub groups id of a given group
  *
  * @param ddManager
  * @param superGroupId
  * @return
  * @throws AdminException
  */
 public String[] getAllSubGroupIds(DomainDriverManager ddManager, String superGroupId)
     throws AdminException {
   try {
     ddManager.getOrganizationSchema();
     String[] asGroupIds =
         ddManager.getOrganization().group.getDirectSubGroupIds(idAsInt(superGroupId));
     if (asGroupIds != null) {
       return asGroupIds;
     }
     return ArrayUtil.EMPTY_STRING_ARRAY;
   } catch (Exception e) {
     throw new AdminException(
         "GroupManager.getAllSubGroupIds",
         SilverpeasException.ERROR,
         "admin.EX_ERR_GET_CHILDREN_GROUP_IDS",
         "father group Id: '" + superGroupId + "'",
         e);
   } finally {
     ddManager.releaseOrganizationSchema();
   }
 }
  /** @return Domain[] */
  public Domain[] getAllDomains() throws AdminException {
    Domain[] valret = null;
    int i;

    try {
      // Set the OrganizationSchema (if not already done)
      getOrganizationSchema();

      // Get the domain information
      DomainRow[] drs = getOrganization().domain.getAllDomains();
      if ((drs == null) || (drs.length <= 0)) {
        throw new AdminException(
            "DomainDriverManager.getAllDomains",
            SilverpeasException.ERROR,
            "admin.EX_ERR_NO_DOMAIN_FOUND");
      }

      valret = new Domain[drs.length];
      for (i = 0; i < drs.length; i++) {
        valret[i] = new Domain();
        valret[i].setId(java.lang.Integer.toString(drs[i].id));
        valret[i].setName(drs[i].name);
        valret[i].setDescription(drs[i].description);
        valret[i].setDriverClassName(drs[i].className);
        valret[i].setPropFileName(drs[i].propFileName);
        valret[i].setAuthenticationServer(drs[i].authenticationServer);
        valret[i].setTheTimeStamp(drs[i].theTimeStamp);
      }
    } catch (AdminPersistenceException e) {
      throw new AdminException(
          "DomainDriverManager.getAllDomains",
          SilverpeasException.ERROR,
          "admin.EX_ERR_GET_ALL_DOMAINS",
          e);
    } finally {
      releaseOrganizationSchema();
    }
    return valret;
  }
  /**
   * return group with given group name in domain
   *
   * @param groupName
   * @return Group
   */
  public Group getGroupByNameInDomain(String groupName, String domainId) throws Exception {
    try {
      // Set the OrganizationSchema (if not already done)
      getOrganizationSchema();

      // Get a DomainDriver instance
      DomainDriver domainDriver = this.getDomainDriver(idAsInt(domainId));

      // Get the group information without id and userId[]
      return domainDriver.getGroupByName(groupName);

    } catch (AdminException e) {
      throw new AdminException(
          "DomainDriverManager.getGroupByNameInDomain",
          SilverpeasException.ERROR,
          "admin.EX_ERR_GET_GROUP",
          "group Name: '" + groupName + "'",
          e);
    } finally {
      releaseOrganizationSchema();
    }
  }
  /**
   * @param domainId
   * @return
   * @throws Exception
   */
  public Group[] getAllRootGroups(String domainId) throws Exception {
    Group[] groups = null;

    try {
      // Set the OrganizationSchema (if not already done)
      getOrganizationSchema();
      // Get a DomainDriver instance
      DomainDriver domainDriver = this.getDomainDriver(idAsInt(domainId));
      // Get Group from specific domain
      groups = domainDriver.getAllRootGroups();
    } catch (AdminException e) {
      throw new AdminException(
          "DomainDriverManager.getAllRootGroups",
          SilverpeasException.ERROR,
          "admin.EX_ERR_GET_ALL_ROOT_GROUPS",
          "domain Id: '" + domainId + "'",
          e);
    } finally {
      releaseOrganizationSchema();
    }
    return groups;
  }
 /**
  * Get the direct groups id containing a user
  *
  * @param ddManager
  * @param sUserId
  * @return
  * @throws AdminException
  */
 public String[] getDirectGroupsOfUser(DomainDriverManager ddManager, String sUserId)
     throws AdminException {
   try {
     ddManager.getOrganizationSchema();
     GroupRow[] grs = ddManager.getOrganization().group.getDirectGroupsOfUser(idAsInt(sUserId));
     // Convert GroupRow objects in Group Object
     String[] groups = new String[grs.length];
     for (int nI = 0; nI < grs.length; nI++) {
       groups[nI] = idAsString(grs[nI].id);
     }
     return groups;
   } catch (Exception e) {
     throw new AdminException(
         "GroupManager.getDirectGroupsOfUser",
         SilverpeasException.ERROR,
         "admin.EX_ERR_GET_USER_GROUPS",
         "User Id: '" + sUserId + "'",
         e);
   } finally {
     ddManager.releaseOrganizationSchema();
   }
 }
  public String updateDomain(Domain theDomain) throws Exception {
    try {
      startTransaction(false);

      DomainRow dr = new DomainRow();
      dr.id = idAsInt(theDomain.getId());
      dr.name = theDomain.getName();
      dr.description = theDomain.getDescription();
      dr.className = theDomain.getDriverClassName();
      dr.propFileName = theDomain.getPropFileName();
      dr.authenticationServer = theDomain.getAuthenticationServer();
      dr.theTimeStamp = theDomain.getTheTimeStamp();
      dr.silverpeasServerURL = theDomain.getSilverpeasServerURL();

      // Create domain
      getOrganization().domain.updateDomain(dr);
      if (domainDriverInstances.get(theDomain.getId()) != null) {
        domainDriverInstances.remove(theDomain.getId());
      }
      this.commit();
      LoginPasswordAuthentication.initDomains();

      return theDomain.getId();
    } catch (AdminException e) {
      try {
        this.rollback();
      } catch (Exception e1) {
        SilverTrace.error("admin", "DomainDriverManager.updateDomain", "root.EX_ERR_ROLLBACK", e1);
      }
      throw new AdminException(
          "DomainDriverManager.updateDomain",
          SilverpeasException.ERROR,
          "admin.EX_ERR_ADD_DOMAIN",
          "domain name: '" + theDomain.getName() + "'",
          e);
    } finally {
      releaseOrganizationSchema();
    }
  }
 /**
  * @param ddManager
  * @return
  * @throws AdminException
  */
 public Group[] getSynchronizedGroups(DomainDriverManager ddManager) throws AdminException {
   try {
     // Get organization
     ddManager.getOrganizationSchema();
     // Get groups of domain from Silverpeas database
     GroupRow[] grs = ddManager.getOrganization().group.getSynchronizedGroups();
     // Convert GroupRow objects in Group Object
     Group[] groups = new Group[grs.length];
     for (int nI = 0; nI < grs.length; nI++) {
       groups[nI] = groupRow2Group(grs[nI]);
     }
     return groups;
   } catch (Exception e) {
     throw new AdminException(
         "GroupManager.getRootGroupsOfDomain",
         SilverpeasException.ERROR,
         "admin.EX_ERR_GET_GROUPS_OF_DOMAIN",
         e);
   } finally {
     ddManager.releaseOrganizationSchema();
   }
 }
  /**
   * @param domainId
   * @return String
   */
  public Domain getDomain(String domainId) throws Exception {
    Domain valret = null;

    try {
      // Set the OrganizationSchema (if not already done)
      getOrganizationSchema();

      // Get the domain information
      DomainRow dr = getOrganization().domain.getDomain(idAsInt(domainId));
      if (dr == null) {
        throw new AdminException(
            "DomainDriverManager.getDomain",
            SilverpeasException.ERROR,
            "admin.EX_ERR_DOMAIN_NOT_FOUND",
            "domain Id: '" + domainId + "'");
      }

      valret = new Domain();
      valret.setId(Integer.toString(dr.id));
      valret.setName(dr.name);
      valret.setDescription(dr.description);
      valret.setDriverClassName(dr.className);
      valret.setPropFileName(dr.propFileName);
      valret.setAuthenticationServer(dr.authenticationServer);
      valret.setTheTimeStamp(dr.theTimeStamp);
      valret.setSilverpeasServerURL(dr.silverpeasServerURL);
    } catch (AdminPersistenceException e) {
      throw new AdminException(
          "DomainDriverManager.getDomain",
          SilverpeasException.ERROR,
          "admin.EX_ERR_GET_DOMAIN",
          "domain id: '" + domainId + "'",
          e);
    } finally {
      releaseOrganizationSchema();
    }
    return valret;
  }
  /**
   * @param domainId
   * @return User[]
   * @throws Exception
   */
  public UserDetail[] getAllUsers(String domainId) throws Exception {
    UserDetail[] uds = null;

    try {
      // Set the OrganizationSchema (if not already done)
      this.getOrganizationSchema();
      // Get a DomainDriver instance
      DomainDriver domainDriver = this.getDomainDriver(idAsInt(domainId));

      // Get User detail from specific domain
      uds = domainDriver.getAllUsers();
    } catch (AdminException e) {
      throw new AdminException(
          "DomainDriverManager.getAllUsers",
          SilverpeasException.ERROR,
          "admin.EX_ERR_GET_ALL_USERS",
          "domain Id: '" + domainId + "'",
          e);
    } finally {
      releaseOrganizationSchema();
    }
    return uds;
  }
 /**
  * @param ddManager
  * @param sDomainId
  * @return
  * @throws AdminException
  */
 public String[] getRootGroupIdsOfDomain(DomainDriverManager ddManager, String sDomainId)
     throws AdminException {
   try {
     // Get organization
     ddManager.getOrganizationSchema();
     // Get groups of domain from Silverpeas database
     String[] groupIds =
         ddManager.getOrganization().group.getAllRootGroupIdsOfDomain(idAsInt(sDomainId));
     if (groupIds != null) {
       return groupIds;
     }
     return ArrayUtil.EMPTY_STRING_ARRAY;
   } catch (Exception e) {
     throw new AdminException(
         "GroupManager.getRootGroupIdsOfDomain",
         SilverpeasException.ERROR,
         "admin.EX_ERR_GET_GROUPS_OF_DOMAIN",
         "domain Id: '" + sDomainId + "'",
         e);
   } finally {
     ddManager.releaseOrganizationSchema();
   }
 }
  /**
   * Get the path from root to a given group
   *
   * @param ddManager
   * @param groupId
   * @return
   * @throws AdminException
   */
  public List<String> getPathToGroup(DomainDriverManager ddManager, String groupId)
      throws AdminException {
    try {
      ddManager.getOrganizationSchema();
      List<String> path = new ArrayList<String>();
      GroupRow superGroup = ddManager.getOrganization().group.getSuperGroup(idAsInt(groupId));
      while (superGroup != null) {
        path.add(0, idAsString(superGroup.id));
        superGroup = ddManager.getOrganization().group.getSuperGroup(superGroup.id);
      }

      return path;
    } catch (Exception e) {
      throw new AdminException(
          "GroupManager.getPathToGroup",
          SilverpeasException.ERROR,
          "admin.EX_ERR_GET_PATH_TO_GROUP",
          "groupId = " + groupId,
          e);
    } finally {
      ddManager.releaseOrganizationSchema();
    }
  }