From 4e1ea6ff023569a8e27e501b8b05cba6c59490d4 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 27 Jan 2010 22:01:06 +0000
Subject: [PATCH] Fix for issue 4517 (Cannot use control panel to edit entry in replicated base DN after a binary update happened in the entry) Treat the ds-sync-hist in a special manner.  It is an attribute with DirectoryString syntax but it can contain byte[] values expressed in a String format which can completely break the UI and the entry processing.

---
 opends/src/guitools/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java |   87 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 84 insertions(+), 3 deletions(-)

diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java b/opends/src/guitools/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java
index ca8ccbe..ad80e04 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java
@@ -53,6 +53,7 @@
 import org.opends.guitools.controlpanel.util.Utilities;
 import org.opends.messages.Message;
 import org.opends.server.api.AttributeSyntax;
+import org.opends.server.replication.plugin.Historical;
 import org.opends.server.schema.SchemaConstants;
 import org.opends.server.types.AttributeType;
 import org.opends.server.types.AttributeValue;
@@ -517,10 +518,10 @@
    */
   protected boolean isPassword(String attrName)
   {
-    boolean isBinary = false;
+    boolean isPassword = false;
     Schema schema = getInfo().getServerDescriptor().getSchema();
-    isBinary = Utilities.hasPasswordSyntax(attrName, schema);
-    return isBinary;
+    isPassword = Utilities.hasPasswordSyntax(attrName, schema);
+    return isPassword;
   }
 
   /**
@@ -632,4 +633,84 @@
     }
     return isEditable;
   }
+
+  /**
+   * This method is called because the ds-sync-hist attribute has a
+   * DirectoryString syntax, but it contains byte[] on it (if there has been
+   * a modification in a binary value).
+   * @param sr the search result to use.
+   * @return the filtered search result to be used to be displayed.
+   */
+  protected CustomSearchResult filterSearchResult(CustomSearchResult sr)
+  {
+    CustomSearchResult filteredSr;
+    List<Object> values =
+      sr.getAttributeValues(Historical.HISTORICALATTRIBUTENAME);
+    if (values != null)
+    {
+      List<Object> newValues = new ArrayList<Object>();
+      for (Object v : values)
+      {
+        newValues.add(filterStringValue(String.valueOf(v)));
+      }
+      if (newValues.equals(values))
+      {
+        filteredSr = sr;
+      }
+      else
+      {
+        filteredSr = sr.clone();
+        filteredSr.set(Historical.HISTORICALATTRIBUTENAME, newValues);
+      }
+    }
+    else
+    {
+      filteredSr = sr;
+    }
+    return filteredSr;
+  }
+
+  /**
+   * This method is called because the ds-sync-hist attribute has a
+   * DirectoryString syntax, but it contains byte[] on it (if there has been
+   * a modification in a binary value).
+   * @param value the value to be filtered.
+   * @return the value that will actually be displayed.
+   */
+  private String filterStringValue(String value)
+  {
+    String filteredValue;
+    // Parse the value to find out if this corresponds to a change in a
+    // binary attribute.
+    int index = value.indexOf(":");
+    if (index != -1)
+    {
+      String modifiedAttr = value.substring(0, index).trim();
+      modifiedAttr = Utilities.getAttributeNameWithoutOptions(modifiedAttr);
+      if (isBinary(modifiedAttr))
+      {
+        String replTag = "repl:";
+        int index2 = value.indexOf(replTag, index);
+        if (index2 != -1)
+        {
+          filteredValue = value.substring(0, index2+replTag.length()) +
+          INFO_CTRL_PANEL_DS_SYNC_HIST_BINARY_VALUE.get();
+        }
+        else
+        {
+          filteredValue = value.substring(0, index+1) +
+          INFO_CTRL_PANEL_DS_SYNC_HIST_BINARY_VALUE.get();
+        }
+      }
+      else
+      {
+        filteredValue = value;
+      }
+    }
+    else
+    {
+      filteredValue = value;
+    }
+    return filteredValue;
+  }
 }

--
Gitblit v1.10.0