From defab91e498d4516f715e0523da20004459211c9 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Tue, 26 Jan 2010 00:52:21 +0000
Subject: [PATCH] Fix for issue 4515 (control-panel entry browser does not deal well with sub-suffixes)

---
 opends/src/guitools/org/opends/guitools/controlpanel/util/NumSubordinateHacker.java     |   14 +++++++-------
 opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java |   40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java b/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java
index 082b23a..cca4b07 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/ui/AbstractBrowseEntriesPanel.java
@@ -1307,6 +1307,7 @@
           InitialLdapContext ctx = getInfo().getDirContext();
           InitialLdapContext ctx1 = controller.getConfigurationConnection();
           boolean setConnection = ctx != ctx1;
+          updateNumSubordinateHacker(desc);
           if (setConnection)
           {
             if (getInfo().getUserDataDirContext() == null)
@@ -1780,6 +1781,45 @@
   }
 
   /**
+   * Updates the NumsubordinateHacker of the browser controller with the
+   * provided server descriptor.
+   * @param server the server descriptor.
+   */
+  private void updateNumSubordinateHacker(ServerDescriptor server)
+  {
+    String serverHost = server.getHostname();
+    int serverPort = server.getAdminConnector().getPort();
+
+    ArrayList<DN> allSuffixes = new ArrayList<DN>();
+    for (BackendDescriptor backend : server.getBackends())
+    {
+      for (BaseDNDescriptor baseDN : backend.getBaseDns())
+      {
+        allSuffixes.add(baseDN.getDn());
+      }
+    }
+    ArrayList<DN> rootSuffixes = new ArrayList<DN>();
+    for (DN dn : allSuffixes)
+    {
+      boolean isRootSuffix = true;
+      for (DN dn1 : allSuffixes)
+      {
+        if (dn1.isAncestorOf(dn) && !dn1.equals(dn))
+        {
+          isRootSuffix = false;
+          break;
+        }
+      }
+      if (isRootSuffix)
+      {
+        rootSuffixes.add(dn);
+      }
+    }
+    controller.getNumSubordinateHacker().update(allSuffixes, rootSuffixes,
+        serverHost, serverPort);
+  }
+
+  /**
    * This is a class that simply checks the number of entries that the browser
    * contains and updates a counter with the new number of entries.
    * It is basically a thread that sleeps and checks whether some
diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/util/NumSubordinateHacker.java b/opends/src/guitools/org/opends/guitools/controlpanel/util/NumSubordinateHacker.java
index 059e31f..36a2e5e 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/util/NumSubordinateHacker.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/util/NumSubordinateHacker.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2008-2009 Sun Microsystems, Inc.
+ *      Copyright 2008-2010 Sun Microsystems, Inc.
  */
 
 package org.opends.guitools.controlpanel.util;
@@ -56,7 +56,7 @@
   }
 
   /**
-    * Tells wether the list of unreliable contains children of
+    * Tells whether the list of unreliable contains children of
     * the entry with LDAPUrl parentUrl.
     * @param parentUrl the LDAPURL of the parent.
     * @return <CODE>true</CODE> if the list of unreliable entries contains a
@@ -66,9 +66,9 @@
     boolean containsChildren = false;
 
     if (!isUnreliableEntryListEmpty) {
-      boolean isInServer = serverHost.equals(parentUrl.getHost()) &&
+      boolean isInServer = serverHost.equalsIgnoreCase(
+          String.valueOf(parentUrl.getHost())) &&
       (serverPort == parentUrl.getPort());
-
       if (isInServer) {
         for (DN dn : unreliableEntryList)
         {
@@ -92,7 +92,7 @@
   }
 
   /**
-    * Tells wether the list of unreliable contains the entry with LDAPURL
+    * Tells whether the list of unreliable contains the entry with LDAPURL
     * url.
     * It assumes that we previously called containsChildrenOf (there's no check
     * of the host/port).
@@ -103,9 +103,9 @@
   public boolean contains(LDAPURL url) {
     boolean contains = false;
     if (!isUnreliableEntryListEmpty) {
-      boolean isInServer = serverHost.equals(url.getHost()) &&
+      boolean isInServer =
+        serverHost.equalsIgnoreCase(String.valueOf(url.getHost())) &&
       (serverPort == url.getPort());
-
       if (isInServer) {
         for (DN dn : unreliableEntryList)
         {

--
Gitblit v1.10.0