Class 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.IOFileFilter BASE_SCRIPT_FILTER
      IOFileFilter instance used during iterate() to find the matching scripts in the given directory.
      protected org.slf4j.Logger log  
      static java.lang.String SCRIPT_REPO
      Id 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.OriginalFile addOrReplace​(RepoFile repoFile, java.lang.Long old)  
      protected ome.model.core.OriginalFile addOrReplace​(org.hibernate.Session session, ome.util.SqlAction sqlAction, ome.system.ServiceFactory sf, RepoFile repoFile, java.lang.Long old)  
      void buildQuery​(QueryBuilder qb)
      Adds a single clause of the form "AND (A OR B ...)" where each ScriptFileType A, B, etc.
      void checkForScriptUpdates()
      Check for updates to scripts, modifying database accordingly.
      int countInDb()  
      int countInDb​(ome.util.SqlAction sql)  
      int countOnDisk()
      Returns the number of files which match scriptFilter in dir.
      boolean delete​(long id)  
      protected java.util.Map.Entry<java.lang.String,​ScriptFileType> findByMimetype​(java.lang.String mimetype)
      Search through all ScriptFileType instances and find one with a matching mimetype string.
      java.lang.Long findInDb​(java.lang.String path, boolean scriptsOnly)  
      java.lang.Long findInDb​(RepoFile file, boolean scriptsOnly)  
      java.lang.Long findInDb​(ome.util.SqlAction sql, RepoFile repoFile, boolean scriptsOnly)
      Looks to see if a path is contained in the repository.
      static java.lang.String getDefaultScriptDir()
      Directory which will be used as the root of this repository if no directory is passed to a constructor.
      java.lang.String getLauncher​(java.lang.String mimetype)
      Find an "omero.launcher..." property string for the given mimetype or return "" if none is found.
      java.lang.String getProcess​(java.lang.String mimetype)
      Find an "omero.process..." property string for the given mimetype or return "" if none is found.
      java.lang.String getScriptDir()
      Returns the actual root of this repository.
      java.lang.String getUuid()
      Uuid of this repository.
      void handleContextRefreshedEvent​(org.springframework.context.event.ContextRefreshedEvent event)
      Loads all ScriptFileType instances 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)  
      boolean isInert​(ome.model.core.OriginalFile f)
      Returns true if the file is an "inert" file e.g.
      boolean isInRepo​(long id)  
      boolean isInRepo​(ome.util.SqlAction sql, long id)  
      java.util.Iterator<java.io.File> iterate()  
      ome.model.core.OriginalFile load​(long id, boolean check)  
      ome.model.core.OriginalFile load​(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 (via iterate() 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 (via iterate() 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)  
      void modificationCheck()
      Checks if
      java.lang.String read​(java.lang.String path)  
      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.
      void setMimetype​(ome.model.core.OriginalFile ofile)  
      void simpleDelete​(java.util.Map<java.lang.String,​java.lang.String> context, Executor executor, ome.system.Principal p, long id)
      Unlike delete(long) this method simply performs the DB delete on the given original file id.
      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.
      ome.model.core.OriginalFile update​(RepoFile repoFile, java.lang.Long id, java.util.Map<java.lang.String,​java.lang.String> context)  
      RepoFile write​(java.lang.String path, java.lang.String text)  
      RepoFile write​(RepoFile repo, java.lang.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 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
        IOFileFilter instance used during iterate() to find the matching scripts in the given directory.
      • log

        protected final org.slf4j.Logger log
    • Method Detail

      • 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 each ScriptFileType A, 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 all ScriptFileType instances 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 equal SCRIPT_REPO.
      • countOnDisk

        public int countOnDisk()
        Returns the number of files which match scriptFilter in dir. Uses iterate() internally.
      • 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 (via 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.
        Parameters:
        modificationCheck -
        mimetype - the mimetype of the scripts or null.
        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 (via 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.
        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)
        Unlike delete(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 the OriginalFile to delete.
      • isInert

        public boolean isInert​(ome.model.core.OriginalFile f)
        Returns true if the file is an "inert" file e.g. a lut, false otherwise.
        Parameters:
        f - The file to handle.
        Returns:
        See above.