Package br.net.woodstock.rockframework.domain.validator.jpa

Examples of br.net.woodstock.rockframework.domain.validator.jpa.ValidationResult


    }

    BeanDescriptor beanDescriptor = new BeanDescriptorBuilder(entity.getClass()).getBeanDescriptor();
    Collection<ValidationResult> collection = new ArrayList<ValidationResult>();
    for (PropertyDescriptor propertyDescriptor : beanDescriptor.getProperties()) {
      ValidationResult result = null;
      boolean checkIdOnly = false;
      boolean checkColumn = false;
      boolean checkJoinColumn = false;

      if ((this.operation == Operation.FIND) || (this.operation == Operation.REMOVE)) {
        checkIdOnly = true;
      }

      if (checkIdOnly) {
        if (propertyDescriptor.isAnnotationPresent(Id.class)) {
          result = this.validateId(entity, propertyDescriptor, this.operation);
        }
      } else {
        if (propertyDescriptor.isAnnotationPresent(Id.class)) {
          result = this.validateId(entity, propertyDescriptor, this.operation);
          checkColumn = true;
        } else if (propertyDescriptor.isAnnotationPresent(Basic.class)) {
          result = this.validateBasic(entity, propertyDescriptor, propertyDescriptor.getAnnotation(Basic.class));
          checkColumn = true;
        } else if (propertyDescriptor.isAnnotationPresent(OneToOne.class)) {
          result = this.validateOneToOne(entity, propertyDescriptor, propertyDescriptor.getAnnotation(OneToOne.class));
          checkJoinColumn = true;
        } else if (propertyDescriptor.isAnnotationPresent(OneToMany.class)) {
          result = this.validateOneToMany(entity, propertyDescriptor, propertyDescriptor.getAnnotation(OneToMany.class));
        } else if (propertyDescriptor.isAnnotationPresent(ManyToOne.class)) {
          result = this.validateManyToOne(entity, propertyDescriptor, propertyDescriptor.getAnnotation(ManyToOne.class));
          checkJoinColumn = true;
        } else if (propertyDescriptor.isAnnotationPresent(ManyToMany.class)) {
          result = this.validateManyToMany(entity, propertyDescriptor, propertyDescriptor.getAnnotation(ManyToMany.class));
        } else if (propertyDescriptor.isAnnotationPresent(Column.class)) {
          result = this.validateColumn(entity, propertyDescriptor, propertyDescriptor.getAnnotation(Column.class));
        }

        if ((result != null) && (!result.isError())) {
          if (checkColumn) {
            if (propertyDescriptor.isAnnotationPresent(Column.class)) {
              result = this.validateColumn(entity, propertyDescriptor, propertyDescriptor.getAnnotation(Column.class));
            }
          }

          if (checkJoinColumn) {
            if (propertyDescriptor.isAnnotationPresent(JoinColumn.class)) {
              result = this.validateJoinColumn(entity, propertyDescriptor, propertyDescriptor.getAnnotation(JoinColumn.class));
            }
          }
        }
      }

      if (result != null) {
        if (result.isError()) {
          collection.add(result);
        } else if (this.includeSuccessResult) {
          collection.add(result);
        }
      }
View Full Code Here


    Object value = propertyDescriptor.getValue(entity);

    if (operation == Operation.PERSIST) {
      if (value == null) {
        if (propertyDescriptor.isAnnotationPresent(GeneratedValue.class)) {
          return new ValidationResult(false, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_OK));
        }
        return new ValidationResult(true, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_ERROR_NOT_NULL, name));
      }

      if (propertyDescriptor.isAnnotationPresent(GeneratedValue.class)) {
        return new ValidationResult(true, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_ERROR_NULL, name));
      }
    } else {
      if (value == null) {
        return new ValidationResult(true, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_ERROR_NOT_NULL, name));
      }
    }
    return new ValidationResult(false, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_OK));
  }
View Full Code Here

    String name = propertyDescriptor.getName();
    Object value = propertyDescriptor.getValue(entity);

    if (value == null) {
      if (column.nullable()) {
        return new ValidationResult(false, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_OK));
      }
      return new ValidationResult(true, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_ERROR_NOT_NULL, name));
    }

    if (value instanceof String) {
      int length = ((String) value).length();
      if (length > column.length()) {
        return new ValidationResult(true, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_ERROR_LENGTH, name, Integer.valueOf(0), Integer.valueOf(column.length())));
      }
    }
    return new ValidationResult(false, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_OK));
  }
View Full Code Here

    String name = propertyDescriptor.getName();
    Object value = propertyDescriptor.getValue(entity);

    if (value == null) {
      if (column.nullable()) {
        return new ValidationResult(false, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_OK));
      }
      return new ValidationResult(true, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_ERROR_NOT_NULL, name));
    }
    return new ValidationResult(false, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_OK));
  }
View Full Code Here

    String name = propertyDescriptor.getName();
    Object value = propertyDescriptor.getValue(entity);

    if (value == null) {
      if (basic.optional()) {
        return new ValidationResult(false, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_OK));
      }
      return new ValidationResult(true, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_ERROR_NOT_NULL, name));
    }

    return new ValidationResult(false, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_OK));
  }
View Full Code Here

  }

  @SuppressWarnings("unused")
  private ValidationResult validateManyToMany(final Object entity, final PropertyDescriptor propertyDescriptor, final ManyToMany manyToMany) {
    String name = propertyDescriptor.getName();
    return new ValidationResult(false, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_OK));
  }
View Full Code Here

    String name = propertyDescriptor.getName();
    Object value = propertyDescriptor.getValue(entity);

    if (value == null) {
      if (manyToOne.optional()) {
        return new ValidationResult(false, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_OK));
      }
      return new ValidationResult(true, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_ERROR_NOT_NULL, name));
    }

    Object id = this.getId(value);

    if ((id == null) && (!manyToOne.optional())) {
      return new ValidationResult(true, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_ERROR_INVALID_REFERENCE, name));
    }

    return new ValidationResult(false, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_OK));
  }
View Full Code Here

    String name = propertyDescriptor.getName();
    Object value = propertyDescriptor.getValue(entity);

    if (value == null) {
      if (oneToOne.optional()) {
        return new ValidationResult(false, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_OK));
      }
      return new ValidationResult(true, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_ERROR_NOT_NULL, name));
    }

    Object id = this.getId(value);

    if ((id == null) && (!oneToOne.optional())) {
      return new ValidationResult(true, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_ERROR_INVALID_REFERENCE, name));
    }

    return new ValidationResult(false, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_OK));
  }
View Full Code Here

  }

  @SuppressWarnings("unused")
  private ValidationResult validateOneToMany(final Object entity, final PropertyDescriptor propertyDescriptor, final OneToMany oneToMany) {
    String name = propertyDescriptor.getName();
    return new ValidationResult(false, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_OK));
  }
View Full Code Here

    Assert.notNull(operation, "operation");

    EntityValidator validator = new EntityValidatorImpl(operation);
    Collection<ValidationResult> results = validator.validate(entity);
    if (results.size() > 0) {
      ValidationResult result = results.iterator().next();
      return new BusinessResult(true, result.getMessage());
    }

    return new BusinessResult(false, AbstractBusiness.OK_MESSAGE);
  }
View Full Code Here

TOP

Related Classes of br.net.woodstock.rockframework.domain.validator.jpa.ValidationResult

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.