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