001/*
002 * Copyright 2017-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2017-2020 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-2020 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.StaticUtils;
041import com.unboundid.util.ThreadSafety;
042import com.unboundid.util.ThreadSafetyLevel;
043
044
045
046/**
047 * This enum defines the set of validation level values that may be used in
048 * conjunction with the {@link UniquenessRequestControl}.
049 * <BR>
050 * <BLOCKQUOTE>
051 *   <B>NOTE:</B>  This class, and other classes within the
052 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
053 *   supported for use against Ping Identity, UnboundID, and
054 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
055 *   for proprietary functionality or for external specifications that are not
056 *   considered stable or mature enough to be guaranteed to work in an
057 *   interoperable way with other types of LDAP servers.
058 * </BLOCKQUOTE>
059 */
060@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
061public enum UniquenessValidationLevel
062{
063  /**
064   * Indicates that no uniqueness validation should be performed.  This
065   * validation level has the same effect for requests sent directly to a
066   * Directory Server and requests sent through a Directory Proxy Server.
067   */
068  NONE(0),
069
070
071
072  /**
073   * Indicates that a single search should be performed per subtree view to
074   * ensure that there are no uniqueness conflicts.  This has the following
075   * behavior:
076   * <UL>
077   *   <LI>
078   *     If the request is received by a Directory Server instance, then only
079   *     that instance will be searched for potential conflicts.  No replicas
080   *     will be examined.
081   *   </LI>
082   *   <LI>
083   *     If the request is received by a Directory Proxy Server instance that
084   *     does not use entry balancing, then only one backend server will be
085   *     searched for potential conflicts.
086   *   </LI>
087   *   <LI>
088   *     If the request is received by a Directory Proxy Server instance that
089   *     uses entry balancing, then the server may only search one backend
090   *     server in one backend set if it can use its global index to identify
091   *     which backend set is appropriate.  However, if the scope of the
092   *     uniqueness request control contains the entire set of entry-balanced
093   *     data and the global index does not include enough information to
094   *     restrict the search to one backend set, then it may be necessary to
095   *     issue the search to one server in each backend set.
096   *   </LI>
097   * </UL>
098   */
099  ALL_SUBTREE_VIEWS(1),
100
101
102
103  /**
104   * Indicates that one server from each entry-balanced backend set should be
105   * searched for potential uniqueness conflicts.  This has the following
106   * behavior:
107   * <UL>
108   *   <LI>
109   *     If the request is received by a Directory Server instance, then only
110   *     that instance will be searched for potential conflicts.  No replicas
111   *     will be examined.
112   *   </LI>
113   *   <LI>
114   *     If the request is received by a Directory Proxy Server instance that
115   *     does not use entry balancing, then only one backend server will be
116   *     searched for potential conflicts.
117   *   </LI>
118   *   <LI>
119   *     If the request is received by a Directory Proxy Server instance that
120   *     uses entry balancing and the scope of the uniqueness request control
121   *     covers the entire set of entry-balanced data, then one server from each
122   *     backend set will be searched for potential conflicts.
123   *   </LI>
124   *   <LI>
125   *     If the request is received by a Directory Proxy Server instance that
126   *     uses entry balancing, and if the uniqueness request control has a base
127   *     DN that is below the balancing point, and if the server's global index
128   *     can be used to identify which backend set contains the entry with that
129   *     DN, then it may only be necessary to search within that one backend
130   *     set, and only within one server in that set.  However, if the global
131   *     index cannot be used to identify the appropriate backend set, then it
132   *     may be necessary to search one server in each backend set.
133   *   </LI>
134   * </UL>
135   */
136  ALL_BACKEND_SETS(2),
137
138
139
140  /**
141   * Indicates that all available servers within the scope of the uniqueness
142   * criteria should be searched for potential uniqueness conflicts.  This has
143   * the following behavior:
144   * <UL>
145   *   <LI>
146   *     If the request is received by a Directory Server instance, then only
147   *     that instance will be searched for potential conflicts.  No replicas
148   *     will be examined.
149   *   </LI>
150   *   <LI>
151   *     If the request is received by a Directory Proxy Server instance that
152   *     does not use entry balancing, then all backend servers with a health
153   *     check state of "AVAILABLE" will be searched for potential conflicts.
154   *   </LI>
155   *   <LI>
156   *     If the request is received by a Directory Proxy Server instance that
157   *     uses entry balancing and the scope of the uniqueness request control
158   *     covers the entire set of entry-balanced data, then all backend servers
159   *     with a health check state of "AVAILABLE" will be searched for
160   *     potential conflicts, across all backend sets.
161   *   </LI>
162   *   <LI>
163   *     If the request is received by a Directory Proxy Server instance that
164   *     uses entry balancing, and if the uniqueness request control has a base
165   *     DN that is below the balancing point, and if the server's global index
166   *     can be used to identify which backend set contains the entry with that
167   *     DN, then it may only be necessary to search all available servers
168   *     within that one backend set.  However, if the global index cannot be
169   *     used to identify the appropriate backend set, then it may be necessary
170   *     to search all available servers in all backend sets.
171   *   </LI>
172   * </UL>
173   */
174  ALL_AVAILABLE_BACKEND_SERVERS(3);
175
176
177
178  // The integer value for this uniqueness validation level.
179  private final int intValue;
180
181
182
183  /**
184   * Creates a new uniqueness validation level with the provided integer value.
185   *
186   * @param  intValue  The integer value for this uniqueness validation level.
187   */
188  UniquenessValidationLevel(final int intValue)
189  {
190    this.intValue = intValue;
191  }
192
193
194
195  /**
196   * Retrieves the integer value for this uniqueness validation level.
197   *
198   * @return  The integer value for this uniqueness validation level.
199   */
200  public int intValue()
201  {
202    return intValue;
203  }
204
205
206
207  /**
208   * Retrieves the uniqueness validation level with the specified integer value.
209   *
210   * @param  intValue  The integer value for the uniqueness validation level to
211   *                   retrieve.
212   *
213   * @return  The uniqueness validation level for the provided integer value, or
214   *          {@code null} if there is no validation level with the given
215   *          integer value.
216   */
217  public static UniquenessValidationLevel valueOf(final int intValue)
218  {
219    switch (intValue)
220    {
221      case 0:
222        return NONE;
223      case 1:
224        return ALL_SUBTREE_VIEWS;
225      case 2:
226        return ALL_BACKEND_SETS;
227      case 3:
228        return ALL_AVAILABLE_BACKEND_SERVERS;
229      default:
230        return null;
231    }
232  }
233
234
235
236  /**
237   * Retrieves the uniqueness validation level with the specified name.
238   *
239   * @param  name  The name of the uniqueness validation level to retrieve.  It
240   *               must not be {@code null}.
241   *
242   * @return  The requested uniqueness validation level, or {@code null} if no
243   *          such level is defined.
244   */
245  public static UniquenessValidationLevel forName(final String name)
246  {
247    switch (StaticUtils.toLowerCase(name))
248    {
249      case "none":
250        return NONE;
251      case "allsubtreeviews":
252      case "all-subtree-views":
253      case "all_subtree_views":
254        return ALL_SUBTREE_VIEWS;
255      case "allbackendsets":
256      case "all-backend-sets":
257      case "all_backend_sets":
258        return ALL_BACKEND_SETS;
259      case "allavailablebackendservers":
260      case "all-available-backend-servers":
261      case "all_available_backend_servers":
262        return ALL_AVAILABLE_BACKEND_SERVERS;
263      default:
264        return null;
265    }
266  }
267}