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