001/*
002 * Copyright 2014-2019 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2019 Ping Identity Corporation
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021package com.unboundid.ldap.sdk.unboundidds.extensions;
022
023
024
025import com.unboundid.asn1.ASN1Element;
026import com.unboundid.asn1.ASN1OctetString;
027import com.unboundid.asn1.ASN1Sequence;
028import com.unboundid.ldap.sdk.Control;
029import com.unboundid.ldap.sdk.ExtendedRequest;
030import com.unboundid.ldap.sdk.LDAPException;
031import com.unboundid.ldap.sdk.ResultCode;
032import com.unboundid.util.Debug;
033import com.unboundid.util.NotMutable;
034import com.unboundid.util.StaticUtils;
035import com.unboundid.util.ThreadSafety;
036import com.unboundid.util.ThreadSafetyLevel;
037import com.unboundid.util.Validator;
038
039import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*;
040
041
042
043/**
044 * This class provides an extended request that may be used to delete a
045 * notification subscription.
046 * <BR>
047 * <BLOCKQUOTE>
048 *   <B>NOTE:</B>  This class, and other classes within the
049 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
050 *   supported for use against Ping Identity, UnboundID, and
051 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
052 *   for proprietary functionality or for external specifications that are not
053 *   considered stable or mature enough to be guaranteed to work in an
054 *   interoperable way with other types of LDAP servers.
055 * </BLOCKQUOTE>
056 * <BR>
057 * The request has an OID of 1.3.6.1.4.1.30221.2.6.39 and a value with the
058 * following encoding:
059 * <BR><BR>
060 * <PRE>
061 *   DeleteNotificationSubscriptionRequest ::= SEQUENCE {
062 *        notificationManagerID          OCTET STRING,
063 *        notificationDestinationID      OCTET STRING,
064 *        notificationSubscriptionID     OCTET STRING }
065 * </PRE>
066 */
067@NotMutable()
068@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
069public final class DeleteNotificationSubscriptionExtendedRequest
070       extends ExtendedRequest
071{
072  /**
073   * The OID (1.3.6.1.4.1.30221.2.6.39) for the delete notification subscription
074   * extended request.
075   */
076  public static final String DELETE_NOTIFICATION_SUBSCRIPTION_REQUEST_OID =
077       "1.3.6.1.4.1.30221.2.6.39";
078
079
080
081  /**
082   * The serial version UID for this serializable class.
083   */
084  private static final long serialVersionUID = 914822438877247L;
085
086
087
088  // The notification destination ID.
089  private final String destinationID;
090
091  // The notification manager ID.
092  private final String managerID;
093
094  // The notification subscription ID.
095  private final String subscriptionID;
096
097
098
099  /**
100   * Creates a new delete notification subscription extended request with the
101   * provided information.
102   *
103   * @param  managerID          The notification manager ID.  It must not be
104   *                            {@code null}.
105   * @param  destinationID      The notification destination ID.  It must not be
106   *                            {@code null}.
107   * @param  subscriptionID     The notification destination ID.  It must not be
108   *                            {@code null}.
109   * @param  controls           The set of controls to include in the request.
110   *                            It may be {@code null} or empty if no controls
111   *                            are needed.
112   */
113  public DeleteNotificationSubscriptionExtendedRequest(final String managerID,
114              final String destinationID, final String subscriptionID,
115              final Control... controls)
116  {
117    super(DELETE_NOTIFICATION_SUBSCRIPTION_REQUEST_OID,
118         encodeValue(managerID, destinationID, subscriptionID), controls);
119
120    this.managerID = managerID;
121    this.destinationID = destinationID;
122    this.subscriptionID = subscriptionID;
123  }
124
125
126
127  /**
128   * Creates a new delete notification subscription extended request from the
129   * provided generic extended request.
130   *
131   * @param  extendedRequest  The generic extended request to use to create this
132   *                          delete notification destination extended request.
133   *
134   * @throws  LDAPException  If a problem occurs while decoding the request.
135   */
136  public DeleteNotificationSubscriptionExtendedRequest(
137              final ExtendedRequest extendedRequest)
138         throws LDAPException
139  {
140    super(extendedRequest);
141
142    final ASN1OctetString value = extendedRequest.getValue();
143    if (value == null)
144    {
145      throw new LDAPException(ResultCode.DECODING_ERROR,
146           ERR_DEL_NOTIFICATION_SUB_REQ_DECODE_NO_VALUE.get());
147    }
148
149    try
150    {
151      final ASN1Element[] elements =
152           ASN1Sequence.decodeAsSequence(value.getValue()).elements();
153      managerID =
154           ASN1OctetString.decodeAsOctetString(elements[0]).stringValue();
155      destinationID =
156           ASN1OctetString.decodeAsOctetString(elements[1]).stringValue();
157      subscriptionID =
158           ASN1OctetString.decodeAsOctetString(elements[2]).stringValue();
159    }
160    catch (final Exception e)
161    {
162      Debug.debugException(e);
163      throw new LDAPException(ResultCode.DECODING_ERROR,
164           ERR_DEL_NOTIFICATION_SUB_REQ_ERROR_DECODING_VALUE.get(
165                StaticUtils.getExceptionMessage(e)),
166           e);
167    }
168  }
169
170
171
172  /**
173   * Encodes the provided information into an ASN.1 octet string suitable for
174   * use as the value of this extended request.
175   *
176   * @param  managerID          The notification manager ID.  It must not be
177   *                            {@code null}.
178   * @param  destinationID      The notification destination ID.  It must not be
179   *                            {@code null}.
180   * @param  subscriptionID     The notification destination ID.  It must not be
181   *                            {@code null}.
182   *
183   * @return  The ASN.1 octet string containing the encoded value.
184   */
185  private static ASN1OctetString encodeValue(final String managerID,
186                      final String destinationID, final String subscriptionID)
187  {
188    Validator.ensureNotNull(managerID);
189    Validator.ensureNotNull(destinationID);
190    Validator.ensureNotNull(subscriptionID);
191
192    final ASN1Sequence valueSequence = new ASN1Sequence(
193         new ASN1OctetString(managerID),
194         new ASN1OctetString(destinationID),
195         new ASN1OctetString(subscriptionID));
196    return new ASN1OctetString(valueSequence.encode());
197  }
198
199
200
201  /**
202   * Retrieves the notification manager ID.
203   *
204   * @return  The notification manager ID.
205   */
206  public String getManagerID()
207  {
208    return managerID;
209  }
210
211
212
213  /**
214   * Retrieves the notification destination ID.
215   *
216   * @return  The notification destination ID.
217   */
218  public String getDestinationID()
219  {
220    return destinationID;
221  }
222
223
224
225  /**
226   * Retrieves the notification subscription ID.
227   *
228   * @return  The notification subscription ID.
229   */
230  public String getSubscriptionID()
231  {
232    return subscriptionID;
233  }
234
235
236
237  /**
238   * {@inheritDoc}
239   */
240  @Override()
241  public DeleteNotificationSubscriptionExtendedRequest duplicate()
242  {
243    return duplicate(getControls());
244  }
245
246
247
248  /**
249   * {@inheritDoc}
250   */
251  @Override()
252  public DeleteNotificationSubscriptionExtendedRequest
253              duplicate(final Control[] controls)
254  {
255    final DeleteNotificationSubscriptionExtendedRequest r =
256         new DeleteNotificationSubscriptionExtendedRequest(managerID,
257              destinationID, subscriptionID, controls);
258    r.setResponseTimeoutMillis(getResponseTimeoutMillis(null));
259    return r;
260  }
261
262
263
264  /**
265   * {@inheritDoc}
266   */
267  @Override()
268  public String getExtendedRequestName()
269  {
270    return INFO_EXTENDED_REQUEST_NAME_DEL_NOTIFICATION_SUB.get();
271  }
272
273
274
275  /**
276   * {@inheritDoc}
277   */
278  @Override()
279  public void toString(final StringBuilder buffer)
280  {
281    buffer.append("DeleteNotificationSubscriptionExtendedRequest(managerID='");
282    buffer.append(managerID);
283    buffer.append("', destinationID='");
284    buffer.append(destinationID);
285    buffer.append("', subscriptionID='");
286    buffer.append(subscriptionID);
287    buffer.append('\'');
288
289    final Control[] controls = getControls();
290    if (controls.length > 0)
291    {
292      buffer.append(", controls={");
293      for (int i=0; i < controls.length; i++)
294      {
295        if (i > 0)
296        {
297          buffer.append(", ");
298        }
299
300        buffer.append(controls[i]);
301      }
302      buffer.append('}');
303    }
304
305    buffer.append(')');
306  }
307}