Class DefaultCockpitConfigurationService

    • Field Detail

      • CHARSET_NAME

        public static final java.lang.String CHARSET_NAME
      • obligatoryMergeAttributes

        protected java.util.List<java.lang.String> obligatoryMergeAttributes
    • Constructor Detail

      • DefaultCockpitConfigurationService

        public DefaultCockpitConfigurationService()
    • Method Detail

      • convertAttributes

        public static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> convertAttributes​(java.util.Map<java.lang.String,​java.lang.String> attributesNeedle)
        Converts flat single attributes needle into multiple search needle compatible with ContextSearchRequest
        Parameters:
        attributesNeedle - single search needle
        Returns:
        a needle compatible with ContextSearchRequest
      • setObligatoryMergeAttributes

        public void setObligatoryMergeAttributes​(java.util.List<java.lang.String> obligatoryMergeAttributes)
        specify obligatory merge-by attribute names. If configuration should be merged (has merge-by attribute) it will be also merged by attributes specified by this property.
      • setObligatoryMergeAttributesImmediately

        protected void setObligatoryMergeAttributesImmediately​(java.util.List<java.lang.String> obligatoryMergeAttributes)
      • buildConfigurationContext

        protected <CONFIG> ConfigContext buildConfigurationContext​(ConfigContext additionalContext,
                                                                   java.lang.Class<CONFIG> configurationType,
                                                                   WidgetInstance currentWidgetInstance)
      • loadConfiguration

        public <C> C loadConfiguration​(ConfigContext context,
                                       java.lang.Class<C> configType,
                                       WidgetInstance currentWidgetInstance)
                                throws CockpitConfigurationException
        Description copied from interface: CockpitConfigurationService
        Loads a single piece of cockpit configuration according to context provided for specific widgetInstance
        Specified by:
        loadConfiguration in interface CockpitConfigurationService
        Parameters:
        context - the context to be used to look for the configuration
        configType - desired configuration type
        currentWidgetInstance - given widget instance
        Returns:
        single piece of cockpit configuration according to context provided
        Throws:
        CockpitConfigurationException - if configuration could not be found or some error occured during loading
      • isRootConfigurationCacheValid

        protected boolean isRootConfigurationCacheValid()
        Checks whether current root configuration cache is valid.
        Returns:
        true if of any reason, cache needs to be reloaded
      • cacheMustBeInvalidated

        @Deprecated(since="1811",
                    forRemoval=true)
        protected boolean cacheMustBeInvalidated()
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 1811, unused
        Configuration cache must be invalidated if this returns true.
        Returns:
        returns true if the configuration cache must be invalidated
      • getConfigFromCache

        protected <C> C getConfigFromCache​(ConfigContext context,
                                           java.lang.Class<C> configType)
        Get configuration from cache
        Parameters:
        context -
        configType -
      • getConfigFromCacheImmediately

        protected <C> C getConfigFromCacheImmediately​(ConfigContext context,
                                                      java.lang.Class<C> configType)
      • putConfigToCache

        protected <C> void putConfigToCache​(ConfigContext context,
                                            java.lang.Class<C> configType,
                                            C config)
        Put configuration to cache.
        Parameters:
        context -
        configType -
        config -
      • putConfigToCacheImmediately

        protected <C> void putConfigToCacheImmediately​(ConfigContext context,
                                                       java.lang.Class<C> configType,
                                                       C config)
      • loadConfiguration

        public <C> C loadConfiguration​(ConfigContext context,
                                       java.lang.Class<C> configType,
                                       java.io.InputStream inputStream)
                                throws CockpitConfigurationException
        Loads configuration of specified type from provided stream
        Type Parameters:
        C - type of configuration
        Parameters:
        context - configuration context matched by configuration to be loaded
        configType - JAXB class representing configuration to be loaded
        inputStream - stream that contains contains configuration xml to be interpreted
        Returns:
        xml from stream parsed to specified configuration class
        Throws:
        CockpitConfigurationException - when read operation fails
      • mergeContexts

        public <C> C mergeContexts​(ConfigContext context,
                                   java.util.List<Context> contextElements,
                                   java.lang.Class<C> configType)
                            throws CockpitConfigurationException
        Merges provided configurations into single JAXB configuration bean.
        Type Parameters:
        C - expected result type
        Parameters:
        context - search context that resulted in provided configuration elements
        contextElements - configuration elements matching provided search context
        configType - expected JAXB configuration bean type
        Returns:
        parsed and merged configuration
        Throws:
        CockpitConfigurationException - thrown when problem with parsing or merging occurred
      • loadRootConfiguration

        public Config loadRootConfiguration​(java.io.InputStream inputStream)
        Loads root configuration
        Parameters:
        inputStream - of configuration
        Returns:
        loaded configuration
      • findContext

        public java.util.List<Context> findContext​(Config configStack,
                                                   java.util.Map<java.lang.String,​java.lang.String> attributesNeedle,
                                                   boolean ignoreEmpty,
                                                   boolean exactMatch)
        Searches for contexts that matches provided attributes list. A context is considered as matching, when contains all provided attributes and their values meets CockpitConfigurationContextStrategy requirements.
        Parameters:
        configStack - configuration root
        attributesNeedle - attributes to meet
        ignoreEmpty - true if empty attributes should be ignored
        exactMatch - true if merge-by should be ignored and only actual attributes of context should be taken under consideration
        Returns:
        list of contexts that meets requirements
        See Also:
        CockpitConfigurationContextStrategy.valueMatches(String, String)
      • findContextImmediately

        protected java.util.List<Context> findContextImmediately​(Config configStack,
                                                                 java.util.Map<java.lang.String,​java.lang.String> attributesNeedle,
                                                                 boolean ignoreEmpty,
                                                                 boolean exactMatch)
      • createContextSearchTerms

        protected ContextSearchTerms createContextSearchTerms​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> resetState,
                                                              java.util.Map<java.lang.String,​java.lang.Integer> resetRelevance,
                                                              ContextSearchRequest request)
      • createSearchRequest

        protected ContextSearchRequest createSearchRequest​(Config configStack,
                                                           java.util.Map<java.lang.String,​java.util.List<java.lang.String>> attributesNeedle)
      • getRelevanceZones

        protected java.util.List<java.lang.String> getRelevanceZones​(ContextSearchRequest request)
      • getContext

        public java.util.Map<java.lang.String,​java.lang.String> getContext​(Context context)
        Retrieves all attributes from context and stores them as map <attribute name, attribute value>
        Parameters:
        context - context to be represented
        Returns:
        map of attributes
      • getContextImmediately

        protected java.util.Map<java.lang.String,​java.lang.String> getContextImmediately​(Context context)
      • setContext

        public void setContext​(Context contextElement,
                               java.util.Map<java.lang.String,​java.lang.String> context)
        Sets context to the context element
        Parameters:
        contextElement - a context element
        context - a map of properties
      • setContextImmediately

        protected void setContextImmediately​(Context contextElement,
                                             java.util.Map<java.lang.String,​java.lang.String> context)
      • getRootDir

        protected java.io.File getRootDir()
      • getConfigAsString

        public java.lang.String getConfigAsString()
        Loads current configuration in form of XML
        Returns:
        configuration XML
      • setConfigAsString

        public void setConfigAsString​(java.lang.String content)
        Stores new configuration
        Parameters:
        content - new configuration in form of XML
      • getConfigAsStringImmediately

        protected java.lang.String getConfigAsStringImmediately()
      • setConfigAsStringImmediately

        protected void setConfigAsStringImmediately​(java.lang.String content)
      • convertConfigToString

        protected java.lang.String convertConfigToString​(java.io.InputStream inputStream)
        Returns string content of the stream.
        Parameters:
        inputStream -
        Returns:
        string content of the stream.
      • resetToDefaults

        public void resetToDefaults()
        Reset cockpit configuration to default. The method looks up configuration file that is defined as a cockpit configuration entry cockpitng.config.default, for example : cockpitng.config.default=/backoffice-web/cockpit-config-default.xml The file path must be relative to resource folder. If cockpitng.config.default is not defined or the file does not exist, a new 'default' configuration will be generated from all default configuration snippets of all widgets present in the system.
        Specified by:
        resetToDefaults in interface CockpitConfigurationService
      • resetToDefaultsInternal

        protected void resetToDefaultsInternal()
      • cacheRootConfiguration

        protected void cacheRootConfiguration​(Config rootConfig,
                                              long cacheTimestamp)
        Caches a root configuration with specified cache time.

        Cache timestamp may determine whether to invalidate cache or not. If at any moment current root configuration origin time is greater then cache timestamp, then cache is invalidated and configuration is loaded again.

        Parameters:
        rootConfig - configuration to be cached
        cacheTimestamp - cache timestamp
      • getConfigFileInputStream

        protected java.io.InputStream getConfigFileInputStream()
      • getConfigFileOutputStream

        protected java.io.OutputStream getConfigFileOutputStream()
      • getLastModification

        protected long getLastModification()
      • invalidateRootConfigurationCache

        protected void invalidateRootConfigurationCache()
        Marks configuration as invalid and force service to load root configuration once again, whenever it is requested.
      • invalidateRootConfigurationCacheImmediately

        protected void invalidateRootConfigurationCacheImmediately()
      • onCacheInvalidation

        public void onCacheInvalidation​(java.lang.Runnable callback)
        Registers callback which is invoked when cache is invalidating.
        Parameters:
        callback - which is invoked when invalidateRootConfigurationCache() is called.
      • invalidateConfigurationCache

        protected void invalidateConfigurationCache()
        Marks context configurations invalid and forces service to load tem once again from root
      • invalidateConfigurationCacheImmediately

        protected void invalidateConfigurationCacheImmediately()
      • invalidateAttributesCache

        protected void invalidateAttributesCache​(Context context)
        Marks context attributes invalid and forces service to load them once again from root
      • invalidateAttributesCacheImmediately

        protected void invalidateAttributesCacheImmediately​(Context context)
      • getCurrentTimeInMillis

        protected long getCurrentTimeInMillis()
      • getMergeUtils

        protected MergeUtils getMergeUtils()
      • setMergeUtils

        public void setMergeUtils​(MergeUtils mergeUtils)
      • setJaxbContextFactory

        public void setJaxbContextFactory​(JAXBContextFactory jaxbContextFactory)
      • getAdapters

        public java.util.Map<java.util.Map<java.lang.String,​java.lang.String>,​CockpitConfigurationAdapter<?>> getAdapters()
      • setAdapters

        public void setAdapters​(java.util.Map<java.util.Map<java.lang.String,​java.lang.String>,​CockpitConfigurationAdapter<?>> adapters)
      • setConfigTypesAdapters

        public void setConfigTypesAdapters​(java.util.Map<java.lang.String,​CockpitConfigurationAdapter<?>> configTypesAdapters)
      • setCockpitProperties

        public void setCockpitProperties​(CockpitProperties cockpitProperties)
      • setWidgetConfigurationContextDecoratorList

        public void setWidgetConfigurationContextDecoratorList​(java.util.List<WidgetConfigurationContextDecorator> widgetConfigurationContextDecoratorList)
      • setConfigurationCache

        public void setConfigurationCache​(ConfigurationCache configurationCache)
      • setCockpitConfigValidator

        public void setCockpitConfigValidator​(SchemaConfigValidator cockpitConfigValidator)
      • getNamespaceReplacements

        @Deprecated(since="2005",
                    forRemoval=true)
        protected java.util.Map<javax.xml.namespace.QName,​javax.xml.namespace.QName> getNamespaceReplacements()
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 2005
      • setNamespaceReplacements

        @Deprecated(since="2005",
                    forRemoval=true)
        public void setNamespaceReplacements​(java.util.Map<java.lang.String,​java.lang.String> namespaceReplacements)
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 2005
      • reset

        public void reset()
        Description copied from interface: Resettable
        Resets the something the implementation provides.
        Specified by:
        reset in interface Resettable
      • assureSecure

        protected void assureSecure​(boolean write)
      • acquireReadLock

        protected void acquireReadLock()
      • releaseReadLock

        protected void releaseReadLock()
      • acquireWriteLock

        protected void acquireWriteLock()
      • releaseWriteLock

        protected void releaseWriteLock()