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