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 Deprecated Methods Modifier and Type Method Description voidaddNote(Document doc, String text, String username)Creates a new note for the whole documentStringcalculateNextVersion(String currentVersion, boolean major)Calculates what will be the next version specification.Documentconvert(Document doc, String format, String username)Convert a document in another format and saves the result in another file in the same foldervoidcopy(Document doc, String targetPath, String username)Copies a document into a target folderDocumentcopyResource(Document doc, String fileVersion, String suffix, String newFileName, String username)Copies a resource in a file in the same folder of the original documentFoldercreatePath(Document doc, String targetPath, String username)Creates a path, all existing nodes in the specified path will be reusedvoiddelete(long docId, String username)Delete a documentStringdisplayFileSize(Long size)Prints the size of a file in human readable formStringdisplayUrl(long tenantId, long docId)Builds the display url of a document(display permalink)StringdisplayUrl(Document doc)Builds the display url of a document(display permalink)StringdisplayUrl(DocumentHistory history)Builds the display url of a document(display permalink)StringdownloadTicket(long docId, boolean pdfConversion, Integer expireHours, Date expireDate, Integer maxDownloads, String username)Creates a new download ticket for a documentStringdownloadUrl(long docId)Builds the download url of a document(download permalink)StringdownloadUrl(Document doc)Builds the download url of a document(download permalink)StringdownloadUrl(DocumentHistory history)Builds the download url of a document(download permalink)DocumentfindById(long docId)Retrieves a document by it's identifierDocumentfindByPath(String path)Retrieves a document by it's pathDocumentfindByPath(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 documentStringgetPath(Document doc)Calculates the full path of a documentUsergetUser(String username)Deprecated.voidlock(long docId, String username)Locks a documentvoidmove(Document doc, String targetPath, String username)Moves a document into a target foldervoidstore(Document doc)Saves / updates a document into the databasevoidstore(Document doc, String username)Saves / updates a document into the databasevoidunlock(long docId, String username)Unlocks a documentvoidwriteToFile(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
-
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 void 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- Throws:
Exception- a generic error happened
-
lock
public void lock(long docId, String username) throws ExceptionLocks 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 ExceptionUnlocks 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 ExceptionDelete 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 ExceptionWrites 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
-
getUser
@Deprecated public User getUser(String username)
Deprecated.Retrieves a user object- Parameters:
username- the username- Returns:
- the user object
-
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 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
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
-
-