/**
   * @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;
  }
  /**
   * 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();
    }
  }
  /**
   * @param group
   * @return
   * @throws Exception
   */
  @Override
  public String createGroup(Group group) throws Exception {
    Group specificGroup = new Group(group);
    try {
      // Set supergroup specific Id
      if (StringUtil.isDefined(group.getSuperGroupId())) {
        // Get the user information
        GroupRow gr = getOrganization().group.getGroup(idAsInt(group.getSuperGroupId()));
        if (gr == null) {
          throw new AdminException(
              "DomainDriverManager.createGroup",
              SilverpeasException.ERROR,
              "admin.EX_ERR_GROUP_NOT_FOUND",
              "group Id: '" + group.getSuperGroupId() + "'");
        }
        specificGroup.setSuperGroupId(gr.specificId);
      }
      // Set subUsers specific Id
      specificGroup.setUserIds(
          translateUserIdsToSpecificIds(idAsInt(group.getDomainId()), group.getUserIds()));
      // Get a DomainDriver instance
      DomainDriver domainDriver = this.getDomainDriver(idAsInt(group.getDomainId()));

      // Update Group in specific domain
      return domainDriver.createGroup(specificGroup);
    } catch (AdminException e) {
      throw new AdminException(
          "DomainDriverManager.createGroup",
          SilverpeasException.ERROR,
          "admin.EX_ERR_UPDATE_GROUP",
          "group Id: '" + group.getId() + "'",
          e);
    }
  }
  @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;
  }
 /** Rollback transaction in specific domain driver */
 public void rollback(String domainId) throws Exception {
   try {
     // Get a DomainDriver instance
     DomainDriver domainDriver = this.getDomainDriver(idAsInt(domainId));
     // Commit transaction
     domainDriver.rollback();
   } catch (Exception e) {
     throw new AdminException(
         "DomainDriverManager.rollback",
         SilverpeasException.ERROR,
         "root.EX_ERR_ROLLBACK",
         "domain Id: '" + domainId + "'",
         e);
   }
 }
 /** Start a new transaction in specific domain driver */
 public void startTransaction(String domainId, boolean bAutoCommit) throws Exception {
   try {
     // Get a AbstractDomainDriver instance
     DomainDriver domainDriver = this.getDomainDriver(idAsInt(domainId));
     // Start transaction
     domainDriver.startTransaction(bAutoCommit);
   } catch (Exception e) {
     throw new AdminException(
         "DomainDriverManager.startTransaction",
         SilverpeasException.ERROR,
         "admin.EX_ERR_START_TRANSACTION",
         "domain Id: '" + domainId + "'",
         e);
   }
 }
 /**
  * @param user
  * @throws Exception
  */
 @Override
 public void updateUserDetail(UserDetail user) throws Exception {
   try {
     // Get a DomainDriver instance
     DomainDriver domainDriver = this.getDomainDriver(idAsInt(user.getDomainId()));
     // Update User detail in specific domain
     domainDriver.updateUserDetail(user);
   } catch (AdminException e) {
     throw new AdminException(
         "DomainDriverManager.updateUser",
         SilverpeasException.ERROR,
         "admin.EX_ERR_UPDATE_USER",
         user.getFirstName() + " " + user.getLastName(),
         e);
   }
 }
 @Override
 public void resetEncryptedPassword(UserDetail user, String encryptedPassword) throws Exception {
   try {
     // Get a DomainDriver instance
     DomainDriver domainDriver = this.getDomainDriver(idAsInt(user.getDomainId()));
     // Update User detail in specific domain
     domainDriver.resetEncryptedPassword(user, encryptedPassword);
   } catch (AdminException e) {
     throw new AdminException(
         "DomainDriverManager.resetEncryptedPassword",
         SilverpeasException.ERROR,
         "admin.EX_ERR_UPDATE_USER",
         "userId : " + user.getId(),
         e);
   }
 }
  /**
   * * Create a new User.
   *
   * @param user
   * @return
   * @throws Exception
   */
  public String createUser(UserFull user) throws Exception {
    try {
      // Get a DomainDriver instance
      DomainDriver domainDriver = this.getDomainDriver(idAsInt(user.getDomainId()));

      // Create User in specific domain
      String sUserId = domainDriver.createUser(user);

      return sUserId;
    } catch (AdminException e) {
      throw new AdminException(
          "DomainDriverManager.createUser",
          SilverpeasException.ERROR,
          "admin.EX_ERR_ADD_USER",
          user.getFirstName() + " " + user.getLastName(),
          e);
    }
  }
  /**
   * @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;
  }
  /**
   * 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 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 groupId
   * @throws Exception
   */
  @Override
  public void deleteGroup(String groupId) throws Exception {
    try {
      // Set the OrganizationSchema (if not already done)
      getOrganizationSchema();

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

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

      // Get Group detail from specific domain
      domainDriver.deleteGroup(gr.specificId);

      // Delete index to given group
      unindexGroup(groupId);

    } catch (AdminException e) {
      throw new AdminException(
          "DomainDriverManager.deleteGroup",
          SilverpeasException.ERROR,
          "admin.EX_ERR_DELETE_GROUP",
          "group Id: '" + groupId + "'",
          e);
    } finally {
      releaseOrganizationSchema();
    }
  }
 /**
  * Called when Admin ends the synchronization
  *
  * @param cancelSynchro true if the synchronization is cancelled, false if it ends normally
  */
 public String endSynchronization(String sdomainId, boolean cancelSynchro) throws Exception {
   // Get a DomainDriver instance
   DomainDriver domainDriver = this.getDomainDriver(idAsInt(sdomainId));
   return domainDriver.endSynchronization(cancelSynchro);
 }
 /** Called when Admin starts the synchronization on a particular Domain */
 public void beginSynchronization(String sdomainId) throws Exception {
   // Get a DomainDriver instance
   DomainDriver domainDriver = this.getDomainDriver(idAsInt(sdomainId));
   domainDriver.beginSynchronization();
 }
  /**
   * @param domainId
   * @return DomainDriver
   */
  public DomainDriver getDomainDriver(int domainId) throws Exception {
    DomainDriver domainDriver = null;
    boolean osAllocated = false;
    try {
      domainDriver = domainDriverInstances.get(idAsString(domainId));
      if (domainDriver == null) {
        // Set the OrganizationSchema (if not already done)
        getOrganizationSchema();
        osAllocated = true;

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

        // Get the driver class name
        try {
          domainDriver = DomainDriverFactory.getDriver(dr.className);
          domainDriver.init(domainId, dr.propFileName, dr.authenticationServer);
        } catch (ClassNotFoundException e) {
          throw new AdminException(
              "DomainDriverManager.getDomainDriver",
              SilverpeasException.ERROR,
              "root.EX_CLASS_NOT_FOUND",
              e);
        } catch (IllegalAccessException e) {
          throw new AdminException(
              "DomainDriverManager.getDomainDriver",
              SilverpeasException.ERROR,
              "root.EX_ILLEGAL_ACCESS",
              e);
        } catch (InstantiationException e) {
          throw new AdminException(
              "DomainDriverManager.getDomainDriver",
              SilverpeasException.ERROR,
              "root.EX_INSTANTIATION",
              e);
        }

        // Save DomainDriver instance
        domainDriverInstances.put(idAsString(domainId), domainDriver);
      }
    } catch (AdminPersistenceException e) {
      throw new AdminException(
          "DomainDriverManager.getDomainDriver",
          SilverpeasException.ERROR,
          "admin.EX_ERR_GET_DOMAIN_DRIVER",
          "domain id: '" + domainId + "'",
          e);
    } finally {
      if (osAllocated) {
        releaseOrganizationSchema();
      }
    }
    return domainDriver;
  }