1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package net.sf.pmr.core.domain.basicProject;
36
37 import java.util.Iterator;
38
39 import net.sf.pmr.core.CoreObjectFactory;
40 import net.sf.pmr.keopsframework.domain.validation.Errors;
41 import net.sf.pmr.keopsframework.domain.validation.Validator;
42
43
44 /***
45 * @author Arnaud Prost (aprost@gmail.com)
46 *
47 * basicProject Validator
48 */
49 public class BasicProjectValidatorImpl implements Validator {
50
51 /***
52 * @see net.sf.pmr.keopsframework.domain.validation.Validator#validate(java.lang.Object)
53 */
54 public Errors validate(final Object object) {
55
56 BasicProject basicProject = (BasicProject) object;
57
58 Errors errors = CoreObjectFactory.getErrors();
59
60 if (basicProject.getCode() == null
61 || basicProject.getCode().trim() == "") {
62
63 errors.rejectValue("code", "basicProject.codeMandatory");
64
65 } else if (basicProject.getCode().length() > 10) {
66
67 errors.rejectValue("code", "basicProject.codeTooLong");
68 }
69
70 if (basicProject.getName() == null
71 || basicProject.getName().trim() == "") {
72
73 errors.rejectValue("name", "basicProject.nameMandatory");
74
75 } else if (basicProject.getName().length() > 100) {
76
77 errors.rejectValue("name", "basicProject.nameTooLong");
78
79 }
80
81 if (basicProject.getMembers().size() < 1) {
82
83 errors.reject("basicProject.atLeastOneMember");
84
85 } else {
86
87 boolean oneMemberIsNotNull = false;
88
89 for (Iterator i = basicProject.getMembers().iterator(); i.hasNext();) {
90
91 if (i.next() != null) {
92 oneMemberIsNotNull = true;
93 }
94
95 }
96
97 if (!oneMemberIsNotNull) {
98 errors.reject("basicProject.atLeastOneMember");
99 }
100
101 }
102
103 return errors;
104
105 }
106 }