Package org.codehaus.groovy.grails.commons

Examples of org.codehaus.groovy.grails.commons.GrailsDomainClass


     * @param grailsDomainClasses the collection of GrailsDomainClasses to look thru
     * @return the corresponding GrailsDomainClass
     */
    public static GrailsDomainClass getGrailsDomainClass(Class clazz, Collection grailsDomainClasses) {
        for (Iterator iter = grailsDomainClasses.iterator(); iter.hasNext(); ) {
            GrailsDomainClass grailsDomainClass = (GrailsDomainClass) iter.next();
            if (grailsDomainClass.getClazz().equals(clazz)) {
                return grailsDomainClass;
            }
        }
        return null;
    }
View Full Code Here


     * @param clazz the user domain Class
     * @param propertyName the property name
     * @return the property
     */
    public static GrailsDomainClassProperty getGrailsDomainClassProperty(Collection grailsDomainClasses, Class clazz, String propertyName) {
        GrailsDomainClass grailsDomainClass = getGrailsDomainClass(clazz, grailsDomainClasses);
        Assert.notNull(grailsDomainClass, "GrailsDomainClass not found for clazz [" + clazz + "]");
        return grailsDomainClass.getPropertyByName(propertyName);
    }
View Full Code Here

        if (classMapping.getRoot() == null) {
            classMapping.setRoot(Boolean.valueOf(SearchableGrailsDomainClassCompassMappingUtils.isRoot(grailsDomainClass, searchableGrailsDomainClasses)));
        }
        Collection superClasses = GrailsDomainClassUtils.getSuperClasses(grailsDomainClass, searchableGrailsDomainClasses);
        if (!superClasses.isEmpty()) {
            GrailsDomainClass parent = GrailsDomainClassUtils.getSuperClass(grailsDomainClass, superClasses);
            classMapping.setMappedClassSuperClass(parent.getClazz());
        }
        if (GrailsDomainClassUtils.isWithinInhertitanceHierarchy(grailsDomainClass, searchableGrailsDomainClasses)) {
            Map data = new HashMap();
            data.put("index", "not_analyzed");
            data.put("excludeFromAll", true);
View Full Code Here

        if (configurationContext.containsKey(CompassXmlConfigurationSearchableCompassConfigurator.CONFIGURED)) {
            return;
        }

        for (Iterator iter = searchableGrailsDomainClasses.iterator(); iter.hasNext(); ) {
            GrailsDomainClass grailsDomainClass = (GrailsDomainClass) iter.next();
            Resource resource = getMappingResource(grailsDomainClass);
            Assert.isTrue(resource.exists(), "expected mapping resource [" + resource + "] to exist but it does not");
            try {
                compassConfiguration.addURL(resource.getURL());
            } catch (IOException ex) {
                String message = "Failed to configure Compass with mapping resource for class [" + grailsDomainClass.getClazz().getName() + "] and resource [" + getMappingResourceName(grailsDomainClass) + "]";
                LOG.error(message, ex);
                throw new IllegalStateException(message + ": " + ex);
            }
        }
    }
View Full Code Here

        if (configurationContext.containsKey(CompassXmlConfigurationSearchableCompassConfigurator.CONFIGURED)) {
            return;
        }

        for (Iterator iter = searchableGrailsDomainClasses.iterator(); iter.hasNext(); ) {
            GrailsDomainClass gdc = (GrailsDomainClass) iter.next();
            compassConfiguration.addClass(gdc.getClazz());
        }
    }
View Full Code Here

     * @return the collection of domain classes mapped by this instance
     */
    public Collection getMappedBy(Collection grailsDomainClasses) {
        Set mappedBy = new HashSet();
        for (Iterator iter = grailsDomainClasses.iterator(); iter.hasNext(); ) {
            GrailsDomainClass grailsDomainClass = (GrailsDomainClass) iter.next();
            Object value = SearchableUtils.getSearchablePropertyValue(grailsDomainClass);
            if (value != null) {
                if (!((value instanceof Boolean) && !(Boolean)value)) {
                    mappedBy.add(grailsDomainClass);
                }
View Full Code Here

        Assert.notNull(compassClassMappingXmlBuilder, "compassClassMappingXmlBuilder cannot be null");

        // map all classes
        List classMappings = new ArrayList();
        for (Iterator iter = searchableGrailsDomainClasses.iterator(); iter.hasNext(); ) {
            GrailsDomainClass grailsDomainClass = (GrailsDomainClass) iter.next();
            CompassClassMapping classMapping = classMapper.getCompassClassMapping(grailsDomainClass, allSearchableGrailsDomainClasses);
            classMappings.add(classMapping);
        }

        // resolve aliases
View Full Code Here

            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++) {
View Full Code Here

     * @return the collection of domain classes mapped by this instance
     */
    public Collection getMappedBy(Collection grailsDomainClasses) {
        Set mappedBy = new HashSet();
        for (Iterator iter = grailsDomainClasses.iterator(); iter.hasNext(); ) {
            GrailsDomainClass grailsDomainClass = (GrailsDomainClass) iter.next();
            if (isMappedBy(grailsDomainClass)) {
                mappedBy.add(grailsDomainClass);
            }
        }
        return mappedBy;
View Full Code Here

TOP

Related Classes of org.codehaus.groovy.grails.commons.GrailsDomainClass

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.