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;
037
038
039
040import java.io.Serializable;
041
042import com.unboundid.ldap.sdk.ResultCode;
043import com.unboundid.util.NotMutable;
044import com.unboundid.util.NotNull;
045import com.unboundid.util.Nullable;
046import com.unboundid.util.ThreadSafety;
047import com.unboundid.util.ThreadSafetyLevel;
048
049
050
051/**
052 * This class provides a data structure that holds information about the result
053 * of a move subtree operation.
054 * <BR>
055 * <BLOCKQUOTE>
056 *   <B>NOTE:</B>  This class, and other classes within the
057 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
058 *   supported for use against Ping Identity, UnboundID, and
059 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
060 *   for proprietary functionality or for external specifications that are not
061 *   considered stable or mature enough to be guaranteed to work in an
062 *   interoperable way with other types of LDAP servers.
063 * </BLOCKQUOTE>
064 */
065@NotMutable()
066@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
067public final class MoveSubtreeResult
068       implements Serializable
069{
070  /**
071   * The serial version UID for this serializable class.
072   */
073  private static final long serialVersionUID = 2881207705643180021L;
074
075
076
077  // Indicates whether any changes were made to the data in the source server.
078  private final boolean sourceServerAltered;
079
080  // Indicates whether any changes were made to the data in the target server.
081  private final boolean targetServerAltered;
082
083  // The number of entries added to the target server.
084  private final int entriesAddedToTarget;
085
086  // The number of entries deleted from the source server.
087  private final int entriesDeletedFromSource;
088
089  // The number of entries read from the source server.
090  private final int entriesReadFromSource;
091
092  // The result code resulting from processing.
093  @NotNull private final ResultCode resultCode;
094
095  // A string providing details of any administrative processing that may be
096  // required to either complete the move or restore servers to their original
097  // state.
098  @Nullable private final String adminActionRequired;
099
100  // A message with information about any error that may have occurred.
101  @Nullable private final String errorMessage;
102
103
104
105  /**
106   * Creates a new move subtree result object with the provided information.
107   *
108   * @param  resultCode                A result code indicating the ultimate
109   *                                   state of the move subtree processing.
110   * @param  errorMessage              A message with information about any
111   *                                   error that occurred.
112   * @param  adminActionRequired       A message with information about any
113   *                                   administrative action that may be
114   *                                   required to bring the servers back to a
115   *                                   consistent state.
116   * @param  sourceServerAltered       Indicates whether any changes were made
117   *                                   to data in the source server.
118   * @param  targetServerAltered       Indicates whether any changes were made
119   *                                   to data in the target server.
120   * @param  entriesReadFromSource     The number of entries that were read from
121   *                                   the source server.
122   * @param  entriesAddedToTarget      The number of entries that were
123   *                                   successfully added to the target server.
124   * @param  entriesDeletedFromSource  The number of entries that were
125   *                                   successfully removed from the source
126   *                                   server.
127   */
128  MoveSubtreeResult(@NotNull final ResultCode resultCode,
129                    @Nullable final String errorMessage,
130                    @Nullable final String adminActionRequired,
131                    final boolean sourceServerAltered,
132                    final boolean targetServerAltered,
133                    final int entriesReadFromSource,
134                    final int entriesAddedToTarget,
135                    final int entriesDeletedFromSource)
136  {
137    this.resultCode               = resultCode;
138    this.errorMessage             = errorMessage;
139    this.adminActionRequired      = adminActionRequired;
140    this.sourceServerAltered      = sourceServerAltered;
141    this.targetServerAltered      = targetServerAltered;
142    this.entriesReadFromSource    = entriesReadFromSource;
143    this.entriesAddedToTarget     = entriesAddedToTarget;
144    this.entriesDeletedFromSource = entriesDeletedFromSource;
145  }
146
147
148
149  /**
150   * Retrieves a result code which indicates the ultimate state of the move
151   * subtree processing.  A result of {@code SUCCESS} indicates that all
152   * processing was successful and the subtree was moved from one server to
153   * another.  Any other result indicates that some kind of error occurred.
154   *
155   * @return  A result code which indicates the ultimate state of the move
156   *          subtree processing.
157   */
158  @NotNull()
159  public ResultCode getResultCode()
160  {
161    return resultCode;
162  }
163
164
165
166  /**
167   * Retrieves an error message with information about a problem that occurred
168   * during processing, if any.
169   *
170   * @return  An error message with information about a problem that occurred
171   *          during processing, or {@code null} if no errors were encountered.
172   */
173  @Nullable()
174  public String getErrorMessage()
175  {
176    return errorMessage;
177  }
178
179
180
181  /**
182   * Retrieves a message with information about any administrative action which
183   * may be required to bring data in the servers back into a consistent state
184   * so that the entries in the target subtree will only exist in one of the
185   * two servers.
186   *
187   * @return  A message with information about any administrative action which
188   *          may be required to bring the data in the servers back into a
189   *          consistent state, or {@code null} if no administrative action is
190   *          necessary.
191   */
192  @Nullable()
193  public String getAdminActionRequired()
194  {
195    return adminActionRequired;
196  }
197
198
199
200  /**
201   * Indicates whether any data in the source server has been altered as a
202   * result of the processing performed during the subtree move.  A successful
203   * subtree move will cause entries to be removed from the source server, but
204   * there may be error conditions which also result in source server changes.
205   *
206   * @return  {@code true} if any data in the source server has been altered as
207   *          a result of the processing performed, or {@code false} if not.
208   */
209  public boolean sourceServerAltered()
210  {
211    return sourceServerAltered;
212  }
213
214
215
216  /**
217   * Indicates whether any data in the target server has been altered as a
218   * result of the processing performed during the subtree move.  A successful
219   * subtree move will cause entries to be added to the target server, but
220   * there may be error conditions which also result in target server changes.
221   *
222   * @return  {@code true} if any data in the target server has been altered as
223   *          a result of the processing performed, or {@code false} if not.
224   */
225  public boolean targetServerAltered()
226  {
227    return targetServerAltered;
228  }
229
230
231
232  /**
233   * Retrieves the number of entries within the specified subtree read from the
234   * source server.
235   *
236   * @return  The number of entries within the specified subtree read from the
237   *          source server.
238   */
239  public int getEntriesReadFromSource()
240  {
241    return entriesReadFromSource;
242  }
243
244
245
246  /**
247   * Retrieves the number of entries added to the target server as a result of
248   * the subtree move.  Note that even in a completely successful subtree move,
249   * it is possible for this number to be less than the number of entries read
250   * from the source server if a {@link MoveSubtreeListener} is in use and its
251   * {@code doPreAddProcessing} method returns null for one or more entries to
252   * indicate that those entries should not be added to the target.
253   *
254   * @return  The number of entries added to the target server as a result of
255   *          the subtree move.
256   */
257  public int getEntriesAddedToTarget()
258  {
259    return entriesAddedToTarget;
260  }
261
262
263
264  /**
265   * Retrieves the number of entries deleted from the source server as a result
266   * of the subtree move.  If all processing is successful, then this value
267   * should match the number of entries read from the source server.
268   *
269   * @return  The number of entries deleted from the target server as a result
270   *          of the subtree move.
271   */
272  public int getEntriesDeletedFromSource()
273  {
274    return entriesDeletedFromSource;
275  }
276
277
278
279  /**
280   * Retrieves a string representation of this move subtree result object.
281   *
282   * @return  A string representation of this move subtree result object.
283   */
284  @Override()
285  @NotNull()
286  public String toString()
287  {
288    final StringBuilder buffer = new StringBuilder();
289    toString(buffer);
290    return buffer.toString();
291  }
292
293
294
295  /**
296   * Appends a string representation of this move subtree result object to the
297   * provided buffer.
298   *
299   * @param  buffer  The buffer to which the information should be appended.
300   */
301  public void toString(@NotNull final StringBuilder buffer)
302  {
303    buffer.append("MoveSubtreeResult(resultCode=");
304    buffer.append(resultCode.getName());
305
306    if (errorMessage != null)
307    {
308      buffer.append(", errorMessage='");
309      buffer.append(errorMessage);
310      buffer.append('\'');
311    }
312
313    if (adminActionRequired != null)
314    {
315      buffer.append(", adminActionRequired='");
316      buffer.append(adminActionRequired);
317      buffer.append('\'');
318    }
319
320    buffer.append(", sourceServerAltered=");
321    buffer.append(sourceServerAltered);
322    buffer.append(", targetServerAltered=");
323    buffer.append(targetServerAltered);
324    buffer.append(", entriesReadFromSource=");
325    buffer.append(entriesReadFromSource);
326    buffer.append(", entriesAddedToTarget=");
327    buffer.append(entriesAddedToTarget);
328    buffer.append(", entriesDeletedFromSource=");
329    buffer.append(entriesDeletedFromSource);
330    buffer.append(')');
331  }
332}