From 70df53f05e4cc8615f2ef13a739f085c706a3ccb Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 14 Oct 2009 11:24:26 +0000
Subject: [PATCH] Fix for issue 4283 (No way to add operational attribute to an entry)

---
 opends/src/guitools/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java |   61 +++++++++---------------------
 1 files changed, 18 insertions(+), 43 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 7862861..50447e3 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java
@@ -53,7 +53,6 @@
 import org.opends.guitools.controlpanel.util.Utilities;
 import org.opends.messages.Message;
 import org.opends.server.api.AttributeSyntax;
-import org.opends.server.config.ConfigConstants;
 import org.opends.server.schema.SchemaConstants;
 import org.opends.server.types.AttributeType;
 import org.opends.server.types.AttributeValue;
@@ -74,6 +73,7 @@
  */
 public abstract class ViewEntryPanel extends StatusGenericPanel
 {
+  private static final long serialVersionUID = -1908757626234678L;
   /**
    * The read-only attributes as they appear on the schema.
    */
@@ -83,6 +83,11 @@
    */
   protected SortedSet<String> schemaReadOnlyAttributesLowerCase =
     new TreeSet<String>();
+  /**
+   * The editable operational attributes.
+   */
+  protected SortedSet<String> editableOperationalAttrNames =
+    new TreeSet<String>();
   private JLabel title= Utilities.createDefaultLabel();
 
   private Set<LDAPEntryChangedListener> listeners =
@@ -390,20 +395,21 @@
   public void configurationChanged(ConfigurationChangeEvent ev)
   {
     Schema schema = ev.getNewDescriptor().getSchema();
-    if (schema != null)
+    if (schema != null && schemaReadOnlyAttributes.isEmpty())
     {
       schemaReadOnlyAttributes.clear();
       schemaReadOnlyAttributesLowerCase.clear();
       for (AttributeType attr : schema.getAttributeTypes().values())
       {
-        if (attr.isOperational())
+        if (attr.isNoUserModification())
         {
           String attrName = attr.getNameOrOID();
-          if (!isEditable(attrName, schema))
-          {
-            schemaReadOnlyAttributes.add(attrName);
-            schemaReadOnlyAttributesLowerCase.add(attrName.toLowerCase());
-          }
+          schemaReadOnlyAttributes.add(attrName);
+          schemaReadOnlyAttributesLowerCase.add(attrName.toLowerCase());
+        }
+        else if (attr.isOperational())
+        {
+          editableOperationalAttrNames.add(attr.getNameOrOID());
         }
       }
     }
@@ -535,7 +541,7 @@
           Utilities.getAttributeNameWithoutOptions(attrName).toLowerCase());
       if (attr != null)
       {
-        AttributeSyntax syntax = attr.getSyntax();
+        AttributeSyntax<?> syntax = attr.getSyntax();
         if (syntax != null)
         {
           isCertificate = syntax.getOID().equals(
@@ -546,37 +552,6 @@
     return isCertificate;
   }
 
-  static String[] editableOperationalAttrNames = {
-      ConfigConstants.ATTR_OBJECTCLASSES,
-      ConfigConstants.ATTR_ATTRIBUTE_TYPES,
-      ConfigConstants.ATTR_MATCHING_RULES,
-      ConfigConstants.ATTR_NAME_FORMS,
-      ConfigConstants.ATTR_LDAP_SYNTAXES,
-      ConfigConstants.ATTR_DIT_STRUCTURE_RULES,
-      "aci"
-  };
-
-  /**
-   * Returns <CODE>true</CODE> if the provided attribute name is an editable
-   * operational attribute and <CODE>false</CODE> otherwise.
-   * @param attrName the attribute name.
-   * @return <CODE>true</CODE> if the provided attribute name is an editable
-   * operational attribute and <CODE>false</CODE> otherwise.
-   */
-  private static boolean isEditableOperationalAttribute(String attrName)
-  {
-    boolean isEditableOperationalAttribute = false;
-    for (String attr : editableOperationalAttrNames)
-    {
-      if (attr.equalsIgnoreCase(attrName))
-      {
-        isEditableOperationalAttribute = true;
-        break;
-      }
-    }
-    return isEditableOperationalAttribute;
-  }
-
   /**
    * Gets the values associated with a given attribute.  The values are the
    * ones displayed in the panel.
@@ -645,16 +620,16 @@
    */
   public static boolean isEditable(String attrName, Schema schema)
   {
-    boolean isOperational = false;
+    boolean isEditable = false;
     attrName = Utilities.getAttributeNameWithoutOptions(attrName);
     if (schema != null)
     {
       AttributeType attrType = schema.getAttributeType(attrName.toLowerCase());
       if (attrType != null)
       {
-        isOperational = attrType.isOperational();
+        isEditable = !attrType.isNoUserModification();
       }
     }
-    return !isOperational || isEditableOperationalAttribute(attrName);
+    return isEditable;
   }
 }

--
Gitblit v1.10.0