Nuxeo Enterprise Platform 5.4

org.nuxeo.ecm.core.api
Interface DocumentModel

All Superinterfaces:
java.io.Serializable
All Known Subinterfaces:
DocumentModelIndexingWrapper
All Known Implementing Classes:
DeletedDocumentModel, DocumentModelImpl, ResultDocumentModel, ShallowDocumentModel, SimpleDocumentModel

public interface DocumentModel
extends java.io.Serializable

The document model is a serializable representation of a core document.

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.

The user may overwrite the default schemas by passing the schemas to be used at model creation via CoreSession.getDocument(DocumentRef, String[])

How a lazy data model is loaded depends on the implementation.

Anyway the API already provides a mechanism to handle this as follow:

 
 public DataModel getDataModel(String schema) {
     DataModel dataModel = dataModels.get(schema);
     if (dataModel != null && !dataModel.isLoaded()) {
         CoreSession client = CoreInstance.getInstance().getClient(
                 getSessionId());
         if (client != null) {
             dataModel = client.getDataModel(getRef(), schema);
             dataModels.put(schema, dataModel);
         }
     }
     return dataModel;
 }
 
 

Author:
Bogdan Stefanescu
See Also:
CoreSession, DataModel

Nested Class Summary
static class DocumentModel.DocumentModelRefresh
          Info fetched internally during a refresh.
 
Field Summary
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
           
 
Method Summary
 DocumentRef checkIn(VersioningOption option, java.lang.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.
 boolean followTransition(java.lang.String transition)
          Follows a given life cycle transition.
 ACP getACP()
          Gets the access control policy (ACP) for this document.
<T> T
getAdapter(java.lang.Class<T> itf)
          Adapts the document to the given interface.
<T> T
getAdapter(java.lang.Class<T> itf, boolean refreshCache)
          Adapts the document to the given interface.
 java.util.Collection<java.lang.String> getAllowedStateTransitions()
          Gets the allowed state transitions for this document.
 java.lang.String getCacheKey()
          Returns a cache key.
 java.lang.String getCheckinComment()
          Returns the checkin comment if the document model is a version.
 ScopedMap getContextData()
          Gets the context data associated to this document.
 java.io.Serializable getContextData(ScopeType scope, java.lang.String key)
          Gets the context data associated to this document for given scope and given key.
 java.io.Serializable getContextData(java.lang.String key)
          Gets the context data using the default scope.
 CoreSession getCoreSession()
          Gets the core session to which this document is tied.
 java.lang.String getCurrentLifeCycleState()
          Returns the life cycle of the document.
 DataModel getDataModel(java.lang.String schema)
          Gets the data model corresponding to the given schema.
 DataModelMap getDataModels()
          Gets the data models.
 java.util.Collection<DataModel> getDataModelsCollection()
          Gets a list with the currently fetched data models.
 java.util.Set<java.lang.String> getDeclaredFacets()
          Gets the facets defined by this document type.
 java.lang.String[] getDeclaredSchemas()
          Gets the schemas defined by this document type.
 DocumentType getDocumentType()
          Gets the document type object.
 long getFlags()
          Returns the flags set on the document model.
 java.lang.String getId()
          Gets the document UUID.
 java.lang.String getLifeCyclePolicy()
          Returns the life cycle policy of the document.
 java.lang.String getLock()
          Gets the lock key if the document is locked.
 java.lang.String getName()
          Gets the document name.
 DocumentRef getParentRef()
          Retrieves the parent reference of the current document.
 DocumentPart getPart(java.lang.String schema)
          Get a document part given its schema name
 DocumentPart[] getParts()
          Gets this document's parts.
 Path getPath()
          Gets the document path.
 java.lang.String getPathAsString()
          Gets the document path as a string.
 java.util.Map<java.lang.String,java.io.Serializable> getPrefetch()
          Returns the map of prefetched values.
 java.util.Map<java.lang.String,java.lang.Object> getProperties(java.lang.String schemaName)
          Gets the values from the given data model as a map.
 Property getProperty(java.lang.String xpath)
          Gets a property given a xpath.
 java.lang.Object getProperty(java.lang.String schemaName, java.lang.String name)
          Gets a property from the given schema.
 java.io.Serializable getPropertyValue(java.lang.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).
 java.lang.String getRepositoryName()
          Returns the name of the repository in which the document is stored.
 java.lang.String getSessionId()
          Retrieves the session id corresponding to this object.
 java.lang.String getSourceId()
          Returns the source document identifier.
<T extends java.io.Serializable>
T
getSystemProp(java.lang.String systemProperty, java.lang.Class<T> type)
          Gets system property of the specified type.
 java.lang.String getTitle()
          Get a text suitable to be shown in a UI for this document.
 java.lang.String getType()
          Gets the document type name.
 java.lang.String getVersionLabel()
          Returns the version label.
 java.lang.String getVersionSeriesId()
          Gets the version series id for this document.
 boolean hasFacet(java.lang.String facet)
          Checks if this document has the given facet.
 boolean hasSchema(java.lang.String schema)
          Checks whether this document model has the given schema.
 boolean isCheckedOut()
          Tests if the document is checked out.
 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 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(java.lang.String lifecycle)
          Used to set lifecycle state along with prefetching other properties.
 void prefetchLifeCyclePolicy(java.lang.String lifeCyclePolicy)
          Used to set lifecycle policy along with prefetching other properties.
 void prefetchProperty(java.lang.String id, java.lang.Object value)
          Store a value in the prefetched inner map.
 void putContextData(ScopeType scope, java.lang.String key, java.io.Serializable value)
          Adds mapping to the context data for given scope.
 void putContextData(java.lang.String key, java.io.Serializable value)
          Sets a context data in the default scope.
 void refresh()
          Same as DocumentModel.refresh(REFRESH_DEFAULT).
 void refresh(int refreshFlags, java.lang.String[] schemas)
          Refresh document data from server.
 void reset()
          Clears any prefetched or cached document data.
 void setACP(ACP acp, boolean overwrite)
          Sets the ACP for this document model.
 void setLock(java.lang.String key)
          Locks this document using the given key.
 void setPathInfo(java.lang.String parentPath, java.lang.String name)
          Sets path info.
 void setProperties(java.lang.String schemaName, java.util.Map<java.lang.String,java.lang.Object> data)
          Sets values for the given data model.
 void setProperty(java.lang.String schemaName, java.lang.String name, java.lang.Object value)
          Sets the property value from the given schema.
 void setPropertyValue(java.lang.String xpath, java.io.Serializable value)
          Sets a property value given a xpath.
 void unlock()
          Unlocks the given document.
 

Field Detail

REFRESH_STATE

static final int REFRESH_STATE
See Also:
Constant Field Values

REFRESH_PREFETCH

static final int REFRESH_PREFETCH
See Also:
Constant Field Values

REFRESH_ACP_IF_LOADED

static final int REFRESH_ACP_IF_LOADED
See Also:
Constant Field Values

REFRESH_ACP_LAZY

static final int REFRESH_ACP_LAZY
See Also:
Constant Field Values

REFRESH_ACP

static final int REFRESH_ACP
See Also:
Constant Field Values

REFRESH_CONTENT_IF_LOADED

static final int REFRESH_CONTENT_IF_LOADED
See Also:
Constant Field Values

REFRESH_CONTENT_LAZY

static final int REFRESH_CONTENT_LAZY
See Also:
Constant Field Values

REFRESH_CONTENT

static final int REFRESH_CONTENT
See Also:
Constant Field Values

REFRESH_IF_LOADED

static final int REFRESH_IF_LOADED
See Also:
Constant Field Values

REFRESH_LAZY

static final int REFRESH_LAZY
See Also:
Constant Field Values

REFRESH_ALL

static final int REFRESH_ALL
See Also:
Constant Field Values

REFRESH_DEFAULT

static final int REFRESH_DEFAULT
See Also:
Constant Field Values
Method Detail

getDocumentType

DocumentType getDocumentType()
Gets the document type object.

Returns:
the document type object

getSessionId

java.lang.String getSessionId()
Retrieves the session id corresponding to this object.

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.

Returns:
the session id the session ID for server side created doc models or null for client side models (used for data transportation)

getCoreSession

CoreSession getCoreSession()
Gets the core session to which this document is tied.

This may be null if the document has been detached from a session.

Returns:
the core session
Since:
5.2.GA

getRef

DocumentRef getRef()
Gets a reference to the core document that can be used either remotely or locally (opens the core JVM).

Returns:
the document reference

getParentRef

DocumentRef getParentRef()
Retrieves the parent reference of the current document.

Returns:
the parent reference or null if no parent

getId

java.lang.String getId()
Gets the document UUID.

Returns:
the document UUID

getName

java.lang.String getName()
Gets the document name.

Returns:
the document name

getTitle

java.lang.String getTitle()
                          throws ClientException
Get a text suitable to be shown in a UI for this document.

Returns:
the title or the internal name if no title could be found
Throws:
ClientException

getPathAsString

java.lang.String getPathAsString()
Gets the document path as a string.

Returns:
the document path as string

getPath

Path getPath()
Gets the document path.

Returns:
the document path as string

getType

java.lang.String getType()
Gets the document type name.

Returns:
the document type name

getDeclaredSchemas

java.lang.String[] getDeclaredSchemas()
Gets the schemas defined by this document type.

Returns:
the defined schemas

getDeclaredFacets

java.util.Set<java.lang.String> getDeclaredFacets()
Gets the facets defined by this document type.

Returns:
the defined facets

getDataModelsCollection

java.util.Collection<DataModel> getDataModelsCollection()
Gets a list with the currently fetched data models.

Returns:
the data models that are already fetched as a collection

getDataModels

DataModelMap getDataModels()
Gets the data models.

Returns:
the data models that are already fetched.

getDataModel

DataModel getDataModel(java.lang.String schema)
                       throws ClientException
Gets the data model corresponding to the given schema.

Null is returned if the document type has no such schema.

Parameters:
schema - the schema name
Returns:
the data model or null if no such schema is supported
Throws:
ClientException

setPathInfo

void setPathInfo(java.lang.String parentPath,
                 java.lang.String name)
Sets path info.

path and ref attributes will be set according to info

Parameters:
parentPath -
name -

getLock

java.lang.String getLock()
Gets the lock key if the document is locked.

This uses the cached lock information and doesn't connect to the server.

To get fresh information from the server, use CoreSession.getLock(DocumentRef).

Returns:
the lock key if the document is locked or null otherwise

isLocked

boolean isLocked()
Tests if the document is locked.

This is using the cached lock information and doesn't connect to the server

To get fresh information from the server use CoreSession.getLock(DocumentRef).

Returns:
the lock key if the document is locked or null otherwise

setLock

void setLock(java.lang.String key)
             throws ClientException
Locks this document using the given key.

This is a wrapper for CoreSession.setLock(DocumentRef, String).

Parameters:
key - the key to use when locking
Throws:
ClientException - if the document is already locked or other error occurs

unlock

void unlock()
            throws ClientException
Unlocks the given document.

This is a wrapper for CoreSession.unlock(DocumentRef)

Throws:
ClientException - if the document is already locked or other error occurs

isCheckedOut

boolean isCheckedOut()
                     throws ClientException
Tests if the document is checked out.

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).

Returns:
true if the document is checked out, false if it is checked in
Throws:
ClientException
Since:
5.4

checkOut

void checkOut()
              throws ClientException
Checks out a document.

A checked out document can be modified normally.

Only applicable to documents that are live (not versions and not proxies).

Throws:
ClientException
Since:
5.4

checkIn

DocumentRef checkIn(VersioningOption option,
                    java.lang.String checkinComment)
                    throws ClientException
Checks in a document and returns the created version.

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).

Parameters:
option - whether to do create a new VersioningOption.MINOR or VersioningOption.MAJOR version during check in
checkinComment - the checkin comment
Returns:
the version just created
Throws:
ClientException
Since:
5.4

getVersionLabel

java.lang.String getVersionLabel()
Returns the version label.

The label returned is computed by the VersioningService.

Returns:
the version label, or null

getCheckinComment

java.lang.String getCheckinComment()
                                   throws ClientException
Returns the checkin comment if the document model is a version.

Returns:
the checkin comment, or null
Throws:
ClientException
Since:
5.4

getVersionSeriesId

java.lang.String getVersionSeriesId()
                                    throws ClientException
Gets the version series id for this document.

All documents and versions derived by a check in or checkout from the same original document share the same version series id.

Returns:
the version series id
Throws:
ClientException
Since:
5.4

isLatestVersion

boolean isLatestVersion()
                        throws ClientException
Checks if a document is the latest version in the version series.

Throws:
ClientException
Since:
5.4

isMajorVersion

boolean isMajorVersion()
                       throws ClientException
Checks if a document is a major version.

Throws:
ClientException
Since:
5.4

isLatestMajorVersion

boolean isLatestMajorVersion()
                             throws ClientException
Checks if a document is the latest major version in the version series.

Throws:
ClientException
Since:
5.4

isVersionSeriesCheckedOut

boolean isVersionSeriesCheckedOut()
                                  throws ClientException
Checks if there is a checked out working copy for the version series of this document.

Throws:
ClientException
Since:
5.4

getACP

ACP getACP()
           throws ClientException
Gets the access control policy (ACP) for this document.

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.

Returns:
the security data model or null if none
Throws:
ClientException

setACP

void setACP(ACP acp,
            boolean overwrite)
            throws ClientException
Sets the ACP for this document model.

This is a wrapper for CoreSession.setACP(DocumentRef, ACP, boolean)

Parameters:
acp - the ACP to set
overwrite - whether to overwrite the old ACP or not
Throws:
ClientException
See Also:
CoreSession#setACP(DocumentRef, ACP, boolean)}

getProperty

java.lang.Object getProperty(java.lang.String schemaName,
                             java.lang.String name)
                             throws ClientException
Gets a property from the given schema.

The data model owning the property will be fetched from the server if not already fetched.

Parameters:
schemaName - the schema name
name - the property name
Returns:
the property value or null if no such property exists
Throws:
ClientException

setProperty

void setProperty(java.lang.String schemaName,
                 java.lang.String name,
                 java.lang.Object value)
                 throws ClientException
Sets the property value from the given schema.

This operation will not fetch the data model if not already fetched

Parameters:
schemaName - the schema name
name - the property name
value - the property value
Throws:
ClientException

getProperties

java.util.Map<java.lang.String,java.lang.Object> getProperties(java.lang.String schemaName)
                                                               throws ClientException
Gets the values from the given data model as a map.

The operation will fetch the data model from the server if not already fetched.

Parameters:
schemaName - the data model schema name
Returns:
the values map
Throws:
ClientException

setProperties

void setProperties(java.lang.String schemaName,
                   java.util.Map<java.lang.String,java.lang.Object> data)
                   throws ClientException
Sets values for the given data model.

This will not fetch the data model if not already fetched.

Parameters:
schemaName - the schema name
data - the values to set
Throws:
ClientException

hasSchema

boolean hasSchema(java.lang.String schema)
Checks whether this document model has the given schema.

Parameters:
schema - the schema name to check
Returns:
true if the document has this schema, false otherwise

hasFacet

boolean hasFacet(java.lang.String facet)
Checks if this document has the given facet.

Parameters:
facet - the facet to check
Returns:
true if the document has this facet, false otherwise

isFolder

boolean isFolder()
Checks if this document is a folder.

Returns:
true if the document is a folder, false otherwise

isVersionable

boolean isVersionable()
Checks if this document can have versions.

Returns:
true if the document can have versions, false otherwise

isDownloadable

boolean isDownloadable()
                       throws ClientException
Checks if this document can be downloaded.

Returns:
true if the document has downloadable content, false otherwise
Throws:
ClientException

isVersion

boolean isVersion()
Checks if this document is a version.

Returns:
true if the document is an older version of another document, false otherwise

isProxy

boolean isProxy()
Checks if this document is a proxy.

Returns:
true if the document is a proxy false otherwise

isImmutable

boolean isImmutable()
Checks if this document is immutable.

Returns:
true if the document is a version or a proxy to a version, false otherwise
Since:
1.6.1 (5.3.1)

getAdapter

<T> T getAdapter(java.lang.Class<T> itf)
Adapts the document to the given interface.

Attention, the first computation will cache the adaptation result for later calls.

Type Parameters:
T - the interface type to adapt to
Parameters:
itf - the interface class
Returns:
the adapted document

getAdapter

<T> T getAdapter(java.lang.Class<T> itf,
                 boolean refreshCache)
Adapts the document to the given interface.

Type Parameters:
T - the interface type to adapt to
Parameters:
itf - the interface class
refreshCache - : readapt and stores in cache if already exists.
Returns:
the adapted document

getCurrentLifeCycleState

java.lang.String getCurrentLifeCycleState()
                                          throws ClientException
Returns the life cycle of the document.

Returns:
the life cycle as a string
Throws:
ClientException
See Also:
org.nuxeo.ecm.core.lifecycle

getLifeCyclePolicy

java.lang.String getLifeCyclePolicy()
                                    throws ClientException
Returns the life cycle policy of the document.

Returns:
the life cycle policy
Throws:
ClientException
See Also:
org.nuxeo.ecm.core.lifecycle

followTransition

boolean followTransition(java.lang.String transition)
                         throws ClientException
Follows a given life cycle transition.

This will update the current life cycle of the document.

Parameters:
transition - the name of the transition to follow
Returns:
a boolean representing the status if the operation
Throws:
ClientException

getAllowedStateTransitions

java.util.Collection<java.lang.String> getAllowedStateTransitions()
                                                                  throws ClientException
Gets the allowed state transitions for this document.

Returns:
a collection of state transitions as string
Throws:
ClientException

getContextData

ScopedMap getContextData()
Gets the context data associated to this document.

Returns:
serializable map of context data.

getContextData

java.io.Serializable getContextData(ScopeType scope,
                                    java.lang.String key)
Gets the context data associated to this document for given scope and given key.


putContextData

void putContextData(ScopeType scope,
                    java.lang.String key,
                    java.io.Serializable value)
Adds mapping to the context data for given scope.

Context 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).


getContextData

java.io.Serializable getContextData(java.lang.String key)
Gets the context data using the default scope.

Parameters:
key - the context data key
Returns:
the value

putContextData

void putContextData(java.lang.String key,
                    java.io.Serializable value)
Sets a context data in the default scope.

Parameters:
key - the context data key
value - the value

copyContextData

void copyContextData(DocumentModel otherDocument)
Copies the context data from given document to this document.


copyContent

void copyContent(DocumentModel sourceDoc)
                 throws ClientException
Copies all the data from a source document.

Throws:
ClientException

getRepositoryName

java.lang.String getRepositoryName()
Returns the name of the repository in which the document is stored.

Returns:
the repository name as a string.

getCacheKey

java.lang.String getCacheKey()
                             throws ClientException
Returns a cache key.

Cache key will be computed like this : docUUID + "-" + sessionId + "-" + timestamp

We will use the last modification time if present for the timestamp.

Returns:
the cache key as a string
Throws:
ClientException

getSourceId

java.lang.String getSourceId()
Returns the source document identifier.

This is useful when not interested about the repository UUID itself. Technically, this is the current version UUID.

Returns:
the source id as a string.

getPrefetch

java.util.Map<java.lang.String,java.io.Serializable> getPrefetch()
Returns the map of prefetched values.

Returns:
the map of prefetched values.

prefetchProperty

void prefetchProperty(java.lang.String id,
                      java.lang.Object value)
Store a value in the prefetched inner map.


prefetchCurrentLifecycleState

void prefetchCurrentLifecycleState(java.lang.String lifecycle)
Used to set lifecycle state along with prefetching other properties.


prefetchLifeCyclePolicy

void prefetchLifeCyclePolicy(java.lang.String lifeCyclePolicy)
Used to set lifecycle policy along with prefetching other properties.


isLifeCycleLoaded

boolean isLifeCycleLoaded()

getSystemProp

<T extends java.io.Serializable> T getSystemProp(java.lang.String systemProperty,
                                                 java.lang.Class<T> type)
                                             throws ClientException,
                                                    DocumentException
Gets system property of the specified type. This is not a lazy loaded property, thus the request is made directly to the server. This is needed as some critical system properties might be changed directly in the core.

Throws:
ClientException
DocumentException

getPart

DocumentPart getPart(java.lang.String schema)
                     throws ClientException
Get a document part given its schema name

Parameters:
schema - the schema
Returns:
the document aprt or null if none exists for that schema
Throws:
ClientException

getParts

DocumentPart[] getParts()
                        throws ClientException
Gets this document's parts.

Throws:
ClientException

getProperty

Property getProperty(java.lang.String xpath)
                     throws PropertyException,
                            ClientException
Gets a property given a xpath.

Throws:
PropertyException
ClientException

getPropertyValue

java.io.Serializable getPropertyValue(java.lang.String xpath)
                                      throws PropertyException,
                                             ClientException
Gets a property value given a xpath.

Throws:
PropertyException
ClientException

setPropertyValue

void setPropertyValue(java.lang.String xpath,
                      java.io.Serializable value)
                      throws PropertyException,
                             ClientException
Sets a property value given a xpath.

Throws:
PropertyException
ClientException

getFlags

long getFlags()
Returns the flags set on the document model.


reset

void reset()
Clears any prefetched or cached document data.

This will force the document to lazily update its data when required.


refresh

void refresh(int refreshFlags,
             java.lang.String[] schemas)
             throws ClientException
Refresh document data from server.

The data models will be removed and all prefetch and system data will be refreshed from the server

The refreshed data contains:

The refresh flags are: If XX_IF_LOADED is used then XX will be refreshed only if already loaded in the document - otherwise a lazy refresh will be done

Parameters:
refreshFlags - the refresh flags
schemas - the document parts (schemas) that should be refreshed now
Throws:
ClientException

refresh

void refresh()
             throws ClientException
Same as DocumentModel.refresh(REFRESH_DEFAULT).

Throws:
ClientException

clone

DocumentModel clone()
                    throws java.lang.CloneNotSupportedException
Clone operation. Must be made public instead of just protected as in Object.

Throws:
java.lang.CloneNotSupportedException

Nuxeo Enterprise Platform 5.4

Copyright © 2010 Nuxeo SAS. All Rights Reserved.