<commit_before>package com.vaadin.grails.server

import com.vaadin.grails.Vaadin
import com.vaadin.grails.VaadinUIClass
import com.vaadin.grails.VaadinViewClass
import grails.util.Holders
import org.apache.log4j.Logger

import javax.annotation.PostConstruct
import java.util.concurrent.ConcurrentHashMap

/**
 * Default implementation for {@link MappingsProvider}.
 *
 * @since 2.0
 * @author <NAME>
 */
class DefaultMappingsProvider implements MappingsProvider {

    static final def log = Logger.getLogger(DefaultMappingsProvider)

    Map<String, VaadinUIClass> uiClassByPath = new ConcurrentHashMap<>()
    Map<URI, VaadinViewClass> viewClassByURI = new ConcurrentHashMap<>()

    Map<String, Object> uiSettingsByPath = new ConcurrentHashMap<>()

    @PostConstruct
    protected void init() {
        def mappingsConfig = Holders.config.vaadin.mappings
        mappingsConfig.each { String path, ConfigObject pathConfig ->
            pathToUIClass(path, pathConfig)
            def fragments = pathConfig.fragments
            fragments.each { String fragment, ConfigObject fragmentConfig ->
                mapFragment(path, fragment, fragmentConfig)
            }
        }
    }

    protected VaadinUIClass pathToUIClass(String path, ConfigObject pathConfig) {
        def ui = pathConfig.get("ui")
        def uiNamespace = pathConfig.get("namespace") ?: null

        uiSettingsByPath.put(path, [:])
        uiSettingsByPath[path]["theme"] = pathConfig.get("theme")
        uiSettingsByPath[path]["widgetset"] = pathConfig.get("widgetset")
        uiSettingsByPath[path]["preservedOnRefresh"] = pathConfig.get("preservedOnRefresh")
        uiSettingsByPath[path]["pageTitle"] = pathConfig.get("pageTitle")
        uiSettingsByPath[path]["pushMode"] = pathConfig.get("pushMode")
        uiSettingsByPath[path]["pushTransport"] = pathConfig.get("pushTransport")

        def uiClass = Vaadin.utils.getVaadinUIClass(ui, uiNamespace)
        if (uiClass == null) {
            throw new RuntimeException("No class found for ui [${ui}]" + (uiNamespace ? " with namespace [${uiNamespace}]" : ""))
        }
        log.debug("Register class [${uiClass.fullName}] for ui [${ui}]" + (uiNamespace ? " with namespace [${uiNamespace}]" : ""))
        addUIClass(path, uiClass)
        uiClass
    }

    protected VaadinViewClass mapFragment(String path, String fragment, ConfigObject fragmentConfig) {
        def view = fragmentConfig.get("view")
        def viewNamespace = fragmentConfig.get("namespace") ?: null

        def viewClass = Vaadin.utils.getVaadinViewClass(view, viewNamespace)
        if (viewClass == null) {
            throw new RuntimeException("No class found for view [${view}]" + (viewNamespace ? " with namespace [${viewNamespace}]" : ""))
        }
        log.debug("Register class [${viewClass.fullName}] for view [${view}]" + (viewNamespace ? " with namespace [${viewNamespace}]" : ""))
        addViewClass(path, fragment, viewClass)
        viewClass
    }

    void addUIClass(String path, VaadinUIClass uiClass) {
        uiClassByPath.put(path, uiClass)
    }

    @Override
    VaadinUIClass getUIClass(String path) {
        uiClassByPath.get(path)
    }

    @Override
    String getPath(VaadinUIClass uiClass) {
        uiClassByPath.find { it.value == uiClass }?.key
    }

    @Override
    String getTheme(String path) {
        uiSettingsByPath[path]["theme"]<commit_msg>Development<commit_after>package com.vaadin.grails.server

import com.vaadin.grails.Vaadin
import com.vaadin.grails.VaadinUIClass
import com.vaadin.grails.VaadinViewClass
import grails.util.Holders
import org.apache.log4j.Logger

import javax.annotation.PostConstruct
import java.util.concurrent.ConcurrentHashMap

/**
 * Default implementation for {@link MappingsProvider}.
 *
 * @since 2.0
 * @author <NAME>
 */
class DefaultMappingsProvider implements MappingsProvider {

    static final def log = Logger.getLogger(DefaultMappingsProvider)

    Map<String, VaadinUIClass> uiClassByPath = new ConcurrentHashMap<>()
    Map<URI, VaadinViewClass> viewClassByURI = new ConcurrentHashMap<>()

    Map<String, Object> uiSettingsByPath = new ConcurrentHashMap<>()

    @PostConstruct
    protected void init() {
        def mappingsConfig = Holders.config.vaadin.mappings
        mappingsConfig.each { String path, ConfigObject pathConfig ->
            pathToUIClass(path, pathConfig)
            def fragments = pathConfig.fragments
            fragments.each { String fragment, ConfigObject fragmentConfig ->
                fragmentToViewClass(path, fragment, fragmentConfig)
            }
        }
    }

    protected VaadinUIClass pathToUIClass(String path, ConfigObject pathConfig) {
        def ui = pathConfig.get("ui")
        def uiNamespace = pathConfig.get("namespace") ?: null

        uiSettingsByPath.put(path, [:])
        uiSettingsByPath[path]["theme"] = pathConfig.get("theme")
        uiSettingsByPath[path]["widgetset"] = pathConfig.get("widgetset")
        uiSettingsByPath[path]["preservedOnRefresh"] = pathConfig.get("preservedOnRefresh")
        uiSettingsByPath[path]["pageTitle"] = pathConfig.get("pageTitle")
        uiSettingsByPath[path]["pushMode"] = pathConfig.get("pushMode")
        uiSettingsByPath[path]["pushTransport"] = pathConfig.get("pushTransport")

        def uiClass = Vaadin.utils.getVaadinUIClass(ui, uiNamespace)
        if (uiClass == null) {
            throw new RuntimeException("No class found for ui [${ui}]" + (uiNamespace ? " with namespace [${uiNamespace}]" : ""))
        }
        log.debug("Register class [${uiClass.fullName}] for ui [${ui}]" + (uiNamespace ? " with namespace [${uiNamespace}]" : ""))
        addUIClass(path, uiClass)
        uiClass
    }

    protected VaadinViewClass fragmentToViewClass(String path, String fragment, ConfigObject fragmentConfig) {
        def view = fragmentConfig.get("view")
        def viewNamespace = fragmentConfig.get("namespace") ?: null

        def viewClass = Vaadin.utils.getVaadinViewClass(view, viewNamespace)
        if (viewClass == null) {
            throw new RuntimeException("No class found for view [${view}]" + (viewNamespace ? " with namespace [${viewNamespace}]" : ""))
        }
        log.debug("Register class [${viewClass.fullName}] for view [${view}]" + (viewNamespace ? " with namespace [${viewNamespace}]" : ""))
        addViewClass(path, fragment, viewClass)
        viewClass
    }

    void addUIClass(String path, VaadinUIClass uiClass) {
        uiClassByPath.put(path, uiClass)
    }

    @Override
    VaadinUIClass getUIClass(String path) {
        uiClassByPath.get(path)
    }

    @Override
    String getPath(VaadinUIClass uiClass) {
        uiClassByPath.find { it.value == uiClass }?.key
    }

    @Override
    String getTheme(String path) {
        uiSettingsByPath[path]["theme"]
{'fraction_non_alphanumeric': 0.11598013438504236, 'fraction_numerical': 0.0008764241893076249, 'mean_word_length': 3.4374594944912507, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '538904', 'n_tokens_mistral': 2008, 'n_tokens_neox': 1930, 'n_words': 409}