Package com.logicaldoc.core.automation
Class DocTool
- java.lang.Object
-
- com.logicaldoc.core.automation.DocTool
-
public class DocTool extends Object
Utility methods to handle documents from within Automation- Since:
- 7.3
- Author:
- Marco Meschieri - LogicalDOC
-
-
Constructor Summary
Constructors Constructor Description DocTool()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addNote(Document doc, String text, String username)
Creates a new note for the whole documentString
calculateNextVersion(String currentVersion, boolean major)
Calculates what will be the next version specification.Document
convert(Document doc, String format, String username)
Convert a document in another format and saves the result in another file in the same folderDocument
copy(Document doc, String targetPath, String username)
Copies a document into a target folderDocument
copyResource(Document doc, String fileVersion, String suffix, String newFileName, String username)
Copies a resource in a file in the same folder of the original documentFolder
createPath(Document doc, String targetPath, String username)
Creates a path, all existing nodes in the specified path will be reusedvoid
delete(long docId, String username)
Delete a documentString
displayFileSize(Long size)
Prints the size of a file in human readable formString
displayUrl(long tenantId, long docId)
Builds the display url of a document(display permalink)String
displayUrl(Document doc)
Builds the display url of a document(display permalink)String
displayUrl(DocumentHistory history)
Builds the display url of a document(display permalink)String
downloadTicket(long docId, boolean pdfConversion, Integer expireHours, Date expireDate, Integer maxDownloads, String username)
Creates a new download ticket for a documentString
downloadUrl(long docId)
Builds the download url of a document(download permalink)String
downloadUrl(Document doc)
Builds the download url of a document(download permalink)String
downloadUrl(DocumentHistory history)
Builds the download url of a document(download permalink)Document
findById(long docId)
Retrieves a document by it's identifierDocument
findByPath(String path)
Retrieves a document by it's pathDocument
findByPath(String path, Long tenantId)
Retrieves a document by it's pathList<DocumentHistory>
getHistories(long docId, String event)
Retrieve the list of events of a documentList<Long>
getIds(Collection<Document> docs)
Converts a collection of documents in a collection of identifiersList<DocumentNote>
getNotes(long docId, String fileVersion)
Lists the notes of a given documentString
getPath(Document doc)
Calculates the full path of a documentvoid
initialize(Document doc)
Initializes lazy loaded collectionsvoid
lock(long docId, String username)
Locks a documentDocument
merge(Collection<Document> documents, long targetFolderId, String fileName, String username)
Merges a set of documents into a single PDF filevoid
move(Document doc, String targetPath, String username)
Moves a document into a target foldervoid
store(Document doc)
Saves / updates a document into the databasevoid
store(Document doc, String username)
Saves / updates a document into the databasevoid
unlock(long docId, String username)
Unlocks a documentvoid
writeToFile(long docId, String fileVersion, String suffix, String outputFile)
Writes a resource in a file in the local file system
-
-
-
Method Detail
-
downloadUrl
public String downloadUrl(long docId)
Builds the download url of a document(download permalink)- Parameters:
docId
- identifier of the document- Returns:
- the download permalink
-
displayUrl
public String displayUrl(long tenantId, long docId)
Builds the display url of a document(display permalink)- Parameters:
tenantId
- identifier of the tenantdocId
- identifier of the document- Returns:
- the display permalink
-
downloadUrl
public String downloadUrl(Document doc)
Builds the download url of a document(download permalink)- Parameters:
doc
- the document- Returns:
- the download permalink
-
downloadUrl
public String downloadUrl(DocumentHistory history)
Builds the download url of a document(download permalink)- Parameters:
history
- object representing an event on a document- Returns:
- the download permalink
-
displayUrl
public String displayUrl(Document doc)
Builds the display url of a document(display permalink)- Parameters:
doc
- the document- Returns:
- the display permalink
-
displayUrl
public String displayUrl(DocumentHistory history)
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) throws Exception
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
- Throws:
Exception
- a generic error happened
-
displayFileSize
public String displayFileSize(Long size)
Prints the size of a file in human readable form- Parameters:
size
- the file size- Returns:
- the human readable representation
-
store
public void store(Document doc)
Saves / updates a document into the database- Parameters:
doc
- the document to save
-
store
public void store(Document doc, String username)
Saves / updates a document into the database- Parameters:
doc
- the document to saveusername
- the user in whose name the method is run
-
initialize
public void initialize(Document doc)
Initializes lazy loaded collections- Parameters:
doc
- the document to initialize
-
move
public void move(Document doc, String targetPath, String username) throws Exception
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- Throws:
Exception
- a generic error happened
-
copy
public Document copy(Document doc, String targetPath, String username) throws Exception
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
- Throws:
Exception
- a generic error happened
-
lock
public void lock(long docId, String username) throws Exception
Locks a document- Parameters:
docId
- identifier of the documentusername
- the user that locks the document- Throws:
Exception
- a generic error happened
-
unlock
public void unlock(long docId, String username) throws Exception
Unlocks a document- Parameters:
docId
- identifier of the documentusername
- the user that locks the document- Throws:
Exception
- a generic error happened
-
delete
public void delete(long docId, String username) throws Exception
Delete a document- Parameters:
docId
- identifier of the documentusername
- the user in whose name the method is run- Throws:
Exception
- a generic error happened
-
copyResource
public Document copyResource(Document doc, String fileVersion, String suffix, String newFileName, String username) throws Exception
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
- Throws:
Exception
- a generic error happened
-
writeToFile
public void writeToFile(long docId, String fileVersion, String suffix, String outputFile) throws Exception
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- Throws:
Exception
- error writing the file
-
convert
public Document convert(Document doc, String format, String username) throws Exception
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
- Throws:
Exception
- generic error happened
-
merge
public Document merge(Collection<Document> documents, long targetFolderId, String fileName, String username) throws Exception
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
- Throws:
Exception
- generic error happened
-
findById
public Document findById(long docId)
Retrieves a document by it's identifier- Parameters:
docId
- identifier of the document- Returns:
- the document object
-
findByPath
public Document findByPath(String path)
Retrieves a document by it's path- Parameters:
path
- full path of the document- Returns:
- the document object
-
findByPath
public Document findByPath(String path, Long tenantId)
Retrieves a document by it's path- Parameters:
path
- full path of the documenttenantId
- identifier of the tenant(optional)- Returns:
- the document object
-
getPath
public String getPath(Document doc)
Calculates the full path of a document- Parameters:
doc
- the document to inspect- Returns:
- the full path
-
getIds
public List<Long> getIds(Collection<Document> docs)
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
public Folder createPath(Document doc, String targetPath, String username)
Creates a path, all existing nodes in the specified path will be reused- Parameters:
doc
- document used to take the root folder in case thetargetPath
represents 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
public List<DocumentHistory> getHistories(long docId, String event)
Retrieve the list of events of a document- Parameters:
docId
- identifier of the documentevent
- event name, optional- Returns:
- list of histories
-
addNote
public void addNote(Document doc, String text, String username)
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
public List<DocumentNote> getNotes(long docId, String fileVersion)
Lists the notes of a given document- Parameters:
docId
- identifier of the documentfileVersion
- version of the file, optional- Returns:
- the list of notes
-
calculateNextVersion
public String calculateNextVersion(String currentVersion, boolean major)
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
-
-