From 7a573aef4c0df5e52534320f8b911e54349f7921 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 04 Aug 2016 15:02:41 +0000
Subject: [PATCH] Make CustomSearchResult closer to SDK's Entry

---
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java |   41 ++++++++++++++++++-----------------------
 1 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java
index e196685..a46bab4 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java
@@ -22,7 +22,6 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
@@ -480,18 +479,17 @@
     for (org.opends.server.types.Attribute attr : newAttrs)
     {
       AttributeDescription attrDesc = attr.getAttributeDescription();
-      String attrName = attrDesc.toString();
-      if (!ViewEntryPanel.isEditable(attrName, schema))
+      final String attrName = attrDesc.toString();
+      if (!ViewEntryPanel.isEditable(attrDesc, schema))
       {
         continue;
       }
       List<ByteString> newValues = new ArrayList<>();
-      Iterator<ByteString> it = attr.iterator();
-      while (it.hasNext())
+      for (ByteString v : attr)
       {
-        newValues.add(it.next());
+        newValues.add(v);
       }
-      List<ByteString> oldValues = oldEntry.getAttributeValues(attrName);
+      org.forgerock.opendj.ldap.Attribute oldAttr = oldEntry.getAttribute(attrDesc);
 
       ByteString rdnValue = null;
       for (AVA ava : newEntry.getName().rdn())
@@ -534,7 +532,7 @@
           break;
         }
       }
-      if (oldValues == null)
+      if (oldAttr == null)
       {
         Set<ByteString> vs = new HashSet<>(newValues);
         if (rdnValue != null)
@@ -548,6 +546,7 @@
               createAttribute(attrName, newValues)));
         }
       } else {
+        final List<ByteString> oldValues = toList(oldAttr);
         List<ByteString> toDelete = disjunction(newValues, oldValues);
         if (oldRdnValueDeleted != null)
         {
@@ -592,37 +591,33 @@
     }
 
     /* Check if there are attributes to delete */
-    for (String attrName : oldEntry.getAttributeNames())
+    for (org.forgerock.opendj.ldap.Attribute attr : oldEntry.getAllAttributes())
     {
-      if (!ViewEntryPanel.isEditable(attrName, schema))
+      AttributeDescription attrDesc = attr.getAttributeDescription();
+      if (!ViewEntryPanel.isEditable(attrDesc, schema))
       {
         continue;
       }
-      List<ByteString> oldValues = oldEntry.getAttributeValues(attrName);
-      AttributeDescription attrDesc = AttributeDescription.valueOf(attrName);
+      org.forgerock.opendj.ldap.Attribute oldAttr = oldEntry.getAttribute(attrDesc);
 
-      List<org.opends.server.types.Attribute> attrs = newEntry.getAttribute(attrDesc.getNameOrOID());
-      if (!find(attrs, attrName) && !oldValues.isEmpty())
+      if (!newEntry.hasAttribute(AttributeDescription.valueOf(attrDesc.getNameOrOID())) && !oldAttr.isEmpty())
       {
         modifications.add(new ModificationItem(
             DirContext.REMOVE_ATTRIBUTE,
-            new BasicAttribute(attrName)));
+            new BasicAttribute(attrDesc.toString())));
       }
     }
     return modifications;
   }
 
-  private static boolean find(List<org.opends.server.types.Attribute> attrs, String attrName)
+  private static List<ByteString> toList(org.forgerock.opendj.ldap.Attribute oldAttr)
   {
-    // TODO JNR use Entry.hasAttribute(AttributeDescription) instead?
-    for (org.opends.server.types.Attribute attr : attrs)
+    List<ByteString> results = new ArrayList<>();
+    for (ByteString v : oldAttr)
     {
-      if (attr.getAttributeDescription().toString().equalsIgnoreCase(attrName))
-      {
-        return true;
-      }
+      results.add(v);
     }
-    return false;
+    return results;
   }
 
   /**

--
Gitblit v1.10.0