ome.services.scripts
Class ScriptRepoHelper

java.lang.Object
  extended by ome.services.scripts.ScriptRepoHelper

public class ScriptRepoHelper
extends Object

Strategy used by the ScriptRepository for registering, loading, and saving files.

Since:
Beta4.2

Field Summary
protected  org.apache.commons.logging.Log log
           
static org.apache.commons.io.filefilter.IOFileFilter SCRIPT_FILTER
          IOFileFilter instance used during iterate() to find the matching scripts in the given directory.
static String SCRIPT_REPO
          Id used by all script repositories.
 
Constructor Summary
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)
           
 
Method Summary
 ome.model.core.OriginalFile addOrReplace(RepoFile repoFile, Long old)
           
protected  ome.model.core.OriginalFile addOrReplace(org.hibernate.Session session, ServiceFactory sf, RepoFile repoFile, Long old)
           
 int countInDb()
           
 int countInDb(org.springframework.jdbc.core.simple.SimpleJdbcOperations jdbc)
           
 int countOnDisk()
          Returns the number of files which match SCRIPT_FILTER in dir.
 boolean delete(long id)
           
 Long findInDb(RepoFile file, boolean scriptsOnly)
           
 Long findInDb(org.springframework.jdbc.core.simple.SimpleJdbcOperations jdbc, 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 getScriptDir()
          Returns the actual root of this repository.
 String getUuid()
          Uuid of this repository.
 List<Long> idsInDb()
           
 List<Long> idsInDb(org.springframework.jdbc.core.simple.SimpleJdbcOperations jdbc)
           
 boolean isInRepo(long id)
           
 boolean isInRepo(org.springframework.jdbc.core.simple.SimpleJdbcOperations jdbc, long id)
           
 Iterator<File> iterate()
           
 ome.model.core.OriginalFile load(long id, boolean check)
           
 ome.model.core.OriginalFile load(long id, org.hibernate.Session s, boolean check)
           
 List<ome.model.core.OriginalFile> loadAll(boolean modificationCheck)
          Walks all files in the repository (via iterate() and adds them if not found in the database.
 void modificationCheck()
          Checks if
 String read(String path)
           
 long removeMissingFilesFromDb(org.springframework.jdbc.core.simple.SimpleJdbcOperations jdbc, org.hibernate.Session session, List<ome.model.core.OriginalFile> filesOnDisk)
          Given the current files on disk, unregister(Long, Session) all files which have been removed from disk.
protected  void unregister(Long old, org.hibernate.Session session)
          Unregisters a given file from the script repository by setting its Repo uuid to null.
 ome.model.core.OriginalFile update(RepoFile repoFile, Long id)
           
 RepoFile write(RepoFile repo, String text)
           
 RepoFile write(String path, String text)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCRIPT_REPO

public static final 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

SCRIPT_FILTER

public static final org.apache.commons.io.filefilter.IOFileFilter SCRIPT_FILTER
IOFileFilter instance used during iterate() to find the matching scripts in the given directory.


log

protected final org.apache.commons.logging.Log log
Constructor Detail

ScriptRepoHelper

public ScriptRepoHelper(Executor ex,
                        String sessionUuid,
                        Roles roles)
See Also:
#ScriptRepoHelper(String, File, Executor, Principal)

ScriptRepoHelper

public ScriptRepoHelper(File dir,
                        Executor ex,
                        Principal p,
                        Roles roles)
See Also:
#ScriptRepoHelper(String, File, Executor, Principal)

ScriptRepoHelper

public ScriptRepoHelper(String uuid,
                        File dir,
                        Executor ex,
                        Principal p,
                        Roles roles)
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 use getDefaultScriptDir() internally.
ex -
p -
Method Detail

getDefaultScriptDir

public static 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 String getScriptDir()
Returns the actual root of this repository.

See Also:
getDefaultScriptDir()

getUuid

public String getUuid()
Uuid of this repository. In the normal case, this will equal SCRIPT_REPO.


countOnDisk

public int countOnDisk()
Returns the number of files which match SCRIPT_FILTER in dir. Uses iterate() internally.


countInDb

public int countInDb()

countInDb

public int countInDb(org.springframework.jdbc.core.simple.SimpleJdbcOperations jdbc)

idsInDb

public List<Long> idsInDb()

idsInDb

public List<Long> idsInDb(org.springframework.jdbc.core.simple.SimpleJdbcOperations jdbc)

isInRepo

public boolean isInRepo(long id)

isInRepo

public boolean isInRepo(org.springframework.jdbc.core.simple.SimpleJdbcOperations jdbc,
                        long id)

findInDb

public Long findInDb(String path,
                     boolean scriptsOnly)

findInDb

public Long findInDb(RepoFile file,
                     boolean scriptsOnly)

findInDb

public Long findInDb(org.springframework.jdbc.core.simple.SimpleJdbcOperations jdbc,
                     RepoFile repoFile,
                     boolean scriptsOnly)
Looks to see if a path is contained in the repository.


iterate

public Iterator<File> iterate()

loadAll

public List<ome.model.core.OriginalFile> loadAll(boolean modificationCheck)
Walks all files in the repository (via iterate() and adds them if not found in the database. If modificationCheck is true, then a change in the sha1 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:

addOrReplace

public ome.model.core.OriginalFile addOrReplace(RepoFile repoFile,
                                                Long old)
Parameters:
repoFile -
old -
Returns:

addOrReplace

protected ome.model.core.OriginalFile addOrReplace(org.hibernate.Session session,
                                                   ServiceFactory sf,
                                                   RepoFile repoFile,
                                                   Long old)

removeMissingFilesFromDb

public long removeMissingFilesFromDb(org.springframework.jdbc.core.simple.SimpleJdbcOperations jdbc,
                                     org.hibernate.Session session,
                                     List<ome.model.core.OriginalFile> filesOnDisk)
Given the current files on disk, unregister(Long, Session) all files which have been removed from disk.


unregister

protected void unregister(Long old,
                          org.hibernate.Session session)
Unregisters a given file from the script repository by setting its Repo uuid to null.


update

public ome.model.core.OriginalFile update(RepoFile repoFile,
                                          Long id)

read

public String read(String path)
            throws IOException
Throws:
IOException

write

public RepoFile write(String path,
                      String text)
               throws IOException
Throws:
IOException

write

public RepoFile write(RepoFile repo,
                      String text)
               throws IOException
Throws:
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,
                                        boolean check)

modificationCheck

public void modificationCheck()
Checks if


delete

public boolean delete(long id)


OmeroJava Api

Version: Beta4.2.1-r8614-Beta4.2-b41

Copyright © 2009 The University of Dundee. All Rights Reserved.