001 /*
002 * Copyright 2008-2015 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2015 UnboundID Corp.
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 */
021 package com.unboundid.ldap.sdk.unboundidds.tasks;
022
023
024
025 import java.util.Arrays;
026 import java.util.Collections;
027 import java.util.Date;
028 import java.util.LinkedHashMap;
029 import java.util.List;
030 import java.util.Map;
031
032 import com.unboundid.ldap.sdk.Attribute;
033 import com.unboundid.ldap.sdk.Entry;
034 import com.unboundid.util.NotMutable;
035 import com.unboundid.util.ThreadSafety;
036 import com.unboundid.util.ThreadSafetyLevel;
037
038 import static com.unboundid.ldap.sdk.unboundidds.tasks.TaskMessages.*;
039 import static com.unboundid.util.Validator.*;
040
041
042
043 /**
044 * <BLOCKQUOTE>
045 * <B>NOTE:</B> This class is part of the Commercial Edition of the UnboundID
046 * LDAP SDK for Java. It is not available for use in applications that
047 * include only the Standard Edition of the LDAP SDK, and is not supported for
048 * use in conjunction with non-UnboundID products.
049 * </BLOCKQUOTE>
050 * This class defines a Directory Server task that can be used to add the
051 * contents of one or more files to the server schema. The properties that are
052 * available for use with this type of task include:
053 * <UL>
054 * <LI>The names of the files to add to the server schema. The specified
055 * files must exist within the server's schema configuration directory
056 * with the appropriate schema elements defined. They should be only the
057 * base names for the file and should not include any path
058 * information. At least one name must be provided.</LI>
059 * </UL>
060 */
061 @NotMutable()
062 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
063 public final class AddSchemaFileTask
064 extends Task
065 {
066 /**
067 * The fully-qualified name of the Java class that is used for the add schema
068 * file task.
069 */
070 static final String ADD_SCHEMA_FILE_TASK_CLASS =
071 "com.unboundid.directory.server.tasks.AddSchemaFileTask";
072
073
074
075 /**
076 * The name of the attribute used to specify the name(s) of the schema file(s)
077 * to add.
078 */
079 private static final String ATTR_SCHEMA_FILE =
080 "ds-task-schema-file-name";
081
082
083
084 /**
085 * The name of the object class used in add schema file task entries.
086 */
087 private static final String OC_ADD_SCHEMA_FILE_TASK =
088 "ds-task-add-schema-file";
089
090
091
092 /**
093 * The task property that will be used for the schema file names.
094 */
095 private static final TaskProperty PROPERTY_SCHEMA_FILE =
096 new TaskProperty(ATTR_SCHEMA_FILE, INFO_DISPLAY_NAME_SCHEMA_FILE.get(),
097 INFO_DESCRIPTION_SCHEMA_FILE.get(), String.class, true,
098 true, false);
099
100
101
102
103 /**
104 * The serial version UID for this serializable class.
105 */
106 private static final long serialVersionUID = -5430392768265418966L;
107
108
109
110 // The names of the schema files to be added.
111 private final List<String> schemaFileNames;
112
113
114
115 /**
116 * Creates a new uninitialized add schema file task instance which should only
117 * be used for obtaining general information about this task, including the
118 * task name, description, and supported properties. Attempts to use a task
119 * created with this constructor for any other reason will likely fail.
120 */
121 public AddSchemaFileTask()
122 {
123 schemaFileNames = null;
124 }
125
126
127
128
129 /**
130 * Creates a new add schema file task to add the specified file to the server
131 * schema.
132 *
133 * @param taskID The task ID to use for this task. If it is
134 * {@code null} then a UUID will be generated for use
135 * as the task ID.
136 * @param schemaFileName The name (without path information) of the file to
137 * add to the server schema. It must not be
138 * {@code null}.
139 */
140 public AddSchemaFileTask(final String taskID, final String schemaFileName)
141 {
142 this(taskID, Arrays.asList(schemaFileName), null, null, null, null, null);
143
144 ensureNotNull(schemaFileName);
145 }
146
147
148
149
150 /**
151 * Creates a new add schema file task to add the specified files 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 schemaFileNames The list of names (without path information) of
158 * the files to add to the server schema. It must
159 * not be {@code null} or empty.
160 */
161 public AddSchemaFileTask(final String taskID,
162 final List<String> schemaFileNames)
163 {
164 this(taskID, schemaFileNames, null, null, null, null, null);
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
175 * for use as the task ID.
176 * @param schemaFileNames The list of names (without path
177 * information) of the files to add to the
178 * server schema. It must not be {@code null}
179 * or empty.
180 * @param scheduledStartTime The time that this task should start
181 * running.
182 * @param dependencyIDs The list of task IDs that will be required
183 * to complete before this task will be
184 * eligible to start.
185 * @param failedDependencyAction Indicates what action should be taken if
186 * any of the dependencies for this task do
187 * not complete successfully.
188 * @param notifyOnCompletion The list of e-mail addresses of individuals
189 * that should be notified when this task
190 * completes.
191 * @param notifyOnError The list of e-mail addresses of individuals
192 * that should be notified if this task does
193 * not complete successfully.
194 */
195 public AddSchemaFileTask(final String taskID,
196 final List<String> schemaFileNames,
197 final Date scheduledStartTime,
198 final List<String> dependencyIDs,
199 final FailedDependencyAction failedDependencyAction,
200 final List<String> notifyOnCompletion,
201 final List<String> notifyOnError)
202 {
203 super(taskID, ADD_SCHEMA_FILE_TASK_CLASS, scheduledStartTime,
204 dependencyIDs, failedDependencyAction, notifyOnCompletion,
205 notifyOnError);
206
207 ensureNotNull(schemaFileNames);
208 ensureFalse(schemaFileNames.isEmpty(),
209 "AddSchemaFileTask.schemaFileNames must not be empty.");
210
211 this.schemaFileNames = Collections.unmodifiableList(schemaFileNames);
212 }
213
214
215
216 /**
217 * Creates a new add schema file task from the provided entry.
218 *
219 * @param entry The entry to use to create this add schema file task.
220 *
221 * @throws TaskException If the provided entry cannot be parsed as a
222 * add schema file task entry.
223 */
224 public AddSchemaFileTask(final Entry entry)
225 throws TaskException
226 {
227 super(entry);
228
229 // Get the set of schema file names. It must be present.
230 final String[] fileNames = entry.getAttributeValues(ATTR_SCHEMA_FILE);
231 if ((fileNames == null) || (fileNames.length == 0))
232 {
233 throw new TaskException(ERR_ADD_SCHEMA_FILE_TASK_NO_FILES.get(
234 getTaskEntryDN()));
235 }
236
237 schemaFileNames = Collections.unmodifiableList(Arrays.asList(fileNames));
238 }
239
240
241
242 /**
243 * Creates a new add schema file task from the provided set of task
244 * properties.
245 *
246 * @param properties The set of task properties and their corresponding
247 * values to use for the task. It must not be
248 * {@code null}.
249 *
250 * @throws TaskException If the provided set of properties cannot be used to
251 * create a valid add schema file task.
252 */
253 public AddSchemaFileTask(final Map<TaskProperty,List<Object>> properties)
254 throws TaskException
255 {
256 super(ADD_SCHEMA_FILE_TASK_CLASS, properties);
257
258 String[] names = null;
259 for (final Map.Entry<TaskProperty,List<Object>> entry :
260 properties.entrySet())
261 {
262 final TaskProperty p = entry.getKey();
263 final String attrName = p.getAttributeName();
264 final List<Object> values = entry.getValue();
265
266 if (attrName.equalsIgnoreCase(ATTR_SCHEMA_FILE))
267 {
268 names = parseStrings(p, values, names);
269 }
270 }
271
272 if (names == null)
273 {
274 throw new TaskException(ERR_ADD_SCHEMA_FILE_TASK_NO_FILES.get(
275 getTaskEntryDN()));
276 }
277
278 schemaFileNames = Collections.unmodifiableList(Arrays.asList(names));
279 }
280
281
282
283 /**
284 * {@inheritDoc}
285 */
286 @Override()
287 public String getTaskName()
288 {
289 return INFO_TASK_NAME_ADD_SCHEMA_FILE.get();
290 }
291
292
293
294 /**
295 * {@inheritDoc}
296 */
297 @Override()
298 public String getTaskDescription()
299 {
300 return INFO_TASK_DESCRIPTION_ADD_SCHEMA_FILE.get();
301 }
302
303
304
305 /**
306 * Retrieves the names (without path information) of the schema files to be
307 * added to the server.
308 *
309 * @return The names of the schema files to be added to the server.
310 */
311 public List<String> getSchemaFileNames()
312 {
313 return schemaFileNames;
314 }
315
316
317
318 /**
319 * {@inheritDoc}
320 */
321 @Override()
322 protected List<String> getAdditionalObjectClasses()
323 {
324 return Arrays.asList(OC_ADD_SCHEMA_FILE_TASK);
325 }
326
327
328
329 /**
330 * {@inheritDoc}
331 */
332 @Override()
333 protected List<Attribute> getAdditionalAttributes()
334 {
335 return Arrays.asList(new Attribute(ATTR_SCHEMA_FILE, schemaFileNames));
336 }
337
338
339
340 /**
341 * {@inheritDoc}
342 */
343 @Override()
344 public List<TaskProperty> getTaskSpecificProperties()
345 {
346 return Collections.unmodifiableList(Arrays.asList(PROPERTY_SCHEMA_FILE));
347 }
348
349
350
351 /**
352 * {@inheritDoc}
353 */
354 @Override()
355 public Map<TaskProperty,List<Object>> getTaskPropertyValues()
356 {
357 final LinkedHashMap<TaskProperty,List<Object>> props =
358 new LinkedHashMap<TaskProperty,List<Object>>();
359
360 props.put(PROPERTY_SCHEMA_FILE,
361 Collections.<Object>unmodifiableList(schemaFileNames));
362
363 props.putAll(super.getTaskPropertyValues());
364 return Collections.unmodifiableMap(props);
365 }
366 }