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 multiple attribute behavior values that may be
050 * used in 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 UniquenessMultipleAttributeBehavior
064{
065  /**
066   * Indicates that the server should treat each configured attribute
067   * separately.  For each attribute, the server will attempt to identify
068   * conflicts with other entries that have the same value for the same
069   * attribute, but it will not flag cases in which the same value is used in
070   * different attribute types.  This behavior is equivalent to including
071   * multiple controls in the request, where each control only references a
072   * single attribute type.
073   */
074  UNIQUE_WITHIN_EACH_ATTRIBUTE(0),
075
076
077
078  /**
079   * Indicates that the server should flag any case in which any entry has a
080   * conflicting value in any of the configured attribute types, including cases
081   * in which the same value appears in multiple attributes within the same
082   * entry.
083   */
084  UNIQUE_ACROSS_ALL_ATTRIBUTES_INCLUDING_IN_SAME_ENTRY(1),
085
086
087
088  /**
089   * Indicates that the server should flag any case in which any entry has a
090   * conflicting value in any of the configured attribute types, with the
091   * exception that conflicts will be permitted across different attributes in
092   * the same entry.
093   */
094  UNIQUE_ACROSS_ALL_ATTRIBUTES_EXCEPT_IN_SAME_ENTRY(2),
095
096
097
098  /**
099   * Indicates that the server should flag any case in which another entry has
100   * the same combination of values for all of the configured attribute types.
101   * This will only apply to entries that have at least one value for each of
102   * the target attributes.  If any of the target attributes has multiple
103   * values, then the server will flag each unique combination of those values.
104   */
105  UNIQUE_IN_COMBINATION(3);
106
107
108
109  // The integer value for this uniqueness multiple attribute behavior.
110  private final int intValue;
111
112
113
114  /**
115   * Creates a new uniqueness multiple attribute behavior with the provided
116   * integer value.
117   *
118   * @param  intValue  The integer value for this uniqueness multiple attribute
119   *                   behavior.
120   */
121  UniquenessMultipleAttributeBehavior(final int intValue)
122  {
123    this.intValue = intValue;
124  }
125
126
127
128  /**
129   * Retrieves the integer value for this uniqueness multiple attribute
130   * behavior.
131   *
132   * @return  The integer value for this uniqueness multiple attribute behavior.
133   */
134  public int intValue()
135  {
136    return intValue;
137  }
138
139
140
141  /**
142   * Retrieves the uniqueness multiple attribute behavior with the specified
143   * integer value.
144   *
145   * @param  intValue  The integer value for the uniqueness multiple attribute
146   *                   behavior to retrieve.
147   *
148   * @return  The uniqueness multiple attribute behavior for the provided
149   *          integer value, or {@code null} if there is no multiple attribute
150   *          behavior with the given integer value.
151   */
152  @Nullable()
153  public static UniquenessMultipleAttributeBehavior valueOf(final int intValue)
154  {
155    switch (intValue)
156    {
157      case 0:
158        return UNIQUE_WITHIN_EACH_ATTRIBUTE;
159      case 1:
160        return UNIQUE_ACROSS_ALL_ATTRIBUTES_INCLUDING_IN_SAME_ENTRY;
161      case 2:
162        return UNIQUE_ACROSS_ALL_ATTRIBUTES_EXCEPT_IN_SAME_ENTRY;
163      case 3:
164        return UNIQUE_IN_COMBINATION;
165      default:
166        return null;
167    }
168  }
169
170
171
172  /**
173   * Retrieves the uniqueness multiple attribute behavior with the specified
174   * name.
175   *
176   * @param  name  The name of the uniqueness multiple attribute behavior to
177   *               retrieve.  It must not be {@code null}.
178   *
179   * @return  The requested uniqueness multiple attribute behavior, or
180   *          {@code null} if no such behavior is defined.
181   */
182  @Nullable()
183  public static UniquenessMultipleAttributeBehavior forName(
184                     @NotNull final String name)
185  {
186    switch (StaticUtils.toLowerCase(name))
187    {
188      case "uniquewithineachattribute":
189      case "unique-within-each-attribute":
190      case "unique_within_each_attribute":
191        return UNIQUE_WITHIN_EACH_ATTRIBUTE;
192      case "uniqueacrossallattributesincludinginsameentry":
193      case "unique-across-all-attributes-including-in-same-entry":
194      case "unique_across_all_attributes_including_in_same_entry":
195        return UNIQUE_ACROSS_ALL_ATTRIBUTES_INCLUDING_IN_SAME_ENTRY;
196      case "uniqueacrossallattributesexceptinsameentry":
197      case "unique-across-all-attributes-except-in-same-entry":
198      case "unique_across_all_attributes_except_in_same_entry":
199        return UNIQUE_ACROSS_ALL_ATTRIBUTES_EXCEPT_IN_SAME_ENTRY;
200      case "uniqueincombination":
201      case "unique-in-combination":
202      case "unique_in_combination":
203        return UNIQUE_IN_COMBINATION;
204      default:
205        return null;
206    }
207  }
208}