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