001/*
002 * Copyright 2014-2022 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2014-2022 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-2022 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 com.unboundid.asn1.ASN1Element;
041import com.unboundid.asn1.ASN1OctetString;
042import com.unboundid.asn1.ASN1Sequence;
043import com.unboundid.ldap.sdk.Control;
044import com.unboundid.ldap.sdk.ExtendedRequest;
045import com.unboundid.ldap.sdk.LDAPException;
046import com.unboundid.ldap.sdk.ResultCode;
047import com.unboundid.util.Debug;
048import com.unboundid.util.NotMutable;
049import com.unboundid.util.NotNull;
050import com.unboundid.util.Nullable;
051import com.unboundid.util.StaticUtils;
052import com.unboundid.util.ThreadSafety;
053import com.unboundid.util.ThreadSafetyLevel;
054import com.unboundid.util.Validator;
055
056import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*;
057
058
059
060/**
061 * This class provides an extended request that may be used to delete a
062 * notification subscription.
063 * <BR>
064 * <BLOCKQUOTE>
065 *   <B>NOTE:</B>  This class, and other classes within the
066 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
067 *   supported for use against Ping Identity, UnboundID, and
068 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
069 *   for proprietary functionality or for external specifications that are not
070 *   considered stable or mature enough to be guaranteed to work in an
071 *   interoperable way with other types of LDAP servers.
072 * </BLOCKQUOTE>
073 * <BR>
074 * The request has an OID of 1.3.6.1.4.1.30221.2.6.39 and a value with the
075 * following encoding:
076 * <BR><BR>
077 * <PRE>
078 *   DeleteNotificationSubscriptionRequest ::= SEQUENCE {
079 *        notificationManagerID          OCTET STRING,
080 *        notificationDestinationID      OCTET STRING,
081 *        notificationSubscriptionID     OCTET STRING }
082 * </PRE>
083 */
084@NotMutable()
085@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
086public final class DeleteNotificationSubscriptionExtendedRequest
087       extends ExtendedRequest
088{
089  /**
090   * The OID (1.3.6.1.4.1.30221.2.6.39) for the delete notification subscription
091   * extended request.
092   */
093  @NotNull public static final String
094       DELETE_NOTIFICATION_SUBSCRIPTION_REQUEST_OID =
095            "1.3.6.1.4.1.30221.2.6.39";
096
097
098
099  /**
100   * The serial version UID for this serializable class.
101   */
102  private static final long serialVersionUID = 914822438877247L;
103
104
105
106  // The notification destination ID.
107  @NotNull private final String destinationID;
108
109  // The notification manager ID.
110  @NotNull private final String managerID;
111
112  // The notification subscription ID.
113  @NotNull private final String subscriptionID;
114
115
116
117  /**
118   * Creates a new delete notification subscription extended request with the
119   * provided information.
120   *
121   * @param  managerID          The notification manager ID.  It must not be
122   *                            {@code null}.
123   * @param  destinationID      The notification destination ID.  It must not be
124   *                            {@code null}.
125   * @param  subscriptionID     The notification destination ID.  It must not be
126   *                            {@code null}.
127   * @param  controls           The set of controls to include in the request.
128   *                            It may be {@code null} or empty if no controls
129   *                            are needed.
130   */
131  public DeleteNotificationSubscriptionExtendedRequest(
132              @NotNull final String managerID,
133              @NotNull final String destinationID,
134              @NotNull final String subscriptionID,
135              @Nullable final Control... controls)
136  {
137    super(DELETE_NOTIFICATION_SUBSCRIPTION_REQUEST_OID,
138         encodeValue(managerID, destinationID, subscriptionID), controls);
139
140    this.managerID = managerID;
141    this.destinationID = destinationID;
142    this.subscriptionID = subscriptionID;
143  }
144
145
146
147  /**
148   * Creates a new delete notification subscription extended request from the
149   * provided generic extended request.
150   *
151   * @param  extendedRequest  The generic extended request to use to create this
152   *                          delete notification destination extended request.
153   *
154   * @throws  LDAPException  If a problem occurs while decoding the request.
155   */
156  public DeleteNotificationSubscriptionExtendedRequest(
157              @NotNull final ExtendedRequest extendedRequest)
158         throws LDAPException
159  {
160    super(extendedRequest);
161
162    final ASN1OctetString value = extendedRequest.getValue();
163    if (value == null)
164    {
165      throw new LDAPException(ResultCode.DECODING_ERROR,
166           ERR_DEL_NOTIFICATION_SUB_REQ_DECODE_NO_VALUE.get());
167    }
168
169    try
170    {
171      final ASN1Element[] elements =
172           ASN1Sequence.decodeAsSequence(value.getValue()).elements();
173      managerID =
174           ASN1OctetString.decodeAsOctetString(elements[0]).stringValue();
175      destinationID =
176           ASN1OctetString.decodeAsOctetString(elements[1]).stringValue();
177      subscriptionID =
178           ASN1OctetString.decodeAsOctetString(elements[2]).stringValue();
179    }
180    catch (final Exception e)
181    {
182      Debug.debugException(e);
183      throw new LDAPException(ResultCode.DECODING_ERROR,
184           ERR_DEL_NOTIFICATION_SUB_REQ_ERROR_DECODING_VALUE.get(
185                StaticUtils.getExceptionMessage(e)),
186           e);
187    }
188  }
189
190
191
192  /**
193   * Encodes the provided information into an ASN.1 octet string suitable for
194   * use as the value of this extended request.
195   *
196   * @param  managerID          The notification manager ID.  It must not be
197   *                            {@code null}.
198   * @param  destinationID      The notification destination ID.  It must not be
199   *                            {@code null}.
200   * @param  subscriptionID     The notification destination ID.  It must not be
201   *                            {@code null}.
202   *
203   * @return  The ASN.1 octet string containing the encoded value.
204   */
205  @NotNull()
206  private static ASN1OctetString encodeValue(@NotNull final String managerID,
207                      @NotNull final String destinationID,
208                      @NotNull final String subscriptionID)
209  {
210    Validator.ensureNotNull(managerID);
211    Validator.ensureNotNull(destinationID);
212    Validator.ensureNotNull(subscriptionID);
213
214    final ASN1Sequence valueSequence = new ASN1Sequence(
215         new ASN1OctetString(managerID),
216         new ASN1OctetString(destinationID),
217         new ASN1OctetString(subscriptionID));
218    return new ASN1OctetString(valueSequence.encode());
219  }
220
221
222
223  /**
224   * Retrieves the notification manager ID.
225   *
226   * @return  The notification manager ID.
227   */
228  @NotNull()
229  public String getManagerID()
230  {
231    return managerID;
232  }
233
234
235
236  /**
237   * Retrieves the notification destination ID.
238   *
239   * @return  The notification destination ID.
240   */
241  @NotNull()
242  public String getDestinationID()
243  {
244    return destinationID;
245  }
246
247
248
249  /**
250   * Retrieves the notification subscription ID.
251   *
252   * @return  The notification subscription ID.
253   */
254  @NotNull()
255  public String getSubscriptionID()
256  {
257    return subscriptionID;
258  }
259
260
261
262  /**
263   * {@inheritDoc}
264   */
265  @Override()
266  @NotNull()
267  public DeleteNotificationSubscriptionExtendedRequest duplicate()
268  {
269    return duplicate(getControls());
270  }
271
272
273
274  /**
275   * {@inheritDoc}
276   */
277  @Override()
278  @NotNull()
279  public DeleteNotificationSubscriptionExtendedRequest duplicate(
280              @Nullable final Control[] controls)
281  {
282    final DeleteNotificationSubscriptionExtendedRequest r =
283         new DeleteNotificationSubscriptionExtendedRequest(managerID,
284              destinationID, subscriptionID, controls);
285    r.setResponseTimeoutMillis(getResponseTimeoutMillis(null));
286    return r;
287  }
288
289
290
291  /**
292   * {@inheritDoc}
293   */
294  @Override()
295  @NotNull()
296  public String getExtendedRequestName()
297  {
298    return INFO_EXTENDED_REQUEST_NAME_DEL_NOTIFICATION_SUB.get();
299  }
300
301
302
303  /**
304   * {@inheritDoc}
305   */
306  @Override()
307  public void toString(@NotNull final StringBuilder buffer)
308  {
309    buffer.append("DeleteNotificationSubscriptionExtendedRequest(managerID='");
310    buffer.append(managerID);
311    buffer.append("', destinationID='");
312    buffer.append(destinationID);
313    buffer.append("', subscriptionID='");
314    buffer.append(subscriptionID);
315    buffer.append('\'');
316
317    final Control[] controls = getControls();
318    if (controls.length > 0)
319    {
320      buffer.append(", controls={");
321      for (int i=0; i < controls.length; i++)
322      {
323        if (i > 0)
324        {
325          buffer.append(", ");
326        }
327
328        buffer.append(controls[i]);
329      }
330      buffer.append('}');
331    }
332
333    buffer.append(')');
334  }
335}