1 21 package com.jaspersoft.jasperserver.war.validation; 22 23 import java.math.BigDecimal ; 24 import java.util.regex.Pattern ; 25 26 import com.jaspersoft.jasperserver.war.dto.DataTypeWrapper; 27 import com.jaspersoft.jasperserver.war.dto.QueryWrapper; 28 import com.jaspersoft.jasperserver.war.common.JasperServerUtil; 29 import com.jaspersoft.jasperserver.api.metadata.common.domain.DataType; 30 import com.jaspersoft.jasperserver.api.metadata.common.domain.Query; 31 import org.springframework.validation.Errors; 32 import org.springframework.validation.Validator; 33 34 38 public class QueryValidator implements Validator 39 { 40 public boolean supports(Class klass) 41 { 42 return QueryWrapper.class.isAssignableFrom(klass); 43 } 44 45 public void validate(Object object, Errors errors) 46 { 47 QueryWrapper wrapper = (QueryWrapper) object; 48 Query query = wrapper.getQuery(); 49 if (query.getName() == null || query.getName().trim().length() == 0) { 50 errors.rejectValue("query.name", "error.not.empty"); 51 } else { 52 if(!JasperServerUtil.regExValidateName(query.getName())) { 53 errors.rejectValue("query.name", null, "Name contains invalid characters"); 54 } 55 if (query.getName().length() > 100) { 56 errors.rejectValue("query.name", null, "Name is longer than 100 characters"); 57 } 58 } 59 60 if (query.getLabel() == null || query.getLabel().trim().length() == 0) { 61 errors.rejectValue("query.label", "error.not.empty"); 62 } else { 63 if(!JasperServerUtil.regExValidateLabel(query.getLabel())) { 64 errors.rejectValue("query.label", null, "Label contains invalid characters"); 65 } 66 if (query.getLabel().length() > 100) { 67 errors.rejectValue("query.label", null, "Label is longer than 100 characters"); 68 } 69 } 70 71 if (query.getDescription() != null && query.getDescription().length() > 250) { 72 errors.rejectValue("query.description", null, "Description is longer than 250 characters"); 73 } 74 75 } 76 } 77 | Popular Tags |