1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.contract.writer.service; |
17 |
|
|
18 |
|
import java.util.Collection; |
19 |
|
import java.util.HashMap; |
20 |
|
import java.util.HashSet; |
21 |
|
import java.util.List; |
22 |
|
import java.util.Map; |
23 |
|
import java.util.Set; |
24 |
|
|
25 |
|
import org.kuali.student.contract.model.Service; |
26 |
|
import org.kuali.student.contract.model.ServiceContractModel; |
27 |
|
import org.kuali.student.contract.model.ServiceMethod; |
28 |
|
import org.kuali.student.contract.model.ServiceMethodError; |
29 |
|
import org.kuali.student.contract.model.XmlType; |
30 |
|
import org.kuali.student.contract.model.util.ServicesFilter; |
31 |
|
import org.kuali.student.contract.model.validation.DictionaryValidationException; |
32 |
|
import org.kuali.student.contract.model.validation.ServiceContractModelValidator; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@author |
37 |
|
|
|
|
| 0% |
Uncovered Elements: 51 (51) |
Complexity: 10 |
Complexity Density: 0.27 |
|
38 |
|
public class PureJavaInfcWriter { |
39 |
|
|
40 |
|
private ServiceContractModel model; |
41 |
|
private String directory; |
42 |
|
private String rootPackage; |
43 |
|
public static final String DEFAULT_ROOT_PACKAGE = "org.kuali.student.service"; |
44 |
|
private ServicesFilter filter; |
45 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
46 |
0
|
public PureJavaInfcWriter(ServiceContractModel model,... |
47 |
|
String directory, |
48 |
|
String rootPackage, |
49 |
|
ServicesFilter filter) { |
50 |
0
|
this.model = model; |
51 |
0
|
this.directory = directory; |
52 |
0
|
this.rootPackage = rootPackage; |
53 |
0
|
this.filter = filter; |
54 |
|
} |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
@param |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
60 |
0
|
public void write() {... |
61 |
0
|
this.validate(); |
62 |
|
|
63 |
0
|
for (Service service : filterServices()) { |
64 |
0
|
new PureJavaInfcWriterForOneService(model, directory, rootPackage, service.getKey()).write(); |
65 |
|
} |
66 |
|
|
67 |
|
|
68 |
0
|
System.out.println("Generating common Info interfaces"); |
69 |
0
|
for (XmlType xmlType : getXmlTypesUsedByMoreThanOneByService()) { |
70 |
0
|
System.out.println("Generating info interface for " + xmlType.getName()); |
71 |
0
|
new PureJavaInfcInfcWriter(model, directory, rootPackage, xmlType.getService(), xmlType).write(); |
72 |
0
|
new PureJavaInfcBeanWriter(model, directory, rootPackage, xmlType.getService(), xmlType).write(); |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
} |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
86 |
0
|
private Set<XmlType> getXmlTypesUsedByMoreThanOneByService() {... |
87 |
0
|
Set<XmlType> set = new HashSet(); |
88 |
0
|
for (XmlType type : model.getXmlTypes()) { |
89 |
0
|
if (type.getService().contains(",")) { |
90 |
0
|
if (type.getPrimitive().equalsIgnoreCase(XmlType.COMPLEX)) { |
91 |
0
|
System.out.println(type.getName() + "==>" + type.getService()); |
92 |
0
|
set.add(type); |
93 |
|
} |
94 |
|
} |
95 |
|
} |
96 |
0
|
return set; |
97 |
|
} |
98 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
99 |
0
|
private Map<String, ServiceMethodError> getServiceMethodErrors() {... |
100 |
0
|
Map<String, ServiceMethodError> errors = new HashMap(); |
101 |
0
|
for (ServiceMethod method : model.getServiceMethods()) { |
102 |
0
|
for (ServiceMethodError error : method.getErrors()) { |
103 |
0
|
errors.put(error.getType(), error); |
104 |
|
} |
105 |
|
} |
106 |
0
|
return errors; |
107 |
|
} |
108 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
109 |
0
|
private List<Service> filterServices() {... |
110 |
0
|
if (filter == null) { |
111 |
0
|
return model.getServices(); |
112 |
|
} |
113 |
0
|
return filter.filter(model.getServices()); |
114 |
|
} |
115 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
116 |
0
|
private void validate() {... |
117 |
0
|
Collection<String> errors = |
118 |
|
new ServiceContractModelValidator(model).validate(); |
119 |
0
|
if (errors.size() > 0) { |
120 |
0
|
StringBuffer buf = new StringBuffer(); |
121 |
0
|
buf.append(errors.size() + " errors found while validating the data."); |
122 |
0
|
int cnt = 0; |
123 |
0
|
for (String msg : errors) { |
124 |
0
|
cnt++; |
125 |
0
|
buf.append("\n"); |
126 |
0
|
buf.append("*error*" + cnt + ":" + msg); |
127 |
|
} |
128 |
|
|
129 |
0
|
throw new DictionaryValidationException(buf.toString()); |
130 |
|
} |
131 |
|
} |
132 |
|
} |