int draftChangenumber,
String changetype,
String delInitiatorsName)
throws DirectoryException
{
AttributeType aType;
String dnString = "";
String pattern;
if (draftChangenumber == 0)
{
// Draft uncompat mode
dnString = "replicationcsn="+ changeNumber +"," + serviceID
+ "," + ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT;
}
else
{
// Draft compat mode
dnString = "changenumber="+ draftChangenumber + "," +
ServerConstants.DN_EXTERNAL_CHANGELOG_ROOT;
}
// Objectclass
HashMap<ObjectClass,String> oClasses =
new LinkedHashMap<ObjectClass,String>(3);
oClasses.putAll(eclObjectClasses);
ObjectClass extensibleObjectOC =
DirectoryServer.getObjectClass(OC_EXTENSIBLE_OBJECT_LC, true);
oClasses.put(extensibleObjectOC, OC_EXTENSIBLE_OBJECT);
HashMap<AttributeType,List<Attribute>> uAttrs =
new LinkedHashMap<AttributeType,List<Attribute>>();
HashMap<AttributeType,List<Attribute>> operationalAttrs =
new LinkedHashMap<AttributeType,List<Attribute>>();
// Operational standard attributes
// subSchemaSubentry
aType = DirectoryServer.getAttributeType(ATTR_SUBSCHEMA_SUBENTRY_LC);
if (aType == null)
aType = DirectoryServer.getDefaultAttributeType(ATTR_SUBSCHEMA_SUBENTRY_LC);
Attribute a = Attributes.create(ATTR_SUBSCHEMA_SUBENTRY_LC,
ConfigConstants.DN_DEFAULT_SCHEMA_ROOT);
List<Attribute> attrList = Collections.singletonList(a);
if (aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
// numSubordinates
aType = DirectoryServer.getAttributeType("numsubordinates");
if (aType == null)
aType = DirectoryServer.getDefaultAttributeType("numSubordinates");
a = Attributes.create("numSubordinates", "0");
attrList = Collections.singletonList(a);
if (aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
// hasSubordinates
aType = DirectoryServer.getAttributeType("hassubordinates");
if (aType == null)
aType = DirectoryServer.getDefaultAttributeType("hasSubordinates");
a = Attributes.create("hasSubordinates", "false");
attrList = Collections.singletonList(a);
if (aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
// entryDN
aType = DirectoryServer.getAttributeType("entrydn");
if (aType == null)
aType = DirectoryServer.getDefaultAttributeType("entryDN");
a = Attributes.create("entryDN", dnString);
attrList = Collections.singletonList(a);
if (aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
// REQUIRED attributes
// ECL Changelog draft change number
if((aType = DirectoryServer.getAttributeType("changenumber")) == null)
aType = DirectoryServer.getDefaultAttributeType("changenumber");
a = Attributes.create("changenumber", String.valueOf(draftChangenumber));
attrList = new ArrayList<Attribute>(1);
attrList.add(a);
if(aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
//
if((aType = DirectoryServer.getAttributeType("changetime")) == null)
aType = DirectoryServer.getDefaultAttributeType("changetime");
SimpleDateFormat dateFormat;
dateFormat = new SimpleDateFormat(DATE_FORMAT_GMT_TIME);
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); // ??
a = Attributes.create(aType,
dateFormat.format(new Date(changeNumber.getTime())));
attrList = new ArrayList<Attribute>(1);
attrList.add(a);
if(aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
/* Change time in a friendly format
Date date = new Date(changeNumber.getTime());
a = Attributes.create("clearChangeTime", date.toString());
attrList = new ArrayList<Attribute>(1);
attrList.add(a);
uAttrs.put(a.getAttributeType(), attrList);
*/
//
if((aType = DirectoryServer.getAttributeType("changetype")) == null)
aType = DirectoryServer.getDefaultAttributeType("changetype");
a = Attributes.create(aType, changetype);
attrList = new ArrayList<Attribute>(1);
attrList.add(a);
if(aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
//
if((aType = DirectoryServer.getAttributeType("targetdn")) == null)
aType = DirectoryServer.getDefaultAttributeType("targetdn");
a = Attributes.create(aType, targetDN.toNormalizedString());
attrList = new ArrayList<Attribute>(1);
attrList.add(a);
if(aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
// NON REQUESTED attributes
if((aType = DirectoryServer.getAttributeType("replicationcsn")) == null)
aType = DirectoryServer.getDefaultAttributeType("replicationcsn");
a = Attributes.create(aType, changeNumber.toString());
attrList = new ArrayList<Attribute>(1);
attrList.add(a);
if(aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
//
if((aType = DirectoryServer.getAttributeType("replicaidentifier")) == null)
aType = DirectoryServer.getDefaultAttributeType("replicaidentifier");
a = Attributes.create(aType, Integer.toString(changeNumber.getServerId()));
attrList = new ArrayList<Attribute>(1);
attrList.add(a);
if(aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
if (clearLDIFchanges != null)
{
if (changetype.equals("add"))
{
if((aType = DirectoryServer.getAttributeType("changes")) == null)
aType = DirectoryServer.getDefaultAttributeType("changes");
a = Attributes.create(aType, clearLDIFchanges + "\n");
// force base64
attrList = new ArrayList<Attribute>(1);
attrList.add(a);
if(aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
pattern = "creatorsName: ";
try
{
int att_cr = clearLDIFchanges.indexOf(pattern);
if (att_cr>0)
{
int start_val_cr = clearLDIFchanges.indexOf(':', att_cr);
int end_val_cr = clearLDIFchanges.indexOf(EOL, att_cr);
String creatorsName =
clearLDIFchanges.substring(start_val_cr+2, end_val_cr);
if((aType =
DirectoryServer.getAttributeType("changeInitiatorsName")) == null)
aType =
DirectoryServer.getDefaultAttributeType("changeInitiatorsName");
a = Attributes.create(aType, creatorsName);
attrList = new ArrayList<Attribute>(1);
attrList.add(a);
if(aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
}
}
catch(Exception e)
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
logError(Message.raw(Category.SYNC, Severity.MILD_ERROR,
"Error in External Change Log when looking for pattern \""
+ pattern + "\" in string \""+
clearLDIFchanges + "\" for change " + dnString));
}
}
else if (changetype.equals("modify")||changetype.equals("modrdn"))
{
if (changetype.equals("modify"))
{
if((aType = DirectoryServer.getAttributeType("changes")) == null)
aType = DirectoryServer.getDefaultAttributeType("changes");
a = Attributes.create(aType, clearLDIFchanges + "\n");
// force base64
attrList = new ArrayList<Attribute>(1);
attrList.add(a);
if(aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
}
pattern = "modifiersName: ";
try
{
int att_cr = clearLDIFchanges.indexOf(pattern);
if (att_cr>0)
{
int start_val_cr = att_cr + pattern.length();
int end_val_cr = clearLDIFchanges.indexOf(EOL, att_cr);
String modifiersName =
clearLDIFchanges.substring(start_val_cr, end_val_cr);
if((aType =
DirectoryServer.getAttributeType("changeInitiatorsName")) == null)
aType =
DirectoryServer.getDefaultAttributeType("changeInitiatorsName");
a = Attributes.create(aType, modifiersName);
attrList = new ArrayList<Attribute>(1);
attrList.add(a);
if(aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
}
}
catch(Exception e)
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
logError(Message.raw(Category.SYNC, Severity.MILD_ERROR,
"Error in External Change Log when looking for pattern \""
+ pattern + "\" in string \""+
clearLDIFchanges + "\" for change " + dnString));
}
}
}
if (changetype.equals("delete") && (delInitiatorsName!=null))
{
if((aType = DirectoryServer.getAttributeType("changeInitiatorsName"))
== null)
aType = DirectoryServer.getDefaultAttributeType("changeInitiatorsName");
a = Attributes.create(aType, delInitiatorsName);
attrList = new ArrayList<Attribute>(1);
attrList.add(a);
if(aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
}
if (targetUUID != null)
{
if((aType = DirectoryServer.getAttributeType("targetentryuuid")) == null)
aType = DirectoryServer.getDefaultAttributeType("targetentryuuid");
a = Attributes.create(aType, targetUUID);
attrList = new ArrayList<Attribute>(1);
attrList.add(a);
if(aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
if (draftChangenumber>0)
{
// compat mode
if((aType = DirectoryServer.getAttributeType("targetuniqueid")) == null)
aType = DirectoryServer.getDefaultAttributeType("targetuniqueid");
String dseeValue = null;
try
{
dseeValue = ECLSearchOperation.openDsToSunDseeNsUniqueId(targetUUID);
}
catch(Exception e)
{
Message errMessage =
NOTE_ERR_ENTRY_UID_DSEE_MAPPING.get(
targetDN.toNormalizedString(),
targetUUID,
e.getLocalizedMessage());
logError(errMessage);
if (debugEnabled())
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
// If the mapping fails, we don't want to stop the operation
// or not return this entry.
if (dseeValue != null)
{
a = Attributes.create(aType, dseeValue);
attrList = new ArrayList<Attribute>(1);
attrList.add(a);
if(aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
}
}
}
if((aType = DirectoryServer.getAttributeType("changelogcookie")) == null)
aType = DirectoryServer.getDefaultAttributeType("changelogcookie");
a = Attributes.create(aType, cookie);
attrList = new ArrayList<Attribute>(1);
attrList.add(a);
if(aType.isOperational())
operationalAttrs.put(aType, attrList);
else
uAttrs.put(aType, attrList);
if (histEntryAttributes != null)
{
for (RawAttribute ra : histEntryAttributes)
{
try
{
String attrName = ra.getAttributeType().toLowerCase();
String eclName = "target" + attrName;
AttributeBuilder builder = new AttributeBuilder(
DirectoryServer.getDefaultAttributeType(eclName));
AttributeType at = builder.getAttributeType();
builder.setOptions(ra.toAttribute().getOptions());
builder.addAll(ra.toAttribute());
attrList = new ArrayList<Attribute>(1);
attrList.add(builder.toAttribute());
uAttrs.put(at, attrList);