public class QueryRequest extends VaultRequest
Available query methods:
query(String)
- query with pagination, use getQueryPage(String)
for pagination of the results
See query(String)
for example request and response methods, including reading of the resulting
data and handling of the X-VaultAPI-DescribeQuery parameter.
Modifier and Type | Class and Description |
---|---|
static class |
QueryRequest.RecordPropertyType
Download option for Document Token
|
Modifier and Type | Field and Description |
---|---|
static String |
HTTP_HEADER_VAULT_DESCRIBE_QUERY
X-VaultAPI-DescribeQuery Set to true to include static field metadata in the response
|
static String |
HTTP_HEADER_VAULT_RECORD_PROPERTIES
X-VaultAPI-RecordProperties If present, the response includes the record properties object.
|
HTTP_HEADER_AUTHORIZATION, HTTP_HEADER_VAULT_CLIENT_ID, vaultClient
Modifier and Type | Method and Description |
---|---|
QueryResponse |
getQueryPage(String pageUrl)
Get Query Page
|
QueryResponse |
query(String vql)
VQL Query
|
QueryRequest |
setDescribeQuery(Boolean queryDescribe)
X-VaultAPI-DescribeQuery
|
QueryRequest |
setRecordProperties(QueryRequest.RecordPropertyType recordPropertyType)
X-VaultAPI-RecordProperties
|
getBaseObjectMapper, send, send, sendReturnBinary, sendReturnBinary, sendToFile, sendToFile, setVaultClient
public static final String HTTP_HEADER_VAULT_DESCRIBE_QUERY
public static final String HTTP_HEADER_VAULT_RECORD_PROPERTIES
public QueryResponse query(String vql)
Perform a Vault query request. Subsequent queries and pagination
are needed to retrieve the full result set if the total records returned exceed the "pagesize"
parameter in the response. See getQueryPage(String)
.
Returned records can be retrieved via the "getData" method in the response.
vql
- The fully formed query stringPOST /api/{version}/query
QueryResponse response = vaultClient.newRequest(QueryRequest.class) .setDescribeQuery(true) .query(query);
Example display of query results, including sub-query results List<QueryResponse.QueryResult> results = response.getData(); System.out.println(spacer + "Total records = " + results.size()); String spacer = StringUtils.leftPad("",level,"\t"); * int i = 0; for (QueryResponse.QueryResult queryResult : results) { i++; System.out.println(spacer + "------- " + i + " -------"); for (String fieldName : queryResult.getFieldNames()) { Object data = queryResult.get(fieldName); if (data instanceof LinkedHashMap) { QueryResponse subQuery = queryResult.getSubQuery(fieldName); if (subQuery != null) { System.out.println(spacer + fieldName + " = "); // Get the subquery results using subQuery.getData() } else { System.out.println(spacer + fieldName + " = null"); } } else { System.out.println(spacer + fieldName + " = " + queryResult.get(fieldName)); } } },
Example reading of pagination details System.out.println("PageSize " + response.getResponseDetails().getPageSize()); System.out.println("PageOffset " + response.getResponseDetails().getPageOffset()); System.out.println("Size " + response.getResponseDetails().getSize()); System.out.println("Total " + response.getResponseDetails().getTotal()); if (resp.getResponseDetails().getNextPage() != null) { System.out.println("Next page " + response.getResponseDetails().getNextPage()); System.out.println("Previous page " + response.getResponseDetails().getPreviousPage()); },
Example reading of X-VaultAPI-DescribeQuery results
The X-VaultAPI-DescribeQuery can be set via the setDescribeQuery(Boolean)
method, with an example response:
if (resp.getQueryDescribe() != null) {
System.out.println("Object Name = " + response.getQueryDescribe().getQueryObject().getName());
System.out.println("Object Label = " + response.getQueryDescribe().getQueryObject().getLabel());
for (ObjectField field : resp.getQueryDescribe().getFields()) {
System.out.println("\tField Name = " + field.getName());
System.out.println("\tField Label = " + field.getLabel());
}
}
public QueryResponse getQueryPage(String pageUrl)
Perform a paginated query based on the URL from a previous query (previous_page or next_page in the response details).
Note that this does not support described query, which should be read upon the first query call if needed.
pageUrl
- The URL from the previous_page or next_page parameter in the form
Example query URL format POST /query/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx?pagesize=10 &pageoffset=10
QueryResponse response = vaultClient.newRequest(QueryRequest.class).query(query); // Get the first pageoffset (assuming correct response and an pageoffset exists) resp = vaultClient.newRequest(QueryRequest.class).getQueryPage(response.getResponseDetails().getNextPage());
public QueryRequest setDescribeQuery(Boolean queryDescribe)
Set to true to include static field metadata in the response for the data record. If not specified, the response does not include any static field metadata. This option eliminates the need to make additional API calls to understand the shape of query response data.
queryDescribe
- True for a describeif (response.getQueryDescribe() != null) { System.out.println("Object Name = " + response.getQueryDescribe().getQueryObject().getName()); System.out.println("Object Label = " + response.getQueryDescribe().getQueryObject().getLabel()); for (ObjectField field : response.getQueryDescribe().getFields()) { System.out.println("\tField Name = " + field.getName()); System.out.println("\tField Label = " + field.getLabel()); } }
public QueryRequest setRecordProperties(QueryRequest.RecordPropertyType recordPropertyType)
If present, the response includes the record properties object. Possible values are all, hidden, redacted, and weblink. If omitted, the record properties object is not included in the response.
recordPropertyType
- record property typeif (response.getRecordProperties() != null) { for (RecordProperty recordProperty : response.getRecordProperties()) { System.out.println("\tId = " + recordProperty.getId()); System.out.println("\tHidden = " + String.join(",", recordProperty.getFieldProperties().get("hidden"))); } }
Copyright © 2021. All rights reserved.