From f73b655466092169abac34833fb628fce1fcdebe Mon Sep 17 00:00:00 2001
From: jcduff <jcduff@localhost>
Date: Thu, 23 Oct 2008 14:04:24 +0000
Subject: [PATCH] The commit will bring the following features :     - An updated version of the underlying database. BDB JE 3.3 is now used.     - Attribute API refactoring providing a better abstraction and offering improved performances.     - A new GUI called the Control-Panel to replace the Status-Panel: the specifications for this       GUI are available on OpenDS Wiki and contains a link to a mockup.        See <https://www.opends.org/wiki/page/ControlPanelUISpecification>.     - Some changes in the replication protocol to implement "Assured Replication Mode". The        specifications are on OpenDS Wiki at <https://www.opends.org/wiki/page/AssuredMode> and section 7       described some of the replication changes required to support this. Assured Replication is not finished,       but the main replication protocol changes to support it are done. As explained by Gilles on an email on       the Dev mailing list (http://markmail.org/message/46rgo3meq3vriy4a), with these changes the newer versions       of OpenDS may not be able to replicate with OpenDS 1.0 instances.     - Support for Service Tags on the platforms where the functionality is available and enabled. Specifications       are published at <https://www.opends.org/wiki/page/OpenDSServiceTagEnabled>. For more information on       Service Tags see <http://wikis.sun.com/display/ServiceTag/Sun+Service+Tag+FAQ>.     - The Admin Connector service. In order to provide agentry of the OpenDS server at any time, a new service       has been added, dedicated to the administration, configuration and monitoring of the server.       An overview of the Admin Connector service and it's use is available on the       OpenDS wiki <https://www.opends.org/wiki/page/ManagingAdministrationTrafficToTheServer>     - Updates to the various command line tools to support the Admin Connector service.     - Some internal re-architecting of the server to put the foundation of future developments such as virtual       directory services. The new NetworkGroups and WorkFlow internal services which have been specified in       <https://www.opends.org/wiki/page/BasicOperationRoutingThroughNetworkGroup> are now implemented.     - Many bug fixes...

---
 opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyDNOperation.java |  292 ++++++++++++++++++---------------------------------------
 1 files changed, 94 insertions(+), 198 deletions(-)

diff --git a/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyDNOperation.java b/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyDNOperation.java
index cf66541..d23006f 100644
--- a/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyDNOperation.java
+++ b/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyDNOperation.java
@@ -28,9 +28,7 @@
 
 
 
-import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.concurrent.locks.Lock;
@@ -55,11 +53,10 @@
 import org.opends.server.core.ModifyDNOperationWrapper;
 import org.opends.server.core.PluginConfigManager;
 import org.opends.server.loggers.debug.DebugTracer;
-import org.opends.server.protocols.asn1.ASN1OctetString;
 import org.opends.server.types.Attribute;
 import org.opends.server.types.AttributeType;
 import org.opends.server.types.AttributeValue;
-import org.opends.server.types.ByteString;
+import org.opends.server.types.Attributes;
 import org.opends.server.types.CanceledOperationException;
 import org.opends.server.types.Control;
 import org.opends.server.types.DebugLogLevel;
@@ -404,39 +401,8 @@
           break modifyDNProcessing;
         }
 
-
-        // Invoke any conflict resolution processing that might be needed by the
-        // synchronization provider.
-        for (SynchronizationProvider provider :
-             DirectoryServer.getSynchronizationProviders())
-        {
-          try
-          {
-            SynchronizationProviderResult result =
-                 provider.handleConflictResolution(this);
-            if (! result.continueProcessing())
-            {
-              setResultCode(result.getResultCode());
-              appendErrorMessage(result.getErrorMessage());
-              setMatchedDN(result.getMatchedDN());
-              setReferralURLs(result.getReferralURLs());
-              break modifyDNProcessing;
-            }
-          }
-          catch (DirectoryException de)
-          {
-            if (debugEnabled())
-            {
-              TRACER.debugCaught(DebugLogLevel.ERROR, de);
-            }
-
-            logError(ERR_MODDN_SYNCH_CONFLICT_RESOLUTION_FAILED.get(
-                          getConnectionID(), getOperationID(),
-                          getExceptionMessage(de)));
-
-            setResponseData(de);
+        if(!handleConflictResolution()) {
             break modifyDNProcessing;
-          }
         }
 
 
@@ -608,37 +574,10 @@
           }
           else
           {
-            for (SynchronizationProvider provider :
-                 DirectoryServer.getSynchronizationProviders())
-            {
-              try
-              {
-                SynchronizationProviderResult result =
-                    provider.doPreOperation(this);
-                if (! result.continueProcessing())
-                {
-                  setResultCode(result.getResultCode());
-                  appendErrorMessage(result.getErrorMessage());
-                  setMatchedDN(result.getMatchedDN());
-                  setReferralURLs(result.getReferralURLs());
+              if(!processPreOperation()) {
                   break modifyDNProcessing;
-                }
               }
-              catch (DirectoryException de)
-              {
-                if (debugEnabled())
-                {
-                  TRACER.debugCaught(DebugLogLevel.ERROR, de);
-                }
-
-                logError(ERR_MODDN_SYNCH_PREOP_FAILED.get(getConnectionID(),
-                              getOperationID(), getExceptionMessage(de)));
-                setResponseData(de);
-                break modifyDNProcessing;
-              }
-            }
-
-            currentBackend.renameEntry(entryDN, newEntry, this);
+              currentBackend.renameEntry(entryDN, newEntry, this);
           }
 
 
@@ -665,28 +604,7 @@
       }
       finally
       {
-
-        for (SynchronizationProvider provider :
-          DirectoryServer.getSynchronizationProviders())
-        {
-          try
-          {
-            provider.doPostOperation(this);
-          }
-          catch (DirectoryException de)
-          {
-            if (debugEnabled())
-            {
-              TRACER.debugCaught(DebugLogLevel.ERROR, de);
-            }
-
-            logError(ERR_MODDN_SYNCH_POSTOP_FAILED.get(getConnectionID(),
-                getOperationID(), getExceptionMessage(de)));
-            setResponseData(de);
-            break;
-          }
-        }
-
+        processPostOperation();
         LockManager.unlock(entryDN, currentLock);
         LockManager.unlock(newDN, newLock);
       }
@@ -1012,12 +930,10 @@
       int numValues  = currentRDN.getNumValues();
       for (int i=0; i < numValues; i++)
       {
-        LinkedHashSet<AttributeValue> valueSet =
-             new LinkedHashSet<AttributeValue>(1);
-        valueSet.add(currentRDN.getAttributeValue(i));
-
-        Attribute a = new Attribute(currentRDN.getAttributeType(i),
-                                    currentRDN.getAttributeName(i), valueSet);
+        Attribute a = Attributes.create(
+            currentRDN.getAttributeType(i),
+            currentRDN.getAttributeName(i),
+            currentRDN.getAttributeValue(i));
 
         // If the associated attribute type is marked NO-USER-MODIFICATION, then
         // refuse the update.
@@ -1047,12 +963,10 @@
     int newRDNValues = newRDN.getNumValues();
     for (int i=0; i < newRDNValues; i++)
     {
-      LinkedHashSet<AttributeValue> valueSet =
-           new LinkedHashSet<AttributeValue>(1);
-      valueSet.add(newRDN.getAttributeValue(i));
-
-      Attribute a = new Attribute(newRDN.getAttributeType(i),
-                                  newRDN.getAttributeName(i), valueSet);
+      Attribute a = Attributes.create(
+          newRDN.getAttributeType(i),
+          newRDN.getAttributeName(i),
+          newRDN.getAttributeValue(i));
 
       LinkedList<AttributeValue> duplicateValues =
            new LinkedList<AttributeValue>();
@@ -1145,108 +1059,11 @@
           break;
 
         case REPLACE:
-          duplicateValues = new LinkedList<AttributeValue>();
-          newEntry.removeAttribute(a.getAttributeType(), a.getOptions());
-          newEntry.addAttribute(a, duplicateValues);
+          newEntry.replaceAttribute(a);
           break;
 
         case INCREMENT:
-          List<Attribute> attrList =
-               newEntry.getAttribute(a.getAttributeType(),
-                                     a.getOptions());
-          if ((attrList == null) || attrList.isEmpty())
-          {
-            throw new DirectoryException(ResultCode.NO_SUCH_ATTRIBUTE,
-                                         ERR_MODDN_PREOP_INCREMENT_NO_ATTR.get(
-                                              String.valueOf(entryDN),
-                                              a.getName()));
-          }
-          else if (attrList.size() > 1)
-          {
-            throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
-                           ERR_MODDN_PREOP_INCREMENT_MULTIPLE_VALUES.get(
-                                String.valueOf(entryDN), a.getName()));
-          }
-
-          LinkedHashSet<AttributeValue> values =
-               attrList.get(0).getValues();
-          if ((values == null) || values.isEmpty())
-          {
-            throw new DirectoryException(ResultCode.NO_SUCH_ATTRIBUTE,
-                                         ERR_MODDN_PREOP_INCREMENT_NO_ATTR.get(
-                                              String.valueOf(entryDN),
-                                              a.getName()));
-          }
-          else if (values.size() > 1)
-          {
-            throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
-                           ERR_MODDN_PREOP_INCREMENT_MULTIPLE_VALUES.get(
-                                String.valueOf(entryDN), a.getName()));
-          }
-
-          long currentLongValue;
-          try
-          {
-            AttributeValue v = values.iterator().next();
-            currentLongValue = Long.parseLong(v.getStringValue());
-          }
-          catch (Exception e)
-          {
-            if (debugEnabled())
-            {
-              TRACER.debugCaught(DebugLogLevel.ERROR, e);
-            }
-
-            throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
-                           ERR_MODDN_PREOP_INCREMENT_VALUE_NOT_INTEGER.get(
-                                String.valueOf(entryDN), a.getName()));
-          }
-
-          LinkedHashSet<AttributeValue> newValues = a.getValues();
-          if ((newValues == null) || newValues.isEmpty())
-          {
-            throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
-                           ERR_MODDN_PREOP_INCREMENT_NO_AMOUNT.get(
-                                String.valueOf(entryDN), a.getName()));
-          }
-          else if (newValues.size() > 1)
-          {
-            throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
-                           ERR_MODDN_PREOP_INCREMENT_MULTIPLE_AMOUNTS.get(
-                                String.valueOf(entryDN), a.getName()));
-          }
-
-          long incrementAmount;
-          try
-          {
-            AttributeValue v = values.iterator().next();
-            incrementAmount = Long.parseLong(v.getStringValue());
-          }
-          catch (Exception e)
-          {
-            if (debugEnabled())
-            {
-              TRACER.debugCaught(DebugLogLevel.ERROR, e);
-            }
-
-            throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
-                           ERR_MODDN_PREOP_INCREMENT_AMOUNT_NOT_INTEGER.get(
-                                String.valueOf(entryDN), a.getName()));
-          }
-
-          long newLongValue = currentLongValue + incrementAmount;
-          ByteString newValueOS =
-               new ASN1OctetString(String.valueOf(newLongValue));
-
-          newValues = new LinkedHashSet<AttributeValue>(1);
-          newValues.add(new AttributeValue(a.getAttributeType(),
-                                           newValueOS));
-
-          List<Attribute> newAttrList = new ArrayList<Attribute>(1);
-          newAttrList.add(new Attribute(a.getAttributeType(),
-                                        a.getName(), newValues));
-          newEntry.putAttribute(a.getAttributeType(), newAttrList);
-
+          newEntry.incrementAttribute(a);
           break;
       }
     }
@@ -1378,5 +1195,84 @@
       addResponseControl(responseControl);
     }
   }
+
+  private boolean handleConflictResolution() {
+      boolean returnVal = true;
+
+      for (SynchronizationProvider<?> provider :
+          DirectoryServer.getSynchronizationProviders()) {
+          try {
+              SynchronizationProviderResult result =
+                  provider.handleConflictResolution(this);
+              if (!result.continueProcessing()) {
+                  setResultCode(result.getResultCode());
+                  appendErrorMessage(result.getErrorMessage());
+                  setMatchedDN(result.getMatchedDN());
+                  setReferralURLs(result.getReferralURLs());
+                  returnVal = false;
+                  break;
+              }
+          } catch (DirectoryException de) {
+              if (debugEnabled()) {
+                  TRACER.debugCaught(DebugLogLevel.ERROR, de);
+              }
+              logError(ERR_MODDN_SYNCH_CONFLICT_RESOLUTION_FAILED.get(
+                      getConnectionID(), getOperationID(),
+                      getExceptionMessage(de)));
+
+              setResponseData(de);
+              returnVal = false;
+              break;
+          }
+      }
+      return returnVal;
+  }
+
+  private boolean processPreOperation() {
+      boolean returnVal = true;
+
+      for (SynchronizationProvider<?> provider :
+          DirectoryServer.getSynchronizationProviders()) {
+          try {
+              SynchronizationProviderResult result =
+                  provider.doPreOperation(this);
+              if (! result.continueProcessing()) {
+                  setResultCode(result.getResultCode());
+                  appendErrorMessage(result.getErrorMessage());
+                  setMatchedDN(result.getMatchedDN());
+                  setReferralURLs(result.getReferralURLs());
+                  returnVal = false;
+                  break;
+              }
+          } catch (DirectoryException de) {
+              if (debugEnabled()) {
+                  TRACER.debugCaught(DebugLogLevel.ERROR, de);
+              }
+              logError(ERR_MODDN_SYNCH_PREOP_FAILED.get(getConnectionID(),
+                      getOperationID(), getExceptionMessage(de)));
+              setResponseData(de);
+              returnVal = false;
+              break;
+          }
+      }
+      return returnVal;
+  }
+
+  private void processPostOperation() {
+      for (SynchronizationProvider<?> provider : DirectoryServer
+              .getSynchronizationProviders()) {
+          try {
+              provider.doPostOperation(this);
+          } catch (DirectoryException de) {
+              if (debugEnabled()) {
+                  TRACER.debugCaught(DebugLogLevel.ERROR, de);
+              }
+              logError(ERR_MODDN_SYNCH_POSTOP_FAILED.get(getConnectionID(),
+                      getOperationID(), getExceptionMessage(de)));
+              setResponseData(de);
+              break;
+          }
+      }
+  }
 }
 

--
Gitblit v1.10.0