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