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