1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.mock.mojo;
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.impl.ServiceContractModelPescXsdLoader;
31 import org.kuali.student.contract.model.util.ServicesFilter;
32 import org.kuali.student.contract.model.validation.DictionaryValidationException;
33 import org.kuali.student.contract.model.validation.ServiceContractModelValidator;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37
38
39
40
41 public class MockImplWriter {
42
43 private static Logger log = LoggerFactory.getLogger(MockImplWriter.class);
44
45 protected ServiceContractModel model;
46 protected String directory;
47 protected String rootPackage;
48 public static final String ROOT_PACKAGE = "org.kuali.student";
49 public static final String LUM_ROOT_PACKAGE = "org.kuali.student.lum";
50 public static final String ENROLLMENT_ROOT_PACKAGE = "org.kuali.student.enrollment";
51 protected ServicesFilter filter;
52 protected boolean isR1;
53
54 public MockImplWriter(ServiceContractModel model,
55 String directory,
56 String rootPackage,
57 ServicesFilter filter,
58 boolean isR1) {
59 this.model = model;
60 this.directory = directory;
61 this.rootPackage = rootPackage;
62 this.filter = filter;
63 this.isR1 = isR1;
64 }
65
66
67
68
69
70 public void write() {
71 this.validate();
72
73 for (Service service : filterServices()) {
74 log.info ("**************writing service=" + service.getKey());
75 new MockImplWriterForOneService(model, directory, rootPackage, service.getKey(), isR1).write();
76 }
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 }
96
97 private Set<XmlType> getXmlTypesUsedByMoreThanOneByService() {
98 Set<XmlType> set = new HashSet();
99 for (XmlType type : model.getXmlTypes()) {
100 if (type.getService().contains(",")) {
101 if (type.getPrimitive().equalsIgnoreCase(XmlType.COMPLEX)) {
102 System.out.println(type.getName() + "==>" + type.getService());
103 set.add(type);
104 }
105 }
106 }
107 return set;
108 }
109
110 private Map<String, ServiceMethodError> getServiceMethodErrors() {
111 Map<String, ServiceMethodError> errors = new HashMap();
112 for (ServiceMethod method : model.getServiceMethods()) {
113 for (ServiceMethodError error : method.getErrors()) {
114 errors.put(error.getType(), error);
115 }
116 }
117 return errors;
118 }
119
120 protected List<Service> filterServices() {
121 if (filter == null) {
122 return model.getServices();
123 }
124 return filter.filter(model.getServices());
125 }
126
127 protected void validate() {
128 Collection<String> errors =
129 new ServiceContractModelValidator(model).validate();
130 if (errors.size() > 0) {
131 StringBuffer buf = new StringBuffer();
132 buf.append(errors.size() + " errors found while validating the data.");
133 int cnt = 0;
134 for (String msg : errors) {
135 cnt++;
136 buf.append("\n");
137 buf.append("*error*" + cnt + ":" + msg);
138 }
139
140 throw new DictionaryValidationException(buf.toString());
141 }
142 }
143 }