package com.vst.webapp.validators;
import com.vst.model.DetailSymbol;
import com.vst.service.DetailSymbolManager;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
/**
* Created by IntelliJ IDEA.
* User: Lilia
* Date: 26.11.2009
* Time: 12:06:19
* To change this template use File | Settings | File Templates.
*/
public class DetailSymbolValidator implements Validator {
DetailSymbolManager detailSymbolManager;
public void setDetailSymbolManager(DetailSymbolManager detailSymbolManager) {
this.detailSymbolManager = detailSymbolManager;
}
public boolean supports(Class aClass) {
return DetailSymbol.class.isAssignableFrom(aClass);
}
public void validate(Object o, Errors errors) {
DetailSymbol detailSymbol = (DetailSymbol) o;
if ((detailSymbol.getType().equals("defect") && (detailSymbol.getDefectType() == null || detailSymbol.getDefectType().getDefectTypeId().longValue() == -1)) ||
(detailSymbol.getType().equals("detail") && (detailSymbol.getConstructionType() == null || detailSymbol.getConstructionType().getConstructionTypeId().longValue() == -1)
)) {
if (detailSymbol.getType().equals("defect") && (detailSymbol.getDefectType() == null || detailSymbol.getDefectType().getDefectTypeId().longValue() == -1)) {
errors.rejectValue("defectType", "reason.noDefectType");
}
if (detailSymbol.getType().equals("detail") &&
(detailSymbol.getConstructionType() == null || detailSymbol.getConstructionType().getConstructionTypeId().longValue() == -1)) {
errors.rejectValue("constructionType", "reason.constructionType.error");
}
} else if (detailSymbol.getSymbolId() == null && detailSymbolManager.detailSymbolExist(detailSymbol)) {
errors.rejectValue("symbolId", "detailSymbol.exist");
}
}
}