Package grails.core

Examples of grails.core.GrailsDomainClass


    private Template generateScaffoldedTemplate(GrailsWebRequest webRequest, String uri) throws IOException {
        Template t = null;
        Collection<String> controllerActions = scaffoldedActionMap.get(webRequest.getControllerName());
        if (controllerActions != null && controllerActions.contains(webRequest.getActionName())) {
            GrailsDomainClass domainClass = controllerToScaffoldedDomainClassMap.get(webRequest.getControllerName());
            if (domainClass != null) {
                int i = uri.lastIndexOf('/');
                String scaffoldedtemplateName = i > -1 ? uri.substring(i) : uri;
                if (scaffoldedtemplateName.toLowerCase().endsWith(".gsp")) {
                    scaffoldedtemplateName = scaffoldedtemplateName.substring(0, scaffoldedtemplateName.length() - 4);
View Full Code Here


                "   Long id\n"// WE NEED this even though GORM 2 doesn't, as we're not a "domain" class within grails-app
                "   Long version\n"+ // WE NEED this even though GORM 2 doesn't, as we're not a "domain" class within grails-app
                " String name\n" +
                "}");

        GrailsDomainClass domainClass = new DefaultGrailsDomainClass(groovyClass);

        Map constraints = domainClass.getConstrainedProperties();

        assertNotNull(constraints);
        assertFalse(constraints.isEmpty());
    }
View Full Code Here

                       "class Sub2 extends Sub { }");

        GrailsApplication ga = new DefaultGrailsApplication(gcl.getLoadedClasses(),gcl);
        ga.initialise();

        GrailsDomainClass gdc1 = (GrailsDomainClass) ga.getArtefact(DomainClassArtefactHandler.TYPE, "Super");
        assertNotNull(gdc1);
        assertTrue(gdc1.isRoot());
        assertEquals(2,gdc1.getSubClasses().size());
        assertFalse(gdc1.getPropertyByName("id").isInherited());

        GrailsDomainClass gdc2 = (GrailsDomainClass) ga.getArtefact(DomainClassArtefactHandler.TYPE, "Sub");

        assertFalse(gdc2.isRoot());
        assertEquals(1,gdc2.getSubClasses().size());
        assertTrue(gdc2.getPropertyByName("id").isInherited());

        GrailsDomainClass gdc3 = (GrailsDomainClass) ga.getArtefact(DomainClassArtefactHandler.TYPE, "Sub2");

        assertFalse(gdc3.isRoot());
        assertEquals(0,gdc3.getSubClasses().size());
        assertTrue(gdc3.getPropertyByName("id").isInherited());
    }
View Full Code Here

                            "other(blank:false,size:5..15,nullable:false)\n" +
                            "email(email:true)\n" +
                        "}\n" +
                        "}");

        GrailsDomainClass domainClass = new DefaultGrailsDomainClass(groovyClass);

        Map constrainedProperties = domainClass.getConstrainedProperties();
        assertTrue(constrainedProperties.size() == 3);
        ConstrainedProperty loginConstraint = (ConstrainedProperty)constrainedProperties.get("login");
        Collection appliedConstraints = loginConstraint.getAppliedConstraints();
        assertTrue(appliedConstraints.size() == 3);
View Full Code Here

    }

    protected boolean canApplyNullableConstraint(String propertyName, GrailsDomainClassProperty property, Constrained constrained) {
        if (property == null || property.getType() == null) return false;

        final GrailsDomainClass domainClass = property.getDomainClass();
        // only apply default nullable to Groovy entities not legacy Java ones
        if (!GroovyObject.class.isAssignableFrom(domainClass.getClazz())) return false;

        final GrailsDomainClassProperty versionProperty = domainClass.getVersion();
        final boolean isVersion = versionProperty != null && versionProperty.equals(property);
        return !constrained.hasAppliedConstraint(ConstrainedProperty.NULLABLE_CONSTRAINT) &&
            isConstrainableProperty(property, propertyName) && !property.isIdentity() && !isVersion && !property.isDerived();
    }
View Full Code Here

        if (associatedObject == null) {
            return;
        }

        GrailsDomainClass associatedDomainClass = getAssociatedDomainClass(associatedObject, persistentProperty);

        if (associatedDomainClass == null || !isOwningInstance(bean, associatedDomainClass) && !persistentProperty.isExplicitSaveUpdateCascade()) {
            return;
        }

        GrailsDomainClassProperty otherSide = null;
        if (persistentProperty.isBidirectional()) {
            otherSide = persistentProperty.getOtherSide();
        }

        Map associatedConstraintedProperties = associatedDomainClass.getConstrainedProperties();

        GrailsDomainClassProperty[] associatedPersistentProperties = associatedDomainClass.getPersistentProperties();
        String nestedPath = errors.getNestedPath();
        try {
            errors.setNestedPath(buildNestedPath(nestedPath, propertyName, indexOrKey));

            for (GrailsDomainClassProperty associatedPersistentProperty : associatedPersistentProperties) {
View Full Code Here

        // test message source
        MessageSource ms = getBean(ctx, GrailsApplication.MESSAGE_SOURCE_BEAN);
        assertNotNull(ms);

        // test domain class setup correctly in the ctx
        GrailsDomainClass domainClass = getBean(ctx, "TestDomainClass");

        assertNotNull(domainClass);
        assertEquals("Test", domainClass.getShortName());

        Class<?> persistentClass = getBean(ctx, "TestPersistentClass");
        assertEquals(dc,persistentClass);

        GrailsDomainClassValidator validator = getBean(ctx, "TestValidator");
View Full Code Here

TOP

Related Classes of grails.core.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.