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