001/*
002 * Copyright 2008-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-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.tasks;
022
023
024
025import java.io.Serializable;
026import java.util.Date;
027
028import com.unboundid.util.NotMutable;
029import com.unboundid.util.ThreadSafety;
030import com.unboundid.util.ThreadSafetyLevel;
031
032import static com.unboundid.util.Validator.*;
033
034
035
036/**
037 * This class provides information about a property that may be used to schedule
038 * a task.
039 * <BR>
040 * <BLOCKQUOTE>
041 *   <B>NOTE:</B>  This class, and other classes within the
042 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
043 *   supported for use against Ping Identity, UnboundID, and Alcatel-Lucent 8661
044 *   server products.  These classes provide support for proprietary
045 *   functionality or for external specifications that are not considered stable
046 *   or mature enough to be guaranteed to work in an interoperable way with
047 *   other types of LDAP servers.
048 * </BLOCKQUOTE>
049 * <BR>
050 * Elements of a task property include:
051 * <UL>
052 *   <LI>The name of the LDAP attribute used to store values for this
053 *       property.</LI>
054 *   <LI>A user-friendly display name for the property.</LI>
055 *   <LI>A user-friendly description for the property.</LI>
056 *   <LI>The expected data type for values of the property.</LI>
057 *   <LI>An optional set of allowed values for the property.  If this is
058 *       defined, then the property will not be allowed to have any value that
059 *       is not included in this set.</LI>
060 *   <LI>A flag that indicates whether the property is required when scheduling
061 *       the corresponding type of task.</LI>
062 *   <LI>A flag that indicates whether the property is allowed to have multiple
063 *       values.</LI>
064 *   <LI>A flag that indicates whether the property should be considered
065 *       advanced and therefore may be hidden from users if a simplified
066 *       interface is to be presented.</LI>
067 * </UL>
068 */
069@NotMutable()
070@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
071public final class TaskProperty
072       implements Serializable
073{
074  /**
075   * The serial version UID for this serializable class.
076   */
077  private static final long serialVersionUID = 8438462010090371903L;
078
079
080
081  // Indicates whether this task property is advanced.
082  private final boolean advanced;
083
084  // Indicates whether this task property is multivalued.
085  private final boolean multiValued;
086
087  // Indicates whether this task property is required.
088  private final boolean required;
089
090  // The data type for this task property.
091  private final Class<?> dataType;
092
093  // The set of allowed values for this task property.
094  private final Object[] allowedValues;
095
096  // The name of the LDAP attribute associated with this task property.
097  private final String attributeName;
098
099  // The human-readable description for this task property.
100  private final String description;
101
102  // The human-readable display name for this task property.
103  private final String displayName;
104
105
106
107  /**
108   * Creates a new task property with the provided information.
109   *
110   * @param  attributeName  The name of the LDAP attribute associated with this
111   *                        task property.  It must not be {@code null}.
112   * @param  displayName    The human-readable display name for this task
113   *                        property.  It must not be {@code null}.
114   * @param  description    The human-readable description for this task
115   *                        property.  It must not be {@code null}.
116   * @param  dataType       A class representing the data type for this
117   *                        property.  Allowed data type classes include:
118   *                        {@code Boolean}, {@code Date}, {@code Long}, and
119   *                        {@code String}.  It must not be {@code null}.
120   * @param  required       Indicates whether this property must be provided
121   *                        when scheduling a task.
122   * @param  multiValued    Indicates whether this property is allowed to have
123   *                        multiple values.
124   * @param  advanced       Indicates whether this property may be considered
125   *                        advanced and doesn't necessarily need to be
126   *                        presented to the user.  Advanced properties must not
127   *                        be required.
128   */
129  public TaskProperty(final String attributeName, final String displayName,
130                      final String description, final Class<?> dataType,
131                      final boolean required, final boolean multiValued,
132                      final boolean advanced)
133  {
134    this(attributeName, displayName, description, dataType, required,
135         multiValued, advanced, null);
136  }
137
138
139
140  /**
141   * Creates a new task property with the provided information.
142   *
143   * @param  attributeName  The name of the LDAP attribute associated with this
144   *                        task property.  It must not be {@code null}.
145   * @param  displayName    The human-readable display name for this task
146   *                        property.  It must not be {@code null}.
147   * @param  description    The human-readable description for this task
148   *                        property.  It must not be {@code null}.
149   * @param  dataType       A class representing the data type for this
150   *                        property.  Allowed data type classes include:
151   *                        {@code Boolean}, {@code Date}, {@code Long}, and
152   *                        {@code String}.  It must not be {@code null}.
153   * @param  required       Indicates whether this property must be provided
154   *                        when scheduling a task.
155   * @param  multiValued    Indicates whether this property is allowed to have
156   *                        multiple values.
157   * @param  advanced       Indicates whether this property may be considered
158   *                        advanced and doesn't necessarily need to be
159   *                        presented to the user.  Advanced properties must not
160   *                        be required.
161   * @param  allowedValues  The set of allowed values for this task property.
162   *                        It may be {@code null} if there is not a predefined
163   *                        set of acceptable values.  If it is provided, then
164   *                        all values must be objects of the class specified as
165   *                        the data type.
166   */
167  public TaskProperty(final String attributeName, final String displayName,
168                      final String description, final Class<?> dataType,
169                      final boolean required, final boolean multiValued,
170                      final boolean advanced, final Object[] allowedValues)
171  {
172    ensureNotNull(attributeName, displayName, description, dataType);
173    ensureTrue(dataType.equals(Boolean.class) || dataType.equals(Date.class) ||
174               dataType.equals(Long.class) || dataType.equals(String.class));
175    ensureFalse(required && advanced,
176                "TaskProperty.required and advanced must not both be true.");
177
178    this.attributeName = attributeName;
179    this.displayName   = displayName;
180    this.description   = description;
181    this.dataType      = dataType;
182    this.required      = required;
183    this.multiValued   = multiValued;
184    this.advanced      = advanced;
185
186    if ((allowedValues == null) || (allowedValues.length == 0))
187    {
188      this.allowedValues = null;
189    }
190    else
191    {
192      for (final Object o : allowedValues)
193      {
194        ensureTrue(dataType.equals(o.getClass()));
195      }
196
197      this.allowedValues = allowedValues;
198    }
199  }
200
201
202
203  /**
204   * Retrieves the name of the LDAP attribute associated with this task
205   * property.
206   *
207   * @return  The name of the LDAP attribute associated with this task property.
208   */
209  public String getAttributeName()
210  {
211    return attributeName;
212  }
213
214
215
216  /**
217   * Retrieves the human-readable display name for this task property.
218   *
219   * @return  The human-readable display name for this task property.
220   */
221  public String getDisplayName()
222  {
223    return displayName;
224  }
225
226
227
228  /**
229   * Retrieves the human-readable description for this task property.
230   *
231   * @return  The human-readable description for this task property.
232   */
233  public String getDescription()
234  {
235    return description;
236  }
237
238
239
240  /**
241   * Retrieves the data type for this task property, which represents the
242   * expected data type for the value(s) of this property.  Supported data types
243   * include {@code Boolean}, {@code Date}, {@code Long}, and {@code String}.
244   *
245   * @return  The data type for this task property.
246   */
247  public Class<?> getDataType()
248  {
249    return dataType;
250  }
251
252
253
254  /**
255   * Indicates whether this task property is required to be provided in order to
256   * schedule a task.
257   *
258   * @return  {@code true} if this task property is required, or {@code false}
259   *          if it is not.
260   */
261  public boolean isRequired()
262  {
263    return required;
264  }
265
266
267
268  /**
269   * Indicates whether this task property is allowed to have multiple values.
270   *
271   * @return  {@code true} if this task property is allowed to have multiple
272   *          values, or {@code false} if it may only have a single value.
273   */
274  public boolean isMultiValued()
275  {
276    return multiValued;
277  }
278
279
280
281  /**
282   * Indicates whether this task property is considered advanced.  Advanced
283   * properties are not necessarily required to schedule the task and may be
284   * hidden from the user if simplicity is desired over flexibility.
285   *
286   * @return  {@code true} if this task property is considered advanced, or
287   *          {@code false} if not.
288   */
289  public boolean isAdvanced()
290  {
291    return advanced;
292  }
293
294
295
296  /**
297   * Retrieves the set of values that may be used for this task property.
298   *
299   * @return  The set of values that may be used for this task property, or
300   *          {@code null} if there is not a predefined set of allowed values.
301   */
302  public Object[] getAllowedValues()
303  {
304    return allowedValues;
305  }
306
307
308
309  /**
310   * Retrieves a string representation of this task property.
311   *
312   * @return  A string representation of this task property.
313   */
314  @Override()
315  public String toString()
316  {
317    final StringBuilder buffer = new StringBuilder();
318    toString(buffer);
319    return buffer.toString();
320  }
321
322
323
324  /**
325   * Appends a string representation of this task property to the provided
326   * buffer.
327   *
328   * @param  buffer  The buffer to which the string representation should be
329   *                 appended.
330   */
331  public void toString(final StringBuilder buffer)
332  {
333    buffer.append("TaskProperty(attrName='");
334    buffer.append(attributeName);
335    buffer.append("', displayName='");
336    buffer.append(displayName);
337    buffer.append("', description='");
338    buffer.append(description);
339    buffer.append("', dataType='");
340    buffer.append(dataType.getName());
341    buffer.append("', required=");
342    buffer.append(required);
343    buffer.append("', multiValued=");
344    buffer.append(multiValued);
345    buffer.append("', advanced=");
346    buffer.append(advanced);
347
348    if (allowedValues != null)
349    {
350      buffer.append(", allowedValues={");
351      for (int i=0; i < allowedValues.length; i++)
352      {
353        if (i > 0)
354        {
355          buffer.append(", ");
356        }
357
358        buffer.append('\'');
359        buffer.append(allowedValues[i]);
360        buffer.append('\'');
361      }
362      buffer.append('}');
363    }
364
365    buffer.append(')');
366  }
367}