Interface Document

All Known Subinterfaces:
SQLDocument
All Known Implementing Classes:
BaseDocument, DBSDocument, SQLDocumentLive, SQLDocumentProxy, SQLDocumentVersion

public interface Document
A low-level document from a Session.
  • Method Details

    • getSession

      Session getSession()
      Gets the session that owns this document.
      Returns:
      the session
    • getName

      String getName()
      Gets the name of this document.
      Returns:
      the document name
    • getPos

      Long getPos()
      Gets the document's position in its containing folder (if ordered).
      Returns:
      the position
      Since:
      6.0
    • getUUID

      String getUUID()
      Gets this document's UUID.
      Returns:
      the document UUID
    • getParent

      Document getParent()
      Gets the parent document, or null if this is the root document.
      Returns:
      the parent document, or null
    • getType

      DocumentType getType()
      Gets the type of this document.
      Returns:
      the document type
    • getPath

      String getPath()
      Gets the path of this document.
      Returns:
      the path
    • setPropertyValue

      void setPropertyValue(String name, Serializable value)
      Sets a simple property value.

      For more generic properties described by an xpath, use setValue(java.lang.String, java.lang.Object) instead.

      Parameters:
      name - the name of the property to set
      value - the value to set
      See Also:
    • setValue

      void setValue(String xpath, Object value) throws PropertyException
      Sets a property value.

      The xpath may point to a partial path, in which case the value may be a complex List or Map.

      Parameters:
      xpath - the xpath of the property to set
      value - the value to set
      Throws:
      PropertyException - if the property does not exist or the value is of the wrong type
      Since:
      7.3
    • getPropertyValue

      Serializable getPropertyValue(String name)
      Gets a simple property value.

      For more generic properties described by an xpath, use getValue(java.lang.String) instead.

      Parameters:
      name - the name of the property to get
      Returns:
      the property value or null if the property is not set
      See Also:
    • getValue

      Object getValue(String xpath) throws PropertyException
      Gets a property value.

      The xpath may point to a partial path, in which case the value may be a complex List or Map.

      Parameters:
      xpath - the xpath of the property to set
      Returns:
      the property value or null if the property is not set
      Throws:
      PropertyException - if the property does not exist
    • visitBlobs

      void visitBlobs(Consumer<Document.BlobAccessor> blobVisitor) throws PropertyException
      Visits all the blobs of this document and calls the passed blob visitor on each one.
      Throws:
      PropertyException
      Since:
      7.3
    • replaceBlobDigest

      String replaceBlobDigest(String key, String newKey, String newDigest)
      Visits the blobs of this document and, for those with a matching key, replace their key and digest with new ones.
      Parameters:
      key - the bob key to look for
      newKey - the new key
      newDigest - the new digest
      Returns:
      the old digest if at least one replacement was done, null otherwise
      Since:
      11.5
    • isFolder

      boolean isFolder()
      Checks whether this document is a folder.
      Returns:
      true if the document is a folder, false otherwise
    • setReadOnly

      void setReadOnly(boolean readonly)
      Sets this document as readonly or not.
      Since:
      5.9.2
    • isReadOnly

      boolean isReadOnly()
      Checks whether this document is readonly or not.
      Since:
      5.9.2
    • remove

      void remove()
      Removes this document and all its children, if any.
    • remove

      void remove(NuxeoPrincipal principal)
      Removes this document and all its children, if any.
      Parameters:
      principal - the caller
      Since:
      11.1
    • removeSingleton

      void removeSingleton()
      Removes this document only, without its children.
      Since:
      11.1
    • getBlobKeys

      default String[] getBlobKeys()
      Since:
      2023
    • makeRecord

      void makeRecord()
      Turns the document into an enforced record.

      A record is a document with specific capabilities related to mandatory retention until a given date, and legal holds. In addition, its main blob receives special treatment from the document blob manager to make sure it's never shared with another blob at the storage level, and is deleted as soon as the record is deleted.

      If the document is already a record, this method has no effect.

      The permission "MakeRecord" is required.

      Since:
      11.1
      See Also:
    • makeFlexibleRecord

      default void makeFlexibleRecord()
      Turns the document into a flexible record.

      A record is a document with specific capabilities related to mandatory retention until a given date, and legal holds.

      If the document is already a flexible record, this method has no effect. An enforced record cannot be turned into a flexible record.

      The permission "MakeRecord" is required.

      Throws:
      IllegalStateException - if the document is an enforced record
      Since:
      2023.1
      See Also:
    • isEnforcedRecord

      default boolean isEnforcedRecord()
      Returns:
      true if the document is a enforced record, false otherwise
      Since:
      2023.1
    • isFlexibleRecord

      default boolean isFlexibleRecord()
      Returns:
      true if the document is a flexible record, false otherwise
      Since:
      2023.1
    • isRecord

      boolean isRecord()
      Checks if the document is a record.
      Returns:
      true if the document is a record, false otherwise
      Since:
      11.1
      See Also:
    • getRetainedProperties

      String[] getRetainedProperties()
      Gets the retained property xpaths of this document instance at the time it became a record.
      Returns:
      the retained properties
      Throws:
      PropertyException - if document is not a record
      Since:
      2021.32
    • isRetainable

      boolean isRetainable(String xpath)
      Can the property be put under retention or legal hold.
      Parameters:
      xpath - the xpath
      Returns:
      true if the property is retainable
      Since:
      2021.32
    • isRetained

      boolean isRetained(String xpath)
      Is the property under retention or legal hold.
      Parameters:
      xpath - the xpath
      Returns:
      true if the property is retained and cannot be deleted/edited
      Since:
      2021.32
    • setRetainUntil

      void setRetainUntil(Calendar retainUntil) throws PropertyException
      Sets a retention date for the document (a record).

      If no previous retention date was set, or if the previous retention date was indeterminate, or if the previous retention date was before the given value, then the retention date is set to the given value.

      If the previous retention date was after the given value (that is, if trying to reduce the retention time), an exception is thrown.

      If the given value is null and the previous retention date is in the past (it has already expired), then the retention date is set to null.

      The permission "SetRetention" is required.

      Parameters:
      retainUntil - the new retention date
      Throws:
      PropertyException - if trying to reduce the retention time, or if the document is not a record
      Since:
      11.1
      See Also:
    • getRetainUntil

      Calendar getRetainUntil()
      Gets the retention date for the document.
      Returns:
      the retention date, or "SetRetention" for a retention in the indeterminate future, or null if there is no retention date
      Since:
      11.1
      See Also:
    • setLegalHold

      void setLegalHold(boolean hold)
      Sets or removes a legal hold on the document (a record).

      The permission "ManageLegalHold" is required.

      Parameters:
      hold - true to set a legal hold, false to remove it
      Throws:
      PropertyException - if the document is not a record
      Since:
      11.1
      See Also:
    • hasLegalHold

      boolean hasLegalHold()
      Checks if the document has a legal hold set.
      Returns:
      true if a legal hold has been set on the document, false otherwise
      Since:
      11.1
      See Also:
    • isUnderRetentionOrLegalHold

      boolean isUnderRetentionOrLegalHold()
      Checks if the document has a retention date in the future or has a legal hold.
      Returns:
      true if the document has a retention date in the future or if it has a legal hold, false otherwise
      Since:
      11.1
      See Also:
    • isRetentionActive

      @Deprecated boolean isRetentionActive()
      Deprecated.
      since 11.1, unused, use hasLegalHold() instead
      Checks whether this document is under active retention.
      Since:
      9.3
    • setRetentionActive

      @Deprecated void setRetentionActive(boolean retentionActive)
      Deprecated.
      since 11.1, unused, use setLegalHold(boolean) instead
      Sets or unsets this document as under active retention.
      Since:
      9.3
    • getLifeCycleState

      String getLifeCycleState()
      Gets the life cycle state of this document.
      Returns:
      the life cycle state
    • setCurrentLifeCycleState

      void setCurrentLifeCycleState(String state)
      Sets the life cycle state of this document.
      Parameters:
      state - the life cycle state
    • getLifeCyclePolicy

      String getLifeCyclePolicy()
      Gets the life cycle policy of this document.
      Returns:
      the life cycle policy
    • setLifeCyclePolicy

      void setLifeCyclePolicy(String policy)
      Sets the life cycle policy of this document.
      Parameters:
      policy - the life cycle policy
    • followTransition

      void followTransition(String transition) throws LifeCycleException
      Follows a given life cycle transition.

      This will update the life cycle state of the document.

      Parameters:
      transition - the name of the transition to follow
      Throws:
      LifeCycleException
    • getAllowedStateTransitions

      Collection<String> getAllowedStateTransitions()
      Returns the allowed state transitions for this document.
      Returns:
      a collection of state transitions
    • isProxy

      boolean isProxy()
      Checks whether or not this document is a proxy.
      Returns:
      true if this document is a proxy, false otherwise
    • getRepositoryName

      String getRepositoryName()
      Gets the repository in which the document lives.
      Returns:
      the repository name.
    • setSystemProp

      void setSystemProp(String name, Serializable value)
      Sets a system property.
    • getSystemProp

      <T extends Serializable> T getSystemProp(String name, Class<T> type)
      Gets a system property.
    • getChangeToken

      String getChangeToken()
      Gets the current change token for this document.
      Returns:
      the change token
      Since:
      9.1
    • validateUserVisibleChangeToken

      boolean validateUserVisibleChangeToken(String changeToken)
      Validates that the passed user-visible change token is compatible with the one for this document.
      Returns:
      false if the change token is not valid
      Since:
      9.2
    • markUserChange

      void markUserChange()
      Marks the document as being modified by a user change.

      This causes an additional change token increment and check during save.

      Since:
      9.2
    • readDocumentPart

      void readDocumentPart(DocumentPart dp) throws PropertyException
      Loads a DocumentPart from storage.

      Reading data is done by DocumentPart because of per-proxy schemas.

      Throws:
      PropertyException
    • getWriteContext

      Document.WriteContext getWriteContext()
      Gets a write context for the current document.
      Since:
      7.3
    • writeDocumentPart

      boolean writeDocumentPart(DocumentPart dp, Document.WriteContext writeContext, boolean create) throws PropertyException
      Writes a DocumentPart to storage.

      Writing data is done by DocumentPart because of per-proxy schemas.

      Parameters:
      dp - the document part
      writeContext - the write context
      create - whether this is for a document creation
      Returns:
      true if something changed
      Throws:
      PropertyException
      Since:
      11.1
    • writeDocumentPart

      @Deprecated default boolean writeDocumentPart(DocumentPart dp, Document.WriteContext writeContext) throws PropertyException
      Deprecated.
      since 11.1, use the signature with create instead
      Writes a DocumentPart to storage.

      Writing data is done by DocumentPart because of per-proxy schemas.

      Returns:
      true if something changed
      Throws:
      PropertyException
    • getAllFacets

      Set<String> getAllFacets()
      Gets the facets available on this document (from the type and the instance facets).
      Returns:
      the facets
      Since:
      5.4.2
    • getFacets

      String[] getFacets()
      Gets the facets defined on this document instance. The type facets are not returned.
      Returns:
      the facets
      Since:
      5.4.2
    • hasFacet

      boolean hasFacet(String facet)
      Checks whether this document has a given facet, either from its type or added on the instance.
      Parameters:
      facet - the facet name
      Returns:
      true if the document has the facet
      Since:
      5.4.2
    • addFacet

      boolean addFacet(String facet)
      Adds a facet to this document.

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

      Parameters:
      facet - the facet name
      Returns:
      true if the facet was added, or false if it is already present
      Throws:
      IllegalArgumentException - if the facet does not exist
      Since:
      5.4.2
    • removeFacet

      boolean removeFacet(String facet)
      Removes a facet from this document.

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

      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
      Since:
      5.4.2
    • setLock

      Lock setLock(Lock lock)
      Sets a lock on this document.
      Parameters:
      lock - the lock to set
      Returns:
      null if locking succeeded, or the existing lock if locking failed
    • removeLock

      Lock removeLock(String owner)
      Removes a lock from this document.
      Parameters:
      owner - the owner to check, or null for no check
      Returns:
      null if there was no lock or if removal succeeded, or a lock if it blocks removal due to owner mismatch
    • getLock

      Lock getLock()
      Gets the lock if one set on this document.
      Returns:
      the lock, or null if no lock is set
    • getChild

      Document getChild(String name)
      Gets a child document given its name.

      Throws DocumentNotFoundException if the document could not be found.

      Parameters:
      name - the name of the child to retrieve
      Returns:
      the child if exists
      Throws:
      DocumentNotFoundException - if the child does not exist
    • getChildren

      List<Document> getChildren()
      Gets the children of the document.
      Returns:
      the children
    • getChildrenIds

      List<String> getChildrenIds()
      Gets a list of the children ids.
      Returns:
      a list of children ids.
      Since:
      1.4.1
    • hasChild

      boolean hasChild(String name)
      Checks whether this document has a child of the given name.
      Parameters:
      name - the name of the child to check
      Returns:
      true if the child exists, false otherwise
    • hasChildren

      boolean hasChildren()
      Tests if the document has any children.
      Returns:
      true if the document has children, false otherwise
    • addChild

      Document addChild(String name, String typeName)
      Creates a new child document of the given type.
      Parameters:
      name - the name of the new child to create
      typeName - the type of the child to create
      Returns:
      the newly created document
    • orderBefore

      void orderBefore(String src, String dest)
      Orders the given source child before the destination child.

      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.

      Parameters:
      src - the document to move
      dest - the document before which to place the source document
    • checkIn

      Document checkIn(String label, String checkinComment)
      Creates a new version.
      Parameters:
      label - the version label
      checkinComment - the checkin comment
      Returns:
      the created version
    • checkOut

      void checkOut()
    • getVersionsIds

      List<String> getVersionsIds()
      Gets the list of version ids for this document.
      Returns:
      the list of version ids
      Since:
      1.4.1
    • getVersions

      List<Document> getVersions()
      Gets the versions for this document.
      Returns:
      the versions of the document, or an empty list if there are no versions
    • getLastVersion

      Document getLastVersion()
      Gets the last version of this document.

      Returns null if there is no version at all.

      Returns:
      the last version, or null if there is no version
    • getSourceDocument

      Document getSourceDocument()
      Gets the source for this document.

      For a version, it's the working copy.

      For a proxy, it's the version the proxy points to.

      Returns:
      the source document
    • restore

      void restore(Document version)
      Replaces this document's content with the version specified.
      Parameters:
      version - the version to replace with
    • getVersion

      Document getVersion(String label)
      Gets a version of this document, given its label.
      Parameters:
      label - the version label
      Returns:
      the version
    • isVersion

      boolean isVersion()
      Checks whether this document is a version document.
      Returns:
      true if it's a version, false otherwise
    • getBaseVersion

      Document getBaseVersion()
      Gets the version to which a checked in document is linked.

      Returns null for a checked out document or a version or a proxy.

      Returns:
      the version, or null
    • isCheckedOut

      boolean isCheckedOut()
      Checks whether this document is checked out.
      Returns:
      true if the document is checked out, or false otherwise
    • getVersionCreationDate

      Calendar getVersionCreationDate()
      Gets the version creation date of this document if it's a version or a proxy.
      Returns:
      the version creation date, or null if it's not a version or a proxy
    • getCheckinComment

      String getCheckinComment()
      Gets the version check in comment of this document if it's a version or a proxy.
      Returns:
      the check in comment, or null if it's not a version or a proxy
    • getVersionSeriesId

      String getVersionSeriesId()
      Gets the version series id.
      Returns:
      the version series id
    • getVersionLabel

      String getVersionLabel()
      Gets the version label.
      Returns:
      the version label
    • isLatestVersion

      boolean isLatestVersion()
      Checks whether this document is the latest version.
      Returns:
      true if this is the latest version, or false otherwise
    • isMajorVersion

      boolean isMajorVersion()
      Checks whether this document is a major version.
      Returns:
      true if this is a major version, or false otherwise
    • isLatestMajorVersion

      boolean isLatestMajorVersion()
      Checks whether this document is the latest major version.
      Returns:
      true if this is the latest major version, or false otherwise
    • isVersionSeriesCheckedOut

      boolean isVersionSeriesCheckedOut()
      Checks if there is a checked out working copy for the version series of this document.
      Returns:
      true if there is a checked out working copy
    • getWorkingCopy

      Document getWorkingCopy()
      Gets the working copy for this document.
      Returns:
      the working copy
    • getTargetDocument

      Document getTargetDocument()
      Gets the document (version or live document) to which this proxy points.
    • setTargetDocument

      void setTargetDocument(Document target)
      Sets the document (version or live document) to which this proxy points.