Class BoxDocument
ObjectNode
. This internal document is the data of this
object and all other fields are metadata.- Author:
- Charles Draper
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Deserializer of BoxDocument for Jackson.static class
Serializer of BoxDocument for Jackson.static enum
Status of the document. -
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a new empty document.BoxDocument
(BoxDocument boxDocument) Copy Constructor.BoxDocument
(String id) Creates a new document initially in an UNPROCESSED state.BoxDocument
(String id, com.fasterxml.jackson.databind.node.ObjectNode document) Creates a new document initially in a READY state with the given internal document.BoxDocument
(String id, BoxDocument.Status status) Creates a new document with the given state. -
Method Summary
Modifier and TypeMethodDescriptionaddDependencies
(DocumentId... dependencies) Adds dependencies for this document.addDependencies
(Collection<? extends DocumentId> dependencies) Adds dependencies for this document.addDependency
(String sourceName, String id) Adds a dependency for this document.Adds a facet to this document.Adds multiple facets to the document.Adds multiple facets to the document.addFacets
(String name, Collection<String> values) Adds multiple facets to the document.addFacets
(Collection<? extends Facet> facets) Adds multiple facets to the document.addFacetsByQuery
(String name, String path) Adds a facet by querying the internal document using the given path.addFacetsByQuery
(Map<String, Set<String>> paths) Adds facets by querying the internal document using the given paths.Clears the set of dependencies.Clears the set of facets.boolean
Returns the cursor.Returns the dependencies.com.fasterxml.jackson.databind.node.ObjectNode
Returns the internal document.Returns the facets.getFacetValue
(String facetName) Returns the first value for the given facet.getFacetValues
(String facetName) Returns all values for the given facet.Returns the groupId.getId()
Returns the unique id of the document.Return the error message.Returns the modified date.Returns the processed date.Returns the status.boolean
Whether or not this document's dependencies differ from the give document's.byte[]
hash()
Hashes the document using SHA-256 including metadata, but excluding all volatile metadata fields (ie, cursor, modified, and processed).int
hashCode()
boolean
Whether or not this document is in the DELETED state.boolean
isError()
Whether or not this document is in the ERROR state.boolean
Whether or not this document's processing has completed.boolean
isReady()
Whether or not this document is in the READY state.boolean
Whether or not this document is in the UNPROCESSED state.boolean
Deprecated.boolean
matches
(Collection<Facet> facets) Determines if this document matches (or should be included in a result set) given the supplied facets.static BoxDocument
parse
(com.fasterxml.jackson.databind.node.ObjectNode json) Creates a new box document from the given json.static BoxDocument
parse
(InputStream json) Creates a new box document from the given json.static BoxDocument
Creates a new box document from the given json.Explicitly sets the status to deleted.Explicitly sets the status to error.setAsError
(String message) Explicitly sets the status to error and includes an error message.Explicitly sets the status to ready.Explicitly sets the status to unprocessed.Sets the cursor.setDependencies
(Collection<? extends DocumentId> dependencies) Clears dependencies and then adds these dependencies for this document.setDocument
(com.fasterxml.jackson.databind.node.ObjectNode document) Sets the internal document and modifies the status to READY if state not explicitly set elsewhere.setFacets
(Collection<? extends Facet> facets) Clears existing facets and then adds these facets to the document.setGroupId
(String groupId) Sets this document's group (used for orphan cleanup).Set the unique id of the document.setMessage
(String message) Sets the message if an error occurred.setModified
(Instant modified) Sets the modified date.setProcessed
(Instant processed) Sets the processed date.setStatus
(BoxDocument.Status status) Explicitly sets the status.com.fasterxml.jackson.databind.node.ObjectNode
toJson()
Serializes to anObjectNode
.com.fasterxml.jackson.databind.node.ObjectNode
toJson
(Collection<String> fields) Returns theObjectNode
representation of this document with the given field projection applied.toString()
toString
(Collection<String> fields) Returns the string representation of this document with the given field projection applied.com.fasterxml.jackson.databind.node.ObjectNode
Sets the status to READY if state not explicitly set elsewhere and returns the internal document.
-
Constructor Details
-
BoxDocument
protected BoxDocument()Creates a new empty document. -
BoxDocument
Creates a new document initially in an UNPROCESSED state.- Parameters:
id
- the unique id of the document
-
BoxDocument
Creates a new document with the given state.- Parameters:
id
- the unique id of the documentstatus
- the status of the document
-
BoxDocument
Creates a new document initially in a READY state with the given internal document.- Parameters:
id
- the unique id of the documentdocument
- the processed document
-
BoxDocument
Copy Constructor.- Parameters:
boxDocument
- the box document to copy
-
-
Method Details
-
toJson
public com.fasterxml.jackson.databind.node.ObjectNode toJson()Serializes to anObjectNode
.- Returns:
- a json representation of this document
-
toJson
Returns theObjectNode
representation of this document with the given field projection applied. Calling this method with an empty projection returns the entire document.Note: projection follows MongoDB's projection pattern (https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/). The projection is only applied to child nodes of objects. Arrays or nested arrays are iterated over and projection picks up again when objects are found. Primitive values that are not part of a terminal projection are removed.
- Parameters:
fields
- collection of dot-notated fields representing the projection- Returns:
- the node representation of this document with projection applied.
-
parse
Creates a new box document from the given json.- Parameters:
json
- the json to parse- Returns:
- the parsed box document
-
parse
Creates a new box document from the given json.- Parameters:
json
- the json to parse- Returns:
- the parsed box document
-
parse
Creates a new box document from the given json.- Parameters:
json
- the json to parse- Returns:
- the parsed box document
-
hash
public byte[] hash()Hashes the document using SHA-256 including metadata, but excluding all volatile metadata fields (ie, cursor, modified, and processed).- Returns:
- the digest
-
hasDifferentDependencies
Whether or not this document's dependencies differ from the give document's.- Parameters:
o
- the document to compare- Returns:
- whether or not the dependencies differ
-
isProcessed
public boolean isProcessed()Whether or not this document's processing has completed. That is whether the document is in a READY or DELETED state.- Returns:
- if in a ready or deleted state
-
isUnProcessed
Deprecated.useisUnprocessed()
insteadWhether or not this document is in the UNPROCESSED state.- Returns:
- if in the UNPROCESSED state
-
isUnprocessed
public boolean isUnprocessed()Whether or not this document is in the UNPROCESSED state.- Returns:
- if in the UNPROCESSED state
-
isDeleted
public boolean isDeleted()Whether or not this document is in the DELETED state.- Returns:
- if in the DELETED state
-
isError
public boolean isError()Whether or not this document is in the ERROR state.- Returns:
- if in the ERROR state
-
isReady
public boolean isReady()Whether or not this document is in the READY state.- Returns:
- if in the READY state
-
matches
Determines if this document matches (or should be included in a result set) given the supplied facets. In order to match, the document must have at least one facet from each facet group represented in the supplied facets. If the supplied facet list is empty, the document will match.- Parameters:
facets
- the facets to test the document against- Returns:
- whether or not this document matches the given facets
-
setAsDeleted
Explicitly sets the status to deleted.- Returns:
- this
-
setAsUnprocessed
Explicitly sets the status to unprocessed.- Returns:
- this
-
setAsReady
Explicitly sets the status to ready.- Returns:
- this
-
setAsError
Explicitly sets the status to error.- Returns:
- this
-
setAsError
Explicitly sets the status to error and includes an error message.- Parameters:
message
- the error message- Returns:
- this
-
addDependency
Adds a dependency for this document.- Parameters:
sourceName
- the sourceName of the dependency to add.id
- the id of the dependency to add.- Returns:
- this
-
addDependencies
Adds dependencies for this document.- Parameters:
dependencies
- the dependencies to add.- Returns:
- this
-
addDependencies
Adds dependencies for this document.- Parameters:
dependencies
- the dependencies to add.- Returns:
- this
-
setDependencies
Clears dependencies and then adds these dependencies for this document.- Parameters:
dependencies
- the dependencies to add.- Returns:
- this
-
addFacet
Adds a facet to this document.- Parameters:
name
- name of the facet groupvalue
- value of the facet- Returns:
- this
-
addFacets
Adds multiple facets to the document.- Parameters:
name
- name of the facet groupvalues
- value(s) of the facet- Returns:
- this
-
addFacets
Adds multiple facets to the document.- Parameters:
name
- name of the facet groupvalues
- values of the facet- Returns:
- this
-
addFacets
Adds multiple facets to the document.- Parameters:
facets
- the facets to add- Returns:
- this
-
addFacets
Adds multiple facets to the document.- Parameters:
facets
- the facets to add- Returns:
- this
-
setFacets
Clears existing facets and then adds these facets to the document.- Parameters:
facets
- the facets to add- Returns:
- this
-
addFacetsByQuery
Adds a facet by querying the internal document using the given path.- Parameters:
name
- name of facetpath
- path to field value in dot notation- Returns:
- this
-
addFacetsByQuery
Adds facets by querying the internal document using the given paths.- Parameters:
paths
- the paths to the field values in dot notation, key is name of facet, value is set of paths- Returns:
- this
-
getId
Returns the unique id of the document.- Returns:
- the unique id of the document
-
setId
Set the unique id of the document.- Parameters:
id
- the id of the document- Returns:
- this
-
getDocument
public com.fasterxml.jackson.databind.node.ObjectNode getDocument()Returns the internal document. Initialized to an empty object.- Returns:
- the internal document
-
setDocument
Sets the internal document and modifies the status to READY if state not explicitly set elsewhere.- Parameters:
document
- the document to set- Returns:
- this
-
withDocument
public com.fasterxml.jackson.databind.node.ObjectNode withDocument()Sets the status to READY if state not explicitly set elsewhere and returns the internal document. The internal documents is initially empty if not already set elsewhere.- Returns:
- internal document
-
getCursor
Returns the cursor.- Returns:
- the cursor
-
setCursor
Sets the cursor.When processing a document, this should only be updated if the box document actually changed since last time. This should generally be left blank because Box will make that determination and set it appropriately when saving. If it's not blank, Box will honor the set value.
- Parameters:
cursor
- the cursor to set- Returns:
- this
-
getModified
Returns the modified date.- Returns:
- when the document was last modified
-
setModified
Sets the modified date.When processing a document, this should only be updated if the box document actually changed since last time. This should generally be left blank because Box will make that determination and set it appropriately when saving. If it's not blank, Box will honor the set value.
- Parameters:
modified
- the modified to set- Returns:
- this
-
getProcessed
Returns the processed date.- Returns:
- the processed
-
setProcessed
Sets the processed date.When processing a document, this can be left blank because Box will set it appropriately when saving. If it's not blank, Box will honor the set value.
- Parameters:
processed
- the processed to set- Returns:
- this
-
getMessage
Return the error message.- Returns:
- the error
-
setMessage
Sets the message if an error occurred.- Parameters:
message
- the message to set if an error occurred- Returns:
- this
-
getFacets
Returns the facets.- Returns:
- the facets
-
getFacetValues
Returns all values for the given facet. An empty set is returned if no facet of the given name exists.- Parameters:
facetName
- the facet name- Returns:
- the facet values
-
getFacetValue
Returns the first value for the given facet.- Parameters:
facetName
- the facet name- Returns:
- the first facet value
-
getDependencies
Returns the dependencies.- Returns:
- the dependencies
-
getGroupId
Returns the groupId.- Returns:
- the groupId
-
setGroupId
Sets this document's group (used for orphan cleanup).- Parameters:
groupId
- the groupId to set- Returns:
- this
-
getStatus
Returns the status.- Returns:
- the status
-
setStatus
Explicitly sets the status.- Parameters:
status
- the status to set- Returns:
- this
-
clearFacets
Clears the set of facets.- Returns:
- this
-
clearDependencies
Clears the set of dependencies.- Returns:
- this
-
hashCode
public int hashCode() -
equals
This method follows the same comparison Box uses internally to determine if the document has been modified. All fields are compared except for the volatile fields cursor, modified, and processed. The two documents must serialize the same in order for them to be considered equal.
-
toString
-
toString
Returns the string representation of this document with the given field projection applied. Calling this method with an empty projection returns the entire document.Note: projection follows MongoDB's projection pattern (https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/). The projection is only applied to child nodes of objects. Arrays or nested arrays are iterated over and projection picks up again when objects are found. Primitive values that are not part of a terminal projection are removed.
- Parameters:
fields
- collection of dot-notated fields representing the projection- Returns:
- the string representation of this document with projection applied.
-
isUnprocessed()
instead