use of com.unboundid.ldap.sdk.unboundidds.controls.UndeleteRequestControl in project ldapsdk by pingidentity.
the class LDAPModify method doAdd.
/**
* Performs the appropriate processing for an LDIF add change record.
*
* @param changeRecord The LDIF add change record to process.
* @param controls The set of controls to include in the request.
* @param pool The connection pool to use to communicate with
* the directory server.
* @param multiUpdateRequests The list to which the request should be added
* if it is to be processed as part of a
* multi-update operation. It may be
* {@code null} if the operation should not be
* processed via the multi-update operation.
* @param rejectWriter The LDIF writer to use for recording
* information about rejected changes. It may be
* {@code null} if no reject writer is
* configured.
*
* @return The result code obtained from processing.
*
* @throws LDAPException If the operation did not complete successfully
* and processing should not continue.
*/
@NotNull()
private ResultCode doAdd(@NotNull final LDIFAddChangeRecord changeRecord, @NotNull final List<Control> controls, @NotNull final LDAPConnectionPool pool, @Nullable final List<LDAPRequest> multiUpdateRequests, @Nullable final LDIFWriter rejectWriter) throws LDAPException {
// Create the add request to process.
final AddRequest addRequest = changeRecord.toAddRequest(true);
for (final Control c : controls) {
addRequest.addControl(c);
}
// control.
if (allowUndelete.isPresent() && addRequest.hasAttribute(ATTR_UNDELETE_FROM_DN)) {
addRequest.addControl(new UndeleteRequestControl());
}
// details request control if appropriate.
if (passwordValidationDetails.isPresent()) {
final Entry entryToAdd = addRequest.toEntry();
if ((!entryToAdd.getAttributesWithOptions(ATTR_USER_PASSWORD, null).isEmpty()) || (!entryToAdd.getAttributesWithOptions(ATTR_AUTH_PASSWORD, null).isEmpty())) {
addRequest.addControl(new PasswordValidationDetailsRequestControl());
}
}
// just add the request to the list and return without doing anything else.
if (multiUpdateErrorBehavior.isPresent()) {
multiUpdateRequests.add(addRequest);
commentToOut(INFO_LDAPMODIFY_ADD_ADDED_TO_MULTI_UPDATE.get(addRequest.getDN()));
return ResultCode.SUCCESS;
}
// If the --dryRun argument was provided, then we'll stop here.
if (dryRun.isPresent()) {
commentToOut(INFO_LDAPMODIFY_DRY_RUN_ADD.get(addRequest.getDN(), dryRun.getIdentifierString()));
return ResultCode.SUCCESS;
}
// Process the add operation and get the result.
commentToOut(INFO_LDAPMODIFY_ADDING_ENTRY.get(addRequest.getDN()));
if (verbose.isPresent()) {
for (final String ldifLine : addRequest.toLDIFChangeRecord().toLDIF(WRAP_COLUMN)) {
out(ldifLine);
}
out();
}
LDAPResult addResult;
try {
addResult = pool.add(addRequest);
} catch (final LDAPException le) {
Debug.debugException(le);
addResult = le.toLDAPResult();
}
// Display information about the result.
displayResult(addResult, useTransaction.isPresent());
// should end all processing, then throw an exception.
switch(addResult.getResultCode().intValue()) {
case ResultCode.SUCCESS_INT_VALUE:
case ResultCode.NO_OPERATION_INT_VALUE:
break;
case ResultCode.ASSERTION_FAILED_INT_VALUE:
writeRejectedChange(rejectWriter, INFO_LDAPMODIFY_ASSERTION_FAILED.get(addRequest.getDN(), String.valueOf(assertionFilter.getValue())), addRequest.toLDIFChangeRecord(), addResult);
throw new LDAPException(addResult);
default:
writeRejectedChange(rejectWriter, null, addRequest.toLDIFChangeRecord(), addResult);
if (useTransaction.isPresent() || (!continueOnError.isPresent())) {
throw new LDAPException(addResult);
}
break;
}
return addResult.getResultCode();
}
use of com.unboundid.ldap.sdk.unboundidds.controls.UndeleteRequestControl in project ldapsdk by pingidentity.
the class ParallelUpdateOperationThread method run.
/**
* Operates in a loop, retrieving changes from the operation queue and
* processing them.
*/
@Override()
public void run() {
LDIFChangeRecord r = opQueue.getChangeRecord();
// Various controls that might be present on the requests.
final Control undeleteRequestControl = new UndeleteRequestControl();
while (r != null) {
if (rateLimiter != null) {
rateLimiter.await();
}
DN parsedDN = null;
DN parsedNewDN = null;
final long startTime = System.currentTimeMillis();
try {
parsedDN = r.getParsedDN();
if (r instanceof LDIFAddChangeRecord) {
final AddRequest addRequest = ((LDIFAddChangeRecord) r).toAddRequest();
addRequest.addControls(addControls);
if (allowUndelete && addRequest.hasAttribute(ATTR_UNDELETE_FROM_DN)) {
addRequest.addControl(undeleteRequestControl);
}
connectionPool.add(addRequest);
parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
} else if (r instanceof LDIFDeleteChangeRecord) {
final DeleteRequest deleteRequest = ((LDIFDeleteChangeRecord) r).toDeleteRequest();
deleteRequest.addControls(deleteControls);
connectionPool.delete(deleteRequest);
parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
} else if (r instanceof LDIFModifyChangeRecord) {
final ModifyRequest modifyRequest = ((LDIFModifyChangeRecord) r).toModifyRequest();
modifyRequest.addControls(modifyControls);
connectionPool.modify(modifyRequest);
parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
} else if (r instanceof LDIFModifyDNChangeRecord) {
final LDIFModifyDNChangeRecord modifyDNChangeRecord = (LDIFModifyDNChangeRecord) r;
parsedNewDN = modifyDNChangeRecord.getNewDN();
final ModifyDNRequest modifyDNRequest = modifyDNChangeRecord.toModifyDNRequest();
modifyDNRequest.addControls(modifyDNControls);
connectionPool.modifyDN(modifyDNRequest);
parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
} else {
// This should never happen.
r.processChange(connectionPool);
parallelUpdate.opCompletedSuccessfully(r, (System.currentTimeMillis() - startTime));
}
} catch (final LDAPException e) {
Debug.debugException(e);
parallelUpdate.opFailed(r, e, (System.currentTimeMillis() - startTime));
}
if (parsedNewDN == null) {
r = opQueue.getChangeRecord(parsedDN);
} else {
r = opQueue.getChangeRecord(parsedDN, parsedNewDN);
}
}
}
Aggregations