@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class ServerSideSortRequestControl extends Control
SortKey
values. Each sort key includes an attribute name and a flag
that indicates whether to sort in ascending or descending order. It may also
specify a custom matching rule that should be used to specify which logic
should be used to perform the sorting.
ServerSideSortResponseControl
to provide information about the
status of the sort processing.
// Perform a search to get all user entries sorted by last name, then by // first name, both in ascending order. SearchRequest searchRequest = new SearchRequest( "ou=People,dc=example,dc=com", SearchScope.SUB, Filter.createEqualityFilter("objectClass", "person")); searchRequest.addControl(new ServerSideSortRequestControl( new SortKey("sn"), new SortKey("givenName"))); SearchResult lastNameAscendingResult; try { lastNameAscendingResult = connection.search(searchRequest); // If we got here, then the search was successful. } catch (LDAPSearchException lse) { // The search failed for some reason. lastNameAscendingResult = lse.getSearchResult(); ResultCode resultCode = lse.getResultCode(); String errorMessageFromServer = lse.getDiagnosticMessage(); } // Get the response control and retrieve the result code for the sort // processing. LDAPTestUtils.assertHasControl(lastNameAscendingResult, ServerSideSortResponseControl.SERVER_SIDE_SORT_RESPONSE_OID); ServerSideSortResponseControl lastNameAscendingResponseControl = ServerSideSortResponseControl.get(lastNameAscendingResult); ResultCode lastNameSortResult = lastNameAscendingResponseControl.getResultCode(); // Perform the same search, but this time request the results to be sorted // in descending order by first name, then last name. searchRequest.setControls(new ServerSideSortRequestControl( new SortKey("givenName", true), new SortKey("sn", true))); SearchResult firstNameDescendingResult; try { firstNameDescendingResult = connection.search(searchRequest); // If we got here, then the search was successful. } catch (LDAPSearchException lse) { // The search failed for some reason. firstNameDescendingResult = lse.getSearchResult(); ResultCode resultCode = lse.getResultCode(); String errorMessageFromServer = lse.getDiagnosticMessage(); } // Get the response control and retrieve the result code for the sort // processing. LDAPTestUtils.assertHasControl(firstNameDescendingResult, ServerSideSortResponseControl.SERVER_SIDE_SORT_RESPONSE_OID); ServerSideSortResponseControl firstNameDescendingResponseControl = ServerSideSortResponseControl.get(firstNameDescendingResult); ResultCode firstNameSortResult = firstNameDescendingResponseControl.getResultCode();
EntrySorter
class for details on performing
client-side sorting in the LDAP SDK.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SERVER_SIDE_SORT_REQUEST_OID
The OID (1.2.840.113556.1.4.473) for the server-side sort request control.
|
Constructor and Description |
---|
ServerSideSortRequestControl(boolean isCritical,
java.util.List<SortKey> sortKeys)
Creates a new server-side sort control that will sort the results based on
the provided set of sort keys.
|
ServerSideSortRequestControl(boolean isCritical,
SortKey... sortKeys)
Creates a new server-side sort control that will sort the results based on
the provided set of sort keys.
|
ServerSideSortRequestControl(Control control)
Creates a new server-side sort request control which is decoded from the
provided generic control.
|
ServerSideSortRequestControl(java.util.List<SortKey> sortKeys)
Creates a new server-side sort control that will sort the results based on
the provided set of sort keys.
|
ServerSideSortRequestControl(SortKey... sortKeys)
Creates a new server-side sort control that will sort the results based on
the provided set of sort keys.
|
Modifier and Type | Method and Description |
---|---|
static ServerSideSortRequestControl |
decodeJSONControl(JSONObject controlObject,
boolean strict)
Attempts to decode the provided object as a JSON representation of a
server-side sort request control.
|
java.lang.String |
getControlName()
Retrieves the user-friendly name for this control, if available.
|
SortKey[] |
getSortKeys()
Retrieves the set of sort keys that define the desired order in which the
results should be returned.
|
JSONObject |
toJSONControl()
Retrieves a representation of this server-side sort request control as a
JSON object.
|
void |
toString(java.lang.StringBuilder buffer)
Appends a string representation of this LDAP control to the provided
buffer.
|
decode, decode, decodeControls, decodeJSONControl, deregisterDecodeableControl, encode, encodeControls, equals, getOID, getValue, hashCode, hasValue, isCritical, readFrom, registerDecodeableControl, registerDecodeableControl, toString, writeTo
@NotNull public static final java.lang.String SERVER_SIDE_SORT_REQUEST_OID
public ServerSideSortRequestControl(@NotNull SortKey... sortKeys)
sortKeys
- The set of sort keys to define the desired order in which
the results should be returned. It must not be
null
or empty.public ServerSideSortRequestControl(@NotNull java.util.List<SortKey> sortKeys)
sortKeys
- The set of sort keys to define the desired order in which
the results should be returned. It must not be
null
or empty.public ServerSideSortRequestControl(boolean isCritical, @NotNull SortKey... sortKeys)
isCritical
- Indicates whether this control should be marked
critical.sortKeys
- The set of sort keys to define the desired order in
which the results should be returned. It must not be
null
or empty.public ServerSideSortRequestControl(boolean isCritical, @NotNull java.util.List<SortKey> sortKeys)
isCritical
- Indicates whether this control should be marked
critical.sortKeys
- The set of sort keys to define the desired order in
which the results should be returned. It must not be
null
or empty.public ServerSideSortRequestControl(@NotNull Control control) throws LDAPException
control
- The generic control to be decoded as a server-side sort
request control.LDAPException
- If the provided control cannot be decoded as a
server-side sort request control.@NotNull public SortKey[] getSortKeys()
@NotNull public java.lang.String getControlName()
getControlName
in class Control
@NotNull public JSONObject toJSONControl()
oid
-- A mandatory string field whose value is the object
identifier for this control. For the server-side sort request control,
the OID is "1.2.840.113556.1.4.473".
control-name
-- An optional string field whose value is a
human-readable name for this control. This field is only intended for
descriptive purposes, and when decoding a control, the oid
field should be used to identify the type of control.
criticality
-- A mandatory Boolean field used to indicate
whether this control is considered critical.
value-base64
-- An optional string field whose value is a
base64-encoded representation of the raw value for this server-side
sort request control. Exactly one of the value-base64
and
value-json
fields must be present.
value-json
-- An optional JSON object field whose value is a
user-friendly representation of the value for this server-side sort
request control. Exactly one of the value-base64
and
value-json
fields must be present, and if the
value-json
field is used, then it will use the following
fields:
sort-keys
-- A mandatory array field whose values are JSON
objects used to specify the requested sort order. Each of the JSON
objects with the following fields:
attribute-name
-- A mandatory string field whose value
is the name of the attribute to use for sorting.
reverse-order
-- A mandatory Boolean field that
indicates whether the results should be sorted in descending
order rather than ascending.
matching-rule-id
-- An optional string field whose
value is the name or OID of the ordering matching rule to use
to perform the sorting.
toJSONControl
in class Control
@NotNull public static ServerSideSortRequestControl decodeJSONControl(@NotNull JSONObject controlObject, boolean strict) throws LDAPException
controlObject
- The JSON object to be decoded. It must not be
null
.strict
- Indicates whether to use strict mode when decoding
the provided JSON object. If this is true
,
then this method will throw an exception if the
provided JSON object contains any unrecognized
fields. If this is false
, then unrecognized
fields will be ignored.LDAPException
- If the provided JSON object cannot be parsed as a
valid server-side sort request control.