use of com.unboundid.ldap.sdk.unboundidds.extensions.MultiUpdateChangesApplied in project ldapsdk by pingidentity.
the class ResultUtils method formatResult.
/**
* Adds a multi-line string representation of the provided result to the
* given list.
*
* @param lines The list to which the lines should be added.
* @param result The result to be formatted.
* @param inTxn Indicates whether the operation is part of an active
* transaction.
* @param prefix The prefix to use for each line.
* @param maxWidth The maximum length of each line in characters, including
* the comment prefix and indent.
*/
private static void formatResult(@NotNull final List<String> lines, @NotNull final LDAPResult result, final boolean inTxn, @NotNull final String prefix, final int maxWidth) {
// Format the result code. If it's a success result but the operation was
// part of a transaction, then indicate that no change has actually been
// made yet.
final ResultCode resultCode = result.getResultCode();
wrap(lines, INFO_RESULT_UTILS_RESULT_CODE.get(String.valueOf(resultCode)), prefix, maxWidth);
if (inTxn && (resultCode == ResultCode.SUCCESS)) {
wrap(lines, INFO_RESULT_UTILS_SUCCESS_WITH_TXN.get(), prefix, maxWidth);
}
// Format the diagnostic message, if there is one.
final String diagnosticMessage = result.getDiagnosticMessage();
if (diagnosticMessage != null) {
wrap(lines, INFO_RESULT_UTILS_DIAGNOSTIC_MESSAGE.get(diagnosticMessage), prefix, maxWidth);
}
// Format the matched DN, if there is one.
final String matchedDN = result.getMatchedDN();
if (matchedDN != null) {
wrap(lines, INFO_RESULT_UTILS_MATCHED_DN.get(matchedDN), prefix, maxWidth);
}
// If there are any referral URLs, then display them.
final String[] referralURLs = result.getReferralURLs();
if (referralURLs != null) {
for (final String referralURL : referralURLs) {
wrap(lines, INFO_RESULT_UTILS_REFERRAL_URL.get(referralURL), prefix, maxWidth);
}
}
if (result instanceof SearchResult) {
final SearchResult searchResult = (SearchResult) result;
// We'll always display the search entry count if we know it.
final int numEntries = searchResult.getEntryCount();
if (numEntries >= 0) {
wrap(lines, INFO_RESULT_UTILS_NUM_SEARCH_ENTRIES.get(numEntries), prefix, maxWidth);
}
// We'll only display the search reference count if it's greater than
// zero.
final int numReferences = searchResult.getReferenceCount();
if (numReferences > 0) {
wrap(lines, INFO_RESULT_UTILS_NUM_SEARCH_REFERENCES.get(numReferences), prefix, maxWidth);
}
} else if (result instanceof StartTransactionExtendedResult) {
final StartTransactionExtendedResult startTxnResult = (StartTransactionExtendedResult) result;
final ASN1OctetString txnID = startTxnResult.getTransactionID();
if (txnID != null) {
if (StaticUtils.isPrintableString(txnID.getValue())) {
wrap(lines, INFO_RESULT_UTILS_START_TXN_RESULT_TXN_ID.get(txnID.stringValue()), prefix, maxWidth);
} else {
wrap(lines, INFO_RESULT_UTILS_START_TXN_RESULT_TXN_ID.get("0x" + StaticUtils.toHex(txnID.getValue())), prefix, maxWidth);
}
}
} else if (result instanceof EndTransactionExtendedResult) {
final EndTransactionExtendedResult endTxnResult = (EndTransactionExtendedResult) result;
final int failedOpMessageID = endTxnResult.getFailedOpMessageID();
if (failedOpMessageID > 0) {
wrap(lines, INFO_RESULT_UTILS_END_TXN_RESULT_FAILED_MSG_ID.get(failedOpMessageID), prefix, maxWidth);
}
final Map<Integer, Control[]> controls = endTxnResult.getOperationResponseControls();
if (controls != null) {
for (final Map.Entry<Integer, Control[]> e : controls.entrySet()) {
for (final Control c : e.getValue()) {
wrap(lines, INFO_RESULT_UTILS_END_TXN_RESULT_OP_CONTROL.get(e.getKey()), prefix, maxWidth);
formatResponseControl(lines, c, prefix + " ", maxWidth);
}
}
}
} else if (result instanceof MultiUpdateExtendedResult) {
final MultiUpdateExtendedResult multiUpdateResult = (MultiUpdateExtendedResult) result;
final MultiUpdateChangesApplied changesApplied = multiUpdateResult.getChangesApplied();
if (changesApplied != null) {
wrap(lines, INFO_RESULT_UTILS_MULTI_UPDATE_CHANGES_APPLIED.get(changesApplied.name()), prefix, maxWidth);
}
final List<ObjectPair<OperationType, LDAPResult>> multiUpdateResults = multiUpdateResult.getResults();
if (multiUpdateResults != null) {
for (final ObjectPair<OperationType, LDAPResult> p : multiUpdateResults) {
wrap(lines, INFO_RESULT_UTILS_MULTI_UPDATE_RESULT_HEADER.get(p.getFirst().name()), prefix, maxWidth);
formatResult(lines, p.getSecond(), false, prefix + " ", maxWidth);
}
}
} else if (result instanceof PasswordModifyExtendedResult) {
final PasswordModifyExtendedResult passwordModifyResult = (PasswordModifyExtendedResult) result;
final String generatedPassword = passwordModifyResult.getGeneratedPassword();
if (generatedPassword != null) {
wrap(lines, INFO_RESULT_UTILS_PASSWORD_MODIFY_RESULT_GENERATED_PW.get(generatedPassword), prefix, maxWidth);
}
} else if (result instanceof ExtendedResult) {
final ExtendedResult extendedResult = (ExtendedResult) result;
final String oid = ((ExtendedResult) result).getOID();
if (oid != null) {
wrap(lines, INFO_RESULT_UTILS_RESPONSE_EXTOP_OID.get(oid), prefix, maxWidth);
}
final ASN1OctetString value = extendedResult.getValue();
if ((value != null) && (value.getValueLength() > 0)) {
wrap(lines, INFO_RESULT_UTILS_RESPONSE_EXTOP_RAW_VALUE_HEADER.get(), prefix, maxWidth);
// We'll ignore the maximum width for this portion of the output.
for (final String line : StaticUtils.stringToLines(StaticUtils.toHexPlusASCII(value.getValue(), 0))) {
lines.add(prefix + " " + line);
}
}
}
// If there are any controls, then display them. We'll interpret any
// controls that we can, but will fall back to a general display for any
// that we don't recognize or can't parse.
final Control[] controls = result.getResponseControls();
if (controls != null) {
for (final Control c : controls) {
formatResponseControl(lines, c, prefix, maxWidth);
}
}
}
Aggregations