Class DocumentModelImpl

    • Field Detail

      • typeName

        protected String typeName
      • schemas

        protected Set<String> schemas
        Schemas including those from instance facets.
      • schemasOrig

        protected Set<String> schemasOrig
        Schemas including those from instance facets when the doc was read
      • facets

        protected Set<String> facets
        Facets including those on instance.
      • retainedProperties

        protected List<String> retainedProperties
        Retained properties.
      • instanceFacets

        public Set<String> instanceFacets
        Instance facets.
      • instanceFacetsOrig

        public Set<String> instanceFacetsOrig
        Instance facets when the document was read.
      • path

        protected Path path
      • pos

        protected Long pos
      • LOCK_UNKNOWN

        protected static final Lock LOCK_UNKNOWN
      • lock

        protected Lock lock
      • isStateLoaded

        protected boolean isStateLoaded
        state is lifecycle, version stuff.
      • currentLifeCycleState

        protected String currentLifeCycleState
      • lifeCyclePolicy

        protected String lifeCyclePolicy
      • isCheckedOut

        protected boolean isCheckedOut
      • versionSeriesId

        protected String versionSeriesId
      • isLatestVersion

        protected boolean isLatestVersion
      • isMajorVersion

        protected boolean isMajorVersion
      • isLatestMajorVersion

        protected boolean isLatestMajorVersion
      • isVersionSeriesCheckedOut

        protected boolean isVersionSeriesCheckedOut
      • checkinComment

        protected String checkinComment
      • checkinDate

        protected Calendar checkinDate
      • acp

        protected transient ACP acp
      • isACPLoaded

        protected transient boolean isACPLoaded
      • repositoryName

        protected String repositoryName
      • coreSession

        protected transient CoreSession coreSession
      • sourceId

        protected String sourceId
      • changeToken

        protected String changeToken
      • isTrashed

        protected boolean isTrashed
      • isRecord

        public boolean isRecord
      • isFlexibleRecord

        public boolean isFlexibleRecord
      • retainUntil

        public Calendar retainUntil
      • hasLegalHold

        public boolean hasLegalHold
    • Method Detail

      • computeSchemas

        public static Set<String> computeSchemas​(DocumentType type,
                                                 Collection<String> instanceFacets,
                                                 boolean isProxy)
        Recomputes effective schemas from a type + instance facets.
      • getSessionId

        public String getSessionId()
        Description copied from interface: DocumentModel
        Returns the repository name and principal when the document is attached.
        Specified by:
        getSessionId in interface DocumentModel
      • getRef

        public DocumentRef getRef()
        Description copied from interface: DocumentModel
        Gets a reference to the core document that can be used either remotely or locally (opens the core JVM).
        Specified by:
        getRef in interface DocumentModel
        Returns:
        the document reference
      • getParentRef

        public DocumentRef getParentRef()
        Description copied from interface: DocumentModel
        Retrieves the parent reference of the current document.
        Specified by:
        getParentRef in interface DocumentModel
        Returns:
        the parent reference or null if no parent
      • getCoreSession

        public CoreSession getCoreSession()
        Description copied from interface: DocumentModel
        Gets the core session to which this document is tied.

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

        Specified by:
        getCoreSession in interface DocumentModel
        Returns:
        the core session
      • getSession

        protected CoreSession getSession()
        Gets the CoreSession, or fails if it's not available.
        Since:
        9.1
      • detach

        public void detach​(boolean loadAll)
        Description copied from interface: DocumentModel
        Detaches the documentImpl from its existing session, so that it can survive beyond the session's closing.
        Specified by:
        detach in interface DocumentModel
        Parameters:
        loadAll - if true, load all data and ACP from the session before detaching
      • attach

        public void attach​(CoreSession coreSession)
        Description copied from interface: DocumentModel
        Reattaches a document to an existing session.
        Specified by:
        attach in interface DocumentModel
        Parameters:
        coreSession - the session to attach to
      • isAttached

        public boolean isAttached()
        Description copied from interface: DocumentModel
        Checks whether this document is attached to a session.
        Specified by:
        isAttached in interface DocumentModel
        Returns:
        true if the document is attached to a session
      • loadDataModel

        protected DataModel loadDataModel​(String schema)
        Lazily loads the given data model.
      • addDataModel

        public void addDataModel​(DataModel dataModel)
      • getSchemas

        public String[] getSchemas()
        Description copied from interface: DocumentModel
        Gets the schemas available on this document (from the type and the facets).
        Specified by:
        getSchemas in interface DocumentModel
        Returns:
        the schemas
      • hasSchema

        public boolean hasSchema​(String schema)
        Description copied from interface: DocumentModel
        Checks if the document has the given schema, either from its type or added on the instance through a facet.
        Specified by:
        hasSchema in interface DocumentModel
        Parameters:
        schema - the schema name
        Returns:
        true if the document has the schema
      • getFacets

        public Set<String> getFacets()
        Description copied from interface: DocumentModel
        Gets the facets available on this document (from the type and the instance facets).
        Specified by:
        getFacets in interface DocumentModel
        Returns:
        the facets
      • getRetainedProperties

        public List<String> getRetainedProperties()
        Description copied from interface: DocumentModel
        Gets the retained properties of this document at the time it became a record.
        Specified by:
        getRetainedProperties in interface DocumentModel
        Returns:
        the retained properties
      • hasFacet

        public boolean hasFacet​(String facet)
        Description copied from interface: DocumentModel
        Checks if the document has a facet, either from its type or added on the instance.
        Specified by:
        hasFacet in interface DocumentModel
        Parameters:
        facet - the facet name
        Returns:
        true if the document has the facet
      • addFacet

        public boolean addFacet​(String facet)
        Description copied from interface: DocumentModel
        Adds a facet to the document instance.

        Does nothing if the facet was already present on the document.

        Specified by:
        addFacet in interface DocumentModel
        Parameters:
        facet - the facet name
        Returns:
        true if the facet was added, or false if it is already present
      • removeFacet

        public boolean removeFacet​(String facet)
        Description copied from interface: DocumentModel
        Removes a facet from the document instance.

        It's not possible to remove a facet coming from the document type.

        Specified by:
        removeFacet in interface DocumentModel
        Parameters:
        facet - the facet name
        Returns:
        true if the facet was removed, or false if it isn't present or is present on the type or does not exit
      • getPos

        public Long getPos()
        Description copied from interface: DocumentModel
        Gets the document's position in its containing folder (if ordered).
        Specified by:
        getPos in interface DocumentModel
        Returns:
        the position, or null if the containing folder is not ordered
      • setPosInternal

        public void setPosInternal​(Long pos)
        Sets the document's position in its containing folder (if ordered). Used internally during construction.
        Parameters:
        pos - the position
        Since:
        6.0
      • getProperties

        public Map<String,​Object> getProperties​(String schemaName)
        Description copied from interface: DocumentModel
        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.

        Specified by:
        getProperties in interface DocumentModel
        Parameters:
        schemaName - the data model schema name
        Returns:
        the values map
      • getProperty

        public Object getProperty​(String schemaName,
                                  String name)
        Description copied from interface: DocumentModel
        Gets a property from the given schema.

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

        Specified by:
        getProperty in interface DocumentModel
        Parameters:
        schemaName - the schema name
        name - the property name
        Returns:
        the property value or null if no such property exists
      • getPropertyObject

        public Property getPropertyObject​(String schema,
                                          String name)
        Description copied from interface: DocumentModel
        Gets a property object from the given schema.
        Specified by:
        getPropertyObject in interface DocumentModel
        Parameters:
        schema - the schema name
        name - the property name
        Returns:
        the property, or null if no such property exists
      • setPathInfo

        public void setPathInfo​(String parentPath,
                                String name)
        Description copied from interface: DocumentModel
        Sets path info.

        path and ref attributes will be set according to info

        Specified by:
        setPathInfo in interface DocumentModel
      • setLock

        public Lock setLock()
        Description copied from interface: DocumentModel
        Sets a lock on the document.
        Specified by:
        setLock in interface DocumentModel
        Returns:
        the lock info that was set
      • removeLock

        public Lock removeLock()
        Description copied from interface: DocumentModel
        Removes the lock on the document.

        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.

        Specified by:
        removeLock in interface DocumentModel
        Returns:
        the removed lock info, or null if there was no lock
      • isCheckedOut

        public boolean isCheckedOut()
        Description copied from interface: DocumentModel
        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).

        Specified by:
        isCheckedOut in interface DocumentModel
        Returns:
        true if the document is checked out, false if it is checked in
      • checkOut

        public void checkOut()
        Description copied from interface: DocumentModel
        Checks out a document.

        A checked out document can be modified normally.

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

        Specified by:
        checkOut in interface DocumentModel
      • checkIn

        public DocumentRef checkIn​(VersioningOption option,
                                   String description)
        Description copied from interface: DocumentModel
        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).

        Specified by:
        checkIn in interface DocumentModel
        Parameters:
        option - whether to do create a new VersioningOption.MINOR or VersioningOption.MAJOR version during check in
        description - the checkin comment
        Returns:
        the version just created
      • getVersionLabel

        public String getVersionLabel()
        Description copied from interface: DocumentModel
        Returns the version label.

        The label returned is computed by the VersioningService.

        Specified by:
        getVersionLabel in interface DocumentModel
        Returns:
        the version label, or null
      • getVersionSeriesId

        public String getVersionSeriesId()
        Description copied from interface: DocumentModel
        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.

        Specified by:
        getVersionSeriesId in interface DocumentModel
        Returns:
        the version series id
      • isLatestVersion

        public boolean isLatestVersion()
        Description copied from interface: DocumentModel
        Checks if a document is the latest version in the version series.
        Specified by:
        isLatestVersion in interface DocumentModel
      • isLatestMajorVersion

        public boolean isLatestMajorVersion()
        Description copied from interface: DocumentModel
        Checks if a document is the latest major version in the version series.
        Specified by:
        isLatestMajorVersion in interface DocumentModel
      • isVersionSeriesCheckedOut

        public boolean isVersionSeriesCheckedOut()
        Description copied from interface: DocumentModel
        Checks if there is a checked out working copy for the version series of this document.
        Specified by:
        isVersionSeriesCheckedOut in interface DocumentModel
      • getCheckinComment

        public String getCheckinComment()
        Description copied from interface: DocumentModel
        Returns the checkin comment if the document model is a version.
        Specified by:
        getCheckinComment in interface DocumentModel
        Returns:
        the checkin comment, or null
      • getCheckinDate

        public Calendar getCheckinDate()
        Description copied from interface: DocumentModel
        Returns the checkin date (the date the version was created) if the document model is a version.
        Specified by:
        getCheckinDate in interface DocumentModel
        Returns:
        the checkin date, or null
      • isRecord

        public boolean isRecord()
        Description copied from interface: DocumentModel
        Checks if the document is a record.
        Specified by:
        isRecord in interface DocumentModel
        Returns:
        true if the document is a record, false otherwise
      • isEnforcedRecord

        public boolean isEnforcedRecord()
        Description copied from interface: DocumentModel
        Checks if the document is an enforced record.
        Specified by:
        isEnforcedRecord in interface DocumentModel
        Returns:
        true if the document is an enforced record, false otherwise
      • isFlexibleRecord

        public boolean isFlexibleRecord()
        Description copied from interface: DocumentModel
        Checks if the document is a flexible record.
        Specified by:
        isFlexibleRecord in interface DocumentModel
        Returns:
        true if the document is a flexible record, false otherwise
      • makeRecord

        public void makeRecord()
      • makeFlexibleRecord

        public void makeFlexibleRecord()
      • setRetainUntil

        public void setRetainUntil​(Calendar retainUntil)
      • setLegalHold

        public void setLegalHold​(boolean hold)
      • getACP

        public ACP getACP()
        Description copied from interface: DocumentModel
        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.

        Specified by:
        getACP in interface DocumentModel
        Returns:
        the security data model or null if none
      • getType

        public String getType()
        Description copied from interface: DocumentModel
        Gets the document type name.
        Specified by:
        getType in interface DocumentModel
        Returns:
        the document type name
      • setProperties

        public void setProperties​(String schemaName,
                                  Map<String,​Object> data)
        Description copied from interface: DocumentModel
        Sets values for the given data model.

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

        Specified by:
        setProperties in interface DocumentModel
        Parameters:
        schemaName - the schema name
        data - the values to set
      • setProperty

        public void setProperty​(String schemaName,
                                String name,
                                Object value)
        Description copied from interface: DocumentModel
        Sets the property value from the given schema.

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

        Specified by:
        setProperty in interface DocumentModel
        Parameters:
        schemaName - the schema name
        name - the property name
        value - the property value
      • getPath

        public Path getPath()
        Description copied from interface: DocumentModel
        Gets the document path.
        Specified by:
        getPath in interface DocumentModel
        Returns:
        the document path as string
      • isTrashed

        public boolean isTrashed()
        Description copied from interface: DocumentModel
        Checks if this document is in the trash.
        Specified by:
        isTrashed in interface DocumentModel
        Returns:
        true if the document is in the trash, false otherwise.
      • isFolder

        public boolean isFolder()
        Description copied from interface: DocumentModel
        Checks if this document is a folder.
        Specified by:
        isFolder in interface DocumentModel
        Returns:
        true if the document is a folder, false otherwise
      • isVersionable

        public boolean isVersionable()
        Description copied from interface: DocumentModel
        Checks if this document can have versions.
        Specified by:
        isVersionable in interface DocumentModel
        Returns:
        true if the document can have versions, false otherwise
      • isDownloadable

        public boolean isDownloadable()
        Description copied from interface: DocumentModel
        Checks if this document can be downloaded.
        Specified by:
        isDownloadable in interface DocumentModel
        Returns:
        true if the document has downloadable content, false otherwise
      • accept

        public void accept​(PropertyVisitor visitor,
                           Object arg)
        Description copied from interface: DocumentModel
        Method that implement the visitor pattern.

        The visitor must return null to stop visiting children otherwise a context object that will be passed as the arg argument to children

        Specified by:
        accept in interface DocumentModel
        Parameters:
        visitor - the visitor to accept
        arg - an argument passed to the visitor. This should be used by the visitor to carry on the visiting context.
      • getAdapter

        public <T> T getAdapter​(Class<T> itf)
        Description copied from interface: DocumentModel
        Adapts the document to the given interface.

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

        Specified by:
        getAdapter in interface DocumentModel
        Type Parameters:
        T - the interface type to adapt to
        Parameters:
        itf - the interface class
        Returns:
        the adapted document
      • getAdapter

        public <T> T getAdapter​(Class<T> itf,
                                boolean refreshCache)
        Description copied from interface: DocumentModel
        Adapts the document to the given interface.
        Specified by:
        getAdapter in interface DocumentModel
        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
      • followTransition

        public boolean followTransition​(String transition)
        Description copied from interface: DocumentModel
        Follows a given life cycle transition.

        This will update the current life cycle of the document.

        Specified by:
        followTransition in interface DocumentModel
        Parameters:
        transition - the name of the transition to follow
        Returns:
        a boolean representing the status if the operation
      • isVersion

        public boolean isVersion()
        Description copied from interface: DocumentModel
        Checks if this document is a version.
        Specified by:
        isVersion in interface DocumentModel
        Returns:
        true if the document is an older version of another document, false otherwise
      • isProxy

        public boolean isProxy()
        Description copied from interface: DocumentModel
        Checks if this document is a proxy.
        Specified by:
        isProxy in interface DocumentModel
        Returns:
        true if the document is a proxy false otherwise
      • isImmutable

        public boolean isImmutable()
        Description copied from interface: DocumentModel
        Checks if this document is immutable.
        Specified by:
        isImmutable in interface DocumentModel
        Returns:
        true if the document is a version or a proxy to a version, false otherwise
      • setIsVersion

        public void setIsVersion​(boolean isVersion)
      • setIsProxy

        public void setIsProxy​(boolean isProxy)
      • setIsImmutable

        public void setIsImmutable​(boolean isImmutable)
      • isDirty

        public boolean isDirty()
        Description copied from interface: DocumentModel
        Checks if the document has actual data to write (dirty parts).
        Specified by:
        isDirty in interface DocumentModel
      • getCacheKey

        public String getCacheKey()
        Description copied from interface: DocumentModel
        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.

        Since 5.6, the timestamp does not hold milliseconds anymore as some databases do not store them, which could interfere with cache key comparisons.

        Specified by:
        getCacheKey in interface DocumentModel
        Returns:
        the cache key as a string
      • getRepositoryName

        public String getRepositoryName()
        Description copied from interface: DocumentModel
        Returns the name of the repository in which the document is stored.
        Specified by:
        getRepositoryName in interface DocumentModel
        Returns:
        the repository name as a string.
      • getSourceId

        public String getSourceId()
        Description copied from interface: DocumentModel
        Returns the source document identifier.

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

        Specified by:
        getSourceId in interface DocumentModel
        Returns:
        the source id as a string.
      • isSchemaLoaded

        public boolean isSchemaLoaded​(String name)
      • isPrefetched

        public boolean isPrefetched​(String xpath)
        Description copied from interface: DocumentModel
        Checks if a property is prefetched.
        Specified by:
        isPrefetched in interface DocumentModel
        Parameters:
        xpath - the property xpath
        Returns:
        true if it is prefetched
      • isPrefetched

        public boolean isPrefetched​(String schemaName,
                                    String name)
        Description copied from interface: DocumentModel
        Checks if a property is prefetched.
        Specified by:
        isPrefetched in interface DocumentModel
        Parameters:
        schemaName - the schema name
        name - the property name
        Returns:
        true if it is prefetched
      • prefetchLifeCyclePolicy

        public void prefetchLifeCyclePolicy​(String lifeCyclePolicy)
        Description copied from interface: DocumentModel
        Used to set lifecycle policy along with prefetching other properties.
        Specified by:
        prefetchLifeCyclePolicy in interface DocumentModel
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getSystemProp

        public <T extends Serializable> T getSystemProp​(String systemProperty,
                                                        Class<T> type)
        Description copied from interface: DocumentModel
        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.
        Specified by:
        getSystemProp in interface DocumentModel
      • getProperty

        public Property getProperty​(String xpath)
        Description copied from interface: DocumentModel
        Gets a property given a xpath.

        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:

        • Indexes start at 0 instead of 1
        • You can express foo/bar[i]/baz as foo/i/baz
        The latter is possible because in Nuxeo lists of complex elements are homogenous, so the name of the second-level element is implied.
        Specified by:
        getProperty in interface DocumentModel
      • getPropertyValue

        public Serializable getPropertyValue​(String xpath)
                                      throws PropertyException
        Description copied from interface: DocumentModel
        Gets a property value given a xpath.

        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:

        • Indexes start at 0 instead of 1
        • You can express foo/bar[i]/baz as foo/i/baz
        The latter is possible because in Nuxeo lists of complex elements are homogenous, so the name of the second-level element is implied.
        Specified by:
        getPropertyValue in interface DocumentModel
        Throws:
        PropertyException
      • reset

        public void reset()
        Description copied from interface: DocumentModel
        Clears any prefetched or cached document data.

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

        Specified by:
        reset in interface DocumentModel
      • refresh

        public void refresh()
        Description copied from interface: DocumentModel
        Same as DocumentModel.refresh(REFRESH_DEFAULT).
        Specified by:
        refresh in interface DocumentModel
      • computeFacetsAndSchemas

        protected void computeFacetsAndSchemas​(Set<String> instanceFacets,
                                               boolean setOrig)
        Recomputes all facets and schemas from the instance facets.
        Since:
        7.1
      • setId

        public void setId​(String id)
        Sets the document id. May be useful when detaching from a repo and attaching to another one or when unmarshalling a documentModel from a XML or JSON representation
        Since:
        5.7.2
      • getSchemaManager

        protected static SchemaManager getSchemaManager()
        Returns:
        SchemaManager service or throws an exception if no one is available
        Since:
        9.3