001/*
002 * Copyright 2014-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2018 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 destination.
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.37 and a value with the
058 * following encoding:
059 * <BR><BR>
060 * <PRE>
061 *   DeleteNotificationDestinationRequest ::= SEQUENCE {
062 *        notificationManagerID         OCTET STRING,
063 *        notificationDestinationID     OCTET STRING }
064 * </PRE>
065 */
066@NotMutable()
067@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
068public final class DeleteNotificationDestinationExtendedRequest
069       extends ExtendedRequest
070{
071  /**
072   * The OID (1.3.6.1.4.1.30221.2.6.37) for the delete notification destination
073   * extended request.
074   */
075  public static final String DELETE_NOTIFICATION_DESTINATION_REQUEST_OID =
076       "1.3.6.1.4.1.30221.2.6.37";
077
078
079
080  /**
081   * The serial version UID for this serializable class.
082   */
083  private static final long serialVersionUID = -2644432176543980784L;
084
085
086
087  // The notification destination ID.
088  private final String destinationID;
089
090  // The notification manager ID.
091  private final String managerID;
092
093
094
095  /**
096   * Creates a new delete notification destination extended request with the
097   * provided information.
098   *
099   * @param  managerID         The notification manager ID.  It must not be
100   *                           {@code null}.
101   * @param  destinationID     The notification destination ID.  It must not be
102   *                           {@code null}.
103   * @param  controls          The set of controls to include in the request.
104   *                           It may be {@code null} or empty if no controls
105   *                           are needed.
106   */
107  public DeleteNotificationDestinationExtendedRequest(final String managerID,
108              final String destinationID, final Control... controls)
109  {
110    super(DELETE_NOTIFICATION_DESTINATION_REQUEST_OID,
111         encodeValue(managerID, destinationID), controls);
112
113    this.managerID = managerID;
114    this.destinationID = destinationID;
115  }
116
117
118
119  /**
120   * Creates a new delete notification destination extended request from the
121   * provided generic extended request.
122   *
123   * @param  extendedRequest  The generic extended request to use to create this
124   *                          delete notification destination extended request.
125   *
126   * @throws  LDAPException  If a problem occurs while decoding the request.
127   */
128  public DeleteNotificationDestinationExtendedRequest(
129              final ExtendedRequest extendedRequest)
130         throws LDAPException
131  {
132    super(extendedRequest);
133
134    final ASN1OctetString value = extendedRequest.getValue();
135    if (value == null)
136    {
137      throw new LDAPException(ResultCode.DECODING_ERROR,
138           ERR_DEL_NOTIFICATION_DEST_REQ_DECODE_NO_VALUE.get());
139    }
140
141    try
142    {
143      final ASN1Element[] elements =
144           ASN1Sequence.decodeAsSequence(value.getValue()).elements();
145      managerID =
146           ASN1OctetString.decodeAsOctetString(elements[0]).stringValue();
147      destinationID =
148           ASN1OctetString.decodeAsOctetString(elements[1]).stringValue();
149    }
150    catch (final Exception e)
151    {
152      Debug.debugException(e);
153      throw new LDAPException(ResultCode.DECODING_ERROR,
154           ERR_DEL_NOTIFICATION_DEST_REQ_ERROR_DECODING_VALUE.get(
155                StaticUtils.getExceptionMessage(e)),
156           e);
157    }
158  }
159
160
161
162  /**
163   * Encodes the provided information into an ASN.1 octet string suitable for
164   * use as the value of this extended request.
165   *
166   * @param  managerID         The notification manager ID.  It must not be
167   *                           {@code null}.
168   * @param  destinationID     The notification destination ID.  It must not be
169   *                           {@code null}.
170   *
171   * @return  The ASN.1 octet string containing the encoded value.
172   */
173  private static ASN1OctetString encodeValue(final String managerID,
174                      final String destinationID)
175  {
176    Validator.ensureNotNull(managerID);
177    Validator.ensureNotNull(destinationID);
178
179    final ASN1Sequence valueSequence = new ASN1Sequence(
180         new ASN1OctetString(managerID),
181         new ASN1OctetString(destinationID));
182    return new ASN1OctetString(valueSequence.encode());
183  }
184
185
186
187  /**
188   * Retrieves the notification manager ID.
189   *
190   * @return  The notification manager ID.
191   */
192  public String getManagerID()
193  {
194    return managerID;
195  }
196
197
198
199  /**
200   * Retrieves the notification destination ID.
201   *
202   * @return  The notification destination ID.
203   */
204  public String getDestinationID()
205  {
206    return destinationID;
207  }
208
209
210
211  /**
212   * {@inheritDoc}
213   */
214  @Override()
215  public DeleteNotificationDestinationExtendedRequest duplicate()
216  {
217    return duplicate(getControls());
218  }
219
220
221
222  /**
223   * {@inheritDoc}
224   */
225  @Override()
226  public DeleteNotificationDestinationExtendedRequest
227              duplicate(final Control[] controls)
228  {
229    final DeleteNotificationDestinationExtendedRequest r =
230         new DeleteNotificationDestinationExtendedRequest(managerID,
231              destinationID, controls);
232    r.setResponseTimeoutMillis(getResponseTimeoutMillis(null));
233    return r;
234  }
235
236
237
238  /**
239   * {@inheritDoc}
240   */
241  @Override()
242  public String getExtendedRequestName()
243  {
244    return INFO_EXTENDED_REQUEST_NAME_DEL_NOTIFICATION_DEST.get();
245  }
246
247
248
249  /**
250   * {@inheritDoc}
251   */
252  @Override()
253  public void toString(final StringBuilder buffer)
254  {
255    buffer.append("DeleteNotificationDestinationExtendedRequest(managerID='");
256    buffer.append(managerID);
257    buffer.append("', destinationID='");
258    buffer.append(destinationID);
259    buffer.append('\'');
260
261    final Control[] controls = getControls();
262    if (controls.length > 0)
263    {
264      buffer.append(", controls={");
265      for (int i=0; i < controls.length; i++)
266      {
267        if (i > 0)
268        {
269          buffer.append(", ");
270        }
271
272        buffer.append(controls[i]);
273      }
274      buffer.append('}');
275    }
276
277    buffer.append(')');
278  }
279}