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