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