001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2006-2008 Sun Microsystems, Inc.
015 * Portions copyright 2012-2016 ForgeRock AS.
016 */
017package org.opends.server.replication.plugin;
018
019import java.util.ArrayList;
020import java.util.List;
021
022import org.opends.server.replication.common.CSN;
023import org.opends.server.replication.protocol.ModifyMsg;
024import org.opends.server.replication.protocol.ReplicationMsg;
025import org.forgerock.opendj.ldap.DN;
026import org.opends.server.types.Modification;
027
028/**
029 * This class if used to build fake Modify Operation from the historical
030 * information that stay in the entry in the database.
031 *
032 * This is useful when a LDAP server can't find a LDAP server that
033 * has already seen all its changes and therefore need to retransmit them.
034 */
035public class FakeModifyOperation extends FakeOperation
036{
037  private List<Modification> mods = new ArrayList<>();
038  private DN dn;
039  private String entryuuid;
040
041  /**
042   * Creates a new ModifyFakeOperation with the provided information.
043   *
044   * @param dn The DN on which the Operation was applied.
045   * @param csn The CSN of the operation.
046   * @param entryuuid The unique ID of the entry on which the Operation applies.
047   */
048  public FakeModifyOperation(DN dn, CSN csn, String entryuuid)
049  {
050    super(csn);
051    this.dn = dn;
052    this.entryuuid = entryuuid;
053  }
054
055  /**
056   * Add a modification to the list of modification included
057   * in this fake operation.
058   *
059   * @param mod A modification that must be added to the list of modifications
060   *            included in this fake operation.
061   */
062  public void addModification(Modification mod)
063  {
064    mods.add(mod);
065  }
066
067  /** {@inheritDoc} */
068  @Override
069  public ReplicationMsg generateMessage()
070  {
071    return new ModifyMsg(getCSN(), dn, mods, entryuuid);
072  }
073}