Package com.logicaldoc.core.automation
Class DocTool
java.lang.Object
com.logicaldoc.core.automation.DocTool
Utility methods to handle documents from within Automation
- Since:
- 7.3
- Author:
- Marco Meschieri - LogicalDOC
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidCreates a new note for the whole documentcalculateNextVersion(String currentVersion, boolean major) Calculates what will be the next version specification.Instantiate a new document that is a clone of the given one.Convert a document in another format and saves the result in another file in the same foldervoidconvertPDF(Document doc) Converts a document in PDF format and saves it as ancillary resource of the document with suffixFormatConverterManager.PDF_CONVERSION_SUFFIX.copy(Document doc, String targetPath, boolean links, boolean notes, boolean security, String username) Copies a document into a target folderCopies a document into a target folderCopies a resource in a file in the same folder of the original documentintcountPages(Document document) Counts the number of pages of a documentCreated a new document into the databasecreateAlias(Document originalDoc, Folder targetFolder, String type, String username) Creates an alias to a documentcreateAlias(Document originalDoc, String targetPath, String type, String username) Creates an alias to a documentcreatePath(Document doc, String targetPath, String username) Creates a path, all existing nodes in the specified path will be reusedvoidDelete a documentdisplayFileSize(Long size) Prints the size of a file in human readable formdisplayUrl(long tenantId, long docId) Builds the display url of a document(display permalink)displayUrl(Document doc) Builds the display url of a document(display permalink)displayUrl(DocumentHistory history) Builds the display url of a document(display permalink)documentEvent(String eventKey) downloadTicket(long docId, boolean pdfConversion, Integer expireHours, Date expireDate, Integer maxDownloads, String username) Creates a new download ticket for a documentdownloadUrl(long docId) Builds the download url of a document(download permalink)downloadUrl(Document doc) Builds the download url of a document(download permalink)downloadUrl(DocumentHistory history) Builds the download url of a document(download permalink)findById(long docId) Retrieves a document by it's identifierfindByPath(String path) Retrieves a document by it's pathfindByPath(String path, Long tenantId) Retrieves a document by it's pathfindTemplateById(long templateId) This method finds a template by IDfindTemplateByName(String name, long tenantId) This method finds a template by namegetHistories(long docId, DocumentEvent event) Retrieve the list of events of a documentgetIds(Collection<Document> docs) Converts a collection of documents in a collection of identifiersLists the notes of a given documentCalculates the full path of a documentSame as parse() but first it tries to get the text from the already built fulltext indexvoidinitialize(Document doc) Initializes lazy loaded collectionsbooleanisDownloadAllowed(long documentId, long userId) booleanisPermissionAllowed(String permission, long documentId, long userId) This method checks if the given permission is enabled for a document and an user.booleanisPreviewAllowed(long documentId, long userId) booleanisReadAllowed(long documentId, long userId) booleanisWriteAllowed(long documentId, long userId) Links two documentsvoidLocks a documentmerge(Collection<Document> documents, long targetFolderId, String fileName, String username) Merges a set of documents into a single PDF filevoidMoves a document into a target folderExtracts the texts from a document, using the same analyzer used for the full-text processing.readAsString(long docId, String fileVersion, String suffix) Gets the content of a resource and reads it as a stringvoidSaves / updates a document into the databasevoidstore(Document doc, DocumentHistory transaction) Saves / updates a document into the databasevoidSaves / updates a document into the databasevoidUnlocks a documentviewTicket(long docId, boolean pdfConversion, Integer expireHours, Date expireDate, Integer maxDownloads, Integer maxViews, String username) Creates a new view ticket for a documentvoidwriteToFile(long docId, String fileVersion, String suffix, String outputFile) Writes a resource in a file in the local file system
- 
Constructor Details- 
DocToolpublic DocTool()
 
- 
- 
Method Details- 
downloadUrlBuilds the download url of a document(download permalink)- Parameters:
- docId- identifier of the document
- Returns:
- the download permalink
 
- 
displayUrlBuilds the display url of a document(display permalink)- Parameters:
- tenantId- identifier of the tenant
- docId- identifier of the document
- Returns:
- the display permalink
 
- 
downloadUrlBuilds the download url of a document(download permalink)- Parameters:
- doc- the document
- Returns:
- the download permalink
 
- 
downloadUrlBuilds the download url of a document(download permalink)- Parameters:
- history- object representing an event on a document
- Returns:
- the download permalink
 
- 
displayUrlBuilds the display url of a document(display permalink)- Parameters:
- doc- the document
- Returns:
- the display permalink
 
- 
displayUrlBuilds the display url of a document(display permalink)- Parameters:
- history- object representing an event on a document
- Returns:
- the display permalink
 
- 
documentEvent
- 
downloadTicketpublic String downloadTicket(long docId, boolean pdfConversion, Integer expireHours, Date expireDate, Integer maxDownloads, String username) Creates a new download ticket for a document- Parameters:
- docId- identifier of the document
- pdfConversion- if the pdf conversion should be downloaded instead of the original file
- expireHours- number of hours after which the ticket expires
- expireDate- a specific expiration date
- maxDownloads- number of downloads over which the ticket expires
- username- the user in whose name the method is run
- Returns:
- the complete download ticket's URL
 
- 
viewTicketpublic String viewTicket(long docId, boolean pdfConversion, Integer expireHours, Date expireDate, Integer maxDownloads, Integer maxViews, String username) Creates a new view ticket for a document- Parameters:
- docId- identifier of the document
- pdfConversion- if the pdf conversion should be downloaded instead of the original file
- expireHours- number of hours after which the ticket expires
- expireDate- a specific expiration date
- maxDownloads- number of downloads over which the ticket expires
- username- the user in whose name the method is run
- maxDownloads- number of views over which the ticket expires
- Returns:
- the complete download ticket's URL
 
- 
displayFileSizePrints the size of a file in human readable form- Parameters:
- size- the file size
- Returns:
- the human readable representation
 
- 
storeSaves / updates a document into the database- Parameters:
- doc- the document to save
- transaction- entry to log the event
 
- 
storeSaves / updates a document into the database- Parameters:
- doc- the document to save
 
- 
storeSaves / updates a document into the database- Parameters:
- doc- the document to save
- username- the user in whose name the method is run
 
- 
createCreated a new document into the database- Parameters:
- doc- the document that carries the metadata
- file- the document's content
- username- the user in whose name the method is run
- Returns:
- the created document
 
- 
initializeInitializes lazy loaded collections- Parameters:
- doc- the document to initialize
 
- 
moveMoves a document into a target folder- Parameters:
- doc- the document
- targetPath- the full path of the target folder
- username- the user in whose name the method is run
- Throws:
- InterruptedException- In case or thread interruption
 
- 
cloneInstantiate a new document that is a clone of the given one. The returned clone is not persisted.- Parameters:
- doc- The source document to clone
- Returns:
- The cloned document
 
- 
copypublic Document copy(Document doc, String targetPath, boolean links, boolean notes, boolean security, String username) Copies a document into a target folder- Parameters:
- doc- the document
- targetPath- the full path of the target folder
- links- if the links must be copied too
- notes- if the notes must be copied too
- security- if the security settings must be copied too
- username- the user in whose name the method is run
- Returns:
- the new document created
 
- 
copyCopies a document into a target folder- Parameters:
- doc- the document
- targetPath- the full path of the target folder
- username- the user in whose name the method is run
- Returns:
- the new document created
 
- 
linkLinks two documents- Parameters:
- doc1- first document
- doc2- second document
- type- type of link(optional)
- Returns:
- the created link
 
- 
createAliaspublic Document createAlias(Document originalDoc, String targetPath, String type, String username) throws PersistenceException Creates an alias to a document- Parameters:
- originalDoc- the original document to be referenced
- targetPath- the full path of the target folder
- type- the alias type(null for the original file or pdf for it's pdf conversion)
- username- the user in whose name the method is run
- Returns:
- The new alias created
- Throws:
- PersistenceException- Error in the database
 
- 
createAliaspublic Document createAlias(Document originalDoc, Folder targetFolder, String type, String username) Creates an alias to a document- Parameters:
- originalDoc- the original document to be referenced
- targetFolder- the folder that will contain the alias
- type- the alias type(null for the original file or pdf for it's pdf conversion)
- username- the user in whose name the method is run
- Returns:
- The new alias created
 
- 
lockLocks a document- Parameters:
- docId- identifier of the document
- username- the user that locks the document
 
- 
unlockUnlocks a document- Parameters:
- docId- identifier of the document
- username- the user that locks the document
 
- 
deleteDelete a document- Parameters:
- docId- identifier of the document
- username- the user in whose name the method is run
 
- 
copyResourcepublic Document copyResource(Document doc, String fileVersion, String suffix, String newFileName, String username) Copies a resource in a file in the same folder of the original document- Parameters:
- doc- The document
- fileVersion- The file version
- suffix- the suffix (eg conversion.pdf)
- newFileName- the file name of the new file
- username- the user in whose name the method is run
- Returns:
- the document
 
- 
readAsStringGets the content of a resource and reads it as a string- Parameters:
- docId- The document's identifier
- fileVersion- The file version
- suffix- The suffix
- Returns:
- the file content as string
 
- 
writeToFileWrites a resource in a file in the local file system- Parameters:
- docId- The document's identifier
- fileVersion- The file version
- suffix- the suffix (eg conversion.pdf)
- outputFile- the user in name of which to take this action
 
- 
convertPDFConverts a document in PDF format and saves it as ancillary resource of the document with suffixFormatConverterManager.PDF_CONVERSION_SUFFIX. If the conversion already exists, nothing will be done.- Parameters:
- doc- the document to convert
 
- 
convertConvert a document in another format and saves the result in another file in the same folder- Parameters:
- doc- the document to convert
- format- it is the output format(e.g. pdf, txt, ...)
- username- the user in whose name the method is run
- Returns:
- the generated conversion document
 
- 
mergepublic Document merge(Collection<Document> documents, long targetFolderId, String fileName, String username) Merges a set of documents into a single PDF file- Parameters:
- documents- the list of documents to merge(the order counts)
- targetFolderId- identifier of the target folder
- fileName- name of the output file(must ends with .pdf)
- username- the user in whose name the method is run
- Returns:
- the generated merged document
 
- 
findByIdRetrieves a document by it's identifier- Parameters:
- docId- identifier of the document
- Returns:
- the document object
 
- 
findByPathRetrieves a document by it's path- Parameters:
- path- full path of the document
- Returns:
- the document object
 
- 
findByPathRetrieves a document by it's path- Parameters:
- path- full path of the document
- tenantId- identifier of the tenant(optional)
- Returns:
- the document object
 
- 
getPathCalculates the full path of a document- Parameters:
- doc- the document to inspect
- Returns:
- the full path
 
- 
getIdsConverts a collection of documents in a collection of identifiers- Parameters:
- docs- the input collection
- Returns:
- the list of all the IDs of the documents in the input collection
 
- 
createPathCreates a path, all existing nodes in the specified path will be reused- Parameters:
- doc- document used to take the root folder in case the- targetPathrepresents a relative path
- targetPath- absolute or relative(in relation to the document's parent folder) path to be created
- username- the user in whose name the method is run
- Returns:
- the folder leaf of the path
 
- 
getHistoriesRetrieve the list of events of a document- Parameters:
- docId- identifier of the document
- event- event name, optional
- Returns:
- list of histories
 
- 
addNoteCreates a new note for the whole document- Parameters:
- doc- the document
- text- text of the note
- username- username of the user in name of which this action is taken
 
- 
getNotesLists the notes of a given document- Parameters:
- docId- identifier of the document
- fileVersion- version of the file, optional
- Returns:
- the list of notes
 
- 
calculateNextVersionCalculates what will be the next version specification. @seeVersion.getNewVersionName(String, boolean)- Parameters:
- currentVersion- the current version(e.g. 1.1, 2.15, ...)
- major- if the new release must be a major release
- Returns:
- the new version
 
- 
findTemplateByNameThis method finds a template by name- Parameters:
- name- Name of the template
- tenantId- Identifier of the owning tenant
- Returns:
- Template with given name
 
- 
findTemplateByIdThis method finds a template by ID- Parameters:
- templateId- Identifier of the template
- Returns:
- Template with given name
 
- 
countPagesCounts the number of pages of a document- Parameters:
- document- the document
- Returns:
- the number of pages
 
- 
parseExtracts the texts from a document, using the same analyzer used for the full-text processing.- Parameters:
- document- The document to elaborate
- fileVersion- Optional file version to consier
- Returns:
- the extracted texts
 
- 
getTextSame as parse() but first it tries to get the text from the already built fulltext index- Parameters:
- document- The document to elaborate
- Returns:
- the extracted texts
 
- 
isPermissionAllowedThis method checks if the given permission is enabled for a document and an user.- Parameters:
- permission- the permission to check
- documentId- ID of the folder
- userId- ID of the user
- Returns:
- if the permission is granted to the user
 
- 
isWriteAllowedpublic boolean isWriteAllowed(long documentId, long userId) 
- 
isReadAllowedpublic boolean isReadAllowed(long documentId, long userId) 
- 
isPreviewAllowedpublic boolean isPreviewAllowed(long documentId, long userId) 
- 
isDownloadAllowedpublic boolean isDownloadAllowed(long documentId, long userId) 
 
-