From 83ae76453e0b08ead8c12bd71c85445bdbbdb590 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 03 Aug 2016 16:05:42 +0000
Subject: [PATCH] Avoid DN being shown twice on UI: dc=example,dc=com,dc=example,dc=com
---
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/CustomSearchResult.java | 41 +-------------------
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java | 49 +-----------------------
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/LDAPEntryReader.java | 20 ++--------
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteEntryTask.java | 2
4 files changed, 11 insertions(+), 101 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java
index 6fe7815..e2de5f8 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java
@@ -510,16 +510,10 @@
while (sr.hasNext())
{
entry = sr.readEntry();
- String name;
if (entry.getName().isRootDN())
{
- name = remoteDn;
+ entry.setName(remoteDn);
}
- else
- {
- name = unquoteRelativeName(entry.getName().toString()) + "," + remoteDn;
- }
- entry.setName(name);
found = true;
}
if (!found)
@@ -728,23 +722,13 @@
continue;
}
- String name = unquoteRelativeName(r.getName().toString()) + "," + parentDn;
boolean add = false;
if (useCustomFilter())
{
// Check that is an immediate child: use a faster method by just
// comparing the number of components.
- DN dn = null;
- try
- {
- dn = DN.valueOf(name);
- add = dn.size() == parentComponents + 1;
- }
- catch (Throwable t)
- {
- throw new RuntimeException("Error decoding dns: "+t, t);
- }
-
+ final DN dn = r.getName();
+ add = dn.size() == parentComponents + 1;
if (!add)
{
// Is not a direct child. Check if the parent has been added,
@@ -766,7 +750,6 @@
}
if (add)
{
- r.setName(name);
childEntries.add(r);
// Time to time we update the display
if (childEntries.size() >= 20) {
@@ -914,32 +897,6 @@
}
}
- /**
- * Removes the quotes surrounding the provided name. JNDI can return relative
- * names with this format.
- * @param name the relative name to be treated.
- * @return an String representing the provided relative name without
- * surrounding quotes.
- */
- private String unquoteRelativeName(String name)
- {
- if (name.length() > 0 && name.charAt(0) == '"')
- {
- if (name.charAt(name.length() - 1) == '"')
- {
- return name.substring(1, name.length() - 1);
- }
- else
- {
- return name.substring(1);
- }
- }
- else
- {
- return name;
- }
- }
-
/** DEBUG : Dump the state of the task. */
void dump() {
System.out.println("=============");
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/CustomSearchResult.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/CustomSearchResult.java
index af08f49..0f2c399 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/CustomSearchResult.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/CustomSearchResult.java
@@ -24,8 +24,6 @@
import java.util.SortedSet;
import java.util.TreeSet;
-import javax.naming.CompositeName;
-import javax.naming.Name;
import javax.naming.NamingException;
import org.forgerock.opendj.ldap.AttributeDescription;
@@ -34,7 +32,6 @@
import org.forgerock.opendj.ldap.responses.SearchResultEntry;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.schema.ObjectClass;
-import org.opends.guitools.controlpanel.util.Utilities;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.AttributeBuilder;
import org.opends.server.types.Entry;
@@ -73,43 +70,11 @@
/**
* Constructor of a search result using a SearchResult as basis.
* @param sr the SearchResult.
- * @param baseDN the base DN of the search that returned the SearchResult.
- * @throws NamingException if there is an error retrieving the attribute
- * values.
+ * @throws NamingException if there is an error retrieving the attribute values.
*/
- public CustomSearchResult(SearchResultEntry sr, String baseDN)
- throws NamingException
+ public CustomSearchResult(SearchResultEntry sr) throws NamingException
{
- String sName = sr.getName().toString();
- Name name;
- if (baseDN != null && baseDN.length() > 0)
- {
- if (sName != null && sName.length() > 0)
- {
- name = new CompositeName(sName);
- name.add(baseDN);
- }
- else {
- name = Utilities.getJNDIName(baseDN);
- }
- }
- else {
- name = new CompositeName(sName);
- }
- StringBuilder buf = new StringBuilder();
- for (int i=0; i<name.size(); i++)
- {
- String n = name.get(i);
- if (n != null && n.length() > 0)
- {
- if (buf.length() != 0)
- {
- buf.append(",");
- }
- buf.append(n);
- }
- }
- dn = buf.toString();
+ dn = sr.getName().toString();
attributes = new HashMap<>();
attrNames = new TreeSet<>();
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteEntryTask.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteEntryTask.java
index ef06eb5..4200792 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteEntryTask.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteEntryTask.java
@@ -328,7 +328,7 @@
SearchResultEntry sr = entryDNs.readEntry();
if (!sr.getName().equals(""))
{
- CustomSearchResult res = new CustomSearchResult(sr, dnToRemove.toString());
+ CustomSearchResult res = new CustomSearchResult(sr);
entryDNFound = DN.valueOf(res.getDN());
deleteSubtreeRecursively(conn, entryDNFound, null, toNotify);
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/LDAPEntryReader.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/LDAPEntryReader.java
index 06e8e81..6b8da9b 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/LDAPEntryReader.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/LDAPEntryReader.java
@@ -25,7 +25,6 @@
import org.forgerock.opendj.ldap.requests.Requests;
import org.forgerock.opendj.ldap.requests.SearchRequest;
import org.forgerock.opendj.ldap.responses.SearchResultEntry;
-import org.forgerock.opendj.ldif.ConnectionEntryReader;
import org.opends.admin.ads.util.ConnectionWrapper;
import org.opends.guitools.controlpanel.datamodel.CustomSearchResult;
import org.opends.guitools.controlpanel.event.EntryReadErrorEvent;
@@ -63,23 +62,12 @@
isOver = false;
final String filter = "(|(objectclass=*)(objectclass=ldapsubentry))";
SearchRequest request = Requests.newSearchRequest(dn, BASE_OBJECT, filter, "*", "+");
- try (ConnectionEntryReader entryReader = conn.getConnection().search(request))
+ SearchResultEntry sr = conn.getConnection().searchSingleEntry(request);
+ if (isInterrupted())
{
- SearchResultEntry sr = null;
- while (entryReader.hasNext())
- {
- sr = entryReader.readEntry();
- }
-
- return new CustomSearchResult(sr, dn);
+ isOver = true;
}
- finally
- {
- if (isInterrupted())
- {
- isOver = true;
- }
- }
+ return new CustomSearchResult(sr);
}
@Override
--
Gitblit v1.10.0