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 Summary
Constructors - 
Method Summary
Modifier 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)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, String 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 documentvoidinitialize(Document doc) Initializes lazy loaded collectionsLinks 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 stores 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
- 
DocTool
public DocTool() 
 - 
 - 
Method Details
- 
downloadUrl
Builds the download url of a document(download permalink)- Parameters:
 docId- identifier of the document- Returns:
 - the download permalink
 
 - 
displayUrl
Builds the display url of a document(display permalink)- Parameters:
 tenantId- identifier of the tenantdocId- identifier of the document- Returns:
 - the display permalink
 
 - 
downloadUrl
Builds the download url of a document(download permalink)- Parameters:
 doc- the document- Returns:
 - the download permalink
 
 - 
downloadUrl
Builds the download url of a document(download permalink)- Parameters:
 history- object representing an event on a document- Returns:
 - the download permalink
 
 - 
displayUrl
Builds the display url of a document(display permalink)- Parameters:
 doc- the document- Returns:
 - the display permalink
 
 - 
displayUrl
Builds the display url of a document(display permalink)- Parameters:
 history- object representing an event on a document- Returns:
 - the display permalink
 
 - 
downloadTicket
public 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 documentpdfConversion- if the pdf conversion should be downloaded instead of the original fileexpireHours- number of hours after which the ticket expiresexpireDate- a specific expiration datemaxDownloads- number of downloads over which the ticket expiresusername- the user in whose name the method is run- Returns:
 - the complete download ticket's URL
 
 - 
viewTicket
public 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 documentpdfConversion- if the pdf conversion should be downloaded instead of the original fileexpireHours- number of hours after which the ticket expiresexpireDate- a specific expiration datemaxDownloads- number of downloads over which the ticket expiresusername- the user in whose name the method is runmaxDownloads- number of views over which the ticket expires- Returns:
 - the complete download ticket's URL
 
 - 
displayFileSize
Prints the size of a file in human readable form- Parameters:
 size- the file size- Returns:
 - the human readable representation
 
 - 
store
Saves / updates a document into the database- Parameters:
 doc- the document to savetransaction- entry to log the event
 - 
store
Saves / updates a document into the database- Parameters:
 doc- the document to save
 - 
store
Saves / updates a document into the database- Parameters:
 doc- the document to saveusername- the user in whose name the method is run
 - 
create
Created a new document into the database- Parameters:
 doc- the document that carries the metadatafile- the document's contentusername- the user in whose name the method is run- Returns:
 - the created document
 
 - 
initialize
Initializes lazy loaded collections- Parameters:
 doc- the document to initialize
 - 
move
Moves a document into a target folder- Parameters:
 doc- the documenttargetPath- the full path of the target folderusername- the user in whose name the method is run
 - 
clone
Instantiate 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
 
 - 
copy
public Document copy(Document doc, String targetPath, boolean links, boolean notes, boolean security, String username) Copies a document into a target folder- Parameters:
 doc- the documenttargetPath- the full path of the target folderlinks- if the links must be copied toonotes- if the notes must be copied toosecurity- if the security settings must be copied toousername- the user in whose name the method is run- Returns:
 - the new document created
 
 - 
copy
Copies a document into a target folder- Parameters:
 doc- the documenttargetPath- the full path of the target folderusername- the user in whose name the method is run- Returns:
 - the new document created
 
 - 
link
Links two documents- Parameters:
 doc1- first documentdoc2- second documenttype- type of link(optional)- Returns:
 - the created link
 
 - 
createAlias
public 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 referencedtargetPath- the full path of the target foldertype- 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
 - 
createAlias
public Document createAlias(Document originalDoc, Folder targetFolder, String type, String username) Creates an alias to a document- Parameters:
 originalDoc- the original document to be referencedtargetFolder- the folder that will contain the aliastype- 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
 
 - 
lock
Locks a document- Parameters:
 docId- identifier of the documentusername- the user that locks the document
 - 
unlock
Unlocks a document- Parameters:
 docId- identifier of the documentusername- the user that locks the document
 - 
delete
Delete a document- Parameters:
 docId- identifier of the documentusername- the user in whose name the method is run
 - 
copyResource
public 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 documentfileVersion- The file versionsuffix- the suffix (eg conversion.pdf)newFileName- the file name of the new fileusername- the user in whose name the method is run- Returns:
 - the document
 
 - 
readAsString
Gets the content of a resource and stores it as a string- Parameters:
 docId- The document's identifierfileVersion- The file versionsuffix- The suffix- Returns:
 - the file content as string
 
 - 
writeToFile
Writes a resource in a file in the local file system- Parameters:
 docId- The document's identifierfileVersion- The file versionsuffix- the suffix (eg conversion.pdf)outputFile- the user in name of which to take this action
 - 
convertPDF
Converts 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
 - 
convert
Convert a document in another format and saves the result in another file in the same folder- Parameters:
 doc- the document to convertformat- it is the output format(e.g. pdf, txt, ...)username- the user in whose name the method is run- Returns:
 - the generated conversion document
 
 - 
merge
public 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 folderfileName- name of the output file(must ends with .pdf)username- the user in whose name the method is run- Returns:
 - the generated merged document
 
 - 
findById
Retrieves a document by it's identifier- Parameters:
 docId- identifier of the document- Returns:
 - the document object
 
 - 
findByPath
Retrieves a document by it's path- Parameters:
 path- full path of the document- Returns:
 - the document object
 
 - 
findByPath
Retrieves a document by it's path- Parameters:
 path- full path of the documenttenantId- identifier of the tenant(optional)- Returns:
 - the document object
 
 - 
getPath
Calculates the full path of a document- Parameters:
 doc- the document to inspect- Returns:
 - the full path
 
 - 
getIds
Converts 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
 
 - 
createPath
Creates a path, all existing nodes in the specified path will be reused- Parameters:
 doc- document used to take the root folder in case thetargetPathrepresents a relative pathtargetPath- absolute or relative(in relation to the document's parent folder) path to be createdusername- the user in whose name the method is run- Returns:
 - the folder leaf of the path
 
 - 
getHistories
Retrieve the list of events of a document- Parameters:
 docId- identifier of the documentevent- event name, optional- Returns:
 - list of histories
 
 - 
addNote
Creates a new note for the whole document- Parameters:
 doc- the documenttext- text of the noteusername- username of the user in name of which this action is taken
 - 
getNotes
Lists the notes of a given document- Parameters:
 docId- identifier of the documentfileVersion- version of the file, optional- Returns:
 - the list of notes
 
 - 
calculateNextVersion
Calculates 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
 
 - 
findTemplateByName
This method finds a template by name- Parameters:
 name- Name of the templatetenantId- Identifier of the owning tenant- Returns:
 - Template with given name
 
 - 
findTemplateById
This method finds a template by ID- Parameters:
 templateId- Identifier of the template- Returns:
 - Template with given name
 
 - 
countPages
Counts the number of pages of a document- Parameters:
 document- the document- Returns:
 - the number of pages
 
 - 
parse
Extracts the texts from a document, using the same analyzer used for the full-text processing.- Parameters:
 document- The document to elaboratefileVersion- Optional file version to consier- Returns:
 - the extracted texts
 
 
 -