Package ome.services.scripts
Class ScriptRepoHelper
- java.lang.Object
-
- ome.tools.spring.OnContextRefreshedEventListener
-
- ome.services.scripts.ScriptRepoHelper
-
- All Implemented Interfaces:
java.util.EventListener,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
public class ScriptRepoHelper extends OnContextRefreshedEventListener
Strategy used by the ScriptRepository for registering, loading, and saving files.- Since:
- Beta4.2
-
-
Field Summary
Fields Modifier and Type Field Description static org.apache.commons.io.filefilter.IOFileFilterBASE_SCRIPT_FILTERIOFileFilterinstance used duringiterate()to find the matching scripts in the given directory.protected org.slf4j.Loggerlogstatic java.lang.StringSCRIPT_REPOId used by all script repositories.
-
Constructor Summary
Constructors Constructor Description ScriptRepoHelper(java.io.File dir, Executor ex, java.lang.String sessionUuid, ome.system.Principal p, ome.system.Roles roles)Deprecated.ScriptRepoHelper(java.io.File dir, Executor ex, java.lang.String sessionUuid, ome.system.Principal p, ome.system.Roles roles, ReadOnlyStatus readOnly)Deprecated.ScriptRepoHelper(java.lang.String uuid, java.io.File dir, Executor ex, java.lang.String sessionUuid, ome.system.Principal p, ome.system.Roles roles)Deprecated.ScriptRepoHelper(java.lang.String uuid, java.io.File dir, Executor ex, java.lang.String sessionUuid, ome.system.Principal p, ome.system.Roles roles, ReadOnlyStatus readOnly)ScriptRepoHelper(Executor ex, java.lang.String sessionUuid, ome.system.Roles roles)Deprecated.ScriptRepoHelper(Executor ex, java.lang.String sessionUuid, ome.system.Roles roles, ReadOnlyStatus readOnly)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ome.model.core.OriginalFileaddOrReplace(RepoFile repoFile, java.lang.Long old)protected ome.model.core.OriginalFileaddOrReplace(org.hibernate.Session session, ome.util.SqlAction sqlAction, ome.system.ServiceFactory sf, RepoFile repoFile, java.lang.Long old)voidbuildQuery(QueryBuilder qb)Adds a single clause of the form "AND (A OR B ...)" where eachScriptFileTypeA, B, etc.voidcheckForScriptUpdates()Check for updates to scripts, modifying database accordingly.intcountInDb()intcountInDb(ome.util.SqlAction sql)intcountOnDisk()Returns the number of files which matchscriptFilterindir.booleandelete(long id)protected java.util.Map.Entry<java.lang.String,ScriptFileType>findByMimetype(java.lang.String mimetype)Search through allScriptFileTypeinstances and find one with a matching mimetype string.java.lang.LongfindInDb(java.lang.String path, boolean scriptsOnly)java.lang.LongfindInDb(RepoFile file, boolean scriptsOnly)java.lang.LongfindInDb(ome.util.SqlAction sql, RepoFile repoFile, boolean scriptsOnly)Looks to see if a path is contained in the repository.static java.lang.StringgetDefaultScriptDir()Directory which will be used as the root of this repository if no directory is passed to a constructor.java.lang.StringgetLauncher(java.lang.String mimetype)Find an "omero.launcher..." property string for the given mimetype or return "" if none is found.java.lang.StringgetProcess(java.lang.String mimetype)Find an "omero.process..." property string for the given mimetype or return "" if none is found.java.lang.StringgetScriptDir()Returns the actual root of this repository.java.lang.StringgetUuid()Uuid of this repository.voidhandleContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent event)Loads allScriptFileTypeinstances from the context, and uses them to initialize all scripts in the repo.java.util.List<java.lang.Long>idsInDb()java.util.List<java.lang.Long>idsInDb(ome.util.SqlAction sql)booleanisInert(ome.model.core.OriginalFile f)Returnstrueif the file is an "inert" file e.g.booleanisInRepo(long id)booleanisInRepo(ome.util.SqlAction sql, long id)java.util.Iterator<java.io.File>iterate()ome.model.core.OriginalFileload(long id, boolean check)ome.model.core.OriginalFileload(long id, org.hibernate.Session s, ome.util.SqlAction sqlAction, boolean check)java.util.List<ome.model.core.OriginalFile>loadAll(boolean modificationCheck)Walks all files in the repository (viaiterate()and adds them if not found in the database.java.util.List<ome.model.core.OriginalFile>loadAll(boolean modificationCheck, java.lang.String mimetype)Walks all files in the repository (viaiterate()and adds them if not found in the database.java.util.List<ome.model.core.OriginalFile>loadAll(boolean modificationCheck, java.lang.String mimetype, ome.system.Principal pp)voidmodificationCheck()Checks ifjava.lang.Stringread(java.lang.String path)longremoveMissingFilesFromDb(ome.util.SqlAction sqlAction, org.hibernate.Session session, java.util.List<ome.model.core.OriginalFile> filesOnDisk)Given the current files on disk,unregister(Long, SqlAction)all files which have been removed from disk.voidsetMimetype(ome.model.core.OriginalFile ofile)voidsimpleDelete(java.util.Map<java.lang.String,java.lang.String> context, Executor executor, ome.system.Principal p, long id)Unlikedelete(long)this method simply performs the DB delete on the given original file id.protected voidunregister(java.lang.Long old, ome.util.SqlAction sqlAction)Unregisters a given file from the script repository by setting its Repo uuid to null.ome.model.core.OriginalFileupdate(RepoFile repoFile, java.lang.Long id, java.util.Map<java.lang.String,java.lang.String> context)RepoFilewrite(java.lang.String path, java.lang.String text)RepoFilewrite(RepoFile repo, java.lang.String text)-
Methods inherited from class ome.tools.spring.OnContextRefreshedEventListener
onApplicationEvent, setApplicationContext
-
-
-
-
Field Detail
-
SCRIPT_REPO
public static final java.lang.String SCRIPT_REPO
Id used by all script repositories. Having a well defined string allows for various repositories to all provide the same functionality.- See Also:
- Constant Field Values
-
BASE_SCRIPT_FILTER
public static final org.apache.commons.io.filefilter.IOFileFilter BASE_SCRIPT_FILTER
IOFileFilterinstance used duringiterate()to find the matching scripts in the given directory.
-
log
protected final org.slf4j.Logger log
-
-
Constructor Detail
-
ScriptRepoHelper
@Deprecated public ScriptRepoHelper(Executor ex, java.lang.String sessionUuid, ome.system.Roles roles)
Deprecated.
-
ScriptRepoHelper
public ScriptRepoHelper(Executor ex, java.lang.String sessionUuid, ome.system.Roles roles, ReadOnlyStatus readOnly)
-
ScriptRepoHelper
@Deprecated public ScriptRepoHelper(java.io.File dir, Executor ex, java.lang.String sessionUuid, ome.system.Principal p, ome.system.Roles roles)Deprecated.
-
ScriptRepoHelper
@Deprecated public ScriptRepoHelper(java.lang.String uuid, java.io.File dir, Executor ex, java.lang.String sessionUuid, ome.system.Principal p, ome.system.Roles roles)Deprecated.
-
ScriptRepoHelper
@Deprecated public ScriptRepoHelper(java.io.File dir, Executor ex, java.lang.String sessionUuid, ome.system.Principal p, ome.system.Roles roles, ReadOnlyStatus readOnly)Deprecated.
-
ScriptRepoHelper
public ScriptRepoHelper(java.lang.String uuid, java.io.File dir, Executor ex, java.lang.String sessionUuid, ome.system.Principal p, ome.system.Roles roles, ReadOnlyStatus readOnly)- Parameters:
uuid- Allows setting a non-default uuid for this script service. Primarily for testing, since services rely on the repository name for finding one another.dir- The directory used by the repo as its root. Other constructors usegetDefaultScriptDir()internally.ex-p-
-
-
Method Detail
-
handleContextRefreshedEvent
public void handleContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent event)
Loads allScriptFileTypeinstances from the context, and uses them to initialize all scripts in the repo.- Specified by:
handleContextRefreshedEventin classOnContextRefreshedEventListener
-
checkForScriptUpdates
public void checkForScriptUpdates()
Check for updates to scripts, modifying database accordingly. Called when Blitz is configured.
-
buildQuery
public void buildQuery(QueryBuilder qb)
Adds a single clause of the form "AND (A OR B ...)" where eachScriptFileTypeA, B, etc. is given a chance to define its own clause.
-
setMimetype
public void setMimetype(ome.model.core.OriginalFile ofile)
-
findByMimetype
protected java.util.Map.Entry<java.lang.String,ScriptFileType> findByMimetype(java.lang.String mimetype)
Search through allScriptFileTypeinstances and find one with a matching mimetype string. Otherwise, return null.
-
getLauncher
public java.lang.String getLauncher(java.lang.String mimetype)
Find an "omero.launcher..." property string for the given mimetype or return "" if none is found.
-
getProcess
public java.lang.String getProcess(java.lang.String mimetype)
Find an "omero.process..." property string for the given mimetype or return "" if none is found.
-
getDefaultScriptDir
public static java.lang.String getDefaultScriptDir()
Directory which will be used as the root of this repository if no directory is passed to a constructor. Equivalent to "lib/scripts" from the current directory.
-
getScriptDir
public java.lang.String getScriptDir()
Returns the actual root of this repository.- See Also:
getDefaultScriptDir()
-
getUuid
public java.lang.String getUuid()
Uuid of this repository. In the normal case, this will equalSCRIPT_REPO.
-
countOnDisk
public int countOnDisk()
-
countInDb
public int countInDb()
-
countInDb
public int countInDb(ome.util.SqlAction sql)
-
idsInDb
public java.util.List<java.lang.Long> idsInDb()
-
idsInDb
public java.util.List<java.lang.Long> idsInDb(ome.util.SqlAction sql)
-
isInRepo
public boolean isInRepo(long id)
-
isInRepo
public boolean isInRepo(ome.util.SqlAction sql, long id)
-
findInDb
public java.lang.Long findInDb(java.lang.String path, boolean scriptsOnly)
-
findInDb
public java.lang.Long findInDb(RepoFile file, boolean scriptsOnly)
-
findInDb
public java.lang.Long findInDb(ome.util.SqlAction sql, RepoFile repoFile, boolean scriptsOnly)Looks to see if a path is contained in the repository.
-
iterate
public java.util.Iterator<java.io.File> iterate()
-
loadAll
public java.util.List<ome.model.core.OriginalFile> loadAll(boolean modificationCheck, java.lang.String mimetype)Walks all files in the repository (viaiterate()and adds them if not found in the database. If modificationCheck is true, then a change in the hash for a file in the repository will cause the old file to be removed from the repository(uuid == null)
and a new file created in its place.- Parameters:
modificationCheck-mimetype- the mimetype of the scripts ornull.- Returns:
- See above.
-
loadAll
public java.util.List<ome.model.core.OriginalFile> loadAll(boolean modificationCheck, java.lang.String mimetype, ome.system.Principal pp)
-
loadAll
public java.util.List<ome.model.core.OriginalFile> loadAll(boolean modificationCheck)
Walks all files in the repository (viaiterate()and adds them if not found in the database. If modificationCheck is true, then a change in the hash for a file in the repository will cause the old file to be removed from the repository(uuid == null)
and a new file created in its place.- Parameters:
modificationCheck-- Returns:
- See above.
-
addOrReplace
public ome.model.core.OriginalFile addOrReplace(RepoFile repoFile, java.lang.Long old)
- Parameters:
repoFile-old-- Returns:
- See above.
-
addOrReplace
protected ome.model.core.OriginalFile addOrReplace(org.hibernate.Session session, ome.util.SqlAction sqlAction, ome.system.ServiceFactory sf, RepoFile repoFile, java.lang.Long old)
-
removeMissingFilesFromDb
public long removeMissingFilesFromDb(ome.util.SqlAction sqlAction, org.hibernate.Session session, java.util.List<ome.model.core.OriginalFile> filesOnDisk)Given the current files on disk,unregister(Long, SqlAction)all files which have been removed from disk.
-
unregister
protected void unregister(java.lang.Long old, ome.util.SqlAction sqlAction)Unregisters a given file from the script repository by setting its Repo uuid to null.
-
update
public ome.model.core.OriginalFile update(RepoFile repoFile, java.lang.Long id, java.util.Map<java.lang.String,java.lang.String> context)
-
read
public java.lang.String read(java.lang.String path) throws java.io.IOException- Throws:
java.io.IOException
-
write
public RepoFile write(java.lang.String path, java.lang.String text) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public RepoFile write(RepoFile repo, java.lang.String text) throws java.io.IOException
- Throws:
java.io.IOException
-
load
public ome.model.core.OriginalFile load(long id, boolean check)
-
load
public ome.model.core.OriginalFile load(long id, org.hibernate.Session s, ome.util.SqlAction sqlAction, boolean check)
-
modificationCheck
public void modificationCheck()
Checks if
-
delete
public boolean delete(long id)
-
simpleDelete
public void simpleDelete(java.util.Map<java.lang.String,java.lang.String> context, Executor executor, ome.system.Principal p, long id)Unlikedelete(long)this method simply performs the DB delete on the given original file id.- Parameters:
context- Call context which affects which group the current user is in. Can be null to pass no call context.executor-p-id- Id of theOriginalFileto delete.
-
isInert
public boolean isInert(ome.model.core.OriginalFile f)
Returnstrueif the file is an "inert" file e.g. a lut,falseotherwise.- Parameters:
f- The file to handle.- Returns:
- See above.
-
-