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