Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. public class EntityValidator extends ApplicationObjectSupport implements Validator {
  2. List <AttributeValueStorage> avsList;
  3. public EntityValidator() {
  4.  
  5. }
  6. @Override
  7. public boolean supports(Class<?> clazz) {
  8. return Entity.class.isAssignableFrom(clazz);
  9. }
  10. @Override
  11. public void validate(Object obj, Errors e) {
  12. Entity et = null;
  13. try{
  14. et = (Entity)obj;
  15. }catch (Throwable t) {
  16. logger.debug("EntityValidator.validate : Object is not of Entity", t);
  17. e.reject("error.entitytype.save.object");
  18. return;
  19. }
  20. avsList=et.getAVS();
  21. for(AttributeValueStorage avs:avsList){
  22. Attribute att = new Attribute();
  23. att = avs.getAttribute();
  24. if(att.getDataTypeId() == 1){
  25. if(att.isRequired()){
  26. ValidationUtils.rejectIfEmptyOrWhitespace(e, "AVS["+avsList.indexOf(avs)+"].valueVarchar", "error.entitytype.save.object");
  27. }
  28. if(att.getRegex().getRegexId()> 0 ){
  29. boolean matches=Pattern.compile(att.getRegex().getPattern()).matcher("AVS["+avsList.indexOf(avs)+"].valueVarchar").matches();
  30. if(!matches){
  31. e.rejectValue("AVS["+avsList.indexOf(avs)+"].valueVarchar", "error.entitytype.name.invalid");
  32. }
  33. }
  34. }
  35. if(att.getDataTypeId() == 2){
  36. if(att.isRequired()){
  37. ValidationUtils.rejectIfEmptyOrWhitespace(e, "AVS["+avsList.indexOf(avs)+"].valueLong", "error.entitytype.save.object");
  38. }
  39. if(att.getRegex().getRegexId()> 0 ){
  40. boolean matches=Pattern.compile(att.getRegex().getPattern()).matcher("AVS["+avsList.indexOf(avs)+"].valueLong").matches();
  41. if(!matches){
  42. e.rejectValue("AVS["+avsList.indexOf(avs)+"].valueLong", "error.entitytype.name.invalid");
  43. }
  44. }
  45. }
  46. if(att.getDataTypeId() == 3){
  47. if(att.isRequired()){
  48. ValidationUtils.rejectIfEmptyOrWhitespace(e, "AVS["+avsList.indexOf(avs)+"].valueDate", "error.entitytype.save.object");
  49. }
  50. if(att.getRegex().getRegexId()> 0 ){
  51. boolean matches=Pattern.compile(att.getRegex().getPattern()).matcher("AVS["+avsList.indexOf(avs)+"].valueDate").matches();
  52. if(!matches){
  53. e.rejectValue("AVS["+avsList.indexOf(avs)+"].valueDate", "error.entitytype.name.invalid");
  54. }
  55. }
  56. }
  57. if(att.getDataTypeId() == 4){
  58. if(att.isRequired()){
  59. ValidationUtils.rejectIfEmptyOrWhitespace(e, "AVS["+avsList.indexOf(avs)+"].valueText", "error.entitytype.save.object");
  60. }
  61. if(att.getRegex().getRegexId()> 0 ){
  62. boolean matches=Pattern.compile(att.getRegex().getPattern()).matcher("AVS["+avsList.indexOf(avs)+"].valueText").matches();
  63. if(!matches){
  64. e.rejectValue("AVS["+avsList.indexOf(avs)+"].valueText", "error.entitytype.name.invalid");
  65. }
  66. }
  67. }
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement