public class ScriptRepoHelper extends OnContextRefreshedEventListener
Modifier and Type | Field and Description |
---|---|
static org.apache.commons.io.filefilter.IOFileFilter |
BASE_SCRIPT_FILTER
IOFileFilter instance used during iterate() to find the
matching scripts in the given directory. |
protected org.slf4j.Logger |
log |
static String |
SCRIPT_REPO
Id used by all script repositories.
|
Constructor and Description |
---|
ScriptRepoHelper(Executor ex,
String sessionUuid,
Roles roles) |
ScriptRepoHelper(File dir,
Executor ex,
Principal p,
Roles roles) |
ScriptRepoHelper(String uuid,
File dir,
Executor ex,
Principal p,
Roles roles) |
Modifier and Type | Method and Description |
---|---|
OriginalFile |
addOrReplace(RepoFile repoFile,
Long old) |
protected OriginalFile |
addOrReplace(org.hibernate.Session session,
SqlAction sqlAction,
ServiceFactory sf,
RepoFile repoFile,
Long old) |
void |
buildQuery(QueryBuilder qb)
Adds a single clause of the form "AND (A OR B ...)" where each
ScriptFileType A, B, etc. is given a chance to define
its own clause. |
int |
countInDb() |
int |
countInDb(SqlAction sql) |
int |
countOnDisk()
Returns the number of files which match
scriptFilter in
dir . |
boolean |
delete(long id) |
protected Map.Entry<String,ScriptFileType> |
findByMimetype(String mimetype)
Search through all
ScriptFileType instances and find one with
a matching mimetype string. |
Long |
findInDb(RepoFile file,
boolean scriptsOnly) |
Long |
findInDb(SqlAction sql,
RepoFile repoFile,
boolean scriptsOnly)
Looks to see if a path is contained in the repository.
|
Long |
findInDb(String path,
boolean scriptsOnly) |
static String |
getDefaultScriptDir()
Directory which will be used as the root of this repository if no
directory is passed to a constructor.
|
String |
getLauncher(String mimetype)
Find an "omero.launcher..." property string for the given mimetype or
return "" if none is found.
|
String |
getProcess(String mimetype)
Find an "omero.process..." property string for the given mimetype or
return "" if none is found.
|
String |
getScriptDir()
Returns the actual root of this repository.
|
String |
getUuid()
Uuid of this repository.
|
void |
handleContextRefreshedEvent(ContextRefreshedEvent event)
Loads all
ScriptFileType instances from the context,
and uses them to initialize all scripts in the repo. |
List<Long> |
idsInDb() |
List<Long> |
idsInDb(SqlAction sql) |
boolean |
isInert(OriginalFile f)
Returns
true if the file is an "inert" file e.g. a lut,
false otherwise. |
boolean |
isInRepo(long id) |
boolean |
isInRepo(SqlAction sql,
long id) |
Iterator<File> |
iterate() |
OriginalFile |
load(long id,
boolean check) |
OriginalFile |
load(long id,
org.hibernate.Session s,
SqlAction sqlAction,
boolean check) |
List<OriginalFile> |
loadAll(boolean modificationCheck)
Walks all files in the repository (via
iterate() and adds them
if not found in the database. |
List<OriginalFile> |
loadAll(boolean modificationCheck,
String mimetype)
Walks all files in the repository (via
iterate() and adds them
if not found in the database. |
List<OriginalFile> |
loadAll(boolean modificationCheck,
String mimetype,
Principal pp) |
void |
modificationCheck()
Checks if
|
String |
read(String path) |
long |
removeMissingFilesFromDb(SqlAction sqlAction,
org.hibernate.Session session,
List<OriginalFile> filesOnDisk)
Given the current files on disk,
unregister(Long, SqlAction)
all files which have been removed from disk. |
void |
setMimetype(OriginalFile ofile) |
void |
simpleDelete(Map<String,String> context,
Executor executor,
Principal p,
long id)
Unlike
delete(long) this method simply performs the DB delete
on the given original file id. |
protected void |
unregister(Long old,
SqlAction sqlAction)
Unregisters a given file from the script repository by setting its
Repo uuid to null.
|
OriginalFile |
update(RepoFile repoFile,
Long id,
Map<String,String> context) |
RepoFile |
write(RepoFile repo,
String text) |
RepoFile |
write(String path,
String text) |
onApplicationEvent, setApplicationContext
public static final String SCRIPT_REPO
public static final org.apache.commons.io.filefilter.IOFileFilter BASE_SCRIPT_FILTER
IOFileFilter
instance used during iterate()
to find the
matching scripts in the given directory.protected final org.slf4j.Logger log
public ScriptRepoHelper(String uuid, File dir, Executor ex, Principal p, Roles roles)
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
use getDefaultScriptDir()
internally.ex
- p
- public void handleContextRefreshedEvent(ContextRefreshedEvent event)
ScriptFileType
instances from the context,
and uses them to initialize all scripts in the repo.handleContextRefreshedEvent
in class OnContextRefreshedEventListener
public void buildQuery(QueryBuilder qb)
ScriptFileType
A, B, etc. is given a chance to define
its own clause.public void setMimetype(OriginalFile ofile)
protected Map.Entry<String,ScriptFileType> findByMimetype(String mimetype)
ScriptFileType
instances and find one with
a matching mimetype string. Otherwise, return null.public String getLauncher(String mimetype)
public String getProcess(String mimetype)
public static String getDefaultScriptDir()
public String getScriptDir()
getDefaultScriptDir()
public String getUuid()
SCRIPT_REPO
.public int countOnDisk()
public int countInDb()
public int countInDb(SqlAction sql)
public boolean isInRepo(long id)
public boolean isInRepo(SqlAction sql, long id)
public Long findInDb(SqlAction sql, RepoFile repoFile, boolean scriptsOnly)
public List<OriginalFile> loadAll(boolean modificationCheck, String mimetype)
iterate()
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.
modificationCheck
- mimetype
- the mimetype of the scripts or null
.public List<OriginalFile> loadAll(boolean modificationCheck, String mimetype, Principal pp)
public List<OriginalFile> loadAll(boolean modificationCheck)
iterate()
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.
modificationCheck
- public OriginalFile addOrReplace(RepoFile repoFile, Long old)
repoFile
- old
- protected OriginalFile addOrReplace(org.hibernate.Session session, SqlAction sqlAction, ServiceFactory sf, RepoFile repoFile, Long old)
public long removeMissingFilesFromDb(SqlAction sqlAction, org.hibernate.Session session, List<OriginalFile> filesOnDisk)
unregister(Long, SqlAction)
all files which have been removed from disk.protected void unregister(Long old, SqlAction sqlAction)
public String read(String path) throws IOException
IOException
public RepoFile write(String path, String text) throws IOException
IOException
public RepoFile write(RepoFile repo, String text) throws IOException
IOException
public OriginalFile load(long id, boolean check)
public OriginalFile load(long id, org.hibernate.Session s, SqlAction sqlAction, boolean check)
public void modificationCheck()
public boolean delete(long id)
public void simpleDelete(Map<String,String> context, Executor executor, Principal p, long id)
delete(long)
this method simply performs the DB delete
on the given original file id.context
- Call context which affecets which group the current user is in.
Can be null to pass no call context.executor
- p
- id
- Id of the OriginalFile
to delete.public boolean isInert(OriginalFile f)
true
if the file is an "inert" file e.g. a lut,
false
otherwise.f
- The file to handle.
Version: 5.3.3-ice35-b63
Copyright © 2017 The University of Dundee & Open Microscopy Environment. All Rights Reserved.