From fbea82c15cf5f1d069e5aa00dcdfdd5172a2cc7b Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Fri, 15 Feb 2013 13:58:25 +0000
Subject: [PATCH] Final fix for OPENDJ-758 : Implement configurable update policy for simple and default mappers

---
 opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/WritabilityPolicy.java |   50 ++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/WritabilityPolicy.java b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/WritabilityPolicy.java
index 2b062bd..d300b62 100644
--- a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/WritabilityPolicy.java
+++ b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/WritabilityPolicy.java
@@ -16,26 +16,64 @@
 
 package org.forgerock.opendj.rest2ldap;
 
+import org.forgerock.opendj.ldap.AttributeDescription;
+
 /**
  * The writability policy determines whether or not an attribute supports
  * updates.
  */
 public enum WritabilityPolicy {
+    // @formatter:off
     /**
-     * The attribute may be provided when creating a new resource, but cannot be
-     * modified afterwards.
+     * The attribute cannot be provided when creating a new resource, nor
+     * modified afterwards. Attempts to update the attribute will result in an
+     * error.
      */
-    CREATE_ONLY,
+    READ_ONLY(false),
 
     /**
      * The attribute cannot be provided when creating a new resource, nor
-     * modified afterwards.
+     * modified afterwards. Attempts to update the attribute will not result in
+     * an error (the new values will be ignored).
      */
-    READ_ONLY,
+    READ_ONLY_DISCARD_WRITES(true),
+
+    /**
+     * The attribute may be provided when creating a new resource, but cannot be
+     * modified afterwards. Attempts to update the attribute will result in an
+     * error.
+     */
+    CREATE_ONLY(false),
+
+    /**
+     * The attribute may be provided when creating a new resource, but cannot be
+     * modified afterwards. Attempts to update the attribute will not result in
+     * an error (the new values will be ignored).
+     */
+    CREATE_ONLY_DISCARD_WRITES(true),
 
     /**
      * The attribute may be provided when creating a new resource, and modified
      * afterwards.
      */
-    READ_WRITE;
+    READ_WRITE(false);
+    // @formatter:on
+
+    private final boolean discardWrites;
+
+    private WritabilityPolicy(final boolean discardWrites) {
+        this.discardWrites = discardWrites;
+    }
+
+    boolean canCreate(final AttributeDescription attribute) {
+        return this != READ_ONLY && !attribute.getAttributeType().isNoUserModification();
+    }
+
+    boolean canWrite(final AttributeDescription attribute) {
+        return this == READ_WRITE && !attribute.getAttributeType().isNoUserModification();
+    }
+
+    boolean discardWrites() {
+        return discardWrites;
+    }
 }

--
Gitblit v1.10.0