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