Class DocumentMcpTool

java.lang.Object
org.exoplatform.documents.mcp.DocumentMcpTool
All Implemented Interfaces:
io.meeds.mcp.server.plugin.McpToolPlugin

@Service @Profile("mcp-server") public class DocumentMcpTool extends Object implements io.meeds.mcp.server.plugin.McpToolPlugin
MCP tools exposing the Documents (DMS) add-on to the AI agent (EVA). Every method acts as the current user, so document ACLs are enforced by DocumentFileService. These tools only READ or update document metadata / content; they carry no coupling to the AI service layer (the AI-powered document experiences remain in the enterprise edition).
  • Field Details

    • FOLDER_URL_FORMAT

      public static final String FOLDER_URL_FORMAT
      See Also:
    • FILE_URL_FORMAT

      public static final String FILE_URL_FORMAT
      See Also:
  • Constructor Details

    • DocumentMcpTool

      public DocumentMcpTool(org.exoplatform.documents.service.DocumentFileService documentFileService, org.exoplatform.services.attachments.service.AttachmentService attachmentService, org.exoplatform.social.attachment.AttachmentService socialAttachmentService, org.exoplatform.commons.file.services.FileService fileService, org.exoplatform.social.core.manager.IdentityManager identityManager, org.exoplatform.social.core.space.spi.SpaceService spaceService, io.meeds.social.translation.service.TranslationService translationService, org.exoplatform.social.core.profileproperty.ProfilePropertyService profilePropertyService, org.exoplatform.portal.config.UserACL userAcl, org.exoplatform.portal.config.UserPortalConfigService portalConfigService, org.exoplatform.upload.UploadService uploadService, org.exoplatform.documents.service.PublicDocumentAccessService publicDocumentAccessService, org.exoplatform.social.metadata.favorite.FavoriteService favoriteService)
  • Method Details

    • getScopeSpaceId

      protected Long getScopeSpaceId()
      Returns:
      the space the current call is limited to, null when it isn't
      Throws:
      IllegalStateException - when the call's identity can't be read
    • getRootFolderBySpace

      public DocumentFolderModel getRootFolderBySpace(Long spaceId, String spaceName) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Reads the root folder of a space's documents, the space given by its id or by its name, exactly one of them. A name is looked up among the spaces the user is a member of, and nothing is guessed.
      Parameters:
      spaceId - the space's id, null when the space is given by its name
      spaceName - the space's name, blank when the space is given by its id
      Returns:
      the space's root folder
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException - when the space doesn't exist, or no space of the user carries the name: the message says how to find it
      IllegalAccessException - when the user can't view the space, or a call limited to a space names another one
      IllegalArgumentException - when both or neither are given, or several of the user's spaces carry the name
    • attachDocumentToContent

      public void attachDocumentToContent(String documentId, String contentType, long contentId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Links an existing document to another content entity (an activity, a note, …) as an attachment, acting as the current user. Validates the document id and the user's read access on it first — matching every sibling tool method — so a blank or inaccessible id fails cleanly instead of reaching the attachment service with an unchecked reference.
      Parameters:
      documentId - the id of the document to attach
      contentType - the target content type the document is attached to
      contentId - the target content id the document is attached to
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • updateDocumentDescription

      public void updateDocumentDescription(String documentId, String htmlDescription) throws IllegalAccessException, Exception
      Throws:
      IllegalAccessException
      Exception
    • getDocumentsByFolderId

      public List<DocumentModel> getDocumentsByFolderId(String folderId, Boolean filesOnly, Boolean foldersOnly, Integer offset, Integer limit) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Lists a page of a folder's children, folders first. A negative limit lists nothing, as list_folder_children does: the storage would read every child.
      Parameters:
      folderId - the folder
      filesOnly - whether only the files are kept
      foldersOnly - whether only the folders are kept
      offset - the first child listed, 0 by default
      limit - the most children listed, the default page size when null or 0, at most 100
      Returns:
      the folder's children on that page
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException - when the folder doesn't exist
      IllegalAccessException - when the user can't read the folder
    • getRootFolderForUser

      public DocumentFolderModel getRootFolderForUser()
    • getDocumentById

      public DocumentModel getDocumentById(String documentId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Returns a document's metadata, with the user's rights on it. A shortcut resolves to its target, whose metadata and edit right are returned; its delete right is left out, deleting the shortcut removing only the shortcut.
      Parameters:
      documentId - the document id
      Returns:
      the document
      Throws:
      IllegalAccessException - when the user can't read it
      org.exoplatform.commons.exception.ObjectNotFoundException - when it doesn't exist
    • getDocumentContentById

      public String getDocumentContentById(String documentId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Returns the text of a document the current user can access: from the search index when it holds it, else extracted from the file itself. When neither gives any text, the actual reason is raised rather than an empty answer, so the agent can tell the user why instead of guessing from the file name.

      The reason never claims the file is still being indexed: the search index service exposes no way to know whether an indexing operation is pending for a file, and the file itself was just read without success. Only a busy extractor, a fact known for certain, is worded as worth another attempt.

      A file too large to be read in one go is read as read_document_text reads it, up to the largest file a user can attach: its first part is returned, with the length of its text and the offset to read on.

      Parameters:
      documentId - the document identifier
      Returns:
      the text of the document
      Throws:
      IllegalAccessException - when the user cannot access the document
      org.exoplatform.commons.exception.ObjectNotFoundException - when the document does not exist
      IllegalStateException - when the document has no readable text, with the reason
    • readDocumentText

      public DocumentTextPartModel readDocumentText(String documentId, Long offset, Integer maxChars, Integer section) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Reads a part of a document's text: from an offset, or the section of one heading of get_document_outline, at most a given number of characters, and says where the next part starts. A document too large to be read in one go is read this way, part by part.
      Parameters:
      documentId - the document id
      offset - the first character, from 0, in the whole text, as next_offset gives it; within a section, brought into it: the section's start when before it
      maxChars - the most characters returned
      section - the index of the heading whose section is read, null to read by offset
      Returns:
      the part read
      Throws:
      IllegalAccessException - when the user cannot access the document
      org.exoplatform.commons.exception.ObjectNotFoundException - when the document does not exist
      IllegalStateException - when the document has no readable text, with the reason
      IllegalArgumentException - when the section isn't one of the outline
    • getDocumentOutline

      public DocumentOutlineModel getDocumentOutline(String documentId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Lists a document's headings: a Word document's headings, a PDF's bookmarks, a presentation's slide titles, a spreadsheet's sheets, each with where its section starts and ends in the text read_document_text reads.
      Parameters:
      documentId - the document id
      Returns:
      the outline, empty when the document has no heading
      Throws:
      IllegalAccessException - when the user cannot access the document
      org.exoplatform.commons.exception.ObjectNotFoundException - when the document does not exist
      IllegalStateException - when the document has no readable text, with the reason
    • getDocumentTranscriptionById

      public String getDocumentTranscriptionById(String documentId, Boolean timestamps) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      The transcript of an audio or video file, read with the user's rights. When there is none, the answer says why, from the file's transcription state (EXO-92097): queued, in progress with its progress, stopped when its run was lost (running, unchanged for TranscriptionState.STALE_MILLIS), failed with its reason, transcribed with no speech heard; a file never sent to transcription answers as before. A transcript grouped into chapters (EXO-92122) is given after the list of its chapters, each with the moment it starts, its title and its summary, so that the assistant can say where in the recording a subject was discussed. Asked with timestamps, a transcript that has timed segments is given one segment per line, each starting with the moment it was said, [mm:ss · Ns] ([h:mm:ss · Ns] past an hour), where N is that moment in whole seconds (EXO-92112); without segments, the plain transcript is given, as without timestamps, or its turns when it tells who speaks. A transcript whose segments tell who speaks (EXO-92123) is given after the list of its speakers, each with its talk time, and each of its lines names who said it: the person named for the speaker, the guest's name, or Speaker N; without timestamps, it is given one turn per line, Name: text, with no moment.
      Parameters:
      documentId - the file's UUID
      timestamps - true to have each segment start with its moment
      Returns:
      the transcript
      Throws:
      IllegalAccessException - when the user may not read the file
      org.exoplatform.commons.exception.ObjectNotFoundException - when the file does not exist
      IllegalStateException - when the file has no transcript, saying why
    • searchDocuments

      public List<DocumentFileModel> searchDocuments(String query, Long spaceId, String spaceName, String parentFolderId, Integer offset, Integer limit, Boolean isFavorites, String updatedSince) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Searches the documents the user can read, optionally in one space, given by its id or by its name (at most one of them), or under one folder.
      Parameters:
      query - the full-text query
      spaceId - the space to search in, null for none
      spaceName - the name of the space to search in, blank for none
      parentFolderId - the folder to search under, which wins over the space
      offset - the first result
      limit - the most results
      isFavorites - true to search the user's favorites only
      updatedSince - an ISO-8601 date or date-time: only the files changed since then, the most recent first; blank for any date
      Returns:
      the matching documents
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException - when the space doesn't exist, or no space of the user carries the name
      IllegalAccessException - when the user can't view the space
      IllegalArgumentException - when both a space id and a name are given, several of the user's spaces carry the name, the date can't be read, or neither a query nor a date is given
    • listFolderChildren

      public List<DocumentModel> listFolderChildren(String folderId, Integer offset, Integer limit, String updatedSince) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Lists the direct children of a folder, folders first, or with a date only the children changed since then, the most recent first.

      Without a date, the storage pages over the listing itself. A date is checked against the same last-change date the listing shows, over the folder's children read in one go, up to MAX_SCANNED_CHILDREN: the storage fills a page up to its limit whenever the folder holds more children, however many rows it leaves out (a shortcut whose target is gone), so a listing asked for one child more than the bound returns it exactly when the folder holds more, and such a folder is refused rather than answered with part of its changes.

      Parameters:
      folderId - the folder id
      offset - the first child
      limit - the most children, at most 100
      updatedSince - an ISO-8601 date or date-time, blank for any date
      Returns:
      the children
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException - when the folder doesn't exist
      IllegalAccessException - when the user can't read the folder
      IllegalArgumentException - when the folder id is blank, the date can't be read, or the folder holds too many children to filter
    • getDocumentPermissions

      public DocumentPermissionsModel getDocumentPermissions(String documentId) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Tells what the current user may do on a folder or a file: the edit right as the repository checks it for the user; the delete right as the storage computes it (the document's permission entries, and any document of the user's own drive), plus the owner's, whom the repository grants every right although that computation leaves the owner out. For a shortcut, the rights are its target's, named in the answer, and the delete right is left out: deleting the shortcut removes only the shortcut.
      Parameters:
      documentId - the folder or file id
      Returns:
      the user's rights on it
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException - when the document doesn't exist
      IllegalAccessException - when the user can't read the document
    • getFolderBreadcrumb

      public List<BreadcrumbItemModel> getFolderBreadcrumb(String folderId) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException
      IllegalAccessException
    • getFolderTree

      public List<DocumentTreeItemModel> getFolderTree(String folderId, Boolean withChildren) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException
      IllegalAccessException
    • listDocumentVersions

      public List<DocumentVersionModel> listDocumentVersions(String documentId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • getDocumentsSize

      public DocumentsSizeModel getDocumentsSize(Long ownerId) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException
      IllegalAccessException
    • createFolder

      public DocumentModel createFolder(String parentFolderId, String name) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Creates a folder under a parent folder, or a chain of nested folders when the name is a path: each segment of Finances/Factures/Entrantes but the last reuses the child folder of that name when there is one and is created otherwise, and the last one is created. A whole tree then takes one call per leaf, every call naming the same parent: none of them needs the id of a folder created by another call of the same round, an id a model calling them together does not have yet and makes up instead.
      Parameters:
      parentFolderId - the folder the name, or the path's first segment, is created under
      name - the folder name, or a path of folder names separated by /
      Returns:
      the last folder of the path, the one created
      Throws:
      IllegalAccessException - when the user cannot read the parent folder or add a folder to it
      org.exoplatform.commons.exception.ObjectNotFoundException - when no folder has the parent folder id
    • createDocument

      public DocumentModel createDocument(String parentFolderId, String name, String content) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Creates a text-based document (markdown, HTML, plain text, CSV, JSON…) from a chat-authored content string. This is the chat-native way to turn generated text into a real file in the Documents app. The name must include a file extension: the extension drives the stored content type via the platform MimeTypeResolver, so use a registered text extension (.txt, .html, .csv, .json, .xml…) so the file has the correct type and is readable via get_document_content_by_id.
      Parameters:
      parentFolderId - the folder where the document is created (get it from get_root_folder_for_user / get_root_folder_by_space / get_documents_by_folder_id)
      name - the document file name, including its extension (e.g. 'notes.md', 'report.txt', 'page.html'). The extension determines the file's content type (via the platform MimeTypeResolver); the name is used as-is.
      content - the text / markdown / HTML body
      Returns:
      the created document
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • createDocumentFromTemplate

      public DocumentModel createDocumentFromTemplate(String parentFolderId, String name, String documentType) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Creates a NEW EMPTY office document (Word/Excel/PowerPoint, or ODF) from the platform's blank template, by delegating to the ecms DocumentService. Use this when the user wants a blank Word/Excel/PowerPoint document to fill in (e.g. via the online editor): create_document cannot produce office files (they are structured packages, not text) and upload_document needs the real file bytes. The template is created synchronously; the file extension is added automatically from documentType.
      Parameters:
      parentFolderId - the folder where the document is created (get it from get_root_folder_for_user / get_root_folder_by_space / get_documents_by_folder_id)
      name - the document name, WITHOUT extension (e.g. 'Q3 report'); the extension is appended automatically from documentType
      documentType - the office document type: one of docx, xlsx, pptx. Availability depends on the installed editor add-on (onlyoffice).
      Returns:
      the created document
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • uploadDocument

      public DocumentModel uploadDocument(String parentFolderId, String name, String base64, String url, String attachmentObjectType, String attachmentObjectId, String onConflict, String uploadId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Uploads a real / binary document (PDF, image, office file…) from exactly one of four sources: a file/image the user attached in the chat conversation (resolved server-side as the current user via attachment_object_type / attachment_object_id), a file the user sent through an upload link (upload_id, filed from its staged file, never read into memory), a base64 payload, or an http(s) URL (fetched server-side behind an SSRF guard).
      Parameters:
      parentFolderId - the destination folder id (get it from get_root_folder_for_user / get_root_folder_by_space / get_documents_by_folder_id)
      name - the document file name including its extension (e.g. 'report.pdf'); when uploading from a URL or a chat attachment it may be left blank to reuse the source file name
      base64 - the file bytes encoded in base64, at most CHUNK_CHARS (20000) characters, a larger file being sent in pieces (mutually exclusive with url / the chat attachment)
      url - an http(s) URL to download the file from, read up to DocumentUploadLimit.URL_FETCH_MAX_BYTES, or the upload size limit when it is lower (mutually exclusive with base64 / the chat attachment)
      attachmentObjectType - the object type of the file the user attached in chat; set automatically by the client — do not fill it from the model
      attachmentObjectId - the object id of the file the user attached in chat; set automatically by the client — do not fill it from the model
      onConflict - what to do when the folder holds a file of that name: keep_both (the default) or new_version
      uploadId - the id start_upload returned, once its curl command sent the file: one of the user's own uploads, consumed by this call once read, whether it succeeds or fails (mutually exclusive with the other sources)
      Returns:
      the created document
      Throws:
      IllegalArgumentException - when a parameter is missing or wrong (the folder id, the source, the name, the conflict action), the file is empty or over the upload size limit, the upload id names no upload of the user's, or a new version is asked of a folder, a shortcut or a file that keeps no versions
      IllegalStateException - when the file can't be read from its source or filed, or the upload is still being sent or failed
      org.exoplatform.commons.exception.ObjectNotFoundException - when the folder or the attachment doesn't exist
      IllegalAccessException - when the user can't read the attachment, or read the folder or add documents to it
    • startDocumentUpload

      public DocumentUploadModel startDocumentUpload(String parentFolderId, String name, Long size, String onConflict) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Starts sending a file in pieces, for a file too large to be sent whole in one tool call: checks the folder, the user's right to add a document to it, the file's size and that its name can take the conflict action, before any piece is sent. The piece that completes the size files the document.
      Parameters:
      parentFolderId - the folder the file is filed into
      name - the file name, with its extension
      size - the file's size, in bytes
      onConflict - what to do when the folder holds a file of that name: keep_both (the default) or new_version
      Returns:
      the upload, with how to send its pieces
      Throws:
      IllegalArgumentException - when a parameter is missing or wrong (the folder id, the name, the size, the conflict action), the size is over the upload size limit, or a new version is asked of a folder, a shortcut or a file that keeps no versions
      IllegalStateException - when the user has too many uploads in progress, the folder can't be read to check the name, or the upload can't be stored on this server
      org.exoplatform.commons.exception.ObjectNotFoundException - when the folder doesn't exist
      IllegalAccessException - when the user can't read the folder or add documents to it
    • appendDocumentUploadChunk

      public DocumentUploadModel appendDocumentUploadChunk(String uploadId, Integer index, String base64) throws IllegalAccessException
      Adds the next piece of a file sent in pieces; the piece that completes the file files it, and returns the document. A piece sent again after a lost answer is acknowledged without being added twice, and the last one returns the document it was filed as.
      Parameters:
      uploadId - the upload
      index - the piece's number, from 0
      base64 - the piece, base64-encoded
      Returns:
      the upload, with the next piece expected, or with its document once filed
      Throws:
      IllegalStateException - when the last piece is sent again while its file is being filed, which leaves the upload open, to be sent again; or when the piece can't be stored, or the file can't be filed, its folder gone included, which ends the upload
      IllegalArgumentException - when the piece is refused, which leaves the upload open, or when the file is refused at its filing, a new version asked of a folder, a shortcut or a file that keeps no versions, which ends the upload
      IllegalAccessException - when the user can no longer add documents to the folder, which ends the upload
    • renameDocument

      public void renameDocument(String documentId, String newName) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Renames a file or a folder.
      Parameters:
      documentId - the file or folder
      newName - its new name
      Throws:
      IllegalAccessException - when the user can't rename the node, or, in a call limited to a space, the node was created by the platform for the space or the call's space can't be read
      org.exoplatform.commons.exception.ObjectNotFoundException - when the node doesn't exist
    • moveDocument

      public void moveDocument(String documentId, String destinationFolderId, String conflictAction) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Moves a file or a folder into another folder; in a call limited to a space, the destination folder must be in that space.
      Parameters:
      documentId - the file or folder to move
      destinationFolderId - the destination folder
      conflictAction - what to do when the destination holds a node of the same name, keepBoth by default
      Throws:
      IllegalAccessException - when the user can't move the node there, or, in a call limited to a space, the destination folder isn't in that space, the node was created by the platform for the space, or the call's space can't be read
      org.exoplatform.commons.exception.ObjectNotFoundException - when a node doesn't exist
    • copyDocument

      public DocumentModel copyDocument(String documentId, String destinationFolderId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Copies a file into another folder; in a call limited to a space, the destination folder must be in that space.
      Parameters:
      documentId - the file to copy
      destinationFolderId - the destination folder
      Returns:
      the copy
      Throws:
      IllegalAccessException - when the user can't copy the node there, or, in a call limited to a space, the destination folder isn't in that space, the node was created by the platform for the space, or the call's space can't be read
      org.exoplatform.commons.exception.ObjectNotFoundException - when a node doesn't exist
      IllegalArgumentException - when the destination folder holds 1000 items or more: the copy could not be found among them afterwards, so nothing is copied
      IllegalStateException - when the copy is made but cannot be found: the folder grew past 1000 items meanwhile, or no added node carries the expected name
    • duplicateDocument

      public DocumentModel duplicateDocument(String documentId, String prefix) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Duplicates a file or a folder in its own folder, with an optional prefix and a " (n)" counter, and returns the duplicate.
      Parameters:
      documentId - the file or folder to duplicate
      prefix - an optional prefix of the duplicate's name
      Returns:
      the duplicate, a file or a folder like the source
      Throws:
      IllegalAccessException - when the user can't read or duplicate the node, or, in a call limited to a space, the node was created by the platform for the space or the call's space can't be read
      org.exoplatform.commons.exception.ObjectNotFoundException - when the node doesn't exist
      IllegalArgumentException - when the source's folder holds 1000 items or more: the duplicate could not be found among them afterwards, so nothing is duplicated
      IllegalStateException - when the duplicate is made but cannot be found: the folder grew past 1000 items meanwhile, or no added node carries the expected name
    • deleteDocument

      public void deleteDocument(String documentId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • undoDeleteDocument

      public void undoDeleteDocument(String documentId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Restores a document that was deleted with delete_document: since that tool trashes immediately (delay 0), the delayed-delete cancel path is a no-op, so the node is resolved from trash (it keeps its id/uuid after the move) and restored to its original location.
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • restoreDocumentVersion

      public DocumentVersionModel restoreDocumentVersion(String versionId)
    • updateVersionSummary

      public DocumentVersionModel updateVersionSummary(String documentId, String versionId, String summary)
    • setDocumentVisibility

      public void setDocumentVisibility(String documentId, Boolean hidden) throws IllegalAccessException
      Hides a file or a folder from the listings, or shows it again; hiding a folder may also hide some of its direct children. In a call limited to a space, only a folder the platform didn't create for the space.
      Parameters:
      documentId - the file or folder
      hidden - true to hide it, false to show it
      Throws:
      IllegalAccessException - in a call limited to a space, when the node is a file or was created by the platform, or the call's space can't be read
      IllegalStateException - when the storage refuses the change, the user's refused access included, which it reports wrapped
    • addDocumentVersion

      public DocumentModel addDocumentVersion(String documentId, String content, String base64, String url, String attachmentObjectType, String attachmentObjectId, String versionSummary, String uploadId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Uploads updated content onto an EXISTING file, creating a NEW version of it (the previous content stays retrievable via list_document_versions / restore_document_version). The new bytes come from exactly one source: a chat-authored text content string, a base64 payload, an http(s) url, a file the user attached in the conversation, or a file the user sent through an upload link (upload_id, streamed from its staged file, never read into memory). The file's name and type are unchanged; only its content and version history are updated.
      Parameters:
      documentId - the id of the existing file to add a version to (get it from get_document_by_id / get_documents_by_folder_id / search_documents)
      content - plain text / markdown / HTML body to write as the new version (use for text files)
      base64 - the new file bytes encoded in base64, at most CHUNK_CHARS (20000) characters
      url - an http(s) URL to download the new content from (fetched server-side behind an SSRF guard, up to DocumentUploadLimit.URL_FETCH_MAX_BYTES, or the upload size limit when it is lower)
      attachmentObjectType - the object type of the file the user attached in chat; set automatically by the client — do not fill it from the model
      attachmentObjectId - the object id of the file the user attached in chat; set automatically by the client — do not fill it from the model
      versionSummary - an optional change note stored on the new version
      uploadId - the id start_upload returned, once its curl command sent the file: one of the user's own uploads, consumed by this call once read, whether it succeeds or fails; refused in a call limited to a space
      Returns:
      the updated document (with its refreshed size / modification info)
      Throws:
      IllegalArgumentException - when not exactly one source is given, the document is a folder, the content is over the upload size limit or refused by a validator, or the upload id names no upload of the user's
      IllegalStateException - when the content can't be read from its source, or the upload is still being sent or failed
      IllegalAccessException - when the user can't edit the document, or an upload id is given in a call limited to a space, or, in a call limited to a space, the file was created by the platform for the space, or the call's space can't be read
      org.exoplatform.commons.exception.ObjectNotFoundException - when the document doesn't exist
    • createPublicLink

      public DocumentPublicLinkModel createPublicLink(String documentId, String password, Long expirationDate) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Creates (or refreshes) an anonymous public share link for a document so it can be downloaded without signing in, optionally protected by a password and/or an expiration date. Requires edit permission on the document.
      Parameters:
      documentId - the id of the file to share publicly (get it from the read tools)
      password - an optional password required to open the link
      expirationDate - an optional expiration date, as epoch milliseconds; after it the link stops working. Leave blank for a link that never expires.
      Returns:
      the shareable link, together with its password and expiration
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • createDocumentShortcut

      public void createDocumentShortcut(String documentId, String destinationFolderId, String conflictAction) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Creates a shortcut (symlink) to a document inside another folder, so the same file appears in a second location without being copied.
      Parameters:
      documentId - the id of the file or folder to create a shortcut to
      destinationFolderId - the id of the folder where the shortcut is placed (get it from get_root_folder_for_user / get_root_folder_by_space / get_documents_by_folder_id)
      conflictAction - behaviour when a node with the same name already exists in the destination; only 'keepBoth' is honoured, defaults to 'keepBoth'
      Throws:
      IllegalAccessException - when the user can't read the nodes, or, in a call limited to a space, the destination folder isn't in that space, the node was created by the platform for the space, or the call's space can't be read
      org.exoplatform.commons.exception.ObjectNotFoundException - when a node doesn't exist
    • shareDocument

      public void shareDocument(String documentId, String username, Long spaceId, String spaceName, Boolean notify) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Shares a document with another user or with a space: the recipient is GRANTED read access to the file and gets it in their "Shared" folder. Provide exactly one of username, spaceId or spaceName. Requires edit permission on the document.
      Parameters:
      documentId - the id of the file to share (get it from the read tools)
      username - the username to share the document with (mutually exclusive with spaceId and spaceName)
      spaceId - the id of the space to share the document with (mutually exclusive with username and spaceName)
      spaceName - the name of the space to share the document with, one of the spaces the user is a member of (mutually exclusive with username and spaceId)
      notify - whether to notify the recipient; defaults to true
      Throws:
      IllegalAccessException - when the user can't edit the document
      org.exoplatform.commons.exception.ObjectNotFoundException - when the document, the user or the space doesn't exist, or no space of the user carries the name
      IllegalArgumentException - when not exactly one recipient is given, or several of the user's spaces carry the name
    • favoriteDocument

      public void favoriteDocument(String documentId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Adds a file to the current user's favorites. Only files can be favorited; folders have no favorites view in the Documents app.
      Parameters:
      documentId - the id of the file to mark as favorite
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • unfavoriteDocument

      public void unfavoriteDocument(String documentId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Removes a file from the current user's favorites. Only files can be favorited; folders have no favorites view in the Documents app.
      Parameters:
      documentId - the id of the file to remove from favorites
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException