Class BackofficeModulesManager


  • public class BackofficeModulesManager
    extends java.lang.Object
    A tooling class capable of finding and reading module's libraries and holding information about them.
    • Constructor Summary

      Constructors 
      Constructor Description
      BackofficeModulesManager​(com.hybris.cockpitng.core.modules.LibraryFetcher libraryFetcher, com.hybris.cockpitng.modules.ModulesEnumeration modules)  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      protected void assureCorrectExistingModulesStructure()
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 1808, introduce only to ease upgrade process - remove all occurrences when removed
      protected void fetchModules​(java.io.File libdir, java.util.Properties libsURLs)  
      java.io.File getDataRootDir()
      Gets a root directory for data files
      protected java.util.function.Function<java.lang.String,​java.lang.String>[] getDirProcessors()  
      protected com.hybris.cockpitng.core.modules.LibraryFetcher getLibraryFetcher()  
      protected java.net.URI getManuallyRegisteredModuleUrl​(java.lang.String moduleName)  
      java.util.Optional<com.hybris.cockpitng.core.modules.ModuleInfo> getModuleInfo​(java.io.File moduleLibFile)
      Gets information about a specified module that is stored in specified library
      java.util.Optional<com.hybris.cockpitng.core.modules.ModuleInfo> getModuleInfo​(java.lang.String moduleName)
      Gets information about a specified module.
      java.io.File getModuleJarsRootDir()
      Gets a root directory, where module's libraries are kept.
      java.util.Optional<java.io.File> getModuleLib​(java.lang.String moduleName)
      Gets specified module's library.
      protected java.lang.String getModuleLibFileName​(java.lang.String moduleName)  
      java.util.Optional<java.lang.String> getModuleName​(java.io.File moduleLibFile)
      Gets name of module that is stored in specified library
      java.util.Optional<java.lang.String> getModuleName​(java.net.URI moduleURI)
      Provides a name of module that origines from provided URI
      protected <R> java.util.Optional<R> getModulePath​(java.io.File moduleLib, java.util.Properties moduleLibsURLS, java.util.function.Function<java.lang.String,​R> pathConverter)  
      protected <R> java.util.Optional<R> getModulePath​(java.lang.String moduleName, java.util.Properties moduleLibsURLS, java.util.function.Function<java.lang.String,​R> pathConverter)  
      java.util.List<java.lang.String> getModules()
      Provides a list of attached backoffice modules.
      protected com.hybris.cockpitng.modules.ModulesEnumeration getModulesEnumeration()  
      java.util.Optional<java.net.URI> getModuleSource​(java.io.File moduleLib)
      Gets the origin URI of module that is stored in specified library
      java.util.Optional<java.net.URI> getModuleSource​(java.lang.String moduleName)
      Gets the origin URI of specified module
      protected java.io.File getRootDir​(java.lang.String configuredRootDir, java.util.function.Function<java.lang.String,​java.lang.String>... processors)  
      protected boolean isModuleFetched​(java.io.File moduleLibFile)  
      boolean isModuleRegistered​(java.lang.String moduleName)
      Checks if specified module is registered.
      protected java.util.Properties loadModuleLibsURLS​(java.io.File libRoot)
      Loads information about libraries mapping: library -> module URL
      protected java.lang.String processDir​(java.lang.String dir, java.util.function.Function<java.lang.String,​java.lang.String>... processors)  
      protected boolean qualifiesForRemoval​(java.io.File moduleLibFile, java.util.Properties moduleLibsURLs)  
      protected boolean qualifiesForUnregistering​(java.io.File moduleLibFile, java.util.Properties moduleLibsURLs)  
      void refreshAndFetch()
      Reloads all informations about registered backoffice modules.
      protected void registerExistingModules​(java.util.Properties libsURLs)  
      protected void registerNewModuleImmediately​(com.hybris.cockpitng.core.modules.ModuleInfo moduleInfo, java.net.URI source)  
      java.io.File registerNewModuleJar​(java.lang.String moduleName)
      Creates and attaches new module library
      protected void registerNewModuleJarImmediately​(java.lang.String moduleName, java.io.File moduleLibFile, java.net.URI source, java.util.Properties moduleLibsURLs)  
      protected void removeModuleJarImmediately​(java.lang.String moduleName, java.io.File moduleLibFile, java.util.Properties moduleLibsURLs)  
      protected void storeModuleLibsURLS​(java.util.Properties props, java.io.File libRoot)  
      void unregisterModuleJar​(java.lang.String moduleName)
      Detaches previously attached module
      protected void unregisterModuleJar​(java.lang.String moduleName, java.io.File moduleLibFile)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BackofficeModulesManager

        public BackofficeModulesManager​(com.hybris.cockpitng.core.modules.LibraryFetcher libraryFetcher,
                                        com.hybris.cockpitng.modules.ModulesEnumeration modules)
    • Method Detail

      • refreshAndFetch

        public void refreshAndFetch()
                             throws com.hybris.cockpitng.core.CockpitApplicationException
        Reloads all informations about registered backoffice modules.

        All currently loaded modules are detached, newly initialized, modules libraries are being recreated and modules reattached.

        Throws:
        com.hybris.cockpitng.core.CockpitApplicationException - throws if modules could not be reattached or libraries could not be recreated
      • isModuleRegistered

        public boolean isModuleRegistered​(java.lang.String moduleName)
        Checks if specified module is registered.
        Parameters:
        moduleName - name of module
        Returns:
        true if module with specified name is already registered
      • getModules

        public java.util.List<java.lang.String> getModules()
        Provides a list of attached backoffice modules. Returned list contains both fetched modules and manually registered.
        Returns:
        list of modules names
        See Also:
        registerNewModuleJar(String)
      • getModuleName

        public java.util.Optional<java.lang.String> getModuleName​(java.net.URI moduleURI)
        Provides a name of module that origines from provided URI
        Parameters:
        moduleURI - module origin
        Returns:
        name of module originated from specified URI
      • getModuleLib

        public java.util.Optional<java.io.File> getModuleLib​(java.lang.String moduleName)
        Gets specified module's library.
        Parameters:
        moduleName - name of module
        Returns:
        library of a module
      • getModuleSource

        public java.util.Optional<java.net.URI> getModuleSource​(java.lang.String moduleName)
        Gets the origin URI of specified module
        Parameters:
        moduleName - name of module
        Returns:
        origin URI of module
      • getModuleSource

        public java.util.Optional<java.net.URI> getModuleSource​(java.io.File moduleLib)
        Gets the origin URI of module that is stored in specified library
        Parameters:
        moduleLib - module's library
        Returns:
        origin URI of module
      • getModuleInfo

        public java.util.Optional<com.hybris.cockpitng.core.modules.ModuleInfo> getModuleInfo​(java.lang.String moduleName)
        Gets information about a specified module.

        Please bear in mind that manager cannot provide module information about manually registerd modules. In this case Optional.empty() is returned.

        Parameters:
        moduleName - name of module
        Returns:
        information about module
        See Also:
        registerNewModuleJar(String)
      • getModuleInfo

        public java.util.Optional<com.hybris.cockpitng.core.modules.ModuleInfo> getModuleInfo​(java.io.File moduleLibFile)
        Gets information about a specified module that is stored in specified library
        Parameters:
        moduleLibFile - module's library
        Returns:
        information about module
      • getModuleName

        public java.util.Optional<java.lang.String> getModuleName​(java.io.File moduleLibFile)
        Gets name of module that is stored in specified library
        Parameters:
        moduleLibFile - module's library
        Returns:
        module name
      • getDataRootDir

        public java.io.File getDataRootDir()
        Gets a root directory for data files
        Returns:
        data root directory
      • getModuleJarsRootDir

        public java.io.File getModuleJarsRootDir()
        Gets a root directory, where module's libraries are kept.
        Returns:
        module's libraries directory
      • registerNewModuleJar

        public java.io.File registerNewModuleJar​(java.lang.String moduleName)
                                          throws java.io.IOException,
                                                 com.hybris.cockpitng.core.CockpitApplicationException
        Creates and attaches new module library
        Parameters:
        moduleName - name of module
        Returns:
        module's library
        Throws:
        java.io.IOException - thrown is a library could not be created (i.e. file already exists)
        com.hybris.cockpitng.core.CockpitApplicationException - thrown if a library for this module is already attached
      • registerNewModuleJarImmediately

        protected void registerNewModuleJarImmediately​(java.lang.String moduleName,
                                                       java.io.File moduleLibFile,
                                                       java.net.URI source,
                                                       java.util.Properties moduleLibsURLs)
                                                throws com.hybris.cockpitng.core.CockpitApplicationException
        Throws:
        com.hybris.cockpitng.core.CockpitApplicationException
      • unregisterModuleJar

        public void unregisterModuleJar​(java.lang.String moduleName)
                                 throws java.io.IOException,
                                        com.hybris.cockpitng.core.CockpitApplicationException
        Detaches previously attached module
        Parameters:
        moduleName - module name
        Throws:
        java.io.IOException - thrown if library could not be deleted
        com.hybris.cockpitng.core.CockpitApplicationException - thrown if module cannot be detached (i.e. is a built in module)
      • unregisterModuleJar

        protected void unregisterModuleJar​(java.lang.String moduleName,
                                           java.io.File moduleLibFile)
                                    throws java.io.IOException,
                                           com.hybris.cockpitng.core.CockpitApplicationException
        Throws:
        java.io.IOException
        com.hybris.cockpitng.core.CockpitApplicationException
      • removeModuleJarImmediately

        protected void removeModuleJarImmediately​(java.lang.String moduleName,
                                                  java.io.File moduleLibFile,
                                                  java.util.Properties moduleLibsURLs)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • qualifiesForUnregistering

        protected boolean qualifiesForUnregistering​(java.io.File moduleLibFile,
                                                    java.util.Properties moduleLibsURLs)
      • qualifiesForRemoval

        protected boolean qualifiesForRemoval​(java.io.File moduleLibFile,
                                              java.util.Properties moduleLibsURLs)
      • getModulePath

        protected <R> java.util.Optional<R> getModulePath​(java.lang.String moduleName,
                                                          java.util.Properties moduleLibsURLS,
                                                          java.util.function.Function<java.lang.String,​R> pathConverter)
      • getModulePath

        protected <R> java.util.Optional<R> getModulePath​(java.io.File moduleLib,
                                                          java.util.Properties moduleLibsURLS,
                                                          java.util.function.Function<java.lang.String,​R> pathConverter)
      • getLibraryFetcher

        protected com.hybris.cockpitng.core.modules.LibraryFetcher getLibraryFetcher()
      • getModulesEnumeration

        protected com.hybris.cockpitng.modules.ModulesEnumeration getModulesEnumeration()
      • getDirProcessors

        protected java.util.function.Function<java.lang.String,​java.lang.String>[] getDirProcessors()
      • getRootDir

        protected java.io.File getRootDir​(java.lang.String configuredRootDir,
                                          java.util.function.Function<java.lang.String,​java.lang.String>... processors)
      • processDir

        protected java.lang.String processDir​(java.lang.String dir,
                                              java.util.function.Function<java.lang.String,​java.lang.String>... processors)
      • loadModuleLibsURLS

        protected java.util.Properties loadModuleLibsURLS​(java.io.File libRoot)
        Loads information about libraries mapping: library -> module URL
        Parameters:
        libRoot - root directory for local modules libraries
        Returns:
        map <library path ; module URL>
      • registerExistingModules

        protected void registerExistingModules​(java.util.Properties libsURLs)
      • isModuleFetched

        protected boolean isModuleFetched​(java.io.File moduleLibFile)
      • assureCorrectExistingModulesStructure

        @Deprecated(since="1808",
                    forRemoval=true)
        protected void assureCorrectExistingModulesStructure()
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 1808, introduce only to ease upgrade process - remove all occurrences when removed
      • fetchModules

        protected void fetchModules​(java.io.File libdir,
                                    java.util.Properties libsURLs)
      • getModuleLibFileName

        protected java.lang.String getModuleLibFileName​(java.lang.String moduleName)
      • storeModuleLibsURLS

        protected void storeModuleLibsURLS​(java.util.Properties props,
                                           java.io.File libRoot)
      • registerNewModuleImmediately

        protected void registerNewModuleImmediately​(com.hybris.cockpitng.core.modules.ModuleInfo moduleInfo,
                                                    java.net.URI source)
      • getManuallyRegisteredModuleUrl

        protected java.net.URI getManuallyRegisteredModuleUrl​(java.lang.String moduleName)