package com.vst.webapp.validators;
import com.vst.model.EquipmentInspection;
import com.vst.service.EquipmentInspectionManager;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
/**
* Created by IntelliJ IDEA.
* User: Администратор
* Date: 07.07.2009
* Time: 14:34:34
* To change this template use File | Settings | File Templates.
*/
public class EquipmentInspectionValidator implements Validator {
EquipmentInspectionManager equipmentInspectionManager;
public void setEquipmentInspectionManager(EquipmentInspectionManager equipmentInspectionManager) {
this.equipmentInspectionManager = equipmentInspectionManager;
}
public boolean supports(Class aClass) {
return EquipmentInspection.class.isAssignableFrom(aClass);
}
public void validate(Object o, Errors errors) {
EquipmentInspection equipmentInspection = (EquipmentInspection) o;
if (equipmentInspection.getType().trim().equals("") || equipmentInspection.getMark().trim().equals("")) {
if (equipmentInspection.getType().trim().equals("")) {
errors.rejectValue("type", "equipmentInspection.type.error");
}
if (equipmentInspection.getMark().trim().equals("")) {
errors.rejectValue("mark", "equipmentInspection.mark.error");
}
if (equipmentInspection.getFactoryNumber().trim().equals("")) {
errors.rejectValue("factoryNumber", "equipmentInspection.number.error");
}
} else {
if (equipmentInspectionManager.exist(equipmentInspection) && equipmentInspection.getEquipmentId() == null) {
errors.rejectValue("equipmentId", "equipmentInspection.error");
}
}
}
}