mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Matthew Swift
15.58.2013 fbea82c15cf5f1d069e5aa00dcdfdd5172a2cc7b
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;
    }
}