k-joseph

Untitled

Jul 17th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. /**
  2. * Checks the form object for any inconsistencies/errors
  3. *
  4. * @see org.springframework.validation.Validator#validate(java.lang.Object,
  5. * org.springframework.validation.Errors)
  6. * @should fail validation if name is null or empty or whitespace
  7. * @should fail validation if description is null or empty or whitespace
  8. * @should fail validation if program name already in use
  9. * @should fail validation if concept is null or empty or whitespace
  10. * @should pass validation if all required fields have proper values
  11. */
  12. public void validate(Object obj, Errors errors) {
  13. Program p = (Program) obj;
  14. if (p == null) {
  15. errors.rejectValue("program", "error.general");
  16. } else {
  17. ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name");
  18. ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "error.description.required");
  19. Program program = Context.getProgramWorkflowService().getProgramByName(new Program(programName).getName());
  20.  
  21. if (program.getName().equals(p.getName()) && !program.getProgramId().equals(p.getProgramId())) {
  22. errors.rejectValue("name", "general.error.nameAlreadyInUse");
  23.  
  24. } else {
  25. Context.evictFromSession(program);
  26. }
  27.  
  28. ValidationUtils.rejectIfEmptyOrWhitespace(errors, "concept", "error.concept");
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment