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.ServiceMethod; |
19 | |
import org.kuali.student.contract.model.ServiceMethodReturnValue; |
20 | |
|
21 | |
import java.util.ArrayList; |
22 | |
import java.util.Collection; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
public class ServiceMethodReturnValueValidator implements ModelValidator |
29 | |
{ |
30 | |
|
31 | |
private ServiceMethodReturnValue returnValue; |
32 | |
private ServiceMethod serviceMethod; |
33 | |
|
34 | |
public ServiceMethodReturnValueValidator (ServiceMethodReturnValue returnValue, |
35 | |
ServiceMethod serviceMethod) |
36 | 0 | { |
37 | 0 | this.returnValue = returnValue; |
38 | 0 | this.serviceMethod = serviceMethod; |
39 | 0 | } |
40 | |
|
41 | |
private Collection errors; |
42 | |
|
43 | |
@Override |
44 | |
public Collection<String> validate () |
45 | |
{ |
46 | 0 | errors = new ArrayList (); |
47 | 0 | basicValidation (); |
48 | 0 | return errors; |
49 | |
} |
50 | |
|
51 | |
private void basicValidation () |
52 | |
{ |
53 | 0 | if (returnValue.getType ().equals ("")) |
54 | |
{ |
55 | 0 | addError ("return type is required"); |
56 | |
} |
57 | 0 | if (returnValue.getDescription ().equals ("")) |
58 | |
{ |
59 | 0 | addError ("Description is required"); |
60 | |
} |
61 | |
|
62 | 0 | } |
63 | |
|
64 | |
private void addError (String msg) |
65 | |
{ |
66 | 0 | String error = "Error in return value for method: " + serviceMethod.getService () |
67 | |
+ "." + serviceMethod.getName () + ": " + msg; |
68 | 0 | if ( ! errors.contains (error)) |
69 | |
{ |
70 | 0 | errors.add (error); |
71 | |
} |
72 | 0 | } |
73 | |
|
74 | |
} |