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.DictionaryModel; |
19 |
|
import org.kuali.student.contract.model.Service; |
20 |
|
import org.kuali.student.contract.model.ServiceContractModel; |
21 |
|
import org.kuali.student.contract.model.ServiceMethod; |
22 |
|
import org.kuali.student.contract.model.ServiceMethodError; |
23 |
|
import org.kuali.student.contract.model.ServiceMethodParameter; |
24 |
|
import org.kuali.student.contract.model.util.ModelFinder; |
25 |
|
|
26 |
|
import java.util.ArrayList; |
27 |
|
import java.util.Collection; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
@author |
32 |
|
|
|
|
| 0% |
Uncovered Elements: 45 (45) |
Complexity: 12 |
Complexity Density: 0.46 |
|
33 |
|
public class ServiceMethodValidator implements ModelValidator { |
34 |
|
|
35 |
|
private ServiceMethod method; |
36 |
|
private ServiceContractModel model; |
37 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
38 |
0
|
public ServiceMethodValidator(ServiceMethod method, ServiceContractModel model) {... |
39 |
0
|
this.method = method; |
40 |
0
|
this.model = model; |
41 |
|
} |
42 |
|
private Collection errors; |
43 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
44 |
0
|
@Override... |
45 |
|
public Collection<String> validate() { |
46 |
0
|
errors = new ArrayList(); |
47 |
0
|
basicValidation(); |
48 |
0
|
for (ServiceMethodParameter param : method.getParameters()) { |
49 |
0
|
errors.addAll(new ServiceMethodParameterValidator(param, method).validate()); |
50 |
|
} |
51 |
0
|
errors.addAll(new ServiceMethodReturnValueValidator(method.getReturnValue(), method).validate()); |
52 |
0
|
for (ServiceMethodError param : method.getErrors()) { |
53 |
0
|
errors.addAll(new ServiceMethodErrorValidator(param, method).validate()); |
54 |
|
} |
55 |
0
|
return errors; |
56 |
|
} |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 6 |
Complexity Density: 0.6 |
|
58 |
0
|
private void basicValidation() {... |
59 |
0
|
if (method.getService().equals("")) { |
60 |
0
|
addError("Service is required"); |
61 |
|
} else { |
62 |
0
|
if (findService(method.getService()) == null) { |
63 |
0
|
addError("Service, [" + method.getService() |
64 |
|
+ "] could not be found in the list of services"); |
65 |
|
} |
66 |
|
} |
67 |
0
|
if (method.getName().equals("")) { |
68 |
0
|
addError("Name is required"); |
69 |
|
} |
70 |
0
|
if (method.getDescription().equals("")) { |
71 |
0
|
addError("Description is required"); |
72 |
|
} |
73 |
0
|
if (method.getReturnValue() == null) { |
74 |
0
|
addError("Return value is required"); |
75 |
|
} |
76 |
|
} |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
78 |
0
|
private Service findService(String service) {... |
79 |
|
|
80 |
0
|
if (!(model instanceof ServiceContractModel)) { |
81 |
0
|
return null; |
82 |
|
} |
83 |
0
|
return new ModelFinder(model).findService(service); |
84 |
|
} |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
86 |
0
|
private void addError(String msg) {... |
87 |
0
|
String error = "Error in service method: " + method.getService() + "." |
88 |
|
+ method.getName() + ": " + msg; |
89 |
0
|
if (!errors.contains(error)) { |
90 |
0
|
errors.add(error); |
91 |
|
} |
92 |
|
} |
93 |
|
} |