validate method

Map<String, List<DfError>> validate(
  1. bool allowEmpty,
  2. DfValidatorListSize listSizeConstraint
)

Implementation

Map<String, List<DfError>> validate(bool allowEmpty, DfValidatorListSize listSizeConstraint) {
  Map<String, List<DfError>> errors = Map<String, List<DfError>>();
  DfBaseEntity entity = renderResultToEntity();
  List<DfBaseEntity> entities = renderResultToEntityList();

  String mainErrKey = "responseResult";
  if (!allowEmpty) {
    if (entity == null && (entities == null || entities.length == 0)) {
      if (errors[mainErrKey] == null)
        errors[mainErrKey] = [];
      errors[mainErrKey].add(AllowEmptyValidateException());
    }
  }
  if (entities != null && listSizeConstraint != null) {
    if ((listSizeConstraint.min != null && entities.length < listSizeConstraint.min) || (listSizeConstraint.max != null && entities.length > listSizeConstraint.max)) {
      if (errors[mainErrKey] == null)
        errors[mainErrKey] = [];
      errors[mainErrKey].add(ListSizeValidateException(listSizeConstraint, entities.length));
    }
  }

  if (entity != null)
    errors.addAll(entity.validate());

  if (entities != null) {
    entities.forEach((entity) {
      errors.addAll(entity.validate());
    });
  }

  return errors;
}