*
* @see org.springframework.validation.Validator#validate(java.lang.Object,
* org.springframework.validation.Errors)
*/
public void validate(Object clazz, Errors e) {
DynamicReport report = (DynamicReport) clazz;
if(!StringUtil.isEmpty(report.getName()) && isDuplicateName(report))
e.reject("error.duplicate-name", new Object[]{"\""+report.getName()+"\"","name"}, "\""+report.getName() +"\" already exists. Please try a different name.");
ValidationUtils.rejectIfEmpty(e, "name", "error.required", new Object[] { "Name" });
ValidationUtils.rejectIfEmpty(e, "title", "error.required", new Object[] { "Title" });
ValidationUtils.rejectIfEmpty(e, "reportGroup", "error.required", new Object[] { "Report Group" });
String reportFile = "";
if (report.getJasperFile()==null && report.isNew())
e.reject("error.required", new Object[] { "Jasper File" }, "Jasper File is required.");
else {
String jasperFile = FileUtil.getFilename(report.getJasperFile().getOriginalFilename());
if (!StringUtil.isEmpty(jasperFile)) {
if (jasperFile.endsWith(".jasper"))
reportFile = jasperFile.substring(0, jasperFile.length()-7);
else
e.reject("error.jasper-file-must-have-extension-of-jasper", "Jasper File must have extension of .jasper");
} else if (report.isNew())
e.reject("error.required", new Object[] { "Jasper File" }, "Jasper File is required.");
}
if (report.getJrxmlFile()==null && report.isNew())
e.reject("error.required", new Object[] { "Jrxml File" }, "Jrxml File is required.");
else {
String jrxmlFile = FileUtil.getFilename(report.getJrxmlFile().getOriginalFilename());
if (!StringUtil.isEmpty(jrxmlFile)) {
if (jrxmlFile.endsWith(".jrxml")) {
if (reportFile.equals(jrxmlFile.substring(0, jrxmlFile.length()-6)))
report.setReportFile(reportFile);
else
e.reject("error.jrxml-file-must-have-same-filename-with-jasper-file","Jrxml File must have same filename with Jasper File.");
} else
e.reject("error.jrxml-file-must-have-extension-of-jrxml", "Jrxml File must have extension of .jrxml");
} else if (report.isNew())
e.reject("error.required", new Object[] { "Jrxml File" }, "Jrxml File is required.");
}
}