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.HashSet;
19 import java.util.List;
20 import java.util.Set;
21
22 import org.kuali.student.contract.model.ServiceContractModel;
23 import org.kuali.student.contract.model.ServiceMethod;
24 import org.kuali.student.contract.model.XmlType;
25 import org.kuali.student.contract.model.util.ModelFinder;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29
30
31
32
33 public class AdminUiWriterForOneService {
34
35
36 private static final Logger log = LoggerFactory.getLogger(AdminUiWriterForOneService.class);
37
38 private ServiceContractModel model;
39 private ModelFinder finder;
40 private String directory;
41 private String rootPackage;
42 private String servKey;
43
44 public AdminUiWriterForOneService(ServiceContractModel model,
45 String directory,
46 String rootPackage,
47 String servKey) {
48 this.model = model;
49 this.finder = new ModelFinder(model);
50 this.directory = directory;
51 this.rootPackage = rootPackage;
52 this.servKey = servKey;
53 }
54
55
56
57
58
59
60 public void write() {
61 List<ServiceMethod> methods = finder.getServiceMethodsInService(servKey);
62 if (methods.isEmpty ()) {
63 log.warn("No methods defined for servKey: " + servKey);
64 return;
65 }
66 Set<XmlType> types = this.getMainXmlTypesUsedByService(methods);
67 if (types.isEmpty()) {
68 log.warn("No types defined for servKey: " + servKey);
69 return;
70 }
71
72 log.info("Generating admin UI for " + types.size() + " in " + servKey);
73 for (XmlType type : types) {
74 new AdminUiInquirableWriter(model, directory, rootPackage, servKey, type, methods).write();
75 new AdminUiLookupableWriter(model, directory, rootPackage, servKey, type, methods).write();
76 new AdminUiLookupViewBeanWriter(model, directory, rootPackage, servKey, type, methods).write();
77 new AdminUiInquiryViewBeanWriter(model, directory, rootPackage, servKey, type, methods).write();
78 }
79 }
80
81 private Set<XmlType> getMainXmlTypesUsedByService(List<ServiceMethod> methods) {
82 Set<XmlType> set = new HashSet();
83 for (ServiceMethod method : methods) {
84 if (method.getReturnValue().getType().endsWith("List")) {
85 continue;
86 }
87 XmlType returnType = finder.findXmlType(method.getReturnValue().getType());
88 if (returnType == null) {
89 continue;
90 }
91 if (!returnType.getPrimitive().equalsIgnoreCase(XmlType.COMPLEX)) {
92 continue;
93 }
94
95 if (returnType.getName().equalsIgnoreCase("TypeInfo")) {
96 if (!servKey.equalsIgnoreCase("type")) {
97 continue;
98 }
99 }
100
101 if (returnType.getName().equalsIgnoreCase("StateInfo")) {
102 if (!servKey.equalsIgnoreCase("state")) {
103 continue;
104 }
105 }
106
107
108
109
110
111
112
113
114 if (method.getName().startsWith("get")) {
115 if (method.getParameters().size() == 2) {
116 if (method.getParameters().get(0).getType().equalsIgnoreCase("String")) {
117 set.add(returnType);
118 continue;
119 }
120 }
121 }
122 }
123 return set;
124 }
125 }