public interface DocumentModel extends Serializable
The document model is made from several data models, each data model is bound to a schema. All the information about a document (like security) is expressed using schemas (and implicitly data models).
Data models are lazily loaded as they are needed. At document model creation only data models corresponding to the default schemas are loaded. The default schemas are configured in the type manager through extension points.
CoreSession
Modifier and Type | Interface and Description |
---|---|
static class |
DocumentModel.DocumentModelRefresh
Info fetched internally during a refresh.
|
Modifier and Type | Field and Description |
---|---|
static int |
REFRESH_ACP |
static int |
REFRESH_ACP_IF_LOADED |
static int |
REFRESH_ACP_LAZY |
static int |
REFRESH_ALL |
static int |
REFRESH_CONTENT |
static int |
REFRESH_CONTENT_IF_LOADED |
static int |
REFRESH_CONTENT_LAZY |
static int |
REFRESH_DEFAULT |
static int |
REFRESH_IF_LOADED |
static int |
REFRESH_LAZY |
static int |
REFRESH_PREFETCH |
static int |
REFRESH_STATE |
Modifier and Type | Method and Description |
---|---|
void |
accept(PropertyVisitor visitor,
Object arg)
Method that implement the visitor pattern.
|
boolean |
addFacet(String facet)
Adds a facet to the document instance.
|
void |
attach(String sid)
Reattaches a document impl to an existing session.
|
DocumentRef |
checkIn(VersioningOption option,
String checkinComment)
Checks in a document and returns the created version.
|
void |
checkOut()
Checks out a document.
|
DocumentModel |
clone()
Clone operation.
|
void |
copyContent(DocumentModel sourceDoc)
Copies all the data from a source document.
|
void |
copyContextData(DocumentModel otherDocument)
Copies the context data from given document to this document.
|
void |
detach(boolean loadAll)
Detaches the documentImpl from its existing session, so that it can survive beyond the session's closing.
|
boolean |
followTransition(String transition)
Follows a given life cycle transition.
|
ACP |
getACP()
Gets the access control policy (ACP) for this document.
|
<T> T |
getAdapter(Class<T> itf)
Adapts the document to the given interface.
|
<T> T |
getAdapter(Class<T> itf,
boolean refreshCache)
Adapts the document to the given interface.
|
Collection<String> |
getAllowedStateTransitions()
Gets the allowed state transitions for this document.
|
Map<String,String> |
getBinaryFulltext()
Gets the fulltext extracted from the binary fields.
|
String |
getCacheKey()
Returns a cache key.
|
String |
getChangeToken()
Gets the current change token for this document.
|
String |
getCheckinComment()
Returns the checkin comment if the document model is a version.
|
ScopedMap |
getContextData()
Gets the context data associated to this document.
|
Serializable |
getContextData(ScopeType scope,
String key)
Deprecated.
since 9.1, scope is unused, use
getContextData(String) instead |
Serializable |
getContextData(String key)
Gets the context data using the default scope.
|
CoreSession |
getCoreSession()
Gets the core session to which this document is tied.
|
String |
getCurrentLifeCycleState()
Returns the life cycle of the document.
|
DataModel |
getDataModel(String schema)
Deprecated.
since 8.4, use direct
Property getters instead |
Map<String,DataModel> |
getDataModels()
Deprecated.
since 8.4, use direct
Property getters instead |
Collection<DataModel> |
getDataModelsCollection()
Deprecated.
since 8.4, internal method
|
Set<String> |
getDeclaredFacets()
Deprecated.
use
getFacets() instead, or call getDocumentType() and look up the type facets |
String[] |
getDeclaredSchemas()
Deprecated.
use
getSchemas() instead, or call getDocumentType() and look up the type schemas |
DocumentType |
getDocumentType()
Gets the document type object.
|
Set<String> |
getFacets()
Gets the facets available on this document (from the type and the instance facets).
|
String |
getId()
Gets the document UUID.
|
String |
getLifeCyclePolicy()
Returns the life cycle policy of the document.
|
Lock |
getLockInfo()
Gets the lock info on the document.
|
String |
getName()
Gets the document name.
|
PropertyObjectResolver |
getObjectResolver(String xpath) |
DocumentRef |
getParentRef()
Retrieves the parent reference of the current document.
|
DocumentPart |
getPart(String schema)
Deprecated.
since 8.4, use direct
Property getters instead |
DocumentPart[] |
getParts()
Deprecated.
since 8.4, use direct
Property getters instead |
Path |
getPath()
Gets the document path.
|
String |
getPathAsString()
Gets the document path as a string.
|
Long |
getPos()
Gets the document's position in its containing folder (if ordered).
|
Map<String,Object> |
getProperties(String schemaName)
Gets the values from the given data model as a map.
|
Property |
getProperty(String xpath)
Gets a property given a xpath.
|
Object |
getProperty(String schemaName,
String name)
Gets a property from the given schema.
|
Property |
getPropertyObject(String schema,
String name)
Gets a property object from the given schema.
|
Collection<Property> |
getPropertyObjects(String schema)
Gets the
Property objects for the given schema. |
Serializable |
getPropertyValue(String xpath)
Gets a property value given a xpath.
|
DocumentRef |
getRef()
Gets a reference to the core document that can be used either remotely or locally (opens the core JVM).
|
String |
getRepositoryName()
Returns the name of the repository in which the document is stored.
|
String[] |
getSchemas()
Gets the schemas available on this document (from the type and the facets).
|
String |
getSessionId()
Retrieves the session id corresponding to this object.
|
String |
getSourceId()
Returns the source document identifier.
|
<T extends Serializable> |
getSystemProp(String systemProperty,
Class<T> type)
Gets system property of the specified type.
|
String |
getTitle()
Get a text suitable to be shown in a UI for this document.
|
String |
getType()
Gets the document type name.
|
String |
getVersionLabel()
Returns the version label.
|
String |
getVersionSeriesId()
Gets the version series id for this document.
|
boolean |
hasFacet(String facet)
Checks if the document has a facet, either from its type or added on the instance.
|
boolean |
hasSchema(String schema)
Checks if the document has the given schema, either from its type or added on the instance through a facet.
|
boolean |
isCheckedOut()
Tests if the document is checked out.
|
boolean |
isDirty()
Checks if the document has actual data to write (dirty parts).
|
boolean |
isDownloadable()
Checks if this document can be downloaded.
|
boolean |
isFolder()
Checks if this document is a folder.
|
boolean |
isImmutable()
Checks if this document is immutable.
|
boolean |
isLatestMajorVersion()
Checks if a document is the latest major version in the version series.
|
boolean |
isLatestVersion()
Checks if a document is the latest version in the version series.
|
boolean |
isLifeCycleLoaded() |
boolean |
isLocked()
Tests if the document is locked.
|
boolean |
isMajorVersion()
Checks if a document is a major version.
|
boolean |
isPrefetched(String xpath)
Checks if a property is prefetched.
|
boolean |
isPrefetched(String schemaName,
String name)
Checks if a property is prefetched.
|
boolean |
isProxy()
Checks if this document is a proxy.
|
boolean |
isVersion()
Checks if this document is a version.
|
boolean |
isVersionable()
Checks if this document can have versions.
|
boolean |
isVersionSeriesCheckedOut()
Checks if there is a checked out working copy for the version series of this document.
|
void |
prefetchCurrentLifecycleState(String lifecycle)
Used to set lifecycle state along with prefetching other properties.
|
void |
prefetchLifeCyclePolicy(String lifeCyclePolicy)
Used to set lifecycle policy along with prefetching other properties.
|
void |
putContextData(ScopeType scope,
String key,
Serializable value)
Deprecated.
since 9.1, scope is unused, use
putContextData(String, Serializable) instead |
void |
putContextData(String key,
Serializable value)
Sets a context data in the default scope.
|
void |
refresh()
Same as
DocumentModel.refresh(REFRESH_DEFAULT) . |
void |
refresh(int refreshFlags,
String[] schemas)
Refresh document data from server.
|
boolean |
removeFacet(String facet)
Removes a facet from the document instance.
|
Lock |
removeLock()
Removes the lock on the document.
|
void |
reset()
Clears any prefetched or cached document data.
|
void |
setACP(ACP acp,
boolean overwrite)
Sets the ACP for this document model.
|
Lock |
setLock()
Sets a lock on the document.
|
void |
setPathInfo(String parentPath,
String name)
Sets path info.
|
void |
setProperties(String schemaName,
Map<String,Object> data)
Sets values for the given data model.
|
void |
setProperty(String schemaName,
String name,
Object value)
Sets the property value from the given schema.
|
void |
setPropertyValue(String xpath,
Serializable value)
Sets a property value given a xpath.
|
static final int REFRESH_STATE
static final int REFRESH_PREFETCH
static final int REFRESH_ACP_IF_LOADED
static final int REFRESH_ACP_LAZY
static final int REFRESH_ACP
static final int REFRESH_CONTENT_IF_LOADED
static final int REFRESH_CONTENT_LAZY
static final int REFRESH_CONTENT
static final int REFRESH_IF_LOADED
static final int REFRESH_LAZY
static final int REFRESH_ALL
static final int REFRESH_DEFAULT
DocumentType getDocumentType()
String getSessionId()
This method should rarely be used, use getCoreSession()
directly instead.
Using the session id you can retrieve the core session that created the object.
Document models created by the user on the client side are not bound to any session. They are simple DTO used to transport data.
CoreSession getCoreSession()
This may be null if the document has been detached from a session.
void detach(boolean loadAll)
loadAll
- if true
, load all data and ACP from the session before detachingvoid attach(String sid)
sid
- the session idDocumentRef getRef()
DocumentRef getParentRef()
Long getPos()
null
if the containing folder is not orderedString getTitle()
String getPathAsString()
String[] getSchemas()
@Deprecated String[] getDeclaredSchemas()
getSchemas()
instead, or call getDocumentType()
and look up the type schemasboolean hasSchema(String schema)
schema
- the schema nametrue
if the document has the schemaSet<String> getFacets()
@Deprecated Set<String> getDeclaredFacets()
getFacets()
instead, or call getDocumentType()
and look up the type facetsboolean hasFacet(String facet)
facet
- the facet nametrue
if the document has the facetboolean addFacet(String facet)
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 presentIllegalArgumentException
- if the facet does not existboolean removeFacet(String facet)
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 exit@Deprecated Collection<DataModel> getDataModelsCollection()
Gets a list with the currently fetched data models.
getSchemas()
,
getProperties(java.lang.String)
,
getPropertyObject(java.lang.String, java.lang.String)
,
getPropertyObjects(java.lang.String)
@Deprecated Map<String,DataModel> getDataModels()
Property
getters insteadgetSchemas()
,
getProperties(java.lang.String)
,
getPropertyObject(java.lang.String, java.lang.String)
,
getPropertyObjects(java.lang.String)
@Deprecated DataModel getDataModel(String schema)
Property
getters insteadNull is returned if the document type has no such schema.
schema
- the schema namegetSchemas()
,
getProperties(java.lang.String)
,
getPropertyObject(java.lang.String, java.lang.String)
,
getPropertyObjects(java.lang.String)
void setPathInfo(String parentPath, String name)
path and ref attributes will be set according to info
boolean isLocked()
Lock info is cached on the document for performance. Use CoreSession.getLockInfo(org.nuxeo.ecm.core.api.DocumentRef)
to get the non-cached
status.
Lock setLock() throws LockException
LockException
- if the document is already lockedLock getLockInfo()
Lock info is cached on the document for performance. Use CoreSession.getLockInfo(org.nuxeo.ecm.core.api.DocumentRef)
to get the non-cached
status.
null
otherwiseLock removeLock() throws LockException
The caller principal should be the same as the one who set the lock or to belongs to the administrator group, otherwise an exception will be throw.
If the document was not locked, does nothing.
Returns the previous lock info.
null
if there was no lockLockException
- if the document is locked by someone elseboolean isCheckedOut()
A checked out document can be modified normally. A checked in document is identical to the last version that it created, and not modifiable.
Only applicable to documents that are live (not versions and not proxies).
true
if the document is checked out, false
if it is checked invoid checkOut()
A checked out document can be modified normally.
Only applicable to documents that are live (not versions and not proxies).
DocumentRef checkIn(VersioningOption option, String checkinComment)
A checked in document is identical to the last version that it created, and not modifiable.
Only applicable to documents that are live (not versions and not proxies).
option
- whether to do create a new VersioningOption.MINOR
or VersioningOption.MAJOR
version
during check incheckinComment
- the checkin commentString getVersionLabel()
The label returned is computed by the VersioningService.
null
String getCheckinComment()
null
String getVersionSeriesId()
All documents and versions derived by a check in or checkout from the same original document share the same version series id.
boolean isLatestVersion()
boolean isMajorVersion()
boolean isLatestMajorVersion()
boolean isVersionSeriesCheckedOut()
ACP getACP()
Returns null if no security was defined on this document.
The ACP can be used to introspect or to evaluate user privileges on this document.
This is a wrapper for CoreSession.getACP(DocumentRef)
but it is recommended since it caches the ACP for
later usage.
void setACP(ACP acp, boolean overwrite)
This is a wrapper for CoreSession.setACP(DocumentRef, ACP, boolean)
acp
- the ACP to setoverwrite
- whether to overwrite the old ACP or notCoreSession#setACP(DocumentRef, ACP, boolean)}
Object getProperty(String schemaName, String name)
The data model owning the property will be fetched from the server if not already fetched.
schemaName
- the schema namename
- the property nameProperty getPropertyObject(String schema, String name)
schema
- the schema namename
- the property namenull
if no such property existsvoid setProperty(String schemaName, String name, Object value)
This operation will not fetch the data model if not already fetched
schemaName
- the schema namename
- the property namevalue
- the property valueMap<String,Object> getProperties(String schemaName)
The operation will fetch the data model from the server if not already fetched.
schemaName
- the data model schema namevoid setProperties(String schemaName, Map<String,Object> data)
This will not fetch the data model if not already fetched.
schemaName
- the schema namedata
- the values to setboolean isFolder()
boolean isVersionable()
boolean isDownloadable()
boolean isVersion()
boolean isProxy()
boolean isImmutable()
true
if the document is a version or a proxy to a version, false
otherwiseboolean isDirty()
void accept(PropertyVisitor visitor, Object arg)
The visitor must return null to stop visiting children otherwise a context object that will be passed as the arg argument to children
visitor
- the visitor to acceptarg
- an argument passed to the visitor. This should be used by the visitor to carry on the visiting
context.<T> T getAdapter(Class<T> itf)
Attention, the first computation will cache the adaptation result for later calls.
T
- the interface type to adapt toitf
- the interface class<T> T getAdapter(Class<T> itf, boolean refreshCache)
T
- the interface type to adapt toitf
- the interface classrefreshCache
- : readapt and stores in cache if already exists.String getCurrentLifeCycleState()
org.nuxeo.ecm.core.lifecycle
String getLifeCyclePolicy()
org.nuxeo.ecm.core.lifecycle
boolean followTransition(String transition)
This will update the current life cycle of the document.
transition
- the name of the transition to followCollection<String> getAllowedStateTransitions()
ScopedMap getContextData()
NOTE since 9.1 the ScopedMap
return type is deprecated, use java.util.Map<String, Serializable>
instead
@Deprecated Serializable getContextData(ScopeType scope, String key)
getContextData(String)
instead@Deprecated void putContextData(ScopeType scope, String key, Serializable value)
putContextData(String, Serializable)
insteadContext data is like a request map set on the document model to pass additional information to components interacting with the document model (events processing for instance).
Serializable getContextData(String key)
key
- the context data keyvoid putContextData(String key, Serializable value)
key
- the context data keyvalue
- the valuevoid copyContextData(DocumentModel otherDocument)
void copyContent(DocumentModel sourceDoc)
String getRepositoryName()
String getCacheKey()
Cache key will be computed like this :
docUUID + "-" + sessionId + "-" + timestamp
We will use the last modification time if present for the timestamp.
Since 5.6, the timestamp does not hold milliseconds anymore as some databases do not store them, which could interfere with cache key comparisons.
String getSourceId()
This is useful when not interested about the repository UUID itself. Technically, this is the current version UUID.
boolean isPrefetched(String xpath)
xpath
- the property xpathtrue
if it is prefetchedboolean isPrefetched(String schemaName, String name)
schemaName
- the schema namename
- the property nametrue
if it is prefetchedvoid prefetchCurrentLifecycleState(String lifecycle)
void prefetchLifeCyclePolicy(String lifeCyclePolicy)
boolean isLifeCycleLoaded()
<T extends Serializable> T getSystemProp(String systemProperty, Class<T> type)
@Deprecated DocumentPart getPart(String schema)
Property
getters insteadschema
- the schemagetPropertyObject(java.lang.String, java.lang.String)
,
getPropertyObjects(java.lang.String)
@Deprecated DocumentPart[] getParts()
Property
getters insteadCollection<Property> getPropertyObjects(String schema)
Property
objects for the given schema.
An empty list is returned if the document doesn't have the schema.
schema
- the schemaProperty getProperty(String xpath) throws PropertyException
Note that what's called xpath in this context is not an actual XPath as specified by the w3c. Main differences are that in our xpath:
foo/bar[i]/baz
as foo/i/baz
PropertyException
Serializable getPropertyValue(String xpath) throws PropertyException
Note that what's called xpath in this context is not an actual XPath as specified by the w3c. Main differences are that in our xpath:
foo/bar[i]/baz
as foo/i/baz
PropertyException
void setPropertyValue(String xpath, Serializable value) throws PropertyException
PropertyException
void reset()
This will force the document to lazily update its data when required.
void refresh(int refreshFlags, String[] schemas)
The data models will be removed and all prefetch and system data will be refreshed from the server
The refreshed data contains:
REFRESH_STATE
REFRESH_PREFETCH
REFRESH_ACP_IF_LOADED
REFRESH_ACP_LAZY
REFRESH_ACP
REFRESH_CONTENT_IF_LOADED
REFRESH_CONTENT_LAZY
REFRESH_CONTENT
REFRESH_DEFAULT
same as REFRESH_STATE | REFRESH_DEFAULT | REFRESH_ACP_IF_LOADED |
REFRESH_CONTENT_IF_LOADED
REFRESH_ALL
same as REFRESH_STATE | REFRESH_PREFTECH | REFRESH_ACP | REFRESH_CONTENT
refreshFlags
- the refresh flagsschemas
- the document parts (schemas) that should be refreshed nowvoid refresh()
DocumentModel.refresh(REFRESH_DEFAULT)
.DocumentModel clone() throws CloneNotSupportedException
CloneNotSupportedException
String getChangeToken()
The change token is an opaque string which is modified every time the document is changed.
Before saving a document through CoreSession.saveDocument(org.nuxeo.ecm.core.api.DocumentModel)
it's possible to pass an expected change token
in the document context data through doc.putContextData(CoreSession.CHANGE_TOKEN, expectedChangeToken)
.
If the change token does not match the stored one, it means that a concurrent update happened, and a
ConcurrentUpdateException
will be thrown.
putContextData(org.nuxeo.common.collections.ScopeType, java.lang.String, java.io.Serializable)
,
CoreSession.CHANGE_TOKEN
,
CoreSession.getChangeToken(org.nuxeo.ecm.core.api.DocumentRef)
Map<String,String> getBinaryFulltext()
PropertyObjectResolver getObjectResolver(String xpath)
xpath
- the property xpathPropertyObjectResolver
to manage the property reference to external entities, null if this
property's type has no resolver.Copyright © 2017 Nuxeo. All rights reserved.