org.pentaho.platform.repository2.unified
Class DefaultUnifiedRepository

java.lang.Object
  extended by org.pentaho.platform.repository2.unified.DefaultUnifiedRepository
All Implemented Interfaces:
IUnifiedRepository

public class DefaultUnifiedRepository
extends Object
implements IUnifiedRepository

Default implementation of IUnifiedRepository. Delegates to IRepositoryFileDao and IRepositoryFileAclDao.

Author:
mlowery

Constructor Summary
DefaultUnifiedRepository(IRepositoryFileDao contentDao, IRepositoryFileAclDao aclDao)
           
 
Method Summary
 boolean canUnlockFile(Serializable fileId)
          Returns true if the current user can unlock the file.
 RepositoryFile createFile(Serializable parentFolderId, RepositoryFile file, IRepositoryFileData data, RepositoryFileAcl acl, String versionMessage)
          Creates a file.
 RepositoryFile createFile(Serializable parentFolderId, RepositoryFile file, IRepositoryFileData data, String versionMessage)
          Creates a file.
 RepositoryFile createFolder(Serializable parentFolderId, RepositoryFile file, RepositoryFileAcl acl, String versionMessage)
          Creates a folder.
 RepositoryFile createFolder(Serializable parentFolderId, RepositoryFile file, String versionMessage)
          Creates a folder.
 void deleteFile(Serializable fileId, boolean permanent, String versionMessage)
          Deletes a file.
 void deleteFile(Serializable fileId, String versionMessage)
          Deletes a file in a recoverable manner.
 void deleteFileAtVersion(Serializable fileId, Serializable versionId)
          Permanently deletes a specific version of a file.
 RepositoryFileAcl getAcl(Serializable fileId)
          Returns ACL for file.
 List<RepositoryFile> getChildren(Serializable folderId)
          Returns the children of this folder.
 List<RepositoryFile> getChildren(Serializable folderId, String filter)
          Returns the children of this folder that match the specified filter.
<T extends IRepositoryFileData>
T
getDataAtVersionForExecute(Serializable fileId, Serializable versionId, Class<T> dataClass)
          Gets data at given version for read.
<T extends IRepositoryFileData>
T
getDataAtVersionForRead(Serializable fileId, Serializable versionId, Class<T> dataClass)
          Gets data at given version for read.
<T extends IRepositoryFileData>
T
getDataForExecute(Serializable fileId, Class<T> dataClass)
          Gets data at base version for execute.
<T extends IRepositoryFileData>
T
getDataForRead(Serializable fileId, Class<T> dataClass)
          Gets data at base version for read.
 List<RepositoryFile> getDeletedFiles()
          Gets all deleted files for the current user.
 List<RepositoryFile> getDeletedFiles(Serializable folderId)
          Gets all deleted files for the current user in this folder.
 List<RepositoryFile> getDeletedFiles(Serializable folderId, String filter)
          Gets all deleted files for the current user in this folder.
 List<RepositoryFileAce> getEffectiveAces(Serializable fileId)
          Returns the list of access control entries (ACEs) that will be used to make an access control decision.
 List<RepositoryFileAce> getEffectiveAces(Serializable fileId, boolean forceEntriesInheriting)
          Returns the list of access control entries (ACEs) that will be used to make an access control decision.
 RepositoryFile getFile(String path)
          Gets file.
 RepositoryFile getFile(String path, boolean loadMaps)
          Same as IUnifiedRepository.getFile(String) except that if loadMaps is true, the maps for localized strings will be loaded as well.
 RepositoryFile getFileAtVersion(Serializable fileId, Serializable versionId)
          Gets file as it was at the given version.
 RepositoryFile getFileById(Serializable fileId)
          Gets file.
 RepositoryFile getFileById(Serializable fileId, boolean loadMaps)
          Same as IUnifiedRepository.getFile(String) except that if loadMaps is true, the maps for localized strings will be loaded as well.
 RepositoryFileTree getTree(String path, int depth, String filter)
          Gets a tree rooted at path.
 List<VersionSummary> getVersionSummaries(Serializable fileId)
          Returns a list of version summary instances.
 VersionSummary getVersionSummary(Serializable fileId, Serializable versionId)
          Returns a version summary for the given file id and version id.
 boolean hasAccess(String path, EnumSet<RepositoryFilePermission> permissions)
          Returns true if user has all permissions given.
 void lockFile(Serializable fileId, String message)
          Locks a file.
 void moveFile(Serializable fileId, String destAbsPath, String versionMessage)
          Moves and/or renames file.
 void restoreFileAtVersion(Serializable fileId, Serializable versionId, String versionMessage)
          Makes a file, as it was at the given version, the latest version.
 void undeleteFile(Serializable fileId, String versionMessage)
          Recovers a deleted file if it was not permanently deleted.
 void unlockFile(Serializable fileId)
          Unlocks a file.
 RepositoryFileAcl updateAcl(RepositoryFileAcl acl)
          Updates an ACL.
 RepositoryFile updateFile(RepositoryFile file, IRepositoryFileData data, String versionMessage)
          Updates a file and/or the data of a file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultUnifiedRepository

public DefaultUnifiedRepository(IRepositoryFileDao contentDao,
                                IRepositoryFileAclDao aclDao)
Method Detail

getEffectiveAces

public List<RepositoryFileAce> getEffectiveAces(Serializable fileId)
Returns the list of access control entries (ACEs) that will be used to make an access control decision.

Specified by:
getEffectiveAces in interface IUnifiedRepository
Parameters:
fileId - file id
Returns:
list of ACEs

getEffectiveAces

public List<RepositoryFileAce> getEffectiveAces(Serializable fileId,
                                                boolean forceEntriesInheriting)
Returns the list of access control entries (ACEs) that will be used to make an access control decision.

Specified by:
getEffectiveAces in interface IUnifiedRepository
Parameters:
fileId - file id
forceEntriesInheriting - true to treat ACL as if isEntriesInheriting was true; this avoids having the caller fetch the parent of ACL belonging to file with fileId; no change is persisted to the ACL
Returns:
list of ACEs

hasAccess

public boolean hasAccess(String path,
                         EnumSet<RepositoryFilePermission> permissions)
Returns true if user has all permissions given.

Specified by:
hasAccess in interface IUnifiedRepository
Parameters:
path - path to file or folder
permissions - permissions to check
Returns:
true if user has all permissions given

getFile

public RepositoryFile getFile(String path)
Gets file. Use this method to test for file existence too.

Specified by:
getFile in interface IUnifiedRepository
Parameters:
path - path to file
Returns:
file or null if the file does not exist or access is denied

getFileById

public RepositoryFile getFileById(Serializable fileId)
Gets file. Use this method to test for file existence too.

Specified by:
getFileById in interface IUnifiedRepository
Parameters:
fileId - file id
Returns:
file or null if the file does not exist or access is denied

getFile

public RepositoryFile getFile(String path,
                              boolean loadMaps)
Same as IUnifiedRepository.getFile(String) except that if loadMaps is true, the maps for localized strings will be loaded as well. (Normally these are not loaded.) Use true in editing tools that can show the maps for editing purposes.

Specified by:
getFile in interface IUnifiedRepository
Parameters:
path - path to file
loadMaps - true to load localized string maps
Returns:
file or null if the file does not exist or access is denied

getFileById

public RepositoryFile getFileById(Serializable fileId,
                                  boolean loadMaps)
Same as IUnifiedRepository.getFile(String) except that if loadMaps is true, the maps for localized strings will be loaded as well. (Normally these are not loaded.) Use true in editing tools that can show the maps for editing purposes.

Specified by:
getFileById in interface IUnifiedRepository
Parameters:
fileId - file id
loadMaps - true to load localized string maps
Returns:
file or null if the file does not exist or access is denied

createFile

public RepositoryFile createFile(Serializable parentFolderId,
                                 RepositoryFile file,
                                 IRepositoryFileData data,
                                 String versionMessage)
Creates a file.

Specified by:
createFile in interface IUnifiedRepository
Parameters:
parentFolderId - parent folder id
file - file to create
data - file data
versionMessage - optional version comment to be applied to parentFolder
Returns:
file that is equal to given file except with id populated

createFolder

public RepositoryFile createFolder(Serializable parentFolderId,
                                   RepositoryFile file,
                                   String versionMessage)
Creates a folder.

Specified by:
createFolder in interface IUnifiedRepository
Parameters:
parentFolderId - parent folder id
file - file to create
versionMessage - optional version comment to be applied to parentFolder
Returns:
file that is equal to given file except with id populated

createFile

public RepositoryFile createFile(Serializable parentFolderId,
                                 RepositoryFile file,
                                 IRepositoryFileData data,
                                 RepositoryFileAcl acl,
                                 String versionMessage)
Creates a file.

Specified by:
createFile in interface IUnifiedRepository
Parameters:
parentFolderId - parent folder id
file - file to create
data - file data
acl - file acl
versionMessage - optional version comment to be applied to parentFolder
Returns:
file that is equal to given file except with id populated

createFolder

public RepositoryFile createFolder(Serializable parentFolderId,
                                   RepositoryFile file,
                                   RepositoryFileAcl acl,
                                   String versionMessage)
Creates a folder.

Specified by:
createFolder in interface IUnifiedRepository
Parameters:
parentFolderId - parent folder id
file - file to create
acl - file acl
versionMessage - optional version comment to be applied to parentFolder
Returns:
file that is equal to given file except with id populated

getDataForExecute

public <T extends IRepositoryFileData> T getDataForExecute(Serializable fileId,
                                                           Class<T> dataClass)
Gets data at base version for execute.

Delegates to #getStreamForRead(RepositoryFile) but assumes that some external system (e.g. Spring Security) is protecting this method with different authorization rules than #getStreamForRead(RepositoryFile).

In a direct contradiction of the previous paragraph, this implementation is not currently protected by Spring Security.

Specified by:
getDataForExecute in interface IUnifiedRepository
Parameters:
fileId - file id
dataClass - class that implements IRepositoryFileData
Returns:
data
See Also:
#getDataForRead(RepositoryFile, Class)

getDataAtVersionForExecute

public <T extends IRepositoryFileData> T getDataAtVersionForExecute(Serializable fileId,
                                                                    Serializable versionId,
                                                                    Class<T> dataClass)
Gets data at given version for read.

Specified by:
getDataAtVersionForExecute in interface IUnifiedRepository
Parameters:
fileId - file id
versionId - version id
dataClass - class that implements IRepositoryFileData
Returns:
data

getDataForRead

public <T extends IRepositoryFileData> T getDataForRead(Serializable fileId,
                                                        Class<T> dataClass)
Gets data at base version for read.

Specified by:
getDataForRead in interface IUnifiedRepository
Parameters:
fileId - file id
dataClass - class that implements IRepositoryFileData
Returns:
data

getDataAtVersionForRead

public <T extends IRepositoryFileData> T getDataAtVersionForRead(Serializable fileId,
                                                                 Serializable versionId,
                                                                 Class<T> dataClass)
Gets data at given version for read.

Specified by:
getDataAtVersionForRead in interface IUnifiedRepository
Parameters:
fileId - file id
versionId - version id
dataClass - class that implements IRepositoryFileData
Returns:
data

getChildren

public List<RepositoryFile> getChildren(Serializable folderId)
Returns the children of this folder.

Specified by:
getChildren in interface IUnifiedRepository
Parameters:
folderId - id of folder whose children to fetch
Returns:
list of children (never null)

getChildren

public List<RepositoryFile> getChildren(Serializable folderId,
                                        String filter)
Returns the children of this folder that match the specified filter.

Specified by:
getChildren in interface IUnifiedRepository
Parameters:
folderId - id of folder whose children to fetch
filter - filter may be a full name or a partial name with one or more wildcard characters ("*"), or a disjunction (using the "|" character to represent logical OR) of these
Returns:
list of children (never null)

updateFile

public RepositoryFile updateFile(RepositoryFile file,
                                 IRepositoryFileData data,
                                 String versionMessage)
Updates a file and/or the data of a file.

Specified by:
updateFile in interface IUnifiedRepository
Parameters:
file - updated file (not a folder); must have non-null id
data - updated data
Returns:
updated file (possibly with new version number)

deleteFile

public void deleteFile(Serializable fileId,
                       boolean permanent,
                       String versionMessage)
Deletes a file.

Specified by:
deleteFile in interface IUnifiedRepository
Parameters:
fileId - file id
permanent - if true, once file is deleted, it cannot be undeleted
versionMessage - optional version comment

deleteFile

public void deleteFile(Serializable fileId,
                       String versionMessage)
Deletes a file in a recoverable manner.

Specified by:
deleteFile in interface IUnifiedRepository
Parameters:
fileId - file id
versionMessage - optional version comment

deleteFileAtVersion

public void deleteFileAtVersion(Serializable fileId,
                                Serializable versionId)
Permanently deletes a specific version of a file. The version is removed from the version history of the given file.

Specified by:
deleteFileAtVersion in interface IUnifiedRepository
Parameters:
fileId - file id
versionId - version id (MUST not be null)

getDeletedFiles

public List<RepositoryFile> getDeletedFiles(Serializable folderId)
Gets all deleted files for the current user in this folder.

Specified by:
getDeletedFiles in interface IUnifiedRepository
Parameters:
folderId - folder id
Returns:
list of deleted files

getDeletedFiles

public List<RepositoryFile> getDeletedFiles(Serializable folderId,
                                            String filter)
Gets all deleted files for the current user in this folder.

Specified by:
getDeletedFiles in interface IUnifiedRepository
Parameters:
folderId - folder id
filter - filter may be a full name or a partial name with one or more wildcard characters ("*"), or a disjunction (using the "|" character to represent logical OR) of these
Returns:
list of deleted files

getDeletedFiles

public List<RepositoryFile> getDeletedFiles()
Gets all deleted files for the current user. This is the "recycle bin" view.

Specified by:
getDeletedFiles in interface IUnifiedRepository
Returns:
list of deleted files

undeleteFile

public void undeleteFile(Serializable fileId,
                         String versionMessage)
Recovers a deleted file if it was not permanently deleted. File is recovered to its original folder.

Specified by:
undeleteFile in interface IUnifiedRepository
Parameters:
fileId - deleted file id
versionMessage - optional version comment to be applied to original parent folder

getAcl

public RepositoryFileAcl getAcl(Serializable fileId)
Returns ACL for file.

Specified by:
getAcl in interface IUnifiedRepository
Parameters:
fileId - file id
Returns:
access control list

lockFile

public void lockFile(Serializable fileId,
                     String message)
Locks a file.

Specified by:
lockFile in interface IUnifiedRepository
Parameters:
fileId - file id

unlockFile

public void unlockFile(Serializable fileId)
Unlocks a file.

Specified by:
unlockFile in interface IUnifiedRepository
Parameters:
fileId - file id

getVersionSummary

public VersionSummary getVersionSummary(Serializable fileId,
                                        Serializable versionId)
Returns a version summary for the given file id and version id.

Specified by:
getVersionSummary in interface IUnifiedRepository
Parameters:
fileId - file id
versionId - version id (if null, returns the last version)
Returns:
version summary

getVersionSummaries

public List<VersionSummary> getVersionSummaries(Serializable fileId)
Returns a list of version summary instances. The first version in the list is the root version. The last version in the list is the base version. Branching and merging are not supported so this is a simple list.

Specified by:
getVersionSummaries in interface IUnifiedRepository
Parameters:
fileId - file id
Returns:
list of version summaries (never null)

getFileAtVersion

public RepositoryFile getFileAtVersion(Serializable fileId,
                                       Serializable versionId)
Gets file as it was at the given version.

Specified by:
getFileAtVersion in interface IUnifiedRepository
Parameters:
fileId - file id
versionId - version id
Returns:
file at version

updateAcl

public RepositoryFileAcl updateAcl(RepositoryFileAcl acl)
Updates an ACL.

Specified by:
updateAcl in interface IUnifiedRepository
Parameters:
acl - ACL to set; must have non-null id
Returns:
updated ACL as it would be if calling IUnifiedRepository.getAcl(Serializable)

moveFile

public void moveFile(Serializable fileId,
                     String destAbsPath,
                     String versionMessage)
Moves and/or renames file.

Specified by:
moveFile in interface IUnifiedRepository
Parameters:
fileId - if of file or folder to move and/or rename
destAbsPath - path to destination; if only moving then destAbsPath will be an existing path

restoreFileAtVersion

public void restoreFileAtVersion(Serializable fileId,
                                 Serializable versionId,
                                 String versionMessage)
Makes a file, as it was at the given version, the latest version. Result should be the same as if the user had called IUnifiedRepository.updateFile(RepositoryFile, IRepositoryFileData, String) with a file and data that matched the state of the file and data at the given version.

Specified by:
restoreFileAtVersion in interface IUnifiedRepository
Parameters:
fileId - file id
versionId - version id
versionMessage - optional version comment

canUnlockFile

public boolean canUnlockFile(Serializable fileId)
Returns true if the current user can unlock the file. This might be a function of access control.

Specified by:
canUnlockFile in interface IUnifiedRepository
Parameters:
fileId - file id
Returns:
true if the current user can unlock the file

getTree

public RepositoryFileTree getTree(String path,
                                  int depth,
                                  String filter)
Gets a tree rooted at path.

Specified by:
getTree in interface IUnifiedRepository
Parameters:
path - path to file
depth - 0 fetches just file at path; positive integer n fetches node at path plus n levels of children; negative integer fetches all children
filter - filter may be a full name or a partial name with one or more wildcard characters ("*"), or a disjunction (using the "|" character to represent logical OR) of these; filter does not apply to root node
Returns:
file or null if the file does not exist or access is denied