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.util.Arrays; 041import java.util.Collections; 042import java.util.Date; 043import java.util.LinkedHashMap; 044import java.util.List; 045import java.util.Map; 046 047import com.unboundid.ldap.sdk.Attribute; 048import com.unboundid.ldap.sdk.Entry; 049import com.unboundid.util.NotMutable; 050import com.unboundid.util.NotNull; 051import com.unboundid.util.Nullable; 052import com.unboundid.util.StaticUtils; 053import com.unboundid.util.ThreadSafety; 054import com.unboundid.util.ThreadSafetyLevel; 055import com.unboundid.util.Validator; 056 057import static com.unboundid.ldap.sdk.unboundidds.tasks.TaskMessages.*; 058 059 060 061/** 062 * This class defines a Directory Server task that can be used to add the 063 * contents of one or more files to the server schema. 064 * <BR> 065 * <BLOCKQUOTE> 066 * <B>NOTE:</B> This class, and other classes within the 067 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 068 * supported for use against Ping Identity, UnboundID, and 069 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 070 * for proprietary functionality or for external specifications that are not 071 * considered stable or mature enough to be guaranteed to work in an 072 * interoperable way with other types of LDAP servers. 073 * </BLOCKQUOTE> 074 * <BR> 075 * The properties that are available for use with this type of task include: 076 * <UL> 077 * <LI>The names of the files to add to the server schema. The specified 078 * files must exist within the server's schema configuration directory 079 * with the appropriate schema elements defined. They should be only the 080 * base names for the file and should not include any path 081 * information. At least one name must be provided.</LI> 082 * </UL> 083 */ 084@NotMutable() 085@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 086public final class AddSchemaFileTask 087 extends Task 088{ 089 /** 090 * The fully-qualified name of the Java class that is used for the add schema 091 * file task. 092 */ 093 @NotNull static final String ADD_SCHEMA_FILE_TASK_CLASS = 094 "com.unboundid.directory.server.tasks.AddSchemaFileTask"; 095 096 097 098 /** 099 * The name of the attribute used to specify the name(s) of the schema file(s) 100 * to add. 101 */ 102 @NotNull private static final String ATTR_SCHEMA_FILE = 103 "ds-task-schema-file-name"; 104 105 106 107 /** 108 * The name of the object class used in add schema file task entries. 109 */ 110 @NotNull private static final String OC_ADD_SCHEMA_FILE_TASK = 111 "ds-task-add-schema-file"; 112 113 114 115 /** 116 * The task property that will be used for the schema file names. 117 */ 118 @NotNull private static final TaskProperty PROPERTY_SCHEMA_FILE = 119 new TaskProperty(ATTR_SCHEMA_FILE, INFO_DISPLAY_NAME_SCHEMA_FILE.get(), 120 INFO_DESCRIPTION_SCHEMA_FILE.get(), String.class, true, 121 true, false); 122 123 124 125 /** 126 * The serial version UID for this serializable class. 127 */ 128 private static final long serialVersionUID = -5430392768265418966L; 129 130 131 132 // The names of the schema files to be added. 133 @NotNull private final List<String> schemaFileNames; 134 135 136 137 /** 138 * Creates a new uninitialized add schema file task instance which should only 139 * be used for obtaining general information about this task, including the 140 * task name, description, and supported properties. Attempts to use a task 141 * created with this constructor for any other reason will likely fail. 142 */ 143 public AddSchemaFileTask() 144 { 145 schemaFileNames = null; 146 } 147 148 149 150 /** 151 * Creates a new add schema file task to add the specified file to the server 152 * schema. 153 * 154 * @param taskID The task ID to use for this task. If it is 155 * {@code null} then a UUID will be generated for use 156 * as the task ID. 157 * @param schemaFileName The name (without path information) of the file to 158 * add to the server schema. It must not be 159 * {@code null}. 160 */ 161 public AddSchemaFileTask(@Nullable final String taskID, 162 @NotNull final String schemaFileName) 163 { 164 this(taskID, Collections.singletonList(schemaFileName), null, null, null, 165 null, null); 166 167 Validator.ensureNotNull(schemaFileName); 168 } 169 170 171 172 /** 173 * Creates a new add schema file task to add the specified files to the server 174 * schema. 175 * 176 * @param taskID The task ID to use for this task. If it is 177 * {@code null} then a UUID will be generated for use 178 * as the task ID. 179 * @param schemaFileNames The list of names (without path information) of 180 * the files to add to the server schema. It must 181 * not be {@code null} or empty. 182 */ 183 public AddSchemaFileTask(@Nullable final String taskID, 184 @NotNull final List<String> schemaFileNames) 185 { 186 this(taskID, schemaFileNames, null, null, null, null, null); 187 } 188 189 190 191 /** 192 * Creates a new add schema file task to add the specified files to the server 193 * schema. 194 * 195 * @param taskID The task ID to use for this task. If it is 196 * {@code null} then a UUID will be generated 197 * for use as the task ID. 198 * @param schemaFileNames The list of names (without path 199 * information) of the files to add to the 200 * server schema. It must not be {@code null} 201 * or empty. 202 * @param scheduledStartTime The time that this task should start 203 * running. 204 * @param dependencyIDs The list of task IDs that will be required 205 * to complete before this task will be 206 * eligible to start. 207 * @param failedDependencyAction Indicates what action should be taken if 208 * any of the dependencies for this task do 209 * not complete successfully. 210 * @param notifyOnCompletion The list of e-mail addresses of individuals 211 * that should be notified when this task 212 * completes. 213 * @param notifyOnError The list of e-mail addresses of individuals 214 * that should be notified if this task does 215 * not complete successfully. 216 */ 217 public AddSchemaFileTask(@Nullable final String taskID, 218 @NotNull final List<String> schemaFileNames, 219 @Nullable final Date scheduledStartTime, 220 @Nullable final List<String> dependencyIDs, 221 @Nullable final FailedDependencyAction failedDependencyAction, 222 @Nullable final List<String> notifyOnCompletion, 223 @Nullable final List<String> notifyOnError) 224 { 225 this(taskID, schemaFileNames, scheduledStartTime, dependencyIDs, 226 failedDependencyAction, null, notifyOnCompletion, null, 227 notifyOnError, null, null, null); 228 } 229 230 231 232 /** 233 * Creates a new add schema file task to add the specified files to the server 234 * schema. 235 * 236 * @param taskID The task ID to use for this task. If it is 237 * {@code null} then a UUID will be generated 238 * for use as the task ID. 239 * @param schemaFileNames The list of names (without path 240 * information) of the files to add to the 241 * server schema. It must not be {@code null} 242 * or empty. 243 * @param scheduledStartTime The time that this task should start 244 * running. 245 * @param dependencyIDs The list of task IDs that will be required 246 * to complete before this task will be 247 * eligible to start. 248 * @param failedDependencyAction Indicates what action should be taken if 249 * any of the dependencies for this task do 250 * not complete successfully. 251 * @param notifyOnStart The list of e-mail addresses of individuals 252 * that should be notified when this task 253 * starts running. 254 * @param notifyOnCompletion The list of e-mail addresses of individuals 255 * that should be notified when this task 256 * completes. 257 * @param notifyOnSuccess The list of e-mail addresses of individuals 258 * that should be notified if this task 259 * completes successfully. 260 * @param notifyOnError The list of e-mail addresses of individuals 261 * that should be notified if this task does 262 * not complete successfully. 263 * @param alertOnStart Indicates whether the server should send an 264 * alert notification when this task starts. 265 * @param alertOnSuccess Indicates whether the server should send an 266 * alert notification if this task completes 267 * successfully. 268 * @param alertOnError Indicates whether the server should send an 269 * alert notification if this task fails to 270 * complete successfully. 271 */ 272 public AddSchemaFileTask(@Nullable final String taskID, 273 @NotNull final List<String> schemaFileNames, 274 @Nullable final Date scheduledStartTime, 275 @Nullable final List<String> dependencyIDs, 276 @Nullable final FailedDependencyAction failedDependencyAction, 277 @Nullable final List<String> notifyOnStart, 278 @Nullable final List<String> notifyOnCompletion, 279 @Nullable final List<String> notifyOnSuccess, 280 @Nullable final List<String> notifyOnError, 281 @Nullable final Boolean alertOnStart, 282 @Nullable final Boolean alertOnSuccess, 283 @Nullable final Boolean alertOnError) 284 { 285 super(taskID, ADD_SCHEMA_FILE_TASK_CLASS, scheduledStartTime, 286 dependencyIDs, failedDependencyAction, notifyOnStart, 287 notifyOnCompletion, notifyOnSuccess, notifyOnError, alertOnStart, 288 alertOnSuccess, alertOnError); 289 290 Validator.ensureNotNull(schemaFileNames); 291 Validator.ensureFalse(schemaFileNames.isEmpty(), 292 "AddSchemaFileTask.schemaFileNames must not be empty."); 293 294 this.schemaFileNames = Collections.unmodifiableList(schemaFileNames); 295 } 296 297 298 299 /** 300 * Creates a new add schema file task from the provided entry. 301 * 302 * @param entry The entry to use to create this add schema file task. 303 * 304 * @throws TaskException If the provided entry cannot be parsed as a 305 * add schema file task entry. 306 */ 307 public AddSchemaFileTask(@NotNull final Entry entry) 308 throws TaskException 309 { 310 super(entry); 311 312 // Get the set of schema file names. It must be present. 313 final String[] fileNames = entry.getAttributeValues(ATTR_SCHEMA_FILE); 314 if ((fileNames == null) || (fileNames.length == 0)) 315 { 316 throw new TaskException(ERR_ADD_SCHEMA_FILE_TASK_NO_FILES.get( 317 getTaskEntryDN())); 318 } 319 320 schemaFileNames = Collections.unmodifiableList(Arrays.asList(fileNames)); 321 } 322 323 324 325 /** 326 * Creates a new add schema file task from the provided set of task 327 * properties. 328 * 329 * @param properties The set of task properties and their corresponding 330 * values to use for the task. It must not be 331 * {@code null}. 332 * 333 * @throws TaskException If the provided set of properties cannot be used to 334 * create a valid add schema file task. 335 */ 336 public AddSchemaFileTask( 337 @NotNull final Map<TaskProperty,List<Object>> properties) 338 throws TaskException 339 { 340 super(ADD_SCHEMA_FILE_TASK_CLASS, properties); 341 342 String[] names = null; 343 for (final Map.Entry<TaskProperty,List<Object>> entry : 344 properties.entrySet()) 345 { 346 final TaskProperty p = entry.getKey(); 347 final String attrName = p.getAttributeName(); 348 final List<Object> values = entry.getValue(); 349 350 if (attrName.equalsIgnoreCase(ATTR_SCHEMA_FILE)) 351 { 352 names = parseStrings(p, values, names); 353 } 354 } 355 356 if (names == null) 357 { 358 throw new TaskException(ERR_ADD_SCHEMA_FILE_TASK_NO_FILES.get( 359 getTaskEntryDN())); 360 } 361 362 schemaFileNames = Collections.unmodifiableList(Arrays.asList(names)); 363 } 364 365 366 367 /** 368 * {@inheritDoc} 369 */ 370 @Override() 371 @NotNull() 372 public String getTaskName() 373 { 374 return INFO_TASK_NAME_ADD_SCHEMA_FILE.get(); 375 } 376 377 378 379 /** 380 * {@inheritDoc} 381 */ 382 @Override() 383 @NotNull() 384 public String getTaskDescription() 385 { 386 return INFO_TASK_DESCRIPTION_ADD_SCHEMA_FILE.get(); 387 } 388 389 390 391 /** 392 * Retrieves the names (without path information) of the schema files to be 393 * added to the server. 394 * 395 * @return The names of the schema files to be added to the server. 396 */ 397 @NotNull() 398 public List<String> getSchemaFileNames() 399 { 400 return schemaFileNames; 401 } 402 403 404 405 /** 406 * {@inheritDoc} 407 */ 408 @Override() 409 @NotNull() 410 protected List<String> getAdditionalObjectClasses() 411 { 412 return Collections.singletonList(OC_ADD_SCHEMA_FILE_TASK); 413 } 414 415 416 417 /** 418 * {@inheritDoc} 419 */ 420 @Override() 421 @NotNull() 422 protected List<Attribute> getAdditionalAttributes() 423 { 424 return Collections.singletonList( 425 new Attribute(ATTR_SCHEMA_FILE, schemaFileNames)); 426 } 427 428 429 430 /** 431 * {@inheritDoc} 432 */ 433 @Override() 434 @NotNull() 435 public List<TaskProperty> getTaskSpecificProperties() 436 { 437 return Collections.singletonList(PROPERTY_SCHEMA_FILE); 438 } 439 440 441 442 /** 443 * {@inheritDoc} 444 */ 445 @Override() 446 @NotNull() 447 public Map<TaskProperty,List<Object>> getTaskPropertyValues() 448 { 449 final LinkedHashMap<TaskProperty,List<Object>> props = 450 new LinkedHashMap<>(StaticUtils.computeMapCapacity(10)); 451 452 props.put(PROPERTY_SCHEMA_FILE, 453 Collections.<Object>unmodifiableList(schemaFileNames)); 454 455 props.putAll(super.getTaskPropertyValues()); 456 return Collections.unmodifiableMap(props); 457 } 458}