001/*
002 * Copyright 2021-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2021-2024 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2021-2024 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.unboundidds.tasks;
037
038
039
040import java.io.Serializable;
041import java.util.ArrayList;
042import java.util.Date;
043import java.util.Iterator;
044import java.util.List;
045
046import com.unboundid.util.Mutable;
047import com.unboundid.util.NotNull;
048import com.unboundid.util.Nullable;
049import com.unboundid.util.ThreadSafety;
050import com.unboundid.util.ThreadSafetyLevel;
051
052
053
054/**
055 * This class defines a set of properties that may be used when creating a
056 * {@link RemoveObjectClassTask}.
057 * <BR>
058 * <BLOCKQUOTE>
059 *   <B>NOTE:</B>  This class, and other classes within the
060 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
061 *   supported for use against Ping Identity, UnboundID, and
062 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
063 *   for proprietary functionality or for external specifications that are not
064 *   considered stable or mature enough to be guaranteed to work in an
065 *   interoperable way with other types of LDAP servers.
066 * </BLOCKQUOTE>
067 */
068@Mutable()
069@ThreadSafety(level=ThreadSafetyLevel.NOT_THREADSAFE)
070public final class RemoveObjectClassTaskProperties
071       implements Serializable
072{
073  /**
074   * The serial version UID for this serializable class.
075   */
076  private static final long serialVersionUID = -1944036171229173315L;
077
078
079
080  // Indicates whether to generate an administrative alert if the task completes
081  // with an error.
082  @Nullable private Boolean alertOnError;
083
084  // Indicates whether to generate an administrative alert when the task starts
085  // running.
086  @Nullable private Boolean alertOnStart;
087
088  // Indicates whether to generate an administrative alert if the task completes
089  // successfully.
090  @Nullable private Boolean alertOnSuccess;
091
092  // The time at which the task should start running.
093  @Nullable private Date scheduledStartTime;
094
095  // The action to take if any of the dependencies for this task complete
096  // unsuccessfully.
097  @Nullable private FailedDependencyAction failedDependencyAction;
098
099  // The dependency IDs of any tasks on which the remove object class task
100  // should depend.
101  @NotNull private final List<String> dependencyIDs;
102
103  // The addresses to email whenever the task completes, regardless of success
104  // or failure.
105  @NotNull private final List<String> notifyOnCompletion;
106
107  // The addresses to email if the task completes with an error.
108  @NotNull private final List<String> notifyOnError;
109
110  // The addresses to email when the task starts.
111  @NotNull private final List<String> notifyOnStart;
112
113  // The addresses to email if the task completes successfully.
114  @NotNull private final List<String> notifyOnSuccess;
115
116  // The name of the object class to be removed from the schema.
117  @NotNull private String objectClass;
118
119  // The task ID to use for the remove object class task.
120  @Nullable private String taskID;
121
122
123
124  /**
125   * Creates a new set of remove object class task properties.  It will use
126   * default values for all general task properties.
127   *
128   * @param  objectClass  The name or OID of the object class to remove from the
129   *                      the server schema.
130   */
131  public RemoveObjectClassTaskProperties(@NotNull final String objectClass)
132  {
133    this.objectClass = objectClass;
134
135    alertOnError = null;
136    alertOnStart = null;
137    alertOnSuccess = null;
138    scheduledStartTime = null;
139    failedDependencyAction = null;
140    dependencyIDs = new ArrayList<>(5);
141    notifyOnCompletion = new ArrayList<>(5);
142    notifyOnError = new ArrayList<>(5);
143    notifyOnStart = new ArrayList<>(5);
144    notifyOnSuccess = new ArrayList<>(5);
145    taskID = null;
146  }
147
148
149
150  /**
151   * Creates a new set of remove object class task properties as a copy of the
152   * provided properties.
153   *
154   * @param  properties  The remove object class task properties to duplicate.
155   */
156  public RemoveObjectClassTaskProperties(
157              @NotNull final RemoveObjectClassTaskProperties properties)
158  {
159    objectClass = properties.getObjectClass();
160    alertOnError = properties.getAlertOnError();
161    alertOnStart = properties.getAlertOnStart();
162    alertOnSuccess = properties.getAlertOnSuccess();
163    scheduledStartTime = properties.getScheduledStartTime();
164    failedDependencyAction = properties.getFailedDependencyAction();
165    dependencyIDs = new ArrayList<>(properties.getDependencyIDs());
166    notifyOnCompletion = new ArrayList<>(properties.getNotifyOnCompletion());
167    notifyOnError = new ArrayList<>(properties.getNotifyOnError());
168    notifyOnStart = new ArrayList<>(properties.getNotifyOnStart());
169    notifyOnSuccess = new ArrayList<>(properties.getNotifyOnSuccess());
170    taskID = properties.getTaskID();
171  }
172
173
174
175  /**
176   * Creates a new set of remove object class task properties set from the
177   * provided task instance.
178   *
179   * @param  task  The remove object class task instance from which the
180   *               properties should be set.
181   */
182  public RemoveObjectClassTaskProperties(
183              @NotNull final RemoveObjectClassTask task)
184  {
185    objectClass = task.getObjectClass();
186    alertOnError = task.getAlertOnError();
187    alertOnStart = task.getAlertOnStart();
188    alertOnSuccess = task.getAlertOnSuccess();
189    scheduledStartTime = task.getScheduledStartTime();
190    failedDependencyAction = task.getFailedDependencyAction();
191    dependencyIDs = new ArrayList<>(task.getDependencyIDs());
192    notifyOnCompletion = new ArrayList<>(task.getNotifyOnCompletionAddresses());
193    notifyOnError = new ArrayList<>(task.getNotifyOnErrorAddresses());
194    notifyOnStart = new ArrayList<>(task.getNotifyOnStartAddresses());
195    notifyOnSuccess = new ArrayList<>(task.getNotifyOnSuccessAddresses());
196    taskID = task.getTaskID();
197  }
198
199
200
201  /**
202   * Retrieves the name or OID of the object class to remove from the server
203   * schema.
204   *
205   * @return  The name or OID of the object class to remove from the server
206   *          schema.
207   */
208  @NotNull()
209  public String getObjectClass()
210  {
211    return objectClass;
212  }
213
214
215
216  /**
217   * Specifies the name or OID of the object class to remove from the server
218   * schema.
219   *
220   * @param  objectClass  The name or OID of the object class to remove from the
221   *                      server schema.
222   */
223  public void setObjectClass(@NotNull final String objectClass)
224  {
225    this.objectClass = objectClass;
226  }
227
228
229
230  /**
231   * Retrieves the task ID that should be used for the task.
232   *
233   * @return  The task ID that should be used for the task, or {@code null} if a
234   *          random UUID should be generated for use as the task ID.
235   */
236  @Nullable()
237  public String getTaskID()
238  {
239    return taskID;
240  }
241
242
243
244  /**
245   *Specifies the task ID that should be used for the task.
246   *
247   * @param  taskID  The task ID that should be used for the task.  It may be
248   *                 {@code null} if a random UUID should be generated for use
249   *                 as the task ID.
250   */
251  public void setTaskID(@Nullable final String taskID)
252  {
253    this.taskID = taskID;
254  }
255
256
257
258  /**
259   * Retrieves the earliest time that the task should be eligible to start
260   * running.
261   *
262   * @return  The earliest time that the task should be eligible to start
263   *          running, or {@code null} if the task should be eligible to start
264   *          immediately (or as soon as all of its dependencies have been
265   *          satisfied).
266   */
267  @Nullable()
268  public Date getScheduledStartTime()
269  {
270    return scheduledStartTime;
271  }
272
273
274
275  /**
276   * Specifies the earliest time that the task should be eligible to start
277   * running.
278   *
279   * @param  scheduledStartTime  The earliest time that the task should be
280   *                             eligible to start running.  It may be
281   *                             {@code null} if the task should be eligible to
282   *                             start immediately (or as soon as all of its
283   *                             dependencies have been satisfied).
284   */
285  public void setScheduledStartTime(@Nullable final Date scheduledStartTime)
286  {
287    this.scheduledStartTime = scheduledStartTime;
288  }
289
290
291
292  /**
293   * Retrieves the task IDs for any tasks that must complete before the new
294   * remove object class task will be eligible to start running.
295   *
296   * @return  The task IDs for any tasks that must complete before the new
297   *          remove object class task will be eligible to start running, or an
298   *          empty list if the new task should not depend on any other tasks.
299   */
300  @NotNull()
301  public List<String> getDependencyIDs()
302  {
303    return new ArrayList<>(dependencyIDs);
304  }
305
306
307
308  /**
309   * Specifies the task IDs for any tasks that must complete before the new
310   * remove object class task will be eligible to start running.
311   *
312   * @param  dependencyIDs  The task IDs for any tasks that must complete before
313   *                        the new remove object class task will be eligible to
314   *                        start running.  It may be {@code null} or empty if
315   *                        the new task should not depend on any other tasks.
316   */
317  public void setDependencyIDs(@Nullable final List<String> dependencyIDs)
318  {
319    this.dependencyIDs.clear();
320    if (dependencyIDs != null)
321    {
322      this.dependencyIDs.addAll(dependencyIDs);
323    }
324  }
325
326
327
328  /**
329   * Retrieves the action that the server should take if any of the tasks on
330   * which the new task depends did not complete successfully.
331   *
332   * @return  The action that the server should take if any of the tasks on
333   *          which the new task depends did not complete successfully, or
334   *          {@code null} if the property should not be specified when creating
335   *          the task (and the server should choose an appropriate failed
336   *          dependency action).
337   */
338  @Nullable()
339  public FailedDependencyAction getFailedDependencyAction()
340  {
341    return failedDependencyAction;
342  }
343
344
345
346  /**
347   * Specifies the action that the server should take if any of the tasks on
348   * which the new task depends did not complete successfully.
349   *
350   * @param  failedDependencyAction  The action that the server should take if
351   *                                 any of the tasks on which the new task
352   *                                 depends did not complete successfully.  It
353   *                                 may be {@code null} if the property should
354   *                                 not be specified when creating the task
355   *                                 (and the server should choose an
356   *                                 appropriate failed dependency action).
357   */
358  public void setFailedDependencyAction(
359       @Nullable final FailedDependencyAction failedDependencyAction)
360  {
361    this.failedDependencyAction = failedDependencyAction;
362  }
363
364
365
366  /**
367   * Retrieves the addresses to email whenever the task starts running.
368   *
369   * @return  The addresses to email whenever the task starts running, or an
370   *          empty list if no email notification should be sent when starting
371   *          the task.
372   */
373  @NotNull()
374  public List<String> getNotifyOnStart()
375  {
376    return new ArrayList<>(notifyOnStart);
377  }
378
379
380
381  /**
382   * Specifies the addresses to email whenever the task starts running.
383   *
384   * @param  notifyOnStart  The addresses to email whenever the task starts
385   *                        running.  It amy be {@code null} or empty if no
386   *                        email notification should be sent when starting the
387   *                        task.
388   */
389  public void setNotifyOnStart(@Nullable final List<String> notifyOnStart)
390  {
391    this.notifyOnStart.clear();
392    if (notifyOnStart != null)
393    {
394      this.notifyOnStart.addAll(notifyOnStart);
395    }
396  }
397
398
399
400  /**
401   * Retrieves the addresses to email whenever the task completes, regardless of
402   * its success or failure.
403   *
404   * @return  The addresses to email whenever the task completes, or an
405   *          empty list if no email notification should be sent when the task
406   *          completes.
407   */
408  @NotNull()
409  public List<String> getNotifyOnCompletion()
410  {
411    return new ArrayList<>(notifyOnCompletion);
412  }
413
414
415
416  /**
417   * Specifies the addresses to email whenever the task completes, regardless of
418   * its success or failure.
419   *
420   * @param  notifyOnCompletion  The addresses to email whenever the task
421   *                             completes.  It amy be {@code null} or empty if
422   *                             no email notification should be sent when the
423   *                             task completes.
424   */
425  public void setNotifyOnCompletion(
426                   @Nullable final List<String> notifyOnCompletion)
427  {
428    this.notifyOnCompletion.clear();
429    if (notifyOnCompletion != null)
430    {
431      this.notifyOnCompletion.addAll(notifyOnCompletion);
432    }
433  }
434
435
436
437  /**
438   * Retrieves the addresses to email if the task completes successfully.
439   *
440   * @return  The addresses to email if the task completes successfully, or an
441   *          empty list if no email notification should be sent on successful
442   *          completion.
443   */
444  @NotNull()
445  public List<String> getNotifyOnSuccess()
446  {
447    return new ArrayList<>(notifyOnSuccess);
448  }
449
450
451
452  /**
453   * Specifies the addresses to email if the task completes successfully.
454   *
455   * @param  notifyOnSuccess  The addresses to email if the task completes
456   *                          successfully.  It amy be {@code null} or empty if
457   *                          no email notification should be sent on
458   *                          successful completion.
459   */
460  public void setNotifyOnSuccess(@Nullable final List<String> notifyOnSuccess)
461  {
462    this.notifyOnSuccess.clear();
463    if (notifyOnSuccess != null)
464    {
465      this.notifyOnSuccess.addAll(notifyOnSuccess);
466    }
467  }
468
469
470
471  /**
472   * Retrieves the addresses to email if the task does not complete
473   * successfully.
474   *
475   * @return  The addresses to email if the task does not complete successfully,
476   *          or an empty list if no email notification should be sent on an
477   *          unsuccessful completion.
478   */
479  @NotNull()
480  public List<String> getNotifyOnError()
481  {
482    return new ArrayList<>(notifyOnError);
483  }
484
485
486
487  /**
488   * Specifies the addresses to email if the task does not complete
489   * successfully.
490   *
491   * @param  notifyOnError  The addresses to email if the task does not complete
492   *                        successfully.  It amy be {@code null} or empty if
493   *                        no email notification should be sent on an
494   *                        unsuccessful completion.
495   */
496  public void setNotifyOnError(@Nullable final List<String> notifyOnError)
497  {
498    this.notifyOnError.clear();
499    if (notifyOnError != null)
500    {
501      this.notifyOnError.addAll(notifyOnError);
502    }
503  }
504
505
506
507  /**
508   * Retrieves the flag that indicates whether the server should send an
509   * administrative alert notification when the task starts running.
510   *
511   * @return  The flag that indicates whether the server should send an
512   *          administrative alert notification when the task starts running,
513   *          or {@code null} if the property should not be specified when the
514   *          task is created (and the server will default to not sending any
515   *          alert).
516   */
517  @Nullable()
518  public Boolean getAlertOnStart()
519  {
520    return alertOnStart;
521  }
522
523
524
525  /**
526   * Specifies the flag that indicates whether the server should send an
527   * administrative alert notification when the task starts running.
528   *
529   * @param  alertOnStart  The flag that indicates whether the server should
530   *                       send an administrative alert notification when the
531   *                       task starts running,  It may be {@code null} if the
532   *                       property should not be specified when the task is
533   *                       created (and the server will default to not sending
534   *                       any alert).
535   */
536  public void setAlertOnStart(@Nullable final Boolean alertOnStart)
537  {
538    this.alertOnStart = alertOnStart;
539  }
540
541
542
543  /**
544   * Retrieves the flag that indicates whether the server should send an
545   * administrative alert notification if the task completes successfully.
546   *
547   * @return  The flag that indicates whether the server should send an
548   *          administrative alert notification if the task completes
549   *          successfully, or {@code null} if the property should not be
550   *          specified when the task is created (and the server will default to
551   *          not sending any alert).
552   */
553  @Nullable()
554  public Boolean getAlertOnSuccess()
555  {
556    return alertOnSuccess;
557  }
558
559
560
561  /**
562   * Specifies the flag that indicates whether the server should send an
563   * administrative alert notification if the task completes successfully.
564   *
565   * @param  alertOnSuccess  The flag that indicates whether the server should
566   *                         send an administrative alert notification if the
567   *                         task completes successfully,  It may be
568   *                         {@code null} if the property should not be
569   *                         specified when the task is created (and the server
570   *                         will default to not sending any alert).
571   */
572  public void setAlertOnSuccess(@Nullable final Boolean alertOnSuccess)
573  {
574    this.alertOnSuccess = alertOnSuccess;
575  }
576
577
578
579  /**
580   * Retrieves the flag that indicates whether the server should send an
581   * administrative alert notification if the task does not complete
582   * successfully.
583   *
584   * @return  The flag that indicates whether the server should send an
585   *          administrative alert notification if the task does not complete
586   *          successfully, or {@code null} if the property should not be
587   *          specified when the task is created (and the server will default to
588   *          not sending any alert).
589   */
590  @Nullable()
591  public Boolean getAlertOnError()
592  {
593    return alertOnError;
594  }
595
596
597
598  /**
599   * Specifies the flag that indicates whether the server should send an
600   * administrative alert notification if the task does not complete
601   * successfully.
602   *
603   * @param  alertOnError  The flag that indicates whether the server should
604   *                       send an administrative alert notification if the task
605   *                       does not complete successfully,  It may be
606   *                       {@code null} if the property should not be specified
607   *                       when the task is created (and the server will default
608   *                       to not sending any alert).
609   */
610  public void setAlertOnError(@Nullable final Boolean alertOnError)
611  {
612    this.alertOnError = alertOnError;
613  }
614
615
616
617  /**
618   * Retrieves a string representation of this remove object class task
619   * properties object.
620   *
621   * @return  A string representation of this remove object class task
622   *          properties object.
623   */
624  @Override()
625  @NotNull()
626  public String toString()
627  {
628    final StringBuilder buffer = new StringBuilder();
629    toString(buffer);
630    return buffer.toString();
631  }
632
633
634
635  /**
636   * Appends a string representation of this remove object class task
637   * properties object to the provided buffer.
638   *
639   * @param  buffer  The buffer to which the string representation will be
640   *                 appended.  It must not be {@code null}.
641   */
642  public void toString(@NotNull final StringBuilder buffer)
643  {
644    buffer.append("RemoveObjectClassProperties(");
645
646    appendNameValuePair(buffer, "taskID", taskID);
647    appendNameValuePair(buffer, "objectClass", objectClass);
648    appendNameValuePair(buffer, "scheduledStartTime", scheduledStartTime);
649    appendNameValuePair(buffer, "dependencyIDs", dependencyIDs);
650    appendNameValuePair(buffer, "failedDependencyAction",
651         failedDependencyAction);
652    appendNameValuePair(buffer, "notifyOnStart", notifyOnStart);
653    appendNameValuePair(buffer, "notifyOnCompletion", notifyOnCompletion);
654    appendNameValuePair(buffer, "notifyOnSuccess", notifyOnSuccess);
655    appendNameValuePair(buffer, "notifyOnError", notifyOnError);
656    appendNameValuePair(buffer, "alertOnStart", alertOnStart);
657    appendNameValuePair(buffer, "alertOnSuccess", alertOnSuccess);
658    appendNameValuePair(buffer, "alertOnError", alertOnError);
659
660    buffer.append(')');
661  }
662
663
664
665  /**
666   * Appends a name-value pair to the provided buffer, if the value is
667   * non-{@code null}.
668   *
669   * @param  buffer  The buffer to which the name-value pair should be appended.
670   * @param  name    The name to be used.  It must not be {@code null}.
671   * @param  value   The value to be used.  It may be {@code null} if there is
672   *                 no value for the property.
673   */
674  private static void appendNameValuePair(@NotNull final StringBuilder buffer,
675                                          @NotNull final String name,
676                                          @Nullable final Object value)
677  {
678    if (value == null)
679    {
680      return;
681    }
682
683    if ((buffer.length() > 0) &&
684         (buffer.charAt(buffer.length() - 1) != '('))
685    {
686      buffer.append(", ");
687    }
688
689    buffer.append(name);
690    buffer.append("='");
691    buffer.append(value);
692    buffer.append('\'');
693  }
694
695
696
697  /**
698   * Appends a name-value pair to the provided buffer, if the value is
699   * non-{@code null}.
700   *
701   * @param  buffer   The buffer to which the name-value pair should be
702   *                  appended.
703   * @param  name     The name to be used.  It must not be {@code null}.
704   * @param  values   The list of values to be used.  It may be {@code null} or
705   *                  empty if there are no values for the property.
706   */
707  private static void appendNameValuePair(@NotNull final StringBuilder buffer,
708                                          @NotNull final String name,
709                                          @Nullable final List<String> values)
710  {
711    if ((values == null) || values.isEmpty())
712    {
713      return;
714    }
715
716    if ((buffer.length() > 0) &&
717         (buffer.charAt(buffer.length() - 1) != '('))
718    {
719      buffer.append(", ");
720    }
721
722    buffer.append(name);
723    buffer.append("={ ");
724
725    final Iterator<String> iterator = values.iterator();
726    while (iterator.hasNext())
727    {
728      buffer.append('\'');
729      buffer.append(iterator.next());
730      buffer.append('\'');
731
732      if (iterator.hasNext())
733      {
734        buffer.append(", ");
735      }
736    }
737
738    buffer.append('}');
739  }
740}