From 16869da731710f4c3754c7b229fa7346211a25a4 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Fri, 01 Feb 2013 14:57:43 +0000
Subject: [PATCH] Pull EntryContainer into LDAPCollectionResourceProvider until layering is better understood.
---
opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Config.java | 197 +++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 188 insertions(+), 9 deletions(-)
diff --git a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Config.java b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Config.java
index b36b195..41f16eb 100644
--- a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Config.java
+++ b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Config.java
@@ -15,6 +15,9 @@
*/
package org.forgerock.opendj.rest2ldap;
+import static org.forgerock.opendj.rest2ldap.Config.ReadOnUpdatePolicy.USE_READ_ENTRY_CONTROLS;
+import static org.forgerock.opendj.rest2ldap.Utils.ensureNotNull;
+
import org.forgerock.opendj.ldap.Filter;
/**
@@ -22,24 +25,200 @@
*/
public final class Config {
- private final Filter trueFilter = Filter.objectClassPresent();
- private final Filter falseFilter = Filter.present("1.1");
+ /**
+ * An interface for incrementally constructing common configuration options.
+ */
+ public static final class Builder {
+ private Filter falseFilter;
+ private ReadOnUpdatePolicy readOnUpdatePolicy;
+ private Filter trueFilter;
+
+ private Builder() {
+ // Nothing to do.
+ }
+
+ /**
+ * Returns a new configuration based on the current state of this
+ * builder.
+ *
+ * @return A new configuration based on the current state of this
+ * builder.
+ */
+ public Config build() {
+ return new Config(trueFilter, falseFilter, readOnUpdatePolicy);
+ }
+
+ /**
+ * Sets the absolute false filter which should be used when querying the
+ * LDAP server.
+ *
+ * @param filter
+ * The absolute false filter.
+ * @return A reference to this builder.
+ */
+ public Builder falseFilter(final Filter filter) {
+ this.trueFilter = ensureNotNull(filter);
+ return this;
+ }
+
+ /**
+ * Sets the policy which should be used in order to read an entry before
+ * it is deleted, or after it is added or modified.
+ *
+ * @param policy
+ * The policy which should be used in order to read an entry
+ * before it is deleted, or after it is added or modified.
+ * @return A reference to this builder.
+ */
+ public Builder readOnUpdatePolicy(final ReadOnUpdatePolicy policy) {
+ this.readOnUpdatePolicy = ensureNotNull(policy);
+ return this;
+ }
+
+ /**
+ * Sets the absolute true filter which should be used when querying the
+ * LDAP server.
+ *
+ * @param filter
+ * The absolute true filter.
+ * @return A reference to this builder.
+ */
+ public Builder trueFilter(final Filter filter) {
+ this.trueFilter = ensureNotNull(filter);
+ return this;
+ }
+ };
/**
- * Returns the absolute true filter.
- *
- * @return The absolute true filter.
+ * The policy which should be used in order to read an entry before it is
+ * deleted, or after it is added or modified.
*/
- public Filter getTrueFilter() {
- return trueFilter;
+ public static enum ReadOnUpdatePolicy {
+ /**
+ * The LDAP entry will not be read when an update is performed. More
+ * specifically, the REST resource will not be returned as part of a
+ * create, delete, patch, or update request.
+ */
+ DISABLED,
+
+ /**
+ * The LDAP entry will be read atomically using the RFC 4527 read-entry
+ * controls. More specifically, the REST resource will be returned as
+ * part of a create, delete, patch, or update request, and it will
+ * reflect the state of the resource at the time the update was
+ * performed. This policy requires that the LDAP server supports RFC
+ * 4527.
+ */
+ USE_READ_ENTRY_CONTROLS,
+
+ /**
+ * The LDAP entry will be read non-atomically using an LDAP search when
+ * an update is performed. More specifically, the REST resource will be
+ * returned as part of a create, delete, patch, or update request, but
+ * it may not reflect the state of the resource at the time the update
+ * was performed.
+ */
+ USE_SEARCH;
+ }
+
+ private static final Config DEFAULT = new Builder().trueFilter(Filter.objectClassPresent())
+ .falseFilter(Filter.present("1.1")).readOnUpdatePolicy(USE_READ_ENTRY_CONTROLS).build();
+
+ /**
+ * Returns a new builder which can be used for incrementally constructing
+ * common configuration options. The builder will initially have
+ * {@link #defaultConfig() default} settings.
+ *
+ * @return The new builder.
+ */
+ public static Builder builder() {
+ return builder(DEFAULT);
}
/**
- * Returns the absolute false filter.
+ * Returns a new builder which can be used for incrementally constructing
+ * common configuration options. The builder will initially have the same
+ * settings as the provided configuration.
+ *
+ * @param config
+ * The initial settings.
+ * @return The new builder.
+ */
+ public static Builder builder(final Config config) {
+ return new Builder().trueFilter(config.trueFilter()).falseFilter(config.falseFilter())
+ .readOnUpdatePolicy(config.readOnUpdatePolicy());
+ }
+
+ /**
+ * Returns the default configuration having the following settings:
+ * <ul>
+ * <li>the absolute true filter {@code (objectClass=*)}
+ * <li>the absolute false filter {@code (1.1=*)}
+ * <li>the read on update policy
+ * {@link ReadOnUpdatePolicy#USE_READ_ENTRY_CONTROLS}.
+ * </ul>
+ *
+ * @return The default configuration.
+ */
+ public static Config defaultConfig() {
+ return DEFAULT;
+ }
+
+ private final Filter falseFilter;
+
+ private final ReadOnUpdatePolicy readOnUpdatePolicy;
+ private final Filter trueFilter;
+
+ private Config(final Filter trueFilter, final Filter falseFilter,
+ final ReadOnUpdatePolicy readOnUpdatePolicy) {
+ this.trueFilter = trueFilter;
+ this.falseFilter = falseFilter;
+ this.readOnUpdatePolicy = readOnUpdatePolicy;
+ }
+
+ /**
+ * Returns the absolute false filter which should be used when querying the
+ * LDAP server.
*
* @return The absolute false filter.
*/
- public Filter getFalseFilter() {
+ public Filter falseFilter() {
return falseFilter;
}
+
+ /**
+ * Returns the policy which should be used in order to read an entry before
+ * it is deleted, or after it is added or modified.
+ *
+ * @return The policy which should be used in order to read an entry before
+ * it is deleted, or after it is added or modified.
+ */
+ public ReadOnUpdatePolicy readOnUpdatePolicy() {
+ return readOnUpdatePolicy;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("trueFilter=");
+ builder.append(trueFilter);
+ builder.append(", falseFilter=");
+ builder.append(falseFilter);
+ builder.append(", readOnUpdatePolicy=");
+ builder.append(readOnUpdatePolicy);
+ return builder.toString();
+ }
+
+ /**
+ * Returns the absolute true filter which should be used when querying the
+ * LDAP server.
+ *
+ * @return The absolute true filter.
+ */
+ public Filter trueFilter() {
+ return trueFilter;
+ }
}
--
Gitblit v1.10.0