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