Class DocumentStorageServiceImpl

  • All Implemented Interfaces:
    DocumentStorageService

    public class DocumentStorageServiceImpl
    extends Object
    implements DocumentStorageService
    This a Sample Implementation of the DocumentStorageService saves the uploaded files on the File System on a folder (by default /docs) and return the complete path to the file that will be stored in the form field property.

    Check that the user that is running the app has write permissions on the storage folder.

    • Constructor Detail

      • DocumentStorageServiceImpl

        public DocumentStorageServiceImpl​(String storagePath)
      • DocumentStorageServiceImpl

        public DocumentStorageServiceImpl()
    • Method Detail

      • buildDocument

        public Document buildDocument​(String name,
                                      long size,
                                      Date lastModified,
                                      Map<String,​String> params)
        Description copied from interface: DocumentStorageService
        Generates a Document instance.
        Specified by:
        buildDocument in interface DocumentStorageService
        Parameters:
        name - The document name
        size - The document size
        lastModified - The lastModified date of the document
        params - A Map containing the params to create the document.
        Returns:
      • saveDocument

        public Document saveDocument​(Document document,
                                     byte[] content)
        Description copied from interface: DocumentStorageService
        Method to store the uploaded file on the system
        Specified by:
        saveDocument in interface DocumentStorageService
        Parameters:
        document - The document to store the content
        content - The document content
        Returns:
        A Document
      • deleteDocument

        public boolean deleteDocument​(String id)
        Description copied from interface: DocumentStorageService
        Deletes the File identified by the given id
        Specified by:
        deleteDocument in interface DocumentStorageService
        Parameters:
        id - The Document id to delete
        Returns:
        true if it was possible to remove, false if not
      • deleteDocument

        public boolean deleteDocument​(Document doc)
        Description copied from interface: DocumentStorageService
        Deletes the File identified by the given id
        Specified by:
        deleteDocument in interface DocumentStorageService
        Parameters:
        doc - The Document to delete
        Returns:
        true if it was possible to remove, false if not
      • getDocumentContent

        public File getDocumentContent​(Document doc)
      • deleteFile

        protected boolean deleteFile​(File file)
      • generateUniquePath

        protected String generateUniquePath()
        Generates a random path to store the file to avoid overwritting files with the same name
        Returns:
        A String containging the path where the document is going to be stored.
      • getFileByPath

        protected File getFileByPath​(String path)