From 6b7eee7b04e2dbf87282c285218c39bbf29b20dc Mon Sep 17 00:00:00 2001
From: jcambon <jcambon@localhost>
Date: Mon, 10 Nov 2008 08:07:58 +0000
Subject: [PATCH] Fix for Issue #3569: dsconfig does not handle correctly multi-valued properties

---
 opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/ArgumentExceptionFactory.java |   19 +++++++++
 opendj-sdk/opends/src/messages/messages/dsconfig.properties                                 |    3 +
 opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java |   42 +++++++++++++--------
 3 files changed, 47 insertions(+), 17 deletions(-)

diff --git a/opendj-sdk/opends/src/messages/messages/dsconfig.properties b/opendj-sdk/opends/src/messages/messages/dsconfig.properties
index a5524ef..f941726 100644
--- a/opendj-sdk/opends/src/messages/messages/dsconfig.properties
+++ b/opendj-sdk/opends/src/messages/messages/dsconfig.properties
@@ -179,7 +179,7 @@
  modification "%s" does not contain a property value. The argument should have \
  the following syntax: property[+|-]:value
 SEVERE_ERR_DSCFG_ERROR_INCOMPATIBLE_PROPERTY_MOD_1071=The property \
- modification "%s" is incompatible with a previous modification to the same \
+ modification "%s" is incompatible with another modification to the same \
  property
 SEVERE_ERR_DSCFG_ERROR_WRONG_MANAGED_OBJECT_TYPE_1072=The %s could not be \
  retrieved because it was the wrong type of managed object: %s
@@ -470,3 +470,4 @@
  server at %s on port %s. Check this port is an administration port
 SEVERE_ERR_DSCFG_ERROR_LDAP_FAILED_TO_CONNECT_NOT_TRUSTED_158=Unable to connect to the \
  server at %s on port %s. In non-interactive mode, you must use the '--trustAll' option
+SEVERE_ERR_DSCFG_ERROR_VALUE_DOES_NOT_EXIST_159=The value %s for the %s property does not exist
\ No newline at end of file
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/ArgumentExceptionFactory.java b/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/ArgumentExceptionFactory.java
index 525a6fd..b5bcf32 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/ArgumentExceptionFactory.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/ArgumentExceptionFactory.java
@@ -604,6 +604,25 @@
 
 
   /**
+   * Creates an argument exception which should be used when a multi-valued
+   * property does not contain a given value.
+   *
+   * @param value
+   *          The property value.
+   * @param propertyName
+   *          The property name.
+   * @return Returns an argument exception.
+   */
+  public static ArgumentException unknownValueForMultiValuedProperty(
+    String value, String propertyName) {
+          Message msg = ERR_DSCFG_ERROR_VALUE_DOES_NOT_EXIST.get(
+            value, propertyName);
+    return new ArgumentException(msg);
+  }
+
+
+
+  /**
    * Creates a CLI exception which should be used when a managed
    * object is retrieved but does not have the correct type
    * appropriate for the associated sub-command.
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java b/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
index e506b6d..7b767aa 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
@@ -754,6 +754,9 @@
 
     // Set properties.
     for (String m : propertySetArgument.getValues()) {
+      if (!propertyResetArgument.getValues().isEmpty()) {
+        throw ArgumentExceptionFactory.incompatiblePropertyModification(m);
+      }
       // Parse the property "property:value".
       int sep = m.indexOf(':');
 
@@ -790,6 +793,9 @@
 
     // Remove properties.
     for (String m : propertyRemoveArgument.getValues()) {
+      if (!propertyResetArgument.getValues().isEmpty()) {
+        throw ArgumentExceptionFactory.incompatiblePropertyModification(m);
+      }
       // Parse the property "property:value".
       int sep = m.indexOf(':');
 
@@ -816,19 +822,20 @@
       }
 
       // Apply the modification.
-      if (lastModTypes.containsKey(propertyName)) {
-        if (lastModTypes.get(propertyName) == ModificationType.SET) {
-          throw ArgumentExceptionFactory.incompatiblePropertyModification(m);
-        }
-      } else {
-        lastModTypes.put(propertyName, ModificationType.REMOVE);
-        modifyPropertyValues(child, pd, changes, ModificationType.REMOVE,
-            value);
+      if (lastModTypes.containsKey(propertyName) &&
+        (lastModTypes.get(propertyName) == ModificationType.SET)) {
+        throw ArgumentExceptionFactory.incompatiblePropertyModification(m);
       }
+
+      lastModTypes.put(propertyName, ModificationType.REMOVE);
+      modifyPropertyValues(child, pd, changes, ModificationType.REMOVE, value);
     }
 
     // Add properties.
     for (String m : propertyAddArgument.getValues()) {
+      if (!propertyResetArgument.getValues().isEmpty()) {
+        throw ArgumentExceptionFactory.incompatiblePropertyModification(m);
+      }
       // Parse the property "property:value".
       int sep = m.indexOf(':');
 
@@ -855,14 +862,13 @@
       }
 
       // Apply the modification.
-      if (lastModTypes.containsKey(propertyName)) {
-        if (lastModTypes.get(propertyName) == ModificationType.SET) {
-          throw ArgumentExceptionFactory.incompatiblePropertyModification(m);
-        }
-      } else {
-        lastModTypes.put(propertyName, ModificationType.ADD);
-        modifyPropertyValues(child, pd, changes, ModificationType.ADD, value);
+      if (lastModTypes.containsKey(propertyName) &&
+        (lastModTypes.get(propertyName) == ModificationType.SET)) {
+        throw ArgumentExceptionFactory.incompatiblePropertyModification(m);
       }
+
+      lastModTypes.put(propertyName, ModificationType.ADD);
+      modifyPropertyValues(child, pd, changes, ModificationType.ADD, value);
     }
 
     // Apply the command line changes.
@@ -931,7 +937,11 @@
         values.add(value);
         break;
       case REMOVE:
-        values.remove(value);
+        if (values.remove(value) != true) {
+          // value was not part of values
+          throw ArgumentExceptionFactory.
+            unknownValueForMultiValuedProperty(s, pd.getName());
+        }
         break;
       case SET:
         values = new TreeSet<T>(pd);

--
Gitblit v1.10.0