001/*
002 * Copyright 2014-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2014-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) 2014-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.extensions;
037
038
039
040import java.io.Serializable;
041import java.util.ArrayList;
042import java.util.Collection;
043import java.util.Collections;
044import java.util.Iterator;
045import java.util.List;
046
047import com.unboundid.asn1.ASN1OctetString;
048import com.unboundid.util.NotMutable;
049import com.unboundid.util.NotNull;
050import com.unboundid.util.Nullable;
051import com.unboundid.util.ThreadSafety;
052import com.unboundid.util.ThreadSafetyLevel;
053import com.unboundid.util.Validator;
054
055
056
057/**
058 * This class represents a data structure with information about a notification
059 * destination defined in a Ping Identity, UnboundID, or Nokia/Alcatel-Lucent
060 * 8661 server instance.
061 * <BR>
062 * <BLOCKQUOTE>
063 *   <B>NOTE:</B>  This class, and other classes within the
064 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
065 *   supported for use against Ping Identity, UnboundID, and
066 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
067 *   for proprietary functionality or for external specifications that are not
068 *   considered stable or mature enough to be guaranteed to work in an
069 *   interoperable way with other types of LDAP servers.
070 * </BLOCKQUOTE>
071 */
072@NotMutable()
073@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
074public final class NotificationDestinationDetails
075       implements Serializable
076{
077  /**
078   * The serial version UID for this serializable class.
079   */
080  private static final long serialVersionUID = -6596207374277234834L;
081
082
083
084  // The encoded details for this notification destination.
085  @NotNull private final List<ASN1OctetString> details;
086
087  // The subscriptions defined for this notification destination.
088  @NotNull private final List<NotificationSubscriptionDetails> subscriptions;
089
090  // The unique ID for this notification destination.
091  @NotNull private final String id;
092
093
094
095  /**
096   * Creates a new notification destination details object with the provided
097   * information.
098   *
099   * @param  id             The unique ID for this notification destination.  It
100   *                        must not be {@code null}.
101   * @param  details        The encoded details for this notification
102   *                        destination.  It must not be {@code null} or empty.
103   * @param  subscriptions  The subscriptions defined for this notification
104   *                        destination.  It may be {@code null} or empty if
105   *                        there are no subscriptions for this destination.
106   */
107  public NotificationDestinationDetails(@NotNull final String id,
108       @NotNull final Collection<ASN1OctetString> details,
109       @Nullable final Collection<NotificationSubscriptionDetails>
110            subscriptions)
111  {
112    Validator.ensureNotNull(id);
113    Validator.ensureNotNull(details);
114    Validator.ensureFalse(details.isEmpty());
115
116    this.id = id;
117    this.details =
118         Collections.unmodifiableList(new ArrayList<>(details));
119
120    if (subscriptions == null)
121    {
122      this.subscriptions = Collections.emptyList();
123    }
124    else
125    {
126      this.subscriptions =
127           Collections.unmodifiableList(new ArrayList<>(subscriptions));
128    }
129  }
130
131
132
133  /**
134   * Retrieves the unique ID for this destination details object.
135   *
136   * @return The unique ID for this destination details object.
137   */
138  @NotNull()
139  public String getID()
140  {
141    return id;
142  }
143
144
145
146  /**
147   * Retrieves the encoded details for this destination details object.
148   *
149   * @return  The encoded details for this destination details object.
150   */
151  @NotNull()
152  public List<ASN1OctetString> getDetails()
153  {
154    return details;
155  }
156
157
158
159  /**
160   * Retrieves the subscriptions defined for this notification destination, if
161   * any.
162   *
163   * @return  The subscriptions defined for this notification destination, or
164   *          an empty list if there are no subscriptions for this destination.
165   */
166  @NotNull()
167  public List<NotificationSubscriptionDetails> getSubscriptions()
168  {
169    return subscriptions;
170  }
171
172
173
174  /**
175   * Retrieves a string representation of this notification subscription details
176   * object.
177   *
178   * @return  A string representation of this notification subscription details
179   *          object.
180   */
181  @Override()
182  @NotNull()
183  public String toString()
184  {
185    final StringBuilder buffer = new StringBuilder();
186    toString(buffer);
187    return buffer.toString();
188  }
189
190
191
192  /**
193   * Appends a string representation of this notification subscription details
194   * object to the provided buffer.
195   *
196   * @param  buffer  The buffer to which the information should be appended.
197   */
198  public void toString(@NotNull final StringBuilder buffer)
199  {
200    buffer.append("NotificationDestination(id='");
201    buffer.append(id);
202    buffer.append("', subscriptionIDs={");
203
204    final Iterator<NotificationSubscriptionDetails> subscriptionIterator =
205         subscriptions.iterator();
206    while (subscriptionIterator.hasNext())
207    {
208      buffer.append('\'');
209      buffer.append(subscriptionIterator.next().getID());
210      buffer.append('\'');
211
212      if (subscriptionIterator.hasNext())
213      {
214        buffer.append(", ");
215      }
216    }
217
218    buffer.append("})");
219  }
220}