public class DefaultFileEngine extends Object implements FileEngine
Modifier and Type | Field and Description |
---|---|
static String |
CONFIGURATION_KEY_TMP_FILE_DIR
Configuration key for temporary file directory,
|
Constructor and Description |
---|
DefaultFileEngine(com.tenduke.sdk2.api.security.Actor actor,
com.tenduke.sdk2.objectmodel.identity.Account account,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Initializes a new instance of the
DefaultFileEngine class. |
Modifier and Type | Method and Description |
---|---|
void |
cp(String source,
String target)
Copies an entry in storage (directory copy is recursive).
|
RegularFile |
createFile(String path,
File file)
Creates file.
|
RegularFile |
createFile(String path,
com.tenduke.sdk2.api.io.Resource file)
Creates file.
|
protected boolean |
doCheckDirExists(String path,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Checks if given directory path exists.
|
protected boolean |
doCheckFileExists(String path,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Checks if given regular file exists.
|
protected String |
doChrootPath(String path)
Applies chroot scope to path and returns the resulting path "under" getChroot().
|
protected void |
doCopyDirectory(Directory dir,
String target,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Copies a
Directory to given path. |
protected RegularFile |
doCopyFile(RegularFile file,
String target,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Copies a
RegularFile to given path. |
protected RegularFile |
doCreateFile(String path,
com.tenduke.sdk2.api.io.Resource file,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Creates file.
|
protected com.tenduke.sdk2.utils.storage.StorageUri |
doCreateFileIdentifier(RegularFile file)
Creates storage file identifier for a regular file object.
|
protected void |
doDeleteDirectory(Directory dir,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Deletes specified directory and all contents in it.
|
protected void |
doDeleteDirectoryRecursively(String path,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Deletes specified directory and all content recursively.
|
protected void |
doDeleteFile(RegularFile file,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Deletes specified file.
|
protected AccessPolicy |
doGetAccessPolicy(String path)
Gets access policy for given path.
|
protected AccessPolicy |
doGetAndCheckAccessPolicy(String path,
AccessPolicy newAccessPolicy)
Gets access policy for given path.
|
protected File |
doGetAsLocalFile(String path,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Gets stored file based on path.
|
protected com.tenduke.sdk2.api.io.Resource |
doGetFileResource(String path,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Gets stored file based on path.
|
protected FileEntry |
doLs(String path,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Lists directory contents or information about file that path denotes.
|
void |
doMkdir(String path,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Creates a new
Directory . |
protected void |
doMoveDirectory(Directory dir,
String target,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Moves a
Directory to a new path. |
protected void |
doMoveFile(RegularFile file,
String target,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Moves a
RegularFile to a new path. |
protected List<AccessPolicy> |
doQueryAccessPolicys(UUID fileEntryId,
String referenceFieldName)
Queries
AccessPolicy entities based on file entry id and reference field name. |
protected Directory |
doQueryDir(String path,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Queries
Directory by path. |
protected RegularFile |
doQueryFile(String path,
Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
Queries
RegularFile by path. |
protected com.tenduke.sdk2.objectmodel.identity.Account |
doResolveAccount(com.tenduke.sdk2.api.security.Actor actor)
Resolves
Account that the actor is related to. |
protected void |
doSetAccessPolicy(String path,
AccessPolicy accessPolicy)
Sets access policy for given path.
|
protected String |
doUnchrootPath(String chrootedPath)
Removes chroot scope from path and returns the result.
|
com.tenduke.sdk2.api.KeyValuePair<File,Boolean> |
ensureFileIsLocal(String path)
Gets stored file ensuring local access.
|
boolean |
exists(String path)
Checks if given path already exists.
|
AccessPolicy |
getAccessPolicy(String path)
Gets access policy for given path.
|
protected com.tenduke.sdk2.api.security.Actor |
getActor()
Gets actor set for this instance.
|
protected UUID |
getActorId()
Gets actor's id.
|
protected com.tenduke.sdk2.api.security.AuthorityChecker |
getAuthorityChecker()
Gets AuthorityChecker from service locator.
|
String |
getChroot()
Gets root path that constrains file engine into an account specific hierarchy.
|
protected com.tenduke.sdk2.api.persistence.EntityManager<? extends com.tenduke.sdk2.api.persistence.EntityTransaction> |
getEntityManager()
Gets entity manager used to manage persistence for file engine objects.
|
com.tenduke.sdk2.api.io.Resource |
getFileResource(String path)
Gets stored file based on path.
|
protected com.tenduke.sdk2.api.storage.StorageProvider |
getStorageProvider()
Gets storage provider from service locator.
|
protected com.tenduke.sdk2.api.UuidGenerator |
getUuidGenerator()
Gets UUID generator from service locator.
|
List<String> |
ls(String path)
Lists directory contents or information about file that path denotes.
|
void |
mkdir(String path)
Creates a new
Directory . |
void |
mv(String source,
String target)
Moves a directory or file.
|
void |
rm(String path)
Removes an entry from storage.
|
void |
setAccessPolicy(String path,
AccessPolicy accessPolicy)
Sets access policy for given path.
|
void |
setChroot(String chroot)
Sets root path that constrains file engine into an account specific hierarchy.
|
RegularFile |
updateFile(RegularFile file)
Updates file entry.
|
public static final String CONFIGURATION_KEY_TMP_FILE_DIR
public DefaultFileEngine(com.tenduke.sdk2.api.security.Actor actor, com.tenduke.sdk2.objectmodel.identity.Account account, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants)
DefaultFileEngine
class.actor
- The effective actor using this instance.account
- Account that actor is related to. Not null argument will constrain this instance to the account storage scope.permissionGrants
- Permission grants used to authorize operations with AuthorityChecker
.public String getChroot()
getChroot
in interface FileEngine
public void setChroot(String chroot)
setChroot
in interface FileEngine
chroot
- root path that constrains file engine into an account specific hierarchy.public AccessPolicy getAccessPolicy(String path) throws PathException
getAccessPolicy
in interface FileEngine
path
- Path to get access policy for.AccessPolicy
set for the path or null if none has been defined.PathException
- for errors parsing path, errors using path, or errors trying to access access policy.public void setAccessPolicy(String path, AccessPolicy accessPolicy) throws PathException
setAccessPolicy
in interface FileEngine
path
- Path to set access policy for.accessPolicy
- The access policy to set for the path. The entity's id field
is always managed by this method. For new policy instances the id
is set to random and for entities found by the path the id is
copied from the existing entity before updating.
A null value will cause current policy object to be deleted if one is found.PathException
- for errors parsing path, errors using path, or errors trying to access access policy.public List<String> ls(String path) throws PathException
FileEntry.pathAsListEntry()
.ls
in interface FileEngine
path
- Path to list content from.PathException
- for errors parsing path or using path.public void mkdir(String path) throws PathException
Directory
.mkdir
in interface FileEngine
path
- Path of directory to create.PathException
- for errors parsing path or creating directory.public void mv(String source, String target) throws PathException
mv
in interface FileEngine
source
- Source path of entry to move.target
- Target path to move to.PathException
- for errors parsing paths or errors using paths.public void cp(String source, String target) throws PathException
cp
in interface FileEngine
source
- Source path of entry to copy.target
- Target path to copy to.PathException
- for errors parsing paths or errors using paths.public void rm(String path) throws PathException
rm
in interface FileEngine
path
- Path denoting directory or file to remove.PathException
- for errors parsing path or errors while using path.public boolean exists(String path) throws PathException
exists
in interface FileEngine
path
- Path to check.PathException
- for errors parsing path.public RegularFile createFile(String path, File file) throws PathException
createFile
in interface FileEngine
path
- Path to create file in.file
- File that holds the data for the file to create. If a null file is passed in a file entry will still be
created with status FileEntry.STATUS_NULL_FILE
.RegularFile
.PathException
- for errors parsing path or using path.public RegularFile createFile(String path, com.tenduke.sdk2.api.io.Resource file) throws PathException
createFile
in interface FileEngine
path
- Path to create file in.file
- File that holds the data for the file to create. If a null file is passed in a file entry will still be
created with status FileEntry.STATUS_NULL_FILE
.RegularFile
.PathException
- for errors parsing path or using path.public RegularFile updateFile(RegularFile file) throws PathException
updateFile
in interface FileEngine
file
- Entry to update.RegularFile
.PathException
- for errors parsing path or using path.public com.tenduke.sdk2.api.KeyValuePair<File,Boolean> ensureFileIsLocal(String path) throws PathException
ensureFileIsLocal
in interface FileEngine
path
- Path to find file in.File
and flag to indicate if caller should delete file
when done using it. Null return value means file was not found.PathException
- for errors parsing path or using path.public com.tenduke.sdk2.api.io.Resource getFileResource(String path) throws PathException
getFileResource
in interface FileEngine
path
- Path to find file in.Resource
. The caller must close the returned resource object.PathException
- for errors parsing path or using path.protected String doChrootPath(String path)
path
- Path to move under chroot.protected String doUnchrootPath(String chrootedPath)
chrootedPath
- Path from which to remove chroot scope.protected AccessPolicy doGetAccessPolicy(String path) throws PathException
path
- Path to get access policy for.AccessPolicy
set for the path or null if none has been defined.PathException
- for errors parsing path or setting access policy for the path.protected AccessPolicy doGetAndCheckAccessPolicy(String path, AccessPolicy newAccessPolicy) throws PathException
path
- Path to get access policy for.newAccessPolicy
- Optional new entity to set reference field information for.AccessPolicy
set for the path or null if none has been defined.PathException
- for errors parsing path or setting access policy for the path.protected List<AccessPolicy> doQueryAccessPolicys(UUID fileEntryId, String referenceFieldName) throws PathException
AccessPolicy
entities based on file entry id and reference field name.fileEntryId
- Identifier of file entry that access policy is related to.referenceFieldName
- Reference field name used in AccessPolicy
for referencing file entry.PathException
- For errors querying file entry's access policies.protected void doSetAccessPolicy(String path, AccessPolicy accessPolicy) throws PathException
path
- Path to set access policy for.accessPolicy
- The access policy to set for the path. The entity's id field
is always managed by this method. For new policy instances the id
is set to random and for entities found by the path the id is
copied from the existing entity before updating.
A null value will cause an existing policy object to be deleted.PathException
- for errors parsing path, errors using path, or errors trying to access access policy.protected boolean doCheckDirExists(String path, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants) throws PathException
path
- Path to check.permissionGrants
- Permissions granted to authorize operations.PathException
- for errors parsing path.protected boolean doCheckFileExists(String path, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants) throws PathException
path
- Path to check.permissionGrants
- Permissions granted to authorize operations.PathException
- for errors parsing path.protected FileEntry doLs(String path, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants) throws PathException
path
- Path to list content from.permissionGrants
- Permissions granted to authorize operations.FileEntry
object in specified path or null if no such directory exists. To access contents
of directory use AbstractDynamicRelatedObject.relatedObjects(java.lang.Class, com.tenduke.sdk2.api.object.Multiplicity)
with relation object type set to Directory
or RegularFile
and multiplicity as
Multiplicity.ONE_TO_MANY
.PathException
- for errors parsing path or using path.public void doMkdir(String path, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants) throws PathException
Directory
.path
- Path of directory to create.permissionGrants
- Permissions granted to authorize operations.PathException
- for errors parsing path or creating directory.protected com.tenduke.sdk2.api.io.Resource doGetFileResource(String path, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants) throws PathException
path
- Path to find file in.permissionGrants
- Permissions granted to authorize operations.Resource
. The caller must close the returned resource object.PathException
- for errors parsing path or using path.protected File doGetAsLocalFile(String path, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants) throws PathException
path
- Path to find file in.permissionGrants
- Permissions granted to authorize operations.File
.PathException
- for errors parsing path or using path.protected RegularFile doCreateFile(String path, com.tenduke.sdk2.api.io.Resource file, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants) throws PathException
path
- Path to create file in.file
- File that holds the data for the file to create. If a null file is passed in a file entry will still be
created with status FileEntry.STATUS_NULL_FILE
.permissionGrants
- Permissions granted to authorize operations.RegularFile
.PathException
- for errors parsing path or using path.protected com.tenduke.sdk2.utils.storage.StorageUri doCreateFileIdentifier(RegularFile file) throws PathException
file
- RegularFile
to create storage file identifier for.StorageProvider
.PathException
- for errors creating file identifier.protected void doMoveDirectory(Directory dir, String target, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants) throws PathException
Directory
to a new path.dir
- Directory to move.target
- New path to move to.permissionGrants
- Permissions granted to authorize operations.PathException
- for errors parsing paths or errors using paths
(e.g. target exists will cause an exception).protected void doMoveFile(RegularFile file, String target, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants) throws PathException
RegularFile
to a new path.file
- File to move.target
- New path to move to.permissionGrants
- Permissions granted to authorize operations.PathException
- for errors parsing paths or errors using paths
(e.g. target exists will cause an exception).protected void doCopyDirectory(Directory dir, String target, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants) throws PathException
Directory
to given path.dir
- Directory to copy.target
- New path to copy to.permissionGrants
- Permissions granted to authorize operations.PathException
- for errors parsing paths or errors using paths
(e.g. target exists will cause an exception).protected RegularFile doCopyFile(RegularFile file, String target, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants) throws PathException
RegularFile
to given path.file
- File to copy.target
- New path to copy to.permissionGrants
- Permissions granted to authorize operations.PathException
- for errors parsing paths or errors using paths
(e.g. target exists will cause an exception).protected void doDeleteFile(RegularFile file, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants) throws PathException
file
- File to delete.permissionGrants
- Permissions granted to authorize operations.PathException
- for errors deleting file.protected void doDeleteDirectory(Directory dir, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants) throws PathException
dir
- Directory to delete.permissionGrants
- Permissions granted to authorize operations.PathException
- for errors parsing path or using path.protected void doDeleteDirectoryRecursively(String path, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants) throws PathException
path
- Starting node in Directory tree to delete.permissionGrants
- Permissions granted to authorize operations.PathException
- for errors parsing path or using path.protected Directory doQueryDir(String path, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants) throws PathException
Directory
by path.path
- Path to match.permissionGrants
- Permissions granted to authorize operations.Directory
with specified path or null if not found.PathException
- for errors parsing path.protected RegularFile doQueryFile(String path, Iterable<com.tenduke.sdk2.api.security.PermissionGrant> permissionGrants) throws PathException
RegularFile
by path.path
- Path to match.permissionGrants
- Permissions granted to authorize operations.RegularFile
with specified path or null if not found.PathException
- for errors parsing path.protected com.tenduke.sdk2.objectmodel.identity.Account doResolveAccount(com.tenduke.sdk2.api.security.Actor actor)
Account
that the actor is related to.actor
- The actor to resolve account for.protected com.tenduke.sdk2.api.security.Actor getActor()
protected UUID getActorId()
protected com.tenduke.sdk2.api.UuidGenerator getUuidGenerator()
protected com.tenduke.sdk2.api.persistence.EntityManager<? extends com.tenduke.sdk2.api.persistence.EntityTransaction> getEntityManager()
protected com.tenduke.sdk2.api.security.AuthorityChecker getAuthorityChecker()
protected com.tenduke.sdk2.api.storage.StorageProvider getStorageProvider()
Copyright © 2015. All rights reserved.