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);