Examples of ConstraintViolation


Examples of com.github.jmkgreen.morphia.mapping.validation.ConstraintViolation

            Class realType = (mf.isSingleValue()) ? mf.getType() : mf.getSubClass();

            if (realType == null) throw new MappingException("Type is null for this MappedField: " + mf);

            if ((!realType.isInterface() && mc.getMapper().getMappedClass(realType).getIdField() == null))
                ve.add(new ConstraintViolation(Level.FATAL, mc, mf, this.getClass(), mf.getFullName() + " is annotated as a @"
                        + Reference.class.getSimpleName() + " but the " + mf.getType().getName()
                        + " class is missing the @" + Id.class.getSimpleName() + " annotation"));
        }
    }
View Full Code Here

Examples of com.github.jmkgreen.morphia.mapping.validation.ConstraintViolation

    public void check(MappedClass mc, Set<ConstraintViolation> ve) {

        List<MappedField> idFields = mc.getFieldsAnnotatedWith(Id.class, javax.persistence.Id.class);

        if (idFields.size() > 1) {
            ve.add(new ConstraintViolation(Level.FATAL, mc, this.getClass(), "More than one @" + Id.class.getSimpleName()
                    + " Field found (" + new FieldEnumString(idFields)
                    + ")."));
        }
    }
View Full Code Here

Examples of com.github.jmkgreen.morphia.mapping.validation.ConstraintViolation

*/
public class EmbeddedAndId implements ClassConstraint {

    public void check(MappedClass mc, Set<ConstraintViolation> ve) {
        if (mc.getEmbeddedAnnotation() != null && mc.getIdField() != null) {
            ve.add(new ConstraintViolation(Level.FATAL, mc, this.getClass(), "@" + Embedded.class.getSimpleName()
                    + " classes cannot specify a @Id field"));
        }
    }
View Full Code Here

Examples of com.github.jmkgreen.morphia.mapping.validation.ConstraintViolation

public class EmbeddedAndValue implements ClassConstraint {

    public void check(MappedClass mc, Set<ConstraintViolation> ve) {

        if (mc.getEmbeddedAnnotation() != null && !mc.getEmbeddedAnnotation().value().equals(Mapper.IGNORED_FIELDNAME)) {
            ve.add(new ConstraintViolation(Level.FATAL, mc, this.getClass(), "@" + Embedded.class.getSimpleName()
                    + " classes cannot specify a fieldName value(); this is on applicable on fields"));
        }
    }
View Full Code Here

Examples of com.github.jmkgreen.morphia.mapping.validation.ConstraintViolation

        for (Class<?> clazz : classesToInspect) {
            if (alreadyInspectedClasses.contains(clazz)) {
                continue;
            }
            if (hasTypeFieldAnnotation(clazz, Id.class) || hasTypeFieldAnnotation(clazz, javax.persistence.Id.class)) {
                ve.add(new ConstraintViolation(Level.FATAL, mc, this.getClass(),
                        "You cannot use @Id on any field of an Embedded/Property object"));
            }
            alreadyInspectedClasses.add(clazz);
            Set<Class<?>> extraClassesToInspect = new HashSet<Class<?>>();
            for (Field field : ReflectionUtils.getDeclaredAndInheritedFields(clazz, true)) {
View Full Code Here

Examples of com.github.jmkgreen.morphia.mapping.validation.ConstraintViolation

public class MultipleVersions implements ClassConstraint {

    public void check(MappedClass mc, Set<ConstraintViolation> ve) {
        List<MappedField> versionFields = mc.getFieldsAnnotatedWith(Version.class);
        if (versionFields.size() > 1)
            ve.add(new ConstraintViolation(Level.FATAL, mc, this.getClass(), "Multiple @" + Version.class
                    + " annotations are not allowed. (" + new FieldEnumString(versionFields)));
    }
View Full Code Here

Examples of com.github.jmkgreen.morphia.mapping.validation.ConstraintViolation

public class EntityAndEmbed implements ClassConstraint {

    public void check(MappedClass mc, Set<ConstraintViolation> ve) {

        if (mc.getEntityAnnotation() != null && mc.getEmbeddedAnnotation() != null) {
            new ConstraintViolation(Level.FATAL, mc, this.getClass(), "Cannot have both @" + Entity.class.getSimpleName() + " and @"
                    + Embedded.class.getSimpleName() + " annotation at class level.");
        }

    }
View Full Code Here

Examples of com.github.jmkgreen.morphia.mapping.validation.ConstraintViolation

*/
public class NoId implements ClassConstraint {

    public void check(MappedClass mc, Set<ConstraintViolation> ve) {
        if (mc.getIdField() == null && mc.getEmbeddedAnnotation() == null) {
            ve.add(new ConstraintViolation(Level.FATAL, mc, this.getClass(),
                    "No field is annotated with @Id; but it is required"));
        }
    }
View Full Code Here

Examples of com.github.jmkgreen.morphia.mapping.validation.ConstraintViolation

            for (String name : mappedField.getLoadNames()) {
//        if (duplicates.contains(name)) {
//          continue;
//        }
                if (!foundNames.add(name)) {
                    ve.add(new ConstraintViolation(Level.FATAL, mc, mappedField, this.getClass(), "Mapping to MongoDB field name '" + name
                            + "' is duplicated; you cannot map different java fields to the same MongoDB field."));
                    duplicates.add(name);
                }
            }
        }
View Full Code Here

Examples of javax.validation.ConstraintViolation

        author.setFirstName("Gavin");
        author.setLastName("King");

        constraintViolations = validator.validate(book, First.class, Second.class, Last.class);
        ConstraintViolation constraintViolation = constraintViolations.iterator().next();
        assertEquals(1, constraintViolations.size());
        assertEquals("may not be empty", constraintViolation.getMessage());
        assertEquals(book, constraintViolation.getRootBean());
        assertEquals(book.getTitle(), constraintViolation.getInvalidValue());
        assertEquals("title", constraintViolation.getPropertyPath().toString());

        book.setTitle("My fault");
        book.setSubtitle("confessions of a president - a book for a nice price");

        constraintViolations = validator.validate(book, First.class, Second.class, Last.class);
        assertEquals(1, constraintViolations.size());
        constraintViolation = constraintViolations.iterator().next();
        assertEquals("size must be between 0 and 30", constraintViolation.getMessage());
        assertEquals(book, constraintViolation.getRootBean());
        assertEquals(book.getSubtitle(), constraintViolation.getInvalidValue());
        assertEquals("subtitle", constraintViolation.getPropertyPath().toString());

        book.setSubtitle("Capitalism in crisis");
        author.setCompany("1234567890ß9876543212578909876542245678987432");

        constraintViolations = validator.validate(book);
        constraintViolation = constraintViolations.iterator().next();
        assertEquals(1, constraintViolations.size());
        assertEquals("size must be between 0 and 40", constraintViolation.getMessage());
        assertEquals(book, constraintViolation.getRootBean());
        assertEquals(author.getCompany(), constraintViolation.getInvalidValue());
        assertEquals("author.company", constraintViolation.getPropertyPath().toString());

        author.setCompany("apache");

        constraintViolations = validator.validate(book, First.class, Second.class, Last.class);
        assertEquals(0, constraintViolations.size());
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.