Search in sources :

Example 1 with MultiUpdateChangesApplied

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);
        }
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) SearchResult(com.unboundid.ldap.sdk.SearchResult) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) MultiUpdateExtendedResult(com.unboundid.ldap.sdk.unboundidds.extensions.MultiUpdateExtendedResult) IntermediateClientResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.IntermediateClientResponseControl) TransactionSettingsResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.TransactionSettingsResponseControl) Control(com.unboundid.ldap.sdk.Control) UniquenessResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.UniquenessResponseControl) SimplePagedResultsControl(com.unboundid.ldap.sdk.controls.SimplePagedResultsControl) PasswordValidationDetailsResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.PasswordValidationDetailsResponseControl) VirtualListViewResponseControl(com.unboundid.ldap.sdk.controls.VirtualListViewResponseControl) GetPasswordPolicyStateIssuesResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.GetPasswordPolicyStateIssuesResponseControl) AccountUsableResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.AccountUsableResponseControl) GetServerIDResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.GetServerIDResponseControl) SoftDeleteResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.SoftDeleteResponseControl) PasswordExpiredControl(com.unboundid.ldap.sdk.controls.PasswordExpiredControl) PasswordExpiringControl(com.unboundid.ldap.sdk.controls.PasswordExpiringControl) PostReadResponseControl(com.unboundid.ldap.sdk.controls.PostReadResponseControl) GetAuthorizationEntryResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.GetAuthorizationEntryResponseControl) ServerSideSortResponseControl(com.unboundid.ldap.sdk.controls.ServerSideSortResponseControl) MatchingEntryCountResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.MatchingEntryCountResponseControl) GeneratePasswordResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.GeneratePasswordResponseControl) EntryChangeNotificationControl(com.unboundid.ldap.sdk.controls.EntryChangeNotificationControl) GetUserResourceLimitsResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.GetUserResourceLimitsResponseControl) AssuredReplicationResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.AssuredReplicationResponseControl) ContentSyncStateControl(com.unboundid.ldap.sdk.controls.ContentSyncStateControl) GetRecentLoginHistoryResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.GetRecentLoginHistoryResponseControl) JoinResultControl(com.unboundid.ldap.sdk.unboundidds.controls.JoinResultControl) GetBackendSetIDResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.GetBackendSetIDResponseControl) PasswordPolicyResponseControl(com.unboundid.ldap.sdk.unboundidds.controls.PasswordPolicyResponseControl) PreReadResponseControl(com.unboundid.ldap.sdk.controls.PreReadResponseControl) AuthorizationIdentityResponseControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl) ContentSyncDoneControl(com.unboundid.ldap.sdk.controls.ContentSyncDoneControl) MultiUpdateChangesApplied(com.unboundid.ldap.sdk.unboundidds.extensions.MultiUpdateChangesApplied) PasswordModifyExtendedResult(com.unboundid.ldap.sdk.extensions.PasswordModifyExtendedResult) StartTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.StartTransactionExtendedResult) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult) StartTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.StartTransactionExtendedResult) NoticeOfDisconnectionExtendedResult(com.unboundid.ldap.sdk.extensions.NoticeOfDisconnectionExtendedResult) MultiUpdateExtendedResult(com.unboundid.ldap.sdk.unboundidds.extensions.MultiUpdateExtendedResult) AbortedTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.AbortedTransactionExtendedResult) EndTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.EndTransactionExtendedResult) PasswordModifyExtendedResult(com.unboundid.ldap.sdk.extensions.PasswordModifyExtendedResult) List(java.util.List) ArrayList(java.util.ArrayList) OperationType(com.unboundid.ldap.sdk.OperationType) EndTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.EndTransactionExtendedResult) Map(java.util.Map) AssuredReplicationServerResultCode(com.unboundid.ldap.sdk.unboundidds.controls.AssuredReplicationServerResultCode) ResultCode(com.unboundid.ldap.sdk.ResultCode) ObjectPair(com.unboundid.util.ObjectPair)

Aggregations

ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1 Control (com.unboundid.ldap.sdk.Control)1 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)1 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)1 OperationType (com.unboundid.ldap.sdk.OperationType)1 ResultCode (com.unboundid.ldap.sdk.ResultCode)1 SearchResult (com.unboundid.ldap.sdk.SearchResult)1 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)1 ContentSyncDoneControl (com.unboundid.ldap.sdk.controls.ContentSyncDoneControl)1 ContentSyncStateControl (com.unboundid.ldap.sdk.controls.ContentSyncStateControl)1 EntryChangeNotificationControl (com.unboundid.ldap.sdk.controls.EntryChangeNotificationControl)1 PasswordExpiredControl (com.unboundid.ldap.sdk.controls.PasswordExpiredControl)1 PasswordExpiringControl (com.unboundid.ldap.sdk.controls.PasswordExpiringControl)1 PostReadResponseControl (com.unboundid.ldap.sdk.controls.PostReadResponseControl)1 PreReadResponseControl (com.unboundid.ldap.sdk.controls.PreReadResponseControl)1 ServerSideSortResponseControl (com.unboundid.ldap.sdk.controls.ServerSideSortResponseControl)1 SimplePagedResultsControl (com.unboundid.ldap.sdk.controls.SimplePagedResultsControl)1 VirtualListViewResponseControl (com.unboundid.ldap.sdk.controls.VirtualListViewResponseControl)1 AbortedTransactionExtendedResult (com.unboundid.ldap.sdk.extensions.AbortedTransactionExtendedResult)1 EndTransactionExtendedResult (com.unboundid.ldap.sdk.extensions.EndTransactionExtendedResult)1