Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EntityValidator extends ApplicationObjectSupport implements Validator {
- List <AttributeValueStorage> avsList;
- public EntityValidator() {
- }
- @Override
- public boolean supports(Class<?> clazz) {
- return Entity.class.isAssignableFrom(clazz);
- }
- @Override
- public void validate(Object obj, Errors e) {
- Entity et = null;
- try{
- et = (Entity)obj;
- }catch (Throwable t) {
- logger.debug("EntityValidator.validate : Object is not of Entity", t);
- e.reject("error.entitytype.save.object");
- return;
- }
- avsList=et.getAVS();
- for(AttributeValueStorage avs:avsList){
- Attribute att = new Attribute();
- att = avs.getAttribute();
- if(att.getDataTypeId() == 1){
- if(att.isRequired()){
- ValidationUtils.rejectIfEmptyOrWhitespace(e, "AVS["+avsList.indexOf(avs)+"].valueVarchar", "error.entitytype.save.object");
- }
- if(att.getRegex().getRegexId()> 0 ){
- boolean matches=Pattern.compile(att.getRegex().getPattern()).matcher("AVS["+avsList.indexOf(avs)+"].valueVarchar").matches();
- if(!matches){
- e.rejectValue("AVS["+avsList.indexOf(avs)+"].valueVarchar", "error.entitytype.name.invalid");
- }
- }
- }
- if(att.getDataTypeId() == 2){
- if(att.isRequired()){
- ValidationUtils.rejectIfEmptyOrWhitespace(e, "AVS["+avsList.indexOf(avs)+"].valueLong", "error.entitytype.save.object");
- }
- if(att.getRegex().getRegexId()> 0 ){
- boolean matches=Pattern.compile(att.getRegex().getPattern()).matcher("AVS["+avsList.indexOf(avs)+"].valueLong").matches();
- if(!matches){
- e.rejectValue("AVS["+avsList.indexOf(avs)+"].valueLong", "error.entitytype.name.invalid");
- }
- }
- }
- if(att.getDataTypeId() == 3){
- if(att.isRequired()){
- ValidationUtils.rejectIfEmptyOrWhitespace(e, "AVS["+avsList.indexOf(avs)+"].valueDate", "error.entitytype.save.object");
- }
- if(att.getRegex().getRegexId()> 0 ){
- boolean matches=Pattern.compile(att.getRegex().getPattern()).matcher("AVS["+avsList.indexOf(avs)+"].valueDate").matches();
- if(!matches){
- e.rejectValue("AVS["+avsList.indexOf(avs)+"].valueDate", "error.entitytype.name.invalid");
- }
- }
- }
- if(att.getDataTypeId() == 4){
- if(att.isRequired()){
- ValidationUtils.rejectIfEmptyOrWhitespace(e, "AVS["+avsList.indexOf(avs)+"].valueText", "error.entitytype.save.object");
- }
- if(att.getRegex().getRegexId()> 0 ){
- boolean matches=Pattern.compile(att.getRegex().getPattern()).matcher("AVS["+avsList.indexOf(avs)+"].valueText").matches();
- if(!matches){
- e.rejectValue("AVS["+avsList.indexOf(avs)+"].valueText", "error.entitytype.name.invalid");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement