001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at
010 * docs/licenses/cddl.txt
011 * or http://www.opensource.org/licenses/cddl1.php.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * docs/licenses/cddl.txt.  If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 *      Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 *      Copyright 2010-2021 Ping Identity Corporation
026 */
027package com.unboundid.directory.sdk.sync.types;
028
029import java.util.Collection;
030import java.util.List;
031
032import com.unboundid.ldap.sdk.ChangeLogEntry;
033import com.unboundid.ldap.sdk.Entry;
034import com.unboundid.ldap.sdk.unboundidds.UnboundIDChangeLogEntry;
035
036/**
037 * This interface represents a single synchronized change from the Sync
038 * Source to the Sync Destination.  It exists from when a change is detected
039 * all the way through when the change is applied at the destination.
040 */
041public interface SyncOperation
042{
043  /**
044   * Return the type of this SynchronizationOperation.
045   *
046   * @return  The type of this SynchronizationOperation.
047   */
048  SyncOperationType getType();
049
050
051
052  /**
053   * Return a String that can be used to correlate this change back to the
054   * source entry. For example, if the source endpoint is a directory server,
055   * this will be a DN.
056   *
057   * @return  A String that can be used to correlate this change back to the
058   *          source entry.
059   */
060  String getIdentifiableInfo();
061
062
063
064  /**
065   * Return a unique ID for this {@code SyncOperation}. This ID is used in
066   * log messages.
067   *
068   * @return  A unique ID for this operation.
069   */
070  String getUniqueId();
071
072
073
074  /**
075   * Return the Entry that was fetched from the sync source. This may be null
076   * if the source entry no longer exists or has not yet been fetched.
077   *
078   * @return  The entry that was fetched from the source server.
079   */
080  Entry getSourceEntry();
081
082
083
084  /**
085   * Sets the entry that was fetched from the sync source.  If the entry was
086   * deleted, then sufficient information about the entry must be provided so
087   * that it can be correlated to a destination entry.
088   *
089   * @param  sourceEntry     The entry that was fetched from the source.
090   * @param  isDeletedEntry  {@code true} if and only if the entry was deleted
091   *                         at the source.
092   */
093  void setSourceEntry(Entry sourceEntry, boolean isDeletedEntry);
094
095
096
097  /**
098   * Return the original changelog entry that was detected for this operation.
099   * This is only applicable when synchronizing from a data source that
100   * supplies an LDAP changelog as described in
101   * <i>draft-good-ldap-changelog</i>, such as the
102   * Ping Identity Directory Server or Sun Directory Server.
103   * <p>
104   * Note that this is the raw changelog entry and does not have any mappings
105   * or filterings applied to it.
106   *
107   * @return a {@link ChangeLogEntry} instance, or null if the source endpoint
108   *         does not use an LDAP changelog for change detection.
109   */
110  ChangeLogEntry getChangeLogEntry();
111
112
113
114  /**
115   * Return the original changelog entry that was detected for this operation.
116   * This is only applicable when synchronizing from
117   * a Ping Identity Directory Server. The UnboundID LDAP Changelog provides
118   * additional functionality not present in other directory servers.
119   * <p>
120   * Note that this is the raw changelog entry and does not have any mappings
121   * or filterings applied to it.
122   *
123   * @return a {@link UnboundIDChangeLogEntry} instance, or null if the source
124   *         endpoint is not a Ping Identity Directory Server.
125   */
126  UnboundIDChangeLogEntry getUnboundIDChangeLogEntry();
127
128
129
130  /**
131   * Return the original change record that was detected for this operation.
132   * This is only applicable when synchronizing from a data source that
133   * is implemented by the <code>SyncSource</code> or
134   * <code>ScriptedSyncSource</code> extension type.
135   *
136   * @return a {@link ChangeRecord} instance, or null if the source endpoint
137   *         is not an instance of <code>SyncSource</code> or
138   *         <code>ScriptedSyncSource</code>.
139   */
140  ChangeRecord getChangeRecord();
141
142
143
144  /**
145   * Return the DatabaseChangeRecord that was detected from a RDBMS. This is
146   * only applicable when synchronizing from a database environment, and will
147   * be null otherwise.
148   *
149   * @return a DatabaseChangeRecord that was detected from a database, or null
150   *         if the sync source is not a JDBC sync source.
151   */
152  DatabaseChangeRecord getDatabaseChangeRecord();
153
154
155
156  /**
157   * Determines whether this SyncOperation represents a modify DN operation on
158   * the source entry (if the source is an LDAP directory). The
159   * result of this method is undefined if the source is a relational database
160   * or some other type of endpoint.
161   *
162   * @return true if the entry has been renamed, false otherwise.
163   */
164  boolean isModifyDN();
165
166
167
168  /**
169   * Returns a representation of the target destination entry before it is
170   * modified or renamed. This can be used to obtain the before-values of any
171   * attributes. The returned entry cannot be modified.
172   * <p>
173   * This value is only defined after the SyncOperation has made it past the
174   * post-mapping stage in the SyncPipe.
175   *
176   * @return a {@link Entry} instance.
177   */
178  Entry getDestinationEntryBeforeChange();
179
180
181
182  /**
183   * Returns a representation of the target destination entry after it is
184   * modified or renamed. This can be used to obtain the after-values of any
185   * attributes.
186   * <p>
187   * This value is only defined after the SyncOperation has made it past the
188   * post-mapping stage in the SyncPipe.
189   * <p>
190   * The returned entry is modifiable and can be used to influence
191   * the final list of modifications to apply at the destination. The
192   * Data Sync Server computes a diff between this entry and the
193   * existing entry returned from the destination. Any modifications to this
194   * entry would have to take place in either
195   * {@code LDAPSyncDestinationPlugin.preFetch} or
196   * {@code LDAPSyncDestinationPlugin.postFetch}.
197   *
198   * @return a {@link Entry} instance.
199   */
200  Entry getDestinationEntryAfterChange();
201
202
203
204  /**
205   * Return the names of the attributes that were modified at the source.
206   *
207   * @return  The names of the attributes that were modified at the source.
208   */
209  Collection<String> getModifiedSourceAttributes();
210
211
212
213  /**
214   * Add an additional source attribute that should be synchronized to the
215   * destination.
216   *
217   * @param  attributeName  The attribute to add to the set of attributes to
218   *                        synchronize.
219   */
220  void addModifiedSourceAttribute(String attributeName);
221
222
223
224  /**
225   * Remove a source attribute that should not be synchronized to the
226   * destination.
227   *
228   * @param  attributeName  The attribute to remove from the set of attributes
229   *                        to synchronize.
230   */
231  void removeModifiedSourceAttribute(String attributeName);
232
233
234
235  /**
236   * Add the name of a destination attribute that should be synchronized.
237   *
238   * @param  attributeName  The name of the destination attribute to
239   *                        synchronize.
240   */
241  void addModifiedDestinationAttribute(String attributeName);
242
243
244
245  /**
246   * Return the name of the Sync Pipe for the operation being processed.
247   *
248   * @return  The name of the Sync Pipe for the operation being processed.
249   */
250  String getSyncPipeName();
251
252
253
254  /**
255   * Return the name of the Sync Class for the operation being processed.
256   *
257   * @return  The name of the Sync Class for the operation being processed.
258   */
259  String getSyncClassName();
260
261
262
263  /**
264   * Return the {@link SyncClass} for the operation being processed. This can
265   * be used to determine the correlation attributes and other properties
266   * configured for this type of change.
267   *
268   * @return  The Sync Class that this operation falls into, or null if no
269   *          Sync Class has been determined yet.
270   */
271  SyncClass getSyncClass();
272
273
274
275  /**
276   * Stores an attachment in the operation.  This can be used by an extension
277   * to have information carried in the synchronization operation from one
278   * extension point to the next.
279   *
280   * @param  key    The key of the attachment.  To avoid conflicts, the
281   *                fully-qualified class name of the extension should be used
282   *                as a prefix of the key.
283   *
284   * @param  value  The value of the attachment.
285   */
286  void putAttachment(Object key, Object value);
287
288
289
290  /**
291   * Returns an attachment from the operation that was previously set with a
292   * call to {@link #putAttachment}.
293   *
294   * @param  key  The key of the attachment.
295   *
296   * @return  The value of the attachment or {@code null} if no attachment was
297   *          set for the specified key.
298   */
299  Object getAttachment(Object key);
300
301
302
303  /**
304   * Returns a list of warning messages (if any) about this SyncOperation. For
305   * example, if a changelog entry omitted some data because an attribute had
306   * too many values, there will be a message in the returned list indicating
307   * so. Typically synchronization of this SyncOperation can continue despite
308   * these warnings.
309   *
310   * @return a list of warning messages; the list will be empty if there are no
311   *         warnings.
312   */
313  List<String> getWarnings();
314
315
316
317  /**
318   * Logs an error message to the synchronization log for this change.  Messages
319   * logged here should pertain to this specific change.  For general logging
320   * capabilities, see {@link SyncServerContext}
321   *
322   * @param  message  The message to log.
323   */
324  void logError(String message);
325
326
327
328  /**
329   * Logs an informational message to the synchronization log for this change.
330   * Messages logged here should pertain to this specific change.  For general
331   * logging capabilities, see {@link SyncServerContext}
332   *
333   * @param  message  The message to log.
334   */
335  void logInfo(String message);
336
337
338
339  /**
340   * Logs a debug message to the synchronization log for this change. Messages
341   * logged here should pertain to this specific change.  For general logging
342   * capabilities, see {@link SyncServerContext}.  To see messages logged with
343   * this API the Sync Log Publisher should include plugin-debug.  For resyncs
344   * pass "--logLevel debug".
345   *
346   * @param  message  The message to log.
347   */
348  void logDebug(String message);
349
350
351
352  /**
353   * Get the "ignored" flag. For create, modify, or delete operations when the
354   * "ignored" flag is set to true the Sync server does not include the
355   * operation in the statistics listed under
356   * "cn=Sync Pipe Monitor: &lt;pipe name&gt;,cn=monitor".
357   *
358   * @return The "ignored" flag.
359   */
360  boolean isIgnored();
361
362
363
364  /**
365   * Sets the "ignored" flag to true. Setting the "ignored" flag to true informs
366   * the Sync server that the create, modify, or delete operation was ignored.
367   * This prevents the operation from being included as an applied operation in
368   * the statistics that are reported for the Sync Pipe via the Management
369   * Console, the bin/status command line utility, and in a raw form under
370   * "cn=Sync Pipe Monitor: &lt;pipe name&gt;,cn=monitor".
371   */
372  void setIgnored();
373}