Class FileService


  • public class FileService
    extends Object
    • Field Detail

      • MODE_OVERWRITE

        public static final Integer MODE_OVERWRITE
      • MODE_RENAME

        public static final Integer MODE_RENAME
      • MODE_NO_OVERWRITE

        public static final Integer MODE_NO_OVERWRITE
      • policy

        protected org.pentaho.platform.api.engine.IAuthorizationPolicy policy
      • defaultUnifiedRepositoryWebService

        protected org.pentaho.platform.repository2.unified.webservices.DefaultUnifiedRepositoryWebService defaultUnifiedRepositoryWebService
      • repository

        protected org.pentaho.platform.api.repository2.unified.IUnifiedRepository repository
      • whitelist

        protected org.pentaho.platform.repository.RepositoryDownloadWhitelist whitelist
    • Constructor Detail

      • FileService

        public FileService()
    • Method Detail

      • doDeleteFiles

        public void doDeleteFiles​(String params)
                           throws Exception
        Moves the list of files to the user's trash folder

        Move a list of files to the user's trash folder, the list should be comma separated.

        Parameters:
        params - Comma separated list of the files to be deleted
        Throws:
        Exception - containing the string, "SystemResource.GENERAL_ERROR"
      • doDeleteFilesPermanent

        public void doDeleteFilesPermanent​(String params)
                                    throws Exception
        Permanently deletes the selected list of files from the repository

        Permanently deletes a comma separated list of files without sending them to the trash folder

        Parameters:
        params - Comma separated list of the files to be deleted
        Throws:
        Exception
      • doDeleteLocale

        public void doDeleteLocale​(String pathId,
                                   String locale)
                            throws Exception
        Delete the locale for the selected file and locale
        Parameters:
        pathId - Colon separated path for the repository file
        locale - The locale to be deleted
        Throws:
        Exception - containing the string, "SystemResource.GENERAL_ERROR"
      • createFile

        public void createFile​(String charsetName,
                               String pathId,
                               InputStream fileContents)
                        throws Exception
        Creates a new file with the provided contents at a given path
        Parameters:
        pathId - (colon separated path for the repository file)
        fileContents - (content of the file)
        Throws:
        IOException
        Exception
      • doMoveFiles

        public void doMoveFiles​(String destPathId,
                                String params)
                         throws FileNotFoundException
        Moves a list of files from its current location to another.

        Moves a list of files from its current location to another, the list should be comma separated.

        Parameters:
        destPathId - colon separated path for the repository file
            :path:to:file:id
         
        params - comma separated list of files to be moved
            path1,path2,...
         
        Throws:
        FileNotFoundException
      • doRestoreFiles

        public void doRestoreFiles​(String params)
                            throws InternalError
        Restores a list of files from the user's trash folder

        Restores a list of files from the user's trash folder to their previous locations. The list should be comma separated.

        Parameters:
        params - Comma separated list of files to be restored
        Throws:
        Exception - containing the string, "SystemResource.GENERAL_ERROR"
        InternalError
      • doRestoreFilesInHomeDir

        public boolean doRestoreFilesInHomeDir​(String params,
                                               int overwriteMode)
        Restores a list of files from the trash folder to user's home folder, ignoring files previous locations (with no change of file owner)
        Parameters:
        params - Comma separated list of files to be restored
        overwriteMode - Default is RENAME (2) which adds a number to the end of the file name. MODE_OVERWRITE (1) will just replace existing or MODE_NO_OVERWRITE (3) will not copy if file exist.
      • getFolderFileIdsThatConflictWithSource

        public String getFolderFileIdsThatConflictWithSource​(String pathToFolder,
                                                             String params)
      • getSourceFileIdsThatNotConflictWithFolderFiles

        protected String getSourceFileIdsThatNotConflictWithFolderFiles​(String pathToFolder,
                                                                        String params)
        Conflict occurs if one of source files has the same name with any of folder files.
        Parameters:
        params - String with file ids, separated by comma
        pathToFolder - path to folder
        Returns:
        String with file ids of not conflict files, separated by comma
      • getCommaSeparatedFileIds

        protected String getCommaSeparatedFileIds​(List<String> fileIdsList)
        Parameters:
        fileIdsList - List with file ids.
        Returns:
        - String of file ids, separated by comma - Empty String if fileIdList is null or empty
      • doGetLocaleProperties

        public List<org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto> doGetLocaleProperties​(String pathId,
                                                                                                                            String locale)
        Retrieve the list of locale properties for a given locale
        Parameters:
        pathId - (colon separated path for the repository file)
        locale -
        Returns:
      • doSetLocaleProperties

        public void doSetLocaleProperties​(String pathId,
                                          String locale,
                                          List<org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto> properties)
                                   throws Exception
        Set the list of locale properties for a given locale
        Parameters:
        pathId -
        locale -
        properties -
        Throws:
        Exception
      • doCopyFiles

        public void doCopyFiles​(String pathId,
                                Integer mode,
                                String params)
        Copy files to a new location
        Parameters:
        pathId -
        mode -
        params -
      • setFileAcls

        public void setFileAcls​(String pathId,
                                org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto acl)
                         throws FileNotFoundException
        Save the acls of the selected file to the repository This method is used to update and save the acls of the selected file to the repository
        Parameters:
        pathId -
        pathId - colon separated path for the repository file
                       :path:to:file:id
                       
        acl - Acl of the repository file RepositoryFileAclDto
        Throws:
        FileNotFoundException
      • doGetIsVisible

        public String doGetIsVisible​(String pathId)
        Check whether the selected repository folder is visible to the current user
        Parameters:
        pathId -
        Returns:
        true or false
      • isFolder

        public boolean isFolder​(String pathId)
        Check whether the selected repository object is a folder or not
        Parameters:
        pathId -
        Returns:
        true or false
      • doesExist

        public boolean doesExist​(String pathId)
        Check whether the selected repository file exist or not
        Parameters:
        pathId -
        Returns:
        true or false
      • doGetDefaultLocation

        public String doGetDefaultLocation​(String pathId)
        Parameters:
        pathId -
        Returns:
        default path to where user can save or open the artifact
      • doGetCanAccess

        public String doGetCanAccess​(String pathId,
                                     String permissions)
        Check whether the current user has specific permission on the selected repository file
        Parameters:
        pathId -
        permissions -
        Returns:
      • doGetReservedChars

        public StringBuffer doGetReservedChars()
      • doGetReservedCharactersDisplay

        public StringBuffer doGetReservedCharactersDisplay()
      • doGetRootProperties

        public org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto doGetRootProperties()
        Retrieves the properties of the root directory
        Returns:
        file properties object RepositoryFileDto for the root directory
      • doGetProperties

        public org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto doGetProperties​(String pathId)
                                                                                                   throws FileNotFoundException
        Retrieves the properties of a selected repository file
        Parameters:
        pathId -
        pathId - colon separated path for the repository file
                       :path:to:file:id
                       
        Returns:
        file properties object RepositoryFileDto
        Throws:
        FileNotFoundException
      • doGetCanCreate

        public String doGetCanCreate()
        Gets the permission for whether or not a user can create files
        Returns:
        Boolean representing whether or not user can create files
      • doGetContentCreator

        public org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto doGetContentCreator​(String pathId)
                                                                                                       throws FileNotFoundException
        Gets the content creator of the specified file
        Parameters:
        pathId -
        Returns:
        Throws:
        FileNotFoundException
      • doGetDeletedFiles

        public List<org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto> doGetDeletedFiles()
        Get deleted files
        Returns:
      • doGetMetadata

        public List<org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto> doGetMetadata​(String pathId)
                                                                                                             throws FileNotFoundException
        Get metadata for a file by path id
        Parameters:
        pathId -
        Returns:
        Throws:
        FileNotFoundException
      • toFileDto

        protected org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto toFileDto​(org.pentaho.platform.api.repository2.unified.RepositoryFile repositoryFile,
                                                                                                       Set<String> memberSet,
                                                                                                       boolean exclude)
      • toFile

        public org.pentaho.platform.api.repository2.unified.RepositoryFile toFile​(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto repositoryFileDto)
      • getWhitelist

        public org.pentaho.platform.repository.RepositoryDownloadWhitelist getWhitelist()
      • isPathValid

        public boolean isPathValid​(String path)
      • isPath

        public boolean isPath​(String pathId)
      • canRestoreToFolderWithNoConflicts

        public boolean canRestoreToFolderWithNoConflicts​(String pathToFolder,
                                                         String params)
        Parameters:
        params - id of files, separated by ','
        Returns:
        false if homeFolder has files with names and extension equal to passed files true otherwise
        Throws:
        IllegalArgumentException - if params is null
      • getPolicy

        public org.pentaho.platform.api.engine.IAuthorizationPolicy getPolicy()
      • doSetContentCreator

        public void doSetContentCreator​(String pathId,
                                        org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto contentCreator)
                                 throws FileNotFoundException
        Store content creator of the selected repository file
        Parameters:
        pathId - colon separated path for the repository file
            :path:to:file:id
         
        contentCreator - repository file
           
             <repositoryFileDto>
             <createdDate>1402911997019</createdDate>
             <fileSize>3461</fileSize>
             <folder>false</folder>
             <hidden>false</hidden>
             <id>ff11ac89-7eda-4c03-aab1-e27f9048fd38</id>
             <lastModifiedDate>1406647160536</lastModifiedDate>
             <locale>en</locale>
             <localePropertiesMapEntries>
               <localeMapDto>
                 <locale>default</locale>
                 <properties>
                   <stringKeyStringValueDto>
                     <key>file.title</key>
                     <value>myFile</value>
                   </stringKeyStringValueDto>
                   <stringKeyStringValueDto>
                     <key>jcr:primaryType</key>
                     <value>nt:unstructured</value>
                   </stringKeyStringValueDto>
                   <stringKeyStringValueDto>
                     <key>title</key>
                     <value>myFile</value>
                   </stringKeyStringValueDto>
                   <stringKeyStringValueDto>
                     <key>file.description</key>
                     <value>myFile Description</value>
                   </stringKeyStringValueDto>
                 </properties>
               </localeMapDto>
             </localePropertiesMapEntries>
             <locked>false</locked>
             <name>myFile.prpt</name></name>
             <originalParentFolderPath>/public/admin</originalParentFolderPath>
             <ownerType>-1</ownerType>
             <path>/public/admin/ff11ac89-7eda-4c03-aab1-e27f9048fd38</path>
             <title>myFile</title>
             <versionId>1.9</versionId>
             <versioned>true</versioned>
           </repositoryFileAclDto>
         
        Throws:
        FileNotFoundException
      • doGetFileLocales

        public List<org.pentaho.platform.api.repository2.unified.webservices.LocaleMapDto> doGetFileLocales​(String pathId)
                                                                                                     throws FileNotFoundException
        Retrieves the list of locale map for the selected repository file. The list will be empty if a problem occurs.
        Parameters:
        pathId - colon separated path for the repository file
            :path:to:file:id
         
        Returns:
        List the list of locales
                   
                   <localePropertiesMapEntries>
                     <localeMapDto>
                       <locale>default</locale>
                       <properties>
                         <stringKeyStringValueDto>
                           <key>file.title</key>
                           <value>myFile</value>
                         </stringKeyStringValueDto>
                         <stringKeyStringValueDto>
                           <key>jcr:primaryType</key>
                           <value>nt:unstructured</value>
                         </stringKeyStringValueDto>
                         <stringKeyStringValueDto>
                           <key>title</key>
                           <value>myFile</value>
                         </stringKeyStringValueDto>
                         <stringKeyStringValueDto>
                           <key>file.description</key>
                           <value>myFile Description</value>
                         </stringKeyStringValueDto>
                       </properties>
                     </localeMapDto>
                   </localePropertiesMapEntries>
                 
        Throws:
        FileNotFoundException
      • doCanAdminister

        public boolean doCanAdminister()
        Checks whether the current user can administer the platform. The conditions are RepositoryReadAction, RepositoryCreateAction and AdministerSecurityAction
        Returns:
        boolean
      • doGetFileAcl

        public org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto doGetFileAcl​(String pathId)
        Retrieves the acls of the selected repository file
        Parameters:
        pathId - (colon separated path for the repository file)
        Returns:
        RepositoryFileAclDto
      • addAdminRole

        protected void addAdminRole​(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto fileAcl)
      • doGetTree

        public org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto doGetTree​(String pathId,
                                                                                                        Integer depth,
                                                                                                        String filter,
                                                                                                        Boolean showHidden,
                                                                                                        Boolean includeAcls)
      • doGetTree

        public org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto doGetTree​(String pathId,
                                                                                                        Integer depth,
                                                                                                        String filter,
                                                                                                        Boolean showHidden,
                                                                                                        Boolean includeAcls,
                                                                                                        Boolean includeSystemFolders)
      • sortByLocaleTitle

        public void sortByLocaleTitle​(Collator collator,
                                      org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileTreeDto tree)
      • doGetGeneratedContent

        public List<org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto> doGetGeneratedContent​(String pathId)
                                                                                                               throws FileNotFoundException
        Retrieve the executed contents for a selected repository file
        Parameters:
        pathId - the path for the file
        Returns:
        list of repositoryFileDto
        Throws:
        FileNotFoundException - if the file is not found
      • doGetGeneratedContent

        public List<org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto> doGetGeneratedContent​(String pathId,
                                                                                                                      String user)
                                                                                                               throws FileNotFoundException
        Retrieve the executed contents for a selected repository file and a given user
        Parameters:
        pathId - the path for the file
        user - the username for the generated content folder
        Returns:
        list of repositoryFileDto
        Throws:
        FileNotFoundException
      • searchGeneratedContent

        protected List<org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto> searchGeneratedContent​(String userDir,
                                                                                                                          String targetComparator,
                                                                                                                          String metadataConstant)
                                                                                                                   throws FileNotFoundException
        Parameters:
        userDir - the user home directory
        targetComparator - the comparator to filter
        metadataConstant - the property used to get the file property to compare
        Returns:
        list of repositoryFileDto
        Throws:
        FileNotFoundException
      • getSessionResource

        protected SessionResource getSessionResource()
        Gets an instance of SessionResource
        Returns:
        SessionResource
      • doRename

        public boolean doRename​(String pathId,
                                String newName)
                         throws Exception
        Rename the name of the selected file
        Parameters:
        pathId - (colon separated path for the repository file)
        newName - (New name of the file)
        Returns:
        Throws:
        Exception
      • doCreateDir

        @Deprecated
        public boolean doCreateDir​(String pathId)
        Deprecated.
        Creates a new folder with the specified name
        Parameters:
        pathId - The path from the root folder to the root node of the tree to return using colon characters in place of / or \ characters. To clarify /path/to/file, the encoded pathId would be :path:to:file
                              :path:to:file
                            
        Returns:
        A jax-rs Response object with the appropriate status code, header, and body.
      • doCreateDirSafe

        public boolean doCreateDirSafe​(String pathId)
                                throws FileService.InvalidNameException
        Creates a new folder with pathId as name if it does not contain reserved characters. To obtain them, the method calls doGetReservedChars(). Additionally, it is checked that folder name is not '.' or '..' and does not contain '/'.
        Parameters:
        pathId - the desired path
        Returns:
        true if the folder has been created
        Throws:
        FileService.InvalidNameException - if pathId contains prohibited characters.
      • isValidFolderName

        public boolean isValidFolderName​(String path)
      • isValidFileName

        public boolean isValidFileName​(String name)

        Check if a given name can be used as a file name.

        Parameters:
        name - the name to be tested
        Returns:
        true if the given name is valid for a file and false otherwise
      • getRepoWs

        protected org.pentaho.platform.repository2.unified.webservices.DefaultUnifiedRepositoryWebService getRepoWs()
      • getRepositoryFileOutputStream

        public org.pentaho.platform.repository2.unified.fileio.RepositoryFileOutputStream getRepositoryFileOutputStream​(String path)
      • getRepositoryFileInputStream

        public org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream getRepositoryFileInputStream​(org.pentaho.platform.api.repository2.unified.RepositoryFile repositoryFile)
                                                                                                               throws FileNotFoundException
        Throws:
        FileNotFoundException
      • getStreamingOutput

        public javax.ws.rs.core.StreamingOutput getStreamingOutput​(InputStream is)
      • getStringKeyStringValueDto

        public org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto getStringKeyStringValueDto​(String key,
                                                                                                                           String value)
      • getRepository

        public org.pentaho.platform.api.repository2.unified.IUnifiedRepository getRepository()
      • getSession

        protected org.pentaho.platform.api.engine.IPentahoSession getSession()
      • escapeJava

        protected String escapeJava​(String value)
      • getDownloadExportProcessor

        protected BaseExportProcessor getDownloadExportProcessor​(String path,
                                                                 boolean requiresZip,
                                                                 boolean withManifest)
      • getDownloadExportHandler

        protected ExportHandler getDownloadExportHandler()
      • getRepositoryRequest

        protected org.pentaho.platform.api.repository2.unified.RepositoryRequest getRepositoryRequest​(String path,
                                                                                                      Boolean showHidden,
                                                                                                      Integer depth,
                                                                                                      String filter)
      • getCollatorInstance

        protected Collator getCollatorInstance()
      • doGetChildren

        public List<org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto> doGetChildren​(String pathId,
                                                                                                              String filter,
                                                                                                              Boolean showHidden,
                                                                                                              Boolean includeAcls)
      • isShowingTitle

        public boolean isShowingTitle​(org.pentaho.platform.api.repository2.unified.RepositoryRequest repositoryRequest)
      • sortByLocaleTitle

        public void sortByLocaleTitle​(Collator collator,
                                      List<org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto> repositoryFileDtoList)
      • getRepositoryRequest

        protected org.pentaho.platform.api.repository2.unified.RepositoryRequest getRepositoryRequest​(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto repositoryFileDto,
                                                                                                      Boolean showHidden,
                                                                                                      String filter,
                                                                                                      Boolean includeAcls)
      • getCollator

        protected Collator getCollator​(int strength)
      • validateDownloadAccess

        protected void validateDownloadAccess​(String importDir)
                                       throws org.pentaho.platform.api.engine.PentahoAccessControlException
        Throws:
        org.pentaho.platform.api.engine.PentahoAccessControlException