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; 031import com.unboundid.util.Validator; 032 033 034 035/** 036 * This class provides information about a property that may be used to schedule 037 * a task. 038 * <BR> 039 * <BLOCKQUOTE> 040 * <B>NOTE:</B> This class, and other classes within the 041 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 042 * supported for use against Ping Identity, UnboundID, and 043 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 044 * for proprietary functionality or for external specifications that are not 045 * considered stable or mature enough to be guaranteed to work in an 046 * interoperable way with other types of LDAP servers. 047 * </BLOCKQUOTE> 048 * <BR> 049 * Elements of a task property include: 050 * <UL> 051 * <LI>The name of the LDAP attribute used to store values for this 052 * property.</LI> 053 * <LI>A user-friendly display name for the property.</LI> 054 * <LI>A user-friendly description for the property.</LI> 055 * <LI>The expected data type for values of the property.</LI> 056 * <LI>An optional set of allowed values for the property. If this is 057 * defined, then the property will not be allowed to have any value that 058 * is not included in this set.</LI> 059 * <LI>A flag that indicates whether the property is required when scheduling 060 * the corresponding type of task.</LI> 061 * <LI>A flag that indicates whether the property is allowed to have multiple 062 * values.</LI> 063 * <LI>A flag that indicates whether the property should be considered 064 * advanced and therefore may be hidden from users if a simplified 065 * interface is to be presented.</LI> 066 * </UL> 067 */ 068@NotMutable() 069@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 070public final class TaskProperty 071 implements Serializable 072{ 073 /** 074 * The serial version UID for this serializable class. 075 */ 076 private static final long serialVersionUID = 8438462010090371903L; 077 078 079 080 // Indicates whether this task property is advanced. 081 private final boolean advanced; 082 083 // Indicates whether this task property is multivalued. 084 private final boolean multiValued; 085 086 // Indicates whether this task property is required. 087 private final boolean required; 088 089 // The data type for this task property. 090 private final Class<?> dataType; 091 092 // The set of allowed values for this task property. 093 private final Object[] allowedValues; 094 095 // The name of the LDAP attribute associated with this task property. 096 private final String attributeName; 097 098 // The human-readable description for this task property. 099 private final String description; 100 101 // The human-readable display name for this task property. 102 private final String displayName; 103 104 105 106 /** 107 * Creates a new task property with the provided information. 108 * 109 * @param attributeName The name of the LDAP attribute associated with this 110 * task property. It must not be {@code null}. 111 * @param displayName The human-readable display name for this task 112 * property. It must not be {@code null}. 113 * @param description The human-readable description for this task 114 * property. It must not be {@code null}. 115 * @param dataType A class representing the data type for this 116 * property. Allowed data type classes include: 117 * {@code Boolean}, {@code Date}, {@code Long}, and 118 * {@code String}. It must not be {@code null}. 119 * @param required Indicates whether this property must be provided 120 * when scheduling a task. 121 * @param multiValued Indicates whether this property is allowed to have 122 * multiple values. 123 * @param advanced Indicates whether this property may be considered 124 * advanced and doesn't necessarily need to be 125 * presented to the user. Advanced properties must not 126 * be required. 127 */ 128 public TaskProperty(final String attributeName, final String displayName, 129 final String description, final Class<?> dataType, 130 final boolean required, final boolean multiValued, 131 final boolean advanced) 132 { 133 this(attributeName, displayName, description, dataType, required, 134 multiValued, advanced, null); 135 } 136 137 138 139 /** 140 * Creates a new task property with the provided information. 141 * 142 * @param attributeName The name of the LDAP attribute associated with this 143 * task property. It must not be {@code null}. 144 * @param displayName The human-readable display name for this task 145 * property. It must not be {@code null}. 146 * @param description The human-readable description for this task 147 * property. It must not be {@code null}. 148 * @param dataType A class representing the data type for this 149 * property. Allowed data type classes include: 150 * {@code Boolean}, {@code Date}, {@code Long}, and 151 * {@code String}. It must not be {@code null}. 152 * @param required Indicates whether this property must be provided 153 * when scheduling a task. 154 * @param multiValued Indicates whether this property is allowed to have 155 * multiple values. 156 * @param advanced Indicates whether this property may be considered 157 * advanced and doesn't necessarily need to be 158 * presented to the user. Advanced properties must not 159 * be required. 160 * @param allowedValues The set of allowed values for this task property. 161 * It may be {@code null} if there is not a predefined 162 * set of acceptable values. If it is provided, then 163 * all values must be objects of the class specified as 164 * the data type. 165 */ 166 public TaskProperty(final String attributeName, final String displayName, 167 final String description, final Class<?> dataType, 168 final boolean required, final boolean multiValued, 169 final boolean advanced, final Object[] allowedValues) 170 { 171 Validator.ensureNotNull(attributeName, displayName, description, dataType); 172 Validator.ensureTrue( 173 dataType.equals(Boolean.class) || dataType.equals(Date.class) || 174 dataType.equals(Long.class) || dataType.equals(String.class)); 175 Validator.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 Validator.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}