1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.admin.ui.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.util.ServicesFilter;
31 import org.kuali.student.contract.model.validation.DictionaryValidationException;
32 import org.kuali.student.contract.model.validation.ServiceContractModelValidator;
33
34
35
36
37
38 public class AdminUiWriter {
39
40 private ServiceContractModel model;
41 private String directory;
42 private String rootPackage;
43 public static final String DEFAULT_ROOT_PACKAGE = "ui.admin";
44 private ServicesFilter filter;
45
46 public AdminUiWriter(ServiceContractModel model,
47 String directory,
48 String rootPackage,
49 ServicesFilter filter) {
50 this.model = model;
51 this.directory = directory;
52 this.rootPackage = rootPackage;
53 this.filter = filter;
54 }
55
56
57
58
59
60 public void write() {
61 this.validate();
62
63 for (Service service : filterServices()) {
64 new AdminUiWriterForOneService(model, directory, rootPackage, service.getKey()).write();
65 }
66 }
67
68 private List<Service> filterServices() {
69 if (filter == null) {
70 return model.getServices();
71 }
72 return filter.filter(model.getServices());
73 }
74
75 private void validate() {
76 Collection<String> errors =
77 new ServiceContractModelValidator(model).validate();
78 if (errors.size() > 0) {
79 StringBuffer buf = new StringBuffer();
80 buf.append(errors.size() + " errors found while validating the data.");
81 int cnt = 0;
82 for (String msg : errors) {
83 cnt++;
84 buf.append("\n");
85 buf.append("*error*" + cnt + ":" + msg);
86 }
87
88 throw new DictionaryValidationException(buf.toString());
89 }
90 }
91 }