1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.contract.model.validation; |
17 | |
|
18 | |
import org.kuali.student.contract.model.ServiceContractModel; |
19 | |
import org.kuali.student.contract.model.ServiceMethod; |
20 | |
import org.kuali.student.contract.model.XmlType; |
21 | |
|
22 | |
import java.util.ArrayList; |
23 | |
import java.util.Collection; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class ServiceContractModelValidator implements ModelValidator { |
30 | |
|
31 | |
private ServiceContractModel model; |
32 | |
|
33 | 0 | public ServiceContractModelValidator(ServiceContractModel model) { |
34 | 0 | this.model = model; |
35 | 0 | } |
36 | |
private Collection errors; |
37 | |
|
38 | |
@Override |
39 | |
public Collection<String> validate() { |
40 | 0 | errors = new ArrayList(); |
41 | 0 | basicValidation(); |
42 | 0 | this.validateServiceMethods(); |
43 | 0 | validateXmlTypes(); |
44 | 0 | return errors; |
45 | |
} |
46 | |
|
47 | |
private void validateServiceMethods() { |
48 | 0 | for (ServiceMethod method : model.getServiceMethods()) { |
49 | 0 | errors.addAll(new ServiceMethodValidator(method, model).validate()); |
50 | |
} |
51 | 0 | } |
52 | |
|
53 | |
private void validateXmlTypes() { |
54 | 0 | if (model.getXmlTypes().size() == 0) { |
55 | 0 | addError("No xmlTypes found"); |
56 | |
} |
57 | 0 | for (XmlType xmlType : model.getXmlTypes()) { |
58 | 0 | XmlTypesValidator validator = new XmlTypesValidator(xmlType, model); |
59 | 0 | errors.addAll(validator.validate()); |
60 | 0 | } |
61 | 0 | } |
62 | |
|
63 | |
private void basicValidation() { |
64 | 0 | if (model.getServiceMethods().size() == 0) { |
65 | 0 | addError("no service methods have been defined"); |
66 | |
} |
67 | 0 | } |
68 | |
|
69 | |
private void addError(String msg) { |
70 | 0 | String error = "Error in service methods: " + msg; |
71 | 0 | if (!errors.contains(error)) { |
72 | 0 | errors.add(error); |
73 | |
} |
74 | 0 | } |
75 | |
} |