Examples of MandatoryFacet


Examples of org.apache.isis.core.metamodel.facets.propparam.mandatory.MandatoryFacet

   
    public void testPrimitiveWithNoAllowsNull_isMandatory() throws Exception {
        final Method method = cls.getMethod("getPrimitiveWithNoAllowsNull");
        facetFactory.process(new FacetFactory.ProcessMethodContext(cls, null, null, method, methodRemover, facetedMethod));
       
        final MandatoryFacet facet = facetedMethod.getFacet(MandatoryFacet.class);
        assertNotNull(facet);
        assertTrue(facet instanceof MandatoryFacetDerivedFromJdoColumn);
        assertThat(facet.isInvertedSemantics(), is(false));
    }
View Full Code Here

Examples of org.apache.isis.core.metamodel.facets.propparam.mandatory.MandatoryFacet

   
    public void testPrimitiveWithAllowsNullFalse() throws Exception {
        final Method method = cls.getMethod("getPrimitiveWithAllowsNullFalse");
        facetFactory.process(new FacetFactory.ProcessMethodContext(cls, null, null, method, methodRemover, facetedMethod));
       
        final MandatoryFacet facet = facetedMethod.getFacet(MandatoryFacet.class);
        assertNotNull(facet);
        assertTrue(facet instanceof MandatoryFacetDerivedFromJdoColumn);
        assertThat(facet.isInvertedSemantics(), is(false));
    }
View Full Code Here

Examples of org.apache.isis.core.metamodel.facets.propparam.mandatory.MandatoryFacet

    public void testPrimitiveWithAllowsNullTrue() throws Exception {
        final Method method = cls.getMethod("getPrimitiveWithAllowsNullTrue");
        facetFactory.process(new FacetFactory.ProcessMethodContext(cls, null, null, method, methodRemover, facetedMethod));
       
        final MandatoryFacet facet = facetedMethod.getFacet(MandatoryFacet.class);
        assertNotNull(facet);
        assertTrue(facet instanceof MandatoryFacetDerivedFromJdoColumn);
        assertThat(facet.isInvertedSemantics(), is(true));
    }
View Full Code Here

Examples of org.apache.isis.core.metamodel.facets.propparam.mandatory.MandatoryFacet

   
    public void testReferenceWithNoAnnotation_isOptional() throws Exception {
        final Method method = cls.getMethod("getReferenceWithNoAnnotation");
        facetFactory.process(new FacetFactory.ProcessMethodContext(cls, null, null, method, methodRemover, facetedMethod));
       
        final MandatoryFacet facet = facetedMethod.getFacet(MandatoryFacet.class);
        assertNotNull(facet);
        assertTrue(facet instanceof MandatoryFacetInferredFromAbsenceOfJdoColumn);
        assertThat(facet.isInvertedSemantics(), is(true));
    }
View Full Code Here

Examples of org.apache.isis.core.metamodel.facets.propparam.mandatory.MandatoryFacet

   
    public void testReferenceWithNoAllowsNull_isOptional() throws Exception {
        final Method method = cls.getMethod("getReferenceWithNoAllowsNull");
        facetFactory.process(new FacetFactory.ProcessMethodContext(cls, null, null, method, methodRemover, facetedMethod));
       
        final MandatoryFacet facet = facetedMethod.getFacet(MandatoryFacet.class);
        assertNotNull(facet);
        assertTrue(facet instanceof MandatoryFacetDerivedFromJdoColumn);
        assertThat(facet.isInvertedSemantics(), is(true));
    }
View Full Code Here

Examples of org.apache.isis.core.metamodel.facets.propparam.mandatory.MandatoryFacet

   
    public void testReferenceWithAllowsNullFalse() throws Exception {
        final Method method = cls.getMethod("getReferenceWithAllowsNullFalse");
        facetFactory.process(new FacetFactory.ProcessMethodContext(cls, null, null, method, methodRemover, facetedMethod));
       
        final MandatoryFacet facet = facetedMethod.getFacet(MandatoryFacet.class);
        assertNotNull(facet);
        assertTrue(facet instanceof MandatoryFacetDerivedFromJdoColumn);
        assertThat(facet.isInvertedSemantics(), is(false));
    }
View Full Code Here

Examples of org.apache.isis.core.metamodel.facets.propparam.mandatory.MandatoryFacet

   
    public void testReferenceWithAllowsNullTrue() throws Exception {
        final Method method = cls.getMethod("getReferenceWithAllowsNullTrue");
        facetFactory.process(new FacetFactory.ProcessMethodContext(cls, null, null, method, methodRemover, facetedMethod));
       
        final MandatoryFacet facet = facetedMethod.getFacet(MandatoryFacet.class);
        assertNotNull(facet);
        assertTrue(facet instanceof MandatoryFacetDerivedFromJdoColumn);
        assertThat(facet.isInvertedSemantics(), is(true));
    }
View Full Code Here

Examples of org.apache.isis.core.metamodel.facets.propparam.mandatory.MandatoryFacet

        assertFalse(objectAssociation.isMandatory());
    }

    @Test
    public void mandatory() throws Exception {
        final MandatoryFacet mockFacet = mockFacetIgnoring(MandatoryFacet.class);
        facetedMethod.addFacet(mockFacet);
        assertTrue(objectAssociation.isMandatory());
    }
View Full Code Here

Examples of org.apache.isis.core.metamodel.facets.propparam.mandatory.MandatoryFacet

    public void process(final ProcessMethodContext processMethodContext) {
        final Column annotation = Annotations.getAnnotation(processMethodContext.getMethod(), Column.class);

        final FacetedMethod holder = processMethodContext.getFacetHolder();
       
        final MandatoryFacet existingFacet = holder.getFacet(MandatoryFacet.class);
        if(existingFacet != null) {
           
            if (existingFacet instanceof OptionalFacetDerivedFromJdoPrimaryKeyAnnotation) {
                // do not replace this facet;
                // we must keep an optional facet here for different reasons
                return;
            }
            if (existingFacet instanceof MandatoryFacetOnPropertyMandatoryAnnotation) {
                // do not replace this facet;
                // an explicit @Mandatory annotation cannot be overridden by @Column annotation
                return;
            }

            // TODO: this isn't really good enough; in theory there could be other implementations of view model
            // rather than just implementing ViewModel.  However, we can't do a lookup of the ObjectSpecification for 'cls'
            // because we would (I think) go into an infinite loop...
            final Class<?> cls = processMethodContext.getCls();
            if(ViewModel.class.isAssignableFrom(cls)) {
                return;
            }
        }
       
        boolean required = whetherRequired(processMethodContext, annotation);
        MandatoryFacet facet = annotation != null
                ? new MandatoryFacetDerivedFromJdoColumn(holder, required)
                : new MandatoryFacetInferredFromAbsenceOfJdoColumn(holder, required);
               
       
        // as a side-effect, will chain any existing facets.
        // we'll exploit this fact for meta-model validation (see #refineMetaModelValidator(), below)
        FacetUtil.addFacet(facet);
       
        // however, if a @Column was explicitly provided, and the underlying facet
        // was the simple MandatoryFacetDefault (from an absence of @Optional or @Mandatory),
        // then don't chain, simply replace.
        if(facet instanceof MandatoryFacetDerivedFromJdoColumn && facet.getUnderlyingFacet() instanceof MandatoryFacetDefault) {
            facet.setUnderlyingFacet(null);
        }
    }
View Full Code Here

Examples of org.apache.isis.core.metamodel.facets.propparam.mandatory.MandatoryFacet

                    validateMandatoryFacet(association, validationFailures);
                }
            }

            private void validateMandatoryFacet(ObjectAssociation association, ValidationFailures validationFailures) {
                MandatoryFacet facet = association.getFacet(MandatoryFacet.class);

                MandatoryFacet underlying = (MandatoryFacet) facet.getUnderlyingFacet();
                if(underlying == null) {
                    return;
                }
               
                if(facet instanceof MandatoryFacetDerivedFromJdoColumn) {

                    if(association.isNotPersisted()) {
                        validationFailures.add("%s: @javax.jdo.annotations.Column found on non-persisted property; please remove)", association.getIdentifier().toClassAndNameIdentityString());
                        return;
                    }

                    if(underlying.isInvertedSemantics() == facet.isInvertedSemantics()) {
                        return;
                    }
                   
                    if(underlying.isInvertedSemantics()) {
                        // ie @Optional
                        validationFailures.add("%s: incompatible usage of Isis' @Optional annotation and @javax.jdo.annotations.Column; use just @javax.jdo.annotations.Column(allowNulls=\"...\")", association.getIdentifier().toClassAndNameIdentityString());
                    } else {
                        validationFailures.add("%s: incompatible Isis' default of required/optional properties vs JDO; add @javax.jdo.annotations.Column(allowNulls=\"...\")", association.getIdentifier().toClassAndNameIdentityString());
                    }
                }
               
                if(facet instanceof MandatoryFacetInferredFromAbsenceOfJdoColumn) {
                   
                    if(association.isNotPersisted()) {
                        // nothing to do.
                        return;
                    }

                    if(underlying.isInvertedSemantics() == facet.isInvertedSemantics()) {
                        return;
                    }
                    if(underlying.isInvertedSemantics()) {
                        // ie @Optional
                        validationFailures.add("%s: incompatible usage of Isis' @Optional annotation and @javax.jdo.annotations.Column; use just @javax.jdo.annotations.Column(allowNulls=\"...\")", association.getIdentifier().toClassAndNameIdentityString());
                    } else {
                        validationFailures.add("%s: incompatible default handling of required/optional properties between Isis and JDO; add @javax.jdo.annotations.Column(allowsNull=\"...\")", association.getIdentifier().toClassAndNameIdentityString());
                    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.