Package ome.services.blitz.repo
Class RepositoryDaoImpl
- java.lang.Object
-
- ome.services.blitz.repo.RepositoryDaoImpl
-
- All Implemented Interfaces:
RepositoryDao
public class RepositoryDaoImpl extends java.lang.Object implements RepositoryDao
DAO class for encapsulating operations related to resource access inside the repository. Methods return types already mapped from Ice. DAO is also used in the form of a mock in unit tests.- Since:
- 5.0.0
-
-
Field Summary
Fields Modifier and Type Field Description protected ome.services.util.Executorexecutorprotected java.lang.StringfileRepoSecretKeyprotected ome.security.basic.OmeroInterceptorinterceptorprotected ome.system.Principalprincipalprotected ome.system.Rolesrolesprotected ome.services.util.ExecutorstatefulExecutor
-
Constructor Summary
Constructors Constructor Description RepositoryDaoImpl(ome.system.Principal principal, ome.services.util.Executor executor)Previous constructor which should no longer be used.RepositoryDaoImpl(ome.system.Principal principal, ome.system.Roles roles, ome.services.util.Executor executor, ome.services.util.Executor statefulExecutor, ome.security.basic.OmeroInterceptor interceptor, java.lang.String fileRepoSecretKey)Primary constructor which takes all final fields.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanUpdate(IObject obj, Ice.Current current)Delegates to IAdmin#canUpdateprotected voidcanWriteParentDirectory(ome.system.ServiceFactory sf, ome.util.SqlAction sql, java.lang.String repoUuid, CheckedPath parent)Throw aSecurityViolationif the current context cannot write to the parent directory.voidcreateOrFixUserDir(java.lang.String repoUuid, java.util.List<CheckedPath> checkedPaths, org.hibernate.Session s, ome.system.ServiceFactory sf, ome.util.SqlAction sql)Checks that the givenCheckedPathobjects exist (viaRepositoryDao.findRepoFile(String, CheckedPath, String, Ice.Current)) and are in the "user" group.protected java.util.List<ome.model.core.OriginalFile>createOriginalFile(ome.system.ServiceFactory sf, ome.util.SqlAction sql, java.lang.String repoUuid, java.util.List<CheckedPath> checked, ChecksumAlgorithm checksumAlgorithm, java.lang.String mimetype, org.hibernate.Session session)Primary location for creating original files from aCheckedPathinstance.protected ome.system.PrincipalcurrentUser(Ice.Current __current)java.util.List<java.lang.Integer>deleteRepoDeleteLogs(java.util.List<ome.util.SqlAction.DeleteLog> templates, Ice.Current current)CallSqlAction.deleteRepoDeleteLogs(DeleteLog)with the current context for a number of templates.intdeleteRepoDeleteLogs(ome.util.SqlAction.DeleteLog template, Ice.Current current)CallSqlAction.deleteRepoDeleteLogs(DeleteLog)with the current context.protected java.util.Map<java.lang.String,java.lang.String>fileContext(long fileId, Ice.Current current)Create a String-String map which can be used as the context for a call to Executor.execute based on the group of the file object.java.util.List<java.lang.Long>filterFilesByRepository(java.lang.String repo, java.util.List<java.lang.Long> ids, Ice.Current current)Find the original file IDs among those given that are in the given repository.java.util.List<java.util.List<ome.util.SqlAction.DeleteLog>>findRepoDeleteLogs(java.util.List<ome.util.SqlAction.DeleteLog> templates, Ice.Current current)AsfindRepoDeleteLogs(DeleteLog, Current)but for a collection of templates.java.util.List<ome.util.SqlAction.DeleteLog>findRepoDeleteLogs(ome.util.SqlAction.DeleteLog template, Ice.Current current)CallSqlAction.findRepoDeleteLogs(DeleteLog)with the current context.OriginalFilefindRepoFile(java.lang.String uuid, CheckedPath checked, java.lang.String mimetype, Ice.Current current)Delegate toSqlAction.findRepoFile(String, String, String, String)for looking up the id of the file, and then load it normally via IQuery.ome.model.core.OriginalFilefindRepoFile(ome.system.ServiceFactory sf, ome.util.SqlAction sql, java.lang.String uuid, CheckedPath checked, java.lang.String mimetype)AsRepositoryDao.findRepoFile(String, CheckedPath, String, Current)but can be called from within a transaction.ome.model.enums.ChecksumAlgorithmgetChecksumAlgorithm(java.lang.String name, Ice.Current current)Retrieve the checksum algorithm of the given name.EventContextgetEventContext(Ice.Current curr)Look up information for the current session as specified in the ctx field of the current.FsFilegetFile(long id, Ice.Current current, java.lang.String repoUuid)Get anFsFileobject based on its ID.OriginalFilegetOriginalFile(long repoId, Ice.Current current)Gets the original file instance for a given file ID.java.util.List<OriginalFile>getOriginalFiles(java.lang.String repoUuid, CheckedPath checked, Ice.Current current)Return a non-null, possibly empty list ofOriginalFileelements which are accessible to the given user at the given path.protected java.util.List<ome.model.core.OriginalFile>getOriginalFiles(ome.system.ServiceFactory sf, ome.util.SqlAction sql, java.lang.String repoUuid, CheckedPath checked)ome.model.core.OriginalFilegetOriginalFileWithHasher(long id, Ice.Current current)Retrieve the original file of the given ID.ome.api.RawFileStoregetRawFileStore(long fileId, CheckedPath checked, java.lang.String mode, Ice.Current current)Create aRawFileBean(i.e.java.lang.StringgetUserInstitution(long userId, Ice.Current current)Get the current user's institution.java.lang.StringgetUserInstitution(long userId, ome.system.ServiceFactory sf)Get the current user's institution.protected java.util.Map<java.lang.String,java.lang.String>groupContext(java.lang.Long groupId, Ice.Current current)Creates a copy of theCurrent.ctxmap and if groupId is not null, sets the "omero.group" key to be a string version of the id.protected voidinternalMkdir(CheckedPath file)This method should only be used by the register public method in order to guarantee that the DB is kept in sync with the file system.java.util.List<Fileset>loadFilesets(java.util.List<java.lang.Long> ids, Ice.Current current)Load filesets by id.voidmakeDirs(PublicRepositoryI repo, java.util.List<CheckedPath> dirs, boolean parents, Ice.Current __current)Create a number of directories in a single transaction, using thePublicRepositoryIinstance as a callback for implementation specific logic.OriginalFileregister(java.lang.String repoUuid, CheckedPath checked, java.lang.String mimetype, Ice.Current current)Register an OriginalFile objectome.model.core.OriginalFileregister(java.lang.String repoUuid, CheckedPath checked, java.lang.String mimetype, ome.system.ServiceFactory sf, ome.util.SqlAction sql, org.hibernate.Session session)Returns original file object is "live" within the Hibernate session.FilesetsaveFileset(java.lang.String repoUuid, Fileset _fs, ChecksumAlgorithm checksumAlgorithm, java.util.List<CheckedPath> paths, Ice.Current current)Fill the various fields of theFilesetand then save the entire instance into the database.JobsaveJob(Job job, Ice.Current current)Create a job from an instance provided by either the client or the server.voidsaveObject(ome.model.IObject object, Ice.Current current)Save the given model object.RMaptreeList(java.lang.String repoUuid, CheckedPath checked, Ice.Current current)protected ome.services.RawFileBeanunwrapRawFileBean(ome.api.RawFileStore proxy)LoadsvoidupdateJob(Job job, java.lang.String message, java.lang.String status, Ice.Current current)Set both the message and the status of the given job.protected SecurityViolationwrapSecurityViolation(ome.conditions.SecurityViolation sv)
-
-
-
Field Detail
-
principal
protected final ome.system.Principal principal
-
roles
protected final ome.system.Roles roles
-
executor
protected final ome.services.util.Executor executor
-
statefulExecutor
protected final ome.services.util.Executor statefulExecutor
-
interceptor
protected final ome.security.basic.OmeroInterceptor interceptor
-
fileRepoSecretKey
protected final java.lang.String fileRepoSecretKey
-
-
Constructor Detail
-
RepositoryDaoImpl
public RepositoryDaoImpl(ome.system.Principal principal, ome.system.Roles roles, ome.services.util.Executor executor, ome.services.util.Executor statefulExecutor, ome.security.basic.OmeroInterceptor interceptor, java.lang.String fileRepoSecretKey)Primary constructor which takes all final fields.
-
RepositoryDaoImpl
public RepositoryDaoImpl(ome.system.Principal principal, ome.services.util.Executor executor)Previous constructor which should no longer be used. Primarily for simplicity of testing.
-
-
Method Detail
-
unwrapRawFileBean
protected ome.services.RawFileBean unwrapRawFileBean(ome.api.RawFileStore proxy)
Loads- Returns:
- See above.
-
wrapSecurityViolation
protected SecurityViolation wrapSecurityViolation(ome.conditions.SecurityViolation sv) throws SecurityViolation
- Throws:
SecurityViolation
-
getRawFileStore
public ome.api.RawFileStore getRawFileStore(long fileId, CheckedPath checked, java.lang.String mode, Ice.Current current) throws SecurityViolationDescription copied from interface:RepositoryDaoCreate aRawFileBean(i.e. an implementation ofRawFileStorewhich can be passed toRepoRawFileStoreIfor performing internal functions. The primary difference to an instance created via the ServiceFactory is that theRawFileBean.setFileIdWithBuffer(long, FileBuffer)method is called pointing to a non-romio file path, e.g. /OMERO/Files/x.- Specified by:
getRawFileStorein interfaceRepositoryDao- Parameters:
fileId- ID of anOriginalFilechecked- Not null. Normalized path from the repository.mode- FileChannel mode, "r", "rw", etc.- Returns:
- An instance with
RawFileBean.setFileIdWithBuffer(long, FileBuffer)called. - Throws:
SecurityViolation
-
findRepoFile
public OriginalFile findRepoFile(java.lang.String uuid, CheckedPath checked, java.lang.String mimetype, Ice.Current current) throws ServerError
Description copied from interface:RepositoryDaoDelegate toSqlAction.findRepoFile(String, String, String, String)for looking up the id of the file, and then load it normally via IQuery. This will enforce any read security checks.- Specified by:
findRepoFilein interfaceRepositoryDao- Returns:
- See above.
- Throws:
ServerError
-
findRepoFile
public ome.model.core.OriginalFile findRepoFile(ome.system.ServiceFactory sf, ome.util.SqlAction sql, java.lang.String uuid, CheckedPath checked, java.lang.String mimetype)Description copied from interface:RepositoryDaoAsRepositoryDao.findRepoFile(String, CheckedPath, String, Current)but can be called from within a transaction.- Specified by:
findRepoFilein interfaceRepositoryDao
-
treeList
public RMap treeList(java.lang.String repoUuid, CheckedPath checked, Ice.Current current) throws ServerError
- Specified by:
treeListin interfaceRepositoryDao- Throws:
ServerError
-
createOrFixUserDir
public void createOrFixUserDir(java.lang.String repoUuid, java.util.List<CheckedPath> checkedPaths, org.hibernate.Session s, ome.system.ServiceFactory sf, ome.util.SqlAction sql) throws ServerErrorDescription copied from interface:RepositoryDaoChecks that the givenCheckedPathobjects exist (viaRepositoryDao.findRepoFile(String, CheckedPath, String, Ice.Current)) and are in the "user" group. If they don't exist, they are created; and if they aren't in the "user" group, they are moved.- Specified by:
createOrFixUserDirin interfaceRepositoryDao- Throws:
ServerError
-
canUpdate
public boolean canUpdate(IObject obj, Ice.Current current)
Description copied from interface:RepositoryDaoDelegates to IAdmin#canUpdate- Specified by:
canUpdatein interfaceRepositoryDao- Returns:
- See above.
-
filterFilesByRepository
public java.util.List<java.lang.Long> filterFilesByRepository(java.lang.String repo, java.util.List<java.lang.Long> ids, Ice.Current current)Description copied from interface:RepositoryDaoFind the original file IDs among those given that are in the given repository.- Specified by:
filterFilesByRepositoryin interfaceRepositoryDao- Parameters:
repo- a repository UUIDids- IDs of original filescurrent- Ice method invocation context- Returns:
- those IDs among those given whose original files are in the given repository
-
getOriginalFile
public OriginalFile getOriginalFile(long repoId, Ice.Current current) throws SecurityViolation
Description copied from interface:RepositoryDaoGets the original file instance for a given file ID.- Specified by:
getOriginalFilein interfaceRepositoryDao- Parameters:
repoId- a file IDcurrent- applicable ICE context- Returns:
- the original file corresponding to the given file ID
- Throws:
SecurityViolation- if the query threw a security violation
-
getOriginalFiles
public java.util.List<OriginalFile> getOriginalFiles(java.lang.String repoUuid, CheckedPath checked, Ice.Current current) throws SecurityViolation
Description copied from interface:RepositoryDaoReturn a non-null, possibly empty list ofOriginalFileelements which are accessible to the given user at the given path. If the directory which they are associated with is not also readable by the current user, then aSecurityViolationwill be thrown.- Specified by:
getOriginalFilesin interfaceRepositoryDao- Parameters:
repoUuid- for the repository in question.checked- normalized path which can be found as the value ofOriginalFile.getPath()in the database.- Throws:
SecurityViolation
-
getOriginalFiles
protected java.util.List<ome.model.core.OriginalFile> getOriginalFiles(ome.system.ServiceFactory sf, ome.util.SqlAction sql, java.lang.String repoUuid, CheckedPath checked)
-
saveFileset
public Fileset saveFileset(java.lang.String repoUuid, Fileset _fs, ChecksumAlgorithm checksumAlgorithm, java.util.List<CheckedPath> paths, Ice.Current current) throws ServerError
Description copied from interface:RepositoryDaoFill the various fields of theFilesetand then save the entire instance into the database.- Specified by:
saveFilesetin interfaceRepositoryDao- Parameters:
repoUuid- for the repository in question._fs- a user providedFilesetthat must minimally have theFilesetEntryobjects present with their clientPath set. The rest of the fields will be filled here.checksumAlgorithm- The algorithm to use.paths- a List of the same size as the number of entries in fs one perFilesetEntry.current- Current context- Throws:
ServerError
-
loadFilesets
public java.util.List<Fileset> loadFilesets(java.util.List<java.lang.Long> ids, Ice.Current current) throws ServerError
Description copied from interface:RepositoryDaoLoad filesets by id.- Specified by:
loadFilesetsin interfaceRepositoryDao- Returns:
- See above.
- Throws:
ServerError
-
register
public OriginalFile register(java.lang.String repoUuid, CheckedPath checked, java.lang.String mimetype, Ice.Current current) throws ServerError
Description copied from interface:RepositoryDaoRegister an OriginalFile object- Specified by:
registerin interfaceRepositoryDao- Parameters:
repoUuid- uuid of the repository that the given file argument should be registered with. Cannot be null.checked- Normalized path provided by the repository. Not null.mimetype- Mimetype for use with the OriginalFile. May be null in which case a default will be chosen.current- Not null.- Returns:
- The OriginalFile with id set (unloaded)
- Throws:
ServerError
-
register
public ome.model.core.OriginalFile register(java.lang.String repoUuid, CheckedPath checked, java.lang.String mimetype, ome.system.ServiceFactory sf, ome.util.SqlAction sql, org.hibernate.Session session) throws ServerErrorReturns original file object is "live" within the Hibernate session.- Specified by:
registerin interfaceRepositoryDao- Parameters:
repoUuid-checked-mimetype-sf-sql-session-- Returns:
- See above.
- Throws:
ServerError
-
saveJob
public Job saveJob(Job job, Ice.Current current) throws ServerError
Description copied from interface:RepositoryDaoCreate a job from an instance provided by either the client or the server. Only those fields which are modifiable by the user will be copied.- Specified by:
saveJobin interfaceRepositoryDao- Parameters:
job- Not null.current- Not null.- Returns:
- See above.
- Throws:
ServerError
-
updateJob
public void updateJob(Job job, java.lang.String message, java.lang.String status, Ice.Current current) throws ServerError
Description copied from interface:RepositoryDaoSet both the message and the status of the given job.- Specified by:
updateJobin interfaceRepositoryDao- Parameters:
job- Not null.message- If null, no modification will be made for the messagestatus- If null, no modification will be made for the status.current- Not null.- Throws:
ServerError
-
makeDirs
public void makeDirs(PublicRepositoryI repo, java.util.List<CheckedPath> dirs, boolean parents, Ice.Current __current) throws ServerError
Description copied from interface:RepositoryDaoCreate a number of directories in a single transaction, using thePublicRepositoryIinstance as a callback for implementation specific logic. Applies thereal user
's event context when within aPublicRepositoryI.sudo(Current, String).- Specified by:
makeDirsin interfaceRepositoryDao- Throws:
ServerError
-
getFile
public FsFile getFile(long id, Ice.Current current, java.lang.String repoUuid)
Description copied from interface:RepositoryDaoGet anFsFileobject based on its ID. Returns null if the file does not exist or does not belong to this repository.- Specified by:
getFilein interfaceRepositoryDao- Parameters:
id- database ID of the sought original filecurrent- current applicable ICE contextrepoUuid- the UUID of the repository containing the original file- Returns:
- the requested FsFile object
-
findRepoDeleteLogs
public java.util.List<ome.util.SqlAction.DeleteLog> findRepoDeleteLogs(ome.util.SqlAction.DeleteLog template, Ice.Current current)Description copied from interface:RepositoryDaoCallSqlAction.findRepoDeleteLogs(DeleteLog)with the current context.- Specified by:
findRepoDeleteLogsin interfaceRepositoryDao- Parameters:
template- not null.current- not null.- Returns:
- all the rows found which match the non-null fields on templates
-
findRepoDeleteLogs
public java.util.List<java.util.List<ome.util.SqlAction.DeleteLog>> findRepoDeleteLogs(java.util.List<ome.util.SqlAction.DeleteLog> templates, Ice.Current current)Description copied from interface:RepositoryDaoAsfindRepoDeleteLogs(DeleteLog, Current)but for a collection of templates.- Specified by:
findRepoDeleteLogsin interfaceRepositoryDao- Parameters:
templates- not null.current- not null.- Returns:
- all the rows found which match the non-null fields on templates
-
deleteRepoDeleteLogs
public int deleteRepoDeleteLogs(ome.util.SqlAction.DeleteLog template, Ice.Current current)Description copied from interface:RepositoryDaoCallSqlAction.deleteRepoDeleteLogs(DeleteLog)with the current context.- Specified by:
deleteRepoDeleteLogsin interfaceRepositoryDao- Parameters:
template- not null.current- not null.- Returns:
- the number of rows deleted
-
deleteRepoDeleteLogs
public java.util.List<java.lang.Integer> deleteRepoDeleteLogs(java.util.List<ome.util.SqlAction.DeleteLog> templates, Ice.Current current)Description copied from interface:RepositoryDaoCallSqlAction.deleteRepoDeleteLogs(DeleteLog)with the current context for a number of templates.- Specified by:
deleteRepoDeleteLogsin interfaceRepositoryDao- Parameters:
templates- not null.current- not null.- Returns:
- A list containing the number of rows deleted
-
getEventContext
public EventContext getEventContext(Ice.Current curr)
Description copied from interface:RepositoryDaoLook up information for the current session as specified in the ctx field of the current.- Specified by:
getEventContextin interfaceRepositoryDao
-
getUserInstitution
public java.lang.String getUserInstitution(long userId, Ice.Current current)Description copied from interface:RepositoryDaoGet the current user's institution.- Specified by:
getUserInstitutionin interfaceRepositoryDao- Parameters:
userId- the ID of the user whose institution is to be fetchedcurrent- the current ICE method invocation context- Returns:
- the institution, may be
null
-
getUserInstitution
public java.lang.String getUserInstitution(long userId, ome.system.ServiceFactory sf)Description copied from interface:RepositoryDaoGet the current user's institution.- Specified by:
getUserInstitutionin interfaceRepositoryDao- Parameters:
userId- the ID of the user whose institution is to be fetchedsf- the service factory to use for the query- Returns:
- the institution, may be
null
-
createOriginalFile
protected java.util.List<ome.model.core.OriginalFile> createOriginalFile(ome.system.ServiceFactory sf, ome.util.SqlAction sql, java.lang.String repoUuid, java.util.List<CheckedPath> checked, ChecksumAlgorithm checksumAlgorithm, java.lang.String mimetype, org.hibernate.Session session)Primary location for creating original files from aCheckedPathinstance. This will use access to the actualFileobject in order to calculate size, timestamps, etc.- Parameters:
sf-sql-repoUuid-checked-checksumAlgorithm-mimetype-session-- Returns:
- See above.
-
internalMkdir
protected void internalMkdir(CheckedPath file)
This method should only be used by the register public method in order to guarantee that the DB is kept in sync with the file system.- Parameters:
file- the path to ensure exists as a directory- Throws:
ome.conditions.ResourceError
-
canWriteParentDirectory
protected void canWriteParentDirectory(ome.system.ServiceFactory sf, ome.util.SqlAction sql, java.lang.String repoUuid, CheckedPath parent)Throw aSecurityViolationif the current context cannot write to the parent directory.- Parameters:
sf-sql-repoUuid-parent-
-
currentUser
protected ome.system.Principal currentUser(Ice.Current __current)
-
fileContext
protected java.util.Map<java.lang.String,java.lang.String> fileContext(long fileId, Ice.Current current) throws SecurityViolationCreate a String-String map which can be used as the context for a call to Executor.execute based on the group of the file object.- Returns:
- See above.
- Throws:
SecurityViolation- if the file can't be read.
-
groupContext
protected java.util.Map<java.lang.String,java.lang.String> groupContext(java.lang.Long groupId, Ice.Current current)Creates a copy of theCurrent.ctxmap and if groupId is not null, sets the "omero.group" key to be a string version of the id.- Parameters:
groupId-current-- Returns:
- See above.
-
getChecksumAlgorithm
public ome.model.enums.ChecksumAlgorithm getChecksumAlgorithm(java.lang.String name, Ice.Current current)Description copied from interface:RepositoryDaoRetrieve the checksum algorithm of the given name.- Specified by:
getChecksumAlgorithmin interfaceRepositoryDao- Parameters:
name- a checksum algorithm name, must existcurrent- Ice method invocation context- Returns:
- the corresponding checksum algorithm model object
-
getOriginalFileWithHasher
public ome.model.core.OriginalFile getOriginalFileWithHasher(long id, Ice.Current current)Description copied from interface:RepositoryDaoRetrieve the original file of the given ID.- Specified by:
getOriginalFileWithHasherin interfaceRepositoryDao- Parameters:
id- the ID of an original file, must existcurrent- Ice method invocation context- Returns:
- the corresponding original file model object
-
saveObject
public void saveObject(ome.model.IObject object, Ice.Current current)Description copied from interface:RepositoryDaoSave the given model object.- Specified by:
saveObjectin interfaceRepositoryDao- Parameters:
object- a model objectcurrent- Ice method invocation context
-
-