001/* 002 * Copyright 2012-2022 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2012-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) 2012-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.controls; 037 038 039 040import com.unboundid.asn1.ASN1OctetString; 041import com.unboundid.ldap.sdk.Control; 042import com.unboundid.ldap.sdk.DecodeableControl; 043import com.unboundid.ldap.sdk.DN; 044import com.unboundid.ldap.sdk.LDAPException; 045import com.unboundid.ldap.sdk.LDAPResult; 046import com.unboundid.ldap.sdk.ResultCode; 047import com.unboundid.util.NotMutable; 048import com.unboundid.util.NotNull; 049import com.unboundid.util.Nullable; 050import com.unboundid.util.ThreadSafety; 051import com.unboundid.util.ThreadSafetyLevel; 052import com.unboundid.util.Validator; 053 054import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*; 055 056 057 058/** 059 * This class provides a response control that holds information about the 060 * soft-deleted entry that results from a soft delete request, and may also be 061 * included in a search result entry which represents a soft-deleted entry. The 062 * value of this control will be the DN of the soft-deleted entry. 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 * This control has an OID of 1.3.6.1.4.1.30221.2.5.21, a criticality of false, 075 * and a value that is simply the string representation of the new DN for the 076 * soft-deleted entry. 077 * <BR><BR> 078 * See the documentation for the {@link SoftDeleteRequestControl} class for an 079 * example demonstrating the use of this control. 080 * 081 * @see SoftDeleteRequestControl 082 */ 083@NotMutable() 084@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 085public final class SoftDeleteResponseControl 086 extends Control 087 implements DecodeableControl 088{ 089 /** 090 * The OID (1.3.6.1.4.1.30221.2.5.21) for the soft delete response control. 091 */ 092 @NotNull public static final String SOFT_DELETE_RESPONSE_OID = 093 "1.3.6.1.4.1.30221.2.5.21"; 094 095 096 097 /** 098 * The serial version UID for this serializable class. 099 */ 100 private static final long serialVersionUID = 3163679387266190228L; 101 102 103 104 // The DN of the soft-deleted representation of the target entry. 105 @NotNull private final String softDeletedEntryDN; 106 107 108 109 /** 110 * Creates a new empty control instance that is intended to be used only for 111 * decoding controls via the {@code DecodeableControl} interface. 112 */ 113 SoftDeleteResponseControl() 114 { 115 softDeletedEntryDN = null; 116 } 117 118 119 120 /** 121 * Creates a new soft delete response control with the provided information. 122 * 123 * @param softDeletedEntryDN The DN of the soft-deleted representation of 124 * the target entry. 125 */ 126 public SoftDeleteResponseControl(@NotNull final String softDeletedEntryDN) 127 { 128 super(SOFT_DELETE_RESPONSE_OID, false, 129 new ASN1OctetString(softDeletedEntryDN)); 130 131 Validator.ensureNotNull(softDeletedEntryDN); 132 133 this.softDeletedEntryDN = softDeletedEntryDN; 134 } 135 136 137 138 /** 139 * Creates a new soft delete response control with the provided information. 140 * 141 * @param oid The OID for the control. 142 * @param isCritical Indicates whether the control should be considered 143 * critical. 144 * @param value The value for the control. 145 * 146 * @throws LDAPException If the provided information cannot be used to 147 * create a valid soft delete response control. 148 */ 149 public SoftDeleteResponseControl(@NotNull final String oid, 150 final boolean isCritical, 151 @Nullable final ASN1OctetString value) 152 throws LDAPException 153 { 154 super(oid, isCritical, value); 155 156 if (value == null) 157 { 158 throw new LDAPException(ResultCode.DECODING_ERROR, 159 ERR_SOFT_DELETE_RESPONSE_NO_VALUE.get()); 160 } 161 162 softDeletedEntryDN = value.stringValue(); 163 if (! DN.isValidDN(softDeletedEntryDN)) 164 { 165 throw new LDAPException(ResultCode.DECODING_ERROR, 166 ERR_SOFT_DELETE_RESPONSE_VALUE_NOT_DN.get()); 167 } 168 } 169 170 171 172 /** 173 * {@inheritDoc} 174 */ 175 @Override() 176 @NotNull() 177 public SoftDeleteResponseControl decodeControl(@NotNull final String oid, 178 final boolean isCritical, 179 @Nullable final ASN1OctetString value) 180 throws LDAPException 181 { 182 return new SoftDeleteResponseControl(oid, isCritical, value); 183 } 184 185 186 187 /** 188 * Retrieves the DN of the entry containing the soft-deleted representation of 189 * the target entry. 190 * 191 * @return The DN of the entry containing the soft-deleted representation of 192 * the target entry. 193 */ 194 @NotNull() 195 public String getSoftDeletedEntryDN() 196 { 197 return softDeletedEntryDN; 198 } 199 200 201 202 /** 203 * Extracts a soft delete response control from the provided delete result. 204 * 205 * @param deleteResult The delete result from which to retrieve the soft 206 * delete response control. 207 * 208 * @return The soft delete response control contained in the provided delete 209 * result, or {@code null} if the result did not contain a soft 210 * delete response control. 211 * 212 * @throws LDAPException If a problem is encountered while attempting to 213 * decode the soft delete response control contained 214 * in the provided result. 215 */ 216 @Nullable() 217 public static SoftDeleteResponseControl get( 218 @NotNull final LDAPResult deleteResult) 219 throws LDAPException 220 { 221 final Control c = deleteResult.getResponseControl(SOFT_DELETE_RESPONSE_OID); 222 if (c == null) 223 { 224 return null; 225 } 226 227 if (c instanceof SoftDeleteResponseControl) 228 { 229 return (SoftDeleteResponseControl) c; 230 } 231 else 232 { 233 return new SoftDeleteResponseControl(c.getOID(), c.isCritical(), 234 c.getValue()); 235 } 236 } 237 238 239 240 /** 241 * {@inheritDoc} 242 */ 243 @Override() 244 @NotNull() 245 public String getControlName() 246 { 247 return INFO_CONTROL_NAME_SOFT_DELETE_RESPONSE.get(); 248 } 249 250 251 252 /** 253 * {@inheritDoc} 254 */ 255 @Override() 256 public void toString(@NotNull final StringBuilder buffer) 257 { 258 buffer.append("SoftDeleteResponseControl(softDeletedEntryDN='"); 259 buffer.append(softDeletedEntryDN); 260 buffer.append("')"); 261 } 262}