From 5c1781321a571986f9a1f4fcdf3e332076ee4c83 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 03 Feb 2016 14:50:55 +0000
Subject: [PATCH] Use AttributeDescription in Entry and Attribute

---
 opendj-server-legacy/src/main/java/org/opends/server/plugins/UniqueAttributePlugin.java |   59 +++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/plugins/UniqueAttributePlugin.java b/opendj-server-legacy/src/main/java/org/opends/server/plugins/UniqueAttributePlugin.java
index 82341c5..3f22cda 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/plugins/UniqueAttributePlugin.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/plugins/UniqueAttributePlugin.java
@@ -26,7 +26,13 @@
  */
 package org.opends.server.plugins;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.forgerock.i18n.LocalizableMessage;
@@ -36,6 +42,7 @@
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.ResultCode;
 import org.forgerock.opendj.ldap.SearchScope;
+import org.forgerock.opendj.ldap.schema.AttributeType;
 import org.opends.server.admin.server.ConfigurationChangeListener;
 import org.opends.server.admin.std.meta.PluginCfgDefn;
 import org.opends.server.admin.std.server.PluginCfg;
@@ -52,9 +59,25 @@
 import org.opends.server.protocols.internal.InternalSearchOperation;
 import org.opends.server.protocols.internal.SearchRequest;
 import org.opends.server.schema.SchemaConstants;
-import org.forgerock.opendj.ldap.schema.AttributeType;
-import org.opends.server.types.*;
-import org.opends.server.types.operation.*;
+import org.opends.server.types.Attribute;
+import org.opends.server.types.DN;
+import org.opends.server.types.DirectoryException;
+import org.opends.server.types.Entry;
+import org.opends.server.types.IndexType;
+import org.opends.server.types.Modification;
+import org.opends.server.types.RDN;
+import org.opends.server.types.SearchFilter;
+import org.opends.server.types.SearchResultEntry;
+import org.opends.server.types.operation.PluginOperation;
+import org.opends.server.types.operation.PostOperationAddOperation;
+import org.opends.server.types.operation.PostOperationModifyDNOperation;
+import org.opends.server.types.operation.PostOperationModifyOperation;
+import org.opends.server.types.operation.PostSynchronizationAddOperation;
+import org.opends.server.types.operation.PostSynchronizationModifyDNOperation;
+import org.opends.server.types.operation.PostSynchronizationModifyOperation;
+import org.opends.server.types.operation.PreOperationAddOperation;
+import org.opends.server.types.operation.PreOperationModifyDNOperation;
+import org.opends.server.types.operation.PreOperationModifyOperation;
 
 import static org.opends.messages.PluginMessages.*;
 import static org.opends.server.protocols.internal.InternalClientConnection.*;
@@ -148,7 +171,7 @@
     {
       for (DN baseDN : cfgBaseDNs)
       {
-        Backend b = DirectoryServer.getBackend(baseDN);
+        Backend<?> b = DirectoryServer.getBackend(baseDN);
         if (b != null && ! b.isIndexed(t, IndexType.EQUALITY))
         {
           throw new ConfigException(ERR_PLUGIN_UNIQUEATTR_ATTR_UNINDEXED.get(
@@ -253,13 +276,9 @@
 
         case INCREMENT:
           // We could calculate the new value, but we'll just take it from the updated entry.
-          for (Attribute updatedAttr : modifyOperation.getModifiedEntry().getAttribute(t, a.getOptions()))
+          Attribute updatedAttr = modifyOperation.getModifiedEntry().getExactAttribute(a.getAttributeDescription());
+          if (updatedAttr != null)
           {
-            if (! updatedAttr.optionsEqual(a.getOptions()))
-            {
-              continue;
-            }
-
             for (ByteString v : updatedAttr)
             {
               PreOperation stop = checkUniqueness(entryDN, t, v, baseDNs, recordedValues, config);
@@ -442,13 +461,9 @@
 
         case INCREMENT:
           // We could calculate the new value, but we'll just take it from the updated entry.
-          for (Attribute updatedAttr : modifyOperation.getModifiedEntry().getAttribute(t, a.getOptions()))
+          Attribute updatedAttr = modifyOperation.getModifiedEntry().getExactAttribute(a.getAttributeDescription());
+          if (updatedAttr != null)
           {
-            if (! updatedAttr.optionsEqual(a.getOptions()))
-            {
-              continue;
-            }
-
             for (ByteString v : updatedAttr)
             {
               sendAlertForUnresolvedConflict(modifyOperation, entryDN,
@@ -703,7 +718,7 @@
     {
       for (DN baseDN : cfgBaseDNs)
       {
-        Backend b = DirectoryServer.getBackend(baseDN);
+        Backend<?> b = DirectoryServer.getBackend(baseDN);
         if (b != null && ! b.isIndexed(t, IndexType.EQUALITY))
         {
           unacceptableReasons.add(ERR_PLUGIN_UNIQUEATTR_ATTR_UNINDEXED.get(
@@ -833,13 +848,9 @@
 
         case INCREMENT:
           // We could calculate the new value, but we'll just take it from the updated entry.
-          for (Attribute updatedAttr : modifyOperation.getModifiedEntry().getAttribute(t, a.getOptions()))
+          Attribute updatedAttr = modifyOperation.getModifiedEntry().getExactAttribute(a.getAttributeDescription());
+          if (updatedAttr != null)
           {
-            if (!updatedAttr.optionsEqual(a.getOptions()))
-            {
-              continue;
-            }
-
             for (ByteString v : updatedAttr)
             {
               uniqueAttrValue2Dn.remove(v);

--
Gitblit v1.10.0