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