use of org.forgerock.opendj.ldap.requests.ModifyDNRequest in project OpenAM by OpenRock.
the class DataLayer method rename.
public void rename(java.security.Principal principal, Guid guid, String newName, boolean deleteOldName) throws UMSException {
String id = guid.getDn();
ResultCode errorCode;
try {
ModifyDNRequest request = LDAPRequests.newModifyDNRequest(id, newName);
int retry = 0;
while (retry <= connNumRetry) {
if (debug.messageEnabled()) {
debug.message("DataLayer.rename retry: " + retry);
}
try (Connection conn = getConnection(principal)) {
conn.applyChange(request);
return;
} catch (LdapException e) {
errorCode = e.getResult().getResultCode();
if (!retryErrorCodes.contains(errorCode) || retry == connNumRetry) {
throw e;
}
retry++;
try {
Thread.sleep(connRetryInterval);
} catch (InterruptedException ex) {
}
}
}
} catch (LdapException e) {
if (debug.warningEnabled()) {
debug.warning("Exception in DataLayer.rename for DN: " + id, e);
}
errorCode = e.getResult().getResultCode();
if (ResultCode.NO_SUCH_OBJECT.equals(errorCode)) {
throw new EntryNotFoundException(id, e);
} else if (ResultCode.INSUFFICIENT_ACCESS_RIGHTS.equals(errorCode)) {
throw new AccessRightsException(id, e);
} else {
throw new UMSException(id, e);
}
}
}
use of org.forgerock.opendj.ldap.requests.ModifyDNRequest in project OpenAM by OpenRock.
the class LdifUtils method createSchemaFromLDIF.
/**
* Creates LDAP schema from LDIF file.
*
* @param ldif LDIF object.
* @param ld LDAP Connection.
* @throws IOException If an error occurs when reading the LDIF file.
*/
public static void createSchemaFromLDIF(LDIFChangeRecordReader ldif, final Connection ld) throws IOException {
while (ldif.hasNext()) {
final ChangeRecord changeRecord = ldif.readChangeRecord();
changeRecord.accept(new ChangeRecordVisitor<Void, Void>() {
@Override
public Void visitChangeRecord(Void aVoid, AddRequest change) {
try {
change.addControl(TransactionIdControl.newControl(AuditRequestContext.createSubTransactionIdValue()));
ld.add(change);
} catch (LdapException e) {
if (ResultCode.ENTRY_ALREADY_EXISTS.equals(e.getResult().getResultCode())) {
for (Attribute attr : change.getAllAttributes()) {
ModifyRequest modifyRequest = LDAPRequests.newModifyRequest(change.getName());
modifyRequest.addModification(new Modification(ModificationType.ADD, attr));
try {
ld.modify(modifyRequest);
} catch (LdapException ex) {
DEBUG.warning("LDAPUtils.createSchemaFromLDIF - Could not modify schema: {}", modifyRequest, ex);
}
}
} else {
DEBUG.warning("LDAPUtils.createSchemaFromLDIF - Could not add to schema: {}", change, e);
}
}
return null;
}
@Override
public Void visitChangeRecord(Void aVoid, ModifyRequest change) {
try {
change.addControl(TransactionIdControl.newControl(AuditRequestContext.createSubTransactionIdValue()));
ld.modify(change);
} catch (LdapException e) {
DEBUG.warning("LDAPUtils.createSchemaFromLDIF - Could not modify schema: {}", change, e);
}
return null;
}
@Override
public Void visitChangeRecord(Void aVoid, ModifyDNRequest change) {
return null;
}
@Override
public Void visitChangeRecord(Void aVoid, DeleteRequest change) {
DEBUG.message("Delete request ignored: {}", changeRecord);
return null;
}
}, null);
}
}
Aggregations