From e33ecc4dd66d4c514cd7ad52d348a0be63a7f1eb Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 08 Jan 2014 14:30:15 +0000
Subject: [PATCH] Increased encapsulation of ReplicationDomain.IEContext + moved more behaviour to it. Reduced members' visibilities in LDAPReplicationDomain + removed several methods.

---
 opends/src/server/org/opends/server/replication/plugin/FractionalLDIFImportPlugin.java |  129 ++++++++++++++----------------------------
 1 files changed, 44 insertions(+), 85 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/plugin/FractionalLDIFImportPlugin.java b/opends/src/server/org/opends/server/replication/plugin/FractionalLDIFImportPlugin.java
index ace6d55..55564ab 100644
--- a/opends/src/server/org/opends/server/replication/plugin/FractionalLDIFImportPlugin.java
+++ b/opends/src/server/org/opends/server/replication/plugin/FractionalLDIFImportPlugin.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2009 Sun Microsystems, Inc.
- *      Portions copyright 2011-2013 ForgeRock AS
+ *      Portions copyright 2011-2014 ForgeRock AS
  */
 package org.opends.server.replication.plugin;
 
@@ -42,6 +42,7 @@
 
 import static org.opends.messages.ReplicationMessages.*;
 import static org.opends.server.replication.plugin.LDAPReplicationDomain.*;
+import static org.opends.server.util.StaticUtils.*;
 
 /**
  * This class implements a Directory Server plugin that is used in fractional
@@ -61,7 +62,7 @@
 {
   /**
    * Holds the fractional configuration and if available the replication domain
-   * matching this import session (they form the importfractional context).
+   * matching this import session (they form the import fractional context).
    * Domain is available if the server is online (import-ldif, online full
    * update..) otherwise, this is an import-ldif with server off. The key is the
    * ImportConfig object of the session which acts as a cookie for the whole
@@ -126,9 +127,7 @@
     super();
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override()
   public final void initializePlugin(Set<PluginType> pluginTypes,
     FractionalLDIFImportPluginCfg configuration)
@@ -153,9 +152,7 @@
     }
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override()
   public final void finalizePlugin()
   {
@@ -217,9 +214,7 @@
     return FractionalConfig.toFractionalConfig(matchingReplicatedDomainCfg);
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override()
   public final void doLDIFImportEnd(LDIFImportConfig importConfig)
   {
@@ -343,26 +338,20 @@
       }
 
       // Compare backend and local fractional configuration
-      boolean sameConfig =
-        isFractionalConfigConsistent(localFractionalConfig, exclIt, inclIt);
+      if (isFractionalConfigConsistent(localFractionalConfig, exclIt, inclIt))
+      {
+        // local and remote non/fractional config are equivalent :
+        // follow import, no need to go with filtering as remote backend
+        // should be ok
+        // let import finish
+        return PluginResult.ImportLDIF.continueEntryProcessing();
+      }
+
       if (localFractionalConfig.isFractional())
       {
-        // Local domain is fractional
-        if (sameConfig)
-        {
-          // Both local and remote fractional configuration are equivalent :
-          // follow import, no need to go with filtering as remote backend
-          // should be ok
-          return PluginResult.ImportLDIF.continueEntryProcessing();
-        }
-
         // Local domain is fractional, remote domain has not same config
-        boolean remoteDomainHasSomeConfig = false;
-        if ((exclAttr != null && (exclAttr.size() > 0))
-            || (inclAttr != null && (inclAttr.size() > 0)))
-        {
-          remoteDomainHasSomeConfig = true;
-        }
+        boolean remoteDomainHasSomeConfig =
+            isNotEmpty(exclAttr) || isNotEmpty(inclAttr);
         if (remoteDomainHasSomeConfig)
         {
           LDAPReplicationDomain domain = importFractionalContext.getDomain();
@@ -372,7 +361,6 @@
             // is different : stop import (error will be logged when import is
             // stopped)
             domain.setImportErrorMessageId(IMPORT_ERROR_MESSAGE_BAD_REMOTE);
-            domain.setFollowImport(false);
             return PluginResult.ImportLDIF.stopEntryProcessing(null);
           }
 
@@ -384,16 +372,10 @@
         // Local domain is fractional but remote domain has no config :
         // flush local config into root entry and follow import with filtering
         flushFractionalConfigIntoEntry(localFractionalConfig, entry);
-      } else
+      }
+      else
       {
         // Local domain is not fractional
-        if (sameConfig)
-        {
-          // None of the local or remote domain has fractional config : nothing
-          // more to do : let import finish
-          return PluginResult.ImportLDIF.continueEntryProcessing();
-        }
-
         LDAPReplicationDomain domain = importFractionalContext.getDomain();
         if (domain != null)
         {
@@ -401,7 +383,6 @@
           //local domain should be configured with the same config as remote one
           domain.setImportErrorMessageId(
               IMPORT_ERROR_MESSAGE_REMOTE_IS_FRACTIONAL);
-          domain.setFollowImport(false);
           return PluginResult.ImportLDIF.stopEntryProcessing(null);
         }
 
@@ -420,6 +401,11 @@
     return PluginResult.ImportLDIF.continueEntryProcessing();
   }
 
+  private boolean isNotEmpty(Attribute attr)
+  {
+    return attr != null && attr.size() > 0;
+  }
+
   private Attribute getAttribute(String attributeName, Entry entry)
   {
     AttributeType attrType = DirectoryServer.getAttributeType(attributeName);
@@ -459,51 +445,19 @@
       String fractAttribute = fractionalExclusive ?
           REPLICATION_FRACTIONAL_EXCLUDE : REPLICATION_FRACTIONAL_INCLUDE;
       AttributeBuilder attrBuilder = new AttributeBuilder(fractAttribute);
-      boolean somethingToFlush = false;
-
       // Add attribute values for all classes
-      int size = fractionalAllClassesAttributes.size();
-      if (size > 0)
-      {
-        String fracValue = "*:";
-        int i = 1;
-        for (String attrName : fractionalAllClassesAttributes)
-        {
-          fracValue += attrName;
-          if (i < size)
-          {
-            fracValue += ",";
-          }
-          i++;
-        }
-        somethingToFlush = true;
-        attrBuilder.add(fracValue);
-      }
+      boolean somethingToFlush =
+          add(attrBuilder, "*", fractionalAllClassesAttributes);
 
       // Add attribute values for specific classes
-      size = fractionalSpecificClassesAttributes.size();
-      if (size > 0)
+      if (fractionalSpecificClassesAttributes.size() > 0)
       {
-        for (String className : fractionalSpecificClassesAttributes.keySet())
+        for (Map.Entry<String, Set<String>> specific
+            : fractionalSpecificClassesAttributes.entrySet())
         {
-          int valuesSize =
-            fractionalSpecificClassesAttributes.get(className).size();
-          if (valuesSize > 0)
+          if (add(attrBuilder, specific.getKey(), specific.getValue()))
           {
-            String fracValue = className + ":";
-            int i = 1;
-            for (String attrName : fractionalSpecificClassesAttributes.get(
-              className))
-            {
-              fracValue += attrName;
-              if (i < valuesSize)
-              {
-                fracValue += ",";
-              }
-              i++;
-            }
             somethingToFlush = true;
-            attrBuilder.add(fracValue);
           }
         }
       }
@@ -517,9 +471,18 @@
     }
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  private static boolean add(AttributeBuilder attrBuilder, String className,
+      Set<String> values)
+  {
+    if (values.size() > 0)
+    {
+      attrBuilder.add(className + ":" + collectionToString(values, ","));
+      return true;
+    }
+    return false;
+  }
+
+  /** {@inheritDoc} */
   @Override()
   public boolean isConfigurationAcceptable(PluginCfg configuration,
     List<Message> unacceptableReasons)
@@ -527,9 +490,7 @@
     return true;
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public boolean isConfigurationChangeAcceptable(
     FractionalLDIFImportPluginCfg configuration,
@@ -538,9 +499,7 @@
     return true;
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public ConfigChangeResult applyConfigurationChange(
     FractionalLDIFImportPluginCfg configuration)

--
Gitblit v1.10.0