001/*
002 * Copyright 2008-2023 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2008-2023 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-2023 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.ArrayList;
041import java.util.Arrays;
042import java.util.Collections;
043import java.util.Date;
044import java.util.LinkedHashMap;
045import java.util.List;
046import java.util.Map;
047
048import com.unboundid.ldap.sdk.Attribute;
049import com.unboundid.ldap.sdk.Entry;
050import com.unboundid.util.Debug;
051import com.unboundid.util.NotMutable;
052import com.unboundid.util.NotNull;
053import com.unboundid.util.Nullable;
054import com.unboundid.util.StaticUtils;
055import com.unboundid.util.ThreadSafety;
056import com.unboundid.util.ThreadSafetyLevel;
057import com.unboundid.util.Validator;
058
059import static com.unboundid.ldap.sdk.unboundidds.tasks.TaskMessages.*;
060
061
062
063/**
064 * This class defines a Directory Server task that can be used to export the
065 * contents of a backend to LDIF.
066 * <BR>
067 * <BLOCKQUOTE>
068 *   <B>NOTE:</B>  This class, and other classes within the
069 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
070 *   supported for use against Ping Identity, UnboundID, and
071 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
072 *   for proprietary functionality or for external specifications that are not
073 *   considered stable or mature enough to be guaranteed to work in an
074 *   interoperable way with other types of LDAP servers.
075 * </BLOCKQUOTE>
076 * <BR>
077 * The properties that are available for use with this type of task include:
078 * <UL>
079 *   <LI>The backend ID for the backend from which the data is to be exported.
080 *       It must be provided when scheduling a task of this type.</LI>
081 *   <LI>The path (on the server system) and name of the LDIF file to be
082 *       written.  It must be provided when scheduling a task of this type.</LI>
083 *   <LI>A flag that indicates whether to append to any existing file or to
084 *       overwrite it.</LI>
085 *   <LI>An optional list of base DNs for branches that should be included in
086 *       the export.</LI>
087 *   <LI>An optional list of base DNs for branches that should be excluded from
088 *       the export.</LI>
089 *   <LI>An optional list of filters that may be used to determine whether an
090 *       entry should be included in the export.</LI>
091 *   <LI>An optional list of filters that may be used to determine whether an
092 *       entry should be excluded from the export.</LI>
093 *   <LI>An optional list of attributes that should be included in entries that
094 *       are exported.</LI>
095 *   <LI>An optional list of attributes that should be excluded form entries
096 *       that are exported.</LI>
097 *   <LI>An integer value that specifies the column at which long lines should
098 *       be wrapped.  A value less than or equal to zero indicates that no
099 *       wrapping should be performed.</LI>
100 *   <LI>A flag that indicates whether to compress the LDIF data as it is
101 *       written.</LI>
102 *   <LI>A flag that indicates whether to encrypt the LDIF data as it is
103 *       written.</LI>
104 *   <LI>A flag that indicates whether to generate a signature for the LDIF data
105 *       as it is written.</LI>
106 *   <LI>The path to a file containing a passphrase to use to generate the
107 *       encryption key.</LI>
108 *   <LI>The ID of the encryption settings definition to use to generate the
109 *       encryption key.</LI>
110 *   <LI>The maximum rate in megabytes per second at which the LDIF file should
111 *       be written.</LI>
112 * </UL>
113 */
114@NotMutable()
115@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
116public final class ExportTask
117       extends Task
118{
119  /**
120   * The fully-qualified name of the Java class that is used for the export
121   * task.
122   */
123  @NotNull static final String EXPORT_TASK_CLASS =
124       "com.unboundid.directory.server.tasks.ExportTask";
125
126
127
128  /**
129   * The name of the attribute used to indicate whether to append to an existing
130   * file.
131   */
132  @NotNull private static final String ATTR_APPEND_TO_LDIF =
133       "ds-task-export-append-to-ldif";
134
135
136
137  /**
138   * The name of the attribute used to specify the backend ID of the backend to
139   * export.
140   */
141  @NotNull private static final String ATTR_BACKEND_ID =
142       "ds-task-export-backend-id";
143
144
145
146  /**
147   * The name of the attribute used to indicate whether the exported LDIF should
148   * be compressed as it is written.
149   */
150  @NotNull private static final String ATTR_COMPRESS =
151       "ds-task-export-compress-ldif";
152
153
154
155  /**
156   * The name of the attribute used to indicate whether the exported LDIF should
157   * be encrypted as it is written.
158   */
159  @NotNull private static final String ATTR_ENCRYPT =
160       "ds-task-export-encrypt-ldif";
161
162
163
164  /**
165   * The name of the attribute used to specify the path to a file that contains
166   * the passphrase to use to generate the encryption key.
167   */
168  @NotNull private static final String ATTR_ENCRYPTION_PASSPHRASE_FILE =
169       "ds-task-export-encryption-passphrase-file";
170
171
172
173  /**
174   * The name of the attribute used to specify the path to a file that contains
175   * the ID of the encryption settings definition to use to generate the
176   * encryption key.
177   */
178  @NotNull private static final String ATTR_ENCRYPTION_SETTINGS_DEFINITION_ID =
179       "ds-task-export-encryption-settings-definition-id";
180
181
182
183  /**
184   * The name of the attribute used to specify the attributes to exclude from
185   * the export.
186   */
187  @NotNull private static final String ATTR_EXCLUDE_ATTRIBUTE =
188       "ds-task-export-exclude-attribute";
189
190
191
192  /**
193   * The name of the attribute used to specify the base DNs to exclude from the
194   * export.
195   */
196  @NotNull private static final String ATTR_EXCLUDE_BRANCH =
197       "ds-task-export-exclude-branch";
198
199
200
201  /**
202   * The name of the attribute used to specify the filters to use to identify
203   * entries to exclude from the export.
204   */
205  @NotNull private static final String ATTR_EXCLUDE_FILTER =
206       "ds-task-export-exclude-filter";
207
208
209
210  /**
211   * The name of the attribute used to specify the attributes to include in the
212   * export.
213   */
214  @NotNull private static final String ATTR_INCLUDE_ATTRIBUTE =
215       "ds-task-export-include-attribute";
216
217
218
219  /**
220   * The name of the attribute used to specify the base DNs to include in the
221   * export.
222   */
223  @NotNull private static final String ATTR_INCLUDE_BRANCH =
224       "ds-task-export-include-branch";
225
226
227
228  /**
229   * The name of the attribute used to specify the filters to use to identify
230   * entries to include in the export.
231   */
232  @NotNull private static final String ATTR_INCLUDE_FILTER =
233       "ds-task-export-include-filter";
234
235
236
237  /**
238   * The name of the attribute used to specify the path to the LDIF file to be
239   * written.
240   */
241  @NotNull private static final String ATTR_LDIF_FILE =
242       "ds-task-export-ldif-file";
243
244
245
246  /**
247   * The name of the attribute used to specify the maximum LDIF write rate in
248   * megabytes per second.
249   */
250  @NotNull private static final String ATTR_MAX_MEGABYTES_PER_SECOND =
251       "ds-task-export-max-megabytes-per-second";
252
253
254
255  /**
256   * The name of the attribute used to indicate whether the exported LDIF should
257   * include a signed hash of the contents.
258   */
259  @NotNull private static final String ATTR_SIGN = "ds-task-export-sign-hash";
260
261
262
263  /**
264   * The name of the attribute used to specify the column at which to wrap long
265   * lines in the export.
266   */
267  @NotNull private static final String ATTR_WRAP_COLUMN =
268       "ds-task-export-wrap-column";
269
270
271
272  /**
273   * The name of the object class used in export task entries.
274   */
275  @NotNull private static final String OC_EXPORT_TASK = "ds-task-export";
276
277
278
279  /**
280   * The task property for the backend ID.
281   */
282  @NotNull private static final TaskProperty PROPERTY_BACKEND_ID =
283       new TaskProperty(ATTR_BACKEND_ID, INFO_DISPLAY_NAME_BACKEND_ID.get(),
284                        INFO_DESCRIPTION_BACKEND_ID_EXPORT.get(), String.class,
285                        true, false, false);
286
287
288
289  /**
290   * The task property for the LDIF file.
291   */
292  @NotNull private static final TaskProperty PROPERTY_LDIF_FILE =
293       new TaskProperty(ATTR_LDIF_FILE, INFO_DISPLAY_NAME_LDIF_FILE.get(),
294                        INFO_DESCRIPTION_LDIF_FILE_EXPORT.get(), String.class,
295                        true, false, false);
296
297
298
299  /**
300   * The task property for the append to LDIF flag.
301   */
302  @NotNull private static final TaskProperty PROPERTY_APPEND_TO_LDIF =
303       new TaskProperty(ATTR_APPEND_TO_LDIF,
304                        INFO_DISPLAY_NAME_APPEND_TO_LDIF.get(),
305                        INFO_DESCRIPTION_APPEND_TO_LDIF.get(), Boolean.class,
306                        false, false, true);
307
308
309
310  /**
311   * The task property for the include branches.
312   */
313  @NotNull private static final TaskProperty PROPERTY_INCLUDE_BRANCH =
314       new TaskProperty(ATTR_INCLUDE_BRANCH,
315                        INFO_DISPLAY_NAME_INCLUDE_BRANCH.get(),
316                        INFO_DESCRIPTION_INCLUDE_BRANCH_EXPORT.get(),
317                        String.class, false, true, true);
318
319
320
321  /**
322   * The task property for the exclude branches.
323   */
324  @NotNull private static final TaskProperty PROPERTY_EXCLUDE_BRANCH =
325       new TaskProperty(ATTR_EXCLUDE_BRANCH,
326                        INFO_DISPLAY_NAME_EXCLUDE_BRANCH.get(),
327                        INFO_DESCRIPTION_EXCLUDE_BRANCH_EXPORT.get(),
328                        String.class, false, true, true);
329
330
331
332  /**
333   * The task property for the include filters.
334   */
335  @NotNull private static final TaskProperty PROPERTY_INCLUDE_FILTER =
336       new TaskProperty(ATTR_INCLUDE_FILTER,
337                        INFO_DISPLAY_NAME_INCLUDE_FILTER.get(),
338                        INFO_DESCRIPTION_INCLUDE_FILTER_EXPORT.get(),
339                        String.class, false, true, true);
340
341
342
343  /**
344   * The task property for the exclude filters.
345   */
346  @NotNull private static final TaskProperty PROPERTY_EXCLUDE_FILTER =
347       new TaskProperty(ATTR_EXCLUDE_FILTER,
348                        INFO_DISPLAY_NAME_EXCLUDE_FILTER.get(),
349                        INFO_DESCRIPTION_EXCLUDE_FILTER_EXPORT.get(),
350                        String.class, false, true, true);
351
352
353
354  /**
355   * The task property for the include attributes.
356   */
357  @NotNull private static final TaskProperty PROPERTY_INCLUDE_ATTRIBUTE =
358       new TaskProperty(ATTR_INCLUDE_ATTRIBUTE,
359                        INFO_DISPLAY_NAME_INCLUDE_ATTRIBUTE.get(),
360                        INFO_DESCRIPTION_INCLUDE_ATTRIBUTE_EXPORT.get(),
361                        String.class, false, true, true);
362
363
364
365  /**
366   * The task property for the exclude attributes.
367   */
368  @NotNull private static final TaskProperty PROPERTY_EXCLUDE_ATTRIBUTE =
369       new TaskProperty(ATTR_EXCLUDE_ATTRIBUTE,
370                        INFO_DISPLAY_NAME_EXCLUDE_ATTRIBUTE.get(),
371                        INFO_DESCRIPTION_EXCLUDE_ATTRIBUTE_EXPORT.get(),
372                        String.class, false, true, true);
373
374
375
376  /**
377   * The task property for the wrap column.
378   */
379  @NotNull private static final TaskProperty PROPERTY_WRAP_COLUMN =
380       new TaskProperty(ATTR_WRAP_COLUMN, INFO_DISPLAY_NAME_WRAP_COLUMN.get(),
381                        INFO_DESCRIPTION_WRAP_COLUMN.get(), Long.class, false,
382                        false, true);
383
384
385
386  /**
387   * The task property for the compress flag.
388   */
389  @NotNull private static final TaskProperty PROPERTY_COMPRESS =
390       new TaskProperty(ATTR_COMPRESS, INFO_DISPLAY_NAME_COMPRESS.get(),
391                        INFO_DESCRIPTION_COMPRESS_EXPORT.get(), Boolean.class,
392                        false, false, false);
393
394
395
396  /**
397   * The task property for the encrypt flag.
398   */
399  @NotNull private static final TaskProperty PROPERTY_ENCRYPT =
400       new TaskProperty(ATTR_ENCRYPT, INFO_DISPLAY_NAME_ENCRYPT.get(),
401                        INFO_DESCRIPTION_ENCRYPT_EXPORT.get(), Boolean.class,
402                        false, false, false);
403
404
405
406  /**
407   * The task property that will be used for the encryption passphrase file.
408   */
409  @NotNull private static final TaskProperty
410       PROPERTY_ENCRYPTION_PASSPHRASE_FILE = new TaskProperty(
411            ATTR_ENCRYPTION_PASSPHRASE_FILE,
412            INFO_DISPLAY_NAME_ENCRYPTION_PASSPHRASE_FILE.get(),
413            INFO_DESCRIPTION_ENCRYPTION_PASSPHRASE_FILE.get(),
414            String.class, false, false, true);
415
416
417
418  /**
419   * The task property that will be used for the encryption settings definition
420   * ID.
421   */
422  @NotNull private static final TaskProperty
423       PROPERTY_ENCRYPTION_SETTINGS_DEFINITION_ID = new TaskProperty(
424            ATTR_ENCRYPTION_SETTINGS_DEFINITION_ID,
425            INFO_DISPLAY_NAME_ENCRYPTION_SETTINGS_DEFINITION_ID.get(),
426            INFO_DESCRIPTION_ENCRYPTION_SETTINGS_DEFINITION_ID.get(),
427            String.class, false, false, true);
428
429
430
431  /**
432   * The task property for the sign flag.
433   */
434  @NotNull private static final TaskProperty PROPERTY_SIGN =
435       new TaskProperty(ATTR_SIGN, INFO_DISPLAY_NAME_SIGN.get(),
436                        INFO_DESCRIPTION_SIGN_EXPORT.get(), Boolean.class,
437                        false, false, false);
438
439
440
441  /**
442   * The task property that will be used for the maximum write rate in megabytes
443   * per second.
444   */
445  @NotNull private static final TaskProperty PROPERTY_MAX_MEGABYTES_PER_SECOND =
446       new TaskProperty(ATTR_MAX_MEGABYTES_PER_SECOND,
447            INFO_DISPLAY_NAME_EXPORT_MAX_MEGABYTES_PER_SECOND.get(),
448            INFO_DESCRIPTION_EXPORT_MAX_MEGABYTES_PER_SECOND.get(),
449            Long.class, false, false, true);
450
451
452
453  /**
454   * The serial version UID for this serializable class.
455   */
456  private static final long serialVersionUID = -6807534587873728959L;
457
458
459
460  // Indicates whether to append the data to an existing file.
461  private final boolean appendToLDIF;
462
463  // Indicates whether to compress the data.
464  private final boolean compress;
465
466  // Indicates whether to encrypt the data.
467  private final boolean encrypt;
468
469  // Indicates whether to sign the data.
470  private final boolean sign;
471
472  // The column at which to wrap long lines.
473  private final int wrapColumn;
474
475  // The maximum write rate in megabytes per second.
476  @Nullable private final Integer maxMegabytesPerSecond;
477
478  // The set of attributes to exclude from the export.
479  @NotNull private final List<String> excludeAttributes;
480
481  // The set of base DNs to exclude from the export.
482  @NotNull private final List<String> excludeBranches;
483
484  // The set of filters to use to identify entries to exclude.
485  @NotNull private final List<String> excludeFilters;
486
487  // The set of attributes to include in the export.
488  @NotNull private final List<String> includeAttributes;
489
490  // The set of base DNs to include in the export.
491  @NotNull private final List<String> includeBranches;
492
493  // The set of filters to use to identify entries to include.
494  @NotNull private final List<String> includeFilters;
495
496  // The backend ID of the backend to export.
497  @NotNull private final String backendID;
498
499  // The path to a file containing the passphrase to use to generate the
500  // encryption key.
501  @Nullable private final String encryptionPassphraseFile;
502
503  // The identifier for the encryption settings definition to use to generate
504  // the encryption key.
505  @Nullable private final String encryptionSettingsDefinitionID;
506
507  // The path to the LDIF file to generate.
508  @NotNull private final String ldifFile;
509
510
511
512  /**
513   * Creates a new uninitialized export task instance which should only be used
514   * for obtaining general information about this task, including the task name,
515   * description, and supported properties.  Attempts to use a task created with
516   * this constructor for any other reason will likely fail.
517   */
518  public ExportTask()
519  {
520    appendToLDIF = false;
521    compress = false;
522    encrypt = false;
523    sign = false;
524    wrapColumn = -1;
525    maxMegabytesPerSecond = null;
526    encryptionPassphraseFile = null;
527    encryptionSettingsDefinitionID = null;
528    excludeAttributes = null;
529    excludeBranches = null;
530    excludeFilters = null;
531    includeAttributes = null;
532    includeBranches = null;
533    includeFilters = null;
534    backendID = null;
535    ldifFile = null;
536  }
537
538
539
540  /**
541   * Creates a new export task with the provided information.
542   *
543   * @param  taskID     The task ID to use for this task.  If it is {@code null}
544   *                    then a UUID will be generated for use as the task ID.
545   * @param  backendID  The backend ID of the backend containing the data to
546   *                    export.  It must not be {@code null}.
547   * @param  ldifFile   The path to the LDIF file to create.  It may be an
548   *                    absolute path or a path relative to the server install
549   *                    root.  It must not be {@code null}.
550   */
551  public ExportTask(@Nullable final String taskID,
552                    @NotNull final String backendID,
553                    @NotNull final String ldifFile)
554  {
555    this(taskID, backendID, ldifFile, false, null, null, null, null, null, null,
556         -1, false, false, false, null, null, null, null, null);
557  }
558
559
560
561  /**
562   * Creates a new export task with the provided information.
563   *
564   * @param  taskID                  The task ID to use for this task.  If it is
565   *                                 {@code null} then a UUID will be generated
566   *                                 for use as the task ID.
567   * @param  backendID               The backend ID of the backend to be
568   *                                 exported.  It must not be {@code null}.
569   * @param  ldifFile                The path to the LDIF file to be written.
570   *                                 It may be an absolute path or one that is
571   *                                 relative to the server root.  It must not
572   *                                 be {@code null}.
573   * @param  appendToLDIF            Indicates whether to an append to any
574   *                                 existing file rather than overwriting it.
575   * @param  includeBranches         The set of base DNs of entries to include
576   *                                 in the export.  It may be {@code null} or
577   *                                 empty if no entries should be excluded
578   *                                 based on their location.
579   * @param  excludeBranches         The set of base DNs of entries to exclude
580   *                                 from the export.  It may be {@code null} or
581   *                                 empty if no entries should be excluded
582   *                                 based on their location.
583   * @param  includeFilters          The set of filters to use to match entries
584   *                                 that should be included in the export.  It
585   *                                 may be {@code null} or empty if no entries
586   *                                 should be excluded based on their content.
587   * @param  excludeFilters          The set of filters to use to match entries
588   *                                 that should be excluded from the export.
589   *                                 It may be {@code null} or empty if no
590   *                                 entries should be excluded based on their
591   *                                 content.
592   * @param  includeAttributes       The set of attributes that should be
593   *                                 included in exported entries.  It may be
594   *                                 {@code null} or empty if all attributes
595   *                                 should be included.
596   * @param  excludeAttributes       The set of attributes that should be
597   *                                 excluded from exported entries.  It may be
598   *                                 {@code null} or empty if no attributes
599   *                                 should be excluded.
600   * @param  wrapColumn              The column at which long lines should be
601   *                                 wrapped.  It may be less than or equal to
602   *                                 zero to indicate that long lines should not
603   *                                 be wrapped.
604   * @param  compress                Indicates whether the LDIF data should be
605   *                                 compressed as it is written.
606   * @param  encrypt                 Indicates whether the LDIF data should be
607   *                                 encrypted as it is written.
608   * @param  sign                    Indicates whether to include a signed hash
609   *                                 of the content in the exported data.
610   * @param  scheduledStartTime      The time that this task should start
611   *                                 running.
612   * @param  dependencyIDs           The list of task IDs that will be required
613   *                                 to complete before this task will be
614   *                                 eligible to start.
615   * @param  failedDependencyAction  Indicates what action should be taken if
616   *                                 any of the dependencies for this task do
617   *                                 not complete successfully.
618   * @param  notifyOnCompletion      The list of e-mail addresses of individuals
619   *                                 that should be notified when this task
620   *                                 completes.
621   * @param  notifyOnError           The list of e-mail addresses of individuals
622   *                                 that should be notified if this task does
623   *                                 not complete successfully.
624   */
625  public ExportTask(@Nullable final String taskID,
626              @NotNull final String backendID,
627              @NotNull final String ldifFile,
628              final boolean appendToLDIF,
629              @Nullable final List<String> includeBranches,
630              @Nullable final List<String> excludeBranches,
631              @Nullable final List<String> includeFilters,
632              @Nullable final List<String> excludeFilters,
633              @Nullable final List<String> includeAttributes,
634              @Nullable final List<String> excludeAttributes,
635              final int wrapColumn,
636              final boolean compress,
637              final boolean encrypt,
638              final boolean sign,
639              @Nullable final Date scheduledStartTime,
640              @Nullable final List<String> dependencyIDs,
641              @Nullable final FailedDependencyAction failedDependencyAction,
642              @Nullable final List<String> notifyOnCompletion,
643              @Nullable final List<String> notifyOnError)
644  {
645    this(taskID, backendID, ldifFile, appendToLDIF, includeBranches,
646         excludeBranches, includeFilters, excludeFilters, includeAttributes,
647         excludeAttributes, wrapColumn, compress, encrypt, null, null, sign,
648         null, scheduledStartTime, dependencyIDs, failedDependencyAction,
649         notifyOnCompletion, notifyOnError);
650  }
651
652
653
654  /**
655   * Creates a new export task with the provided information.
656   *
657   * @param  taskID                          The task ID to use for this task.
658   *                                         If it is {@code null} then a UUID
659   *                                         will be generated for use as the
660   *                                         task ID.
661   * @param  backendID                       The backend ID of the backend to be
662   *                                         exported.  It must not be
663   *                                         {@code null}.
664   * @param  ldifFile                        The path to the LDIF file to be
665   *                                         written.  It may be an absolute
666   *                                         path or one that is relative to the
667   *                                         server root.  It must not be
668   *                                         {@code null}.
669   * @param  appendToLDIF                    Indicates whether to an append to
670   *                                         any existing file rather than
671   *                                         overwriting it.
672   * @param  includeBranches                 The set of base DNs of entries to
673   *                                         include in the export.  It may be
674   *                                         {@code null} or empty if no entries
675   *                                         should be excluded based on their
676   *                                         location.
677   * @param  excludeBranches                 The set of base DNs of entries to
678   *                                         exclude from the export.  It may be
679   *                                         {@code null} or empty if no entries
680   *                                         should be excluded based on their
681   *                                         location.
682   * @param  includeFilters                  The set of filters to use to match
683   *                                         entries that should be included in
684   *                                         the export.  It may be {@code null}
685   *                                         or empty if no entries should be
686   *                                         excluded based on their content.
687   * @param  excludeFilters                  The set of filters to use to match
688   *                                         entries that should be excluded
689   *                                         from the export.  It may be
690   *                                         {@code null} or empty if no entries
691   *                                         should be excluded based on their
692   *                                         content.
693   * @param  includeAttributes               The set of attributes that should
694   *                                         be included in exported entries.
695   *                                         It may be {@code null} or empty if
696   *                                         all attributes should be included.
697   * @param  excludeAttributes               The set of attributes that should
698   *                                         be excluded from exported entries.
699   *                                         It may be {@code null} or empty if
700   *                                         no attributes should be excluded.
701   * @param  wrapColumn                      The column at which long lines
702   *                                         should be wrapped.  It may be less
703   *                                         than or equal to zero to indicate
704   *                                         that long lines should not be
705   *                                         wrapped.
706   * @param  compress                        Indicates whether the LDIF data
707   *                                         should be compressed as it is
708   *                                         written.
709   * @param  encrypt                         Indicates whether the LDIF data
710   *                                         should be encrypted as it is
711   *                                         written.
712   * @param  encryptionPassphraseFile        The path to a file containing the
713   *                                         passphrase to use to generate the
714   *                                         encryption key.  It amy be
715   *                                         {@code null} if the LDIF file is
716   *                                         not to be encrypted, or if the key
717   *                                         should be obtained in some other
718   *                                         way.
719   * @param  encryptionSettingsDefinitionID  The ID of the encryption settings
720   *                                         definition use to generate the
721   *                                         encryption key.  It may be
722   *                                         {@code null} if the LDIF file is
723   *                                         not to be encrypted, or if the key
724   *                                         should be obtained in some other
725   *                                         way.
726   * @param  sign                            Indicates whether to include a
727   *                                         signed hash of the content in the
728   *                                         exported data.
729   * @param  maxMegabytesPerSecond           The maximum rate in megabytes per
730   *                                         second at which the LDIF file
731   *                                         should be written.
732   * @param  scheduledStartTime              The time that this task should
733   *                                         start running.
734   * @param  dependencyIDs                   The list of task IDs that will be
735   *                                         required to complete before this
736   *                                         task will be eligible to start.
737   * @param  failedDependencyAction          Indicates what action should be
738   *                                         taken if any of the dependencies
739   *                                         for this task do not complete
740   *                                         successfully.
741   * @param  notifyOnCompletion              The list of e-mail addresses of
742   *                                         individuals that should be notified
743   *                                         when this task completes.
744   * @param  notifyOnError                   The list of e-mail addresses of
745   *                                         individuals that should be notified
746   *                                         if this task does not complete
747   *                                         successfully.
748   */
749  public ExportTask(@Nullable final String taskID,
750              @NotNull final String backendID,
751              @NotNull final String ldifFile,
752              final boolean appendToLDIF,
753              @Nullable final List<String> includeBranches,
754              @Nullable final List<String> excludeBranches,
755              @Nullable final List<String> includeFilters,
756              @Nullable final List<String> excludeFilters,
757              @Nullable final List<String> includeAttributes,
758              @Nullable final List<String> excludeAttributes,
759              final int wrapColumn,
760              final boolean compress, final boolean encrypt,
761              @Nullable final String encryptionPassphraseFile,
762              @Nullable final String encryptionSettingsDefinitionID,
763              final boolean sign,
764              @Nullable final Integer maxMegabytesPerSecond,
765              @Nullable final Date scheduledStartTime,
766              @Nullable final List<String> dependencyIDs,
767              @Nullable final FailedDependencyAction failedDependencyAction,
768              @Nullable final List<String> notifyOnCompletion,
769              @Nullable final List<String> notifyOnError)
770  {
771    this(taskID, backendID, ldifFile, appendToLDIF, includeBranches,
772         excludeBranches, includeFilters, excludeFilters, includeAttributes,
773         excludeAttributes, wrapColumn, compress, encrypt,
774         encryptionPassphraseFile, encryptionSettingsDefinitionID, sign,
775         maxMegabytesPerSecond, scheduledStartTime, dependencyIDs,
776         failedDependencyAction, null, notifyOnCompletion, null,
777         notifyOnError, null, null, null);
778  }
779
780
781
782  /**
783   * Creates a new export task with the provided information.
784   *
785   * @param  taskID                          The task ID to use for this task.
786   *                                         If it is {@code null} then a UUID
787   *                                         will be generated for use as the
788   *                                         task ID.
789   * @param  backendID                       The backend ID of the backend to be
790   *                                         exported.  It must not be
791   *                                         {@code null}.
792   * @param  ldifFile                        The path to the LDIF file to be
793   *                                         written.  It may be an absolute
794   *                                         path or one that is relative to the
795   *                                         server root.  It must not be
796   *                                         {@code null}.
797   * @param  appendToLDIF                    Indicates whether to an append to
798   *                                         any existing file rather than
799   *                                         overwriting it.
800   * @param  includeBranches                 The set of base DNs of entries to
801   *                                         include in the export.  It may be
802   *                                         {@code null} or empty if no entries
803   *                                         should be excluded based on their
804   *                                         location.
805   * @param  excludeBranches                 The set of base DNs of entries to
806   *                                         exclude from the export.  It may be
807   *                                         {@code null} or empty if no entries
808   *                                         should be excluded based on their
809   *                                         location.
810   * @param  includeFilters                  The set of filters to use to match
811   *                                         entries that should be included in
812   *                                         the export.  It may be {@code null}
813   *                                         or empty if no entries should be
814   *                                         excluded based on their content.
815   * @param  excludeFilters                  The set of filters to use to match
816   *                                         entries that should be excluded
817   *                                         from the export.  It may be
818   *                                         {@code null} or empty if no entries
819   *                                         should be excluded based on their
820   *                                         content.
821   * @param  includeAttributes               The set of attributes that should
822   *                                         be included in exported entries.
823   *                                         It may be {@code null} or empty if
824   *                                         all attributes should be included.
825   * @param  excludeAttributes               The set of attributes that should
826   *                                         be excluded from exported entries.
827   *                                         It may be {@code null} or empty if
828   *                                         no attributes should be excluded.
829   * @param  wrapColumn                      The column at which long lines
830   *                                         should be wrapped.  It may be less
831   *                                         than or equal to zero to indicate
832   *                                         that long lines should not be
833   *                                         wrapped.
834   * @param  compress                        Indicates whether the LDIF data
835   *                                         should be compressed as it is
836   *                                         written.
837   * @param  encrypt                         Indicates whether the LDIF data
838   *                                         should be encrypted as it is
839   *                                         written.
840   * @param  encryptionPassphraseFile        The path to a file containing the
841   *                                         passphrase to use to generate the
842   *                                         encryption key.  It amy be
843   *                                         {@code null} if the LDIF file is
844   *                                         not to be encrypted, or if the key
845   *                                         should be obtained in some other
846   *                                         way.
847   * @param  encryptionSettingsDefinitionID  The ID of the encryption settings
848   *                                         definition use to generate the
849   *                                         encryption key.  It may be
850   *                                         {@code null} if the LDIF file is
851   *                                         not to be encrypted, or if the key
852   *                                         should be obtained in some other
853   *                                         way.
854   * @param  sign                            Indicates whether to include a
855   *                                         signed hash of the content in the
856   *                                         exported data.
857   * @param  maxMegabytesPerSecond           The maximum rate in megabytes per
858   *                                         second at which the LDIF file
859   *                                         should be written.
860   * @param  scheduledStartTime              The time that this task should
861   *                                         start running.
862   * @param  dependencyIDs                   The list of task IDs that will be
863   *                                         required to complete before this
864   *                                         task will be eligible to start.
865   * @param  failedDependencyAction          Indicates what action should be
866   *                                         taken if any of the dependencies
867   *                                         for this task do not complete
868   *                                         successfully.
869   * @param  notifyOnStart                   The list of e-mail addresses of
870   *                                         individuals that should be notified
871   *                                         when this task starts running.
872   * @param  notifyOnCompletion              The list of e-mail addresses of
873   *                                         individuals that should be notified
874   *                                         when this task completes.
875   * @param  notifyOnSuccess                 The list of e-mail addresses of
876   *                                         individuals that should be notified
877   *                                         if this task completes
878   *                                         successfully.
879   * @param  notifyOnError                   The list of e-mail addresses of
880   *                                         individuals that should be notified
881   *                                         if this task does not complete
882   *                                         successfully.
883   * @param  alertOnStart                    Indicates whether the server should
884   *                                         send an alert notification when
885   *                                         this task starts.
886   * @param  alertOnSuccess                  Indicates whether the server should
887   *                                         send an alert notification if this
888   *                                         task completes successfully.
889   * @param  alertOnError                    Indicates whether the server should
890   *                                         send an alert notification if this
891   *                                         task fails to complete
892   *                                         successfully.
893   */
894  public ExportTask(@Nullable final String taskID,
895              @NotNull final String backendID,
896              @NotNull final String ldifFile,
897              final boolean appendToLDIF,
898              @Nullable final List<String> includeBranches,
899              @Nullable final List<String> excludeBranches,
900              @Nullable final List<String> includeFilters,
901              @Nullable final List<String> excludeFilters,
902              @Nullable final List<String> includeAttributes,
903              @Nullable final List<String> excludeAttributes,
904              final int wrapColumn,
905              final boolean compress, final boolean encrypt,
906              @Nullable final String encryptionPassphraseFile,
907              @Nullable final String encryptionSettingsDefinitionID,
908              final boolean sign,
909              @Nullable final Integer maxMegabytesPerSecond,
910              @Nullable final Date scheduledStartTime,
911              @Nullable final List<String> dependencyIDs,
912              @Nullable final FailedDependencyAction failedDependencyAction,
913              @Nullable final List<String> notifyOnStart,
914              @Nullable final List<String> notifyOnCompletion,
915              @Nullable final List<String> notifyOnSuccess,
916              @Nullable final List<String> notifyOnError,
917              @Nullable final Boolean alertOnStart,
918              @Nullable final Boolean alertOnSuccess,
919              @Nullable final Boolean alertOnError)
920  {
921    super(taskID, EXPORT_TASK_CLASS, scheduledStartTime,
922         dependencyIDs, failedDependencyAction, notifyOnStart,
923         notifyOnCompletion, notifyOnSuccess, notifyOnError, alertOnStart,
924         alertOnSuccess, alertOnError);
925
926    Validator.ensureNotNull(backendID, ldifFile);
927
928    this.backendID = backendID;
929    this.ldifFile = ldifFile;
930    this.appendToLDIF = appendToLDIF;
931    this.wrapColumn = wrapColumn;
932    this.compress = compress;
933    this.encrypt = encrypt;
934    this.encryptionPassphraseFile = encryptionPassphraseFile;
935    this.encryptionSettingsDefinitionID = encryptionSettingsDefinitionID;
936    this.sign = sign;
937    this.maxMegabytesPerSecond = maxMegabytesPerSecond;
938
939    if (includeBranches == null)
940    {
941      this.includeBranches = Collections.emptyList();
942    }
943    else
944    {
945      this.includeBranches = Collections.unmodifiableList(includeBranches);
946    }
947
948    if (excludeBranches == null)
949    {
950      this.excludeBranches = Collections.emptyList();
951    }
952    else
953    {
954      this.excludeBranches = Collections.unmodifiableList(excludeBranches);
955    }
956
957    if (includeFilters == null)
958    {
959      this.includeFilters = Collections.emptyList();
960    }
961    else
962    {
963      this.includeFilters = Collections.unmodifiableList(includeFilters);
964    }
965
966    if (excludeFilters == null)
967    {
968      this.excludeFilters = Collections.emptyList();
969    }
970    else
971    {
972      this.excludeFilters = Collections.unmodifiableList(excludeFilters);
973    }
974
975    if (includeAttributes == null)
976    {
977      this.includeAttributes = Collections.emptyList();
978    }
979    else
980    {
981      this.includeAttributes = Collections.unmodifiableList(includeAttributes);
982    }
983
984    if (excludeAttributes == null)
985    {
986      this.excludeAttributes = Collections.emptyList();
987    }
988    else
989    {
990      this.excludeAttributes = Collections.unmodifiableList(excludeAttributes);
991    }
992  }
993
994
995
996  /**
997   * Creates a new export task from the provided entry.
998   *
999   * @param  entry  The entry to use to create this export task.
1000   *
1001   * @throws  TaskException  If the provided entry cannot be parsed as an export
1002   *                         task entry.
1003   */
1004  public ExportTask(@NotNull final Entry entry)
1005         throws TaskException
1006  {
1007    super(entry);
1008
1009
1010    // Get the backend ID.  It must be present.
1011    backendID = entry.getAttributeValue(ATTR_BACKEND_ID);
1012    if (backendID == null)
1013    {
1014      throw new TaskException(ERR_EXPORT_TASK_NO_BACKEND_ID.get(
1015                                   getTaskEntryDN()));
1016    }
1017
1018
1019    // Get the LDIF file path.  It must be present.
1020    ldifFile = entry.getAttributeValue(ATTR_LDIF_FILE);
1021    if (ldifFile == null)
1022    {
1023      throw new TaskException(ERR_EXPORT_TASK_NO_LDIF_FILE.get(
1024                                   getTaskEntryDN()));
1025    }
1026
1027
1028    // Get the appendLDIF flag.  It may be absent.
1029    appendToLDIF = parseBooleanValue(entry, ATTR_APPEND_TO_LDIF, false);
1030
1031
1032    // Get the list of include branches.  It may be absent.
1033    includeBranches = parseStringList(entry, ATTR_INCLUDE_BRANCH);
1034
1035
1036    // Get the list of exclude branches.  It may be absent.
1037    excludeBranches = parseStringList(entry, ATTR_EXCLUDE_BRANCH);
1038
1039
1040    // Get the list of include filters.  It may be absent.
1041    includeFilters = parseStringList(entry, ATTR_INCLUDE_FILTER);
1042
1043
1044    // Get the list of exclude filters.  It may be absent.
1045    excludeFilters = parseStringList(entry, ATTR_EXCLUDE_FILTER);
1046
1047
1048    // Get the list of include attributes.  It may be absent.
1049    includeAttributes = parseStringList(entry, ATTR_INCLUDE_ATTRIBUTE);
1050
1051
1052    // Get the list of exclude attributes.  It may be absent.
1053    excludeAttributes = parseStringList(entry, ATTR_EXCLUDE_ATTRIBUTE);
1054
1055
1056    // Get the wrap column.  It may be absent.
1057    final String wrapStr = entry.getAttributeValue(ATTR_WRAP_COLUMN);
1058    if (wrapStr == null)
1059    {
1060      wrapColumn = -1;
1061    }
1062    else
1063    {
1064      try
1065      {
1066        wrapColumn = Integer.parseInt(wrapStr);
1067      }
1068      catch (final Exception e)
1069      {
1070        Debug.debugException(e);
1071        throw new TaskException(ERR_EXPORT_TASK_CANNOT_PARSE_WRAP_COLUMN.get(
1072                                     getTaskEntryDN(), wrapStr), e);
1073      }
1074    }
1075
1076
1077    // Get the compress flag.  It may be absent.
1078    compress = parseBooleanValue(entry, ATTR_COMPRESS, false);
1079
1080
1081    // Get the encrypt flag.  It may be absent.
1082    encrypt = parseBooleanValue(entry, ATTR_ENCRYPT, false);
1083
1084
1085    // Get the path to the encryption passphrase file.  It may be absent.
1086    encryptionPassphraseFile =
1087         entry.getAttributeValue(ATTR_ENCRYPTION_PASSPHRASE_FILE);
1088
1089
1090    // Get the encryption settings definition ID.  It may be absent.
1091    encryptionSettingsDefinitionID =
1092         entry.getAttributeValue(ATTR_ENCRYPTION_SETTINGS_DEFINITION_ID);
1093
1094
1095    // Get the sign flag.  It may be absent.
1096    sign = parseBooleanValue(entry, ATTR_SIGN, false);
1097
1098
1099    // Get the maximum write rate in megabytes per second.  It may be absent.
1100    maxMegabytesPerSecond =
1101         entry.getAttributeValueAsInteger(ATTR_MAX_MEGABYTES_PER_SECOND);
1102  }
1103
1104
1105
1106  /**
1107   * Creates a new export task from the provided set of task properties.
1108   *
1109   * @param  properties  The set of task properties and their corresponding
1110   *                     values to use for the task.  It must not be
1111   *                     {@code null}.
1112   *
1113   * @throws  TaskException  If the provided set of properties cannot be used to
1114   *                         create a valid export task.
1115   */
1116  public ExportTask(@NotNull final Map<TaskProperty,List<Object>> properties)
1117         throws TaskException
1118  {
1119    super(EXPORT_TASK_CLASS, properties);
1120
1121    boolean  a         = false;
1122    boolean  c         = false;
1123    boolean  e         = false;
1124    boolean  s         = false;
1125    Integer  maxMB     = null;
1126    long     w         = 0;
1127    String   b         = null;
1128    String   encID     = null;
1129    String   encPWFile = null;
1130    String   l         = null;
1131    String[] eA        = StaticUtils.NO_STRINGS;
1132    String[] eB        = StaticUtils.NO_STRINGS;
1133    String[] eF        = StaticUtils.NO_STRINGS;
1134    String[] iA        = StaticUtils.NO_STRINGS;
1135    String[] iB        = StaticUtils.NO_STRINGS;
1136    String[] iF        = StaticUtils.NO_STRINGS;
1137
1138    for (final Map.Entry<TaskProperty,List<Object>> entry :
1139         properties.entrySet())
1140    {
1141      final TaskProperty p = entry.getKey();
1142      final String attrName = p.getAttributeName();
1143      final List<Object> values = entry.getValue();
1144
1145      if (attrName.equalsIgnoreCase(ATTR_BACKEND_ID))
1146      {
1147        b = parseString(p, values, b);
1148      }
1149      else if (attrName.equalsIgnoreCase(ATTR_LDIF_FILE))
1150      {
1151        l = parseString(p, values, l);
1152      }
1153      else if (attrName.equalsIgnoreCase(ATTR_APPEND_TO_LDIF))
1154      {
1155        a = parseBoolean(p, values, a);
1156      }
1157      else if (attrName.equalsIgnoreCase(ATTR_INCLUDE_BRANCH))
1158      {
1159        iB = parseStrings(p, values, iB);
1160      }
1161      else if (attrName.equalsIgnoreCase(ATTR_EXCLUDE_BRANCH))
1162      {
1163        eB = parseStrings(p, values, eB);
1164      }
1165      else if (attrName.equalsIgnoreCase(ATTR_INCLUDE_FILTER))
1166      {
1167        iF = parseStrings(p, values, iF);
1168      }
1169      else if (attrName.equalsIgnoreCase(ATTR_EXCLUDE_FILTER))
1170      {
1171        eF = parseStrings(p, values, eF);
1172      }
1173      else if (attrName.equalsIgnoreCase(ATTR_INCLUDE_ATTRIBUTE))
1174      {
1175        iA = parseStrings(p, values, iA);
1176      }
1177      else if (attrName.equalsIgnoreCase(ATTR_EXCLUDE_ATTRIBUTE))
1178      {
1179        eA = parseStrings(p, values, eA);
1180      }
1181      else if (attrName.equalsIgnoreCase(ATTR_WRAP_COLUMN))
1182      {
1183        w = parseLong(p, values, w);
1184      }
1185      else if (attrName.equalsIgnoreCase(ATTR_COMPRESS))
1186      {
1187        c = parseBoolean(p, values, c);
1188      }
1189      else if (attrName.equalsIgnoreCase(ATTR_ENCRYPT))
1190      {
1191        e = parseBoolean(p, values, e);
1192      }
1193      else if (attrName.equalsIgnoreCase(ATTR_ENCRYPTION_PASSPHRASE_FILE))
1194      {
1195        encPWFile = parseString(p, values, encPWFile);
1196      }
1197      else if (attrName.equalsIgnoreCase(
1198           ATTR_ENCRYPTION_SETTINGS_DEFINITION_ID))
1199      {
1200        encID = parseString(p, values, encID);
1201      }
1202      else if (attrName.equalsIgnoreCase(ATTR_SIGN))
1203      {
1204        s = parseBoolean(p, values, s);
1205      }
1206      else if (attrName.equalsIgnoreCase(ATTR_MAX_MEGABYTES_PER_SECOND))
1207      {
1208        final Long maxMBLong = parseLong(p, values, null);
1209        if (maxMBLong == null)
1210        {
1211          maxMB = null;
1212        }
1213        else
1214        {
1215          maxMB = maxMBLong.intValue();
1216        }
1217      }
1218    }
1219
1220    if (b == null)
1221    {
1222      throw new TaskException(ERR_EXPORT_TASK_NO_BACKEND_ID.get(
1223                                   getTaskEntryDN()));
1224    }
1225
1226    if (l == null)
1227    {
1228      throw new TaskException(ERR_EXPORT_TASK_NO_LDIF_FILE.get(
1229                                   getTaskEntryDN()));
1230    }
1231
1232    backendID = b;
1233    ldifFile = l;
1234    appendToLDIF = a;
1235    includeAttributes = Collections.unmodifiableList(Arrays.asList(iA));
1236    excludeAttributes = Collections.unmodifiableList(Arrays.asList(eA));
1237    includeBranches = Collections.unmodifiableList(Arrays.asList(iB));
1238    excludeBranches = Collections.unmodifiableList(Arrays.asList(eB));
1239    includeFilters = Collections.unmodifiableList(Arrays.asList(iF));
1240    excludeFilters = Collections.unmodifiableList(Arrays.asList(eF));
1241    wrapColumn = (int) w;
1242    compress = c;
1243    encrypt = e;
1244    encryptionPassphraseFile = encPWFile;
1245    encryptionSettingsDefinitionID = encID;
1246    sign = s;
1247    maxMegabytesPerSecond = maxMB;
1248  }
1249
1250
1251
1252  /**
1253   * {@inheritDoc}
1254   */
1255  @Override()
1256  @NotNull()
1257  public String getTaskName()
1258  {
1259    return INFO_TASK_NAME_EXPORT.get();
1260  }
1261
1262
1263
1264  /**
1265   * {@inheritDoc}
1266   */
1267  @Override()
1268  @NotNull()
1269  public String getTaskDescription()
1270  {
1271    return INFO_TASK_DESCRIPTION_EXPORT.get();
1272  }
1273
1274
1275
1276  /**
1277   * Retrieves the backend ID of the backend from which the data is to be
1278   * exported.
1279   *
1280   * @return  The backend ID of the backend from which the data is to be
1281   *          exported.
1282   */
1283  @NotNull()
1284  public String getBackendID()
1285  {
1286    return backendID;
1287  }
1288
1289
1290
1291  /**
1292   * Retrieves the path to the LDIF file to which the exported data should be
1293   * written.  It may be either an absolute path or one that is relative to the
1294   * server root.
1295   *
1296   * @return  The path to the LDIF file to which the exported data should be
1297   *          written.
1298   */
1299  @NotNull()
1300  public String getLDIFFile()
1301  {
1302    return ldifFile;
1303  }
1304
1305
1306
1307  /**
1308   * Indicates whether to append to the LDIF file rather than overwriting it if
1309   * it already exists.
1310   *
1311   * @return  {@code true} if the server should append to an existing LDIF file,
1312   *          or {@code false} if the server should overwrite it.
1313   */
1314  public boolean appendToLDIF()
1315  {
1316    return appendToLDIF;
1317  }
1318
1319
1320
1321  /**
1322   * Retrieves a list of base DNs of branches that should be included in the
1323   * export.
1324   *
1325   * @return  A list of base DNs of branches that should be included in the
1326   *          export, or an empty list if no entries should be excluded based on
1327   *          their location.
1328   */
1329  @NotNull()
1330  public List<String> getIncludeBranches()
1331  {
1332    return includeBranches;
1333  }
1334
1335
1336
1337  /**
1338   * Retrieves a list of base DNs of branches that should be excluded from the
1339   * export.
1340   *
1341   * @return  A list of base DNs of branches that should be excluded from the
1342   *          export, or an empty list if no entries should be excluded based on
1343   *          their location.
1344   */
1345  @NotNull()
1346  public List<String> getExcludeBranches()
1347  {
1348    return excludeBranches;
1349  }
1350
1351
1352
1353  /**
1354   * Retrieves a list of search filters that should be used to determine which
1355   * entries should be included in the export.
1356   *
1357   * @return  A list of search filters that should be used to determine which
1358   *          entries should be included in the export, or an empty list if no
1359   *          entries should be excluded based on their content.
1360   */
1361  @NotNull()
1362  public List<String> getIncludeFilters()
1363  {
1364    return includeFilters;
1365  }
1366
1367
1368
1369  /**
1370   * Retrieves a list of search filters that should be used to determine which
1371   * entries should be excluded from the export.
1372   *
1373   * @return  A list of search filters that should be used to determine which
1374   *          entries should be excluded from the export, or an empty list if no
1375   *          entries should be excluded based on their content.
1376   */
1377  @NotNull()
1378  public List<String> getExcludeFilters()
1379  {
1380    return excludeFilters;
1381  }
1382
1383
1384
1385  /**
1386   * Retrieves a list of the attributes that should be included in exported
1387   * entries.
1388   *
1389   * @return  A list of the attributes that should be included in exported
1390   *          entries, or an empty list if no attributes should be excluded.
1391   */
1392  @NotNull()
1393  public List<String> getIncludeAttributes()
1394  {
1395    return includeAttributes;
1396  }
1397
1398
1399
1400  /**
1401   * Retrieves a list of the attributes that should be excluded from exported
1402   * entries.
1403   *
1404   * @return  A list of the attributes that should be excluded from exported
1405   *          entries, or an empty list if no attributes should be excluded.
1406   */
1407  @NotNull()
1408  public List<String> getExcludeAttributes()
1409  {
1410    return excludeAttributes;
1411  }
1412
1413
1414
1415  /**
1416   * Retrieves the column number at which long lines should be wrapped.
1417   *
1418   * @return  The column number at which long lines should be wrapped, or a
1419   *          value less than or equal to zero to indicate that no wrapping
1420   *          should be performed.
1421   */
1422  public int getWrapColumn()
1423  {
1424    return wrapColumn;
1425  }
1426
1427
1428
1429  /**
1430   * Indicates whether the LDIF data should be compressed as it is exported.
1431   *
1432   * @return  {@code true} if the LDIF data should be compressed as it is
1433   *          exported, or {@code false} if not.
1434   */
1435  public boolean compress()
1436  {
1437    return compress;
1438  }
1439
1440
1441
1442  /**
1443   * Indicates whether the LDIF data should be encrypted as it is exported.
1444   *
1445   * @return  {@code true} if the LDIF data should be encrypted as it is
1446   *          exported, or {@code false} if not.
1447   */
1448  public boolean encrypt()
1449  {
1450    return encrypt;
1451  }
1452
1453
1454
1455  /**
1456   * Retrieves the path to a file that contains the passphrase to use to
1457   * generate the encryption key.
1458   *
1459   * @return  The path to a file that contains the passphrase to use to
1460   *          generate the encryption key, or {@code null} if the LDIF file
1461   *          should not be encrypted or if the encryption key should be
1462   *          obtained through some other means.
1463   */
1464  @Nullable()
1465  public String getEncryptionPassphraseFile()
1466  {
1467    return encryptionPassphraseFile;
1468  }
1469
1470
1471
1472  /**
1473   * Retrieves the identifier of the encryption settings definition to use to
1474   * generate the encryption key.
1475   *
1476   * @return  The identifier of the encryption settings definition to use to
1477   *          generate the encryption key, or {@code null} if the LDIF file
1478   *          should not be encrypted or if the encryption key should be
1479   *          obtained through some other means.
1480   */
1481  @Nullable()
1482  public String getEncryptionSettingsDefinitionID()
1483  {
1484    return encryptionSettingsDefinitionID;
1485  }
1486
1487
1488
1489  /**
1490   * Indicates whether the exported LDIF data should include a signed hash.
1491   *
1492   * @return  {@code true} if the exported LDIF data should include a signed
1493   *          hash, or {@code false} if not.
1494   */
1495  public boolean sign()
1496  {
1497    return sign;
1498  }
1499
1500
1501
1502  /**
1503   * Retrieves the maximum rate, in megabytes per second, at which the LDIF file
1504   * should be written.
1505   *
1506   * @return  The maximum rate, in megabytes per second, at which the LDIF file
1507   *          should be written, or {@code null} if the writing should not be
1508   *          rate limited.
1509   */
1510  @Nullable()
1511  public Integer getMaxMegabytesPerSecond()
1512  {
1513    return maxMegabytesPerSecond;
1514  }
1515
1516
1517
1518  /**
1519   * {@inheritDoc}
1520   */
1521  @Override()
1522  @NotNull()
1523  protected List<String> getAdditionalObjectClasses()
1524  {
1525    return Collections.singletonList(OC_EXPORT_TASK);
1526  }
1527
1528
1529
1530  /**
1531   * {@inheritDoc}
1532   */
1533  @Override()
1534  @NotNull()
1535  protected List<Attribute> getAdditionalAttributes()
1536  {
1537    final ArrayList<Attribute> attrs = new ArrayList<>(20);
1538
1539    attrs.add(new Attribute(ATTR_BACKEND_ID, backendID));
1540    attrs.add(new Attribute(ATTR_LDIF_FILE, ldifFile));
1541    attrs.add(new Attribute(ATTR_APPEND_TO_LDIF, String.valueOf(appendToLDIF)));
1542    attrs.add(new Attribute(ATTR_COMPRESS, String.valueOf(compress)));
1543    attrs.add(new Attribute(ATTR_ENCRYPT, String.valueOf(encrypt)));
1544    attrs.add(new Attribute(ATTR_SIGN, String.valueOf(sign)));
1545
1546    if (! includeBranches.isEmpty())
1547    {
1548      attrs.add(new Attribute(ATTR_INCLUDE_BRANCH, includeBranches));
1549    }
1550
1551    if (! excludeBranches.isEmpty())
1552    {
1553      attrs.add(new Attribute(ATTR_EXCLUDE_BRANCH, excludeBranches));
1554    }
1555
1556    if (! includeAttributes.isEmpty())
1557    {
1558      attrs.add(new Attribute(ATTR_INCLUDE_ATTRIBUTE, includeAttributes));
1559    }
1560
1561    if (! excludeAttributes.isEmpty())
1562    {
1563      attrs.add(new Attribute(ATTR_EXCLUDE_ATTRIBUTE, excludeAttributes));
1564    }
1565
1566    if (! includeFilters.isEmpty())
1567    {
1568      attrs.add(new Attribute(ATTR_INCLUDE_FILTER, includeFilters));
1569    }
1570
1571    if (! excludeFilters.isEmpty())
1572    {
1573      attrs.add(new Attribute(ATTR_EXCLUDE_FILTER, excludeFilters));
1574    }
1575
1576    if (wrapColumn > 0)
1577    {
1578      attrs.add(new Attribute(ATTR_WRAP_COLUMN, String.valueOf(wrapColumn)));
1579    }
1580
1581    if (encryptionPassphraseFile != null)
1582    {
1583      attrs.add(new Attribute(ATTR_ENCRYPTION_PASSPHRASE_FILE,
1584           encryptionPassphraseFile));
1585    }
1586
1587    if (encryptionSettingsDefinitionID != null)
1588    {
1589      attrs.add(new Attribute(ATTR_ENCRYPTION_SETTINGS_DEFINITION_ID,
1590           encryptionSettingsDefinitionID));
1591    }
1592
1593    if (maxMegabytesPerSecond != null)
1594    {
1595      attrs.add(new Attribute(ATTR_MAX_MEGABYTES_PER_SECOND,
1596           String.valueOf(maxMegabytesPerSecond)));
1597    }
1598
1599    return attrs;
1600  }
1601
1602
1603
1604  /**
1605   * {@inheritDoc}
1606   */
1607  @Override()
1608  @NotNull()
1609  public List<TaskProperty> getTaskSpecificProperties()
1610  {
1611    final List<TaskProperty> propList = Arrays.asList(
1612         PROPERTY_BACKEND_ID,
1613         PROPERTY_LDIF_FILE,
1614         PROPERTY_APPEND_TO_LDIF,
1615         PROPERTY_INCLUDE_BRANCH,
1616         PROPERTY_EXCLUDE_BRANCH,
1617         PROPERTY_INCLUDE_FILTER,
1618         PROPERTY_EXCLUDE_FILTER,
1619         PROPERTY_INCLUDE_ATTRIBUTE,
1620         PROPERTY_EXCLUDE_ATTRIBUTE,
1621         PROPERTY_WRAP_COLUMN,
1622         PROPERTY_COMPRESS,
1623         PROPERTY_ENCRYPT,
1624         PROPERTY_ENCRYPTION_PASSPHRASE_FILE,
1625         PROPERTY_ENCRYPTION_SETTINGS_DEFINITION_ID,
1626         PROPERTY_SIGN,
1627         PROPERTY_MAX_MEGABYTES_PER_SECOND);
1628
1629    return Collections.unmodifiableList(propList);
1630  }
1631
1632
1633
1634  /**
1635   * {@inheritDoc}
1636   */
1637  @Override()
1638  @NotNull()
1639  public Map<TaskProperty,List<Object>> getTaskPropertyValues()
1640  {
1641    final LinkedHashMap<TaskProperty,List<Object>> props =
1642         new LinkedHashMap<>(StaticUtils.computeMapCapacity(30));
1643
1644    props.put(PROPERTY_BACKEND_ID,
1645              Collections.<Object>singletonList(backendID));
1646
1647    props.put(PROPERTY_LDIF_FILE,
1648              Collections.<Object>singletonList(ldifFile));
1649
1650    props.put(PROPERTY_APPEND_TO_LDIF,
1651              Collections.<Object>singletonList(appendToLDIF));
1652
1653    props.put(PROPERTY_INCLUDE_BRANCH,
1654              Collections.<Object>unmodifiableList(includeBranches));
1655
1656    props.put(PROPERTY_EXCLUDE_BRANCH,
1657              Collections.<Object>unmodifiableList(excludeBranches));
1658
1659    props.put(PROPERTY_INCLUDE_FILTER,
1660              Collections.<Object>unmodifiableList(includeFilters));
1661
1662    props.put(PROPERTY_EXCLUDE_FILTER,
1663              Collections.<Object>unmodifiableList(excludeFilters));
1664
1665    props.put(PROPERTY_INCLUDE_ATTRIBUTE,
1666              Collections.<Object>unmodifiableList(includeAttributes));
1667
1668    props.put(PROPERTY_EXCLUDE_ATTRIBUTE,
1669              Collections.<Object>unmodifiableList(excludeAttributes));
1670
1671    props.put(PROPERTY_WRAP_COLUMN,
1672              Collections.<Object>singletonList((long) wrapColumn));
1673
1674    props.put(PROPERTY_COMPRESS,
1675              Collections.<Object>singletonList(compress));
1676
1677    props.put(PROPERTY_ENCRYPT,
1678              Collections.<Object>singletonList(encrypt));
1679
1680    if (encryptionPassphraseFile == null)
1681    {
1682      props.put(PROPERTY_ENCRYPTION_PASSPHRASE_FILE, Collections.emptyList());
1683    }
1684    else
1685    {
1686      props.put(PROPERTY_ENCRYPTION_PASSPHRASE_FILE,
1687         Collections.<Object>singletonList(encryptionPassphraseFile));
1688    }
1689
1690    if (encryptionSettingsDefinitionID == null)
1691    {
1692      props.put(PROPERTY_ENCRYPTION_SETTINGS_DEFINITION_ID,
1693           Collections.emptyList());
1694    }
1695    else
1696    {
1697      props.put(PROPERTY_ENCRYPTION_SETTINGS_DEFINITION_ID,
1698         Collections.<Object>singletonList(encryptionSettingsDefinitionID));
1699    }
1700
1701    props.put(PROPERTY_SIGN, Collections.<Object>singletonList(sign));
1702
1703    if (maxMegabytesPerSecond == null)
1704    {
1705      props.put(PROPERTY_MAX_MEGABYTES_PER_SECOND, Collections.emptyList());
1706    }
1707    else
1708    {
1709      props.put(PROPERTY_MAX_MEGABYTES_PER_SECOND,
1710         Collections.<Object>singletonList(maxMegabytesPerSecond.longValue()));
1711    }
1712
1713    props.putAll(super.getTaskPropertyValues());
1714    return Collections.unmodifiableMap(props);
1715  }
1716}