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