5046N/A/*
5046N/A * CDDL HEADER START
5046N/A *
5046N/A * The contents of this file are subject to the terms of the
5046N/A * Common Development and Distribution License, Version 1.0 only
5046N/A * (the "License"). You may not use this file except in compliance
5046N/A * with the License.
5046N/A *
5046N/A * You can obtain a copy of the license at
5046N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
5046N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
5046N/A * See the License for the specific language governing permissions
5046N/A * and limitations under the License.
5046N/A *
5046N/A * When distributing Covered Code, include this CDDL HEADER in each
5046N/A * file and include the License file at
5046N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
5046N/A * add the following below this CDDL HEADER, with the fields enclosed
5046N/A * by brackets "[]" replaced with your own identifying information:
5046N/A * Portions Copyright [yyyy] [name of copyright owner]
5046N/A *
5046N/A * CDDL HEADER END
5046N/A *
5046N/A *
5046N/A * Copyright 2010 Sun Microsystems, Inc.
5046N/A */
5046N/A
5046N/Aimport netscape.ldap.*;
5046N/Aimport netscape.ldap.util.*;
5046N/Aimport java.util.ArrayList;
5046N/A
5046N/Aclass Change {
5046N/A int changeNumber = 0;
5046N/A String changelogCookie = null;
5046N/A CSN csn;
5046N/A String type = "";
5046N/A String dn = "";
5046N/A ArrayList<String> changes = new ArrayList<String>(2);
5046N/A String change = "";
5046N/A String replicaIdentifier = null;
5046N/A String changeNumberValue = null;
5046N/A String nsUniqueId = "";
5046N/A boolean deleteOldRDN = false;
5046N/A String newRDN = null;
5046N/A String newSuperior = null;
5046N/A
5046N/A
5046N/A public Change(LDAPEntry entry) throws Exception {
5046N/A
5046N/A
5046N/A LDAPAttribute attr = entry.getAttribute("replicaIdentifier");
5046N/A if ( attr == null ) {
5046N/A throw new Exception("No value found for replicaIdentifier");
5046N/A }
5046N/A replicaIdentifier = attr.getStringValueArray()[0];
5046N/A
5046N/A
5046N/A attr = entry.getAttribute("changeNumber");
5046N/A if ( attr == null ) {
5046N/A throw new Exception("No value found for changeNumber");
5046N/A }
5046N/A changeNumberValue = attr.getStringValueArray()[0];
5046N/A changeNumber = Integer.parseInt(changeNumberValue);
5046N/A
5046N/A attr = entry.getAttribute("changelogCookie");
5046N/A if ( attr != null ) {
5046N/A changelogCookie = attr.getStringValueArray()[0];
5046N/A }
5046N/A
5046N/A
5046N/A attr = entry.getAttribute("replicationCSN");
5046N/A if ( attr == null ) {
5046N/A throw new Exception("No value found for replicationCSN");
5046N/A }
5046N/A csn = new CSN(attr.getStringValueArray()[0]);
5046N/A
5046N/A attr = entry.getAttribute("targetDN");
5046N/A if ( attr == null ) {
5046N/A throw new Exception("No value found for targetDN");
5046N/A }
5046N/A dn = attr.getStringValueArray()[0];
5046N/A
5046N/A attr = entry.getAttribute("changeType");
5046N/A if ( attr == null ) {
5046N/A throw new Exception("No value found for changeType");
5046N/A }
5046N/A type = attr.getStringValueArray()[0];
5046N/A
5046N/A
5046N/A// attr = entry.getAttribute("targetUniqueId");
5046N/A// if ( attr == null ) {
5046N/A// throw new Exception("No value found for targetUniqueId");
5046N/A// }
5046N/A// nsUniqueId=attr.getStringValueArray()[0];
5046N/A attr = entry.getAttribute("targetEntryUUID");
5046N/A if ( attr == null ) {
5046N/A throw new Exception("No value found for targetEntryUUID");
5046N/A }
5046N/A nsUniqueId = attr.getStringValueArray()[0];
5046N/A
5046N/A
5046N/A // modrdn
5046N/A if ( type.equals("modrdn") ) {
5046N/A attr = entry.getAttribute("deleteOldRDN");
5046N/A if ( attr == null ) {
5046N/A throw new Exception("No value found for deleteOldRDN");
5046N/A }
5046N/A deleteOldRDN = Boolean.getBoolean(attr.getStringValueArray()[0]);
5046N/A
5046N/A attr = entry.getAttribute("newRDN");
5046N/A if ( attr == null ) {
5046N/A throw new Exception("No value found for newRDN");
5046N/A }
5046N/A newRDN = attr.getStringValueArray()[0];
5046N/A
5046N/A attr = entry.getAttribute("newSuperior");
5046N/A if ( attr != null ) {
5046N/A newSuperior=attr.getStringValueArray()[0];
5046N/A }
5046N/A }
5046N/A
5046N/A // Conflict
5046N/A attr = entry.getAttribute("changeHasReplFixupOp");
5046N/A if ( attr != null ) {
5046N/A change = attr.getStringValueArray()[0];
5046N/A if ( change.trim().endsWith("-") ) {
5046N/A change = change.substring(0, change.length()-3) + "\r\n";
5046N/A }
5046N/A String changeHasReplFixupOp=change.replaceFirst("targetDn", "dn") + "\r\n";
5046N/A
5046N/A // println ("INFO", "FixupOp (csn="+ csn+"):\n" + changeHasReplFixupOp);
5046N/A changes.add(changeHasReplFixupOp);
5046N/A }
5046N/A
5046N/A attr = entry.getAttribute("changes");
5046N/A if ( attr != null ) {
5046N/A change = attr.getStringValueArray()[0];
5046N/A if ( change.trim().endsWith("-") ) {
5046N/A change = change.substring(0, change.length()-3) + "\r\n";
5046N/A }
5046N/A }
5046N/A
5046N/A
5046N/A if ( type.equals("modify") && ( change.equals("") ) ) {
5046N/A throw new Exception("Attribute changes is empty - replicationCSN="+ csn);
5046N/A //EclReadAndPlay.accessOut.println (getDate() + "- WARNING: Ignore change csn=" + csn );
5046N/A }
5046N/A
5046N/A String myChange = "dn: " + dn + "\n" +
5046N/A "changetype: " + type + "\n" +
5046N/A change +"\n";
5046N/A
5046N/A changes.add(myChange);
5046N/A
5046N/A changes.trimToSize();
5046N/A
5046N/A }
5046N/A
5046N/A
5046N/A public String toString() {
5046N/A return ("change number " + changeNumber + " (csn="+csn +")");
5046N/A }
5046N/A}