Package edu.byu.hbll.box
Class BoxQuery
- java.lang.Object
-
- edu.byu.hbll.box.BoxQuery
-
public class BoxQuery extends Object
Query for requesting documents from Box.There are two ways of querying box. The first is to request documents by id. When requesting by id, the limit is ignored. There will be a 1:1 representation of documents according to the ids. If a document is not processed for a given id, a placeholder will still appear for that id. Documents are always returned in the same order as the requested ids.
The second query type harvests documents by requesting and filtering all documents according to the cursor, facets and limit instructions. Documents are always returned in cursor order. Only processed documents are returned. For this query type, the ids, process and wait clauses are ignored.
If there are ids in the query, then the id query type is used.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BoxQuery.Order
Order ascending or descending.
-
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_CURSOR
static long
DEFAULT_CURSOR_DESC
static long
DEFAULT_LIMIT
static BoxQuery.Order
DEFAULT_ORDER
static boolean
DEFAULT_PROCESS
static Set<BoxDocument.Status>
DEFAULT_STATUSES
static boolean
DEFAULT_WAIT
static String
DOCUMENT_FIELD
static String
METADATA_FIELD
static String
METADATA_FIELD_CURSOR
static String
METADATA_FIELD_DEPENDENCIES
static String
METADATA_FIELD_FACETS
static String
METADATA_FIELD_GROUP_ID
static String
METADATA_FIELD_ID
static String
METADATA_FIELD_MODIFIED
static String
METADATA_FIELD_PROCESSED
static String
METADATA_FIELD_STATUS
static long
UNLIMITED
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BoxQuery
addFacet(Facet facet)
Adds filter facets.BoxQuery
addFacet(String name, String value)
Adds a filter facet.BoxQuery
addFacets(Facet... facets)
Adds filter facets.BoxQuery
addFacets(Collection<? extends Facet> facets)
Adds filter facets.BoxQuery
addField(String field)
Limit the document to only these fields.BoxQuery
addFields(String... fields)
Limit the document to only these fields.BoxQuery
addFields(Collection<String> fields)
Limit the document to only these fields.BoxQuery
addId(String id)
Adds an id to this query.BoxQuery
addIds(String... ids)
Adds ids to this query.BoxQuery
addIds(Collection<String> ids)
Adds ids to this query.BoxQuery
addStatus(BoxDocument.Status status)
Queries by these document statuses.BoxQuery
addStatuses(BoxDocument.Status... statuses)
Queries by these document statuses.BoxQuery
addStatuses(Collection<BoxDocument.Status> statuses)
Queries by these document statuses.BoxQuery
clearFacets()
Clears all the facets.BoxQuery
clearFields()
Clears all the fields.BoxQuery
clearIds()
Clears all the ids.BoxQuery
clearStatuses()
Clears all the statuses.Optional<Long>
getCursor()
Returns the cursor.long
getCursorOrDefault()
Returns the cursor or the default cursor if cursor not set.Set<Facet>
getFacets()
Returns the specified facets.Set<String>
getFields()
Returns the specified fields.List<String>
getIds()
Returns the specified ids.Optional<Long>
getLimit()
Returns the limit.long
getLimitOrDefault()
Returns the limit or the default limit if limit not set.Optional<Long>
getOffset()
Returns the offset.Optional<BoxQuery.Order>
getOrder()
Returns the sort order.BoxQuery.Order
getOrderOrDefault()
Returns the sort order.Set<BoxDocument.Status>
getStatuses()
Returns the specified statuses.Set<BoxDocument.Status>
getStatusesOrDefault()
Returns the statuses or the default statuses if none set.boolean
isAscendingOrder()
Returns whether or not the order is ascending.boolean
isDescendingOrder()
Returns whether or not the order is descending.boolean
isHarvestQuery()
Whether or not this is a harvest query rather than an ID query.boolean
isIdQuery()
Whether or not this is an ID query rather than harvest query.Optional<Boolean>
isProcess()
Whether or not to ask Box to (re)process the document now and return the result.Optional<Boolean>
isWait()
Whether or not to wait for documents to be processed.BoxQuery
setAscendingOrder()
Sets the order to be ascending (default).BoxQuery
setCursor(long cursor)
Sets the cursor.BoxQuery
setCursor(Long cursor)
Sets the cursor.BoxQuery
setDescendingOrder()
Sets the order to be descending.BoxQuery
setDocumentOnly()
Clears any set fields and adds the document field.BoxQuery
setFacets(Collection<? extends Facet> facets)
Adds filter facets.BoxQuery
setFields(Collection<String> fields)
Limit the document to only these fields.BoxQuery
setLimit(long limit)
Limits the number of documents returned to no more than this number.BoxQuery
setLimit(Long limit)
Limits the number of documents returned to no more than this number.BoxQuery
setMetadataOnly()
Clears any set fields and adds the box metadata field.BoxQuery
setOffset(long offset)
The number of documents to skip in the results set.BoxQuery
setOffset(Long offset)
The number of documents to skip in the results set.BoxQuery
setOrder(BoxQuery.Order order)
Sets the sort order.BoxQuery
setProcess(Boolean process)
Whether or not to ask Box to (re)process the document now and return the result.BoxQuery
setStatuses(Collection<BoxDocument.Status> statuses)
Sets statuses to be queried.BoxQuery
setUnlimited()
Sets the limit to UNLIMITED.BoxQuery
setWait(Boolean wait)
Whether or not to wait for Box to process the document before returning.
-
-
-
Field Detail
-
DEFAULT_LIMIT
public static final long DEFAULT_LIMIT
- See Also:
- Constant Field Values
-
DEFAULT_CURSOR
public static final long DEFAULT_CURSOR
- See Also:
- Constant Field Values
-
DEFAULT_CURSOR_DESC
public static final long DEFAULT_CURSOR_DESC
- See Also:
- Constant Field Values
-
DEFAULT_PROCESS
public static final boolean DEFAULT_PROCESS
- See Also:
- Constant Field Values
-
DEFAULT_WAIT
public static final boolean DEFAULT_WAIT
- See Also:
- Constant Field Values
-
DEFAULT_ORDER
public static final BoxQuery.Order DEFAULT_ORDER
-
DEFAULT_STATUSES
public static final Set<BoxDocument.Status> DEFAULT_STATUSES
-
UNLIMITED
public static final long UNLIMITED
- See Also:
- Constant Field Values
-
DOCUMENT_FIELD
public static final String DOCUMENT_FIELD
- See Also:
- Constant Field Values
-
METADATA_FIELD
public static final String METADATA_FIELD
- See Also:
- Constant Field Values
-
METADATA_FIELD_ID
public static final String METADATA_FIELD_ID
- See Also:
- Constant Field Values
-
METADATA_FIELD_STATUS
public static final String METADATA_FIELD_STATUS
- See Also:
- Constant Field Values
-
METADATA_FIELD_CURSOR
public static final String METADATA_FIELD_CURSOR
- See Also:
- Constant Field Values
-
METADATA_FIELD_PROCESSED
public static final String METADATA_FIELD_PROCESSED
- See Also:
- Constant Field Values
-
METADATA_FIELD_MODIFIED
public static final String METADATA_FIELD_MODIFIED
- See Also:
- Constant Field Values
-
METADATA_FIELD_FACETS
public static final String METADATA_FIELD_FACETS
- See Also:
- Constant Field Values
-
METADATA_FIELD_DEPENDENCIES
public static final String METADATA_FIELD_DEPENDENCIES
- See Also:
- Constant Field Values
-
METADATA_FIELD_GROUP_ID
public static final String METADATA_FIELD_GROUP_ID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BoxQuery
public BoxQuery()
Creates a new empty query.
-
BoxQuery
public BoxQuery(BoxQuery query)
Copy constructor.- Parameters:
query
- query to copy
-
BoxQuery
public BoxQuery(Collection<String> ids)
Creates a new query with the given ids.- Parameters:
ids
- the ids
-
BoxQuery
public BoxQuery(String... ids)
Creates a new query with the given ids.- Parameters:
ids
- the ids
-
-
Method Detail
-
addFacet
public BoxQuery addFacet(String name, String value)
Adds a filter facet. Facets across facet groups are ANDed. Facets within a facet group are ORed. Applicable only for harvest queries.- Parameters:
name
- name of the facet groupvalue
- value of the facet- Returns:
- this
-
addFacet
public BoxQuery addFacet(Facet facet)
Adds filter facets. Facets across facet groups are ANDed. Facets within a facet group are ORed. Applicable only for harvest queries.- Parameters:
facet
- the facet to add- Returns:
- this
-
addFacets
public BoxQuery addFacets(Facet... facets)
Adds filter facets. Facets across facet groups are ANDed. Facets within a facet group are ORed. Applicable only for harvest queries.- Parameters:
facets
- the facets to add- Returns:
- this
-
addFacets
public BoxQuery addFacets(Collection<? extends Facet> facets)
Adds filter facets. Facets across facet groups are ANDed. Facets within a facet group are ORed. Applicable only for harvest queries.- Parameters:
facets
- the facets to add- Returns:
- this
-
addField
public BoxQuery addField(String field)
Limit the document to only these fields. Dot notation.- Parameters:
field
- the field to add- Returns:
- this
-
addFields
public BoxQuery addFields(Collection<String> fields)
Limit the document to only these fields. Dot notation.- Parameters:
fields
- the fields to add- Returns:
- this
-
addFields
public BoxQuery addFields(String... fields)
Limit the document to only these fields. Dot notation.- Parameters:
fields
- the fields to add- Returns:
- this
-
addId
public BoxQuery addId(String id)
Adds an id to this query.- Parameters:
id
- the id to add- Returns:
- this
-
addIds
public BoxQuery addIds(Collection<String> ids)
Adds ids to this query.- Parameters:
ids
- the ids to add- Returns:
- this
-
addIds
public BoxQuery addIds(String... ids)
Adds ids to this query.- Parameters:
ids
- the ids to add- Returns:
- this
-
addStatus
public BoxQuery addStatus(BoxDocument.Status status)
Queries by these document statuses.- Parameters:
status
- the status to add- Returns:
- this
-
addStatuses
public BoxQuery addStatuses(BoxDocument.Status... statuses)
Queries by these document statuses.- Parameters:
statuses
- the statuses to set- Returns:
- this
-
addStatuses
public BoxQuery addStatuses(Collection<BoxDocument.Status> statuses)
Queries by these document statuses.- Parameters:
statuses
- the statuses to set- Returns:
- this
-
clearFacets
public BoxQuery clearFacets()
Clears all the facets.- Returns:
- this
-
clearFields
public BoxQuery clearFields()
Clears all the fields.- Returns:
- this
-
clearIds
public BoxQuery clearIds()
Clears all the ids.- Returns:
- this
-
clearStatuses
public BoxQuery clearStatuses()
Clears all the statuses.- Returns:
- this
-
getCursor
public Optional<Long> getCursor()
Returns the cursor. If null, the cursor was not explicitly set.- Returns:
- the cursor
-
getCursorOrDefault
public long getCursorOrDefault()
Returns the cursor or the default cursor if cursor not set.- Returns:
- the limit
-
getOrder
public Optional<BoxQuery.Order> getOrder()
Returns the sort order.- Returns:
- the order
-
getOrderOrDefault
public BoxQuery.Order getOrderOrDefault()
Returns the sort order.- Returns:
- the order
-
getLimit
public Optional<Long> getLimit()
Returns the limit. If null, no limit was specified. Null does not mean NO_LIMIT. It means a default limit should be used.- Returns:
- the limit
-
getLimitOrDefault
public long getLimitOrDefault()
Returns the limit or the default limit if limit not set.- Returns:
- the limit
-
getStatuses
public Set<BoxDocument.Status> getStatuses()
Returns the specified statuses.- Returns:
- the statuses
-
getStatusesOrDefault
public Set<BoxDocument.Status> getStatusesOrDefault()
Returns the statuses or the default statuses if none set.- Returns:
- the statuses
-
isAscendingOrder
public boolean isAscendingOrder()
Returns whether or not the order is ascending.- Returns:
- whether or not the order is ascending
-
isDescendingOrder
public boolean isDescendingOrder()
Returns whether or not the order is descending.- Returns:
- whether or not the order is descending
-
isHarvestQuery
public boolean isHarvestQuery()
Whether or not this is a harvest query rather than an ID query.- Returns:
- whether or not is a harvest query
-
isIdQuery
public boolean isIdQuery()
Whether or not this is an ID query rather than harvest query.- Returns:
- whether or not is an ID query
-
isProcess
public Optional<Boolean> isProcess()
Whether or not to ask Box to (re)process the document now and return the result. Not valid for harvest type queries- Returns:
- the process
-
isWait
public Optional<Boolean> isWait()
Whether or not to wait for documents to be processed.- Returns:
- the wait
-
setAscendingOrder
public BoxQuery setAscendingOrder()
Sets the order to be ascending (default).- Returns:
- this
-
setDescendingOrder
public BoxQuery setDescendingOrder()
Sets the order to be descending.- Returns:
- this
-
setCursor
public BoxQuery setCursor(long cursor)
Sets the cursor. Documents are ordered by cursor ascending so this is used for paging. Only documents greater than or equal to this cursor will be returned. Applicable only for harvest queries.- Parameters:
cursor
- the cursor to set- Returns:
- this
-
setCursor
public BoxQuery setCursor(Long cursor)
Sets the cursor. Documents are ordered by cursor ascending so this is used for paging. Only documents greater than or equal to this cursor will be returned. Applicable only for harvest queries.- Parameters:
cursor
- the cursor to set- Returns:
- this
-
setDocumentOnly
public BoxQuery setDocumentOnly()
Clears any set fields and adds the document field.- Returns:
- this
-
setFacets
public BoxQuery setFacets(Collection<? extends Facet> facets)
Adds filter facets. Facets across facet groups are ANDed. Facets within a facet group are ORed. Applicable only for harvest queries.- Parameters:
facets
- the facets to add- Returns:
- this
-
setFields
public BoxQuery setFields(Collection<String> fields)
Limit the document to only these fields. Dot notation.- Parameters:
fields
- the fields to add- Returns:
- this
-
setLimit
public BoxQuery setLimit(long limit)
Limits the number of documents returned to no more than this number. This is effectively the page size. A limit ofUNLIMITED
means return all documents. Applicable only for harvest queries.- Parameters:
limit
- the limit to set- Returns:
- this
-
setLimit
public BoxQuery setLimit(Long limit)
Limits the number of documents returned to no more than this number. This is effectively the page size. A limit ofUNLIMITED
means return all documents. Applicable only for harvest queries.- Parameters:
limit
- the limit to set- Returns:
- this
-
setOffset
public BoxQuery setOffset(long offset)
The number of documents to skip in the results set.- Parameters:
offset
- the offset to set- Returns:
- this
-
setOffset
public BoxQuery setOffset(Long offset)
The number of documents to skip in the results set.- Parameters:
offset
- the offset to set- Returns:
- this
-
setOrder
public BoxQuery setOrder(BoxQuery.Order order)
Sets the sort order.- Parameters:
order
- the order to set- Returns:
- this
-
setMetadataOnly
public BoxQuery setMetadataOnly()
Clears any set fields and adds the box metadata field.- Returns:
- this
-
setProcess
public BoxQuery setProcess(Boolean process)
Whether or not to ask Box to (re)process the document now and return the result. Not valid for harvest type queries.- Parameters:
process
- the process to set- Returns:
- this
-
setStatuses
public BoxQuery setStatuses(Collection<BoxDocument.Status> statuses)
Sets statuses to be queried.- Parameters:
statuses
- the statuses to set- Returns:
- this
-
setUnlimited
public BoxQuery setUnlimited()
Sets the limit to UNLIMITED. Same as limit(BoxQuery.UNLIMITED).- Returns:
- this
-
-