Package grails.plugin.searchable.internal.compass.config.mapping

Examples of grails.plugin.searchable.internal.compass.config.mapping.SearchableGrailsDomainClassMappingConfigurator


        Map classesByStrategy = new HashMap();
        Collection grailsDomainClasses = SearchableUtils.getGrailsDomainClasses(grailsApplication);
        Set mappableClasses = new HashSet();
        Set notMapped = new HashSet(grailsDomainClasses);
        for (int i = 0; i < classMappingConfigurators.length; i++) {
            SearchableGrailsDomainClassMappingConfigurator configurator = classMappingConfigurators[i];

            // Total hack. This seems to be the easiest way to initialise this
            // particular property mapping configurator.
            if (configurator instanceof SearchableClassPropertySearchableGrailsDomainClassMappingConfigurator) {
                classMapper = ((SearchableClassPropertySearchableGrailsDomainClassMappingConfigurator) configurator).
                        getMappingDescriptionProviderManager();
                classMapper.init(
                        compassConfiguration,
                        (Map) configurationContext.get("customConverters"),
                        defaultExcludes,
                        defaultFormats);
            }

            Collection classes = configurator.getMappedBy(notMapped);
            if (classes != null) {
                notMapped.removeAll(classes);
                if (LOG.isDebugEnabled()) {
                    for (Iterator iter = classes.iterator(); iter.hasNext(); ) {
                        GrailsDomainClass grailsDomainClass = (GrailsDomainClass) iter.next();
                        LOG.debug("Mapping class [" + grailsDomainClass.getClazz().getName() + "] with strategy [" + configurator.getName() + "]");
                    }
                }
                classesByStrategy.put(classMappingConfigurators[i], classes);
                mappableClasses.addAll(classes);
            }
        }

        // Deal with any domain classes configured through the application's runtime
        // config. This is treated differently to the other configuration options
        // because it can override existing mapping information. Also, it requires
        // access to the application config object.
        AppConfigClassMapper overrideClassMapper = new AppConfigClassMapper(grailsApplication.getConfig());
        overrideClassMapper.init(compassConfiguration, (Map) configurationContext.get("customConverters"), defaultExcludes, defaultFormats);

        AppConfigMappingConfigurator appConfigConfigurator = new AppConfigMappingConfigurator(grailsApplication.getConfig());
        appConfigConfigurator.setMappingDescriptionProviderManager(overrideClassMapper);
        appConfigConfigurator.setCompassClassMappingXmlBuilder(classMappingXmlBuilder);

        Collection appConfigMapped = appConfigConfigurator.getMappedBy(grailsDomainClasses);
        mappableClasses.addAll(appConfigMapped);

        // Check whether search has been explicitly removed from any domain classes.
        Collection unmapped = appConfigConfigurator.getUnmapped(grailsDomainClasses);
        mappableClasses.removeAll(unmapped);
        notMapped.addAll(unmapped);

        if (LOG.isDebugEnabled() && !notMapped.isEmpty()) {
            for (Iterator iter = notMapped.iterator(); iter.hasNext(); ) {
                GrailsDomainClass grailsDomainClass = (GrailsDomainClass) iter.next();
                LOG.debug("No mapping strategy found for class [" + grailsDomainClass.getClazz().getName() + "]: assuming this class is not searchable");
            }
        }

        // map classes in the order defined by the classMappingConfigurators
        for (int i = 0; i < classMappingConfigurators.length; i++) {
            SearchableGrailsDomainClassMappingConfigurator classMappingConfigurator = classMappingConfigurators[i];
            Collection classes = (Collection) classesByStrategy.get(classMappingConfigurator);
            if (classes != null && !classes.isEmpty()) {
                classMappingConfigurator.configureMappings(compassConfiguration, configurationContext, classes, mappableClasses);
            }
        }

        // Finally, execute the config-based configurator so that it can add and
        // override mappings.
View Full Code Here

TOP

Related Classes of grails.plugin.searchable.internal.compass.config.mapping.SearchableGrailsDomainClassMappingConfigurator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.