From cd737457af3d812b90fedfcef2769407a58e1a8d Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 04 Aug 2016 15:06:12 +0000
Subject: [PATCH] Replace CustomSearchResult by SDK's Entry

---
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/CustomSearchResult.java |   24 ------------------------
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ManageTasksPanel.java          |   14 ++++++++++----
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java  |   11 +++++++++--
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java       |    5 ++++-
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java            |    4 +++-
 5 files changed, 26 insertions(+), 32 deletions(-)

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 85ffff1..16df5a0 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
@@ -18,14 +18,12 @@
 
 import javax.naming.NamingException;
 
-import org.forgerock.opendj.adapter.server3x.Converters;
 import org.forgerock.opendj.ldap.Attribute;
 import org.forgerock.opendj.ldap.AttributeDescription;
 import org.forgerock.opendj.ldap.DN;
 import org.forgerock.opendj.ldap.Entry;
 import org.forgerock.opendj.ldap.LinkedHashMapEntry;
 import org.forgerock.opendj.ldap.responses.SearchResultEntry;
-import org.opends.server.types.OpenDsException;
 
 /**
  * This is a commodity class used to wrap the SearchResult class of JNDI.
@@ -119,26 +117,4 @@
   public int hashCode() {
     return entry.hashCode();
   }
-
-  /** 
-   * Sets the given attribute.
-   * @param attr the attribute.
-   */
-  public void set(final Attribute attr)
-  {
-    entry.removeAttribute(attr.getAttributeDescription());
-    entry.addAttribute(attr);
-  }
-
-  /**
-   * Gets the Entry object equivalent to this CustomSearchResult.
-   * The method assumes that the schema in DirectoryServer has been initialized.
-   * @return the Entry object equivalent to this CustomSearchResult.
-   * @throws OpenDsException if there is an error parsing the DN or retrieving
-   * the attributes definition and objectclasses in the schema of the server.
-   */
-  public org.opends.server.types.Entry getEntry() throws OpenDsException
-  {
-    return Converters.to(entry);
-  }
 }
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ManageTasksPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ManageTasksPanel.java
index e27d203..964a9b2 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ManageTasksPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ManageTasksPanel.java
@@ -50,7 +50,9 @@
 
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.adapter.server3x.Converters;
 import org.forgerock.opendj.ldap.DN;
+import org.forgerock.opendj.ldap.Entry;
 import org.forgerock.opendj.ldap.LinkedAttribute;
 import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
 import org.opends.guitools.controlpanel.datamodel.CustomSearchResult;
@@ -497,11 +499,13 @@
       {
         final LinkedAttribute attr = new LinkedAttribute(attrNames[j]);
         attr.add(values[j] + r.nextInt());
-        csr.set(attr);
+        Entry entry = csr.getSdkEntry();
+        entry.removeAttribute(attr.getAttributeDescription());
+        entry.addAttribute(attr);
       }
       try
       {
-        list.add(new TaskEntry(csr.getEntry()));
+        list.add(new TaskEntry(Converters.to(csr.getSdkEntry())));
       }
       catch (Throwable t)
       {
@@ -561,11 +565,13 @@
       {
         final LinkedAttribute attr = new LinkedAttribute(attrNames[j]);
         attr.add(values[j]);
-        csr.set(attr);
+        Entry entry = csr.getSdkEntry();
+        entry.removeAttribute(attr.getAttributeDescription());
+        entry.addAttribute(attr);
       }
       try
       {
-        list.add(new TaskEntry(csr.getEntry()));
+        list.add(new TaskEntry(Converters.to(csr.getSdkEntry())));
       }
       catch (Throwable t)
       {
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java
index fbb561c..9351e6e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java
@@ -1599,7 +1599,10 @@
       Attribute attr = searchResult.getAttribute(attrName);
       if (attr != null && !attr.isEmpty())
       {
-        newResult.set(new LinkedAttribute(attr));
+        final Attribute newAttr = new LinkedAttribute(attr);
+        org.forgerock.opendj.ldap.Entry entry = newResult.getSdkEntry();
+        entry.removeAttribute(newAttr.getAttributeDescription());
+        entry.addAttribute(newAttr);
       }
     }
     ignoreEntryChangeEvents = true;
@@ -1649,7 +1652,11 @@
           if (newPwds.equals(lastUserPasswords.get(attrName)))
           {
             Attribute oldValues = searchResult.getAttribute(attrName);
-            newResult.set(oldValues != null ? new LinkedAttribute(oldValues) : new LinkedAttribute(attrName));
+            final Attribute newAttr =
+                oldValues != null ? new LinkedAttribute(oldValues) : new LinkedAttribute(attrName);
+            org.forgerock.opendj.ldap.Entry entry = newResult.getSdkEntry();
+            entry.removeAttribute(newAttr.getAttributeDescription());
+            entry.addAttribute(newAttr);
           }
           else
           {
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java
index ed64d99..4eee0ac 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java
@@ -725,7 +725,10 @@
         Attribute attr = searchResult.getAttribute(attrName);
         if (attr != null && !attr.isEmpty())
         {
-          newResult.set(new LinkedAttribute(attr));
+          final Attribute newAttr = new LinkedAttribute(attr);
+          org.forgerock.opendj.ldap.Entry entry = newResult.getSdkEntry();
+          entry.removeAttribute(newAttr.getAttributeDescription());
+          entry.addAttribute(newAttr);
         }
       }
       ignoreEntryChangeEvents = true;
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java
index 226b3ec..7804754 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java
@@ -486,7 +486,9 @@
     }
     if (!attr.isEmpty())
     {
-      sr.set(attr);
+      org.forgerock.opendj.ldap.Entry entry = sr.getSdkEntry();
+      entry.removeAttribute(attr.getAttributeDescription());
+      entry.addAttribute(attr);
     }
   }
 

--
Gitblit v1.10.0