001/*
002 * Copyright 2020-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2020-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) 2020-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 RemoveAttributeTypeTask}.
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 RemoveAttributeTypeTaskProperties
071       implements Serializable
072{
073  /**
074   * The serial version UID for this serializable class.
075   */
076  private static final long serialVersionUID = 8648887754165247809L;
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 attribute type 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 attribute to be removed from the schema.
117  @NotNull private String attributeType;
118
119  // The task ID to use for the remove attribute type task.
120  @Nullable private String taskID;
121
122
123
124  /**
125   * Creates a new set of remove attribute type task properties.  It will use
126   * default values for all general task properties.
127   *
128   * @param  attributeType  The name or OID of the attribute type to remove from
129   *                        the server schema.
130   */
131  public RemoveAttributeTypeTaskProperties(@NotNull final String attributeType)
132  {
133    this.attributeType = attributeType;
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 attribute type task properties as a copy of the
152   * provided properties.
153   *
154   * @param  properties  The remove attribute type task properties to duplicate.
155   */
156  public RemoveAttributeTypeTaskProperties(
157              @NotNull final RemoveAttributeTypeTaskProperties properties)
158  {
159    attributeType = properties.getAttributeType();
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 attribute type task properties set from the
177   * provided task instance.
178   *
179   * @param  task  The remove attribute type task instance from which the
180   *               properties should be set.
181   */
182  public RemoveAttributeTypeTaskProperties(
183              @NotNull final RemoveAttributeTypeTask task)
184  {
185    attributeType = task.getAttributeType();
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 attribute type to remove from the server
203   * schema.
204   *
205   * @return  The name or OID of the attribute type to remove from the server
206   *          schema.
207   */
208  @NotNull()
209  public String getAttributeType()
210  {
211    return attributeType;
212  }
213
214
215
216  /**
217   * Specifies the name or OID of the attribute type to remove from the server
218   * schema.
219   *
220   * @param  attributeType  The name or OID of the attribute type to remove from
221   *                        the server schema.
222   */
223  public void setAttributeType(@NotNull final String attributeType)
224  {
225    this.attributeType = attributeType;
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 attribute type task will be eligible to start running.
295   *
296   * @return  The task IDs for any tasks that must complete before the new
297   *          remove attribute type task will be eligible to start running, or
298   *          an empty list if the new task should not depend on any other
299   *          tasks.
300   */
301  @NotNull()
302  public List<String> getDependencyIDs()
303  {
304    return new ArrayList<>(dependencyIDs);
305  }
306
307
308
309  /**
310   * Specifies the task IDs for any tasks that must complete before the new
311   * remove attribute type task will be eligible to start running.
312   *
313   * @param  dependencyIDs  The task IDs for any tasks that must complete before
314   *                        the new remove attribute type task will be eligible
315   *                        to start running.  It may be {@code null} or empty
316   *                        if the new task should not depend on any other
317   *                        tasks.
318   */
319  public void setDependencyIDs(@Nullable final List<String> dependencyIDs)
320  {
321    this.dependencyIDs.clear();
322    if (dependencyIDs != null)
323    {
324      this.dependencyIDs.addAll(dependencyIDs);
325    }
326  }
327
328
329
330  /**
331   * Retrieves the action that the server should take if any of the tasks on
332   * which the new task depends did not complete successfully.
333   *
334   * @return  The action that the server should take if any of the tasks on
335   *          which the new task depends did not complete successfully, or
336   *          {@code null} if the property should not be specified when creating
337   *          the task (and the server should choose an appropriate failed
338   *          dependency action).
339   */
340  @Nullable()
341  public FailedDependencyAction getFailedDependencyAction()
342  {
343    return failedDependencyAction;
344  }
345
346
347
348  /**
349   * Specifies the action that the server should take if any of the tasks on
350   * which the new task depends did not complete successfully.
351   *
352   * @param  failedDependencyAction  The action that the server should take if
353   *                                 any of the tasks on which the new task
354   *                                 depends did not complete successfully.  It
355   *                                 may be {@code null} if the property should
356   *                                 not be specified when creating the task
357   *                                 (and the server should choose an
358   *                                 appropriate failed dependency action).
359   */
360  public void setFailedDependencyAction(
361       @Nullable final FailedDependencyAction failedDependencyAction)
362  {
363    this.failedDependencyAction = failedDependencyAction;
364  }
365
366
367
368  /**
369   * Retrieves the addresses to email whenever the task starts running.
370   *
371   * @return  The addresses to email whenever the task starts running, or an
372   *          empty list if no email notification should be sent when starting
373   *          the task.
374   */
375  @NotNull()
376  public List<String> getNotifyOnStart()
377  {
378    return new ArrayList<>(notifyOnStart);
379  }
380
381
382
383  /**
384   * Specifies the addresses to email whenever the task starts running.
385   *
386   * @param  notifyOnStart  The addresses to email whenever the task starts
387   *                        running.  It amy be {@code null} or empty if no
388   *                        email notification should be sent when starting the
389   *                        task.
390   */
391  public void setNotifyOnStart(@Nullable final List<String> notifyOnStart)
392  {
393    this.notifyOnStart.clear();
394    if (notifyOnStart != null)
395    {
396      this.notifyOnStart.addAll(notifyOnStart);
397    }
398  }
399
400
401
402  /**
403   * Retrieves the addresses to email whenever the task completes, regardless of
404   * its success or failure.
405   *
406   * @return  The addresses to email whenever the task completes, or an
407   *          empty list if no email notification should be sent when the task
408   *          completes.
409   */
410  @NotNull()
411  public List<String> getNotifyOnCompletion()
412  {
413    return new ArrayList<>(notifyOnCompletion);
414  }
415
416
417
418  /**
419   * Specifies the addresses to email whenever the task completes, regardless of
420   * its success or failure.
421   *
422   * @param  notifyOnCompletion  The addresses to email whenever the task
423   *                             completes.  It amy be {@code null} or empty if
424   *                             no email notification should be sent when the
425   *                             task completes.
426   */
427  public void setNotifyOnCompletion(
428                   @Nullable final List<String> notifyOnCompletion)
429  {
430    this.notifyOnCompletion.clear();
431    if (notifyOnCompletion != null)
432    {
433      this.notifyOnCompletion.addAll(notifyOnCompletion);
434    }
435  }
436
437
438
439  /**
440   * Retrieves the addresses to email if the task completes successfully.
441   *
442   * @return  The addresses to email if the task completes successfully, or an
443   *          empty list if no email notification should be sent on successful
444   *          completion.
445   */
446  @NotNull()
447  public List<String> getNotifyOnSuccess()
448  {
449    return new ArrayList<>(notifyOnSuccess);
450  }
451
452
453
454  /**
455   * Specifies the addresses to email if the task completes successfully.
456   *
457   * @param  notifyOnSuccess  The addresses to email if the task completes
458   *                          successfully.  It amy be {@code null} or empty if
459   *                          no email notification should be sent on
460   *                          successful completion.
461   */
462  public void setNotifyOnSuccess(@Nullable final List<String> notifyOnSuccess)
463  {
464    this.notifyOnSuccess.clear();
465    if (notifyOnSuccess != null)
466    {
467      this.notifyOnSuccess.addAll(notifyOnSuccess);
468    }
469  }
470
471
472
473  /**
474   * Retrieves the addresses to email if the task does not complete
475   * successfully.
476   *
477   * @return  The addresses to email if the task does not complete successfully,
478   *          or an empty list if no email notification should be sent on an
479   *          unsuccessful completion.
480   */
481  @NotNull()
482  public List<String> getNotifyOnError()
483  {
484    return new ArrayList<>(notifyOnError);
485  }
486
487
488
489  /**
490   * Specifies the addresses to email if the task does not complete
491   * successfully.
492   *
493   * @param  notifyOnError  The addresses to email if the task does not complete
494   *                        successfully.  It amy be {@code null} or empty if
495   *                        no email notification should be sent on an
496   *                        unsuccessful completion.
497   */
498  public void setNotifyOnError(@Nullable final List<String> notifyOnError)
499  {
500    this.notifyOnError.clear();
501    if (notifyOnError != null)
502    {
503      this.notifyOnError.addAll(notifyOnError);
504    }
505  }
506
507
508
509  /**
510   * Retrieves the flag that indicates whether the server should send an
511   * administrative alert notification when the task starts running.
512   *
513   * @return  The flag that indicates whether the server should send an
514   *          administrative alert notification when the task starts running,
515   *          or {@code null} if the property should not be specified when the
516   *          task is created (and the server will default to not sending any
517   *          alert).
518   */
519  @Nullable()
520  public Boolean getAlertOnStart()
521  {
522    return alertOnStart;
523  }
524
525
526
527  /**
528   * Specifies the flag that indicates whether the server should send an
529   * administrative alert notification when the task starts running.
530   *
531   * @param  alertOnStart  The flag that indicates whether the server should
532   *                       send an administrative alert notification when the
533   *                       task starts running,  It may be {@code null} if the
534   *                       property should not be specified when the task is
535   *                       created (and the server will default to not sending
536   *                       any alert).
537   */
538  public void setAlertOnStart(@Nullable final Boolean alertOnStart)
539  {
540    this.alertOnStart = alertOnStart;
541  }
542
543
544
545  /**
546   * Retrieves the flag that indicates whether the server should send an
547   * administrative alert notification if the task completes successfully.
548   *
549   * @return  The flag that indicates whether the server should send an
550   *          administrative alert notification if the task completes
551   *          successfully, or {@code null} if the property should not be
552   *          specified when the task is created (and the server will default to
553   *          not sending any alert).
554   */
555  @Nullable()
556  public Boolean getAlertOnSuccess()
557  {
558    return alertOnSuccess;
559  }
560
561
562
563  /**
564   * Specifies the flag that indicates whether the server should send an
565   * administrative alert notification if the task completes successfully.
566   *
567   * @param  alertOnSuccess  The flag that indicates whether the server should
568   *                         send an administrative alert notification if the
569   *                         task completes successfully,  It may be
570   *                         {@code null} if the property should not be
571   *                         specified when the task is created (and the server
572   *                         will default to not sending any alert).
573   */
574  public void setAlertOnSuccess(@Nullable final Boolean alertOnSuccess)
575  {
576    this.alertOnSuccess = alertOnSuccess;
577  }
578
579
580
581  /**
582   * Retrieves the flag that indicates whether the server should send an
583   * administrative alert notification if the task does not complete
584   * successfully.
585   *
586   * @return  The flag that indicates whether the server should send an
587   *          administrative alert notification if the task does not complete
588   *          successfully, or {@code null} if the property should not be
589   *          specified when the task is created (and the server will default to
590   *          not sending any alert).
591   */
592  @Nullable()
593  public Boolean getAlertOnError()
594  {
595    return alertOnError;
596  }
597
598
599
600  /**
601   * Specifies the flag that indicates whether the server should send an
602   * administrative alert notification if the task does not complete
603   * successfully.
604   *
605   * @param  alertOnError  The flag that indicates whether the server should
606   *                       send an administrative alert notification if the task
607   *                       does not complete successfully,  It may be
608   *                       {@code null} if the property should not be specified
609   *                       when the task is created (and the server will default
610   *                       to not sending any alert).
611   */
612  public void setAlertOnError(@Nullable final Boolean alertOnError)
613  {
614    this.alertOnError = alertOnError;
615  }
616
617
618
619  /**
620   * Retrieves a string representation of this remove attribute type task
621   * properties object.
622   *
623   * @return  A string representation of this remove attribute type task
624   *          properties object.
625   */
626  @Override()
627  @NotNull()
628  public String toString()
629  {
630    final StringBuilder buffer = new StringBuilder();
631    toString(buffer);
632    return buffer.toString();
633  }
634
635
636
637  /**
638   * Appends a string representation of this remove attribute type task
639   * properties object to the provided buffer.
640   *
641   * @param  buffer  The buffer to which the string representation will be
642   *                 appended.  It must not be {@code null}.
643   */
644  public void toString(@NotNull final StringBuilder buffer)
645  {
646    buffer.append("RemoveAttributeTypeProperties(");
647
648    appendNameValuePair(buffer, "taskID", taskID);
649    appendNameValuePair(buffer, "attributeType", attributeType);
650    appendNameValuePair(buffer, "scheduledStartTime", scheduledStartTime);
651    appendNameValuePair(buffer, "dependencyIDs", dependencyIDs);
652    appendNameValuePair(buffer, "failedDependencyAction",
653         failedDependencyAction);
654    appendNameValuePair(buffer, "notifyOnStart", notifyOnStart);
655    appendNameValuePair(buffer, "notifyOnCompletion", notifyOnCompletion);
656    appendNameValuePair(buffer, "notifyOnSuccess", notifyOnSuccess);
657    appendNameValuePair(buffer, "notifyOnError", notifyOnError);
658    appendNameValuePair(buffer, "alertOnStart", alertOnStart);
659    appendNameValuePair(buffer, "alertOnSuccess", alertOnSuccess);
660    appendNameValuePair(buffer, "alertOnError", alertOnError);
661
662    buffer.append(')');
663  }
664
665
666
667  /**
668   * Appends a name-value pair to the provided buffer, if the value is
669   * non-{@code null}.
670   *
671   * @param  buffer  The buffer to which the name-value pair should be appended.
672   * @param  name    The name to be used.  It must not be {@code null}.
673   * @param  value   The value to be used.  It may be {@code null} if there is
674   *                 no value for the property.
675   */
676  private static void appendNameValuePair(@NotNull final StringBuilder buffer,
677                                          @NotNull final String name,
678                                          @Nullable final Object value)
679  {
680    if (value == null)
681    {
682      return;
683    }
684
685    if ((buffer.length() > 0) &&
686         (buffer.charAt(buffer.length() - 1) != '('))
687    {
688      buffer.append(", ");
689    }
690
691    buffer.append(name);
692    buffer.append("='");
693    buffer.append(value);
694    buffer.append('\'');
695  }
696
697
698
699  /**
700   * Appends a name-value pair to the provided buffer, if the value is
701   * non-{@code null}.
702   *
703   * @param  buffer   The buffer to which the name-value pair should be
704   *                  appended.
705   * @param  name     The name to be used.  It must not be {@code null}.
706   * @param  values   The list of values to be used.  It may be {@code null} or
707   *                  empty if there are no values for the property.
708   */
709  private static void appendNameValuePair(@NotNull final StringBuilder buffer,
710                                          @NotNull final String name,
711                                          @Nullable final List<String> values)
712  {
713    if ((values == null) || values.isEmpty())
714    {
715      return;
716    }
717
718    if ((buffer.length() > 0) &&
719         (buffer.charAt(buffer.length() - 1) != '('))
720    {
721      buffer.append(", ");
722    }
723
724    buffer.append(name);
725    buffer.append("={ ");
726
727    final Iterator<String> iterator = values.iterator();
728    while (iterator.hasNext())
729    {
730      buffer.append('\'');
731      buffer.append(iterator.next());
732      buffer.append('\'');
733
734      if (iterator.hasNext())
735      {
736        buffer.append(", ");
737      }
738    }
739
740    buffer.append('}');
741  }
742}