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 | |
|
32 | |
private ServiceContractModel model; |
33 | |
|
34 | |
public ServiceContractModelValidator (ServiceContractModel model) |
35 | 0 | { |
36 | 0 | this.model = model; |
37 | 0 | } |
38 | |
private Collection errors; |
39 | |
|
40 | |
@Override |
41 | |
public Collection<String> validate () |
42 | |
{ |
43 | 0 | errors = new ArrayList (); |
44 | 0 | basicValidation (); |
45 | 0 | this.validateServiceMethods (); |
46 | 0 | validateXmlTypes (); |
47 | 0 | return errors; |
48 | |
} |
49 | |
|
50 | |
private void validateServiceMethods () |
51 | |
{ |
52 | 0 | for (ServiceMethod method : model.getServiceMethods ()) |
53 | |
{ |
54 | 0 | errors.addAll (new ServiceMethodValidator (method, model).validate ()); |
55 | |
} |
56 | 0 | } |
57 | |
|
58 | |
private void validateXmlTypes () |
59 | |
{ |
60 | 0 | if (model.getXmlTypes ().size () == 0) |
61 | |
{ |
62 | 0 | addError ("No xmlTypes found"); |
63 | |
} |
64 | 0 | for (XmlType xmlType : model.getXmlTypes ()) |
65 | |
{ |
66 | 0 | XmlTypesValidator validator = new XmlTypesValidator (xmlType, model); |
67 | 0 | errors.addAll (validator.validate ()); |
68 | 0 | } |
69 | 0 | } |
70 | |
|
71 | |
private void basicValidation () |
72 | |
{ |
73 | 0 | if (model.getServiceMethods ().size () == 0) |
74 | |
{ |
75 | 0 | addError ("no service methods have been defined"); |
76 | |
} |
77 | 0 | } |
78 | |
|
79 | |
private void addError (String msg) |
80 | |
{ |
81 | 0 | String error = "Error in service methods: " + msg; |
82 | 0 | if ( ! errors.contains (error)) |
83 | |
{ |
84 | 0 | errors.add (error); |
85 | |
} |
86 | 0 | } |
87 | |
} |