// Just log it and move on.
LOG.log(Level.INFO, "Ignoring attribute not found: " +
modListToString(op.getModifications()));
} else {
// report the error to the user
MessageBuilder error = op.getErrorMessage();
throw new ApplicationException(
ReturnCode.IMPORT_ERROR,
INFO_ERROR_APPLY_LDIF_MODIFY.get(dnByteString.toString(),
error != null ? error.toString() : ""),
null);
}
break;
case ADD:
LOG.log(Level.INFO, "preparing to add " + dnByteString);
AddChangeRecordEntry acre = (AddChangeRecordEntry) cre;
List<Attribute> attrs = acre.getAttributes();
ArrayList<RawAttribute> rawAttrs =
new ArrayList<RawAttribute>(attrs.size());
for (Attribute a : attrs) {
rawAttrs.add(new LDAPAttribute(a));
}
AddOperation addOp = cc.processAdd(dnByteString, rawAttrs);
rc = addOp.getResultCode();
if (rc.equals(ResultCode.SUCCESS)) {
LOG.log(Level.INFO, "processed server add " + addOp.getEntryDN());
} else if (rc.equals(ResultCode.ENTRY_ALREADY_EXISTS)) {
// Compare the attributes with the existing entry to see if we
// can ignore this add.
boolean ignore = true;
for (RawAttribute attr : rawAttrs) {
ArrayList<ByteString> values = attr.getValues();
for (ByteString value : values) {
CompareOperation compOp =
cc.processCompare(dnByteString, attr.getAttributeType(), value);
if (ResultCode.ASSERTION_FAILED.equals(compOp.getResultCode())) {
ignore = false;
break;
}
}
}
if (!ignore) {
MessageBuilder error = addOp.getErrorMessage();
throw new ApplicationException(
ReturnCode.IMPORT_ERROR,
INFO_ERROR_APPLY_LDIF_ADD.get(dnByteString.toString(),
error != null ? error.toString() : ""),
null);
}
} else {
boolean ignore = false;
if (rc.equals(ResultCode.ENTRY_ALREADY_EXISTS)) {
// The entry already exists. Compare the attributes with the
// existing entry to see if we can ignore this add.
try {
InternalSearchOperation searchOp =
cc.processSearch(
cre.getDN(),
SearchScope.BASE_OBJECT,
SearchFilter.createFilterFromString(
"objectclass=*"));
LinkedList<SearchResultEntry> se = searchOp.getSearchEntries();
if (se.size() > 0) {
SearchResultEntry e = se.get(0);
List<Attribute> eAttrs = new ArrayList<Attribute>();
eAttrs.addAll(e.getAttributes());
eAttrs.add(e.getObjectClassAttribute());
if (compareUserAttrs(attrs, eAttrs)) {
LOG.log(Level.INFO, "Ignoring failure to add " +
dnByteString + " since the existing entry's " +
"attributes are identical");
ignore = true;
}
}
} catch (Exception e) {
LOG.log(Level.INFO, "Error attempting to compare rejected add " +
"entry with existing entry", e);
}
}
if (!ignore) {
MessageBuilder error = addOp.getErrorMessage();
throw new ApplicationException(
ReturnCode.IMPORT_ERROR,
INFO_ERROR_APPLY_LDIF_ADD.get(dnByteString.toString(),
error != null ? error.toString() : ""),
null);
}
}
break;
case DELETE:
LOG.log(Level.INFO, "preparing to delete " + dnByteString);
DeleteOperation delOp = cc.processDelete(dnByteString);
rc = delOp.getResultCode();
if (rc.equals(ResultCode.SUCCESS)) {
LOG.log(Level.INFO, "processed server delete " +
delOp.getEntryDN());
} else {
// report the error to the user
MessageBuilder error = delOp.getErrorMessage();
throw new ApplicationException(
ReturnCode.IMPORT_ERROR,
INFO_ERROR_APPLY_LDIF_DELETE.get(dnByteString.toString(),
error != null ? error.toString() : ""),
null);
}
break;
default:
LOG.log(Level.SEVERE, "Unexpected record type " + cre.getClass());