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