001/*
002 * Copyright 2017-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2017-2018 Ping Identity Corporation
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021package com.unboundid.ldap.sdk.unboundidds.controls;
022
023
024
025import com.unboundid.util.StaticUtils;
026import com.unboundid.util.ThreadSafety;
027import com.unboundid.util.ThreadSafetyLevel;
028
029
030
031/**
032 * This enum defines the set of multiple attribute behavior values that may be
033 * used in conjunction with the {@link UniquenessRequestControl}.
034 * <BR>
035 * <BLOCKQUOTE>
036 *   <B>NOTE:</B>  This class, and other classes within the
037 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
038 *   supported for use against Ping Identity, UnboundID, and Alcatel-Lucent 8661
039 *   server products.  These classes provide support for proprietary
040 *   functionality or for external specifications that are not considered stable
041 *   or mature enough to be guaranteed to work in an interoperable way with
042 *   other types of LDAP servers.
043 * </BLOCKQUOTE>
044 */
045@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
046public enum UniquenessMultipleAttributeBehavior
047{
048  /**
049   * Indicates that the server should treat each configured attribute
050   * separately.  For each attribute, the server will attempt to identify
051   * conflicts with other entries that have the same value for the same
052   * attribute, but it will not flag cases in which the same value is used in
053   * different attribute types.  This behavior is equivalent to including
054   * multiple controls in the request, where each control only references a
055   * single attribute type.
056   */
057  UNIQUE_WITHIN_EACH_ATTRIBUTE(0),
058
059
060
061  /**
062   * Indicates that the server should flag any case in which any entry has a
063   * conflicting value in any of the configured attribute types, including cases
064   * in which the same value appears in multiple attributes within the same
065   * entry.
066   */
067  UNIQUE_ACROSS_ALL_ATTRIBUTES_INCLUDING_IN_SAME_ENTRY(1),
068
069
070
071  /**
072   * Indicates that the server should flag any case in which any entry has a
073   * conflicting value in any of the configured attribute types, with the
074   * exception that conflicts will be permitted across different attributes in
075   * the same entry.
076   */
077  UNIQUE_ACROSS_ALL_ATTRIBUTES_EXCEPT_IN_SAME_ENTRY(2),
078
079
080
081  /**
082   * Indicates that the server should flag any case in which another entry has
083   * the same combination of values for all of the configured attribute types.
084   * This will only apply to entries that have at least one value for each of
085   * the target attributes.  If any of the target attributes has multiple
086   * values, then the server will flag each unique combination of those values.
087   */
088  UNIQUE_IN_COMBINATION(3);
089
090
091
092  // The integer value for this uniqueness multiple attribute behavior.
093  private final int intValue;
094
095
096
097  /**
098   * Creates a new uniqueness multiple attribute behavior with the provided
099   * integer value.
100   *
101   * @param  intValue  The integer value for this uniqueness multiple attribute
102   *                   behavior.
103   */
104  UniquenessMultipleAttributeBehavior(final int intValue)
105  {
106    this.intValue = intValue;
107  }
108
109
110
111  /**
112   * Retrieves the integer value for this uniqueness multiple attribute
113   * behavior.
114   *
115   * @return  The integer value for this uniqueness multiple attribute behavior.
116   */
117  public int intValue()
118  {
119    return intValue;
120  }
121
122
123
124  /**
125   * Retrieves the uniqueness multiple attribute behavior with the specified
126   * integer value.
127   *
128   * @param  intValue  The integer value for the uniqueness multiple attribute
129   *                   behavior to retrieve.
130   *
131   * @return  The uniqueness multiple attribute behavior for the provided
132   *          integer value, or {@code null} if there is no multiple attribute
133   *          behavior with the given integer value.
134   */
135  public static UniquenessMultipleAttributeBehavior valueOf(final int intValue)
136  {
137    switch (intValue)
138    {
139      case 0:
140        return UNIQUE_WITHIN_EACH_ATTRIBUTE;
141      case 1:
142        return UNIQUE_ACROSS_ALL_ATTRIBUTES_INCLUDING_IN_SAME_ENTRY;
143      case 2:
144        return UNIQUE_ACROSS_ALL_ATTRIBUTES_EXCEPT_IN_SAME_ENTRY;
145      case 3:
146        return UNIQUE_IN_COMBINATION;
147      default:
148        return null;
149    }
150  }
151
152
153
154  /**
155   * Retrieves the uniqueness multiple attribute behavior with the specified
156   * name.
157   *
158   * @param  name  The name of the uniqueness multiple attribute behavior to
159   *               retrieve.  It must not be {@code null}.
160   *
161   * @return  The requested uniqueness multiple attribute behavior, or
162   *          {@code null} if no such behavior is defined.
163   */
164  public static UniquenessMultipleAttributeBehavior forName(final String name)
165  {
166    switch (StaticUtils.toLowerCase(name))
167    {
168      case "uniquewithineachattribute":
169      case "unique-within-each-attribute":
170      case "unique_within_each_attribute":
171        return UNIQUE_WITHIN_EACH_ATTRIBUTE;
172      case "uniqueacrossallattributesincludinginsameentry":
173      case "unique-across-all-attributes-including-in-same-entry":
174      case "unique_across_all_attributes_including_in_same_entry":
175        return UNIQUE_ACROSS_ALL_ATTRIBUTES_INCLUDING_IN_SAME_ENTRY;
176      case "uniqueacrossallattributesexceptinsameentry":
177      case "unique-across-all-attributes-except-in-same-entry":
178      case "unique_across_all_attributes_except_in_same_entry":
179        return UNIQUE_ACROSS_ALL_ATTRIBUTES_EXCEPT_IN_SAME_ENTRY;
180      case "uniqueincombination":
181      case "unique-in-combination":
182      case "unique_in_combination":
183        return UNIQUE_IN_COMBINATION;
184      default:
185        return null;
186    }
187  }
188}