/**
  * Validates Response object.
  *
  * <p>Returns List of validation errors if the object is not valid. Main rules: if field is
  * required, response answer on that field should not be empty, if field type is date, response
  * answer on that field should match DATE_REGEX.
  *
  * @return List of validation errors or null if Response object is valid
  */
 public List<ValidationError> validate() {
   List<ValidationError> errors = new ArrayList<>();
   if (answers != null) {
     for (Answer answer : answers) {
       if (answer.field.required && answer.isEmptyAnswer()) {
         errors.add(new ValidationError(answer.field.label, "Field is required."));
       }
       if (answer.field.fieldType.equals(FieldType.DATE)
           && !answer.value.isEmpty()
           && !isValidDate(answer.value)) {
         errors.add(
             new ValidationError(
                 answer.field.label, "Wrong date format. Please, use yyyy-mm-dd format."));
       }
     }
   }
   return errors.isEmpty() ? null : errors;
 }
Exemplo n.º 2
0
  public boolean matches(Criteria criteria) {
    score = 0;

    boolean kill = false;
    boolean anyMatches = false;
    for (Criterion criterion : criteria) {
      Answer answer = answers.get(criterion.getAnswer().getQuestionText());
      boolean match =
          criterion.getWeight() == Weight.DontCare || answer.match(criterion.getAnswer());
      if (!match && criterion.getWeight() == Weight.MustMatch) {
        kill = true;
      }
      if (match) {
        score += criterion.getWeight().getValue();
      }
      anyMatches |= match;
      // ...
    }
    if (kill) return false;
    return anyMatches;
  }
Exemplo n.º 3
0
 public void add(Answer answer) {
   answers.put(answer.getQuestionText(), answer);
 }