001/*
002 * Copyright 2017-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2017-2024 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2017-2024 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.unboundidds.controls;
037
038
039
040import com.unboundid.util.NotNull;
041import com.unboundid.util.Nullable;
042import com.unboundid.util.StaticUtils;
043import com.unboundid.util.ThreadSafety;
044import com.unboundid.util.ThreadSafetyLevel;
045
046
047
048/**
049 * This enum defines the set of validation level values that may be used in
050 * conjunction with the {@link UniquenessRequestControl}.
051 * <BR>
052 * <BLOCKQUOTE>
053 *   <B>NOTE:</B>  This class, and other classes within the
054 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
055 *   supported for use against Ping Identity, UnboundID, and
056 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
057 *   for proprietary functionality or for external specifications that are not
058 *   considered stable or mature enough to be guaranteed to work in an
059 *   interoperable way with other types of LDAP servers.
060 * </BLOCKQUOTE>
061 */
062@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
063public enum UniquenessValidationLevel
064{
065  /**
066   * Indicates that no uniqueness validation should be performed.  This
067   * validation level has the same effect for requests sent directly to a
068   * Directory Server and requests sent through a Directory Proxy Server.
069   */
070  NONE(0),
071
072
073
074  /**
075   * Indicates that a single search should be performed per subtree view to
076   * ensure that there are no uniqueness conflicts.  This has the following
077   * behavior:
078   * <UL>
079   *   <LI>
080   *     If the request is received by a Directory Server instance, then only
081   *     that instance will be searched for potential conflicts.  No replicas
082   *     will be examined.
083   *   </LI>
084   *   <LI>
085   *     If the request is received by a Directory Proxy Server instance that
086   *     does not use entry balancing, then only one backend server will be
087   *     searched for potential conflicts.
088   *   </LI>
089   *   <LI>
090   *     If the request is received by a Directory Proxy Server instance that
091   *     uses entry balancing, then the server may only search one backend
092   *     server in one backend set if it can use its global index to identify
093   *     which backend set is appropriate.  However, if the scope of the
094   *     uniqueness request control contains the entire set of entry-balanced
095   *     data and the global index does not include enough information to
096   *     restrict the search to one backend set, then it may be necessary to
097   *     issue the search to one server in each backend set.
098   *   </LI>
099   * </UL>
100   */
101  ALL_SUBTREE_VIEWS(1),
102
103
104
105  /**
106   * Indicates that one server from each entry-balanced backend set should be
107   * searched for potential uniqueness conflicts.  This has the following
108   * behavior:
109   * <UL>
110   *   <LI>
111   *     If the request is received by a Directory Server instance, then only
112   *     that instance will be searched for potential conflicts.  No replicas
113   *     will be examined.
114   *   </LI>
115   *   <LI>
116   *     If the request is received by a Directory Proxy Server instance that
117   *     does not use entry balancing, then only one backend server will be
118   *     searched for potential conflicts.
119   *   </LI>
120   *   <LI>
121   *     If the request is received by a Directory Proxy Server instance that
122   *     uses entry balancing and the scope of the uniqueness request control
123   *     covers the entire set of entry-balanced data, then one server from each
124   *     backend set will be searched for potential conflicts.
125   *   </LI>
126   *   <LI>
127   *     If the request is received by a Directory Proxy Server instance that
128   *     uses entry balancing, and if the uniqueness request control has a base
129   *     DN that is below the balancing point, and if the server's global index
130   *     can be used to identify which backend set contains the entry with that
131   *     DN, then it may only be necessary to search within that one backend
132   *     set, and only within one server in that set.  However, if the global
133   *     index cannot be used to identify the appropriate backend set, then it
134   *     may be necessary to search one server in each backend set.
135   *   </LI>
136   * </UL>
137   */
138  ALL_BACKEND_SETS(2),
139
140
141
142  /**
143   * Indicates that all available servers within the scope of the uniqueness
144   * criteria should be searched for potential uniqueness conflicts.  This has
145   * the following behavior:
146   * <UL>
147   *   <LI>
148   *     If the request is received by a Directory Server instance, then only
149   *     that instance will be searched for potential conflicts.  No replicas
150   *     will be examined.
151   *   </LI>
152   *   <LI>
153   *     If the request is received by a Directory Proxy Server instance that
154   *     does not use entry balancing, then all backend servers with a health
155   *     check state of "AVAILABLE" will be searched for potential conflicts.
156   *   </LI>
157   *   <LI>
158   *     If the request is received by a Directory Proxy Server instance that
159   *     uses entry balancing and the scope of the uniqueness request control
160   *     covers the entire set of entry-balanced data, then all backend servers
161   *     with a health check state of "AVAILABLE" will be searched for
162   *     potential conflicts, across all backend sets.
163   *   </LI>
164   *   <LI>
165   *     If the request is received by a Directory Proxy Server instance that
166   *     uses entry balancing, and if the uniqueness request control has a base
167   *     DN that is below the balancing point, and if the server's global index
168   *     can be used to identify which backend set contains the entry with that
169   *     DN, then it may only be necessary to search all available servers
170   *     within that one backend set.  However, if the global index cannot be
171   *     used to identify the appropriate backend set, then it may be necessary
172   *     to search all available servers in all backend sets.
173   *   </LI>
174   * </UL>
175   */
176  ALL_AVAILABLE_BACKEND_SERVERS(3);
177
178
179
180  // The integer value for this uniqueness validation level.
181  private final int intValue;
182
183
184
185  /**
186   * Creates a new uniqueness validation level with the provided integer value.
187   *
188   * @param  intValue  The integer value for this uniqueness validation level.
189   */
190  UniquenessValidationLevel(final int intValue)
191  {
192    this.intValue = intValue;
193  }
194
195
196
197  /**
198   * Retrieves the integer value for this uniqueness validation level.
199   *
200   * @return  The integer value for this uniqueness validation level.
201   */
202  public int intValue()
203  {
204    return intValue;
205  }
206
207
208
209  /**
210   * Retrieves the uniqueness validation level with the specified integer value.
211   *
212   * @param  intValue  The integer value for the uniqueness validation level to
213   *                   retrieve.
214   *
215   * @return  The uniqueness validation level for the provided integer value, or
216   *          {@code null} if there is no validation level with the given
217   *          integer value.
218   */
219  @Nullable()
220  public static UniquenessValidationLevel valueOf(final int intValue)
221  {
222    switch (intValue)
223    {
224      case 0:
225        return NONE;
226      case 1:
227        return ALL_SUBTREE_VIEWS;
228      case 2:
229        return ALL_BACKEND_SETS;
230      case 3:
231        return ALL_AVAILABLE_BACKEND_SERVERS;
232      default:
233        return null;
234    }
235  }
236
237
238
239  /**
240   * Retrieves the uniqueness validation level with the specified name.
241   *
242   * @param  name  The name of the uniqueness validation level to retrieve.  It
243   *               must not be {@code null}.
244   *
245   * @return  The requested uniqueness validation level, or {@code null} if no
246   *          such level is defined.
247   */
248  @Nullable()
249  public static UniquenessValidationLevel forName(@NotNull final String name)
250  {
251    switch (StaticUtils.toLowerCase(name))
252    {
253      case "none":
254        return NONE;
255      case "allsubtreeviews":
256      case "all-subtree-views":
257      case "all_subtree_views":
258        return ALL_SUBTREE_VIEWS;
259      case "allbackendsets":
260      case "all-backend-sets":
261      case "all_backend_sets":
262        return ALL_BACKEND_SETS;
263      case "allavailablebackendservers":
264      case "all-available-backend-servers":
265      case "all_available_backend_servers":
266        return ALL_AVAILABLE_BACKEND_SERVERS;
267      default:
268        return null;
269    }
270  }
271}