Package com.logicaldoc.core.document

# Class DocumentManager

java.lang.Object
com.logicaldoc.core.document.DocumentManager

@Component("documentManager") public class DocumentManager extends Object
Basic Implementation of `DocumentManager`

Since:
  3.5
Author:
  Marco Meschieri - LogicalDOC

## Constructor Summary

Constructors
Constructor
Description
`DocumentManager()`

## Method Summary

Modifier and Type
Method
Description
`void`
`archiveDocuments(Set<Long> docIds, DocumentHistory transaction)`
Archives all the documents in a folder's tree
`long`
`archiveFolder(long folderId, DocumentHistory transaction)`
Archives all the documents in a folder's tree
`void`
`changeIndexingStatus(Document doc, IndexingStatus status)`
Utility method used to declare that: the document must be taken into consideration by the indexer (status = `IndexingStatus.TO_INDEX` . the document must be taken into consideration by the indexer for the metadata only(status = `IndexingStatus.TO_INDEX_METADATA`. the document must not be taken into consideration by the indexer (status = `IndexingStatus.SKIP`).
`DocumentFuture`
`checkin(long docId, File file, String filename, boolean release, Document docVO, DocumentHistory transaction)`
Checks in the given document
`DocumentFuture`
`checkin(long docId, InputStream content, String filename, boolean release, Document docVO, DocumentHistory transaction)`
Checks in the given document
`void`
`checkout(long docId, DocumentHistory transaction)`
Checks out the given document
`void`
`checkout(Document document, DocumentHistory transaction)`
Checks out the given document
`DocumentFuture`
`copyToFolder(Document doc, Folder folder, DocumentHistory transaction, boolean links, boolean notes, boolean security)`
Copy a document to the specified folder.
`int`
`countPages(Document doc)`
Counts the number of pages of a document
`DocumentFuture`
`create(File file, Document docVO, DocumentHistory transaction)`
Creates a new Document.
`DocumentFuture`
`create(InputStream content, Document docVO, DocumentHistory transaction)`
Creates a new Document.
`Document`
`createAlias(Document doc, Folder folder, String aliasType, DocumentHistory transaction)`
Create an alias(shortcut) associated to the given doc to the specified folder.
`Ticket`
`createTicket(Ticket ticket, DocumentHistory transaction)`
Creates a new ticket.
`void`
`deleteFromIndex(Document doc)`
Utility method for document removal from index and database update(flag indexed)
`Version`
`deleteVersion(long versionId, DocumentHistory transaction)`
Deletes a specific version.
`void`
`destroyDocument(long docId, FolderHistory transaction)`
Permanently deletes a document from the system, the document and all the dependent resources will not be recoverable in the future.
`int`
`enforceFilesIntoFolderStore(long rootFolderId, DocumentHistory transaction)`
Moves all the files of the documents in the given tree from it's original location to the store defined in the owning folder
`static DocumentManager`
`get()`
Gets the object available in the application context
`long`
`index(long docId, String content, DocumentHistory transaction)`
Re-indexes an existing document in the full-text index.
`void`
`lock(long docId, DocumentStatus status, DocumentHistory transaction)`
Locks the given document
`void`
`lock(Document document, DocumentStatus status, DocumentHistory transaction)`
Locks the given document, it is synchronized because under high-ferquency, Hibernate may fail
`void`
`makeImmutable(long docId, DocumentHistory transaction)`
Marks the document, with the given docId, as immutable and save the given document history
`DocumentFuture`
`merge(Collection<Document> documents, long targetFolderId, String fileName, DocumentHistory transaction)`
Merges a set of documents into a single PDF file
`DocumentFuture`
`moveToFolder(Document doc, Folder folder, DocumentHistory transaction)`
Moves a document to the specified folder.
`String`
`parseDocument(Document doc, String fileVersion)`
Retrieves the document's content as a string
`void`
`promoteVersion(long docId, String version, DocumentHistory transaction)`
Promotes an old version to the current default one.
`DocumentFuture`
`rename(long docId, String newName, DocumentHistory transaction)`
Rename an existing document filename.
`DocumentFuture`
`replaceAlias(long aliasId, DocumentHistory transaction)`
Replaces an alias with a copy of the original file
`DocumentFuture`
`replaceFile(long docId, String fileVersion, File newFile, DocumentHistory transaction)`
Replaces the file of a given version
`DocumentFuture`
`replaceFile(long docId, String fileVersion, InputStream content, DocumentHistory transaction)`
Replaces the file of a given version
`void`
`unlock(long docId, DocumentHistory transaction)`
Unchecks out the given document
`boolean`
`unprotect(String sid, long docId, String password)`
Tries to unprotect a document, If the password is correct, the document stays unprotected for all the duration of the session.
`void`
`update(Document document, Document docVO, DocumentHistory transaction)`
Updates an existing document and marks it to be re-indexed

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### DocumentManager

public DocumentManager()

## Method Details

### get

public static DocumentManager get()
Gets the object available in the application context

Returns:
  the instance of this object in the application context

### replaceFile

public DocumentFuture replaceFile(long docId, String fileVersion, InputStream content, DocumentHistory transaction) throws IOException, PersistenceException
Replaces the file of a given version

Parameters:
  `docId` - the document to be updated
  `fileVersion` - the file version
  `content` - the new content
  `transaction` - entry to log the event (set the user)
Returns:
  A future to check the completion of all the checkin operations
Throws:
  `PersistenceException` - error at data layer
  `IOException` - I/O error

### replaceFile

public DocumentFuture replaceFile(long docId, String fileVersion, File newFile, DocumentHistory transaction) throws PersistenceException, IOException
Replaces the file of a given version

Parameters:
  `docId` - the document to be updated
  `fileVersion` - the file version
  `newFile` - the file to use
  `transaction` - entry to log the event (set the user)
Returns:
  A future to check the completion of all the checkin operations
Throws:
  `PersistenceException` - error at data layer
  `IOException` - I/O error

### checkin

public DocumentFuture checkin(long docId, InputStream content, String filename, boolean release, Document docVO, DocumentHistory transaction) throws IOException, PersistenceException
Checks in the given document

Parameters:
  `docId` - the document to be checked in
  `content` - input stream pointing to the new document version
  `filename` - new filename (can also be the old one)
  `release` - True if this is a new release(eg: 2.0) rather than a subversion(eg: 1.1)
  `docVO` - The value object containing document's metadata applied during the checkin (optional)
  `transaction` - entry to log the event, set the user and comment
Returns:
  A future to check the completion of all the checkin operations
Throws:
  `IOException` - I/O error
  `PersistenceException` - error at data layer

### checkin

public DocumentFuture checkin(long docId, File file, String filename, boolean release, Document docVO, DocumentHistory transaction) throws PersistenceException
Checks in the given document

Parameters:
  `docId` - the document to be checked in
  `file` - of the new document version
  `filename` - new filename (can also be the old one)
  `release` - True if this is a new release(eg: 2.0) rather than a subversion(eg: 1.1)
  `docVO` - The value object containing document's metadata applied during the checkin (optional)
  `transaction` - entry to log the event, set the user and comment
Returns:
  A future to check the completion of all the checkin operations
Throws:
  `PersistenceException` - error at data layer

### checkout

public void checkout(long docId, DocumentHistory transaction) throws PersistenceException
Checks out the given document

Parameters:
  `docId` - the document to be checked out
  `transaction` - entry to log the event (set the user)
Throws:
  `PersistenceException` - error at data layer

### checkout

public void checkout(Document document, DocumentHistory transaction) throws PersistenceException
Checks out the given document

Parameters:
  `document` - the document to be checked out
  `transaction` - entry to log the event (set the user)
Throws:
  `PersistenceException` - error at data layer

### lock

public void lock(long docId, DocumentStatus status, DocumentHistory transaction) throws PersistenceException
Locks the given document

Parameters:
  `docId` - the document to be locked
  `status` - the lock type (used to populate status attribute of the document)
  `transaction` - entry to log the event (set the user)
Throws:
  `PersistenceException` - if an error occurs, this exception is thrown

### lock

public void lock(Document document, DocumentStatus status, DocumentHistory transaction) throws PersistenceException
Locks the given document, it is synchronized because under high-ferquency, Hibernate may fail

Parameters:
  `document` - the document to be locked
  `status` - the lock type (used to populate status attribute of the document)
  `transaction` - entry to log the event (set the user)
Throws:
  `PersistenceException` - if an error occurs, this exception is thrown

### deleteFromIndex

public void deleteFromIndex(Document doc)
Utility method for document removal from index and database update(flag indexed)

Parameters:
  `doc` - the document to remove from the index

### parseDocument

public String parseDocument(Document doc, String fileVersion) throws ParsingException
Retrieves the document's content as a string

Parameters:
  `doc` - the document representation
  `fileVersion` - version of the file
Returns:
  The document's content
Throws:
  `ParsingException` - error in the parsing

### index

public long index(long docId, String content, DocumentHistory transaction) throws PersistenceException, ParsingException
Re-indexes an existing document in the full-text index.

Parameters:
  `docId` - The document to be indexed
  `content` - The content to use as document's body (can be null to parse the file)
  `transaction` - entry to log the event (set the user)
Returns:
  the number of milliseconds required to parse the document
Throws:
  `PersistenceException` - error at data layer
  `ParsingException` - error during parsing

### update

public void update(Document document, Document docVO, DocumentHistory transaction) throws PersistenceException
Updates an existing document and marks it to be re-indexed

Parameters:
  `document` - The document to be updated
  `docVO` - value object containing the new metadata
  `transaction` - entry to log the event (set the user)
Throws:
  `PersistenceException` - if an error occurs, this exception is thrown

### moveToFolder

public DocumentFuture moveToFolder(Document doc, Folder folder, DocumentHistory transaction) throws PersistenceException
Moves a document to the specified folder. All stores(db, file system, index) will be consequently altered.

Parameters:
  `doc` - The document to move
  `folder` - The target folder
  `transaction` - entry to log the event (set the user)
Returns:
  A future to check the completion of the move
Throws:
  `PersistenceException` - raised if the document cannot be moved

### create

public DocumentFuture create(InputStream content, Document docVO, DocumentHistory transaction) throws PersistenceException
Creates a new Document. Saves the information provided. That also includes updating the search index for example.

Parameters:
  `content` - The document's content
  `docVO` - The value object containing the document's metadata
  `transaction` - The transaction metadata (remember to set the user and the comment)
Returns:
  A `Pair` where the key is the newly created document and the value is a future to track the completion of the creation tasks.
Throws:
  `PersistenceException` - raised if the document cannot be created

### create

public DocumentFuture create(File file, Document docVO, DocumentHistory transaction) throws PersistenceException
Creates a new Document. Saves the information provided. That also includes updating the search index for example.

Parameters:
  `file` - The document's file
  `docVO` - The value object containing the document's metadata
  `transaction` - The transaction metadata (remember to set the user and the comment)
Returns:
  A `Pair` where the key is the newly created document and the value is a future to track the completion of the creation tasks.
Throws:
  `PersistenceException` - raised if the document cannot be created

### countPages

public int countPages(Document doc)
Counts the number of pages of a document

Parameters:
  `doc` - the document
Returns:
  the number of pages

### copyToFolder

public DocumentFuture copyToFolder(Document doc, Folder folder, DocumentHistory transaction, boolean links, boolean notes, boolean security) throws PersistenceException, IOException
Copy a document to the specified folder.

Parameters:
  `doc` - The document to move
  `folder` - The target folder
  `transaction` - entry to log the event (set the user)
  `links` - if links must be copied too
  `notes` - if notes and annotations must be copied too
  `notes` - if security settings must be copied too
Returns:
  A `Pair` where the key is the newly created document and the value is a future to track the completion of the copy tasks.
Throws:
  `PersistenceException` - error at data layer
  `IOException` - I/O error

### unlock

public void unlock(long docId, DocumentHistory transaction) throws PersistenceException
Unchecks out the given document

Parameters:
  `docId` - the document to be unchecked out
  `transaction` - entry to log the event
Throws:
  `PersistenceException` - if an error occurs, this exception is thrown

### makeImmutable

public void makeImmutable(long docId, DocumentHistory transaction) throws PersistenceException
Marks the document, with the given docId, as immutable and save the given document history

Parameters:
  `docId` - identifier of the document
  `transaction` - entry to log the event (set the user)
Throws:
  `PersistenceException` - raised if the document cannot be marked immutable

### rename

public DocumentFuture rename(long docId, String newName, DocumentHistory transaction) throws PersistenceException
Rename an existing document filename.

Parameters:
  `docId` - The document to be renamed
  `newName` - The new filename of the document
  `transaction` - entry to log the event (set the user)
Returns:
  A future to track the completion of the rename
Throws:
  `PersistenceException` - if an error occurs, this exception is thrown

### replaceAlias

public DocumentFuture replaceAlias(long aliasId, DocumentHistory transaction) throws PersistenceException
Replaces an alias with a copy of the original file

Parameters:
  `aliasId` - ID of the alias to replace
  `transaction` - entry to log the event (set the user)
Returns:
  A `Pair` where the key is the newly created document and the value is a future to track the completion of the replace tasks.
Throws:
  `PersistenceException` - raised if the alias cannot be replaced

### createAlias

public Document createAlias(Document doc, Folder folder, String aliasType, DocumentHistory transaction) throws PersistenceException
Create an alias(shortcut) associated to the given doc to the specified folder.

Parameters:
  `doc` - The document for which will be created the shortcut
  `folder` - The target folder
  `aliasType` - the alias type(null for the original file or pdf for it's pdf conversion)
  `transaction` - entry to log the event (set the user)
Returns:
  The created document
Throws:
  `PersistenceException` - error at data layer

### changeIndexingStatus

public void changeIndexingStatus(Document doc, IndexingStatus status)
Utility method used to declare that:

1. the document must be taken into consideration by the indexer (status = `IndexingStatus.TO_INDEX` .
2. the document must be taken into consideration by the indexer for the metadata only(status = `IndexingStatus.TO_INDEX_METADATA`.
3. the document must not be taken into consideration by the indexer (status = `IndexingStatus.SKIP`). If the document was previously indexed it is removed from the index.

Status:

1. `IndexingStatus.TO_INDEX`
2. `IndexingStatus.TO_INDEX_METADATA`
3. `IndexingStatus.SKIP`

Parameters:
  `doc` - The document for which will be changed the indexer status.
  `status` - The new document indexer status.

### deleteVersion

public Version deleteVersion(long versionId, DocumentHistory transaction) throws PersistenceException
Deletes a specific version.

Parameters:
  `versionId` - The version to delete
  `transaction` - entry to log the event (set the user)
Returns:
  the latest version
Throws:
  `PersistenceException` - If the version cannot be deleted

### archiveFolder

public long archiveFolder(long folderId, DocumentHistory transaction) throws PersistenceException
Archives all the documents in a folder's tree

Parameters:
  `folderId` - The root folder
  `transaction` - entry to log the event (set the user)
Returns:
  Total number of archived documents
Throws:
  `PersistenceException` - raised if at least a document cannot be archived

### archiveDocuments

public void archiveDocuments(Set<Long> docIds, DocumentHistory transaction) throws PersistenceException
Archives all the documents in a folder's tree

Parameters:
  `docIds` - Documents to be archived
  `transaction` - entry to log the event (set the user)
Throws:
  `PersistenceException` - raised if at least a document cannot be archived

### createTicket

public Ticket createTicket(Ticket ticket, DocumentHistory transaction) throws PersistenceException, PermissionException
Creates a new ticket.

Parameters:
  `ticket` - Value object carrying the metadata for the ticket to create
  `transaction` - entry to log the event (set the user)
Returns:
  The created ticket with the url property filled
Throws:
  `PersistenceException` - raised if the download ticket cannot be created
  `PermissionException` - raised if the user does not have the download permission

### unprotect

public boolean unprotect(String sid, long docId, String password)
Tries to unprotect a document, If the password is correct, the document stays unprotected for all the duration of the session.

Parameters:
  `sid` - Session identifier
  `docId` - The document id
  `password` - The password to try
Returns:
  True if the file gets unprotected

### promoteVersion

public void promoteVersion(long docId, String version, DocumentHistory transaction) throws PersistenceException, IOException
Promotes an old version to the current default one. If you promote a prior version, what it does is make it the default version again. (regardless of there being many versions).

Parameters:
  `docId` - the document to be updated
  `version` - the version
  `transaction` - entry to log the event (set the user)
Throws:
  `PersistenceException` - error at data layer
  `IOException` - I/O error

### enforceFilesIntoFolderStore

public int enforceFilesIntoFolderStore(long rootFolderId, DocumentHistory transaction) throws PersistenceException, IOException
Moves all the files of the documents in the given tree from it's original location to the store defined in the owning folder

Parameters:
  `rootFolderId` - identifier of the root of the tree to process
  `transaction` - informations about the transaction, optional
Returns:
  number of moved files
Throws:
  `PersistenceException` - error at data layer
  `IOException` - I/O error

### merge

public DocumentFuture merge(Collection<Document> documents, long targetFolderId, String fileName, DocumentHistory transaction) throws IOException, PersistenceException
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)
  `transaction` - informations about the transaction, optional
Returns:
  A `Pair` where the key is the generated merged document and the value is a future to track the completion of the merge tasks.
Throws:
  `IOException` - I/O error
  `PersistenceException` - error at data layer

### destroyDocument

public void destroyDocument(long docId, FolderHistory transaction) throws PersistenceException, PermissionException
Permanently deletes a document from the system, the document and all the dependent resources will not be recoverable in the future.

Parameters:
  `docId` - the document to destroy
  `transaction` - the current session
Throws:
  `PersistenceException` - error at data layer
  `PermissionException` - The user cannot destroy the document