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