Validator.java 967 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
package at.ac.tuwien.sepm.assignment.individual.util;

import at.ac.tuwien.sepm.assignment.individual.entity.Horse;
import at.ac.tuwien.sepm.assignment.individual.entity.Owner;
import org.springframework.stereotype.Component;

@Component
public class Validator {



    public void validateNewOwner(Owner owner) throws ValidationException {
    }

    public void validateUpdateOwner(Owner owner) throws ValidationException {
    }

    public void validateNewHorse(Horse horse) throws ValidationException {
19 20
        if(horse.getName() == null || horse.getScore() == 0 || horse.getBirthday() == null || horse.getRace() == null){
            throw new ValidationException("All or some required values missing: name, score, birthday, race");
21
        }
22 23 24 25 26
        if(horse.getScore() > 5 || horse.getScore() < 1) {
            throw new ValidationException("Score value " + horse.getScore() + " not allowed. The score must be an integer between 1 and 5");
        }
    }
}