001/* 002 * Copyright 2016-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2016-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) 2016-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.experimental; 037 038 039 040import com.unboundid.ldap.sdk.Entry; 041import com.unboundid.ldap.sdk.LDAPException; 042import com.unboundid.ldap.sdk.ModifyDNRequest; 043import com.unboundid.ldap.sdk.OperationType; 044import com.unboundid.ldap.sdk.ResultCode; 045import com.unboundid.util.NotMutable; 046import com.unboundid.util.StaticUtils; 047import com.unboundid.util.ThreadSafety; 048import com.unboundid.util.ThreadSafetyLevel; 049 050import static com.unboundid.ldap.sdk.experimental.ExperimentalMessages.*; 051 052 053 054/** 055 * This class represents an entry that holds information about a modify DN 056 * operation processed by an LDAP server, as per the specification described in 057 * draft-chu-ldap-logschema-00. 058 */ 059@NotMutable() 060@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 061public final class DraftChuLDAPLogSchema00ModifyDNEntry 062 extends DraftChuLDAPLogSchema00Entry 063{ 064 /** 065 * The name of the attribute used to hold the value of the delete old RDN 066 * flag. 067 */ 068 public static final String ATTR_DELETE_OLD_RDN = "reqDeleteOldRDN"; 069 070 071 072 /** 073 * The name of the attribute used to hold the new RDN value. 074 */ 075 public static final String ATTR_NEW_RDN = "reqNewRDN"; 076 077 078 079 /** 080 * The name of the attribute used to hold the new superior DN value. 081 */ 082 public static final String ATTR_NEW_SUPERIOR_DN = "reqNewSuperior"; 083 084 085 086 /** 087 * The serial version UID for this serializable class. 088 */ 089 private static final long serialVersionUID = 5891004379538957384L; 090 091 092 093 // The delete old RDN value. 094 private final boolean deleteOldRDN; 095 096 // The new RDN. 097 private final String newRDN; 098 099 // The new superior DN. 100 private final String newSuperiorDN; 101 102 103 104 /** 105 * Creates a new instance of this modify DN access log entry from the provided 106 * entry. 107 * 108 * @param entry The entry used to create this modify DN access log entry. 109 * 110 * @throws LDAPException If the provided entry cannot be decoded as a valid 111 * modify DN access log entry as per the specification 112 * contained in draft-chu-ldap-logschema-00. 113 */ 114 public DraftChuLDAPLogSchema00ModifyDNEntry(final Entry entry) 115 throws LDAPException 116 { 117 super(entry, OperationType.MODIFY_DN); 118 119 120 // Get the new RDN. 121 newRDN = entry.getAttributeValue(ATTR_NEW_RDN); 122 if (newRDN == null) 123 { 124 throw new LDAPException(ResultCode.DECODING_ERROR, 125 ERR_LOGSCHEMA_DECODE_MISSING_REQUIRED_ATTR.get(entry.getDN(), 126 ATTR_NEW_RDN)); 127 } 128 129 130 // Get the delete old RDN flag. 131 final String deleteOldRDNString = 132 entry.getAttributeValue(ATTR_DELETE_OLD_RDN); 133 if (deleteOldRDNString == null) 134 { 135 throw new LDAPException(ResultCode.DECODING_ERROR, 136 ERR_LOGSCHEMA_DECODE_MISSING_REQUIRED_ATTR.get(entry.getDN(), 137 ATTR_DELETE_OLD_RDN)); 138 } 139 140 final String lowerDeleteOldRDN = 141 StaticUtils.toLowerCase(deleteOldRDNString); 142 if (lowerDeleteOldRDN.equals("true")) 143 { 144 deleteOldRDN = true; 145 } 146 else if (lowerDeleteOldRDN.equals("false")) 147 { 148 deleteOldRDN = false; 149 } 150 else 151 { 152 throw new LDAPException(ResultCode.DECODING_ERROR, 153 ERR_LOGSCHEMA_DECODE_MODIFY_DN_DELETE_OLD_RDN_ERROR.get( 154 entry.getDN(), ATTR_DELETE_OLD_RDN, deleteOldRDNString)); 155 } 156 157 158 // Get the new superior DN. 159 newSuperiorDN = entry.getAttributeValue(ATTR_NEW_SUPERIOR_DN); 160 } 161 162 163 164 /** 165 * Retrieves the new RDN for the modify DN request described by this modify DN 166 * access log entry. 167 * 168 * @return The new RDN for the modify DN request described by this modify DN 169 * access log entry. 170 */ 171 public String getNewRDN() 172 { 173 return newRDN; 174 } 175 176 177 178 /** 179 * Retrieves the value of the "delete old RDN" flag for the modify DN request 180 * described by this modify DN access log entry. 181 * 182 * @return {@code true} if the modify request indicated that old RDN 183 * attribute values should be removed from the entry, or 184 * {@code false} if old RDN attribute values should be preserved. 185 */ 186 public boolean deleteOldRDN() 187 { 188 return deleteOldRDN; 189 } 190 191 192 193 /** 194 * Retrieves the new superior DN for the modify DN request described by this 195 * modify DN access log entry, if any. 196 * 197 * @return The new superior DN for the modify DN request described by this 198 * modify DN access log entry, or {@code null} if there is no new 199 * superior DN. 200 */ 201 public String getNewSuperiorDN() 202 { 203 return newSuperiorDN; 204 } 205 206 207 208 /** 209 * Retrieves a {@code ModifyDNRequest} created from this modify DN access log 210 * entry. 211 * 212 * @return The {@code ModifyDNRequest} created from this modify DN access log 213 * entry. 214 */ 215 public ModifyDNRequest toModifyDNRequest() 216 { 217 return new ModifyDNRequest(getTargetEntryDN(), newRDN, deleteOldRDN, 218 newSuperiorDN, getRequestControlArray()); 219 } 220}