Package org.apache.isis.core.progmodel.facets.value.bigdecimal

Examples of org.apache.isis.core.progmodel.facets.value.bigdecimal.BigDecimalValueFacet


        final Column annotation = Annotations.getAnnotation(processMethodContext.getMethod(), Column.class);

        if(BigDecimal.class != processMethodContext.getMethod().getReturnType()) {
            return;
        }
        final BigDecimalValueFacet facet;
        final FacetedMethod holder = processMethodContext.getFacetHolder();
       
        if (annotation == null) {
            facet = new BigDecimalFacetFallback(holder);
        } else {
View Full Code Here


        if (valueFacet != null) {
            String format = null;
            final Class<?> specClass = spec.getCorrespondingClass();
            if(specClass == java.math.BigDecimal.class) {
                // look for facet on member, else on the value's spec
                final BigDecimalValueFacet bigDecimalValueFacet =
                        getFacet(BigDecimalValueFacet.class,
                                objectMember,
                                valueAdapter != null? valueAdapter.getSpecification(): null);
                if(bigDecimalValueFacet != null) {
                    final Integer precision = bigDecimalValueFacet.getPrecision();
                    final Integer scale = bigDecimalValueFacet.getScale();
                    format = String.format("big-decimal(%d,%d)", precision, scale);
                }
            } else if(specClass == java.math.BigInteger.class) {
                // TODO: need to extend BigIntegerValueFacet similar to BigDecimalValueFacet
            }
View Full Code Here

    public void testAnnotationPickedUpOnProperty() throws Exception {
        final Class<?> cls = SimpleObjectWithBigDecimalColumnAnnotations.class;
        final Method method = cls.getMethod("getBigDecimalPropertyWithColumnAnnotation");
        facetFactory.process(new FacetFactory.ProcessMethodContext(cls, null, null, method, methodRemover, facetedMethod));

        final BigDecimalValueFacet facet = facetedMethod.getFacet(BigDecimalValueFacet.class);
        assertNotNull(facet);
        assertTrue(facet instanceof BigDecimalFacetDerivedFromJdoColumn);
        assertThat(facet.getLength(), is(12));
        assertThat(facet.getScale(), is(3));
    }
View Full Code Here

    public void testAnnotationDefaultsLengthIfMissing() throws Exception {
        final Class<?> cls = SimpleObjectWithBigDecimalColumnAnnotations.class;
        final Method method = cls.getMethod("getBigDecimalPropertyWithColumnAnnotationMissingLength");
        facetFactory.process(new FacetFactory.ProcessMethodContext(cls, null, null, method, methodRemover, facetedMethod));

        final BigDecimalValueFacet facet = facetedMethod.getFacet(BigDecimalValueFacet.class);
        assertNotNull(facet);
        assertTrue(facet instanceof BigDecimalFacetDerivedFromJdoColumn);
        assertThat(facet.getLength(), is(18));
    }
View Full Code Here

            return;
        }
       
        final FacetedMethod holder = processMethodContext.getFacetHolder();

        BigDecimalValueFacet existingFacet = (BigDecimalValueFacet) holder.getFacet(BigDecimalValueFacet.class);

        final Column jdoColumnAnnotation = Annotations.getAnnotation(processMethodContext.getMethod(), Column.class);

        if (jdoColumnAnnotation == null) {
            if(existingFacet != null && !existingFacet.isNoop()) {
                // do nothing
            } else {
                final BigDecimalValueFacet facet = new BigDecimalFacetFallback(holder);
                FacetUtil.addFacet(facet);
            }
        } else {
           
            // obtain the existing facet's length and scale, to use as defaults if none are specified on the @Column
            // this will mean a metamodel validation exception will only be fired later (see #refineMetaModelValidator)
            // if there was an *explicit* value defined on the @Column annotation that is incompatible with existing.
            Integer existingLength = null;
            Integer existingScale = null;
            if(existingFacet != null && !existingFacet.isNoop()) {
                existingLength = existingFacet.getLength();
                existingScale = existingFacet.getScale();
            }
           
            Integer length = valueElseDefaults(jdoColumnAnnotation.length(), existingLength, DEFAULT_LENGTH);
            Integer scale = valueElseDefaults(jdoColumnAnnotation.scale(), existingScale, DEFAULT_SCALE);
            final BigDecimalValueFacet facet = new BigDecimalFacetDerivedFromJdoColumn(holder, length, scale);
            FacetUtil.addFacet(facet);
        }
    }
View Full Code Here

    public void testAnnotationDefaultsScaleIfMissing() throws Exception {
        final Class<?> cls = SimpleObjectWithBigDecimalColumnAnnotations.class;
        final Method method = cls.getMethod("getBigDecimalPropertyWithColumnAnnotationMissingScale");
        facetFactory.process(new FacetFactory.ProcessMethodContext(cls, null, null, method, methodRemover, facetedMethod));
       
        final BigDecimalValueFacet facet = facetedMethod.getFacet(BigDecimalValueFacet.class);
        assertNotNull(facet);
        assertTrue(facet instanceof BigDecimalFacetDerivedFromJdoColumn);
        assertThat(facet.getScale(), is(2));
    }
View Full Code Here

                    validateBigDecimalValueFacet(association, validationFailures);
                }
            }

            private void validateBigDecimalValueFacet(ObjectAssociation association, ValidationFailures validationFailures) {
                BigDecimalValueFacet facet = association.getFacet(BigDecimalValueFacet.class);
                if(facet == null) {
                    return;
                }
               
                BigDecimalValueFacet underlying = (BigDecimalValueFacet) facet.getUnderlyingFacet();
                if(underlying == null) {
                    return;
                }
               
                if(facet instanceof BigDecimalFacetDerivedFromJdoColumn) {
                   
                    if(underlying instanceof BigDecimalFacetForPropertyFromJavaxValidationDigitsAnnotation) {

                        if(notNullButNotEqual(facet.getLength(), underlying.getLength())) {
                            validationFailures.add("%s: @javax.jdo.annotations.Column(length=...) different from @javax.validation.constraint.Digits(...); should equal the sum of its integer and fraction attributes", association.getIdentifier().toClassAndNameIdentityString());
                        }
   
                        if(notNullButNotEqual(facet.getScale(), underlying.getScale())) {
                            validationFailures.add("%s: @javax.jdo.annotations.Column(scale=...) different from @javax.validation.constraint.Digits(fraction=...)", association.getIdentifier().toClassAndNameIdentityString());
                        }
                    }
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.isis.core.progmodel.facets.value.bigdecimal.BigDecimalValueFacet

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.