public class DBSDocument extends BaseDocument<State>
Document
for Document-Based Storage. The document is stored as a JSON-like Map. The keys
of the Map are the property names (including special names for system properties), and the values Map are
Serializable values, either:
BaseDocument.BlobWriteContext<T extends StateAccessor>, BaseDocument.BlobWriteInfo<T extends StateAccessor>, BaseDocument.StateBlobAccessor, BaseDocument.Visit
Document.BlobAccessor, Document.WriteContext
BLOB_DATA, BLOB_DIGEST, BLOB_ENCODING, BLOB_LENGTH, BLOB_MIME_TYPE, BLOB_NAME, DC_ISSUED, DC_MODIFIED, DC_PREFIX, EMPTY_STRING_ARRAY, FULLTEXT_BINARYTEXT_PROP, FULLTEXT_JOBID_PROP, FULLTEXT_SIMPLETEXT_PROP, LOCK_CREATED_PROP, LOCK_OWNER_PROP, MISC_LIFECYCLE_STATE_PROP, NO_DIRTY, NON_CANONICAL_INDEX, RELATED_TEXT, RELATED_TEXT_ID, RELATED_TEXT_RESOURCES, TOKEN_SEP, VERSION_WRITABLE_PROPS
Constructor and Description |
---|
DBSDocument(DBSDocumentState docState,
DocumentType type,
DBSSession session,
boolean readonly) |
Modifier and Type | Method and Description |
---|---|
Document |
addChild(String name,
String typeName)
Creates a new child document of the given type.
|
boolean |
addFacet(String facet)
Adds a facet to this document.
|
Document |
checkIn(String label,
String checkinComment)
Creates a new version.
|
void |
checkOut() |
boolean |
equals(Object other) |
void |
followTransition(String transition)
Follows a given life cycle transition.
|
Set<String> |
getAllFacets()
Gets the facets available on this document (from the type and the instance facets).
|
Collection<String> |
getAllowedStateTransitions()
Returns the allowed state transitions for this document.
|
Document |
getBaseVersion()
Gets the version to which a checked in document is linked.
|
String |
getChangeToken()
Gets the current change token for this document.
|
String |
getCheckinComment()
Gets the version check in comment of this document if it's a version or a proxy.
|
protected State |
getChild(State state,
String name,
Type type)
Gets a child state.
|
Document |
getChild(String name)
Gets a child document given its name.
|
protected List<State> |
getChildAsList(State state,
String name)
Gets a child state which is a list.
|
protected State |
getChildForWrite(State state,
String name,
Type type)
Gets a child state into which we will want to write data.
|
List<Document> |
getChildren()
Gets the children of the document.
|
List<String> |
getChildrenIds()
Gets a list of the children ids.
|
protected Lock |
getDocumentLock()
Gets the lock from this recently created and unsaved document.
|
String[] |
getFacets()
Gets the facets defined on this document instance.
|
Document |
getLastVersion()
Gets the last version of this document.
|
String |
getLifeCyclePolicy()
Gets the life cycle policy of this document.
|
String |
getLifeCycleState()
Gets the life cycle state of this document.
|
String |
getName()
Gets the name of this document.
|
Document |
getParent()
Gets the parent document, or
null if this is the root document. |
String |
getPath()
Gets the path of this document.
|
Long |
getPos()
Gets the document's position in its containing folder (if ordered).
|
Serializable |
getPropertyValue(String name)
Gets a simple property value.
|
protected List<Schema> |
getProxySchemas()
Gets the list of proxy schemas, if this is a proxy.
|
protected static String |
getProxyUserVisibleChangeToken(String proxyToken,
String targetToken) |
String |
getRepositoryName()
Gets the repository in which the document lives.
|
protected String |
getSchema(String xpath) |
protected static Set<String> |
getSchemas(DocumentType type,
List<Object> facets) |
Session |
getSession()
Gets the session that owns this document.
|
Document |
getSourceDocument()
Gets the source for this document.
|
protected DBSDocumentState |
getStateOrTarget()
Gets the target state if this is a proxy, or the regular state otherwise.
|
protected DBSDocumentState |
getStateOrTarget(String xpath) |
protected DBSDocumentState |
getStateOrTarget(Type type) |
protected DBSDocumentState |
getStateOrTargetForSchema(String schema)
Checks if the given schema should be resolved on the proxy or the target.
|
<T extends Serializable> |
getSystemProp(String name,
Class<T> type)
Gets a system property.
|
DBSDocument |
getTargetDocument()
Gets the document (version or live document) to which this proxy points.
|
protected String |
getTargetDocumentId() |
DocumentType |
getType()
Gets the type of this document.
|
String |
getUUID()
Gets this document's UUID.
|
Object |
getValue(String xpath)
Gets a property value.
|
Document |
getVersion(String label)
Gets a version of this document, given its label.
|
Calendar |
getVersionCreationDate()
Gets the version creation date of this document if it's a version or a proxy.
|
String |
getVersionLabel()
Gets the version label.
|
List<Document> |
getVersions()
Gets the versions for this document.
|
String |
getVersionSeriesId()
Gets the version series id.
|
List<String> |
getVersionsIds()
Gets the list of version ids for this document.
|
Document |
getWorkingCopy()
Gets the working copy for this document.
|
boolean |
hasChild(String name)
Checks whether this document has a child of the given name.
|
boolean |
hasChildren()
Tests if the document has any children.
|
boolean |
hasFacet(String facet)
Checks whether this document has a given facet, either from its type or added on the instance.
|
int |
hashCode() |
protected String |
internalName(String name)
Finds the internal name to use to refer to this property.
|
boolean |
isCheckedOut()
Checks whether this document is checked out.
|
protected boolean |
isEqualOnVersion(Object ob,
String key) |
boolean |
isFolder()
Checks whether this document is a folder.
|
boolean |
isLatestMajorVersion()
Checks whether this document is the latest major version.
|
boolean |
isLatestVersion()
Checks whether this document is the latest version.
|
boolean |
isMajorVersion()
Checks whether this document is a major version.
|
boolean |
isProxy()
Checks whether or not this document is a proxy.
|
boolean |
isReadOnly()
Checks whether this document is readonly or not.
|
protected boolean |
isSchemaForProxy(String schema) |
boolean |
isVersion()
Checks whether this document is a version document.
|
boolean |
isVersionSeriesCheckedOut()
Checks if there is a checked out working copy for the version series of this document.
|
void |
markUserChange()
Marks the document as being modified by a user change.
|
void |
orderBefore(String src,
String dest)
Orders the given source child before the destination child.
|
void |
readDocumentPart(DocumentPart dp)
Loads a
DocumentPart from storage. |
Map<String,Serializable> |
readPrefetch(ComplexType complexType,
Set<String> xpaths)
Reads a set of prefetched fields.
|
void |
remove()
Removes this document and all its children, if any.
|
protected Lock |
removeDocumentLock(String owner)
Removes a lock from this recently created and unsaved document.
|
boolean |
removeFacet(String facet)
Removes a facet from this document.
|
void |
restore(Document version)
Replaces this document's content with the version specified.
|
void |
setCurrentLifeCycleState(String lifeCycleState)
Sets the life cycle state of this document.
|
protected Lock |
setDocumentLock(Lock lock)
Sets a lock on this recently created and unsaved document.
|
void |
setLifeCyclePolicy(String policy)
Sets the life cycle policy of this document.
|
void |
setPropertyValue(String name,
Serializable value)
Sets a simple property value.
|
void |
setReadOnly(boolean readonly)
Sets this document as readonly or not.
|
void |
setSystemProp(String name,
Serializable value)
Sets a system property.
|
void |
setTargetDocument(Document target)
Sets the document (version or live document) to which this proxy points.
|
void |
setValue(String xpath,
Object value)
Sets a property value.
|
String |
toString() |
protected void |
updateList(State state,
String name,
Field field,
String xpath,
List<Object> values)
Update a list.
|
protected List<State> |
updateList(State state,
String name,
Property property)
Update a list.
|
protected static boolean |
validateProxyChangeToken(String userVisibleChangeToken,
DBSDocumentState proxyState,
DBSDocumentState targetState) |
boolean |
validateUserVisibleChangeToken(String userVisibleChangeToken)
Validates that the passed user-visible change token is compatible with the one for this document.
|
void |
visitBlobs(Consumer<Document.BlobAccessor> blobVisitor)
Visits all the blobs of this document and calls the passed blob visitor on each one.
|
boolean |
writeDocumentPart(DocumentPart dp,
Document.WriteContext writeContext)
Writes a
DocumentPart to storage. |
buildUserVisibleChangeToken, canonicalXPath, checkReadOnlyIgnoredWrite, clearDirtyFlags, getBlobInfo, getLegacyChangeToken, getLock, getValueBlob, getValueComplex, getValueField, getValueObject, getWriteContext, isVersionWritableProperty, readComplexProperty, readPrefetch, readPrefetch, readPrefetchField, removeLock, setBlobInfo, setLock, setValueBlob, setValueComplex, setValueField, setValueObject, typedArray, updateChangeToken, validateLegacyChangeToken, validateUserVisibleChangeToken, visitBlobs, writeComplexProperty, writeComplexProperty
public static final String SYSPROP_FULLTEXT_SIMPLE
public static final String SYSPROP_FULLTEXT_BINARY
public static final String SYSPROP_FULLTEXT_JOBID
public static final String KEY_PREFIX
public static final String KEY_ID
public static final String KEY_PARENT_ID
public static final String KEY_ANCESTOR_IDS
public static final String KEY_PRIMARY_TYPE
public static final String KEY_MIXIN_TYPES
public static final String KEY_NAME
public static final String KEY_POS
public static final String KEY_ACP
public static final String KEY_ACL_NAME
public static final String KEY_PATH_INTERNAL
public static final String KEY_ACL
public static final String KEY_ACE_USER
public static final String KEY_ACE_PERMISSION
public static final String KEY_ACE_GRANT
public static final String KEY_ACE_CREATOR
public static final String KEY_ACE_BEGIN
public static final String KEY_ACE_END
public static final String KEY_ACE_STATUS
public static final String KEY_READ_ACL
public static final String KEY_IS_CHECKED_IN
public static final String KEY_IS_VERSION
public static final String KEY_IS_LATEST_VERSION
public static final String KEY_IS_LATEST_MAJOR_VERSION
public static final String KEY_MAJOR_VERSION
public static final String KEY_MINOR_VERSION
public static final String KEY_VERSION_SERIES_ID
public static final String KEY_VERSION_CREATED
public static final String KEY_VERSION_LABEL
public static final String KEY_VERSION_DESCRIPTION
public static final String KEY_BASE_VERSION_ID
public static final String KEY_IS_PROXY
public static final String KEY_PROXY_TARGET_ID
public static final String KEY_PROXY_VERSION_SERIES_ID
public static final String KEY_PROXY_IDS
public static final String KEY_LIFECYCLE_POLICY
public static final String KEY_LIFECYCLE_STATE
public static final String KEY_LOCK_OWNER
public static final String KEY_LOCK_CREATED
public static final String KEY_SYS_CHANGE_TOKEN
public static final String KEY_CHANGE_TOKEN
public static final String KEY_DC_MODIFIED
public static final String KEY_BLOB_NAME
public static final String KEY_BLOB_MIME_TYPE
public static final String KEY_BLOB_ENCODING
public static final String KEY_BLOB_DIGEST
public static final String KEY_BLOB_LENGTH
public static final String KEY_BLOB_DATA
public static final String KEY_FULLTEXT_SIMPLE
public static final String KEY_FULLTEXT_BINARY
public static final String KEY_FULLTEXT_JOBID
public static final String KEY_FULLTEXT_SCORE
public static final String APPLICATION_OCTET_STREAM
public static final Long INITIAL_SYS_CHANGE_TOKEN
public static final Long INITIAL_CHANGE_TOKEN
protected final DBSDocumentState docState
protected final DocumentType type
protected final List<Schema> proxySchemas
protected final DBSSession session
protected boolean readonly
protected static final Map<String,String> systemPropNameMap
public static final String CHANGE_TOKEN_PROXY_SEP
public DBSDocument(DBSDocumentState docState, DocumentType type, DBSSession session, boolean readonly)
public DocumentType getType()
Document
public Session getSession()
Document
public String getRepositoryName()
Document
protected List<Schema> getProxySchemas()
BaseDocument
getProxySchemas
in class BaseDocument<State>
null
public String getUUID()
Document
public String getName()
Document
public Long getPos()
Document
public Document getParent()
Document
null
if this is the root document.null
public boolean isProxy()
Document
true
if this document is a proxy, false
otherwisepublic boolean isVersion()
Document
true
if it's a version, false
otherwisepublic String getPath()
Document
public Document getChild(String name)
Document
Throws DocumentNotFoundException
if the document could not be found.
name
- the name of the child to retrievepublic List<Document> getChildren()
Document
Returns an empty list for non-folder documents.
public List<String> getChildrenIds()
Document
Returns an empty list for non-folder documents.
public boolean hasChild(String name)
Document
Returns false
for non-folder documents.
name
- the name of the child to checktrue
if the child exists, false
otherwisepublic boolean hasChildren()
Document
Returns false
for non-folder documents.
true
if the document has children, false
otherwisepublic Document addChild(String name, String typeName)
Document
Throws an error if this document is not a folder.
name
- the name of the new child to createtypeName
- the type of the child to createpublic void orderBefore(String src, String dest)
Document
Both source and destination must be names that point to child documents of this document. The source document
will be placed before the destination one. If destination is null
, the source document will be appended
at the end of the children list.
src
- the document to movedest
- the document before which to place the source documentpublic Serializable getPropertyValue(String name)
Document
For more generic properties described by an xpath, use Document.getValue(java.lang.String)
instead.
name
- the name of the property to getnull
if the property is not setDocument.getValue(java.lang.String)
public void setPropertyValue(String name, Serializable value)
Document
For more generic properties described by an xpath, use Document.setValue(java.lang.String, java.lang.Object)
instead.
name
- the name of the property to setvalue
- the value to setDocument.setValue(java.lang.String, java.lang.Object)
protected State getChild(State state, String name, Type type)
BaseDocument
getChild
in class BaseDocument<State>
state
- the parent statename
- the child nametype
- the child's typenull
if it doesn't existprotected State getChildForWrite(State state, String name, Type type) throws PropertyException
BaseDocument
Creates it if needed.
getChildForWrite
in class BaseDocument<State>
state
- the parent statename
- the child nametype
- the child's typenull
PropertyException
protected List<State> getChildAsList(State state, String name)
BaseDocument
getChildAsList
in class BaseDocument<State>
state
- the parent statename
- the child namenull
protected void updateList(State state, String name, Field field, String xpath, List<Object> values)
BaseDocument
updateList
in class BaseDocument<State>
state
- the parent statename
- the child namefield
- the list element typexpath
- the xpath of this listvalues
- the valuesprotected List<State> updateList(State state, String name, Property property) throws PropertyException
BaseDocument
updateList
in class BaseDocument<State>
state
- the parent statename
- the child nameproperty
- the propertyPropertyException
public Object getValue(String xpath) throws PropertyException
Document
The xpath may point to a partial path, in which case the value may be a complex List
or Map
.
xpath
- the xpath of the property to setnull
if the property is not setPropertyException
- if the property does not existpublic void setValue(String xpath, Object value) throws PropertyException
Document
The xpath may point to a partial path, in which case the value may be a complex List
or Map
.
xpath
- the xpath of the property to setvalue
- the value to setPropertyException
- if the property does not exist or the value is of the wrong typepublic void visitBlobs(Consumer<Document.BlobAccessor> blobVisitor) throws PropertyException
Document
PropertyException
public Document checkIn(String label, String checkinComment)
Document
label
- the version labelcheckinComment
- the checkin commentpublic void checkOut()
public List<String> getVersionsIds()
Document
public List<Document> getVersions()
Document
public Document getLastVersion()
Document
Returns null
if there is no version at all.
null
if there is no versionpublic Document getSourceDocument()
Document
For a version, it's the working copy.
For a proxy, it's the version the proxy points to.
public void restore(Document version)
Document
version
- the version to replace withpublic Document getVersion(String label)
Document
label
- the version labelpublic Document getBaseVersion()
Document
Returns null
for a checked out document or a version or a proxy.
null
public boolean isCheckedOut()
Document
true
if the document is checked out, or false
otherwisepublic String getVersionSeriesId()
Document
public Calendar getVersionCreationDate()
Document
null
if it's not a version or a proxypublic String getVersionLabel()
Document
public String getCheckinComment()
Document
null
if it's not a version or a proxypublic boolean isLatestVersion()
Document
true
if this is the latest version, or false
otherwisepublic boolean isMajorVersion()
Document
true
if this is a major version, or false
otherwisepublic boolean isLatestMajorVersion()
Document
true
if this is the latest major version, or false
otherwiseprotected boolean isEqualOnVersion(Object ob, String key)
public boolean isVersionSeriesCheckedOut()
Document
true
if there is a checked out working copypublic Document getWorkingCopy()
Document
public boolean isFolder()
Document
true
if the document is a folder, false
otherwisepublic void setReadOnly(boolean readonly)
Document
public boolean isReadOnly()
Document
public void remove()
Document
public String getLifeCycleState()
Document
public void setCurrentLifeCycleState(String lifeCycleState) throws LifeCycleException
Document
lifeCycleState
- the life cycle stateLifeCycleException
public String getLifeCyclePolicy()
Document
public void setLifeCyclePolicy(String policy) throws LifeCycleException
Document
policy
- the life cycle policyLifeCycleException
public void followTransition(String transition) throws LifeCycleException
Document
This will update the life cycle state of the document.
transition
- the name of the transition to followLifeCycleException
public Collection<String> getAllowedStateTransitions() throws LifeCycleException
Document
LifeCycleException
public void setSystemProp(String name, Serializable value)
Document
public <T extends Serializable> T getSystemProp(String name, Class<T> type)
Document
public String getChangeToken()
Document
protected static String getProxyUserVisibleChangeToken(String proxyToken, String targetToken)
public boolean validateUserVisibleChangeToken(String userVisibleChangeToken)
Document
false
if the change token is not validprotected static boolean validateProxyChangeToken(String userVisibleChangeToken, DBSDocumentState proxyState, DBSDocumentState targetState)
public void markUserChange()
Document
This causes an additional change token increment and check during save.
protected DBSDocumentState getStateOrTarget(Type type) throws PropertyException
PropertyException
protected DBSDocumentState getStateOrTarget(String xpath)
protected DBSDocumentState getStateOrTargetForSchema(String schema)
protected DBSDocumentState getStateOrTarget()
protected boolean isSchemaForProxy(String schema)
public void readDocumentPart(DocumentPart dp) throws PropertyException
Document
DocumentPart
from storage.
Reading data is done by DocumentPart
because of per-proxy schemas.
PropertyException
protected String internalName(String name)
BaseDocument
internalName
in class BaseDocument<State>
public Map<String,Serializable> readPrefetch(ComplexType complexType, Set<String> xpaths) throws PropertyException
Document
Reading data is done by ComplexType
because of per-proxy schemas.
PropertyException
public boolean writeDocumentPart(DocumentPart dp, Document.WriteContext writeContext) throws PropertyException
Document
DocumentPart
to storage.
Writing data is done by DocumentPart
because of per-proxy schemas.
true
if something changedPropertyException
public Set<String> getAllFacets()
Document
public String[] getFacets()
Document
public boolean hasFacet(String facet)
Document
facet
- the facet nametrue
if the document has the facetpublic boolean addFacet(String facet)
Document
Does nothing if the facet was already present on the document.
facet
- the facet nametrue
if the facet was added, or false
if it is already presentpublic boolean removeFacet(String facet)
Document
It's not possible to remove a facet coming from the document type.
facet
- the facet nametrue
if the facet was removed, or false
if it isn't present or is present on the type or
does not exitprotected static Set<String> getSchemas(DocumentType type, List<Object> facets)
public DBSDocument getTargetDocument()
Document
protected String getTargetDocumentId()
public void setTargetDocument(Document target)
Document
protected Lock getDocumentLock()
BaseDocument
getDocumentLock
in class BaseDocument<State>
null
if no lock is setprotected Lock setDocumentLock(Lock lock)
BaseDocument
setDocumentLock
in class BaseDocument<State>
lock
- the lock to setnull
if locking succeeded, or the existing lock if locking failedprotected Lock removeDocumentLock(String owner)
BaseDocument
removeDocumentLock
in class BaseDocument<State>
null
if there was no lock or if removal succeeded, or a lock if it blocks removal due to owner
mismatchCopyright © 2017 Nuxeo. All rights reserved.