PageRenderTime 27ms CodeModel.GetById 11ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 1ms

/hippo/src/main/java/com/googlecode/hdbc/model/validator/ExperimentDataValidator.java

http://hdbc.googlecode.com/
Java | 52 lines | 27 code | 6 blank | 19 comment | 5 complexity | 5e3b80a8bd10afd4ad5902354d2913a2 MD5 | raw file
 1package com.googlecode.hdbc.model.validator;
 2
 3import org.springframework.validation.Errors;
 4import org.springframework.validation.Validator;
 5
 6import com.googlecode.hdbc.model.record.ExperimentData;
 7
 8public class ExperimentDataValidator extends DataValidator implements Validator {
 9
10	public boolean supports(Class clazz) {
11		return false;
12	}
13
14	/**
15	 * Validate the ExperimentData dumb object
16	 * <p>
17	 * Specification
18	 * validate :: Object -> Errors -> Boolean
19	 * validate obj | obj.uid == null || obj.uid > 0
20	 * 					&&
21	 * 				  obj.title != null && len(obj.title) <= 64
22	 * 					&&
23	 * 				  obj.purpose != null && len(obj.purpose) <= 128
24	 * 					&&
25	 * 				  obj.method == null || len(obj.method) <= 4000
26	 * 					&&
27	 * 			      obj.conclusion == null || len(obj.conclusion) <= 4000 = false
28	 * 				 | otherwise = true
29	 * <p>
30	 * precondition is obj.title and obj.purpose /= null
31	 * postcondition error.count >= 0
32	 */
33	public void validate(Object target, Errors errors) {
34		ExperimentData data = (ExperimentData) target;
35		if (!this.isNullOrGreaterThan(data.getUid(), 0)) {
36			errors.rejectValue("uid", ValidationErrorCd.NUMBER_BELOW_MINIMUM.toString(), new Object[] {0}, "na");
37		}
38		if (!this.isNotNullAndUpToLengthN(data.getTitle(), 64)) {
39			errors.rejectValue("title", ValidationErrorCd.REQUIRED_STRING_TOO_LONG.toString(), new Object[] {64}, "na");
40		}
41		if (!this.isNotNullAndUpToLengthN(data.getPurpose(), 128)) {
42			errors.rejectValue("purpose", ValidationErrorCd.REQUIRED_STRING_TOO_LONG.toString(), new Object[] {128}, "na");
43		}
44		if (!this.isNullOrUptoLengthN(data.getMethod(), 4000)) {
45			errors.rejectValue("method", ValidationErrorCd.OPTIONAL_STRING_TO_LONG.toString(), new Object[] {4000}, "na");
46		}
47		if (!this.isNullOrUptoLengthN(data.getConclusion(), 4000)) {
48			errors.rejectValue("conclusion", ValidationErrorCd.OPTIONAL_STRING_TO_LONG.toString(), new Object[] {4000}, "na");
49		}
50	}
51
52}